Skip to main content

Order Medication

Beta

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

React hook: useScriptSureOrderMedication

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

A thin wrapper around useMedicationOrder from @medplum/react-hooks that exposes two operations: drug search and order creation. The hook is vendor-neutral — the FHIR operations route to ScriptSure bots via OperationDefinition.

The patient must be synced before calling orderMedication. See Sync a Patient.

import { useState } from 'react';
import { useScriptSureOrderMedication } from '@medplum/scriptsure-react';

function OrderMedicationPanel({ patientId }: { patientId: string }) {
const { searchMedications, orderMedication } = useScriptSureOrderMedication();
const [iframeUrl, setIframeUrl] = useState<string>();

async function handleSearch() {
const medications = await searchMedications({ term: 'lisinopril', searchGeneric: true });
// medications is Medication[]
}

async function handleOrder() {
const result = await orderMedication({
patientId,
pharmacyOrganizationId: 'org-123',
diagnoses: [{ icdId: 'I10', name: 'Essential hypertension' }],
});
setIframeUrl(result.launchUrl); // render in an iframe for prescriber to review/sign
}

if (iframeUrl) {
return <iframe src={iframeUrl} width="100%" height="800px" />;
}

return (
<div>
<button onClick={handleSearch}>Search</button>
<button onClick={handleOrder}>Order</button>
</div>
);
}

searchMedications

Calls POST /fhir/R4/Medication/$drug-search. Returns Medication[].

ParameterTypeDescription
termstringFree-text drug search term
ndcstringNational Drug Code
rxNormstringRxNorm code
routedMedIdnumberVendor routed medication id
searchOtcbooleanInclude over-the-counter drugs
searchSupplybooleanInclude supplies
searchBrandbooleanInclude brand-name drugs
searchGenericbooleanInclude generic drugs
includeCodebooleanInclude coding in returned Medication resources
quantityQualifiersbooleanReturn quantity qualifiers instead of Medication[]

orderMedication

Calls POST /fhir/R4/MedicationRequest/$order-medication. Creates or updates a draft MedicationRequest and returns a launchUrl to embed as an iframe for the prescriber to review and sign.

Request fields:

FieldTypeRequiredDescription
patientIdstringyesMedplum Patient resource id
medicationRequestIdstringExisting draft MedicationRequest id to update
drugsMedicationOrderDrugInput[]Drug lines for the order
combinationMedbooleanWhether the order is a combination medication
compoundTitlestringTitle for a compound medication
compoundQuantitynumberTotal quantity for a compound medication
compoundQuantityQualifierstringUnit qualifier for compound quantity
compoundSigs{ sigOrder: number; line3: string; drugId?: number }[]Sig lines for compound medications
conditionIdsstring[]Medplum Condition resource ids
coverageIdstringMedplum Coverage resource id
payerOrganizationIdstringMedplum Organization resource id for the payer
pharmacyOrganizationIdstringMedplum Organization resource id for the dispensing pharmacy
pharmacyNcpdpIdstringNCPDP id of the dispensing pharmacy
pharmacyNamestringDisplay name of the dispensing pharmacy
diagnoses{ icdId: string; name: string }[]ICD diagnoses to associate with the order
writtenDatestringDate the prescription was written (FHIR date)
fillDatestringRequested fill date (FHIR date)
durationDaysnumberDays supply
pharmacyNotestringNotes to pharmacist
patientInstructionstringFree-text patient instructions
appIdstringVendor application id

Response fields:

FieldTypeDescription
orderIdnumberVendor-side order id
vendorPatientIdnumberVendor-side patient id
launchUrlstringiFrame URL for the prescriber to review and sign the order
medicationRequestIdstringMedplum MedicationRequest resource id created or updated
pendingOrderStatus'queued' | 'reused'Whether the vendor pending order was newly queued or reused