refs/refs/fhir-to-omop-demo/demo/translate/map/Medication.jq

72 lines · jq
2# Transforms FHIR Medication into OMOP table records.
4# This transformation is needed to populate missing medication information
5# from the MedicationRequest records when a MedicationReference is used.
8include "fhir";
9include "fhir/common";
11##
12# Select the drug concept from the Medication record.
14def drug:
15 if has("code") then
16 if (.code.coding | length) > 1 then
17 error("Multiple code.codings in Medication/\(.id)")
18 end
19 | .code.coding[0].concept
20 else
21 {
22 "concept_id": null,
23 "concept_code": null,
24 "route_concept_id": null,
25 "source_concept_id": null
26 }
27 end
30# See: https://ohdsi.github.io/CommonDataModel/drug_dose.html
31# TODO: include the 'has dose form' value in concept
32# TODO: include numerator in concept
33# TODO: if there is a dosageQuantity, use it, too
34def quantity:
35 if (drug | has("drug") and drug.has_dose_form) then
36 drug.drug.numerator
37 else
38 null
39 end
43Medication |
45 "drug_exposure",
46 .id, # drug_exposure_id
47 null, # person_id
48 drug.concept_id, # drug_concept_id
49 null, # drug_exposure_start_date
50 null, # drug_exposure_start_datetime
51 null, # drug_exposure_end_date
52 null, # drug_exposure_end_datetime
53 null, # verbatim_end_date
54 null, # drug_type_concept_id - EHR prescription
55 null, # stop_reason
56 null, # refills
57 quantity, # quantity
58 null, # days_supply
59 null, # sig
60 drug.route_concept_id, # route_concept_id
61 null, # lot_number
62 null, # provider_id
63 null, # visit_occurrence_id
64 null, # visit_detail_id
65 drug.concept_code, # drug_source_value
66 drug.source_concept_id, # drug_source_concept_id
67 null, # route_source_value
68 null # dose_unit_source_value
71@tsv