h-adminsim 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- h_adminsim-1.0.0/LICENSE +30 -0
- h_adminsim-1.0.0/PKG-INFO +494 -0
- h_adminsim-1.0.0/README.md +455 -0
- h_adminsim-1.0.0/pyproject.toml +61 -0
- h_adminsim-1.0.0/src/h_adminsim/__init__.py +5 -0
- h_adminsim-1.0.0/src/h_adminsim/admin_staff.py +280 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/configs/data4primary.yaml +47 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/configs/data4secondary.yaml +47 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/configs/data4tertiary.yaml +47 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/country/address.json +141859 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/country/country_code.json +244 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/departments/department.json +85 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/departments/symptom.json +4530 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/fhir.schema.json +75253 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/names/firstname.txt +1219 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/names/lastname.txt +88799 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/cancel_patient_system.txt +38 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/intake_staff_task_user.txt +16 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/intake_supervisor_system.txt +8 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/intake_supervisor_user.txt +31 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/reschedule_patient_system.txt +38 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/schedule_patient_rejected_system.txt +42 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/schedule_patient_system.txt +36 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/schedule_staff_reasoning.txt +57 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/schedule_staff_sc_tool_calling.txt +13 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/schedule_staff_system.txt +10 -0
- h_adminsim-1.0.0/src/h_adminsim/assets/prompts/schedule_staff_tool_calling.txt +41 -0
- h_adminsim-1.0.0/src/h_adminsim/client/__init__.py +3 -0
- h_adminsim-1.0.0/src/h_adminsim/client/google_client.py +209 -0
- h_adminsim-1.0.0/src/h_adminsim/client/openai_client.py +199 -0
- h_adminsim-1.0.0/src/h_adminsim/client/vllm_client.py +160 -0
- h_adminsim-1.0.0/src/h_adminsim/environment/__init__.py +1 -0
- h_adminsim-1.0.0/src/h_adminsim/environment/hospital.py +462 -0
- h_adminsim-1.0.0/src/h_adminsim/environment/op_scheduling_simulation.py +1126 -0
- h_adminsim-1.0.0/src/h_adminsim/pipeline/__init__.py +3 -0
- h_adminsim-1.0.0/src/h_adminsim/pipeline/data_generator.py +192 -0
- h_adminsim-1.0.0/src/h_adminsim/pipeline/evaluator.py +33 -0
- h_adminsim-1.0.0/src/h_adminsim/pipeline/simulation.py +231 -0
- h_adminsim-1.0.0/src/h_adminsim/registry/__init__.py +5 -0
- h_adminsim-1.0.0/src/h_adminsim/registry/errors.py +89 -0
- h_adminsim-1.0.0/src/h_adminsim/registry/models.py +126 -0
- h_adminsim-1.0.0/src/h_adminsim/registry/phrases.py +10 -0
- h_adminsim-1.0.0/src/h_adminsim/registry/pydantic_models.py +21 -0
- h_adminsim-1.0.0/src/h_adminsim/registry/variables.py +9 -0
- h_adminsim-1.0.0/src/h_adminsim/supervisor.py +182 -0
- h_adminsim-1.0.0/src/h_adminsim/task/agent_task.py +900 -0
- h_adminsim-1.0.0/src/h_adminsim/task/fhir_manager.py +222 -0
- h_adminsim-1.0.0/src/h_adminsim/task/schedule_assign.py +151 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/__init__.py +5 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/agent_data_builder.py +124 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/data_converter.py +536 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/data_synthesizer.py +365 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/evaluator.py +258 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/sanity_checker.py +216 -0
- h_adminsim-1.0.0/src/h_adminsim/tools/scheduling_rule.py +420 -0
- h_adminsim-1.0.0/src/h_adminsim/utils/__init__.py +136 -0
- h_adminsim-1.0.0/src/h_adminsim/utils/common_utils.py +698 -0
- h_adminsim-1.0.0/src/h_adminsim/utils/fhir_utils.py +190 -0
- h_adminsim-1.0.0/src/h_adminsim/utils/filesys_utils.py +135 -0
- h_adminsim-1.0.0/src/h_adminsim/utils/image_preprocess_utils.py +188 -0
- h_adminsim-1.0.0/src/h_adminsim/utils/random_utils.py +358 -0
- h_adminsim-1.0.0/src/h_adminsim/version.txt +1 -0
h_adminsim-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Copyright (c) 2025, H-AdminSim developers.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are
|
|
6
|
+
met:
|
|
7
|
+
|
|
8
|
+
* Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
* Redistributions in binary form must reproduce the above
|
|
12
|
+
copyright notice, this list of conditions and the following
|
|
13
|
+
disclaimer in the documentation and/or other materials provided
|
|
14
|
+
with the distribution.
|
|
15
|
+
|
|
16
|
+
* Neither the name of the H-AdminSim Developers nor the names of any
|
|
17
|
+
contributors may be used to endorse or promote products derived
|
|
18
|
+
from this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
24
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
25
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
26
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
27
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
28
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: h_adminsim
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python package for simulating hospital administrative tasks.
|
|
5
|
+
License: BSD-3-Clause
|
|
6
|
+
Author: Jun-Min Lee
|
|
7
|
+
Author-email: ljm56897@gmail.com
|
|
8
|
+
Requires-Python: >=3.11,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Dist: aiohttp (==3.9.0)
|
|
14
|
+
Requires-Dist: beautifulsoup4 (==4.13.5)
|
|
15
|
+
Requires-Dist: datasets (==2.16.1)
|
|
16
|
+
Requires-Dist: dotenv (==0.9.9)
|
|
17
|
+
Requires-Dist: fastapi (==0.115.12)
|
|
18
|
+
Requires-Dist: google-genai (==1.19.0)
|
|
19
|
+
Requires-Dist: langchain (==0.3.27)
|
|
20
|
+
Requires-Dist: langchain-google-genai (==2.1.8)
|
|
21
|
+
Requires-Dist: langchain-openai (==0.3.28)
|
|
22
|
+
Requires-Dist: matplotlib (==3.10.3)
|
|
23
|
+
Requires-Dist: numpy (==1.26.4)
|
|
24
|
+
Requires-Dist: openai (>=1.99.1,<=1.108.0)
|
|
25
|
+
Requires-Dist: orjson (==3.10.18)
|
|
26
|
+
Requires-Dist: patientsim (>=1.0.0,<2.0.0)
|
|
27
|
+
Requires-Dist: peft (==0.14.0)
|
|
28
|
+
Requires-Dist: pillow (==11.2.1)
|
|
29
|
+
Requires-Dist: sconf (==0.2.5)
|
|
30
|
+
Requires-Dist: streamlit (==1.45.1)
|
|
31
|
+
Requires-Dist: streamlit-chat (==0.1.1)
|
|
32
|
+
Requires-Dist: tqdm (==4.65.0)
|
|
33
|
+
Requires-Dist: transformers (>=4.53.2,<=4.56.1)
|
|
34
|
+
Requires-Dist: uvicorn (==0.34.3)
|
|
35
|
+
Requires-Dist: vllm (>=0.10.2,<0.11.0)
|
|
36
|
+
Project-URL: Source, https://github.com/ljm565/H-AdminSim
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# H-AdminSim
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+

|
|
43
|
+

|
|
44
|
+

|
|
45
|
+

|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Overview 📚
|
|
49
|
+
H-AdminSim is an official Python package for simulating interactions between hospital administrative staff and first-visit outpatients using LLM agents.
|
|
50
|
+
It provides a standardized evaluation testbed for assessing LLM performance across key administrative tasks across multiple care levels (primary, secondary, and tertiary), with optional [FHIR](https://www.hl7.org/fhir/) integration and support for heterogeneous deployment environments, allowing flexible simulation workflows tailored to diverse hospital systems.
|
|
51
|
+
|
|
52
|
+
Large hospitals often handle 10,000+ outpatient encounters per day, and prior reports indicate limited specialization among administrative staff despite high workload.
|
|
53
|
+
H-AdminSim is designed to help address these challenges by offering a realistic, reproducible simulation environment that supports future hospital automation and LLM-assisted administrative workflows.
|
|
54
|
+
|
|
55
|
+
* Paper: https://arxiv.org/abs/2602.05407
|
|
56
|
+
* PyPI Package: https://pypi.org/project/h-adminsim/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### 1. Care level-specific data synthesis
|
|
63
|
+
We provide [configuration examples](https://github.com/ljm565/H-AdminSim/blob/master/src/h_adminsim/assets/configs/) for simulating primary, secondary, and tertiary care settings.
|
|
64
|
+
Each configuration reflects key characteristics of its hospital level:
|
|
65
|
+
|
|
66
|
+
* Hospital time granularity: `tertiary` < `secondary` = `primary` (coarser in lower levels)
|
|
67
|
+
* Number of departments: `primary` < `secondary` < `tertiary`
|
|
68
|
+
* Number of physicians: `primary` < `secondary` < `tertiary`
|
|
69
|
+
* Patient referral rate: `primary` < `secondary` < `tertiary`
|
|
70
|
+
* Proportion of patients with preferred `physician`/`date`: `primary` < `secondary` = `tertiary`
|
|
71
|
+
|
|
72
|
+
You may also define your own conditions using a custom configuration file (e.g., [data_synthesis.yaml](https://github.com/ljm565/H-AdminSim/blob/master/config/data_synthesis.yaml))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### 2. Hospital Administration Simulation
|
|
78
|
+
#### 2.1. Patient Intake Simulation
|
|
79
|
+
We extend the previously emergency department-focused [PatientSim](https://github.com/ljm565/patientsim-pkg) to enable realistic conversations between administrative staff and first-visit outpatients with diverse backgrounds.
|
|
80
|
+
* **Disease profile**: One of 194 disease–symptom pairs across 9 internal-medicine departments (`gastroenterology`, `cardiology`, `pulmonology`, `endocrinology/metabolism`, `nephrology`, `hematology/oncology`, `allergy`, `infectious diseases`, `rheumatology`)
|
|
81
|
+
* **Medical referral status**: Dialogue flow adapts based on whether the patient has a referral
|
|
82
|
+
* **Tasks**: Department recommendation, information extraction, structured data construction
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
#### 2.2. Appointment Scheduling Simulation
|
|
86
|
+
We simulate realistic scheduling interactions between administrative staff and patients, reflecting diverse scheduling behaviors and hospital-level constraints.
|
|
87
|
+
* **Time flow**: Users can define the simulation period and starting point, enabling the agent to perform time-related tasks based on the progression of simulated time.
|
|
88
|
+
* **Patient preferences**: `ASAP` (earliest slot), `physician` (specific physician requested), `date` (preferred date range start)
|
|
89
|
+
* **Random requests**: `cancellation`, `rescheduling`
|
|
90
|
+
* **Tasks**: New appointment scheduling, rescheduling, schdule cancellation
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
#### 2.3. FHIR Integration
|
|
94
|
+
We provide optional support for integrating with FHIR, allowing the simulator to operate flexibly across heterogeneous hospital environments as long as FHIR-compatible data is available. For instructions on running a FHIR server, please refer to the [FHIR Server Execution](https://github.com/ljm565/fhir_server) repository.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
## Recent updates 📣
|
|
102
|
+
* *December 2025 (v1.0.0)*: H-AdminSim package has been released.
|
|
103
|
+
* *December 2025 (v0.7.2)*: Rule-based and tool calling-based scheduling logics have been supported.
|
|
104
|
+
* *November 2025 (v0.7.1)*: Self-corrective feedback logic has been supported.
|
|
105
|
+
* *October 2025 (v0.7.0)*: Simulation has been improved reflecting feedbacks from experts.
|
|
106
|
+
* *September 2025 (v0.6.0)*: Simulation has been improved reflecting feedbacks from experts.
|
|
107
|
+
* *August 2025 (v0.5.2)*: We has supported vLLM inference of the Hugging Face models.
|
|
108
|
+
* *August 2025 (v0.5.1)*: Now you can easily set the virtual environment using Poetry.
|
|
109
|
+
* *August 2025 (v0.5.0)*: We integrated the FHIR server to retrieve hospital information during hospital administration office agent simulation.
|
|
110
|
+
<!-- * *July 2025 (v0.4.2)*: We have supported LangChain's JsonOutputParser funtion as well as naive LLM API methods.
|
|
111
|
+
* *July 2025 (v0.4.1)*: Add functionality to schedule appointments based on the hospital's current time (the time the patient contacted for booking).
|
|
112
|
+
* *July 2025 (v0.4.0)*: Added a hospital simulation environment to enable rescheduling based on patient priority, flexibility, and other constraints.
|
|
113
|
+
* *July 2025 (v0.3.1)*: Added agent results evaluation codes.
|
|
114
|
+
* *July 2025 (v0.3.0)*: This repository has supported Gemini- and GPT-based LLM agent task testing: 'department', 'schedule', 'fhir_resource', 'fhir_api'.
|
|
115
|
+
* *June 2025 (v0.2.2)*: Added *PractitionerRole* resource type and function to make more realistic data.
|
|
116
|
+
* *June 2025 (v0.2.1)*: Fixed *Appointment* resource type error and added function to show failed files during creating data to FHIR.
|
|
117
|
+
* *June 2025 (v0.2.0)*: Added function to map synthetic data to some *workflow* resource types in FHIR.
|
|
118
|
+
* *June 2025 (v0.1.2)*: The data synthesis speed has been improved, and a sanity check feature has been added during synthesis.
|
|
119
|
+
* *June 2025 (v0.1.1)*: Added random patient data synthesizing codes and completed sanity check.
|
|
120
|
+
* *June 2025 (v0.1.0)*: Added random hospital data synthesizing codes and completed sanity check.
|
|
121
|
+
* *June 2025 (v0.0.5)*: Enhanced and fixed the FHIR manager operations.
|
|
122
|
+
* *June 2025 (v0.0.4)*: Updated documents (environment setting, CRUD guides)
|
|
123
|
+
* *June 2025 (v0.0.3)*: Now we has supported FHIR CRUD.
|
|
124
|
+
* *June 2025 (v0.0.2)*: Created chat demo `README.md`.
|
|
125
|
+
* *June 2025 (v0.0.1)*: Created chat demo codes using FastAPI communication. -->
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
## Quick Starts 🚀
|
|
133
|
+
### 1. Installation
|
|
134
|
+
```bash
|
|
135
|
+
pip install h_adminsim
|
|
136
|
+
```
|
|
137
|
+
```python
|
|
138
|
+
import h_adminsim
|
|
139
|
+
print(h_adminsim.__version__)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
### 2. Environment Variables
|
|
145
|
+
Before using the LLM API, you need to provide the API key (or the required environment variables for each model) either directly or in a `.env` file.
|
|
146
|
+
```bash
|
|
147
|
+
# For GPT API without Azure
|
|
148
|
+
OPENAI_API_KEY=${YOUR_OPENAI_KEY}
|
|
149
|
+
|
|
150
|
+
# For Gemini API
|
|
151
|
+
GOOGLE_API_KEY=${YOUR_GEMINI_API_KEY"}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### 3. Simulation
|
|
157
|
+
```python
|
|
158
|
+
from h_adminsim import AdminStaffAgent, SupervisorAgent
|
|
159
|
+
from h_adminsim.pipeline import DataGenerator, Simulator
|
|
160
|
+
from h_adminsim.task.agent_task import OutpatientFirstIntake, OutpatientFirstScheduling
|
|
161
|
+
|
|
162
|
+
data_generator = DataGenerator()
|
|
163
|
+
data_generator.build(convert_to_fhir=True)
|
|
164
|
+
agent_data_dir = data_generator.save_dir / 'agent_data'
|
|
165
|
+
output_dir = data_generator.save_dir / 'simulation_results'
|
|
166
|
+
|
|
167
|
+
# Intake task
|
|
168
|
+
intake_task = OutpatientFirstIntake(
|
|
169
|
+
patient_model='gpt-5-nano',
|
|
170
|
+
admin_staff_model='gemini-2.5-flash',
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# Scheduling task
|
|
174
|
+
scheduling_task = OutpatientFirstScheduling(
|
|
175
|
+
patient_model='gpt-5-nano',
|
|
176
|
+
admin_staff_model='gpt-5-mini',
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
# Simulation
|
|
180
|
+
simulator = Simulator(
|
|
181
|
+
intake_task=intake_task,
|
|
182
|
+
scheduling_task=scheduling_task,
|
|
183
|
+
)
|
|
184
|
+
simulator.run(
|
|
185
|
+
simulation_data_path=agent_data_dir,
|
|
186
|
+
output_dir=output_dir,
|
|
187
|
+
resume=False,
|
|
188
|
+
verbose=True
|
|
189
|
+
)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
## Components Details ⚙️
|
|
198
|
+
### 1. Data synthesis
|
|
199
|
+
```python
|
|
200
|
+
from h_adminsim.pipeline import DataGenerator
|
|
201
|
+
|
|
202
|
+
# 1. Generator Initialization
|
|
203
|
+
# 1.1. Default usaage
|
|
204
|
+
data_generator = DataGenerator() # Default: primary care
|
|
205
|
+
# data_generator = DateGenerator(level='secondary') # For secondary care
|
|
206
|
+
# data_generator = DateGenerator(level='tertiary') # For tertiary care
|
|
207
|
+
|
|
208
|
+
# 1.2. You can synthesize data with your own configuration
|
|
209
|
+
data_generator = DataGenerator(config='data_config.yaml')
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# 2. Synthesizing Data
|
|
213
|
+
# 2.1. Default usage
|
|
214
|
+
data_generator.build()
|
|
215
|
+
|
|
216
|
+
# 2.2. When you want the synthesized data returned along with its FHIR-converted version (optional)
|
|
217
|
+
data_generator.build(convert_to_fhir=True)
|
|
218
|
+
|
|
219
|
+
# 2.3. When you want to upload the synthesized data to your own FHIR server (optional)
|
|
220
|
+
# Provide your FHIR server URL
|
|
221
|
+
data_generator.upload_to_fhir(
|
|
222
|
+
fhir_data_dir=data_generator.save_dir / "fhir_data",
|
|
223
|
+
fhir_url=${FHIR_URL},
|
|
224
|
+
)
|
|
225
|
+
```
|
|
226
|
+
<details>
|
|
227
|
+
<summary>Configuration example for data synthesis</summary>
|
|
228
|
+
|
|
229
|
+
```yaml
|
|
230
|
+
# Base
|
|
231
|
+
seed: 9999
|
|
232
|
+
|
|
233
|
+
# FHIR server url
|
|
234
|
+
fhir_url: http://localhost:8080/fhir # Optional: set your FHIR server URL here
|
|
235
|
+
|
|
236
|
+
# Data configs
|
|
237
|
+
project: ./synthetic_data/
|
|
238
|
+
data_name: hospital_small # Output path: ./synthetic_data/hospital_small/data
|
|
239
|
+
hospital_data:
|
|
240
|
+
hospital_n: 10 # Number of hospitals to synthesize
|
|
241
|
+
start_date:
|
|
242
|
+
min: 2025-03-17 # ISO format: YYYY-MM-DD
|
|
243
|
+
max: 2025-09-21
|
|
244
|
+
days: 7 # Simulation period (in days)
|
|
245
|
+
interval_hour: 0.25 # Time unit expressed in hours
|
|
246
|
+
start_hour: # Possible hospital opening hours
|
|
247
|
+
min: 9
|
|
248
|
+
max: 10
|
|
249
|
+
end_hour: # Possible hospital closing hours
|
|
250
|
+
min: 18
|
|
251
|
+
max: 19
|
|
252
|
+
department_per_hospital:
|
|
253
|
+
min: 7
|
|
254
|
+
max: 9
|
|
255
|
+
doctor_per_department:
|
|
256
|
+
min: 1
|
|
257
|
+
max: 1
|
|
258
|
+
working_days: # Number of days each doctor works during the simulation period
|
|
259
|
+
min: 3
|
|
260
|
+
max: 4
|
|
261
|
+
doctor_capacity_per_hour:
|
|
262
|
+
min: 1
|
|
263
|
+
max: 4
|
|
264
|
+
doctor_has_schedule_prob: 0 # Probability that a doctor has at least one fixed schedule
|
|
265
|
+
schedule_coverage_ratio: # Proportion of fixed schedules relative to total working hours
|
|
266
|
+
min: 0.4
|
|
267
|
+
max: 0.6
|
|
268
|
+
appointment_coverage_ratio: # Proportion of appointments scheduled outside fixed schedules
|
|
269
|
+
min: 0.2
|
|
270
|
+
max: 0.5
|
|
271
|
+
preference:
|
|
272
|
+
type: ['asap', 'doctor', 'date'] # Types of patient scheduling preferences
|
|
273
|
+
probs: [0.4, 0.4, 0.2] # Probability distribution for each preference type
|
|
274
|
+
symptom:
|
|
275
|
+
type: ['simple', 'with_history'] # 'simple' = no referral; 'with_history' = referral case
|
|
276
|
+
probs: [0.7, 0.3] # Probability distribution for symptom types
|
|
277
|
+
```
|
|
278
|
+
</details>
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
### 2. Task Initialization
|
|
283
|
+
#### 2.1. Patient Intake
|
|
284
|
+
```python
|
|
285
|
+
from h_adminsim import SupervisorAgent
|
|
286
|
+
from h_adminsim.task.agent_task import OutpatientFirstIntake
|
|
287
|
+
|
|
288
|
+
# 1. Patient Intake
|
|
289
|
+
# 1.1. Default usage (Staff-only)
|
|
290
|
+
intake_task = OutpatientFirstIntake(
|
|
291
|
+
patient_model='gpt-5-nano',
|
|
292
|
+
admin_staff_model='gpt-5-mini',
|
|
293
|
+
intake_max_inference=5, # Default: up to 5 rounds (10 turns) of dialogue
|
|
294
|
+
)
|
|
295
|
+
##############################################################
|
|
296
|
+
|
|
297
|
+
# 1.2. Role separation
|
|
298
|
+
# Staff: dialogue handling, Supervisor: data collection and structuring
|
|
299
|
+
supervisor_agent = SupervisorAgent(
|
|
300
|
+
target_task='first_outpatient_scheduling',
|
|
301
|
+
model='gemini-2.5-flash',
|
|
302
|
+
api_key=${YOUR_API_KEY}, # You may set the API key here instead of using a .env file
|
|
303
|
+
)
|
|
304
|
+
intake_task = OutpatientFirstIntake(
|
|
305
|
+
patient_model='gemini-2.5-flash',
|
|
306
|
+
admin_staff_model='gpt-5',
|
|
307
|
+
supervisor_agent=supervisor_agent,
|
|
308
|
+
intake_max_inference=8,
|
|
309
|
+
)
|
|
310
|
+
##############################################################
|
|
311
|
+
|
|
312
|
+
# 1.3. Advanced usage: vLLM
|
|
313
|
+
supervisor_agent = SupervisorAgent(
|
|
314
|
+
target_task='first_outpatient_scheduling',
|
|
315
|
+
model='meta-llama/Llama-3.3-70B-Instruct',
|
|
316
|
+
use_vllm=True, # Use a vLLM-hosted model as the supervisor
|
|
317
|
+
vllm_endpoint='http://0.0.0.0:8000', # vLLM server endpoint
|
|
318
|
+
)
|
|
319
|
+
intake_task = OutpatientFirstIntake(
|
|
320
|
+
patient_model='meta-llama/Llama-3.3-70B-Instruct',
|
|
321
|
+
admin_staff_model='meta-llama/Llama-3.3-70B-Instruct',
|
|
322
|
+
supervisor_agent=supervisor_agent,
|
|
323
|
+
intake_max_inference=5,
|
|
324
|
+
patient_vllm_endpoint='http://0.0.0.0:8000',
|
|
325
|
+
admin_staff_vllm_endpoint='http://0.0.0.0:8000',
|
|
326
|
+
)
|
|
327
|
+
##############################################################
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
#### 2.2. Appointment Scheduling
|
|
333
|
+
```python
|
|
334
|
+
from h_adminsim import AdminStaffAgent, SupervisorAgent
|
|
335
|
+
from h_adminsim.task.agent_task import OutpatientFirstScheduling
|
|
336
|
+
|
|
337
|
+
# 2. Appointment Scheduling
|
|
338
|
+
# 2.1. Default usage (Tool-calling with reasoning fallbacks)
|
|
339
|
+
scheduling_task = OutpatientFirstScheduling(
|
|
340
|
+
patient_model='gpt-5-nano',
|
|
341
|
+
admin_staff_model='gemini-2.5-flash',
|
|
342
|
+
schedule_cancellation_prob=0.05, # Cancellation event
|
|
343
|
+
request_early_schedule_prob=0.1, # Rescheduling event
|
|
344
|
+
preference_rejection_prob = 0.3, # Prob. of rejecting the first-priority scheduling preference
|
|
345
|
+
preference_rejection_prob_decay = 0.5, # Decay factor for the preference rejection prob.
|
|
346
|
+
scheduling_max_inference=5,
|
|
347
|
+
scheduling_strategy='tool_calling',
|
|
348
|
+
fhir_integration=False,
|
|
349
|
+
)
|
|
350
|
+
##############################################################
|
|
351
|
+
|
|
352
|
+
# 2.2. LLM reasoning-based scheduling without tool-calling
|
|
353
|
+
scheduling_task = OutpatientFirstScheduling(
|
|
354
|
+
patient_model='gpt-5-nano',
|
|
355
|
+
admin_staff_model='gpt-5-mini',
|
|
356
|
+
schedule_cancellation_prob=0.05, # Cancellation event
|
|
357
|
+
request_early_schedule_prob=0.1, # Rescheduling event
|
|
358
|
+
preference_rejection_prob = 0.3, # Prob. of rejecting the first-priority scheduling preference
|
|
359
|
+
preference_rejection_prob_decay = 0.5, # Decay factor for the preference rejection prob.
|
|
360
|
+
scheduling_max_inference=5,
|
|
361
|
+
scheduling_strategy='reasoning',
|
|
362
|
+
fhir_integration=False,
|
|
363
|
+
)
|
|
364
|
+
##############################################################
|
|
365
|
+
|
|
366
|
+
# 2.3. HIS upload via FHIR
|
|
367
|
+
scheduling_task = OutpatientFirstScheduling(
|
|
368
|
+
patient_model='gpt-5-nano',
|
|
369
|
+
admin_staff_model='gemini-2.5-flash',
|
|
370
|
+
schedule_cancellation_prob=0.05, # Cancellation event
|
|
371
|
+
request_early_schedule_prob=0.1, # Rescheduling event
|
|
372
|
+
preference_rejection_prob = 0.3, # Prob. of rejecting the first-priority scheduling preference
|
|
373
|
+
preference_rejection_prob_decay = 0.5, # Decay factor for the preference rejection prob.
|
|
374
|
+
scheduling_max_inference=5,
|
|
375
|
+
scheduling_strategy='tool_calling',
|
|
376
|
+
fhir_integration=True,
|
|
377
|
+
)
|
|
378
|
+
##############################################################
|
|
379
|
+
|
|
380
|
+
# 2.4. Advanced usage: vLLM
|
|
381
|
+
scheduling_task = OutpatientFirstScheduling(
|
|
382
|
+
patient_model='meta-llama/Llama-3.3-70B-Instruct',
|
|
383
|
+
admin_staff_model='gpt-5-mini',
|
|
384
|
+
schedule_cancellation_prob=0.05, # Cancellation event
|
|
385
|
+
request_early_schedule_prob=0.1, # Rescheduling event
|
|
386
|
+
preference_rejection_prob = 0.3, # Prob. of rejecting the first-priority scheduling preference
|
|
387
|
+
preference_rejection_prob_decay = 0.5, # Decay factor for the preference rejection prob.
|
|
388
|
+
scheduling_max_inference=5,
|
|
389
|
+
scheduling_strategy='tool-calling', # Currently, we do not support tool-calling from vLLM
|
|
390
|
+
fhir_integration=False,
|
|
391
|
+
patient_vllm_endpoint='http://0.0.0.0:8000',
|
|
392
|
+
|
|
393
|
+
)
|
|
394
|
+
##############################################################
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
### 3. Simulation
|
|
400
|
+
```python
|
|
401
|
+
from h_adminsim.pipeline import Simulator
|
|
402
|
+
|
|
403
|
+
# 3. Simulator initialization
|
|
404
|
+
# 3.1. Default usage
|
|
405
|
+
simulator = Simulator(
|
|
406
|
+
intake_task=intake_task,
|
|
407
|
+
scheduling_task=scheduling_task,
|
|
408
|
+
simulation_start_day_before=3,
|
|
409
|
+
fhir_integration=False,
|
|
410
|
+
fhir_url=None,
|
|
411
|
+
fhir_max_connection_retries=5,
|
|
412
|
+
random_seed=9999,
|
|
413
|
+
)
|
|
414
|
+
##############################################################
|
|
415
|
+
|
|
416
|
+
# 3.2. FHIR integration
|
|
417
|
+
# (If enabled, scheduling task must be initialized with `fhir_integration=True`)
|
|
418
|
+
simulator = Simulator(
|
|
419
|
+
intake_task=intake_task,
|
|
420
|
+
scheduling_task=scheduling_task,
|
|
421
|
+
simulation_start_day_before=3,
|
|
422
|
+
fhir_integration=True,
|
|
423
|
+
fhir_url='http://localhost:8080/fhir',
|
|
424
|
+
fhir_max_connection_retries=5,
|
|
425
|
+
random_seed=9999,
|
|
426
|
+
)
|
|
427
|
+
##############################################################
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
# 3.3. Running a single task
|
|
431
|
+
# 3.3.1. Intake task only
|
|
432
|
+
simulator = Simulator(
|
|
433
|
+
intake_task=intake_task,
|
|
434
|
+
scheduling_task=None,
|
|
435
|
+
simulation_start_day_before=3,
|
|
436
|
+
fhir_integration=False,
|
|
437
|
+
fhir_url=None,
|
|
438
|
+
fhir_max_connection_retries=5,
|
|
439
|
+
random_seed=9999,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
# 3.3.2. Scheduling task only
|
|
443
|
+
simulator = Simulator(
|
|
444
|
+
intake_task=None,
|
|
445
|
+
scheduling_task=scheduling_task,
|
|
446
|
+
simulation_start_day_before=3,
|
|
447
|
+
fhir_integration=False,
|
|
448
|
+
fhir_url=None,
|
|
449
|
+
fhir_max_connection_retries=5,
|
|
450
|
+
random_seed=9999,
|
|
451
|
+
)
|
|
452
|
+
##############################################################
|
|
453
|
+
```
|
|
454
|
+
```python
|
|
455
|
+
# Run the initialized simulator
|
|
456
|
+
simulator.run(
|
|
457
|
+
simulation_data_path='hospital_data/primary/agent_data',
|
|
458
|
+
output_dir='hospital_data/primary/simulation_results',
|
|
459
|
+
resume=False, # If the simulation stopped unexpectedly, set resume=True with the same paths
|
|
460
|
+
verbose=True,
|
|
461
|
+
)
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
## Citation
|
|
471
|
+
For `H-AdminSim` and `PatientSim` outpatient simulation, please cite the following.
|
|
472
|
+
```
|
|
473
|
+
@misc{lee2026hadminsimmultiagentsimulatorrealistic,
|
|
474
|
+
title={H-AdminSim: A Multi-Agent Simulator for Realistic Hospital Administrative Workflows with FHIR Integration},
|
|
475
|
+
author={Jun-Min Lee and Meong Hi Son and Edward Choi},
|
|
476
|
+
year={2026},
|
|
477
|
+
eprint={2602.05407},
|
|
478
|
+
archivePrefix={arXiv},
|
|
479
|
+
primaryClass={cs.AI},
|
|
480
|
+
url={https://arxiv.org/abs/2602.05407},
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
<!--
|
|
486
|
+
|
|
487
|
+
## More Details on Module Tests 🔍
|
|
488
|
+
1. [Getting Started](https://github.com/ljm565/H-AdminSim/blob/master/docs/1_getting_started.md)
|
|
489
|
+
2. [How to perform CRUD on FHIR](https://github.com/ljm565/H-AdminSim/blob/master/docs/2_fhir_crud.md)
|
|
490
|
+
3. [Hospital Data Synthesis](https://github.com/ljm565/H-AdminSim/blob/master/docs/3_data_synthesis.md)
|
|
491
|
+
4. [Agent Simulation](https://github.com/ljm565/H-AdminSim/blob/master/docs/4_agent_test.md) -->
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|