Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import base64 | |
# Define function to read CSV file | |
def read_data(): | |
data = pd.read_csv("health_conditions.csv") | |
return data | |
# Define function to update CSV file | |
def update_data(data): | |
data.to_csv("health_conditions.csv", index=False) | |
# Define function to display data | |
def display_data(data): | |
st.write(data) | |
# Define function to add new data | |
def add_data(data, new_data): | |
data = pd.concat([data, new_data], ignore_index=True) | |
return data | |
# Define function to delete data | |
def delete_data(data, indices): | |
data = data.drop(indices, axis=0) | |
data = data.reset_index(drop=True) | |
return data | |
# Define function to download data as CSV file | |
def download_data(data): | |
csv = data.to_csv(index=False) | |
href = f'<a href="data:file/csv;base64,{base64.b64encode(csv.encode()).decode()}" download="health_conditions.csv">Download CSV file</a>' | |
return href | |
def create_phq9_questions(): | |
questions = [ | |
{"question": "Little interest or pleasure in doing things", "icd10": "F32.1"}, | |
{"question": "Feeling down, depressed, or hopeless", "icd10": "F32.1"}, | |
{"question": "Trouble falling or staying asleep, or sleeping too much", "icd10": "F32.1"}, | |
{"question": "Feeling tired or having little energy", "icd10": "F32.1"}, | |
{"question": "Poor appetite or overeating", "icd10": "F32.1"}, | |
{"question": "Feeling bad about yourself β or that you are a failure or have let yourself or your family down", "icd10": "F32.1"}, | |
{"question": "Trouble concentrating on things, such as reading the newspaper or watching television", "icd10": "F32.1"}, | |
{"question": "Moving or speaking so slowly that other people could have noticed? Or the opposite β being so fidgety or restless that you have been moving around a lot more than usual", "icd10": "F32.1"}, | |
{"question": "Thoughts that you would be better off dead or of hurting yourself in some way", "icd10": "F32.1"} | |
] | |
return questions | |
# Define main function | |
def main(): | |
st.title("Health Condition Costs Visualization") | |
data = read_data() | |
display_data(data) | |
st.write("To add new data, please fill in the form below:") | |
condition = st.text_input("Condition") | |
icd10_code = st.text_input("ICD10 Code") | |
snomed_code = st.text_input("SNOMED Code") | |
loinc_code = st.text_input("LOINC Code") | |
assessment = st.text_input("Assessment") | |
if st.button("Add"): | |
new_data = pd.DataFrame({ | |
"condition": [condition], | |
"ICD10_code": [icd10_code], | |
"SNOMED_code": [snomed_code], | |
"LOINC_code": [loinc_code], | |
"assessment": [assessment] | |
}) | |
data = add_data(data, new_data) | |
update_data(data) | |
indices = [] | |
for i, row in data.iterrows(): | |
if st.checkbox(f"Delete row {i+1}"): | |
indices.append(i) | |
if len(indices) > 0: | |
data = delete_data(data, indices) | |
update_data(data) | |
st.markdown(download_data(data), unsafe_allow_html=True) | |
# Get the PHQ9 questions | |
questions = create_phq9_questions() | |
# Display each question and an input text field for the answer | |
for question in questions: | |
st.markdown(question["question"]) | |
answer = st.text_input("Your Answer:") | |
if __name__ == "__main__": | |
main() | |