awacke1 commited on
Commit
2938865
·
1 Parent(s): cf17196

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -1
app.py CHANGED
@@ -15,6 +15,8 @@ IBM FHIR Sandbox: IBM offers a free FHIR sandbox environment that you can use fo
15
  """)
16
 
17
 
 
 
18
  import hl7apy
19
  from fhir.resources import Bundle, Patient, Observation
20
  from fhirclient.models.fhirreference import FHIRReference
@@ -45,5 +47,95 @@ st.write("HL7 v2.x message:")
45
  st.code(str(msg))
46
  st.write("FHIR resources:")
47
  st.code(bundle.json())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  """)
16
 
17
 
18
+
19
+ st.markdown("""
20
  import hl7apy
21
  from fhir.resources import Bundle, Patient, Observation
22
  from fhirclient.models.fhirreference import FHIRReference
 
47
  st.code(str(msg))
48
  st.write("FHIR resources:")
49
  st.code(bundle.json())
50
+
51
+ """)
52
+
53
+
54
+
55
+
56
+ st.markdown("""
57
+ import requests
58
+ import streamlit as st
59
+ from fhir.resources import QuestionnaireResponse
60
+ from fhirclient.models.fhirreference import FHIRReference
61
+
62
+ # Set up the LOINC search API endpoint
63
+ loinc_search_url = "https://search.loinc.org/search"
64
 
65
+ # Set up the FHIR server base URL
66
+ fhir_server_url = "http://hapi.fhir.org/baseR4"
67
+
68
+ # Define the Exercise Assessment questionnaire ID
69
+ exercise_questionnaire_id = "exercise-questionnaire"
70
+
71
+ # Define the Exercise Assessment questionnaire response ID prefix
72
+ exercise_response_prefix = "exercise-response"
73
+
74
+ # Define the Exercise Assessment observation code
75
+ exercise_observation_code = "8867-4"
76
+
77
+ # Set the Streamlit app title and page layout
78
+ st.set_page_config(page_title="Exercise Assessment", layout="wide")
79
+ st.title("Exercise Assessment")
80
+
81
+ # Define a function to search for LOINC codes
82
+ def search_loinc_codes(query):
83
+ params = {
84
+ "sa": "true",
85
+ "co": "true",
86
+ "ec": "true",
87
+ "df": "true",
88
+ "loinc_num": query
89
+ }
90
+ response = requests.get(loinc_search_url, params=params)
91
+ if response.ok:
92
+ return response.json()["hits"]
93
+ else:
94
+ return []
95
+
96
+ # Display a search box for LOINC codes
97
+ query = st.text_input("Enter a LOINC code:")
98
+
99
+ # Search for LOINC codes and display the results
100
+ if query:
101
+ st.write(f"Search results for '{query}':")
102
+ results = search_loinc_codes(query)
103
+ for result in results:
104
+ st.write(f"{result['code']} - {result['display']}")
105
+ st.write(f"{result['system']}#{result['code']}")
106
+
107
+ # Allow the user to select a LOINC code
108
+ if len(results) == 1:
109
+ selected_code = results[0]["code"]
110
+ else:
111
+ selected_code = st.selectbox("Select a LOINC code:", [result["code"] for result in results])
112
+
113
+ # Render the Exercise Assessment using the selected LOINC code
114
+ st.write(f"Selected LOINC code: {selected_code}")
115
+ exercise_questionnaire_response_id = f"{exercise_response_prefix}-{selected_code}"
116
+ exercise_questionnaire_response = QuestionnaireResponse(
117
+ questionnaire=FHIRReference(f"Questionnaire/{exercise_questionnaire_id}"),
118
+ status="in-progress",
119
+ subject=FHIRReference("Patient/example")
120
+ )
121
+ exercise_questionnaire_response.identifier = [{"value": exercise_questionnaire_response_id}]
122
+ exercise_questionnaire_response.item = [
123
+ {
124
+ "linkId": "1",
125
+ "text": "How many minutes of aerobic exercise did you do today?",
126
+ "type": "integer"
127
+ },
128
+ {
129
+ "linkId": "2",
130
+ "text": "How many minutes of strength training did you do today?",
131
+ "type": "integer"
132
+ }
133
+ ]
134
+ st.write("Exercise Assessment:")
135
+ st.json(exercise_questionnaire_response.as_json())
136
+
137
+ # Save the Exercise Assessment to the FHIR server
138
+ fhir_client = FHIRClient(settings={"app_id": "my_web_app", "api_base": fhir_server_url})
139
+ fhir_client.create(exercise_questionnaire_response)
140
+
141
+ """)