Skip to main content

Pharmacy Search

Beta

The ScriptSure integration is in beta. Features and APIs may change.

React hook: useScriptSurePharmacySearch

Package: @medplum/scriptsure-react · GitHub Source Code

Wraps usePharmacySearch with ScriptSure bot identifiers pre-configured. Exposes two methods: searchPharmacies to query the pharmacy directory and addToFavorites to save a pharmacy to a patient's profile.

import { useState } from 'react';
import { useScriptSurePharmacySearch } from '@medplum/scriptsure-react';
import type { Organization } from '@medplum/fhirtypes';

function PharmacyPicker({ patientId }: { patientId: string }) {
const { searchPharmacies, addToFavorites } = useScriptSurePharmacySearch();
const [results, setResults] = useState<Organization[]>([]);

async function handleSearch() {
const pharmacies = await searchPharmacies({ zip: '94103', name: 'CVS' });
setResults(pharmacies);
}

async function handleSelect(pharmacy: Organization) {
await addToFavorites({ patientId, pharmacy, setAsPrimary: true });
}

return (
<ul>
{results.map((pharmacy, i) => (
<li key={i}>
{pharmacy.name}
<button onClick={() => handleSelect(pharmacy)}>Add</button>
</li>
))}
</ul>
);
}

searchPharmacies

Calls scriptsure-search-pharmacy-bot and returns Organization[]. Supply at least one parameter to narrow results.

ParameterTypeDescription
namestringPharmacy name
citystringCity
statestringState
zipstringZIP code
addressstringStreet address
phoneOrFaxstringPhone or fax number
ncpdpIDstringNCPDP ID for exact lookup

addToFavorites

Calls scriptsure-add-patient-pharmacy-bot and saves the pharmacy to the patient's profile.

ParameterTypeDescription
patientIdstringMedplum Patient resource ID
pharmacyOrganizationFHIR Organization resource to add
setAsPrimarybooleanWhether to set as the patient's primary pharmacy

Returns { success: boolean, message: string, organization: Organization }. If the provider is not yet enrolled, the pharmacy is saved locally and synced to ScriptSure on the next patient sync — success is still true in that case.