Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
import json
import requests
from bs4 import BeautifulSoup
import webbrowser
# local import
import config
# Settings
settings = {
'app_id': config.app_id,
'api_base': config.api_base
fhir_endpoint = config.api_base
swagger_url = config.swagger_url
format_ = config.format_
pretty = config.pretty
def open_swagger():, new = 2, autoraise = True)
def get_resource_list(URL = ""):
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find_all("ul", class_="nav")
resources_text = results[1].text
resources = resources_text.split()
resources_list = []
for resource in resources:
except Exception as e:
return resources_list
def get_resource_index(resource, resource_list=get_resource_list()):
return resource_list.index(resource.lower().capitalize())
def get_resource_url(resource="Practitioner", id=""):
return f"{fhir_endpoint}/{resource}/{id}?{format_}&{pretty}" #if id else f"{fhir_endpoint}/{resource}/"
def is_hapi_live(url=config.api_base, resources=get_resource_list()):
check every available resource for a 200 status code
for resource in resources:
r = requests.get(url = f"{url}/{resource}", params = {})
if r.status_code != 200:
print(f"{resource} - {r.status_code}")
return False
return True
except Exception as e:
# print(f"Exception - {e}")
return False
def get_json(resource="Patient", id=""):
r = requests.get(url = get_resource_url(resource="Patient", id=id), params = PARAMS)
return f"ERROR: request to {get_resource_url(resource='Patient', id=id)} failed."
return json.dumps(r.json(), indent=4, sort_keys=True) if r.status_code == 200 else r.status_code
# return r.json() if r.status_code == 200 else r.status_code