-
Notifications
You must be signed in to change notification settings - Fork 2
/
scripts.txt
185 lines (136 loc) · 6.53 KB
/
scripts.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Create constraints to ensure unique ids for resource types
CREATE CONSTRAINT pid FOR (p:Patient) REQUIRE p.id IS UNIQUE;
CREATE CONSTRAINT prid FOR (p:Practitioner) REQUIRE p.id IS UNIQUE;
CREATE CONSTRAINT orgid FOR (o:Organization) REQUIRE o.id IS UNIQUE;
CREATE CONSTRAINT encid FOR (e:Encounter) REQUIRE e.id_name IS UNIQUE;
CREATE CONSTRAINT cond FOR (c:Condition) REQUIRE c.id IS UNIQUE;
CREATE CONSTRAINT obs FOR (o:Observation) REQUIRE o.id IS UNIQUE;
CREATE CONSTRAINT mr FOR (m:MedicationRequest) REQUIRE m.id IS UNIQUE;
CREATE CONSTRAINT pr FOR (pr:Procedure) REQUIRE pr.id IS UNIQUE;
#Patient Node
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Patient"
Create (p: Patient {lname: ent.resource.name[0].family, fname: ent.resource.name[0].given[0], sex: ent.resource.gender, birthDate: ent.resource.birthDate, state: ent.resource.address[0].state, city: ent.resource.address[0].city, zip: ent.resource.address[0].postalCode, id: ent.resource.id})
#Practitioner Node
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Practitioner"
CREATE (prov: Practitioner {fname: ent.resource.name[0].given[0], name: ent.resource.name[0].family, gender: ent.resource.gender, id: ent.resource.id})
#Organization Node
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Organization"
create (org: Organization {name: ent.resource.name, orgtype: ent.resource.type[0].coding[0].display, id: ent.resource.id, addressCity: ent.resource.address[0].city, addressState: ent.resource.address[0].state, addressLine: ent.resource.address[0].line[0]})
#Encounter Node
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Encounter"
create (enc: Encounter {type: ent.resource.class.code, id: ent.resource.id, provider: ent.resource.participant[0].individual.reference,
encstart: ent.resource.period.start,
encend: ent.resource.period.end,
id: ent.resource.id,
pid: ent.resource.subject.reference,
status: ent.resource.status,
orgid: ent.resource.serviceProvider.reference
})
#Condition
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Condition"
create (c: Condition {
type: ent.resource.resourceType,
id: ent.resource.id,
clinicalstatus: ent.resource.clinicalstatus.coding[0].code,
verificationstatus: ent.resource.verificationStatus.coding[0].code,
conditioncode: ent.resource.code.text,
pid: ent.resource.subject.reference,
encref: ent.resource.encounter.reference,
onsetdate: ent.resource.onsetDateTime,
recordeddata: ent.resource.recordedDate
})
#Observation
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Observation"
create (obs: Observation {
id: ent.resource.id,
obscategory: ent.resource.category[0].coding[0].display,
obstext: ent.resource.code.text,
encid: ent.resource.encounter.reference,
obstimedate: ent.resource.effectiveDateTime,
obsvalue: ent.resource.valueQuantity.value,
obsunit: ent.resource.valueQuantity.unit,
obscode: ent.resource.valueQuantity.code,
pid: ent.resource.subject.reference})
#MedicationRequest
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="MedicationRequest"
create (medrequest: MedicationRequest {
id: ent.resource.id,
status: ent.resource.status,
intent: ent.resource.intent,
codingdisplaytext: ent.resource.medicationCodeableConcept.text,
codingdisplaycode: ent.resource.medicationCodeableConcept.coding[0].code,
pid: ent.resource.subject.reference,
encid: ent.resource.encounter.reference,
reasonid: ent.resource.reasonReference[0].reference,
requesterid: ent.resource.requester.reference,
authoredon: ent.resource.authoredOn
})
#Procedure
call apoc.load.json("fhir/Clara183_Carbajal274_c698c2cc-6766-c4dd-f15a-e4b8e023c660.json") yield value unwind value.entry as ent
with ent
where ent.resource.resourceType ="Procedure"
create (pr: Procedure {
id: ent.resource.id,
status: ent.resource.status,
intent: ent.resource.intent,
codingdisplaytext: ent.resource.code.text,
pid: ent.resource.subject.reference,
encid: ent.resource.encounter.reference,
reasonid: ent.resource.reasonReference[0].reference,
startdate: ent.resource.performedPeriod.start,
enddate: ent.resource.performedPeriod.stop
})
## Build relationships
#Creating relationship patient to encounter
match (p:Patient),(e:Encounter) where e.pid contains p.id CREATE (p)-[r:HASENCOUNTER]->(e)
RETURN type(r)
#Encounter to Observation
match (o: Observation),(e: Encounter) where o.encid contains e.id CREATE (e)-[r:HASOBSERVATION]->(o)
RETURN type(r)
#Condition to Encounter
match (c: Condition),(e: Encounter) where c.encref contains e.id CREATE (e)-[r:REVEALEDCONDITION]->(c)
RETURN type(r)
#Condition to Patient
match (c: Condition),(p: Patient) where c.pid contains p.id CREATE (p)-[r:CONDITION {date: c.onsetdate}]->(c)
RETURN type(r)
#Temporal relationship of Conditions
MATCH (c:Condition)
WITH c
ORDER BY c.onsetdate ASC
LIMIT 50
WITH collect(c) as conditions
FOREACH (i in range(0, size(conditions) - 2) |
FOREACH (node1 in [conditions[i]] |
FOREACH (node2 in [conditions[i+1]] |
CREATE (node1)-[:NEXTCONDITION{date: node2.onsetdate}]->(node2))))
MATCH (c:Condition), (p:Patient) where c.pid contains p.id
WITH c, p ORDER BY c.onsetdate ASC LIMIT 1
CREATE (p)-[r:FIRSTCONDITION {date: c.onsetdate}]->(c)
RETURN type(r)
MATCH (c:Condition), (p:Patient) where c.pid contains p.id
WITH c, p ORDER BY c.onsetdate DESC LIMIT 1
CREATE (p)-[r:LATESTCONDITION {date: c.onsetdate}]->(c)
RETURN type(r)
#medicationrequest and condition
match (c: Condition),(mr: MedicationRequest) where mr.reasonid contains c.id CREATE (mr)-[r:TREATMENTFOR]->(c)
RETURN type(r)
#Procedure and Condition
#Procedure and Encounter
match (c: Condition),(pr: Procedure) where pr.reasonid contains c.id CREATE (pr)-[r:PROCEDUREFORTREATMENT]->(c)
RETURN type(r)
match (e: Encounter),(pr: Procedure) where pr.encid contains e.id CREATE (pr)-[r:PROCEDUREINENCOUNTER]->(c)
RETURN type(r)