Skip to content

Instantly share code, notes, and snippets.

@johngrimes
Last active August 3, 2022 06:44
Show Gist options
  • Save johngrimes/68fb3e9a2963283c57070f399b27b8a3 to your computer and use it in GitHub Desktop.
Save johngrimes/68fb3e9a2963283c57070f399b27b8a3 to your computer and use it in GitHub Desktop.
Upload FHIR JSON Bundles to a FHIR server (in parallel)
import multiprocessing as mp
import sys
from time import time
import requests
def upload_bundle(file):
with open(file) as bundle:
data = bundle.read()
start = time()
print(f"Sending: {file}")
response = requests.post(url=url, data=data, headers=headers)
print(f"Completed with {response.status_code}: {file} ({time() - start:.3f} s)")
if response.status_code != 200:
print(response.text)
url = sys.argv[1]
files = sys.argv[2:]
headers = {"Content-Type": "application/fhir+json", "Accept": "application/fhir+json"}
if __name__ == "__main__":
overall_start = time()
with mp.Pool(mp.cpu_count()) as pool:
pool.map(upload_bundle, files)
print(f"Finished in {time() - overall_start:.3f} s.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment