# DoseSpot eRx Integration Guide

This guide explains how to get the **DoseSpot eRx interface iframed into Medplum** and **sync the relevant resources between Medplum and DoseSpot**. It is all integrated into the [Provider App](https://provider.medplum.com/) already, but these instructions will show you how to use the hooks and bots in your own application.

**info**: This is a [premium](/content/pricing/index.html) tier 3rd party integration feature. Please contact us at [support@medplum.com](mailto:support@medplum.com) to get access.

## Authentication

To use any of the hooks or bots, you will first need to add your DoseSpot clinician ID as an [identifier](/content/docs/fhir-basics#naming-data-identifiers/index.html) to each User's [ProjectMembership](/content/docs/api/fhir/medplum/projectmembership/index.html). Please contact Medplum support to get your DoseSpot clinician ID.

```typescript
{
  "resourceType": "ProjectMembership",
  "id": "123",
  "project": {
    "reference": "Project/123"
  },
  "user": {
    "reference": "User/123"
  },
  "identifier": [
    {
      "system": "https://my.staging.dosespot.com/webapi/v2/", // https://my.dosespot.com/webapi/v2/ for production
      "value": "123456"
    }
  ],
}
```

## Syncing Patient and Displaying the DoseSpot Iframe

To embed the DoseSpot eRx interface into Medplum and sync a patient's data to DoseSpot, you should use the [useDoseSpotIFrame](https://github.com/medplum/medplum/blob/113821deb5058bc1c6bc95f5d294d05e7fc4cd5e/packages/dosespot-react/src/useDoseSpotIFrame.ts#L12) hook, called with _a specific patient_. It will handle the SSO into DoseSpot, returning a URL that can be embedded in an iframe and sync the patient by performing the necessary steps.

### Sync Requirements

**1. Syncs Patient -> DoseSpot**: Ensure the patient's data includes:
- Email address
- Valid 9-digit phone number without the +1 prefix
- Address
- Date of birth
- First and last name

**Pediatric Patients (Under 18)**: required to sync Height and Weight as [Observations](/content/docs/api/fhir/resources/observation/index.html) using the correct LOINC codes.

Here’s a sample patient object:

```typescript
{
  "resourceType": "Patient",
  "name": [ 
    {
      "given": ["Frodo"],
      "family": "Baggins"
    }
  ],
  "telecom": [
    {
      "system": "email",
      "use": "home",
      "value": "frodo@example.com"
    },
    {
      "system": "phone",
      "use": "home",
      "value": "6175672093"
    }
  ],
  "address": [
    {
      "line": ["98 Battery St"],
      "city": "San Francisco",
      "state": "CA",
      "postalCode": "94118"
    }
  ],
  "birthDate": "1978-06-15",
  "identifier": [
    {
      "system": "https://dosespot.com/patient-id",
      "value": "78089260"
    }
  ]
}
```

### Height and Weight for Pediatric Patients

For patients under 18 years of age, here’s an example of a valid Height Observation:

```typescript
{
  "resourceType": "Observation",
  "status": "final",
  "category": [
    {
      "coding": [
        {
          "system": "http://terminology.hl7.org/CodeSystem/observation-category",
          "code": "vital-signs",
          "display": "Vital Signs"
        }
      ]
    }
  ],
  "code": {
    "coding": [
      {
        "system": "http://loinc.org",
        "code": "8302-2",
        "display": "Body height"
      }
    ],
    "text": "Body height"
  },
  "subject": {
    "reference": "Patient/123"
  },
  "effectiveDateTime": "2024-11-20T10:30:00Z",
  "valueQuantity": {
    "value": 59,
    "unit": "cm",
    "system": "http://unitsofmeasure.org",
    "code": "cm"
  }
}
```

### Syncing Active Prescriptions

Use the **DoseSpot Prescription Sync Bot** to sync prescriptions back to Medplum.

Example of executing the bot:

```typescript
const DOSESPOT_PRESCRIPTIONS_SYNC_BOT: Identifier = {
  system: 'https://www.medplum.com/bots',
  value: 'dosespot-prescriptions-sync-bot',
};
const medicationRequests = await medplum.execute(DOSESPOT_PRESCRIPTIONS_SYNC_BOT, {
  patientId,
  start: "2023-01-01",
  end: "2025-01-01",
  // raw: true // returns raw DoseSpot prescription data instead of creating and returning MedicationRequest resources
}) as MedicationRequest[];
```

Example of a MedicationRequest resource created by the bot:

```typescript
{
  "resourceType": "MedicationRequest",
  "id": "123",
  "identifier": [
    {
      "system": "https://dosespot.com/prescription-id",
      "value": "459848468"
    }
  ],
  "status": "completed",
  "intent": "order",
  "medicationCodeableConcept": {
    "coding": [
      {
        "system": "http://hl7.org/fhir/sid/ndc",
        "code": "57896059815"
      }
    ],
    "text": "Lip-Care External Stick"
  },
  "subject": {
    "reference": "Patient/123",
    "display": "John Doe"
  },
  "authoredOn": "2025-05-06T23:43:01.483",
  "recorder": {
    "identifier": {
      "value": "dosespot"
    }
  },
  "dispenseRequest": {
    "validityPeriod": {
      "start": "2025-05-06T23:43:01.483"
    },
    "quantity": {
      "value": 2,
      "unit": "Stick",
      "system": "http://unitsofmeasure.org"
    },
    "expectedSupplyDuration": {
      "value": 1,
      "unit": "days",
      "system": "http://unitsofmeasure.org",
      "code": "d"
    }
  }
}
```

For further documentation, see specific sections on **Prescription Status**, **Medication History**, and **Enroll Prescribers.**

### Additional Notes

- Require Height LOINC Codes: **Height** `8302-2`, **Weight** `29463-7`.
- Ensure practitioners have required roles and identifiers.

Refer to the documentation for detailed implementation, examples, and structure to ensure smooth integration with DoseSpot.
