awacke1 commited on
Commit
c84ee12
Β·
1 Parent(s): 251a107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -50
app.py CHANGED
@@ -9,57 +9,72 @@ Prompt:
9
  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.
10
  """)
11
 
12
- # User controls on the sidebar
13
- st.sidebar.title("User control")
14
- gender = st.sidebar.selectbox("Choose a gender", ["M", "F"])
15
- age_group = st.sidebar.selectbox("Choose an age group", ["Age0to18", "Age19to44", "Age44to64", "Age64to84", "Age85andOver"])
16
- diastolic_bp = st.sidebar.number_input("What is the Diastolic Blood Pressure?")
17
- systolic_bp = st.sidebar.number_input("What is the Systolic Blood Pressure?")
18
-
19
- # Clinical Terminology code types and codes
20
  clinical_terminology_map = {
21
- 'gender': {'LOINC': ['8450-9', '11884-4'], 'ICD10': ['Z56.9'], 'CPT': [], 'SNOMED': ['263495006']},
22
- 'age_group': {'LOINC': ['3141-9', '8302-2', '8462-4', '8480-6', '8486-3'], 'ICD10': [], 'CPT': [], 'SNOMED': ['259200006', '246075003', '370115009', '370116005', '370117002']},
23
- 'diastolic_bp': {'LOINC': ['8462-4'], 'ICD10': [], 'CPT': [], 'SNOMED': ['182558007']},
24
- 'systolic_bp': {'LOINC': ['8480-6'], 'ICD10': [], 'CPT': [], 'SNOMED': ['182557006']},
25
- 'Blood_pressure': {'LOINC': ['55284-4'], 'ICD10': [], 'CPT': [], 'SNOMED': ['271649006']}
26
  }
27
 
28
- # Save button and CSV file
29
- st.title("FHIR-ASMT")
30
- if st.button("Save"):
31
- file_name = 'FHIR-ASMT.csv'
32
- if os.path.exists(file_name):
33
- with open(file_name, 'a', newline='') as f:
34
- writer = csv.writer(f)
35
- # Get the code type and code corresponding to each user input
36
- gender_code_type, gender_code = clinical_terminology_map['gender'].items()
37
- age_group_code_type, age_group_code = clinical_terminology_map['age_group'].items()
38
- diastolic_bp_code_type, diastolic_bp_code = clinical_terminology_map['diastolic_bp'].items()
39
- systolic_bp_code_type, systolic_bp_code = clinical_terminology_map['systolic_bp'].items()
40
- bp_code_type, bp_code = clinical_terminology_map['Blood_pressure'].items()
41
- # Write all the fields in the CSV
42
- writer.writerow([gender, age_group, diastolic_bp, systolic_bp,
43
- gender_code_type, gender_code[0],
44
- age_group_code_type, age_group_code[0],
45
- diastolic_bp_code_type, diastolic_bp_code[0],
46
- systolic_bp_code_type, systolic_bp_code[0],
47
- bp_code_type, bp_code[0]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  else:
49
- # Create the CSV file with column headers
50
- with open(file_name, 'w', newline='') as f:
51
- writer = csv.writer(f)
52
- writer.writerow(['Gender', 'Age Group', 'Diastolic BP', 'Systolic BP',
53
- 'Gender Code Type', 'Gender Code',
54
- 'Age Group Code Type', 'Age Group Code',
55
- 'Diastolic BP Code Type', 'Diastolic BP Code',
56
- 'Systolic BP Code Type', 'Systolic BP Code',
57
- 'Blood Pressure Code Type', 'Blood Pressure Code'])
58
-
59
- # Read and display the CSV file
60
- if os.path.exists('FHIR-ASMT.csv'):
61
- with open('FHIR-ASMT.csv', 'r') as f:
62
- reader = csv.reader(f)
63
- data = list(reader)
64
- if len(data) > 1:
65
- st.dataframe(data[1:], data[0])
 
9
  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.
10
  """)
11
 
12
+
13
+
14
+
15
+ import streamlit as st
16
+ import pandas as pd
17
+ import hl7
18
+
19
+ # Define the clinical terminology map
20
  clinical_terminology_map = {
21
+ 'gender': {'LOINC': '76690-1', 'code_system': 'http://loinc.org'},
22
+ 'age': {'LOINC': '21840-4', 'code_system': 'http://loinc.org'},
23
+ 'diastolic_blood_pressure': {'SNOMED-CT': '16303008', 'code_system': 'http://snomed.info/sct'},
24
+ 'systolic_blood_pressure': {'SNOMED-CT': '271649006', 'code_system': 'http://snomed.info/sct'},
25
+ 'blood_pressure': {'LOINC': '85354-9', 'code_system': 'http://loinc.org'}
26
  }
27
 
28
+ # Define a function to read the data from the CSV file
29
+ def read_data():
30
+ try:
31
+ df = pd.read_csv('FHIR-ASMT.csv')
32
+ except FileNotFoundError:
33
+ df = pd.DataFrame(columns=['Gender', 'Age', 'Diastolic Blood Pressure', 'Systolic Blood Pressure'])
34
+ return df
35
+
36
+ # Define the Streamlit user interface
37
+ def app():
38
+ st.sidebar.header('Assessment Questions')
39
+
40
+ # Gender
41
+ st.sidebar.subheader('Choose a Gender')
42
+ gender = st.sidebar.radio('', ('M', 'F'))
43
+ gender_code_type, gender_code = list(clinical_terminology_map['gender'].items())[0]
44
+
45
+ # Age
46
+ st.sidebar.subheader('Choose an age group')
47
+ age_group = st.sidebar.selectbox('', ['Age0to18', 'Age19to44', 'Age44to64', 'Age64to84', 'Age85andOver'])
48
+ age_code_type, age_code = list(clinical_terminology_map['age'].items())[0]
49
+
50
+ # Diastolic blood pressure
51
+ st.sidebar.subheader('What is the diastolic blood pressure?')
52
+ diastolic_bp = st.sidebar.number_input('', value=0, step=1)
53
+ diastolic_bp_code_type, diastolic_bp_code = list(clinical_terminology_map['diastolic_blood_pressure'].items())[0]
54
+
55
+ # Systolic blood pressure
56
+ st.sidebar.subheader('What is the systolic blood pressure?')
57
+ systolic_bp = st.sidebar.number_input('', value=0, step=1)
58
+ systolic_bp_code_type, systolic_bp_code = list(clinical_terminology_map['systolic_blood_pressure'].items())[0]
59
+
60
+ # Save button
61
+ if st.sidebar.button('Save'):
62
+ df = read_data()
63
+
64
+ # Append the new data to the dataframe
65
+ new_data = {'Gender': gender, 'Age': age_group, 'Diastolic Blood Pressure': diastolic_bp,
66
+ 'Systolic Blood Pressure': systolic_bp}
67
+ df = df.append(new_data, ignore_index=True)
68
+
69
+ # Save the dataframe to the CSV file
70
+ df.to_csv('FHIR-ASMT.csv', index=False)
71
+
72
+ # Show the current data
73
+ st.header('Assessment Data')
74
+ data = read_data()
75
+ if not data.empty:
76
+ st.write(data)
77
  else:
78
+ st.write('No data available')
79
+
80
+ app()