File size: 2,685 Bytes
41a1041
 
 
 
 
 
1a65ac1
41a1041
 
 
0f1ad66
 
 
41a1041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e066c54
41a1041
 
 
5a5819d
 
41a1041
 
670e896
 
 
 
 
 
41a1041
670e896
 
 
 
 
 
 
 
41a1041
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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

""")