Takes in the user facial symptoms including allergy information in a form of form and output the report, the report output results will only show once they made online mayment through gateway
To upload files, please first save the app
import streamlit as st
from sqlalchemy import create_engine, Column, Integer, String, Boolean, Float
from sqlalchemy.orm import DeclarativeBase, Session
from datetime import datetime
import json
# Database setup
class Base(DeclarativeBase):
pass
class SymptomReport(Base):
__tablename__ = 'symptom_reports'
id = Column(Integer, primary_key=True)
name = Column(String)
age = Column(Integer)
facial_redness = Column(Boolean)
facial_swelling = Column(Boolean)
itching = Column(Boolean)
known_allergies = Column(String)
payment_status = Column(Boolean, default=False)
amount_paid = Column(Float)
timestamp = Column(String)
engine = create_engine('sqlite:///symptoms.db')
Base.metadata.create_all(bind=engine)
def save_report(data):
with Session(engine) as session:
report = SymptomReport(**data)
session.add(report)
session.commit()
return report.id
def get_report(report_id):
with Session(engine) as session:
return session.query(SymptomReport).filter(SymptomReport.id == report_id).first()
def update_payment_status(report_id):
with Session(engine) as session:
report = session.query(SymptomReport).filter(SymptomReport.id == report_id).first()
if report:
report.payment_status = True
report.amount_paid = 25.00 # Fixed consultation fee
session.commit()
# Streamlit UI
st.title("Facial Symptoms Assessment Form")
if "report_id" not in st.session_state:
st.session_state.report_id = None
if "payment_made" not in st.session_state:
st.session_state.payment_made = False
# Form section
with st.form("symptom_form"):
st.write("Please fill in your symptoms information:")
name = st.text_input("Full Name")
age = st.number_input("Age", min_value=0, max_value=120)
st.write("Select your symptoms:")
facial_redness = st.checkbox("Facial Redness")
facial_swelling = st.checkbox("Facial Swelling")
itching = st.checkbox("Itching")
known_allergies = st.text_area("List any known allergies (if any)")
submitted = st.form_submit_button("Submit")
if submitted:
report_data = {
"name": name,
"age": age,
"facial_redness": facial_redness,
"facial_swelling": facial_swelling,
"itching": itching,
"known_allergies": known_allergies,
"payment_status": False,
"amount_paid": 0.0,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
report_id = save_report(report_data)
st.session_state.report_id = report_id
st.success("Form submitted successfully! Please proceed to payment.")
# Payment section
if st.session_state.report_id and not st.session_state.payment_made:
st.write("---")
st.write("### Payment Gateway")
st.write("Consultation Fee: $25.00")
with st.form("payment_form"):
st.write("Payment Information")
card_number = st.text_input("Card Number")
expiry = st.text_input("Expiry Date (MM/YY)")
cvv = st.text_input("CVV", type="password")
payment_submitted = st.form_submit_button("Pay Now")
if payment_submitted:
# Simulate payment processing
update_payment_status(st.session_state.report_id)
st.session_state.payment_made = True
st.success("Payment processed successfully!")
st.rerun()
# Report display section
if st.session_state.payment_made and st.session_state.report_id:
st.write("---")
st.write("### Symptom Assessment Report")
report = get_report(st.session_state.report_id)
if report:
st.write(f"Patient Name: {report.name}")
st.write(f"Age: {report.age}")
st.write("\nSymptoms:")
st.write(f"- Facial Redness: {'Yes' if report.facial_redness else 'No'}")
st.write(f"- Facial Swelling: {'Yes' if report.facial_swelling else 'No'}")
st.write(f"- Itching: {'Yes' if report.itching else 'No'}")
st.write(f"\nKnown Allergies: {report.known_allergies if report.known_allergies else 'None reported'}")
symptom_count = sum([report.facial_redness, report.facial_swelling, report.itching])
st.write("\nPreliminary Assessment:")
if symptom_count >= 2:
st.warning("Multiple symptoms detected. Recommend consulting with an allergist.")
elif symptom_count == 1:
st.info("Mild symptoms detected. Monitor condition and seek medical attention if symptoms worsen.")
else:
st.success("No significant symptoms detected. Continue monitoring for any changes.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?