> ## Documentation Index
> Fetch the complete documentation index at: https://docs.connectivehealth.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Bulk Medication History

> FHIR resources produced from a medication history request

# Overview

Bulk Medication History is the FHIR representation of the medication fill and prescription history returned for a
population of patients. It is produced after a customer submits a patient population using one of the
[Medication History](/medication-history/patient-panel-load) request APIs
([patient panel load](/medication-history/patient-panel-load) or
[bulk file load](/medication-history/bulk-patient-panel-file-load)). The `correlationId` returned from that original
request ties the resulting FHIR data back to the request that produced it.

Unlike the [Patient Everything](/fhir/patient-everything-bundle) and [Patient Summary](/fhir/patient-summary-bundle)
outputs, this data is **not** wrapped in a single
[Bundle](https://www.hl7.org/fhir/R4/bundle.html) resource. Instead, following the HL7
[Bulk Data Access](https://build.fhir.org/ig/HL7/bulk-data/en/) approach, resources are grouped by resource type and
written out as newline-delimited JSON (NDJSON) files -- one resource per line, one file per resource type (for
example, all `MedicationRequest` resources for the whole population are written to a single file).

# Delivery

Bulk Medication History files are pushed to customer cloud storage using the same mechanisms described in
[Delivery](/fhir/overview#delivery) (S3, Azure, and soon Google Cloud Storage). Webhook notification of delivery
completion is planned for this output but is **not yet available** -- today, delivery is push-only with no
accompanying webhook event.

# Resources Included

| Resource                                                  | US Core Profile                                                                                                     | Description                                                                                                                       |
| --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| [Patient](/fhir/resources/patient)                        | [US Core Patient](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-patient.html)                       | The patient the medication history belongs to. One resource per unique patient in the request.                                    |
| [Practitioner](/fhir/resources/practitioner)              | [US Core Practitioner](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-practitioner.html)             | The prescriber of a medication.                                                                                                   |
| [PractitionerRole](/fhir/resources/practitioner-role)     | [US Core PractitionerRole](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-practitionerrole.html)     | Links the prescriber to their office location and contact details, and is referenced as the requester on the `MedicationRequest`. |
| [Location](/fhir/resources/location)                      | [US Core Location](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-location.html)                     | Used twice: once for the prescriber's office, and once for the pharmacy that dispensed the medication.                            |
| [Medication](/fhir/resources/medication)                  | [US Core Medication](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-medication.html)                 | The drug product itself (code, and form when known).                                                                              |
| [MedicationRequest](/fhir/resources/medication-request)   | [US Core MedicationRequest](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-medicationrequest.html)   | The prescription order.                                                                                                           |
| [MedicationDispense](/fhir/resources/medication-dispense) | [US Core MedicationDispense](https://hl7.org/fhir/us/core/STU9/StructureDefinition-us-core-medicationdispense.html) | The fill/dispense event at the pharmacy.                                                                                          |
| [OperationOutcome](/fhir/resources/operation-outcome)     | *(none -- base FHIR resource)*                                                                                      | Used for two different informational/error situations -- see below.                                                               |

## OperationOutcome usage

`OperationOutcome` appears in two distinct situations in this output, rather than representing a single consistent
concept:

1. **Incomplete medication record** -- if a medication record from the source system is missing its history source
   qualifier, it does not contain enough information to build the resources above. An `OperationOutcome` with
   severity `information` is emitted in its place instead of any medication resources for that record.
2. **Patient-level error** -- if the original patient population request encountered an error while trying to locate
   or process a specific patient, that error is surfaced as a separate `OperationOutcome`, unrelated to any specific
   medication.

See the [OperationOutcome resource page](/fhir/resources/operation-outcome) for the exact fields populated in each case.

# Stable IDs

Unlike the [Patient Everything](/fhir/patient-everything-bundle#stable-ids) and
[Patient Summary](/fhir/patient-summary-bundle#stable-ids) bundles, IDs in this output are **not consistently stable**
across resource types. The table below summarizes what determines each resource's ID, and whether that leads to
deduplication across the population being processed. See [FHIR IDs](/fhir/overview#fhir-ids) for background on why
stable IDs matter.

| Resource           | Based on                                                                                                      | Deduplicated across the file?                                                                                                                    |
| ------------------ | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Patient            | Provider's patient identifier system and value                                                                | Yes -- one `Patient` per unique patient.                                                                                                         |
| Practitioner       | The specific medication record                                                                                | No -- the same real-world prescriber appears as a separate resource for every medication they prescribed.                                        |
| PractitionerRole   | The specific medication record                                                                                | No -- same caveat as `Practitioner`.                                                                                                             |
| Location           | The specific medication record                                                                                | No -- applies to both the prescriber's office and the pharmacy; the same address or pharmacy is not deduplicated across medications.             |
| Medication         | Product code, drug description, form code, and strength                                                       | Yes -- identical medications collapse into a single resource, shared across every `MedicationRequest`/`MedicationDispense` that references them. |
| MedicationRequest  | Patient, written date, product code, drug description, directions, strength, refills, and quantity prescribed | Yes, if all of those fields match another record.                                                                                                |
| MedicationDispense | Patient, last filled date, sold date, product code, drug description, directions, strength, and days supply   | Yes, if all of those fields match another record.                                                                                                |
| OperationOutcome   | *(not applicable)*                                                                                            | No stable ID is assigned; treat each occurrence as a standalone informational/error entry rather than a resource to track over time.             |
