-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFHIRfetch.py
More file actions
executable file
·74 lines (61 loc) · 1.98 KB
/
FHIRfetch.py
File metadata and controls
executable file
·74 lines (61 loc) · 1.98 KB
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
#!/usr/bin/python
########################## FHIRfetch.py #########################
# Author: SG Langer Sept 2018
#
# Purpose: take command line args to seach the FHIR index and
# return a list of URLS to image series matching search spec
#
################################################################
import os, dicom, sys, commands
import json
from download_data import FHIR
if __name__ == '__main__':
############################# main ################
# Purpose: parse command line args
#
# arg[1] = organ
# arg[2] = condition
# arg[3] = study type
# arg[4] = dump directory for series fetched
##################################################
mod = 'FHIRfetch.py: main'
os.system('clear')
ROOT = '/home/sgl02/code/py-code/mlcBuilder/'
# use cmd line arg to locate spec qry
if len(sys.argv ) != 4 :
print "Incorrect Usage: see below. No trailing /"
print ">./FHIRfetch.py organ condition destination_directory "
exit(1)
else :
ORGAN = sys.argv[1]
COND = sys.argv[2]
DEST = sys.argv[3]
# create a connection to the FHIR server
cur = FHIR('hackFHIR')
fp = open(DEST + '/results.txt' , 'w')
# get the COnditions that match Organ and Cond
buf = cur.getConditions(ORGAN, COND)
# print buf
print '*****************************'
print buf['total']
# now find the dxReports for the patients found above
# that have positive findings for the COndition
i = 0
while i< buf['total'] :
PID = buf['entry'][i]['resource']['subject']['reference']
PID = PID[PID.find('/') + 1:]
res = cur.getReports(PID)
j = 0
fp.write(PID + '\n')
while j< res['total'] :
rid = res['entry'][j]['resource']['identifier'][0]['value']
# and tie imagingStudy to the report
stdyUID = cur.getImagingStudy (rid)
stdyUID = stdyUID['entry'][0]['resource']['uid']
str1 = 'report ' + rid + ' ' + res['entry'][j]['resource']['conclusion'] + ' studyUID = ' + stdyUID + '\n'
fp.write(str1)
j = j+1
i = i +1
# then parse over them for the right modality type
fp.close()
sys.exit(0)