-
Notifications
You must be signed in to change notification settings - Fork 2
/
DSTU2libs.py
160 lines (158 loc) · 7.37 KB
/
DSTU2libs.py
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
import json, requests, sqlite3, os, argparse, itertools
def DSTU2fixEntity(conn,entity,args):
entity,successful=fixEntity(conn,entity)
return entity,successful
def fixEntity(conn,entity):
c=conn.cursor()
resourceType=entity.get('resourceType')
successful="success"
if(resourceType=="Patient"):
pass
elif(resourceType=="Observation"):
reference=entity.get('subject').get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
entity['subject']['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
elif(resourceType=="Medication"):
print("we don't handle medications")
successful="removeFile"
# if(entity.get('product')!=None):
# # We have a product, and it may have ingrediants
# if(entity.get('product').get('ingredient')!=None):
# for ingredient in entity.get('product').get('ingredient'):
# if(ingredient.get('item')!=None):
# reference=ingredient.get('item').get('reference').split('/')
# referenceType=reference[0]
# referenceID=reference[1]
# c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
# result=c.fetchone()
# if(result):
# referenceID=result[2]
# ingredient['item']['reference']="{}/{}".format(referenceType,referenceID)
# else:
# successful="notSuccess"
# break
elif(resourceType=="Condition"):
if(entity.get('patient')!=None):
reference=entity.get('patient').get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
entity['patient']['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
elif(resourceType=="Encounter"):
if(entity.get('patient')!=None):
reference=entity.get('patient').get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
entity['patient']['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
if(entity.get('indication')!=None):
for indication in entity.get('indication'):
reference=indication.get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
indication['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
break
elif(resourceType=="Procedure"):
reference=entity.get('subject').get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
entity['subject']['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
elif(resourceType=="MedicationStatement"):
if(entity.get('patient')!=None):
reference=entity.get('patient').get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
entity['patient']['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
elif(resourceType=="Practitioner"):
if(entity.get('practitionerRole'!=None)):
print("need to implement")
if(entity.get('qualification'!=None)):
print("need to convert qualification")
elif(resourceType=="MedicationOrder"):
if(entity.get('dateWritten')==None):
print("Cannot import this file, needs dateWritten")
successful="removeFile"
pass
if(entity.get('patient')!=None):
reference=entity.get('patient').get('reference').split('/')
referenceType=reference[0]
referenceID=reference[1]
c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
result=c.fetchone()
if(result):
referenceID=result[2]
entity['patient']['reference']="{}/{}".format(referenceType,referenceID)
else:
successful="notSuccess"
elif(resourceType=="Device"):
print("we don't allow posting of Devices currently")
successful="removeFile"
# if(entity.get('patient')!=None):
# reference=entity.get('patient').get('reference').split('/')
# referenceType=reference[0]
# referenceID=reference[1]
# c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
# result=c.fetchone()
# if(result):
# referenceID=result[2]
# entity['patient']['reference']="{}/{}".format(referenceType,referenceID)
# else:
# successful="notSuccess"
# if(entity.get('owner')!=None):
# print("need to implement owner in Device")
# successful="removeFile"
# pass
# if(entity.get('location')!=None):
# print("need to implement location in Device")
# successful="removeFile"
# pass
elif(resourceType=="DeviceUseStatement"):
print("we don't allow posting of DeviceUseStatement currently")
successful="removeFile"
pass
# reference=entity.get('subject').get('reference').split('/')
# referenceType=reference[0]
# referenceID=reference[1]
# c.execute("SELECT * from IDMap WHERE oldID='{}' AND resourceType='{}';".format(referenceID,referenceType))
# result=c.fetchone()
# if(result):
# referenceID=result[2]
# entity['subject']['reference']="{}/{}".format(referenceType,referenceID)
# else:
# successful="notSuccess"
return entity,successful