File size: 5,796 Bytes
40cbaf1
 
fc1a58d
 
415a9d1
fc1a58d
bb7fa0b
fc1a58d
 
9188f50
fc1a58d
bb7fa0b
fc1a58d
 
9188f50
fc1a58d
a17abe9
 
fc1a58d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import streamlit as st
import pandas as pd
import json
from datetime import datetime

# Function to load patient data from JSON
def load_data():
    with open('data.json', 'r') as f:
        return pd.DataFrame(json.load(f))

# Function to save patient data to JSON
def save_data(df):
    with open('data.json', 'w') as f:
        json.dump(df.to_dict(orient='records'), f, indent=4)

# Load the existing data
df = load_data()

# Sidebar for navigation
st.sidebar.title("Navigation")
options = ["View Patient Data", "Add New Patient", "Add New Visit"]
choice = st.sidebar.selectbox("Choose an option", options)

if choice == "View Patient Data":
    # Sidebar for Patient Selection
    st.sidebar.header('Select Patient')
    patient_id = st.sidebar.selectbox('Patient ID', df['patient_id'].unique())

    # Filter Data for Selected Patient
    patient_data = df[df['patient_id'] == patient_id]

    # Display Patient Profile
    st.header('Patient Profile')
    st.write(f"Name: {patient_data['name'].values[0]}")
    st.write(f"Age: {patient_data['age'].values[0]}")
    st.write(f"Gender: {patient_data['gender'].values[0]}")
    st.write(f"Medical History: {patient_data['medical_history'].values[0]}")

    # Visualization of Vital Signs
    st.header('Vital Signs Over Time')

    # Line Chart for Heart Rate
    fig = px.line(patient_data, x='date', y='heart_rate', title='Heart Rate Over Time')
    st.plotly_chart(fig)

    # Line Chart for Blood Pressure
    fig = px.line(patient_data, x='date', y='blood_pressure', title='Blood Pressure Over Time')
    st.plotly_chart(fig)

    # Line Chart for Blood Glucose
    fig = px.line(patient_data, x='date', y='blood_glucose', title='Blood Glucose Over Time')
    st.plotly_chart(fig)

    # Dropdown for selecting specific visit details
    st.header('Previous Visit Details')
    selected_date = st.selectbox('Select Visit Date', patient_data['date'].unique())
    selected_visit = patient_data[patient_data['date'] == selected_date]

    st.write(f"**Visit Date:** {selected_date}")
    st.write(f"Heart Rate: {selected_visit['heart_rate'].values[0]}")
    st.write(f"Blood Pressure: {selected_visit['blood_pressure'].values[0]}")
    st.write(f"Blood Glucose: {selected_visit['blood_glucose'].values[0]}")

    # Alerts and Notifications
    st.header('Alerts')
    if selected_visit['heart_rate'].values[0] > 100:
        st.error('High heart rate detected!')
    if selected_visit['blood_pressure'].values[0] > 140:
        st.error('High blood pressure detected!')

    # Download Button for Patient Data
    st.download_button(
        label="Download Patient Data as CSV",
        data=patient_data.to_csv().encode('utf-8'),
        file_name=f'patient_{patient_id}_data.csv',
        mime='text/csv',
    )

elif choice == "Add New Patient":
    st.header("Add New Patient")

    # Input fields for new patient data
    new_patient_id = st.number_input("Patient ID", min_value=0, step=1)
    new_name = st.text_input("Name")
    new_age = st.number_input("Age", min_value=0, step=1)
    new_gender = st.selectbox("Gender", ["Male", "Female"])
    new_medical_history = st.text_area("Medical History")

    if st.button("Add Patient"):
        new_patient_data = {
            'patient_id': new_patient_id,
            'name': new_name,
            'age': new_age,
            'gender': new_gender,
            'medical_history': new_medical_history,
            'date': None,
            'heart_rate': None,
            'blood_pressure': None,
            'blood_glucose': None,
            'temperature': None,
            'medical_complaints': None,
            'symptoms': None,
            'physical_examination': None,
            'diagnosis': None,
            'extra_notes': None,
            'treatment': None
        }
        df = pd.concat([df, pd.DataFrame([new_patient_data])], ignore_index=True)
        save_data(df)
        st.success("New patient added successfully!")

elif choice == "Add New Visit":
    st.header("Add New Visit")

    # Input fields for adding a new visit
    patient_id = st.number_input("Patient ID", min_value=0, step=1)
    visit_date = st.date_input("Date of Visit", value=datetime.today())
    medical_complaints = st.text_area("Medical Complaints")
    symptoms = st.text_area("Symptoms")
    physical_examination = st.text_area("Physical Examination")
    diagnosis = st.text_area("Diagnosis")
    heart_rate = st.number_input("Heart Rate", min_value=0)
    blood_pressure = st.number_input("Blood Pressure", min_value=0)
    temperature = st.number_input("Temperature", min_value=0)
    glucose = st.number_input("Blood Glucose", min_value=0)
    extra_notes = st.text_area("Extra Notes")
    treatment = st.text_area("Treatment")

    if st.button("Add Visit"):
        new_visit_data = {
            'patient_id': patient_id,
            'name': df[df['patient_id'] == patient_id]['name'].values[0],
            'age': df[df['patient_id'] == patient_id]['age'].values[0],
            'gender': df[df['patient_id'] == patient_id]['gender'].values[0],
            'medical_history': df[df['patient_id'] == patient_id]['medical_history'].values[0],
            'date': visit_date.strftime('%Y-%m-%d'),
            'heart_rate': heart_rate,
            'blood_pressure': blood_pressure,
            'blood_glucose': glucose,
            'temperature': temperature,
            'medical_complaints': medical_complaints,
            'symptoms': symptoms,
            'physical_examination': physical_examination,
            'diagnosis': diagnosis,
            'extra_notes': extra_notes,
            'treatment': treatment
        }
        df = pd.concat([df, pd.DataFrame([new_visit_data])], ignore_index=True)
        save_data(df)
        st.success("New visit added successfully!")