eRx
Create Prescriptions
🚧

The eRx Service is currently in beta.

Prescribing

The eRx Service allows you to prescribe medications to your patients via embedded UI elements (opens in a new tab). These prescriptions are synced back into the FHIR service in the form of MedicationRequest (opens in a new tab) and MedicationDispense (opens in a new tab) resources.

Getting Started

To prescribe your first medication, you'll need to install the photon elements package from NPM:

npm install @photonhealth/elements

Here is a minimal react example application that we'll build on in following code samples. Note the skipRedirectCallback. This property is necessary when using Auth0Provider to log into Oystehr and as well as embedding the eRx element.

index.jsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App.jsx';
import { Auth0Provider } from '@auth0/auth0-react';
import './index.css';
 
ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <Auth0Provider
      domain={'https://auth.zapehr.com'}
      clientId={'your_oystehr_app_client_id'}
      authorizationParams={{
        audience: 'https://api.zapehr.com',
        redirect_uri: 'http://localhost:3000',
      }}
      skipRedirectCallback={window.location.href.includes('photon=true')}
    >
      <App />
    </Auth0Provider>
  </React.StrictMode>
);

This code sample demonstrates placing the photon-client as high up in the authenticated tree as possible:

App.jsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import Patient from './Patient.jsx'
import { useAuth0 } from '@auth0/auth0-react';
import("@photonhealth/elements").catch((e) => {console.error(e)});
 
function App() {
  const { isAuthenticated, isLoading, loginWithRedirect } = useAuth0();
 
  if (!isAuthenticated && isLoading) {
    return 'Loading...';
  }
 
  if (!isAuthenticated && !isLoading) {
    loginWithRedirect().catch((error) => {
      throw new Error(`Error calling loginWithRedirect Auth0 ${error}`);
    });
  }
 
  return (
    <photon-client
        id={"your-photon-client-id"}
        org={"your-photon-org-id"}
        dev-mode="true"
        auto-login="true"
        redirect-uri="http://localhost:3000"
      >
      <Patient />
    </photon-client>
  );
}
 
export default App;

Now it is time to add the prescribe element (opens in a new tab) to your application:

Patient.jsx
import { createRef, useState, useEffect } from 'react';
import './Page.css';
 
function Patient() {
  const id = 'the_patient_id';
 
  const photonPrescribeRef = createRef();
 
  useEffect(() => {
    const log = () => {
      console.log("treatment prescribed!");
    }
    if (photonPrescribeRef.current) {
      photonPrescribeRef.current.addEventListener("photon-prescribe-success", log);
      const removal = () => photonPrescribeRef.current.removeEventListener("photon-prescribe-success", log);
      return () => removal()
    }
  }, []);
 
  return (
    <div>
      <h1>Prescribe</h1>
      <photon-prescribe-workflow ref={photonPrescribeRef} enable-order={true} patient-id={id} />
    </div>
  );
}
 
export default Patient;

It's required that you sync your patient with the eRx service before presenting the prescribe modal to providers, for more information see patient sync.

Prescriptions on FHIR

The eRx service provides built in FHIR workflow support for the prescription and dispensing of medications.

MedicationRequest

When a medication is prescribed, a MedicationRequest (opens in a new tab) resource is created. This resource contains the details of the prescription, such as the medication, the dosage, and the patient.

Here is an example medication request:

{
    "resourceType": "MedicationRequest",
    "identifier": [
        {
            "system": "http://api.zapehr.com/photon-prescription-id",
            "value": "rx_21G8C1TNF8TZ5N9DAJN66H9KSH"
        },
        {
            "system": "http://api.zapehr.com/photon-event-id",
            "value": "id_PRESCRIPTION_CREATED_EVENT_2"
        },
        {
            "system": "http://api.zapehr.com/photon-organization-id",
            "value": "org:org_KzSVZBQixLRkqj5d"
        }
    ],
    "status": "active",
    "intent": "order",
    "subject": {
        "reference": "Patient/06d1cf3d-c33e-40d2-b6c2-191538e9bb8c"
    },
    "requester": {
        "reference": "Practitioner/3c9a43c1-00fe-432c-9782-ce876c2e5831"
    },
    "dispenseRequest": {
        "quantity": {
            "unit": "EA",
            "value": 20
        },
        "numberOfRepeatsAllowed": 2,
        "expectedSupplyDuration": {
            "code": "d",
            "system": "http://unitsofmeasure.org",
            "unit": "day",
            "value": 10
        },
        "validityPeriod": {
            "start": "2022-01-01",
            "end": "2023-01-01"
        }
    },
    "dosageInstruction": [
        {
            "patientInstruction": "Take twice daily"
        }
    ],
    "medicationCodeableConcept": {
        "coding": [
            {
                "system": "http://api.zapehr.com/photon-treatment-id",
                "code": "med_01HQY2N8PCWKQVZC7GQXEF0Z86",
                "display": "Zestril (Lisinopril 2.5 mg) Oral tablet"
            },
            {
                "system": "http://api.zapehr.com/rxcui",
                "code": "104375",
                "display": "Zestril (Lisinopril 2.5 mg) Oral tablet"
            },
            {
                "system": "http://api.zapehr.com/ndc",
                "code": "2-0530",
                "display": "Zestril (Lisinopril 2.5 mg) Oral tablet"
            }
        ]
    },
    "extension": [
        {
            "url": "http://api.zapehr.com/photon-event-time",
            "valueDateTime": "2022-01-01T01:00:00.000Z"
        }
    ],
    "id": "1d9df545-8230-4913-a6be-90886a4abf4f",
    "meta": {
        "versionId": "a5de4dbb-e8ed-4965-806b-ffd9d8e47fe0",
        "lastUpdated": "2024-05-15T23:11:30.669Z"
    }
}

A few of these fields are worthy of note.

  • requester.reference property points to the practitioner who prescribed the medication
  • subject.reference references the patient prescribed the medication
  • medicationCodeableConcept describes the medication coding information for the drug that was prescribed
  • dispenseRequest is the information sent to the pharmacy about the quantity, timing, and refills of the prescription
  • dosageInstruction is the instructions provided to the patient
  • status can be 'active', 'completed', or 'stopped' and will update as the patient fills their medication

MedicationDispense

When the prescription is sent to the pharmacy for filling, a MedicationDispense (opens in a new tab) resource is created.

{
    "resourceType": "MedicationDispense",
    "identifier": [
        {
            "system": "http://api.zapehr.com/photon-order-id",
            "value": "ord_01G8AHAFDJ7FV2Y77FVWA19009"
        },
        {
            "system": "http://api.zapehr.com/photon-event-id",
            "value": "id_ORDER_CREATED_EVENT_TWO_PRESCRIPTIONS"
        },
        {
            "system": "http://api.zapehr.com/photon-organization-id",
            "value": "org:org_KzSVZBQixLRkqj5d"
        }
    ],
    "status": "unknown",
    "subject": {
        "reference": "Patient/06d1cf3d-c33e-40d2-b6c2-191538e9bb8c"
    },
    "medicationCodeableConcept": {
        "coding": [
            {
                "system": "http://api.zapehr.com/photon-treatment-id",
                "code": "med_01HQY2N8PCWKQVZC7GQXEF0Z86",
                "display": "Zestril (Lisinopril 2.5 mg) Oral tablet"
            },
            {
                "system": "http://api.zapehr.com/rxcui",
                "code": "104375",
                "display": "Zestril (Lisinopril 2.5 mg) Oral tablet"
            },
            {
                "system": "http://api.zapehr.com/ndc",
                "code": "2-0530",
                "display": "Zestril (Lisinopril 2.5 mg) Oral tablet"
            }
        ]
    },
    "authorizingPrescription": [
        {
            "reference": "MedicationRequest/f176619d-08c2-4754-a9d6-ddab468b3fb1"
        }
    ],
    "extension": [
        {
            "url": "http://api.zapehr.com/photon-event-time",
            "valueDateTime": "2022-01-01T02:00:00.000Z"
        }
    ]
}

Here are some note worthy properties:

  • authorizingPrescription points back to the original prescription stored in a MedicationRequest resource
  • medicationCodeableConcept describes the medication coding information for the drug that was dispensed (note that this can theoretically be different than what was prescribed)