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

lines 61–61 81 lines · jq
2# Transforms FHIR MedicationRequests into OMOP table records.
5include "fhir";
6include "fhir/common";
9# Include the route_concept_id in the drug concept.
10def drug:
11 if has("medicationCodeableConcept") then
12 if (.medicationCodeableConcept.coding | length) > 1 then
13 debug("Multiple medicationCodeableConcept.codings in MedicationRequest/\(.id)")
14 end
15 | .medicationCodeableConcept.coding[0].concept
16 else
17 {
18 "concept_id": null,
19 "concept_code": null,
20 "route_concept_id": null,
21 "source_concept_id": null
22 }
23 end
27# See: https://ohdsi.github.io/CommonDataModel/drug_dose.html
28# TODO: include the 'has dose form' value in concept
29# TODO: include numerator in concept
30# TODO: if there is a dosageQuantity, use it, too
31def quantity:
32 if (drug | has("drug") and drug.has_dose_form) then
33 drug.drug.numerator
34 else
35 null
36 end
39# If this is a MedicationReference, then the contents of this record will be
40# merged with the Medication record contents in the next phase of loading.
41def id:
42 if has("medicationReference") then
43 .medicationReference.id
44 else
45 .id
46 end
50MedicationRequest |
52 "drug_exposure", # TABLE COLUMNS
53 id, # drug_exposure_id
54 .subject.id, # person_id
55 drug.concept_id, # drug_concept_id
56 .authoredOn, # drug_exposure_start_date
57 .authoredOn, # drug_exposure_start_datetime
58 null, # drug_exposure_end_date
59 null, # drug_exposure_end_datetime
60 null, # verbatim_end_date
61 32838, # drug_type_concept_id - EHR prescription
62 null, # stop_reason
63 null, # refills
64 quantity, # quantity
65 null, # days_supply
66 .note, # sig
67 drug.route_concept_id, # route_concept_id
68 null, # lot_number
69 .requester.id, # provider_id
70 .encounter.id, # visit_occurrence_id
71 null, # visit_detail_id
72 drug.concept_code, # drug_source_value
73 drug.source_concept_id, # drug_source_concept_id
74 null, # route_source_value
75 null # dose_unit_source_value
77| select(
78 ((.[0] == "drug_exposure") and length == 24)
81@tsv