awacke1 commited on
Commit
41a1041
·
1 Parent(s): 9f50086

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -0
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from fhirclient import client
4
+ from fhir.resources import (patient as fhirpatient,
5
+ observation as fhirobservation)
6
+
7
+ import settings
8
+
9
+ #pip install fhir.resources fhirclient
10
+
11
+ from fhirclient.models import (client as fhirclient,
12
+ bundle as fhirbundle,
13
+ patient as fhirpatient)
14
+
15
+ settings = {
16
+ 'app_id': 'my_app',
17
+ 'api_base': 'https://hapi.fhir.org/baseR4',
18
+ 'redirect_uri': 'http://localhost:8000/callback',
19
+ 'scope': 'launch/patient openid fhirUser',
20
+ 'client_secret': 'my_app_secret'
21
+ }
22
+
23
+
24
+ def bmi_calculator(height, weight):
25
+ bmi = weight / ((height/100)**2)
26
+ return bmi
27
+
28
+ def get_patient_data(client):
29
+ patient = fhirpatient.Patient.read('self', client.server)
30
+
31
+ # Get the patient's weight and height observations
32
+ weight_obs = client.server.request(fhirobservation.Observation
33
+ .where({'subject': f'Patient/{patient.id}',
34
+ 'code': '29463-7'}))
35
+ height_obs = client.server.request(fhirobservation.Observation
36
+ .where({'subject': f'Patient/{patient.id}',
37
+ 'code': '8302-2'}))
38
+
39
+ # Get the latest weight and height values
40
+ weight = float(weight_obs.entry[-1].resource.valueQuantity.value)
41
+ height = float(height_obs.entry[-1].resource.valueQuantity.value)
42
+
43
+ return height, weight
44
+
45
+ smart = client.FHIRClient(settings=settings.settings)
46
+
47
+ st.title("BMI Calculator")
48
+
49
+ if smart.ready:
50
+ st.write("SMART on FHIR connection successful!")
51
+ st.write("Loading patient data...")
52
+ height, weight = get_patient_data(smart)
53
+ st.write("Patient height:", height, "cm")
54
+ st.write("Patient weight:", weight, "kg")
55
+ st.write("Calculating BMI...")
56
+ bmi = bmi_calculator(height, weight)
57
+ st.write("Your BMI is:", round(bmi, 2))
58
+
59
+ if bmi < 18.5:
60
+ st.write("You are underweight.")
61
+ elif bmi >= 18.5 and bmi < 25:
62
+ st.write("You have a healthy weight.")
63
+ elif bmi >= 25 and bmi < 30:
64
+ st.write("You are overweight.")
65
+ else:
66
+ st.write("You are obese.")
67
+ else:
68
+ st.write("SMART on FHIR connection failed. Please check your app settings.")
69
+
70
+
71
+ st.markdown("""
72
+ There are several public SMART on FHIR test servers available that allow for public access:
73
+
74
+ ## HAPI FHIR Public Test Server:
75
+ This is a free, public test server that allows users to test their FHIR apps.
76
+ The server is available at the following
77
+ URL:
78
+ https://hapi.fhir.org/baseR4
79
+
80
+ ## SMART Health IT Sandbox: This is a free, public sandbox environment that allows users to test their SMART on FHIR apps.
81
+ The sandbox is available at the following
82
+ URL:
83
+ https://sandbox.smarthealthit.org
84
+
85
+ ## Argonaut Project Test Server: This is a public test server that is maintained by the Argonaut Project,
86
+ an initiative to accelerate the development and adoption of FHIR.
87
+ The server is available at the following
88
+ URL:
89
+ http://argonaut.healthintersections.com.au
90
+
91
+
92
+ """)