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

114 lines · jq
2# Transforms FHIR Patients into OMOP person table records.
5include "fhir";
6include "fhir/common";
8def yob: .birthDate | split("-")[0] | tonumber;
9def mob: .birthDate | split("-")[1] | tonumber;
10def dob: .birthDate | split("-")[2] | tonumber;
12def gender:
13 (
14 [
15 .extension[]
16 | select(.url == "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex")
17 ]
18 ) as $gender |
19 if ($gender | length) > 1 then
20 debug("Patient/\(.id) has multiple genders") |
21 $gender[0]
22 elif ($gender | length) == 1 then
23 $gender[0]
24 else
25 debug("Patient/\(.id) has no gender") |
26 null
27 end
30def gender_concept_id:
31 gender as $gender |
32 if $gender.valueCode == "M" then
33 8507
34 elif $gender.valueCode == "F" then
35 8532
36 else
37 debug("Unable to determine gender for Patient/\(.id)") |
38 null
39 end
42def ethnicity:
43 (
44 [
45 .extension[]
46 | select(.url == "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity")
47 | .extension[]
48 | select(has("valueCoding"))
49 | .valueCoding
50 ]
51 ) as $ethnicity |
52 if ($ethnicity | length) > 1 then
53 debug("Multiple ethnicities in Patient/\(.id)") |
54 $ethnicity[0].concept
55 elif ($ethnicity | length) == 1 then
56 $ethnicity[0].concept
57 else
58 debug("Patient/\(.id) has no ethnicity") |
59 null
60 end
63def race:
64 (
65 [
66 .extension[]
67 | select(.url == "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race")
68 | .extension[]
69 | select(has("valueCoding"))
70 | .valueCoding
71 ]
72 ) as $races |
73 if ($races | length) > 1 then
74 debug("Multiple races in Patient/\(.id)") |
75 $races[0].concept
76 elif ($races | length) == 1 then
77 $races[0].concept
78 else
79 debug("Patient/\(.id) has no race") |
80 null
81 end
84# Creates a link that work in the local hapi server.
85def hapi_url:
86 # Would be nicer if there was a module for accessing env variables for this.
87 "http://localhost:8080/Patient/\(.id)"
90Patient |
92 "person", # OMOP person table
93 .id, # person_id
94 gender_concept_id, # gender_concept_id
95 yob, # year_of_birth
96 mob, # month_of_birth
97 dob, # day_of_birth
98 null, # birth_datetime
99 race.concept_id, # race_concept_id
100 ethnicity.concept_id, # ethnicity_concept_id
101 null, # location_id
102 null, # provider_id - last seen general practitioner
103 null, # care_site_id - the location of their provider
104 hapi_url, # person_source_value
105 gender.valueCode, # gender_source_value
106 null, # gender_source_concept_id
107 race.concept_code, # race_source_value
108 race.source_concept_id, # race_source_concept_id
109 ethnicity.concept_code, # ethnicity_source_value
110 ethnicity.source_concept_id # ethnicity_source_concept_id
113@tsv