Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from fpdf import FPDF
|
| 3 |
+
import datetime
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="HouseMD - Clinical App", layout="wide")
|
| 7 |
+
|
| 8 |
+
# ------------------ USER ROLE HANDLING ------------------
|
| 9 |
+
roles = {
|
| 10 |
+
"doctor": "doctor123",
|
| 11 |
+
"reception": "reception123",
|
| 12 |
+
"pharmacy": "pharmacy123",
|
| 13 |
+
"lab": "lab123",
|
| 14 |
+
"radiology": "radiology123",
|
| 15 |
+
"biochem": "biochem123",
|
| 16 |
+
"pathology": "pathology123"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
st.sidebar.title("HouseMD Login")
|
| 20 |
+
username = st.sidebar.selectbox("Select Role", list(roles.keys()))
|
| 21 |
+
password = st.sidebar.text_input("Enter Password", type="password")
|
| 22 |
+
if password != roles.get(username):
|
| 23 |
+
st.sidebar.warning("Enter correct password to continue.")
|
| 24 |
+
st.stop()
|
| 25 |
+
|
| 26 |
+
st.sidebar.success(f"Logged in as: {username.upper()}")
|
| 27 |
+
|
| 28 |
+
# ------------------ FUNCTIONS ------------------
|
| 29 |
+
|
| 30 |
+
def symptom_picker():
|
| 31 |
+
st.header("π©Ί Symptom-Based Trigger")
|
| 32 |
+
symptoms = ["Fever", "Burning urination", "Abdominal pain", "Cough", "Chest pain"]
|
| 33 |
+
selected = st.multiselect("Select presenting symptoms:", symptoms)
|
| 34 |
+
if selected:
|
| 35 |
+
st.info(f"Selected: {', '.join(selected)}")
|
| 36 |
+
st.success("Might be: UTI, Pneumonia, Gastroenteritis (Mock output)")
|
| 37 |
+
|
| 38 |
+
def history_taking():
|
| 39 |
+
st.header("π History Taking")
|
| 40 |
+
systems = {
|
| 41 |
+
"General": ["Fever", "Weight loss", "Fatigue"],
|
| 42 |
+
"GI": ["Abdominal pain", "Nausea", "Vomiting"],
|
| 43 |
+
"GU": ["Burning urination", "Frequency", "Flank pain"]
|
| 44 |
+
}
|
| 45 |
+
for system, questions in systems.items():
|
| 46 |
+
with st.expander(f"{system} History"):
|
| 47 |
+
for q in questions:
|
| 48 |
+
st.checkbox(q)
|
| 49 |
+
|
| 50 |
+
def test_suggestions():
|
| 51 |
+
st.header("π§ͺ Suggested Tests")
|
| 52 |
+
if st.button("Show Suggested Tests"):
|
| 53 |
+
tests = ["CBC", "Urine Routine", "RBS", "LFT"]
|
| 54 |
+
for t in tests:
|
| 55 |
+
st.checkbox(t)
|
| 56 |
+
|
| 57 |
+
def triage_tests():
|
| 58 |
+
st.header("π¨ Triage Diagnostic Workflow")
|
| 59 |
+
test = st.selectbox("Select Test", ["X-ray Chest", "CBC", "USG Abdomen"])
|
| 60 |
+
triage = st.radio("Triage Level", ["π’ Green", "π‘ Yellow", "π΄ Red"])
|
| 61 |
+
st.success(f"Test ordered: {test} with {triage} priority")
|
| 62 |
+
|
| 63 |
+
def prescription_builder():
|
| 64 |
+
st.header("π Prescription Generator")
|
| 65 |
+
name = st.text_input("Patient Name")
|
| 66 |
+
meds = st.text_area("Enter medicines and instructions")
|
| 67 |
+
if st.button("Generate PDF Rx"):
|
| 68 |
+
filename = f"{name}_rx.pdf"
|
| 69 |
+
pdf = FPDF()
|
| 70 |
+
pdf.add_page()
|
| 71 |
+
pdf.set_font("Arial", size=12)
|
| 72 |
+
pdf.cell(200, 10, f"Prescription for {name}", ln=True)
|
| 73 |
+
pdf.multi_cell(0, 10, meds)
|
| 74 |
+
pdf.output(filename)
|
| 75 |
+
with open(filename, "rb") as f:
|
| 76 |
+
st.download_button("Download Prescription PDF", f, file_name=filename)
|
| 77 |
+
os.remove(filename)
|
| 78 |
+
|
| 79 |
+
def reception_panel():
|
| 80 |
+
st.header("π§Ύ Reception - Patient Entry")
|
| 81 |
+
name = st.text_input("Patient Name")
|
| 82 |
+
age = st.number_input("Age", min_value=0, max_value=120)
|
| 83 |
+
complaint = st.text_input("Chief Complaint")
|
| 84 |
+
if st.button("Add to Queue"):
|
| 85 |
+
st.success(f"Added {name} to queue")
|
| 86 |
+
|
| 87 |
+
def pharmacy_panel():
|
| 88 |
+
st.header("π Pharmacy Panel")
|
| 89 |
+
st.table({"Patient": ["Aman"], "Medicines": ["Amoxicillin x5"], "Dispensed": ["β"]})
|
| 90 |
+
st.button("Mark as Dispensed")
|
| 91 |
+
|
| 92 |
+
def lab_panel():
|
| 93 |
+
st.header("π¬ Lab Dashboard")
|
| 94 |
+
st.table({"Patient": ["Ravi", "Neha"], "Test": ["CBC", "Urine"], "Status": ["Pending", "Pending"]})
|
| 95 |
+
st.button("Mark Sample Collected")
|
| 96 |
+
|
| 97 |
+
def radiology_panel():
|
| 98 |
+
st.header("π©» Radiology Panel")
|
| 99 |
+
file = st.file_uploader("Upload Radiology Report")
|
| 100 |
+
if file:
|
| 101 |
+
st.success("File uploaded.")
|
| 102 |
+
|
| 103 |
+
def admin_dashboard():
|
| 104 |
+
st.header("π Admin Dashboard")
|
| 105 |
+
st.metric("Todayβs OPD Revenue", "βΉ6,000")
|
| 106 |
+
st.metric("Pharmacy Income", "βΉ3,200")
|
| 107 |
+
st.metric("Lab Collections", "βΉ2,500")
|
| 108 |
+
|
| 109 |
+
# ------------------ UI ROUTING ------------------
|
| 110 |
+
|
| 111 |
+
if username == "doctor":
|
| 112 |
+
st.title("π₯ Doctor's Panel")
|
| 113 |
+
tabs = st.tabs(["Symptom Trigger", "History", "Tests", "Triage", "Prescription", "Admin"])
|
| 114 |
+
with tabs[0]: symptom_picker()
|
| 115 |
+
with tabs[1]: history_taking()
|
| 116 |
+
with tabs[2]: test_suggestions()
|
| 117 |
+
with tabs[3]: triage_tests()
|
| 118 |
+
with tabs[4]: prescription_builder()
|
| 119 |
+
with tabs[5]: admin_dashboard()
|
| 120 |
+
|
| 121 |
+
elif username == "reception":
|
| 122 |
+
st.title("π§Ύ Reception Desk")
|
| 123 |
+
reception_panel()
|
| 124 |
+
|
| 125 |
+
elif username == "pharmacy":
|
| 126 |
+
st.title("π Pharmacy Desk")
|
| 127 |
+
pharmacy_panel()
|
| 128 |
+
|
| 129 |
+
elif username == "lab":
|
| 130 |
+
st.title("π¬ Lab Technician Panel")
|
| 131 |
+
lab_panel()
|
| 132 |
+
|
| 133 |
+
elif username == "radiology":
|
| 134 |
+
st.title("π©» Radiology Panel")
|
| 135 |
+
radiology_panel()
|
| 136 |
+
|
| 137 |
+
else:
|
| 138 |
+
st.info("Panel for this role is coming soon.")
|