FHIR Medication - kind-lab/mimic-fhir GitHub Wiki

FHIR Medication

Medication in FHIR is organized into 4 resources

  • Medication: Stores all medications and medication mixes.
  • MedicationRequest: Any prescription or order for medication is stored here.
  • MedicationDispense: Pharmacy or in hospital dispensation of medication
  • MedicationAdministration: The actual administration of the requested/dispensed medication

The hospital medicine workflow prescribe -> dispense -> administer in FHIR becomes: MedicationRequest -> MedicationDispense -> MedicationAdministration.

Mapping MIMIC medication tables to FHIR

The medication across MIMIC do NOT have one single source, thus we need multiple CodeSystems coming out mimic-fhir to fully describe the medication.

The medication CodeSystems that were generated were:

CodeSystem Source Usage Notes
medication-formulary-drug-cd prescriptions.formulary_drug_cd and emar_detail.product_code Medication for MedicationRequest and MedicationAdministration For requests, can be part of med mixes
medication-name prescriptions.drug, pharmacy.medication, emar.medication Medication for MedicationDispense and some MedicationAdministration Only used in medadmin if drug product_code is not present
medication-poe-iv poe.order_type Medication for MedicationAdministration Only used if product code and drug name are not present
medication-ndc prescriptions.ndc Medication for MedicationRequest NDC is used as the primary identifier in medication coming out of prescriptions
medication-gsn prescriptions.gsn Medication for MedicationRequest GSN is the secondary identifier in medication coming out of prescriptions
medication-icu d_items.itemid for inputevents Medication for MedicationAdministrationICU ICU meds are stored separately from the rest of the medication

For the generation of medication resources the CodeSystems were effectively translated into fhir resources. The exception was prescription medication. Since there are multiple identifiers in prescriptions (ndc, gsn, formulary_drug_cd, drug name) more distinct medication were created. Some notes from creating prescription medication:

  • Medication NDC can map to multiple gsn and formulary drug codes.
  • Medication GSN can map to multiple ndc and formulary drug codes.
  • Medication formulary drug codes often map to multiple NDC and GSN.
  • The intermixing of all the identifiers led to more medication resources being created to get full coverage.

The other more complex medication was medication mixes. These were constructed from prescriptions with multiple drugs linked to one pharmacy_id. Thus once the base medication were created, the medication mixes were generated with references to the base medication in the ingredients element.

MediationRequest Notes

The primary identifier for medicationRequest is pharmacy_id, but if not present the poe_id is used.

There are two main types of medicationRequest, hosp and icu coming from MIMIC. The tables used for each are:

  • hosp tables
    • prescriptions: This is the primary source for medicationRequest
    • pharmacy: The pharmacy table supplements the prescriptions table with some timing information for the prescription
    • emar: Medication usage starts with a medicationRequest, but sometimes in emar there is no link to a pharmacy_id. In this case the medication is already present in the emar table (often basic IV meds). This accounts for about ~4 million med requests
    • poe: There are about ~150,000 emar events that have no pharmacy_id, and no medication specified. In these cases the poe order specifies the majority of the time (other than ~50) that IV/TPN is being used. A basic medicationRequest resource is made with IV/TPN as the medication requested.
      • BUT the IV events have lots of different medication being delivered... some product_description are filled in emar_detail. Maybe these events just don't have a medication request. If no pharmacy/prescriptions then no medicationRequest? Since it is more of a direct medicationAdministration
  • icu tables
    • inputevents

Remaining issues/to do:

  • No clear way to set source table for information. Would be nice to say that the poe table was the source for the request or the prescriptions table was the source. Need to look more into Provenance
  • What to do with emar events with no pharmacy_id or medication? Currently no medication request
  • dose_val_rx from prescriptions contains ranges and some free text (ie to, mg, various units). Can grab lower ranges but for free text ones potentially just omit for now (drops ~1 million out of the 16 million rows in prescriptions, about 2,000 distinct entries to deal with)
    • Grabbing lower bound of ranges and omit if just free text

MedicationDispense Notes

Medication dispenses are based on the pharmacy table with some connections to emar_detail. Notes:

  • Medication dispense are only generated for pharmacy_id that have a non NULL medication value
  • The primary key for the medication dispense is the pharmacy_id
  • MedicationRequest was linked by pharmacy_id being converted to uuid for medreq
  • MedicationAdminstration are linked to medicationDispense through emar_detail
    • Grouped emar_detail rows that had dose delivered (so not rows with NULL value for parent_field_ordinal)

Remaining issues/to do:

  • Incorporate NULL medication through poe potentially. Or look into emar_detail product_description since it is often filled with IV medication
  • Do we need separate source id for MedicationRequest and MedicationDispsense? They both use pharmacy_id but generate unique uuid in mimic-fhir since they use different namespaces
  • Medication is currently pulled from pharmacy but that does not account for medication mixes seen in prescriptions. Link with pharmacy_id and construct medication mixes to properly reference

MedicationAdministration Notes

MedicationAdministration is based on the emar_detail table, there will be a separate entry for ICU medadmin. Notes:

  • dose_given is used for the dosage.dose in fhir but the mimic column has non-numeric values for some
    • only ~70,000 are non-numeric out of ~27 million so a minority
      • ~24,000 are N, INI with product_amount_given storing actual dose information. Map these
      • ~46,000 have only a dose_given with an NULL dose_given_unit. These values mostly have the unit typed in the dose_given. Omit for now
    • For those non-numeric values it is often just free text of units (ie mg, drop, mL) or fully typed out dose (ie one gtt)
  • medicationReference filled in depending on data present:
    1. emar_detail.product_code
    2. emar.medication
    3. poe.order_type -> for TPN/IV orders
    4. NULL -> when none of the above are present enter a null flavour for FHIR
  • Duplicate rows. There are currently 3,711 duplicate entries into emar_detail, presumabely added through human error at the hospital.
    • Duplicates will be filtered out using a group by

Remaining issues/to do:

  • dose_given values with free text parse these. About 46,000 to clean up

Medication codes/identifier

  • In emar when there is no reference to medication, the poe order_type is used. This is for IV/TPN primarily. There are ~1,300,000 emar events with null medication and all but 46 are IV/TPN.