awacke1's picture
Update app.py
50f3518
raw
history blame
7.51 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
""")
def ShowDiabetesAssessment():
st.markdown("""
# Diabetes Assessment with Code Mapping:
## By asking these questions and conducting appropriate tests, healthcare professionals can determine the risk factors for diabetes and pre-diabetes and develop an appropriate treatment plan.
Medical History: Knowing a person's medical history is important in determining the risk factors for diabetes. Questions may include:
Have you ever been diagnosed with diabetes before? (ICD10 code: E11.-)
Have any of your family members been diagnosed with diabetes? (ICD10 code: Z83.3)
Have you been diagnosed with gestational diabetes during pregnancy? (ICD10 code: O24.4-)
Lifestyle Factors: Lifestyle factors such as physical activity, diet, and smoking can also play a role in determining the risk for diabetes. Questions may include:
How often do you engage in physical activity? (LOINC code: 8692-2)
What types of foods do you typically eat? (LOINC code: 62392-6)
Do you smoke or use tobacco products? (SNOMED code: 77176002)
Physical Exam: A physical exam can help identify risk factors for diabetes. Questions may include:
What is your body mass index (BMI)? (LOINC code: 39156-5)
Have you noticed any changes in your vision or eye health? (ICD10 code: H36.9)
Have you experienced any numbness or tingling in your hands or feet? (ICD10 code: R20.2)
Laboratory Tests: Laboratory tests can help diagnose diabetes and identify risk factors. Questions may include:
Have you had a recent blood test to check your blood sugar levels? (LOINC code: 14749-6)
Have you had a test to check your HbA1c levels? (LOINC code: 4548-4)
Have you had a lipid profile test to check your cholesterol levels? (LOINC code: 24331-1)
Other Medical Conditions: Certain medical conditions can increase the risk for diabetes. Questions may include:
Have you been diagnosed with polycystic ovary syndrome (PCOS)? (ICD10 code: E28.2)
Do you have a history of heart disease? (ICD10 code: I25.10)
Have you been diagnosed with sleep apnea? (ICD10 code: G47.33)
""")
# 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')
ShowDiabetesAssessment()
# 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()