@medplum/dosespot-react 4.3.10 → 4.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/cjs/index.d.ts +46 -0
- package/dist/esm/index.d.ts +46 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +4 -4
- package/package.json +11 -11
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{DOSESPOT_IFRAME_BOT:()=>DOSESPOT_IFRAME_BOT,DOSESPOT_MEDICATION_HISTORY_BOT:()=>DOSESPOT_MEDICATION_HISTORY_BOT,DOSESPOT_NOTIFICATION_COUNTS_BOT:()=>DOSESPOT_NOTIFICATION_COUNTS_BOT,DOSESPOT_PATIENT_ID_SYSTEM:()=>DOSESPOT_PATIENT_ID_SYSTEM,DOSESPOT_PATIENT_SYNC_BOT:()=>DOSESPOT_PATIENT_SYNC_BOT,DOSESPOT_PRESCRIPTIONS_SYNC_BOT:()=>DOSESPOT_PRESCRIPTIONS_SYNC_BOT,MEDPLUM_BOT_SYSTEM:()=>MEDPLUM_BOT_SYSTEM,useDoseSpotIFrame:()=>useDoseSpotIFrame,useDoseSpotNotifications:()=>useDoseSpotNotifications});module.exports=__toCommonJS(index_exports);var MEDPLUM_BOT_SYSTEM="https://www.medplum.com/bots",DOSESPOT_PATIENT_ID_SYSTEM="https://dosespot.com/patient-id",DOSESPOT_PATIENT_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-patient-sync-bot"},DOSESPOT_IFRAME_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-iframe-bot"},DOSESPOT_MEDICATION_HISTORY_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-medication-history-bot"},DOSESPOT_PRESCRIPTIONS_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-prescriptions-sync-bot"},DOSESPOT_NOTIFICATION_COUNTS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-notification-counts-bot"};var import_react_hooks=require("@medplum/react-hooks"),import_react=require("react");function useDoseSpotIFrame(options){let medplum=(0,
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var index_exports={};__export(index_exports,{DOSESPOT_ADD_FAVORITE_MEDICATION_BOT:()=>DOSESPOT_ADD_FAVORITE_MEDICATION_BOT,DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM:()=>DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM,DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM:()=>DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM,DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT:()=>DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT,DOSESPOT_IFRAME_BOT:()=>DOSESPOT_IFRAME_BOT,DOSESPOT_MEDICATION_HISTORY_BOT:()=>DOSESPOT_MEDICATION_HISTORY_BOT,DOSESPOT_NOTIFICATION_COUNTS_BOT:()=>DOSESPOT_NOTIFICATION_COUNTS_BOT,DOSESPOT_PATIENT_ID_SYSTEM:()=>DOSESPOT_PATIENT_ID_SYSTEM,DOSESPOT_PATIENT_SYNC_BOT:()=>DOSESPOT_PATIENT_SYNC_BOT,DOSESPOT_PRESCRIPTIONS_SYNC_BOT:()=>DOSESPOT_PRESCRIPTIONS_SYNC_BOT,DOSESPOT_SEARCH_MEDICATIONS_BOT:()=>DOSESPOT_SEARCH_MEDICATIONS_BOT,MEDPLUM_BOT_SYSTEM:()=>MEDPLUM_BOT_SYSTEM,getMedicationName:()=>getMedicationName,useDoseSpotClinicFormulary:()=>useDoseSpotClinicFormulary,useDoseSpotIFrame:()=>useDoseSpotIFrame,useDoseSpotNotifications:()=>useDoseSpotNotifications});module.exports=__toCommonJS(index_exports);var MEDPLUM_BOT_SYSTEM="https://www.medplum.com/bots",DOSESPOT_PATIENT_ID_SYSTEM="https://dosespot.com/patient-id",DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM="https://dosespot.com/clinic-favorite-medication-id",DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM="https://dosespot.com/dispensable-drug-id",DOSESPOT_PATIENT_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-patient-sync-bot"},DOSESPOT_IFRAME_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-iframe-bot"},DOSESPOT_ADD_FAVORITE_MEDICATION_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-add-favorite-medication-bot"},DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-get-favorite-medications-bot"},DOSESPOT_SEARCH_MEDICATIONS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-search-medication-bot"},DOSESPOT_MEDICATION_HISTORY_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-medication-history-bot"},DOSESPOT_PRESCRIPTIONS_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-prescriptions-sync-bot"},DOSESPOT_NOTIFICATION_COUNTS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-notification-counts-bot"};var import_core=require("@medplum/core"),import_react_hooks=require("@medplum/react-hooks"),import_react=require("react");function useDoseSpotClinicFormulary(){let[directions,privateSetDirections]=(0,import_react.useState)(void 0),[selectedMedication,privateSetSelectedMedication]=(0,import_react.useState)(void 0),medplum=(0,import_react_hooks.useMedplum)(),state={selectedMedication,directions},saveFavoriteMedication=(0,import_react.useCallback)(async()=>{if(!selectedMedication)throw new Error("Must select a medication before adding a favorite medication");let medicationKnowledgeWithDirections={resourceType:"MedicationKnowledge",code:{...selectedMedication},administrationGuidelines:[{dosage:[{dosage:[{patientInstruction:directions||""}],type:{coding:[{system:"https://dosespot.com/patient-instructions"}]}}]}]};return medplum.executeBot(DOSESPOT_ADD_FAVORITE_MEDICATION_BOT,medicationKnowledgeWithDirections)},[selectedMedication,directions,medplum]),searchMedications=(0,import_react.useCallback)(async searchTerm=>await medplum.executeBot(DOSESPOT_SEARCH_MEDICATIONS_BOT,{name:searchTerm}),[medplum]);return{state,searchMedications,setSelectedMedication:medication=>{let medicationToSet;(0,import_core.isCodeableConcept)(medication)?medicationToSet={...medication}:(0,import_core.isCoding)(medication)&&(medicationToSet={text:medication.display||"",coding:[medication]}),privateSetSelectedMedication(medicationToSet)},setSelectedMedicationDirections:directions2=>{privateSetDirections(directions2)},saveFavoriteMedication,clear:()=>{privateSetSelectedMedication(void 0),privateSetDirections(void 0)}}}var import_react_hooks2=require("@medplum/react-hooks"),import_react2=require("react");function useDoseSpotIFrame(options){let medplum=(0,import_react_hooks2.useMedplum)(),{patientId,onPatientSyncSuccess,onIframeSuccess,onError}=options,initializingRef=(0,import_react2.useRef)(!1),[iframeUrl,setIframeUrl]=(0,import_react2.useState)(void 0),onPatientSyncSuccessRef=(0,import_react2.useRef)(onPatientSyncSuccess);onPatientSyncSuccessRef.current=onPatientSyncSuccess;let onIframeSuccessRef=(0,import_react2.useRef)(onIframeSuccess);onIframeSuccessRef.current=onIframeSuccess;let onErrorRef=(0,import_react2.useRef)(onError);onErrorRef.current=onError;let initPage=(0,import_react2.useCallback)(async()=>{if(!initializingRef.current){initializingRef.current=!0;try{patientId&&(await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT,{patientId}),onPatientSyncSuccessRef.current?.());let result=await medplum.executeBot(DOSESPOT_IFRAME_BOT,{patientId});result.url&&(setIframeUrl(result.url),onIframeSuccessRef.current?.(result.url))}catch(err){onErrorRef.current?.(err)}}},[medplum,patientId]);return(0,import_react2.useEffect)(()=>{initPage().catch(console.error)},[initPage]),iframeUrl}var import_react_hooks3=require("@medplum/react-hooks"),import_react3=require("react");var DEFAULT_REFRESH_INTERVAL_MILLISECONDS=1e4;function useDoseSpotNotifications(options){let medplum=(0,import_react_hooks3.useMedplum)(),{onChange,onError}=options??{},hasDoseSpot=medplum.getProjectMembership()?.identifier?.some(i=>i.system?.includes("dosespot")),refreshInterval=options?.refreshIntervalMilliseconds??DEFAULT_REFRESH_INTERVAL_MILLISECONDS,timerRef=(0,import_react3.useRef)(void 0),[unreadCount,setUnreadCount]=(0,import_react3.useState)(void 0),stopTimer=(0,import_react3.useCallback)(()=>{let timerId=timerRef.current;timerId&&clearInterval(timerId)},[]),updateCount=(0,import_react3.useCallback)(async()=>{try{let result=await medplum.executeBot(DOSESPOT_NOTIFICATION_COUNTS_BOT,{}),newCount=0;result.PendingPrescriptionsCount&&(newCount+=result.PendingPrescriptionsCount),result.PendingRxChangeCount&&(newCount+=result.PendingRxChangeCount),result.RefillRequestsCount&&(newCount+=result.RefillRequestsCount),result.TransactionErrorsCount&&(newCount+=result.TransactionErrorsCount),newCount!==unreadCount&&(setUnreadCount(newCount),onChange?.(newCount))}catch(err){onError?.(err),stopTimer()}},[medplum,unreadCount,onChange,onError,stopTimer]),startTimer=(0,import_react3.useCallback)(()=>{timerRef.current=setInterval(()=>{updateCount().catch(console.error)},refreshInterval)},[updateCount,refreshInterval]);return(0,import_react3.useEffect)(()=>(hasDoseSpot&&startTimer(),stopTimer),[hasDoseSpot,startTimer,stopTimer]),unreadCount}var getMedicationName=medication=>medication?.code?.text||"";
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts", "../../src/common.ts", "../../src/useDoseSpotIFrame.ts", "../../src/useDoseSpotNotifications.ts"],
|
|
4
|
-
"sourcesContent": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nexport * from './common';\nexport * from './useDoseSpotIFrame';\nexport * from './useDoseSpotNotifications';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { Identifier } from '@medplum/fhirtypes';\n\nexport const MEDPLUM_BOT_SYSTEM = 'https://www.medplum.com/bots';\n\nexport const DOSESPOT_PATIENT_ID_SYSTEM = 'https://dosespot.com/patient-id';\n\nexport const DOSESPOT_PATIENT_SYNC_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-patient-sync-bot' };\n\nexport const DOSESPOT_IFRAME_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-iframe-bot' };\n\nexport const DOSESPOT_MEDICATION_HISTORY_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-medication-history-bot',\n};\n\nexport const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-prescriptions-sync-bot',\n};\n\nexport const DOSESPOT_NOTIFICATION_COUNTS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-notification-counts-bot',\n};\n\nexport interface DoseSpotNotificationCountsResponse {\n PendingPrescriptionsCount: number;\n PendingRxChangeCount: number;\n RefillRequestsCount: number;\n TransactionErrorsCount: number;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_IFRAME_BOT, DOSESPOT_PATIENT_SYNC_BOT } from './common';\n\nexport interface DoseSpotIFrameOptions {\n readonly patientId?: string;\n readonly onPatientSyncSuccess?: () => void;\n readonly onIframeSuccess?: (url: string) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nexport function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined {\n const medplum = useMedplum();\n const { patientId, onPatientSyncSuccess, onIframeSuccess, onError } = options;\n const initializingRef = useRef<boolean>(false);\n const [iframeUrl, setIframeUrl] = useState<string | undefined>(undefined);\n\n const onPatientSyncSuccessRef = useRef(onPatientSyncSuccess);\n onPatientSyncSuccessRef.current = onPatientSyncSuccess;\n\n const onIframeSuccessRef = useRef(onIframeSuccess);\n onIframeSuccessRef.current = onIframeSuccess;\n\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n const initPage = useCallback(async () => {\n if (initializingRef.current) {\n return;\n }\n\n initializingRef.current = true;\n try {\n if (patientId) {\n await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT, { patientId });\n onPatientSyncSuccessRef.current?.();\n }\n const result = await medplum.executeBot(DOSESPOT_IFRAME_BOT, { patientId });\n if (result.url) {\n setIframeUrl(result.url);\n onIframeSuccessRef.current?.(result.url);\n }\n } catch (err: unknown) {\n onErrorRef.current?.(err);\n }\n }, [medplum, patientId]);\n\n useEffect(() => {\n initPage().catch(console.error);\n }, [initPage]);\n\n return iframeUrl;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_NOTIFICATION_COUNTS_BOT, DoseSpotNotificationCountsResponse } from './common';\n\nexport interface DoseSpotNotificationsOptions {\n readonly refreshIntervalMilliseconds?: number;\n readonly onChange?: (count: number) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nconst DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 10000;\n\nexport function useDoseSpotNotifications(options?: DoseSpotNotificationsOptions): number | undefined {\n const medplum = useMedplum();\n const { onChange, onError } = options ?? {};\n const hasDoseSpot = medplum.getProjectMembership()?.identifier?.some((i) => i.system?.includes('dosespot'));\n const refreshInterval = options?.refreshIntervalMilliseconds ?? DEFAULT_REFRESH_INTERVAL_MILLISECONDS;\n const timerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n const [unreadCount, setUnreadCount] = useState<number | undefined>(undefined);\n\n const stopTimer = useCallback(() => {\n const timerId = timerRef.current;\n if (timerId) {\n clearInterval(timerId);\n }\n }, []);\n\n const updateCount = useCallback(async () => {\n try {\n const result = (await medplum.executeBot(\n DOSESPOT_NOTIFICATION_COUNTS_BOT,\n {}\n )) as DoseSpotNotificationCountsResponse;\n\n let newCount = 0;\n if (result.PendingPrescriptionsCount) {\n newCount += result.PendingPrescriptionsCount;\n }\n if (result.PendingRxChangeCount) {\n newCount += result.PendingRxChangeCount;\n }\n if (result.RefillRequestsCount) {\n newCount += result.RefillRequestsCount;\n }\n if (result.TransactionErrorsCount) {\n newCount += result.TransactionErrorsCount;\n }\n if (newCount !== unreadCount) {\n setUnreadCount(newCount);\n onChange?.(newCount);\n }\n } catch (err: unknown) {\n onError?.(err);\n stopTimer();\n }\n }, [medplum, unreadCount, onChange, onError, stopTimer]);\n\n const startTimer = useCallback(() => {\n timerRef.current = setInterval(() => {\n updateCount().catch(console.error);\n }, refreshInterval);\n }, [updateCount, refreshInterval]);\n\n useEffect(() => {\n // Start an interval timer to update the count every 5 seconds\n if (hasDoseSpot) {\n startTimer();\n }\n\n // Clear the interval timer when the component is unmounted\n return stopTimer;\n }, [hasDoseSpot, startTimer, stopTimer]);\n\n return unreadCount;\n}\n"],
|
|
5
|
-
"mappings": "wpBAAA,
|
|
6
|
-
"names": ["import_react_hooks", "import_react"]
|
|
3
|
+
"sources": ["../../src/index.ts", "../../src/common.ts", "../../src/useDoseSpotClinicFormulary.ts", "../../src/useDoseSpotIFrame.ts", "../../src/useDoseSpotNotifications.ts", "../../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nexport * from './common';\nexport * from './useDoseSpotClinicFormulary';\nexport * from './useDoseSpotIFrame';\nexport * from './useDoseSpotNotifications';\nexport * from './utils';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { Identifier } from '@medplum/fhirtypes';\n\nexport const MEDPLUM_BOT_SYSTEM = 'https://www.medplum.com/bots';\n\nexport const DOSESPOT_PATIENT_ID_SYSTEM = 'https://dosespot.com/patient-id';\n\nexport const DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM = 'https://dosespot.com/clinic-favorite-medication-id';\n\nexport const DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM = 'https://dosespot.com/dispensable-drug-id';\n\nexport const DOSESPOT_PATIENT_SYNC_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-patient-sync-bot' };\n\nexport const DOSESPOT_IFRAME_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-iframe-bot' };\n\nexport const DOSESPOT_ADD_FAVORITE_MEDICATION_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-add-favorite-medication-bot',\n};\n\nexport const DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-get-favorite-medications-bot',\n};\n\nexport const DOSESPOT_SEARCH_MEDICATIONS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-search-medication-bot',\n};\n\nexport const DOSESPOT_MEDICATION_HISTORY_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-medication-history-bot',\n};\n\nexport const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-prescriptions-sync-bot',\n};\n\nexport const DOSESPOT_NOTIFICATION_COUNTS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-notification-counts-bot',\n};\n\nexport interface DoseSpotNotificationCountsResponse {\n PendingPrescriptionsCount: number;\n PendingRxChangeCount: number;\n RefillRequestsCount: number;\n TransactionErrorsCount: number;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { isCodeableConcept, isCoding } from '@medplum/core';\nimport { CodeableConcept, Coding, MedicationKnowledge } from '@medplum/fhirtypes';\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useState } from 'react';\nimport { DOSESPOT_ADD_FAVORITE_MEDICATION_BOT, DOSESPOT_SEARCH_MEDICATIONS_BOT } from './common';\n\nexport interface DoseSpotClinicFormularyReturn {\n state: DoseSpotClinicFormularyState;\n /**\n * Search for DoseSpot Medications and returns array of temporary MedicationKnowledge objects that are not yet saved to the FHIR server\n */\n readonly searchMedications: (searchTerm: string) => Promise<CodeableConcept[]>;\n /**\n * Set the currently selected medication. Can be set as a CodeableConcept or a Coding, but state is always stored as a CodeableConcept\n */\n readonly setSelectedMedication: (medication: CodeableConcept | Coding | undefined) => void;\n /**\n * Set the directions for the currently selected medication\n */\n readonly setSelectedMedicationDirections: (directions: string | undefined) => void;\n /**\n * Save a DoseSpot Medication to the Clinic's favorites and returns the MedicationKnowledge object that was saved\n */\n readonly saveFavoriteMedication: () => Promise<MedicationKnowledge>;\n /**\n * Clear the state\n */\n readonly clear: () => void;\n}\n\nexport interface DoseSpotClinicFormularyState {\n selectedMedication: CodeableConcept | undefined;\n directions: string | undefined;\n}\n\nexport function useDoseSpotClinicFormulary(): DoseSpotClinicFormularyReturn {\n const [directions, privateSetDirections] = useState<string | undefined>(undefined);\n const [selectedMedication, privateSetSelectedMedication] = useState<CodeableConcept | undefined>(undefined);\n const medplum = useMedplum();\n\n const state: DoseSpotClinicFormularyState = { selectedMedication, directions };\n\n const saveFavoriteMedication = useCallback(async (): Promise<MedicationKnowledge> => {\n if (!selectedMedication) {\n throw new Error('Must select a medication before adding a favorite medication');\n }\n\n //Add the directions to the medicationKnowledge object\n const medicationKnowledgeWithDirections = {\n resourceType: 'MedicationKnowledge',\n code: { ...selectedMedication },\n administrationGuidelines: [\n {\n dosage: [\n {\n dosage: [\n {\n patientInstruction: directions || '',\n },\n ],\n type: {\n coding: [\n {\n system: 'https://dosespot.com/patient-instructions',\n },\n ],\n },\n },\n ],\n },\n ],\n };\n\n return medplum.executeBot(DOSESPOT_ADD_FAVORITE_MEDICATION_BOT, medicationKnowledgeWithDirections);\n }, [selectedMedication, directions, medplum]);\n\n const searchMedications = useCallback(\n async (searchTerm: string): Promise<CodeableConcept[]> => {\n return (await medplum.executeBot(DOSESPOT_SEARCH_MEDICATIONS_BOT, { name: searchTerm })) as CodeableConcept[];\n },\n [medplum]\n );\n\n const setSelectedMedicationDirections = (directions: string | undefined): void => {\n privateSetDirections(directions);\n };\n\n const setSelectedMedication = (medication: CodeableConcept | Coding | undefined): void => {\n let medicationToSet: CodeableConcept | undefined;\n if (isCodeableConcept(medication)) {\n medicationToSet = { ...medication };\n } else if (isCoding(medication)) {\n medicationToSet = {\n text: medication.display || '',\n coding: [medication],\n };\n }\n privateSetSelectedMedication(medicationToSet);\n };\n\n const clear = (): void => {\n privateSetSelectedMedication(undefined);\n privateSetDirections(undefined);\n };\n\n return {\n state,\n searchMedications,\n setSelectedMedication,\n setSelectedMedicationDirections,\n saveFavoriteMedication,\n clear,\n };\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_IFRAME_BOT, DOSESPOT_PATIENT_SYNC_BOT } from './common';\n\nexport interface DoseSpotIFrameOptions {\n readonly patientId?: string;\n readonly onPatientSyncSuccess?: () => void;\n readonly onIframeSuccess?: (url: string) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nexport function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined {\n const medplum = useMedplum();\n const { patientId, onPatientSyncSuccess, onIframeSuccess, onError } = options;\n const initializingRef = useRef<boolean>(false);\n const [iframeUrl, setIframeUrl] = useState<string | undefined>(undefined);\n\n const onPatientSyncSuccessRef = useRef(onPatientSyncSuccess);\n onPatientSyncSuccessRef.current = onPatientSyncSuccess;\n\n const onIframeSuccessRef = useRef(onIframeSuccess);\n onIframeSuccessRef.current = onIframeSuccess;\n\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n const initPage = useCallback(async () => {\n if (initializingRef.current) {\n return;\n }\n\n initializingRef.current = true;\n try {\n if (patientId) {\n await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT, { patientId });\n onPatientSyncSuccessRef.current?.();\n }\n const result = await medplum.executeBot(DOSESPOT_IFRAME_BOT, { patientId });\n if (result.url) {\n setIframeUrl(result.url);\n onIframeSuccessRef.current?.(result.url);\n }\n } catch (err: unknown) {\n onErrorRef.current?.(err);\n }\n }, [medplum, patientId]);\n\n useEffect(() => {\n initPage().catch(console.error);\n }, [initPage]);\n\n return iframeUrl;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_NOTIFICATION_COUNTS_BOT, DoseSpotNotificationCountsResponse } from './common';\n\nexport interface DoseSpotNotificationsOptions {\n readonly refreshIntervalMilliseconds?: number;\n readonly onChange?: (count: number) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nconst DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 10000;\n\nexport function useDoseSpotNotifications(options?: DoseSpotNotificationsOptions): number | undefined {\n const medplum = useMedplum();\n const { onChange, onError } = options ?? {};\n const hasDoseSpot = medplum.getProjectMembership()?.identifier?.some((i) => i.system?.includes('dosespot'));\n const refreshInterval = options?.refreshIntervalMilliseconds ?? DEFAULT_REFRESH_INTERVAL_MILLISECONDS;\n const timerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n const [unreadCount, setUnreadCount] = useState<number | undefined>(undefined);\n\n const stopTimer = useCallback(() => {\n const timerId = timerRef.current;\n if (timerId) {\n clearInterval(timerId);\n }\n }, []);\n\n const updateCount = useCallback(async () => {\n try {\n const result = (await medplum.executeBot(\n DOSESPOT_NOTIFICATION_COUNTS_BOT,\n {}\n )) as DoseSpotNotificationCountsResponse;\n\n let newCount = 0;\n if (result.PendingPrescriptionsCount) {\n newCount += result.PendingPrescriptionsCount;\n }\n if (result.PendingRxChangeCount) {\n newCount += result.PendingRxChangeCount;\n }\n if (result.RefillRequestsCount) {\n newCount += result.RefillRequestsCount;\n }\n if (result.TransactionErrorsCount) {\n newCount += result.TransactionErrorsCount;\n }\n if (newCount !== unreadCount) {\n setUnreadCount(newCount);\n onChange?.(newCount);\n }\n } catch (err: unknown) {\n onError?.(err);\n stopTimer();\n }\n }, [medplum, unreadCount, onChange, onError, stopTimer]);\n\n const startTimer = useCallback(() => {\n timerRef.current = setInterval(() => {\n updateCount().catch(console.error);\n }, refreshInterval);\n }, [updateCount, refreshInterval]);\n\n useEffect(() => {\n // Start an interval timer to update the count every 5 seconds\n if (hasDoseSpot) {\n startTimer();\n }\n\n // Clear the interval timer when the component is unmounted\n return stopTimer;\n }, [hasDoseSpot, startTimer, stopTimer]);\n\n return unreadCount;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { MedicationKnowledge } from '@medplum/fhirtypes';\n\nexport const getMedicationName = (medication: MedicationKnowledge | undefined): string => {\n return medication?.code?.text || '';\n};\n"],
|
|
5
|
+
"mappings": "wpBAAA,wiCCIO,IAAM,mBAAqB,+BAErB,2BAA6B,kCAE7B,mCAAqC,qDAErC,oCAAsC,2CAEtC,0BAAwC,CAAE,OAAQ,mBAAoB,MAAO,2BAA4B,EAEzG,oBAAkC,CAAE,OAAQ,mBAAoB,MAAO,qBAAsB,EAE7F,qCAAmD,CAC9D,OAAQ,mBACR,MAAO,sCACT,EAEa,sCAAoD,CAC/D,OAAQ,mBACR,MAAO,uCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,gCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,iCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,iCACT,EAEa,iCAA+C,CAC1D,OAAQ,mBACR,MAAO,kCACT,EC1CA,gBAA4C,yBAE5C,mBAA2B,gCAC3B,aAAsC,iBAgC/B,SAAS,4BAA4D,CAC1E,GAAM,CAAC,WAAY,oBAAoB,KAAI,uBAA6B,MAAS,EAC3E,CAAC,mBAAoB,4BAA4B,KAAI,uBAAsC,MAAS,EACpG,WAAU,+BAAW,EAErB,MAAsC,CAAE,mBAAoB,UAAW,EAEvE,0BAAyB,0BAAY,SAA0C,CACnF,GAAI,CAAC,mBACH,MAAM,IAAI,MAAM,8DAA8D,EAIhF,IAAM,kCAAoC,CAC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a,2BAAY,IAAM,CACnC,SAAS,QAAU,YAAY,IAAM,CACnC,YAAY,EAAE,MAAM,QAAQ,KAAK,CACnC,EAAG,eAAe,CACpB,EAAG,CAAC,YAAa,eAAe,CAAC,EAEjC,kCAAU,KAEJ,aACF,WAAW,EAIN,WACN,CAAC,YAAa,WAAY,SAAS,CAAC,EAEhC,WACT,CCxEO,IAAM,kBAAqB,YACzB,YAAY,MAAM,MAAQ",
|
|
6
|
+
"names": ["directions", "import_react_hooks", "import_react", "import_react_hooks", "import_react"]
|
|
7
7
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { CodeableConcept } from '@medplum/fhirtypes';
|
|
2
|
+
import { Coding } from '@medplum/fhirtypes';
|
|
1
3
|
import { Identifier } from '@medplum/fhirtypes';
|
|
4
|
+
import { MedicationKnowledge } from '@medplum/fhirtypes';
|
|
5
|
+
|
|
6
|
+
export declare const DOSESPOT_ADD_FAVORITE_MEDICATION_BOT: Identifier;
|
|
7
|
+
|
|
8
|
+
export declare const DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM = "https://dosespot.com/clinic-favorite-medication-id";
|
|
9
|
+
|
|
10
|
+
export declare const DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM = "https://dosespot.com/dispensable-drug-id";
|
|
11
|
+
|
|
12
|
+
export declare const DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT: Identifier;
|
|
2
13
|
|
|
3
14
|
export declare const DOSESPOT_IFRAME_BOT: Identifier;
|
|
4
15
|
|
|
@@ -12,6 +23,37 @@ export declare const DOSESPOT_PATIENT_SYNC_BOT: Identifier;
|
|
|
12
23
|
|
|
13
24
|
export declare const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier;
|
|
14
25
|
|
|
26
|
+
export declare const DOSESPOT_SEARCH_MEDICATIONS_BOT: Identifier;
|
|
27
|
+
|
|
28
|
+
export declare interface DoseSpotClinicFormularyReturn {
|
|
29
|
+
state: DoseSpotClinicFormularyState;
|
|
30
|
+
/**
|
|
31
|
+
* Search for DoseSpot Medications and returns array of temporary MedicationKnowledge objects that are not yet saved to the FHIR server
|
|
32
|
+
*/
|
|
33
|
+
readonly searchMedications: (searchTerm: string) => Promise<CodeableConcept[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Set the currently selected medication. Can be set as a CodeableConcept or a Coding, but state is always stored as a CodeableConcept
|
|
36
|
+
*/
|
|
37
|
+
readonly setSelectedMedication: (medication: CodeableConcept | Coding | undefined) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Set the directions for the currently selected medication
|
|
40
|
+
*/
|
|
41
|
+
readonly setSelectedMedicationDirections: (directions: string | undefined) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Save a DoseSpot Medication to the Clinic's favorites and returns the MedicationKnowledge object that was saved
|
|
44
|
+
*/
|
|
45
|
+
readonly saveFavoriteMedication: () => Promise<MedicationKnowledge>;
|
|
46
|
+
/**
|
|
47
|
+
* Clear the state
|
|
48
|
+
*/
|
|
49
|
+
readonly clear: () => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export declare interface DoseSpotClinicFormularyState {
|
|
53
|
+
selectedMedication: CodeableConcept | undefined;
|
|
54
|
+
directions: string | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
15
57
|
export declare interface DoseSpotIFrameOptions {
|
|
16
58
|
readonly patientId?: string;
|
|
17
59
|
readonly onPatientSyncSuccess?: () => void;
|
|
@@ -32,8 +74,12 @@ export declare interface DoseSpotNotificationsOptions {
|
|
|
32
74
|
readonly onError?: (err: unknown) => void;
|
|
33
75
|
}
|
|
34
76
|
|
|
77
|
+
export declare const getMedicationName: (medication: MedicationKnowledge | undefined) => string;
|
|
78
|
+
|
|
35
79
|
export declare const MEDPLUM_BOT_SYSTEM = "https://www.medplum.com/bots";
|
|
36
80
|
|
|
81
|
+
export declare function useDoseSpotClinicFormulary(): DoseSpotClinicFormularyReturn;
|
|
82
|
+
|
|
37
83
|
export declare function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined;
|
|
38
84
|
|
|
39
85
|
export declare function useDoseSpotNotifications(options?: DoseSpotNotificationsOptions): number | undefined;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { CodeableConcept } from '@medplum/fhirtypes';
|
|
2
|
+
import { Coding } from '@medplum/fhirtypes';
|
|
1
3
|
import { Identifier } from '@medplum/fhirtypes';
|
|
4
|
+
import { MedicationKnowledge } from '@medplum/fhirtypes';
|
|
5
|
+
|
|
6
|
+
export declare const DOSESPOT_ADD_FAVORITE_MEDICATION_BOT: Identifier;
|
|
7
|
+
|
|
8
|
+
export declare const DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM = "https://dosespot.com/clinic-favorite-medication-id";
|
|
9
|
+
|
|
10
|
+
export declare const DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM = "https://dosespot.com/dispensable-drug-id";
|
|
11
|
+
|
|
12
|
+
export declare const DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT: Identifier;
|
|
2
13
|
|
|
3
14
|
export declare const DOSESPOT_IFRAME_BOT: Identifier;
|
|
4
15
|
|
|
@@ -12,6 +23,37 @@ export declare const DOSESPOT_PATIENT_SYNC_BOT: Identifier;
|
|
|
12
23
|
|
|
13
24
|
export declare const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier;
|
|
14
25
|
|
|
26
|
+
export declare const DOSESPOT_SEARCH_MEDICATIONS_BOT: Identifier;
|
|
27
|
+
|
|
28
|
+
export declare interface DoseSpotClinicFormularyReturn {
|
|
29
|
+
state: DoseSpotClinicFormularyState;
|
|
30
|
+
/**
|
|
31
|
+
* Search for DoseSpot Medications and returns array of temporary MedicationKnowledge objects that are not yet saved to the FHIR server
|
|
32
|
+
*/
|
|
33
|
+
readonly searchMedications: (searchTerm: string) => Promise<CodeableConcept[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Set the currently selected medication. Can be set as a CodeableConcept or a Coding, but state is always stored as a CodeableConcept
|
|
36
|
+
*/
|
|
37
|
+
readonly setSelectedMedication: (medication: CodeableConcept | Coding | undefined) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Set the directions for the currently selected medication
|
|
40
|
+
*/
|
|
41
|
+
readonly setSelectedMedicationDirections: (directions: string | undefined) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Save a DoseSpot Medication to the Clinic's favorites and returns the MedicationKnowledge object that was saved
|
|
44
|
+
*/
|
|
45
|
+
readonly saveFavoriteMedication: () => Promise<MedicationKnowledge>;
|
|
46
|
+
/**
|
|
47
|
+
* Clear the state
|
|
48
|
+
*/
|
|
49
|
+
readonly clear: () => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export declare interface DoseSpotClinicFormularyState {
|
|
53
|
+
selectedMedication: CodeableConcept | undefined;
|
|
54
|
+
directions: string | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
15
57
|
export declare interface DoseSpotIFrameOptions {
|
|
16
58
|
readonly patientId?: string;
|
|
17
59
|
readonly onPatientSyncSuccess?: () => void;
|
|
@@ -32,8 +74,12 @@ export declare interface DoseSpotNotificationsOptions {
|
|
|
32
74
|
readonly onError?: (err: unknown) => void;
|
|
33
75
|
}
|
|
34
76
|
|
|
77
|
+
export declare const getMedicationName: (medication: MedicationKnowledge | undefined) => string;
|
|
78
|
+
|
|
35
79
|
export declare const MEDPLUM_BOT_SYSTEM = "https://www.medplum.com/bots";
|
|
36
80
|
|
|
81
|
+
export declare function useDoseSpotClinicFormulary(): DoseSpotClinicFormularyReturn;
|
|
82
|
+
|
|
37
83
|
export declare function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined;
|
|
38
84
|
|
|
39
85
|
export declare function useDoseSpotNotifications(options?: DoseSpotNotificationsOptions): number | undefined;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var MEDPLUM_BOT_SYSTEM="https://www.medplum.com/bots",DOSESPOT_PATIENT_ID_SYSTEM="https://dosespot.com/patient-id",DOSESPOT_PATIENT_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-patient-sync-bot"},DOSESPOT_IFRAME_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-iframe-bot"},DOSESPOT_MEDICATION_HISTORY_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-medication-history-bot"},DOSESPOT_PRESCRIPTIONS_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-prescriptions-sync-bot"},DOSESPOT_NOTIFICATION_COUNTS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-notification-counts-bot"};import{useMedplum}from"@medplum/react-hooks";import{useCallback,useEffect,useRef,useState}from"react";function useDoseSpotIFrame(options){let medplum=
|
|
1
|
+
var MEDPLUM_BOT_SYSTEM="https://www.medplum.com/bots",DOSESPOT_PATIENT_ID_SYSTEM="https://dosespot.com/patient-id",DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM="https://dosespot.com/clinic-favorite-medication-id",DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM="https://dosespot.com/dispensable-drug-id",DOSESPOT_PATIENT_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-patient-sync-bot"},DOSESPOT_IFRAME_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-iframe-bot"},DOSESPOT_ADD_FAVORITE_MEDICATION_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-add-favorite-medication-bot"},DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-get-favorite-medications-bot"},DOSESPOT_SEARCH_MEDICATIONS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-search-medication-bot"},DOSESPOT_MEDICATION_HISTORY_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-medication-history-bot"},DOSESPOT_PRESCRIPTIONS_SYNC_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-prescriptions-sync-bot"},DOSESPOT_NOTIFICATION_COUNTS_BOT={system:MEDPLUM_BOT_SYSTEM,value:"dosespot-notification-counts-bot"};import{isCodeableConcept,isCoding}from"@medplum/core";import{useMedplum}from"@medplum/react-hooks";import{useCallback,useState}from"react";function useDoseSpotClinicFormulary(){let[directions,privateSetDirections]=useState(void 0),[selectedMedication,privateSetSelectedMedication]=useState(void 0),medplum=useMedplum(),state={selectedMedication,directions},saveFavoriteMedication=useCallback(async()=>{if(!selectedMedication)throw new Error("Must select a medication before adding a favorite medication");let medicationKnowledgeWithDirections={resourceType:"MedicationKnowledge",code:{...selectedMedication},administrationGuidelines:[{dosage:[{dosage:[{patientInstruction:directions||""}],type:{coding:[{system:"https://dosespot.com/patient-instructions"}]}}]}]};return medplum.executeBot(DOSESPOT_ADD_FAVORITE_MEDICATION_BOT,medicationKnowledgeWithDirections)},[selectedMedication,directions,medplum]),searchMedications=useCallback(async searchTerm=>await medplum.executeBot(DOSESPOT_SEARCH_MEDICATIONS_BOT,{name:searchTerm}),[medplum]);return{state,searchMedications,setSelectedMedication:medication=>{let medicationToSet;isCodeableConcept(medication)?medicationToSet={...medication}:isCoding(medication)&&(medicationToSet={text:medication.display||"",coding:[medication]}),privateSetSelectedMedication(medicationToSet)},setSelectedMedicationDirections:directions2=>{privateSetDirections(directions2)},saveFavoriteMedication,clear:()=>{privateSetSelectedMedication(void 0),privateSetDirections(void 0)}}}import{useMedplum as useMedplum2}from"@medplum/react-hooks";import{useCallback as useCallback2,useEffect,useRef,useState as useState2}from"react";function useDoseSpotIFrame(options){let medplum=useMedplum2(),{patientId,onPatientSyncSuccess,onIframeSuccess,onError}=options,initializingRef=useRef(!1),[iframeUrl,setIframeUrl]=useState2(void 0),onPatientSyncSuccessRef=useRef(onPatientSyncSuccess);onPatientSyncSuccessRef.current=onPatientSyncSuccess;let onIframeSuccessRef=useRef(onIframeSuccess);onIframeSuccessRef.current=onIframeSuccess;let onErrorRef=useRef(onError);onErrorRef.current=onError;let initPage=useCallback2(async()=>{if(!initializingRef.current){initializingRef.current=!0;try{patientId&&(await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT,{patientId}),onPatientSyncSuccessRef.current?.());let result=await medplum.executeBot(DOSESPOT_IFRAME_BOT,{patientId});result.url&&(setIframeUrl(result.url),onIframeSuccessRef.current?.(result.url))}catch(err){onErrorRef.current?.(err)}}},[medplum,patientId]);return useEffect(()=>{initPage().catch(console.error)},[initPage]),iframeUrl}import{useMedplum as useMedplum3}from"@medplum/react-hooks";import{useCallback as useCallback3,useEffect as useEffect2,useRef as useRef2,useState as useState3}from"react";var DEFAULT_REFRESH_INTERVAL_MILLISECONDS=1e4;function useDoseSpotNotifications(options){let medplum=useMedplum3(),{onChange,onError}=options??{},hasDoseSpot=medplum.getProjectMembership()?.identifier?.some(i=>i.system?.includes("dosespot")),refreshInterval=options?.refreshIntervalMilliseconds??DEFAULT_REFRESH_INTERVAL_MILLISECONDS,timerRef=useRef2(void 0),[unreadCount,setUnreadCount]=useState3(void 0),stopTimer=useCallback3(()=>{let timerId=timerRef.current;timerId&&clearInterval(timerId)},[]),updateCount=useCallback3(async()=>{try{let result=await medplum.executeBot(DOSESPOT_NOTIFICATION_COUNTS_BOT,{}),newCount=0;result.PendingPrescriptionsCount&&(newCount+=result.PendingPrescriptionsCount),result.PendingRxChangeCount&&(newCount+=result.PendingRxChangeCount),result.RefillRequestsCount&&(newCount+=result.RefillRequestsCount),result.TransactionErrorsCount&&(newCount+=result.TransactionErrorsCount),newCount!==unreadCount&&(setUnreadCount(newCount),onChange?.(newCount))}catch(err){onError?.(err),stopTimer()}},[medplum,unreadCount,onChange,onError,stopTimer]),startTimer=useCallback3(()=>{timerRef.current=setInterval(()=>{updateCount().catch(console.error)},refreshInterval)},[updateCount,refreshInterval]);return useEffect2(()=>(hasDoseSpot&&startTimer(),stopTimer),[hasDoseSpot,startTimer,stopTimer]),unreadCount}var getMedicationName=medication=>medication?.code?.text||"";export{DOSESPOT_ADD_FAVORITE_MEDICATION_BOT,DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM,DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM,DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT,DOSESPOT_IFRAME_BOT,DOSESPOT_MEDICATION_HISTORY_BOT,DOSESPOT_NOTIFICATION_COUNTS_BOT,DOSESPOT_PATIENT_ID_SYSTEM,DOSESPOT_PATIENT_SYNC_BOT,DOSESPOT_PRESCRIPTIONS_SYNC_BOT,DOSESPOT_SEARCH_MEDICATIONS_BOT,MEDPLUM_BOT_SYSTEM,getMedicationName,useDoseSpotClinicFormulary,useDoseSpotIFrame,useDoseSpotNotifications};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/common.ts", "../../src/useDoseSpotIFrame.ts", "../../src/useDoseSpotNotifications.ts"],
|
|
4
|
-
"sourcesContent": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { Identifier } from '@medplum/fhirtypes';\n\nexport const MEDPLUM_BOT_SYSTEM = 'https://www.medplum.com/bots';\n\nexport const DOSESPOT_PATIENT_ID_SYSTEM = 'https://dosespot.com/patient-id';\n\nexport const DOSESPOT_PATIENT_SYNC_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-patient-sync-bot' };\n\nexport const DOSESPOT_IFRAME_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-iframe-bot' };\n\nexport const DOSESPOT_MEDICATION_HISTORY_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-medication-history-bot',\n};\n\nexport const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-prescriptions-sync-bot',\n};\n\nexport const DOSESPOT_NOTIFICATION_COUNTS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-notification-counts-bot',\n};\n\nexport interface DoseSpotNotificationCountsResponse {\n PendingPrescriptionsCount: number;\n PendingRxChangeCount: number;\n RefillRequestsCount: number;\n TransactionErrorsCount: number;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_IFRAME_BOT, DOSESPOT_PATIENT_SYNC_BOT } from './common';\n\nexport interface DoseSpotIFrameOptions {\n readonly patientId?: string;\n readonly onPatientSyncSuccess?: () => void;\n readonly onIframeSuccess?: (url: string) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nexport function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined {\n const medplum = useMedplum();\n const { patientId, onPatientSyncSuccess, onIframeSuccess, onError } = options;\n const initializingRef = useRef<boolean>(false);\n const [iframeUrl, setIframeUrl] = useState<string | undefined>(undefined);\n\n const onPatientSyncSuccessRef = useRef(onPatientSyncSuccess);\n onPatientSyncSuccessRef.current = onPatientSyncSuccess;\n\n const onIframeSuccessRef = useRef(onIframeSuccess);\n onIframeSuccessRef.current = onIframeSuccess;\n\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n const initPage = useCallback(async () => {\n if (initializingRef.current) {\n return;\n }\n\n initializingRef.current = true;\n try {\n if (patientId) {\n await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT, { patientId });\n onPatientSyncSuccessRef.current?.();\n }\n const result = await medplum.executeBot(DOSESPOT_IFRAME_BOT, { patientId });\n if (result.url) {\n setIframeUrl(result.url);\n onIframeSuccessRef.current?.(result.url);\n }\n } catch (err: unknown) {\n onErrorRef.current?.(err);\n }\n }, [medplum, patientId]);\n\n useEffect(() => {\n initPage().catch(console.error);\n }, [initPage]);\n\n return iframeUrl;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_NOTIFICATION_COUNTS_BOT, DoseSpotNotificationCountsResponse } from './common';\n\nexport interface DoseSpotNotificationsOptions {\n readonly refreshIntervalMilliseconds?: number;\n readonly onChange?: (count: number) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nconst DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 10000;\n\nexport function useDoseSpotNotifications(options?: DoseSpotNotificationsOptions): number | undefined {\n const medplum = useMedplum();\n const { onChange, onError } = options ?? {};\n const hasDoseSpot = medplum.getProjectMembership()?.identifier?.some((i) => i.system?.includes('dosespot'));\n const refreshInterval = options?.refreshIntervalMilliseconds ?? DEFAULT_REFRESH_INTERVAL_MILLISECONDS;\n const timerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n const [unreadCount, setUnreadCount] = useState<number | undefined>(undefined);\n\n const stopTimer = useCallback(() => {\n const timerId = timerRef.current;\n if (timerId) {\n clearInterval(timerId);\n }\n }, []);\n\n const updateCount = useCallback(async () => {\n try {\n const result = (await medplum.executeBot(\n DOSESPOT_NOTIFICATION_COUNTS_BOT,\n {}\n )) as DoseSpotNotificationCountsResponse;\n\n let newCount = 0;\n if (result.PendingPrescriptionsCount) {\n newCount += result.PendingPrescriptionsCount;\n }\n if (result.PendingRxChangeCount) {\n newCount += result.PendingRxChangeCount;\n }\n if (result.RefillRequestsCount) {\n newCount += result.RefillRequestsCount;\n }\n if (result.TransactionErrorsCount) {\n newCount += result.TransactionErrorsCount;\n }\n if (newCount !== unreadCount) {\n setUnreadCount(newCount);\n onChange?.(newCount);\n }\n } catch (err: unknown) {\n onError?.(err);\n stopTimer();\n }\n }, [medplum, unreadCount, onChange, onError, stopTimer]);\n\n const startTimer = useCallback(() => {\n timerRef.current = setInterval(() => {\n updateCount().catch(console.error);\n }, refreshInterval);\n }, [updateCount, refreshInterval]);\n\n useEffect(() => {\n // Start an interval timer to update the count every 5 seconds\n if (hasDoseSpot) {\n startTimer();\n }\n\n // Clear the interval timer when the component is unmounted\n return stopTimer;\n }, [hasDoseSpot, startTimer, stopTimer]);\n\n return unreadCount;\n}\n"],
|
|
5
|
-
"mappings": "AAIO,IAAM,mBAAqB,+BAErB,2BAA6B,kCAE7B,0BAAwC,CAAE,OAAQ,mBAAoB,MAAO,2BAA4B,EAEzG,oBAAkC,CAAE,OAAQ,mBAAoB,MAAO,qBAAsB,EAE7F,gCAA8C,CACzD,OAAQ,mBACR,MAAO,iCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,iCACT,EAEa,iCAA+C,CAC1D,OAAQ,mBACR,MAAO,kCACT,
|
|
6
|
-
"names": ["useMedplum", "useCallback", "useEffect", "useRef", "useState", "useMedplum", "useRef", "useState", "useCallback", "useEffect"]
|
|
3
|
+
"sources": ["../../src/common.ts", "../../src/useDoseSpotClinicFormulary.ts", "../../src/useDoseSpotIFrame.ts", "../../src/useDoseSpotNotifications.ts", "../../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { Identifier } from '@medplum/fhirtypes';\n\nexport const MEDPLUM_BOT_SYSTEM = 'https://www.medplum.com/bots';\n\nexport const DOSESPOT_PATIENT_ID_SYSTEM = 'https://dosespot.com/patient-id';\n\nexport const DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM = 'https://dosespot.com/clinic-favorite-medication-id';\n\nexport const DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM = 'https://dosespot.com/dispensable-drug-id';\n\nexport const DOSESPOT_PATIENT_SYNC_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-patient-sync-bot' };\n\nexport const DOSESPOT_IFRAME_BOT: Identifier = { system: MEDPLUM_BOT_SYSTEM, value: 'dosespot-iframe-bot' };\n\nexport const DOSESPOT_ADD_FAVORITE_MEDICATION_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-add-favorite-medication-bot',\n};\n\nexport const DOSESPOT_GET_FAVORITE_MEDICATIONS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-get-favorite-medications-bot',\n};\n\nexport const DOSESPOT_SEARCH_MEDICATIONS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-search-medication-bot',\n};\n\nexport const DOSESPOT_MEDICATION_HISTORY_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-medication-history-bot',\n};\n\nexport const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-prescriptions-sync-bot',\n};\n\nexport const DOSESPOT_NOTIFICATION_COUNTS_BOT: Identifier = {\n system: MEDPLUM_BOT_SYSTEM,\n value: 'dosespot-notification-counts-bot',\n};\n\nexport interface DoseSpotNotificationCountsResponse {\n PendingPrescriptionsCount: number;\n PendingRxChangeCount: number;\n RefillRequestsCount: number;\n TransactionErrorsCount: number;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { isCodeableConcept, isCoding } from '@medplum/core';\nimport { CodeableConcept, Coding, MedicationKnowledge } from '@medplum/fhirtypes';\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useState } from 'react';\nimport { DOSESPOT_ADD_FAVORITE_MEDICATION_BOT, DOSESPOT_SEARCH_MEDICATIONS_BOT } from './common';\n\nexport interface DoseSpotClinicFormularyReturn {\n state: DoseSpotClinicFormularyState;\n /**\n * Search for DoseSpot Medications and returns array of temporary MedicationKnowledge objects that are not yet saved to the FHIR server\n */\n readonly searchMedications: (searchTerm: string) => Promise<CodeableConcept[]>;\n /**\n * Set the currently selected medication. Can be set as a CodeableConcept or a Coding, but state is always stored as a CodeableConcept\n */\n readonly setSelectedMedication: (medication: CodeableConcept | Coding | undefined) => void;\n /**\n * Set the directions for the currently selected medication\n */\n readonly setSelectedMedicationDirections: (directions: string | undefined) => void;\n /**\n * Save a DoseSpot Medication to the Clinic's favorites and returns the MedicationKnowledge object that was saved\n */\n readonly saveFavoriteMedication: () => Promise<MedicationKnowledge>;\n /**\n * Clear the state\n */\n readonly clear: () => void;\n}\n\nexport interface DoseSpotClinicFormularyState {\n selectedMedication: CodeableConcept | undefined;\n directions: string | undefined;\n}\n\nexport function useDoseSpotClinicFormulary(): DoseSpotClinicFormularyReturn {\n const [directions, privateSetDirections] = useState<string | undefined>(undefined);\n const [selectedMedication, privateSetSelectedMedication] = useState<CodeableConcept | undefined>(undefined);\n const medplum = useMedplum();\n\n const state: DoseSpotClinicFormularyState = { selectedMedication, directions };\n\n const saveFavoriteMedication = useCallback(async (): Promise<MedicationKnowledge> => {\n if (!selectedMedication) {\n throw new Error('Must select a medication before adding a favorite medication');\n }\n\n //Add the directions to the medicationKnowledge object\n const medicationKnowledgeWithDirections = {\n resourceType: 'MedicationKnowledge',\n code: { ...selectedMedication },\n administrationGuidelines: [\n {\n dosage: [\n {\n dosage: [\n {\n patientInstruction: directions || '',\n },\n ],\n type: {\n coding: [\n {\n system: 'https://dosespot.com/patient-instructions',\n },\n ],\n },\n },\n ],\n },\n ],\n };\n\n return medplum.executeBot(DOSESPOT_ADD_FAVORITE_MEDICATION_BOT, medicationKnowledgeWithDirections);\n }, [selectedMedication, directions, medplum]);\n\n const searchMedications = useCallback(\n async (searchTerm: string): Promise<CodeableConcept[]> => {\n return (await medplum.executeBot(DOSESPOT_SEARCH_MEDICATIONS_BOT, { name: searchTerm })) as CodeableConcept[];\n },\n [medplum]\n );\n\n const setSelectedMedicationDirections = (directions: string | undefined): void => {\n privateSetDirections(directions);\n };\n\n const setSelectedMedication = (medication: CodeableConcept | Coding | undefined): void => {\n let medicationToSet: CodeableConcept | undefined;\n if (isCodeableConcept(medication)) {\n medicationToSet = { ...medication };\n } else if (isCoding(medication)) {\n medicationToSet = {\n text: medication.display || '',\n coding: [medication],\n };\n }\n privateSetSelectedMedication(medicationToSet);\n };\n\n const clear = (): void => {\n privateSetSelectedMedication(undefined);\n privateSetDirections(undefined);\n };\n\n return {\n state,\n searchMedications,\n setSelectedMedication,\n setSelectedMedicationDirections,\n saveFavoriteMedication,\n clear,\n };\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_IFRAME_BOT, DOSESPOT_PATIENT_SYNC_BOT } from './common';\n\nexport interface DoseSpotIFrameOptions {\n readonly patientId?: string;\n readonly onPatientSyncSuccess?: () => void;\n readonly onIframeSuccess?: (url: string) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nexport function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined {\n const medplum = useMedplum();\n const { patientId, onPatientSyncSuccess, onIframeSuccess, onError } = options;\n const initializingRef = useRef<boolean>(false);\n const [iframeUrl, setIframeUrl] = useState<string | undefined>(undefined);\n\n const onPatientSyncSuccessRef = useRef(onPatientSyncSuccess);\n onPatientSyncSuccessRef.current = onPatientSyncSuccess;\n\n const onIframeSuccessRef = useRef(onIframeSuccess);\n onIframeSuccessRef.current = onIframeSuccess;\n\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n\n const initPage = useCallback(async () => {\n if (initializingRef.current) {\n return;\n }\n\n initializingRef.current = true;\n try {\n if (patientId) {\n await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT, { patientId });\n onPatientSyncSuccessRef.current?.();\n }\n const result = await medplum.executeBot(DOSESPOT_IFRAME_BOT, { patientId });\n if (result.url) {\n setIframeUrl(result.url);\n onIframeSuccessRef.current?.(result.url);\n }\n } catch (err: unknown) {\n onErrorRef.current?.(err);\n }\n }, [medplum, patientId]);\n\n useEffect(() => {\n initPage().catch(console.error);\n }, [initPage]);\n\n return iframeUrl;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_NOTIFICATION_COUNTS_BOT, DoseSpotNotificationCountsResponse } from './common';\n\nexport interface DoseSpotNotificationsOptions {\n readonly refreshIntervalMilliseconds?: number;\n readonly onChange?: (count: number) => void;\n readonly onError?: (err: unknown) => void;\n}\n\nconst DEFAULT_REFRESH_INTERVAL_MILLISECONDS = 10000;\n\nexport function useDoseSpotNotifications(options?: DoseSpotNotificationsOptions): number | undefined {\n const medplum = useMedplum();\n const { onChange, onError } = options ?? {};\n const hasDoseSpot = medplum.getProjectMembership()?.identifier?.some((i) => i.system?.includes('dosespot'));\n const refreshInterval = options?.refreshIntervalMilliseconds ?? DEFAULT_REFRESH_INTERVAL_MILLISECONDS;\n const timerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n const [unreadCount, setUnreadCount] = useState<number | undefined>(undefined);\n\n const stopTimer = useCallback(() => {\n const timerId = timerRef.current;\n if (timerId) {\n clearInterval(timerId);\n }\n }, []);\n\n const updateCount = useCallback(async () => {\n try {\n const result = (await medplum.executeBot(\n DOSESPOT_NOTIFICATION_COUNTS_BOT,\n {}\n )) as DoseSpotNotificationCountsResponse;\n\n let newCount = 0;\n if (result.PendingPrescriptionsCount) {\n newCount += result.PendingPrescriptionsCount;\n }\n if (result.PendingRxChangeCount) {\n newCount += result.PendingRxChangeCount;\n }\n if (result.RefillRequestsCount) {\n newCount += result.RefillRequestsCount;\n }\n if (result.TransactionErrorsCount) {\n newCount += result.TransactionErrorsCount;\n }\n if (newCount !== unreadCount) {\n setUnreadCount(newCount);\n onChange?.(newCount);\n }\n } catch (err: unknown) {\n onError?.(err);\n stopTimer();\n }\n }, [medplum, unreadCount, onChange, onError, stopTimer]);\n\n const startTimer = useCallback(() => {\n timerRef.current = setInterval(() => {\n updateCount().catch(console.error);\n }, refreshInterval);\n }, [updateCount, refreshInterval]);\n\n useEffect(() => {\n // Start an interval timer to update the count every 5 seconds\n if (hasDoseSpot) {\n startTimer();\n }\n\n // Clear the interval timer when the component is unmounted\n return stopTimer;\n }, [hasDoseSpot, startTimer, stopTimer]);\n\n return unreadCount;\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport { MedicationKnowledge } from '@medplum/fhirtypes';\n\nexport const getMedicationName = (medication: MedicationKnowledge | undefined): string => {\n return medication?.code?.text || '';\n};\n"],
|
|
5
|
+
"mappings": "AAIO,IAAM,mBAAqB,+BAErB,2BAA6B,kCAE7B,mCAAqC,qDAErC,oCAAsC,2CAEtC,0BAAwC,CAAE,OAAQ,mBAAoB,MAAO,2BAA4B,EAEzG,oBAAkC,CAAE,OAAQ,mBAAoB,MAAO,qBAAsB,EAE7F,qCAAmD,CAC9D,OAAQ,mBACR,MAAO,sCACT,EAEa,sCAAoD,CAC/D,OAAQ,mBACR,MAAO,uCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,gCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,iCACT,EAEa,gCAA8C,CACzD,OAAQ,mBACR,MAAO,iCACT,EAEa,iCAA+C,CAC1D,OAAQ,mBACR,MAAO,kCACT,EC1CA,OAAS,kBAAmB,aAAgB,gBAE5C,OAAS,eAAkB,uBAC3B,OAAS,YAAa,aAAgB,QAgC/B,SAAS,4BAA4D,CAC1E,GAAM,CAAC,WAAY,oBAAoB,EAAI,SAA6B,MAAS,EAC3E,CAAC,mBAAoB,4BAA4B,EAAI,SAAsC,MAAS,EACpG,QAAU,WAAW,EAEr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,OAAO,sBACT,UAAY,OAAO,qBAEjB,OAAO,yBACT,UAAY,OAAO,wBAEjB,WAAa,cACf,eAAe,QAAQ,EACvB,WAAW,QAAQ,EAEvB,OAAS,IAAc,CACrB,UAAU,GAAG,EACb,UAAU,CACZ,CACF,EAAG,CAAC,QAAS,YAAa,SAAU,QAAS,SAAS,CAAC,EAEjD,WAAaA,aAAY,IAAM,CACnC,SAAS,QAAU,YAAY,IAAM,CACnC,YAAY,EAAE,MAAM,QAAQ,KAAK,CACnC,EAAG,eAAe,CACpB,EAAG,CAAC,YAAa,eAAe,CAAC,EAEjC,OAAAC,WAAU,KAEJ,aACF,WAAW,EAIN,WACN,CAAC,YAAa,WAAY,SAAS,CAAC,EAEhC,WACT,CCxEO,IAAM,kBAAqB,YACzB,YAAY,MAAM,MAAQ",
|
|
6
|
+
"names": ["directions", "useMedplum", "useCallback", "useState", "useMedplum", "useState", "useCallback", "useMedplum", "useCallback", "useEffect", "useRef", "useState", "useMedplum", "useRef", "useState", "useCallback", "useEffect"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medplum/dosespot-react",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.11",
|
|
4
4
|
"description": "Medplum DoseSpot React SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"medplum",
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"test:watch": "vitest watch"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@medplum/core": "4.3.
|
|
64
|
-
"@medplum/fhirtypes": "4.3.
|
|
65
|
-
"@medplum/mock": "4.3.
|
|
66
|
-
"@medplum/react": "4.3.
|
|
67
|
-
"@testing-library/jest-dom": "6.
|
|
63
|
+
"@medplum/core": "4.3.11",
|
|
64
|
+
"@medplum/fhirtypes": "4.3.11",
|
|
65
|
+
"@medplum/mock": "4.3.11",
|
|
66
|
+
"@medplum/react": "4.3.11",
|
|
67
|
+
"@testing-library/jest-dom": "6.7.0",
|
|
68
68
|
"@testing-library/react": "16.3.0",
|
|
69
|
-
"@types/node": "20.19.
|
|
70
|
-
"@types/react": "19.1.
|
|
69
|
+
"@types/node": "20.19.11",
|
|
70
|
+
"@types/react": "19.1.10",
|
|
71
71
|
"@types/react-dom": "19.1.7",
|
|
72
72
|
"@vitejs/plugin-react": "5.0.0",
|
|
73
73
|
"jsdom": "26.1.0",
|
|
@@ -76,9 +76,9 @@
|
|
|
76
76
|
"vitest": "3.2.4"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@medplum/core": "4.3.
|
|
80
|
-
"@medplum/fhirtypes": "4.3.
|
|
81
|
-
"@medplum/react-hooks": "4.3.
|
|
79
|
+
"@medplum/core": "4.3.11",
|
|
80
|
+
"@medplum/fhirtypes": "4.3.11",
|
|
81
|
+
"@medplum/react-hooks": "4.3.11",
|
|
82
82
|
"react": "^18.0.0 || ^19.0.0"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|