netflypsb commited on
Commit
1b2207b
·
verified ·
1 Parent(s): c58b33a

Update app.py

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