Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,96 +31,102 @@ if uploaded_file:
|
|
31 |
|
32 |
# Display patient data
|
33 |
patient_data = df[df['Patient ID'] == patient_id]
|
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 |
elif action == "Create New Patient":
|
126 |
st.header("Create New Patient Account")
|
|
|
31 |
|
32 |
# Display patient data
|
33 |
patient_data = df[df['Patient ID'] == patient_id]
|
34 |
+
if not patient_data.empty:
|
35 |
+
st.header("General Information")
|
36 |
+
st.write(f"**Patient ID:** {patient_id}")
|
37 |
+
st.write(f"**Name:** {patient_data.iloc[0]['Patient Name']}")
|
38 |
+
st.write(f"**Date of Birth:** {patient_data.iloc[0]['Date of Birth'].strftime('%Y-%m-%d')}")
|
39 |
+
st.write(f"**Age:** {patient_data.iloc[0]['Age']}")
|
40 |
+
st.write(f"**Gender:** {patient_data.iloc[0]['Gender']}")
|
41 |
+
st.write(f"**Medical History:** {patient_data.iloc[0]['Medical History']}")
|
42 |
+
st.write(f"**Allergies:** {patient_data.iloc[0]['Allergies']}")
|
43 |
|
44 |
+
# Graphs of medical data
|
45 |
+
st.header("Medical Data Over Time")
|
46 |
+
fig, ax = plt.subplots(2, 2, figsize=(12, 8))
|
47 |
+
ax[0, 0].plot(patient_data['Visit Date'], patient_data['Systolic BP'])
|
48 |
+
ax[0, 0].set_title("Systolic Blood Pressure")
|
49 |
+
ax[0, 1].plot(patient_data['Visit Date'], patient_data['Glucose'])
|
50 |
+
ax[0, 1].set_title("Glucose")
|
51 |
+
ax[1, 0].plot(patient_data['Visit Date'], patient_data['Cholesterol'])
|
52 |
+
ax[1, 0].set_title("Cholesterol")
|
53 |
+
ax[1, 1].plot(patient_data['Visit Date'], patient_data['Hemoglobin'])
|
54 |
+
ax[1, 1].set_title("Hemoglobin")
|
55 |
+
st.pyplot(fig)
|
56 |
|
57 |
+
# Current visit input
|
58 |
+
st.header("Current Visit")
|
59 |
+
with st.form("current_visit_form"):
|
60 |
+
new_visit_date = st.date_input("Visit Date", dt.date.today())
|
61 |
+
complaint = st.text_area("Complaint")
|
62 |
+
physical_exam = st.text_area("Physical Examination")
|
63 |
+
systolic_bp = st.number_input("Systolic Blood Pressure", min_value=0)
|
64 |
+
diastolic_bp = st.number_input("Diastolic Blood Pressure", min_value=0)
|
65 |
+
temperature = st.number_input("Temperature", min_value=0.0, format="%.1f")
|
66 |
+
glucose = st.number_input("Glucose", min_value=0)
|
67 |
+
cholesterol = st.number_input("Cholesterol", min_value=0)
|
68 |
+
hemoglobin = st.number_input("Hemoglobin", min_value=0)
|
69 |
+
other_notes = st.text_area("Other Notes")
|
70 |
+
submitted = st.form_submit_button("Add Entry")
|
71 |
+
if submitted:
|
72 |
+
new_entry = {
|
73 |
+
"Patient ID": patient_id,
|
74 |
+
"Patient Name": patient_data.iloc[0]['Patient Name'],
|
75 |
+
"Date of Birth": patient_data.iloc[0]['Date of Birth'],
|
76 |
+
"Age": patient_data.iloc[0]['Age'],
|
77 |
+
"Gender": patient_data.iloc[0]['Gender'],
|
78 |
+
"Medical History": patient_data.iloc[0]['Medical History'],
|
79 |
+
"Allergies": patient_data.iloc[0]['Allergies'],
|
80 |
+
"Visit Date": new_visit_date,
|
81 |
+
"Complaint": complaint,
|
82 |
+
"Physical Examination": physical_exam,
|
83 |
+
"Systolic BP": systolic_bp,
|
84 |
+
"Diastolic BP": diastolic_bp,
|
85 |
+
"Temperature": temperature,
|
86 |
+
"Glucose": glucose,
|
87 |
+
"Cholesterol": cholesterol,
|
88 |
+
"Hemoglobin": hemoglobin,
|
89 |
+
"Other Notes": other_notes,
|
90 |
+
}
|
91 |
+
df = pd.concat([df, pd.DataFrame([new_entry])], ignore_index=True)
|
92 |
|
93 |
+
# Save the updated data to CSV
|
94 |
+
buffer = io.StringIO()
|
95 |
+
df.to_csv(buffer, index=False)
|
96 |
+
buffer.seek(0)
|
97 |
+
bytes_data = io.BytesIO(buffer.getvalue().encode('utf-8'))
|
98 |
+
st.success("New visit entry added successfully!")
|
99 |
|
100 |
+
# Reload data
|
101 |
+
df = load_data(io.StringIO(buffer.getvalue()))
|
102 |
+
patient_data = df[df['Patient ID'] == patient_id]
|
103 |
|
104 |
+
# Download button (moved outside the form)
|
105 |
+
st.download_button(
|
106 |
+
label="Download Updated Data",
|
107 |
+
data=bytes_data,
|
108 |
+
file_name="updated_patient_data.csv",
|
109 |
+
mime="text/csv"
|
110 |
+
)
|
111 |
|
112 |
+
# Dropdown menu of previous visits
|
113 |
+
st.header("Previous Visits")
|
114 |
+
visit_date = st.selectbox("Select Visit Date", patient_data['Visit Date'].dt.strftime('%Y-%m-%d').unique())
|
115 |
+
visit_data = patient_data[patient_data['Visit Date'] == pd.to_datetime(visit_date)]
|
116 |
+
if not visit_data.empty:
|
117 |
+
st.write(f"**Complaint:** {visit_data.iloc[0]['Complaint']}")
|
118 |
+
st.write(f"**Physical Examination:** {visit_data.iloc[0]['Physical Examination']}")
|
119 |
+
st.write(f"**Systolic BP:** {visit_data.iloc[0]['Systolic BP']}")
|
120 |
+
st.write(f"**Diastolic BP:** {visit_data.iloc[0]['Diastolic BP']}")
|
121 |
+
st.write(f"**Temperature:** {visit_data.iloc[0]['Temperature']}")
|
122 |
+
st.write(f"**Glucose:** {visit_data.iloc[0]['Glucose']}")
|
123 |
+
st.write(f"**Cholesterol:** {visit_data.iloc[0]['Cholesterol']}")
|
124 |
+
st.write(f"**Hemoglobin:** {visit_data.iloc[0]['Hemoglobin']}")
|
125 |
+
st.write(f"**Other Notes:** {visit_data.iloc[0]['Other Notes']}")
|
126 |
+
else:
|
127 |
+
st.write("No visit data available for the selected date.")
|
128 |
+
else:
|
129 |
+
st.write("No patient data available.")
|
130 |
|
131 |
elif action == "Create New Patient":
|
132 |
st.header("Create New Patient Account")
|