Abstract. This paper uses discrete event simulation theory and stochastic service system to analyze the queuing problems in hospital outpatient services. It applies the event scheduling simulation strategy to create a system that assigns random pain scores (from 1 to 10) to patients and classifies those with scores below 5 as needing urgent service. The system aims to optimize the number of service desks and the waiting times based on the patients’ pain scores. This paper tackles the challenge of balancing the number of servers and the urgency of patients.
-
Simulation:
- Models patient arrivals, priority-based service, and queue dynamics using
simpy. - Dynamically adjusts the number of service desks based on failures (e.g., excessive waiting times or queue capacity breaches).
- Real-time simulation updates streamed to the frontend.
- Models patient arrivals, priority-based service, and queue dynamics using
-
Visualization:
- Interactive scatterplot created with D3.js.
- Points represent simulation runs, color-coded for failure or success:
- Red: Waiting time failure.
- Orange: Queue capacity failure.
- Green: Successful run.
- Hover over points to see the run information.
-
Backend:
- Flask-based API streams simulation results as Server-Sent Events (SSE).
- Fully modular structure for simulation logic, visualization, and configuration.
- Python 3.8+ is required.
- Install required Python packages:
pip install flask simpy numpy matplotlib
- Install
D3.jsby including it in yourindex.html:<script src="https://d3js.org/d3.v7.min.js"></script>
-
Clone the Repository:
git clone https://github.com/p0ur1a/Hospital_Simulation cd Hospital_Simulation -
Set Up Environment:
- Install dependencies:
pip install -r requirements.txt
- Install dependencies:
-
Run the Flask Server:
python app.py
-
Access the Application: Open your browser and navigate to:
http://127.0.0.1:5000/
- The backend simulates patient flow, calculating:
- Average waiting times.
- Causes of system failures (waiting time or queue capacity breaches).
- Results are streamed to the frontend after each run using SSE.
- The frontend visualizes the results dynamically with D3.js:
- A scatterplot updates incrementally as runs are completed.
- Hovering over points reveals details like run number and average waiting time.
- Hover Tooltip: Displays run number and average waiting time for each point.
- Color Codes:
- Red: Waiting time failure.
- Orange: Queue capacity failure.
- Green: Success.
- Dynamic Updates: Points appear incrementally as the simulation progresses.
Adjust simulation parameters in config.py:
- Simulation Time:
SIMULATION_TIME - Service Time Distribution:
SERVICE_TIME_LAMBDA_PARAM - Priority Levels:
PRIORITY_LOWER_BOUND,PRIORITY_UPPER_BOUND - Queue Capacity:
WAITING_LINE_CAPACITY - Interarrival Rate:
INTERARRIVAL_RATE_LAMBDA_PARAM
- Flask: Backend web framework.
- SimPy: Process-based discrete-event simulation library.
- Numpy: For numerical calculations.
- Matplotlib: For optional visualizations.
- D3.js: Interactive data visualizations.
Pouria Bahri
Email: Bapouria@gmail.com
GitHub: (https://github.com/p0ur1a)
This project is licensed under the MIT License.