awacke1's picture
Update app.py
4651dc4
raw
history blame
5.45 kB
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
def diabetes_code_lookup(code):
# LOINC codes related to diabetes
loinc_codes = {
'14771-0': 'Glucose [Mass/volume] in Blood',
'49642-8': 'Hemoglobin A1c/Hemoglobin.total in Blood',
'2345-7': 'Glucose [Mass/volume] in Serum or Plasma',
# Add more LOINC codes related to diabetes here
}
# SNOMED-CT codes related to diabetes
snomed_codes = {
'73211009': 'Diabetes mellitus (disorder)',
'15777000': 'Insulin-dependent diabetes mellitus (disorder)',
'44054006': 'Non-insulin dependent diabetes mellitus (disorder)',
# Add more SNOMED-CT codes related to diabetes here
}
# ICD-10 codes related to diabetes
icd_codes = {
'E10.9': 'Type 1 diabetes mellitus without complications',
'E11.9': 'Type 2 diabetes mellitus without complications',
'E08.9': 'Diabetes mellitus due to an underlying condition without complications',
# Add more ICD-10 codes related to diabetes here
}
# Look up the code in each dictionary
loinc_desc = loinc_codes.get(code, 'Code not found')
snomed_desc = snomed_codes.get(code, 'Code not found')
icd_desc = icd_codes.get(code, 'Code not found')
# Display the results
st.markdown(f'### LOINC code {code}: {loinc_desc}')
st.markdown(f'### SNOMED-CT code {code}: {snomed_desc}')
st.markdown(f'### ICD-10 code {code}: {icd_desc}')
st.markdown("""
# Diabetes ICD10 Codes:
E10.9 - Type 1 diabetes mellitus without complications
E11.9 - Type 2 diabetes mellitus without complications
E08.9 - Diabetes mellitus due to an underlying condition without complications
E13.9 - Other specified diabetes mellitus without complications
E10.65 - Type 1 diabetes mellitus with hyperglycemia
E11.65 - Type 2 diabetes mellitus with hyperglycemia
E08.65 - Diabetes mellitus due to an underlying condition with hyperglycemia
E13.65 - Other specified diabetes mellitus with hyperglycemia
""")
# 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()
diabetes_code_lookup('E11.9')
# Display each question and an input text field for the answer
keycount=0
for question in questions:
keycount+=1
st.markdown(question["question"])
answer = st.text_input("Your Answer:". key=str(keycount))
if __name__ == "__main__":
main()