import streamlit as st import fhirclient.models.observation as o import fhirclient.models.codeableconcept as cc import requests from fhirclient.models.fhirreference import FHIRReference from fhirclient.models.codeableconcept import CodeableConcept from fhirclient.models.fhirsearch import FHIRSearch from fhirclient.models.observation import Observation as FhirObservation import csv import datetime import hl7 # from hl7 import segments # from hl7apy import core # from hl7apy.consts import VALIDATION_LEVEL import pandas as pd # from fhirclient.models.questionnaire import QuestionnaireResponse as FhirQuestionnaireResponse # from fhirclient.models.fhirabstractbase import FHIRValidationError # from fhir.resources import QuestionnaireResponse # from fhir.resources import Bundle, Patient, Observation # import webbrowser # LOINC code for the assessment of blood pressure # LOINC_CODE = "69737-5" ICD_10 = "F41.1" # Display the assessment form st.header("Assessment of Generalized Anxiety Disorder") q1 = st.number_input("Over the last two weeks, how often have you been bothered by feeling nervous, anxious or on edge?", min_value=0, max_value=3, step=1) q2 = st.number_input("Over the last two weeks, how often have you been bothered by not being able to stop or control worrying?", min_value=0, max_value=3, step=1) q3 = st.number_input("Over the last two weeks, how often have you been bothered by worrying too much about different things?", min_value=0, max_value=3, step=1) q4 = st.number_input("Over the last two weeks, how often have you been bothered by having trouble relaxing?", min_value=0, max_value=3, step=1) q5 = st.number_input("Over the last two weeks, how often have you been bothered by being so restless that it's hard to sit still?", min_value=0, max_value=3, step=1) q6 = st.number_input("Over the last two weeks, how often have you been bothered by becoming easily annoyed or irritable?", min_value=0, max_value=3, step=1) q7 = st.number_input("Over the last two weeks, how often have you been bothered by feeling afraid, as if something awful might happen?", min_value=0, max_value=3, step=1) total = q1 + q2 + q3 + q4 + q5 + q6 + q7 st.write('Your total score is: ', total) # Create the SMART/FHIR Observation gad_observation = o.Observation() gad_observation.code = cc.CodeableConcept() gad_observation.code.coding = [ { "system": "http://loinc.org", "code": ICD_10, "display": "GAD-7 score" } ] gad_observation.component = [ { "code": { "coding": [ { "system": "http://loinc.org", "code": "8480-6", "display": "Systolic blood pressure" } ] }, "valueQuantity": { "value": total, "unit": "points", "system": "http://unitsofmeasure.org", "code": "" } } ] # Display the observation JSON #st.write(bp_observation.as_json()) st.write(gad_observation.component) # Create a dictionary to map age group to LOINC code age_group_loinc_map = { "Age0to18": "82810-3", "Age19to44": "82811-1", "Age44to64": "82812-9", "Age64to84": "82813-7", "Age85andOver": "82814-5" } # Create a dictionary to map age group to SNOMED code age_group_snomed_map = { "Age0to18": "313307000", "Age19to44": "313308005", "Age44to64": "313309002", "Age64to84": "313310007", "Age85andOver": "313311006" } # Create a dictionary to map gender to SNOMED code gender_snomed_map = { "M": "248153007", "F": "248152002" } # Define function to write assessment data to a csv file # fhir_server_url = "http://hapi.fhir.org/baseR4" # loinc_search_url = "https://search.loinc.org/search" # anixety_questionnaire_id = "anixety-questionnaire" # anixety_response_prefix = "anixety-response" # anixety_observation_code = "69737-5" # def search_loinc_codes(query): # params = { "sa": "true", "co": "true", "ec": "true", "df": "true", "loinc_num": query } # response = requests.get(loinc_search_url, params=params) # if response.ok: # return response.json()["hits"] # else: return [] # query = st.text_input("Enter a LOINC code:") # if query: # st.write(f"Search results for '{query}':") # results = search_loinc_codes(query) # for result in results: # st.write(f"{result['code']} - {result['display']}") # st.write(f"{result['system']}#{result['code']}") # # Allow the user to select a LOINC code # if len(results) == 1: # selected_code = results[0]["code"] # else: # selected_code = st.selectbox("Select a LOINC code:", [result["code"] for result in results]) # # Render the Exercise Assessment using the selected LOINC code # st.write(f"Selected LOINC code: {selected_code}") # anixety_questionnaire_response_id = f"{anixety_response_prefix}-{selected_code}" # anixety_questionnaire_response = QuestionnaireResponse( # questionnaire=FHIRReference(f"Questionnaire/{anixety_questionnaire_id}"), # status="in-progress", # subject=FHIRReference("Patient/example") # ) # anixety_questionnaire_response.identifier = [{"value": anixety_questionnaire_id}] # anixety_questionnaire_response.item = [ # { # "linkId": "1", # "text": "How many minutes of aerobic exercise did you do today?", # "type": "integer" # }, # { # "linkId": "2", # "text": "How many minutes of strength training did you do today?", # "type": "integer" # } # ] # st.write("Exercise Assessment:") # st.json(anixety_questionnaire_response.as_json()) # # Save the Exercise Assessment to the FHIR server # fhir_client = FHIRClient(settings={"app_id": "my_web_app", "api_base": fhir_server_url}) # fhir_client.create(anixety_questionnaire_response)