Example Integration

The three examples below outline a typical flow for creating a prescription for your patient.

Create a Patient

The first step in the prescribe flow is the creation of a patient record. This can be done manually in the UI (by a provider) or automatically via your backend as patients are created on your system.

A request to the createPatient mutation will create a patient in the Photon system. If a needed, the updatePatient mutation works in a similar fashion, and can be used to add or update an existing patient record.

Patient metadata, including allergies and medical history are shared with pharmacies once prescriptions and written and ordered. Photon will ensure that providers and pharmacists are always accessing the same patient record.

const graphQLClient = new GraphQLClient('https://api.photon.health/graphql', {
  headers: {
      authorization: 'AUTH TOKEN HERE',
  },
});
const query = gql`
{
  mutation createPatient(
    $name: NameInput!,
    $dateOfBirth: AWSDate!,
    $sex: SexType!,
    $phone: AWSPhone!,
    $allergies: [ConceptInput],
    $medicationHistory: [ConceptInput]
  ) {
    createPatient(
      name: $name
      dateOfBirth: $dateOfBirth
      sex: $sex
      gender: $gender
      email: $email
      phone: $phone
      allergies: $allergies
      medicationHistory: $medicationHistory
    ) {
      id
    }
  }
}
`;
const variables = {
  name: {
    first: "Jane",
    last: "Doe"
  },
  dateOfBirth: "1911-01-01",
  sex: "FEMALE",
  phone: "+12025550102",
  email: "[email protected]"
};
const results = await graphQLClient.request(query, variables);

Write a Prescription

The next step in the process is the creation of a prescription. These requests should only be made from a frontend application that's integrated with Photon.

🚧

Provider Authentication Required

Unlike all other requests, only an authorized prescriber can write a prescription! Access tokens generated from machine-to-machine credentials are not be able to hit the createPrescription mutation.

Only access tokens generated for a logged-in authorized provider are accepted.

A lot of this functionality, including provider authentication (via SSO) is made available in the Javascript SDK ]. Under the hood, the SDK is calling the createPrescription mutation, which looks like this:

const query = gql`
{
  mutation createPrescription(
    $patientId: ID!,
    $medicationId: ID!,
    $dispenseAsWritten: Boolean!,
    $dispenseQuantity: Int!,
    $dispenseUnit: DispenseUnit!,
    $refillsAllowed: Int!,
    $daysSupply: Int!,
    $instructions: String!) {
  createPrescription(
    patientId: $patientId
    medicationId: $medicationId
    dispenseAsWritten: $dispenseAsWritten
    dispenseQuantity: $dispenseQuantity
    dispenseUnit: $dispenseUnit
    refillsAllowed: $refillsAllowed
    daysSupply: $daysSupply
    instructions: $instructions
  ) {
    id
  }
}
`;

const variables = {
  patientId: "pat_01G8VFW0X44YCW8KW7FW3FC0ZT",
  medicationId: "med_cd545sasd24qa3sw",
  dispenseAsWritten: true,
  dispenseQuantity :30,
  dispenseUnit: "Each",
  refillsAllowed: 12,
  daysSupply: 30,
  instructions: "Take once daily",
}
const results = await graphQLClient.request(query, variables);

Notice that this mutation requires a patientId which is returned by createPatient mutation in the previous step.

A medicaitonId is also required. A list of medications can be retrieved by hitting the medications query. Medication IDs do not change, so they can be cached or stored internally.

const query = gql`
{
  medications {
    id
    name
  }
}
`;
const results = await graphQLClient.request(query);

Submit an Order

Once a prescription is ready to be sent to a pharmacy, a provider or an automated request may create an Order. Orders may contain fill requests for multiple prescriptions. OTC medications may also be added at this step.

πŸ“˜

Prescriptions written with Photon are not assigned or sent to a specific pharmacy until an order is placed - either by a patient or a provider.

A preferred pharmacy can be specified if a patient choses, otherwise Photon will route the prescription to the the most optimal pharmacy.

This request can be made via the SDK on the frontend or via a request on the backend, via GraphQL APIs.

const query = gql`
{
  mutation createOrder(
    $patientId: ID,
    $fills: [FillInput],
    $address: AddressInput,
    $pharmacyId: ID
) {
  createOrder(
    patientId: $patientId
    fills: $fills
    address: $address
    pharmacyId: $pharmacyId
  ) {
    id
  }
}
`;

const variables = {
  patientId: "pat_01G8Y2AX5PW501N79CS70PH4FA",
  "fills": [{ prescriptionId: "rx_01G8Y3536S4QVWX7FPDQ4TN9BM" }],
  pharmacyId: "phr_01G89KFFBN79JDBS6628XERP9H",
  address: { street1: "123 Main St", postalCode: "11111", country: "USA", state: "NY", city: "Brooklyn" } }
const results = await graphQLClient.request(query, variables);