Spaces:
Sleeping
Sleeping
File size: 6,752 Bytes
40cbaf1 9188f50 0a5028c 415a9d1 9188f50 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
import streamlit as st
import pandas as pd
import datetime as dt
import matplotlib.pyplot as plt
# Function to load data
@st.cache
def load_data(file):
df = pd.read_csv(file)
df['Date of Birth'] = pd.to_datetime(df['Date of Birth'])
df['Age'] = (pd.Timestamp.now() - df['Date of Birth']).astype('<m8[Y]')
df['Visit Date'] = pd.to_datetime(df['Visit Date'])
return df
# Sidebar: Upload CSV file
uploaded_file = st.sidebar.file_uploader("Upload Patient Data CSV", type="csv")
if uploaded_file:
df = load_data(uploaded_file)
# Sidebar: Select or create patient
action = st.sidebar.selectbox("Action", ["Select Patient", "Create New Patient"])
if action == "Select Patient":
patient_id = st.sidebar.selectbox("Patient ID", df['Patient ID'].unique())
# Display patient data
patient_data = df[df['Patient ID'] == patient_id]
st.header("General Information")
st.write(f"**Patient ID:** {patient_id}")
st.write(f"**Name:** {patient_data.iloc[0]['Patient Name']}")
st.write(f"**Date of Birth:** {patient_data.iloc[0]['Date of Birth'].strftime('%Y-%m-%d')}")
st.write(f"**Age:** {patient_data.iloc[0]['Age']}")
st.write(f"**Gender:** {patient_data.iloc[0]['Gender']}")
st.write(f"**Medical History:** {patient_data.iloc[0]['Medical History']}")
st.write(f"**Allergies:** {patient_data.iloc[0]['Allergies']}")
# Graphs of medical data
st.header("Medical Data Over Time")
fig, ax = plt.subplots(2, 2, figsize=(12, 8))
ax[0, 0].plot(patient_data['Visit Date'], patient_data['Systolic BP'])
ax[0, 0].set_title("Systolic Blood Pressure")
ax[0, 1].plot(patient_data['Visit Date'], patient_data['Glucose'])
ax[0, 1].set_title("Glucose")
ax[1, 0].plot(patient_data['Visit Date'], patient_data['Cholesterol'])
ax[1, 0].set_title("Cholesterol")
ax[1, 1].plot(patient_data['Visit Date'], patient_data['Hemoglobin'])
ax[1, 1].set_title("Hemoglobin")
st.pyplot(fig)
# Dropdown menu of previous visits
st.header("Previous Visits")
visit_date = st.selectbox("Select Visit Date", patient_data['Visit Date'].dt.strftime('%Y-%m-%d').unique())
visit_data = patient_data[patient_data['Visit Date'] == pd.to_datetime(visit_date)]
st.write(f"**Complaint:** {visit_data.iloc[0]['Complaint']}")
st.write(f"**Physical Examination:** {visit_data.iloc[0]['Physical Examination']}")
st.write(f"**Systolic BP:** {visit_data.iloc[0]['Systolic BP']}")
st.write(f"**Diastolic BP:** {visit_data.iloc[0]['Diastolic BP']}")
st.write(f"**Temperature:** {visit_data.iloc[0]['Temperature']}")
st.write(f"**Glucose:** {visit_data.iloc[0]['Glucose']}")
st.write(f"**Cholesterol:** {visit_data.iloc[0]['Cholesterol']}")
st.write(f"**Hemoglobin:** {visit_data.iloc[0]['Hemoglobin']}")
st.write(f"**Other Notes:** {visit_data.iloc[0]['Other Notes']}")
# Current visit input
st.header("Current Visit")
with st.form("current_visit_form"):
new_visit_date = st.date_input("Visit Date", dt.date.today())
complaint = st.text_area("Complaint")
physical_exam = st.text_area("Physical Examination")
systolic_bp = st.number_input("Systolic Blood Pressure", min_value=0)
diastolic_bp = st.number_input("Diastolic Blood Pressure", min_value=0)
temperature = st.number_input("Temperature", min_value=0.0, format="%.1f")
glucose = st.number_input("Glucose", min_value=0)
cholesterol = st.number_input("Cholesterol", min_value=0)
hemoglobin = st.number_input("Hemoglobin", min_value=0)
other_notes = st.text_area("Other Notes")
submitted = st.form_submit_button("Add Entry")
if submitted:
new_entry = {
"Patient ID": patient_id,
"Patient Name": patient_data.iloc[0]['Patient Name'],
"Date of Birth": patient_data.iloc[0]['Date of Birth'],
"Age": patient_data.iloc[0]['Age'],
"Gender": patient_data.iloc[0]['Gender'],
"Medical History": patient_data.iloc[0]['Medical History'],
"Allergies": patient_data.iloc[0]['Allergies'],
"Visit Date": new_visit_date,
"Complaint": complaint,
"Physical Examination": physical_exam,
"Systolic BP": systolic_bp,
"Diastolic BP": diastolic_bp,
"Temperature": temperature,
"Glucose": glucose,
"Cholesterol": cholesterol,
"Hemoglobin": hemoglobin,
"Other Notes": other_notes,
}
df = df.append(new_entry, ignore_index=True)
df.to_csv(uploaded_file, index=False)
st.success("New visit entry added successfully!")
elif action == "Create New Patient":
st.header("Create New Patient Account")
with st.form("new_patient_form"):
new_patient_id = st.text_input("Patient ID")
new_patient_name = st.text_input("Patient Name")
new_dob = st.date_input("Date of Birth")
new_age = (pd.Timestamp.now() - pd.to_datetime(new_dob)).days // 365
new_gender = st.selectbox("Gender", ["Male", "Female", "Other"])
new_med_history = st.text_area("Medical History")
new_allergies = st.text_area("Allergies")
new_submitted = st.form_submit_button("Add New Patient")
if new_submitted:
new_patient = {
"Patient ID": new_patient_id,
"Patient Name": new_patient_name,
"Date of Birth": new_dob,
"Age": new_age,
"Gender": new_gender,
"Medical History": new_med_history,
"Allergies": new_allergies,
"Visit Date": None,
"Complaint": None,
"Physical Examination": None,
"Systolic BP": None,
"Diastolic BP": None,
"Temperature": None,
"Glucose": None,
"Cholesterol": None,
"Hemoglobin": None,
"Other Notes": None,
}
df = df.append(new_patient, ignore_index=True)
df.to_csv(uploaded_file, index=False)
st.success("New patient account created successfully!")
|