-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfhir_script.py
73 lines (52 loc) · 1.88 KB
/
fhir_script.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
'''
import json
import fhirclient.models.patient as p
with open('fhir/Zackary401_Littel644_b3e09e1a-6149-4b8f-a045-29f135ad8884.json', 'r') as h:
pjs = json.load(h)
patient = p.Patient(pjs)
patient.name[0].given
'''
from fhirclient import client
import json
#from fhirclient.models.fhirabstractbase import FHIRAbstractBase
# Create an instance of the FHIR client using the server URL
settings = {
'app_id': 'my_web_app',
'api_base': 'http://my.fhir.server.com/baseDstu3'
}
smart = client.FHIRClient(settings=settings)
# Read #the contents of the file containing the Bundle
with open('fhir/Alejandra902_Villa94_63056f6b-4cb3-4f9b-9a62-c3817991e6a1.json', 'r') as f:
bundle_json = json.load(f)
# Parse the Bundle using the FHIR client
entries = bundle_json['entry']
print("Parsed entires")
# Parse the Bundle using the FHIR client
# bundle = smart.parse_resources('Bundle', bundle_json)
# Iterate through the resources in the Bundle and handle each one appropriately
condition_arr = []
for entry in entries:
resource = entry.get("resource", None)
#print(resource)
resource_type = resource.get("resourceType", None)
print(resource_type)
if resource_type == 'Procedure':
print(resource)
condition_arr.append(resource)
'''
if resource_type == 'Patient':
# Handle Patient resource
print('Handling Patient resource')
elif resource_type == 'Observation':
# Handle Observation resource
print('Handling Observation resource')
elif resource_type == 'MedicationRequest':
# Handle MedicationRequest resource
print('Handling MedicationRequest resource')
else:
# Handle other resource types as needed
print('Handling resource of type {}'.format(resource_type))
'''
#print(condition_arr)
with open('tmp/procedure.json', 'w') as out:
out.write(json.dumps(condition_arr[0]))