{
  "version": 3,
  "sources": ["../../src/index.ts", "../../../dosespot-core/src/pharmacy-utils.ts", "../../src/useDoseSpotClinicFormulary.ts", "../../src/useDoseSpotIFrame.ts", "../../src/useDoseSpotNotifications.ts", "../../src/useDoseSpotPatientPharmacy.ts", "../../src/utils.ts", "../../src/useDoseSpotPharmacySearch.ts", "../../src/useDoseSpotSelfEnrollment.ts"],
  "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 './useDoseSpotPatientPharmacy';\nexport * from './useDoseSpotPharmacySearch';\nexport * from './useDoseSpotSelfEnrollment';\nexport * from './utils';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Identifier } from '@medplum/fhirtypes';\n\n// DoseSpot-specific pharmacy preference type system\nexport const DOSESPOT_PHARMACY_PREFERENCE_TYPE_SYSTEM = 'https://dosespot.com/pharmacy-preference-type';\n\n// Re-export generic pharmacy utilities from @medplum/core\nexport {\n  addPreferredPharmacyToPatient,\n  createPreferredPharmacyExtension,\n  getPreferredPharmaciesFromPatient,\n  isAddPharmacyResponse,\n  isOrganizationArray,\n  PATIENT_PREFERRED_PHARMACY_URL,\n  PHARMACY_PREFERENCE_TYPE_SYSTEM,\n  PHARMACY_TYPE_PREFERRED,\n  PHARMACY_TYPE_PRIMARY,\n  removePreferredPharmacyFromPatient,\n} from '@medplum/core';\nexport type { AddFavoriteParams, AddPharmacyResponse, PharmacySearchParams, PreferredPharmacy } from '@medplum/core';\n\n// Bot system\nexport const MEDPLUM_BOT_SYSTEM = 'https://www.medplum.com/bots';\n\n// DoseSpot identifier systems\nexport const DOSESPOT_PATIENT_ID_SYSTEM = 'https://dosespot.com/patient-id';\nexport const DOSESPOT_PHARMACY_ID_SYSTEM = 'https://dosespot.com/pharmacy-id';\nexport const DOSESPOT_CLINIC_FAVORITE_ID_SYSTEM = 'https://dosespot.com/clinic-favorite-medication-id';\nexport const DOSESPOT_DISPENSABLE_DRUG_ID_SYSTEM = 'https://dosespot.com/dispensable-drug-id';\n\n// Bot identifiers - Pharmacy\nexport const DOSESPOT_SEARCH_PHARMACY_BOT: Identifier = {\n  system: MEDPLUM_BOT_SYSTEM,\n  value: 'dosespot-search-pharmacy-bot',\n};\n\nexport const DOSESPOT_ADD_PATIENT_PHARMACY_BOT: Identifier = {\n  system: MEDPLUM_BOT_SYSTEM,\n  value: 'dosespot-add-patient-pharmacy-bot',\n};\n\n// Bot identifiers - Patient and Medications\nexport const DOSESPOT_PATIENT_SYNC_BOT: Identifier = {\n  system: MEDPLUM_BOT_SYSTEM,\n  value: 'dosespot-patient-sync-bot',\n};\n\nexport const DOSESPOT_IFRAME_BOT: Identifier = {\n  system: MEDPLUM_BOT_SYSTEM,\n  value: 'dosespot-iframe-bot',\n};\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\n// Bot identifiers - Enrollment\nexport const DOSESPOT_SELF_ENROLL_PRESCRIBER_BOT: Identifier = {\n  system: MEDPLUM_BOT_SYSTEM,\n  value: 'dosespot-self-enroll-prescriber-bot',\n};\n\n// DoseSpot notification response type\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 type { 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 type { ProjectMembership } from '@medplum/fhirtypes';\nimport type { MedicationIFrameOptions } from '@medplum/react-hooks';\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useEffect, useRef, useState } from 'react';\nimport { DOSESPOT_IFRAME_BOT, DOSESPOT_PATIENT_SYNC_BOT, DOSESPOT_SELF_ENROLL_PRESCRIBER_BOT } from './common';\nimport type { DoseSpotSelfEnrollmentResult } from './useDoseSpotSelfEnrollment';\n\nexport interface DoseSpotIFrameOptions extends MedicationIFrameOptions {\n  /**\n   * When true, automatically runs the self-enrollment bot before loading\n   * the iframe if the current user does not have a DoseSpot identifier\n   * on their ProjectMembership. Requires an active PractitionerRole with\n   * DoseSpot role type codes for the practitioner.\n   */\n  readonly selfEnroll?: boolean;\n  /** Called after self-enrollment completes successfully. */\n  readonly onSelfEnrollSuccess?: (result: DoseSpotSelfEnrollmentResult) => void;\n}\n\n/**\n * React hook that syncs a patient to DoseSpot and returns the iframe URL.\n *\n * Runs optional self-enrollment, then the patient-sync bot (when `patientId`\n * is set), then the iframe bot \u2014 aligned with {@link @medplum/react-hooks#useMedicationIFrame}\n * behavior plus DoseSpot-specific enrollment.\n *\n * @param options - Configuration and callback options.\n * @returns The DoseSpot iframe URL, or undefined while loading.\n */\nexport function useDoseSpotIFrame(options: DoseSpotIFrameOptions): string | undefined {\n  const medplum = useMedplum();\n  const { patientId, selfEnroll, onPatientSyncSuccess, onIframeSuccess, onSelfEnrollSuccess, onError } = options;\n  const [iframeUrl, setIframeUrl] = useState<string | undefined>(undefined);\n\n  const onPatientSyncSuccessRef = useRef(onPatientSyncSuccess);\n  const onIframeSuccessRef = useRef(onIframeSuccess);\n  const onSelfEnrollSuccessRef = useRef(onSelfEnrollSuccess);\n  const onErrorRef = useRef(onError);\n\n  useEffect(() => {\n    onPatientSyncSuccessRef.current = onPatientSyncSuccess;\n    onIframeSuccessRef.current = onIframeSuccess;\n    onSelfEnrollSuccessRef.current = onSelfEnrollSuccess;\n    onErrorRef.current = onError;\n  }, [onPatientSyncSuccess, onIframeSuccess, onSelfEnrollSuccess, onError]);\n\n  useEffect(() => {\n    let cancelled = false;\n\n    const run = async (): Promise<void> => {\n      if (selfEnroll && !hasDoseSpotIdentifier(medplum.getProjectMembership())) {\n        const enrollResult = (await medplum.executeBot(\n          DOSESPOT_SELF_ENROLL_PRESCRIBER_BOT,\n          {}\n        )) as DoseSpotSelfEnrollmentResult;\n        if (cancelled) {\n          return;\n        }\n        onSelfEnrollSuccessRef.current?.(enrollResult);\n      }\n\n      if (patientId) {\n        await medplum.executeBot(DOSESPOT_PATIENT_SYNC_BOT, { patientId });\n        if (cancelled) {\n          return;\n        }\n        onPatientSyncSuccessRef.current?.();\n      }\n      const result = await medplum.executeBot(DOSESPOT_IFRAME_BOT, { patientId });\n      if (cancelled) {\n        return;\n      }\n      if (result.url) {\n        setIframeUrl(result.url);\n        onIframeSuccessRef.current?.(result.url);\n      }\n    };\n\n    run().catch((err: unknown) => {\n      if (!cancelled) {\n        onErrorRef.current?.(err);\n      }\n    });\n\n    return (): void => {\n      cancelled = true;\n    };\n  }, [medplum, patientId, selfEnroll]);\n\n  return iframeUrl;\n}\n\n/**\n * Checks whether a ProjectMembership has a DoseSpot identifier.\n *\n * @param membership - The project membership to check.\n * @returns True when membership identifiers include a DoseSpot system URL.\n */\nfunction hasDoseSpotIdentifier(membership: ProjectMembership | undefined): boolean {\n  return !!membership?.identifier?.some((i) => i.system?.includes('dosespot'));\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 type { DoseSpotNotificationCountsResponse } from './common';\nimport { DOSESPOT_NOTIFICATION_COUNTS_BOT } 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 type { Organization } from '@medplum/fhirtypes';\nimport { useMedplum } from '@medplum/react-hooks';\nimport { useCallback, useState } from 'react';\nimport { DOSESPOT_ADD_PATIENT_PHARMACY_BOT, DOSESPOT_SEARCH_PHARMACY_BOT } from './common';\nimport { getPharmacyIdFromOrganization } from './utils';\n\n/**\n * Search parameters for pharmacy search.\n * See DoseSpot API section 3.13.2.\n */\nexport interface PharmacySearchParams {\n  /** Pharmacy's store name (min 3 chars) */\n  name?: string;\n  /** City (min 3 chars) */\n  city?: string;\n  /** State (min 3 chars) */\n  state?: string;\n  /** Zip code (min 3 chars) */\n  zip?: string;\n  /** Address (min 3 chars) */\n  address?: string;\n  /** Phone or fax number */\n  phoneOrFax?: string;\n  /** Collection of pharmacy specialties (numeric values) */\n  specialty?: number[];\n  /** National Council for Prescription Drug Programs Identifier */\n  ncpdpID?: string;\n  /** Page number of results (defaults to 1) */\n  pageNumber?: number;\n}\n\n/**\n * Response from adding a pharmacy to a patient's favorites.\n */\nexport interface AddPatientPharmacyResponse {\n  /** Whether the operation was successful */\n  success: boolean;\n  /** A message describing the result */\n  message: string;\n  /** The persisted Organization resource with ID */\n  organization?: Organization;\n}\n\n/**\n * State managed by the useDoseSpotPatientPharmacy hook.\n */\nexport interface DoseSpotPatientPharmacyState {\n  /** The currently selected pharmacy Organization */\n  selectedPharmacy: Organization | undefined;\n  /** Whether to set the selected pharmacy as the patient's primary pharmacy */\n  setAsPrimary: boolean;\n}\n\n/**\n * Return type for the useDoseSpotPatientPharmacy hook.\n */\nexport interface DoseSpotPatientPharmacyReturn {\n  /** Current state of the hook */\n  state: DoseSpotPatientPharmacyState;\n  /**\n   * Search for pharmacies in DoseSpot.\n   * Returns synthetic Organization resources (not persisted to DB).\n   */\n  readonly searchPharmacies: (params: PharmacySearchParams) => Promise<Organization[]>;\n  /**\n   * Set the currently selected pharmacy.\n   */\n  readonly setSelectedPharmacy: (pharmacy: Organization | undefined) => void;\n  /**\n   * Set whether to add the pharmacy as the patient's primary pharmacy.\n   */\n  readonly setAsPrimary: (primary: boolean) => void;\n  /**\n   * Add the selected pharmacy to the patient's favorites in DoseSpot.\n   * @param patientId - The Medplum Patient ID\n   */\n  readonly addFavoritePharmacy: (patientId: string) => Promise<AddPatientPharmacyResponse>;\n  /**\n   * Clear the state (selected pharmacy and setAsPrimary flag).\n   */\n  readonly clear: () => void;\n}\n\n/**\n * React hook for searching DoseSpot pharmacies and adding them to patient favorites.\n *\n * @returns The hook return object with state and methods.\n *\n * @example\n * ```tsx\n * function PharmacySearch({ patientId }: { patientId: string }) {\n *   const {\n *     state,\n *     searchPharmacies,\n *     setSelectedPharmacy,\n *     setAsPrimary,\n *     addFavoritePharmacy,\n *     clear\n *   } = useDoseSpotPatientPharmacy();\n *\n *   const handleSearch = async () => {\n *     const results = await searchPharmacies({ zip: '94118' });\n *     // Display results to user\n *   };\n *\n *   const handleAddFavorite = async () => {\n *     const result = await addFavoritePharmacy(patientId);\n *     if (result.success) {\n *       clear();\n *     }\n *   };\n * }\n * ```\n */\nexport function useDoseSpotPatientPharmacy(): DoseSpotPatientPharmacyReturn {\n  const [selectedPharmacy, privateSetSelectedPharmacy] = useState<Organization | undefined>(undefined);\n  const [setAsPrimaryState, privateSetAsPrimary] = useState(false);\n  const medplum = useMedplum();\n\n  const state: DoseSpotPatientPharmacyState = {\n    selectedPharmacy,\n    setAsPrimary: setAsPrimaryState,\n  };\n\n  const searchPharmacies = useCallback(\n    async (params: PharmacySearchParams): Promise<Organization[]> => {\n      return (await medplum.executeBot(DOSESPOT_SEARCH_PHARMACY_BOT, params)) as Organization[];\n    },\n    [medplum]\n  );\n\n  const setSelectedPharmacy = (pharmacy: Organization | undefined): void => {\n    privateSetSelectedPharmacy(pharmacy);\n  };\n\n  const setAsPrimary = (primary: boolean): void => {\n    privateSetAsPrimary(primary);\n  };\n\n  const addFavoritePharmacy = useCallback(\n    async (patientId: string): Promise<AddPatientPharmacyResponse> => {\n      if (!selectedPharmacy) {\n        throw new Error('Must select a pharmacy before adding it as a favorite');\n      }\n\n      const pharmacyId = getPharmacyIdFromOrganization(selectedPharmacy);\n      if (!pharmacyId) {\n        throw new Error('Selected pharmacy does not have a valid DoseSpot pharmacy ID');\n      }\n\n      return medplum.executeBot(DOSESPOT_ADD_PATIENT_PHARMACY_BOT, {\n        patientId,\n        pharmacy: selectedPharmacy,\n        setAsPrimary: setAsPrimaryState,\n      }) as Promise<AddPatientPharmacyResponse>;\n    },\n    [selectedPharmacy, setAsPrimaryState, medplum]\n  );\n\n  const clear = (): void => {\n    privateSetSelectedPharmacy(undefined);\n    privateSetAsPrimary(false);\n  };\n\n  return {\n    state,\n    searchPharmacies,\n    setSelectedPharmacy,\n    setAsPrimary,\n    addFavoritePharmacy,\n    clear,\n  };\n}\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\nimport type { MedicationKnowledge, Organization } from '@medplum/fhirtypes';\nimport { DOSESPOT_PHARMACY_ID_SYSTEM } from './common';\n\nexport const getMedicationName = (medication: MedicationKnowledge | undefined): string => {\n  return medication?.code?.text || '';\n};\n\n/**\n * Extracts the DoseSpot pharmacy ID from an Organization resource.\n * @param organization - The FHIR Organization resource representing a pharmacy.\n * @returns The DoseSpot pharmacy ID, or undefined if not found.\n */\nexport function getPharmacyIdFromOrganization(organization: Organization): number | undefined {\n  const id = organization.identifier?.find((i) => i.system === DOSESPOT_PHARMACY_ID_SYSTEM)?.value;\n  return id ? Number.parseInt(id, 10) : undefined;\n}\n\nexport {\n  addPreferredPharmacyToPatient,\n  createPreferredPharmacyExtension,\n  getPreferredPharmaciesFromPatient,\n  isAddPharmacyResponse,\n  isOrganizationArray,\n  PATIENT_PREFERRED_PHARMACY_URL,\n  PHARMACY_PREFERENCE_TYPE_SYSTEM,\n  PHARMACY_TYPE_PREFERRED,\n  PHARMACY_TYPE_PRIMARY,\n  removePreferredPharmacyFromPatient,\n} from '@medplum/core';\nexport type { PreferredPharmacy } from '@medplum/core';\n", "// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { UsePharmacySearchReturn } from '@medplum/react-hooks';\nimport { usePharmacySearch } from '@medplum/react-hooks';\nimport { DOSESPOT_ADD_PATIENT_PHARMACY_BOT, DOSESPOT_SEARCH_PHARMACY_BOT } from './common';\n\nexport type UseDoseSpotPharmacySearchReturn = UsePharmacySearchReturn;\n\n/**\n * React hook that provides DoseSpot-specific pharmacy search and add-to-favorites functionality.\n *\n * Thin wrapper around the generic {@link @medplum/react-hooks#usePharmacySearch} hook,\n * pre-configured with DoseSpot bot identifiers.\n *\n * @returns An object with `searchPharmacies` and `addToFavorites` callbacks.\n */\nexport function useDoseSpotPharmacySearch(): UseDoseSpotPharmacySearchReturn {\n  return usePharmacySearch(DOSESPOT_SEARCH_PHARMACY_BOT, DOSESPOT_ADD_PATIENT_PHARMACY_BOT);\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_SELF_ENROLL_PRESCRIBER_BOT } from './common';\n\n/**\n * Result returned by the DoseSpot self-enrollment bot.\n */\nexport interface DoseSpotSelfEnrollmentResult {\n  status: 'created' | 'already_enrolled' | 'advanced';\n  doseSpotClinicianId: number;\n  registrationStatus: string;\n  epcsEnabled: boolean;\n  nextSteps: string[];\n}\n\n/**\n * Options for the {@link useDoseSpotSelfEnrollment} hook.\n */\nexport interface DoseSpotSelfEnrollmentOptions {\n  /** Whether to run the self-enrollment bot. Defaults to true. */\n  readonly enabled?: boolean;\n  /** Called when enrollment succeeds. */\n  readonly onSuccess?: (result: DoseSpotSelfEnrollmentResult) => void;\n  /** Called when enrollment fails. */\n  readonly onError?: (err: unknown) => void;\n}\n\n/**\n * React hook that executes the DoseSpot self-enrollment bot.\n *\n * Runs the `dosespot-self-enroll-prescriber-bot` once on mount (when enabled)\n * and returns the enrollment result, loading state, and any error.\n *\n * The bot is idempotent -- it creates the clinician on the first call and\n * auto-advances through registration stages (IDP, TFA) on subsequent calls.\n *\n * @param options - Configuration options.\n * @returns An object with `result`, `loading`, and `error` fields.\n */\nexport function useDoseSpotSelfEnrollment(options?: DoseSpotSelfEnrollmentOptions): {\n  result: DoseSpotSelfEnrollmentResult | undefined;\n  loading: boolean;\n  error: unknown;\n} {\n  const medplum = useMedplum();\n  const enabled = options?.enabled ?? true;\n  const initializingRef = useRef(false);\n  const [result, setResult] = useState<DoseSpotSelfEnrollmentResult | undefined>(undefined);\n  const [loading, setLoading] = useState(enabled);\n  const [error, setError] = useState<unknown>(undefined);\n\n  const onSuccessRef = useRef(options?.onSuccess);\n  onSuccessRef.current = options?.onSuccess;\n\n  const onErrorRef = useRef(options?.onError);\n  onErrorRef.current = options?.onError;\n\n  const enroll = useCallback(async () => {\n    if (initializingRef.current || !enabled) {\n      return;\n    }\n\n    initializingRef.current = true;\n    setLoading(true);\n    setError(undefined);\n\n    try {\n      const enrollResult = (await medplum.executeBot(\n        DOSESPOT_SELF_ENROLL_PRESCRIBER_BOT,\n        {}\n      )) as DoseSpotSelfEnrollmentResult;\n\n      setResult(enrollResult);\n      onSuccessRef.current?.(enrollResult);\n    } catch (err: unknown) {\n      setError(err);\n      onErrorRef.current?.(err);\n    } finally {\n      setLoading(false);\n    }\n  }, [medplum, enabled]);\n\n  useEffect(() => {\n    enroll().catch(console.error);\n  }, [enroll]);\n\n  return { result, loading, error };\n}\n"],
  "mappings": "wpBAAA,gwECSA,gBAWO,yBAdA,IAkBM,mBAAqB,+BAGrB,2BAA6B,kCAC7B,4BAA8B,mCAC9B,mCAAqC,qDACrC,oCAAsC,2CAGtC,6BAA2C,CACtD,OAAQ,mBACR,MAAO,8BACT,EAEa,kCAAgD,CAC3D,OAAQ,mBACR,MAAO,mCACT,EAGa,0B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IAAAC,oBAA2B,gCAC3BC,cAAyD,iBAsClD,SAAS,0BAA0B,QAIxC,CACA,IAAM,WAAU,gCAAW,EACrB,QAAU,SAAS,SAAW,GAC9B,mBAAkB,sBAAO,EAAK,EAC9B,CAAC,OAAQ,SAAS,KAAI,wBAAmD,MAAS,EAClF,CAAC,QAAS,UAAU,KAAI,wBAAS,OAAO,EACxC,CAAC,MAAO,QAAQ,KAAI,wBAAkB,MAAS,EAE/C,gBAAe,sBAAO,SAAS,SAAS,EAC9C,aAAa,QAAU,SAAS,UAEhC,IAAM,cAAa,sBAAO,SAAS,OAAO,EAC1C,WAAW,QAAU,SAAS,QAE9B,IAAM,UAAS,2BAAY,SAAY,CACrC,GAAI,kBAAgB,SAAW,CAAC,SAIhC,iBAAgB,QAAU,GAC1B,WAAW,EAAI,EACf,SAAS,MAAS,EAElB,GAAI,CACF,IAAM,aAAgB,MAAM,QAAQ,WAClC,oCACA,CAAC,CACH,EAEA,UAAU,YAAY,EACtB,aAAa,UAAU,YAAY,CACrC,OAAS,IAAc,CACrB,SAAS,GAAG,EACZ,WAAW,UAAU,GAAG,CAC1B,QAAE,CACA,WAAW,EAAK,CAClB,EACF,EAAG,CAAC,QAAS,OAAO,CAAC,EAErB,kCAAU,IAAM,CACd,OAAO,EAAE,MAAM,QAAQ,KAAK,CAC9B,EAAG,CAAC,MAAM,CAAC,EAEJ,CAAE,OAAQ,QAAS,KAAM,CAClC",
  "names": ["import_core", "directions", "import_react_hooks", "import_react", "import_react_hooks", "import_react", "import_react_hooks", "import_react", "import_core", "import_react_hooks", "import_react_hooks", "import_react"]
}
