refs/refs/fhir-x-omop/fhir_x_omop/to_fhir/immunization.py

73 lines · py
1from fhir.resources.immunization import Immunization
2from omop_pydantic import DrugExposure
4from chidian import DataMapping, Mapper
5import chidian.partials as p
7immunization_mapper = Mapper(
8 lambda src: {
9 "resourceType": "Immunization",
10 "id": (p.get("drug_exposure_id") | p.str())(src),
11 "identifier": [{
12 "system": "http://omop.org/drug_exposure",
13 "value": (p.get("drug_exposure_id") | p.str())(src),
14 }],
15 "status": "completed",
16 "vaccineCode": {
17 "coding": [{
18 "system": p.case(p.get("drug_type_concept_id")(src), {
19 38000179: "http://hl7.org/fhir/sid/cvx",
20 38000180: "http://www.nlm.nih.gov/research/umls/rxnorm",
21 }, default="http://omop.org/drug"),
22 "code": p.get("drug_source_value")(src),
23 "display": p.get("drug_source_value")(src),
24 }]
25 },
26 "patient": {
27 "reference": (p.get("person_id") | p.format("Patient/{}"))(src)
28 },
29 "encounter": {
30 "reference": (p.get("visit_occurrence_id") | p.format("Encounter/{}"))(src)
31 },
32 "occurrenceDateTime": (p.get("drug_exposure_start_datetime") | p.str())(src),
33 "recorded": (p.get("drug_exposure_start_datetime") | p.str())(src),
34 "primarySource": True,
35 "lotNumber": p.get("lot_number")(src),
36 "route": {
37 "coding": [{
38 "system": "http://terminology.hl7.org/CodeSystem/v3-RouteOfAdministration",
39 "code": p.case(p.get("route_source_value")(src), {
40 "intramuscular": "IM",
41 "subcutaneous": "SC",
42 "oral": "PO",
43 "intranasal": "NASINHL",
44 }, default="IM"),
45 "display": p.get("route_source_value")(src)
46 }]
47 },
48 "doseQuantity": {
49 "value": (p.get("quantity") | p.float())(src),
50 "unit": p.get("dose_unit_source_value", default='dose')(src),
51 "system": "http://unitsofmeasure.org",
52 "code": p.get("dose_unit_source_value", default='dose')(src)
53 },
54 "performer": [{
55 "function": {
56 "coding": [{
57 "system": "http://terminology.hl7.org/CodeSystem/v2-0443",
58 "code": "AP",
59 "display": "Administering Provider"
60 }]
61 },
62 "actor": {
63 "reference": (p.get("provider_id") | p.format("Practitioner/{}"))(src)
64 }
65 }],
66 }
69to_fhir_immunization = DataMapping(
70 mapper=immunization_mapper,
71 input_schema=DrugExposure,
72 output_schema=Immunization,