forked from BSCrumpton/ImportFhirJson
-
Notifications
You must be signed in to change notification settings - Fork 1
/
postTesting.py
34 lines (27 loc) · 1.41 KB
/
postTesting.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
import json, requests
SERVER="https://apps.hdap.gatech.edu/omoponfhir2/fhir/"
# testFile='/home/bcrumpton3-gtri/Documents/AllOfUs/ImportFhirJson/test/folder/1032702/new_patient_smart-1032702.json'
testFile='/home/bcrumpton3-gtri/Documents/AllOfUs/ImportFhirJson/test/afolder/aobservation.json'
# ResourceType="Patient"
ResourceType='Observation'
with open(testFile,'r') as f:
try:
tempString=json.load(f)
except json.JSONDecodeError:
print("file {} is invalid json".format(jsonFile))
# print(tempString)
tempString.pop('id')
tempString.pop('meta')
# print(tempString)
response = requests.post("{}{}".format(SERVER,ResourceType),auth=requests.auth.HTTPBasicAuth('***REMOVED***','***REMOVED***'),json=tempString)
print(response)
print(response.text)
newLocation=response.headers.get('Location')
print(json.loads(requests.get(newLocation,auth=requests.auth.HTTPBasicAuth('***REMOVED***','***REMOVED***')).text))
getresponse = requests.get("{}{}".format(SERVER,ResourceType),auth=requests.auth.HTTPBasicAuth('***REMOVED***','***REMOVED***'))
getjson_response=json.loads(getresponse.text)
print(getjson_response)
response = requests.delete(newLocation,auth=requests.auth.HTTPBasicAuth('***REMOVED***','***REMOVED***'))
getresponse = requests.get("{}{}".format(SERVER,ResourceType),auth=requests.auth.HTTPBasicAuth('***REMOVED***','***REMOVED***'))
getjson_response=json.loads(getresponse.text)
print(getjson_response)