Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,66 +2,134 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
st.
|
| 25 |
-
st.
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
st.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
st.
|
| 39 |
-
|
| 40 |
-
# Line Chart for
|
| 41 |
-
fig = px.line(patient_data, x='date', y='
|
| 42 |
-
st.plotly_chart(fig)
|
| 43 |
-
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
st.
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
st.
|
| 58 |
-
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
from datetime import datetime
|
| 6 |
|
| 7 |
+
# Function to load patient data
|
| 8 |
+
def load_data():
|
| 9 |
+
return pd.read_csv('patient_data.csv')
|
| 10 |
+
|
| 11 |
+
# Function to save patient data
|
| 12 |
+
def save_data(df):
|
| 13 |
+
df.to_csv('patient_data.csv', index=False)
|
| 14 |
+
|
| 15 |
+
# Load the existing data
|
| 16 |
+
df = load_data()
|
| 17 |
+
|
| 18 |
+
# Sidebar for navigation
|
| 19 |
+
st.sidebar.title("Navigation")
|
| 20 |
+
options = ["View Patient Data", "Add New Patient", "Add New Visit"]
|
| 21 |
+
choice = st.sidebar.selectbox("Choose an option", options)
|
| 22 |
+
|
| 23 |
+
if choice == "View Patient Data":
|
| 24 |
+
# Sidebar for Patient Selection
|
| 25 |
+
st.sidebar.header('Select Patient')
|
| 26 |
+
patient_id = st.sidebar.selectbox('Patient ID', df['patient_id'].unique())
|
| 27 |
+
|
| 28 |
+
# Filter Data for Selected Patient
|
| 29 |
+
patient_data = df[df['patient_id'] == patient_id]
|
| 30 |
+
|
| 31 |
+
# Display Patient Profile
|
| 32 |
+
st.header('Patient Profile')
|
| 33 |
+
st.write(f"Name: {patient_data['name'].values[0]}")
|
| 34 |
+
st.write(f"Age: {patient_data['age'].values[0]}")
|
| 35 |
+
st.write(f"Gender: {patient_data['gender'].values[0]}")
|
| 36 |
+
st.write(f"Medical History: {patient_data['medical_history'].values[0]}")
|
| 37 |
+
|
| 38 |
+
# Visualization of Vital Signs
|
| 39 |
+
st.header('Vital Signs Over Time')
|
| 40 |
+
|
| 41 |
+
# Line Chart for Heart Rate
|
| 42 |
+
fig = px.line(patient_data, x='date', y='heart_rate', title='Heart Rate Over Time')
|
| 43 |
+
st.plotly_chart(fig)
|
| 44 |
+
|
| 45 |
+
# Line Chart for Blood Pressure
|
| 46 |
+
fig = px.line(patient_data, x='date', y='blood_pressure', title='Blood Pressure Over Time')
|
| 47 |
+
st.plotly_chart(fig)
|
| 48 |
+
|
| 49 |
+
# Line Chart for Blood Glucose
|
| 50 |
+
fig = px.line(patient_data, x='date', y='blood_glucose', title='Blood Glucose Over Time')
|
| 51 |
+
st.plotly_chart(fig)
|
| 52 |
+
|
| 53 |
+
# Dropdown for selecting specific visit details
|
| 54 |
+
st.header('Previous Visit Details')
|
| 55 |
+
selected_date = st.selectbox('Select Visit Date', patient_data['date'].unique())
|
| 56 |
+
selected_visit = patient_data[patient_data['date'] == selected_date]
|
| 57 |
+
|
| 58 |
+
st.write(f"**Visit Date:** {selected_date}")
|
| 59 |
+
st.write(f"Heart Rate: {selected_visit['heart_rate'].values[0]}")
|
| 60 |
+
st.write(f"Blood Pressure: {selected_visit['blood_pressure'].values[0]}")
|
| 61 |
+
st.write(f"Blood Glucose: {selected_visit['blood_glucose'].values[0]}")
|
| 62 |
+
|
| 63 |
+
# Alerts and Notifications
|
| 64 |
+
st.header('Alerts')
|
| 65 |
+
if selected_visit['heart_rate'].values[0] > 100:
|
| 66 |
+
st.error('High heart rate detected!')
|
| 67 |
+
if selected_visit['blood_pressure'].values[0] > 140:
|
| 68 |
+
st.error('High blood pressure detected!')
|
| 69 |
+
|
| 70 |
+
# Download Button for Patient Data
|
| 71 |
+
st.download_button(
|
| 72 |
+
label="Download Patient Data as CSV",
|
| 73 |
+
data=patient_data.to_csv().encode('utf-8'),
|
| 74 |
+
file_name=f'patient_{patient_id}_data.csv',
|
| 75 |
+
mime='text/csv',
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
elif choice == "Add New Patient":
|
| 79 |
+
st.header("Add New Patient")
|
| 80 |
+
|
| 81 |
+
# Input fields for new patient data
|
| 82 |
+
new_patient_id = st.number_input("Patient ID", min_value=0, step=1)
|
| 83 |
+
new_name = st.text_input("Name")
|
| 84 |
+
new_age = st.number_input("Age", min_value=0, step=1)
|
| 85 |
+
new_gender = st.selectbox("Gender", ["Male", "Female"])
|
| 86 |
+
new_medical_history = st.text_area("Medical History")
|
| 87 |
+
|
| 88 |
+
if st.button("Add Patient"):
|
| 89 |
+
new_patient_data = {
|
| 90 |
+
'patient_id': new_patient_id,
|
| 91 |
+
'name': new_name,
|
| 92 |
+
'age': new_age,
|
| 93 |
+
'gender': new_gender,
|
| 94 |
+
'medical_history': new_medical_history,
|
| 95 |
+
'date': None,
|
| 96 |
+
'heart_rate': None,
|
| 97 |
+
'blood_pressure': None,
|
| 98 |
+
'blood_glucose': None
|
| 99 |
+
}
|
| 100 |
+
df = df.append(new_patient_data, ignore_index=True)
|
| 101 |
+
save_data(df)
|
| 102 |
+
st.success("New patient added successfully!")
|
| 103 |
+
|
| 104 |
+
elif choice == "Add New Visit":
|
| 105 |
+
st.header("Add New Visit")
|
| 106 |
+
|
| 107 |
+
# Input fields for adding a new visit
|
| 108 |
+
patient_id = st.number_input("Patient ID", min_value=0, step=1)
|
| 109 |
+
visit_date = st.date_input("Date of Visit", value=datetime.today())
|
| 110 |
+
medical_complaints = st.text_area("Medical Complaints")
|
| 111 |
+
symptoms = st.text_area("Symptoms")
|
| 112 |
+
physical_examination = st.text_area("Physical Examination")
|
| 113 |
+
diagnosis = st.text_area("Diagnosis")
|
| 114 |
+
heart_rate = st.number_input("Heart Rate", min_value=0)
|
| 115 |
+
blood_pressure = st.number_input("Blood Pressure", min_value=0)
|
| 116 |
+
temperature = st.number_input("Temperature", min_value=0)
|
| 117 |
+
glucose = st.number_input("Blood Glucose", min_value=0)
|
| 118 |
+
extra_notes = st.text_area("Extra Notes")
|
| 119 |
+
treatment = st.text_area("Treatment")
|
| 120 |
+
|
| 121 |
+
if st.button("Add Visit"):
|
| 122 |
+
new_visit_data = {
|
| 123 |
+
'patient_id': patient_id,
|
| 124 |
+
'name': df[df['patient_id'] == patient_id]['name'].values[0],
|
| 125 |
+
'age': df[df['patient_id'] == patient_id]['age'].values[0],
|
| 126 |
+
'gender': df[df['patient_id'] == patient_id]['gender'].values[0],
|
| 127 |
+
'medical_history': df[df['patient_id'] == patient_id]['medical_history'].values[0],
|
| 128 |
+
'date': visit_date,
|
| 129 |
+
'heart_rate': heart_rate,
|
| 130 |
+
'blood_pressure': blood_pressure,
|
| 131 |
+
'blood_glucose': glucose,
|
| 132 |
+
}
|
| 133 |
+
df = df.append(new_visit_data, ignore_index=True)
|
| 134 |
+
save_data(df)
|
| 135 |
+
st.success("New visit added successfully!")
|