Skip to content
Permalink
master
Switch branches/tags
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():
webbrowser.open(swagger_url, new = 2, autoraise = True)
def get_resource_list(URL = "http://127.0.0.1:8080/home?serverId=home&pretty=true&_summary=&resource="):
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:
try:
int(resource)
except Exception as e:
resources_list.append(resource)
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
"""
try:
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=""):
PARAMS={}
try:
r = requests.get(url = get_resource_url(resource="Patient", id=id), params = PARAMS)
except:
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