Spaces:
Runtime error
Runtime error
#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. Avoid an error in line File "/home/user/app/app.py", line 36, in <module> | |
# gender_code_type, gender_code = clinical_terminology_map['gender'].items() of ValueError too many values to unpack after clicking save | |
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. | |
""") | |
# User controls on the sidebar | |
st.sidebar.title("User control") | |
gender = st.sidebar.selectbox("Choose a gender", ["M", "F"]) | |
age_group = st.sidebar.selectbox("Choose an age group", ["Age0to18", "Age19to44", "Age44to64", "Age64to84", "Age85andOver"]) | |
diastolic_bp = st.sidebar.number_input("What is the Diastolic Blood Pressure?") | |
systolic_bp = st.sidebar.number_input("What is the Systolic Blood Pressure?") | |
# Clinical Terminology code types and codes | |
clinical_terminology_map = { | |
'gender': {'LOINC': ['8450-9', '11884-4'], 'ICD10': ['Z56.9'], 'CPT': [], 'SNOMED': ['263495006']}, | |
'age_group': {'LOINC': ['3141-9', '8302-2', '8462-4', '8480-6', '8486-3'], 'ICD10': [], 'CPT': [], 'SNOMED': ['259200006', '246075003', '370115009', '370116005', '370117002']}, | |
'diastolic_bp': {'LOINC': ['8462-4'], 'ICD10': [], 'CPT': [], 'SNOMED': ['182558007']}, | |
'systolic_bp': {'LOINC': ['8480-6'], 'ICD10': [], 'CPT': [], 'SNOMED': ['182557006']}, | |
'Blood_pressure': {'LOINC': ['55284-4'], 'ICD10': [], 'CPT': [], 'SNOMED': ['271649006']} | |
} | |
# Save button and CSV file | |
st.title("FHIR-ASMT") | |
if st.button("Save"): | |
file_name = 'FHIR-ASMT.csv' | |
if os.path.exists(file_name): | |
with open(file_name, 'a', newline='') as f: | |
writer = csv.writer(f) | |
# Get the code type and code corresponding to each user input | |
gender_code_type, gender_code = clinical_terminology_map['gender'].items() | |
age_group_code_type, age_group_code = clinical_terminology_map['age_group'].items() | |
diastolic_bp_code_type, diastolic_bp_code = clinical_terminology_map['diastolic_bp'].items() | |
systolic_bp_code_type, systolic_bp_code = clinical_terminology_map['systolic_bp'].items() | |
bp_code_type, bp_code = clinical_terminology_map['Blood_pressure'].items() | |
# Write all the fields in the CSV | |
writer.writerow([gender, age_group, diastolic_bp, systolic_bp, | |
gender_code_type, gender_code[0], | |
age_group_code_type, age_group_code[0], | |
diastolic_bp_code_type, diastolic_bp_code[0], | |
systolic_bp_code_type, systolic_bp_code[0], | |
bp_code_type, bp_code[0]]) | |
else: | |
# Create the CSV file with column headers | |
with open(file_name, 'w', newline='') as f: | |
writer = csv.writer(f) | |
writer.writerow(['Gender', 'Age Group', 'Diastolic BP', 'Systolic BP', | |
'Gender Code Type', 'Gender Code', | |
'Age Group Code Type', 'Age Group Code', | |
'Diastolic BP Code Type', 'Diastolic BP Code', | |
'Systolic BP Code Type', 'Systolic BP Code', | |
'Blood Pressure Code Type', 'Blood Pressure Code']) | |
# Read and display the CSV file | |
if os.path.exists('FHIR-ASMT.csv'): | |
with open('FHIR-ASMT.csv', 'r') as f: | |
reader = csv.reader(f) | |
data = list(reader) | |
if len(data) > 1: | |
st.dataframe(data[1:], data[0]) |