File size: 3,712 Bytes
d23da4a
 
 
 
 
 
 
 
 
 
 
c84ee12
 
 
 
 
 
 
 
d23da4a
c84ee12
 
 
 
 
d23da4a
 
c84ee12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d23da4a
c84ee12
 
 
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

import streamlit as st
import hl7
import os
import csv

st.markdown("""
Prompt:
Write a streamlit python program that uses the python hl7 library to render a clinical terminology based assessment with LOINC, ICD10, CPT, and SNOMED code types and codes for an assessment user interface that asks four questions:  1) Choose a Gender (M/F), 2) Choose an age group ["Age0to18","Age19to44","Age44to64","Age64to84", "Age85andOver"], 3) What is the diastolic blood pressure?, 4) What is the systolic blood pressure?  For the interface have user controls on the sidebar.  In the center area have a text file named FHIR-ASMT.csv store the fields each time the user submits using a button labeled Save.  Each time reload the file and show it as a table in the center area.  Instrument the questions and answers with their corresponding clinical terminology type and code.  If the file is not created yet on reading it, create the file as an empty CSV with just the column headers in CSV format.  Include a python list dictionary with the map of the clinical terminology code types and codes for each question and the overall blood pressure clinical terminology code type and codes.
""")




import streamlit as st
import pandas as pd
import hl7

# Define the clinical terminology map
clinical_terminology_map = {
    'gender': {'LOINC': '76690-1', 'code_system': 'http://loinc.org'},
    'age': {'LOINC': '21840-4', 'code_system': 'http://loinc.org'},
    'diastolic_blood_pressure': {'SNOMED-CT': '16303008', 'code_system': 'http://snomed.info/sct'},
    'systolic_blood_pressure': {'SNOMED-CT': '271649006', 'code_system': 'http://snomed.info/sct'},
    'blood_pressure': {'LOINC': '85354-9', 'code_system': 'http://loinc.org'}
}

# Define a function to read the data from the CSV file
def read_data():
    try:
        df = pd.read_csv('FHIR-ASMT.csv')
    except FileNotFoundError:
        df = pd.DataFrame(columns=['Gender', 'Age', 'Diastolic Blood Pressure', 'Systolic Blood Pressure'])
    return df

# Define the Streamlit user interface
def app():
    st.sidebar.header('Assessment Questions')

    # Gender
    st.sidebar.subheader('Choose a Gender')
    gender = st.sidebar.radio('', ('M', 'F'))
    gender_code_type, gender_code = list(clinical_terminology_map['gender'].items())[0]

    # Age
    st.sidebar.subheader('Choose an age group')
    age_group = st.sidebar.selectbox('', ['Age0to18', 'Age19to44', 'Age44to64', 'Age64to84', 'Age85andOver'])
    age_code_type, age_code = list(clinical_terminology_map['age'].items())[0]

    # Diastolic blood pressure
    st.sidebar.subheader('What is the diastolic blood pressure?')
    diastolic_bp = st.sidebar.number_input('', value=0, step=1)
    diastolic_bp_code_type, diastolic_bp_code = list(clinical_terminology_map['diastolic_blood_pressure'].items())[0]

    # Systolic blood pressure
    st.sidebar.subheader('What is the systolic blood pressure?')
    systolic_bp = st.sidebar.number_input('', value=0, step=1)
    systolic_bp_code_type, systolic_bp_code = list(clinical_terminology_map['systolic_blood_pressure'].items())[0]

    # Save button
    if st.sidebar.button('Save'):
        df = read_data()

                # Append the new data to the dataframe
        new_data = {'Gender': gender, 'Age': age_group, 'Diastolic Blood Pressure': diastolic_bp,
                    'Systolic Blood Pressure': systolic_bp}
        df = df.append(new_data, ignore_index=True)

        # Save the dataframe to the CSV file
        df.to_csv('FHIR-ASMT.csv', index=False)

    # Show the current data
    st.header('Assessment Data')
    data = read_data()
    if not data.empty:
        st.write(data)
    else:
        st.write('No data available')

app()