import streamlit as st import pandas as pd # 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'Download CSV file' return href # 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) if __name__ == "__main__": main()