-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_obs.py
More file actions
27 lines (22 loc) · 774 Bytes
/
post_obs.py
File metadata and controls
27 lines (22 loc) · 774 Bytes
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
import requests
from pathlib import Path
import os
import json
from pprint import pprint
from datetime import datetime
BASE_URL = "https://hapi.fhir.org/baseR4"
cwd = Path(os.getcwd())
data_dir = cwd / "data"
data_dir.mkdir(exist_ok=True)
def post_observation_to_hapi(observation):
url = f"{BASE_URL}/Observation"
headers = {"Content-Type": "application/fhir+json"}
try:
response = requests.post(url, headers=headers, json=observation)
response.raise_for_status()
print("Observation posted successfully.")
#pprint(response.json())# uncomment it only if intended to view in the output
except Exception as e:
print(f"Error posting observation: {e}")
if response is not None:
print(response.text)