awacke1's picture
Update app.py
783ac30
import streamlit as st
import pandas as pd
from fhirclient import client
from fhir.resources import (patient as fhirpatient,
observation as fhirobservation)
#import settings
#pip install fhir.resources fhirclient
#from fhirclient.models import (client as fhirclient,
# bundle as fhirbundle,
# patient as fhirpatient)
settings = {
'app_id': 'my_app',
'api_base': 'https://hapi.fhir.org/baseR4',
'redirect_uri': 'http://localhost:8000/callback',
'scope': 'launch/patient openid fhirUser',
'client_secret': 'my_app_secret'
}
def bmi_calculator(height, weight):
bmi = weight / ((height/100)**2)
return bmi
def get_patient_data(client):
patient = fhirpatient.Patient.read('self', client.server)
# Get the patient's weight and height observations
weight_obs = client.server.request(fhirobservation.Observation
.where({'subject': f'Patient/{patient.id}',
'code': '29463-7'}))
height_obs = client.server.request(fhirobservation.Observation
.where({'subject': f'Patient/{patient.id}',
'code': '8302-2'}))
# Get the latest weight and height values
weight = float(weight_obs.entry[-1].resource.valueQuantity.value)
height = float(height_obs.entry[-1].resource.valueQuantity.value)
return height, weight
# smart = client.FHIRClient(settings=settings.settings)
st.title("BMI Calculator")
#if smart.ready:
if (True==True):
st.write("SMART on FHIR connection successful!")
st.write("Loading patient data...")
#height, weight = get_patient_data(smart)
#st.write("Patient height:", height, "cm")
#st.write("Patient weight:", weight, "kg")
#st.write("Calculating BMI...")
#bmi = bmi_calculator(height, weight)
#st.write("Your BMI is:", round(bmi, 2))
#if bmi < 18.5:
# st.write("You are underweight.")
#elif bmi >= 18.5 and bmi < 25:
# st.write("You have a healthy weight.")
#elif bmi >= 25 and bmi < 30:
# st.write("You are overweight.")
#else:
# st.write("You are obese.")
else:
st.write("SMART on FHIR connection failed. Please check your app settings.")
st.markdown("""
There are several public SMART on FHIR test servers available that allow for public access:
## HAPI FHIR Public Test Server:
This is a free, public test server that allows users to test their FHIR apps.
The server is available at the following
URL:
https://hapi.fhir.org/baseR4
""")