Simply A&E Flow Model
Model was written in NetLogo 5.0.1
•
Viewed 579 times
•
Downloaded 44 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
;; Types of Turtle breed [patients patient] ;; A breed of turtle to represent patients breed [caregivers caregiver] ;; A breed of turtle to represent caregivers breed [minorgivers minorgiver] ;; A breed of turtle that can only treat minors patients breed [mylabels mylabel] ;; A breed to allow us to add labels to the plot ;; Global Variables globals[ dist_patient_lv1_fq ;; Distribution of frequency of creation of lv 1 patients dist_patient_lv2_fq ;; Same for level 2 dist_patient_lv3_fq ;; Same for level 3 dist_lv1_treatment_times ;; Amount of treatment time required for lv 1 patient dist_lv2_treatment_times ;; Same for level 2 dist_lv3_treatment_times ;; Same for level 3 dist_lv1_arrival_type ;; Defines the arrival location/type - ambulance or waiting room dist_lv2_arrival_type ;; Same for level 2 dist_lv3_arrival_type ;; Same for level 3 simticks ;; This is a variable I'm going to use to give track of time minor_size ;; Number of minor spaces major_size ;; Number of major spaces resus_size ;; Number of resus spaces waittime_ambulance_avg ;; Variable to hold a calculation of waiting time average for ambulance waittime_ambulance_max ;; Variable to hold a calculation of waiting time max for ambulance waittime_waitroom_avg ;; Variable to hold a calculation of waiting time average for waiting room waittime_waitroom_max ;; Variable to hold a calculation of waiting time max for waiting room ] ;; Turtle Variables patients-own[ pt_severity ;; Current severity (could be dynamic) pt_severity_initial ;; Arrival severity pt_creation_time ;; Time created pt_treatment_time ;; Treatment time remaining (dynamic) pt_treatment_time_initial ;; Treatment time initial pt_location ;; Location of patient pt_arrival_type ;; How patient arrived pt_waitingtime ;; How long is patient in department pt_allocated_caregiver ;; Is patient currently allocated caregiver (binary) ] caregivers-own[ caregiver_available ;; Is caregiver currently available ] minorgivers-own[ minorgiver_available ] ;; Where I know a variable will have lots of options, it's good to write them in. e.g. ;; Patient locations ;; 11 = Ambulance Bay ;; 12 = Waiting Room ;; 21 = Minors ;; 22 = Majors ;; 23 = Resus ;; 31 = Admission Ward ;; 91 = Discharged ;; =============== ;; Setup procedure - Get the simulation ready ;; =============== to setup clear-all ;; Resets the environment reset-ticks ;; Resets the built in clock set dist_patient_lv1_fq [0 0 1 1 1 2 2 3 4 5] ;; A set of values this variable can take set dist_patient_lv2_fq [0 0 0 0 1 1 1 2 3 3] ;; as above. etc set dist_patient_lv3_fq [0 0 0 0 0 0 0 0 1 2] set dist_lv1_treatment_times [1 1 1 1 1 1 2 2 3 3] ;; These distributions say that the options for set dist_lv2_treatment_times [3 3 3 3 4 4 5 6 8 9] ;; this value can be any of these numbers set dist_lv3_treatment_times [6 6 6 6 6 7 7 8 9 12] ;; This could be any distribution you wanted set dist_lv1_arrival_type [12] ;; At present, I've said this distribution can only be one value set dist_lv2_arrival_type [12 12 12 11 11] ;; Potential arrival types for lvl 2 patients set dist_lv3_arrival_type [11] set-default-shape caregivers "circle" set-default-shape minorgivers "square" set-default-shape patients "person" create-caregivers caregivers_number [set color blue setxy -5 12] ;; Make 4 caregivers create-minorgivers minorgivers_number [set color violet setxy -5 11] set minor_size minor_size_slider ;; Minors has this many cubicles set major_size major_size_slider ;; Majors has this many cubicles set resus_size resus_size_slider ;; Resus has this many cubicles setup-patches end ;; Setup patches to setup-patches ask patch -5 8 [set pcolor green] ask patch -5 0 [set pcolor orange] ask patch -5 -8 [set pcolor red] create-mylabels 1 [setxy -5 9 set label "Minors Cubicles" set color black] create-mylabels 1 [setxy -5 1 set label "Majors Cubicles" set color black] create-mylabels 1 [setxy -5 -7 set label "Resus Cubicles" set color black] end ;; ==================== ;; Main simulation code - Runs on repetition with click of go button ;; ==================== to go move-clock make-newpatients move-lvl3patients-maj-resus admit-lvl3patients-resus admit-lvl3patients-major admit-lvl2patients-major admit-lvl1patients-minor allocate-minorgivers allocate-caregivers treat-patients discharge-patients animate-patients-1 calculate-variables tick end to animate-patients-1 ask patients with [xcor < -4 AND pt_location = 23][setxy -4 -8] ask patients with [xcor < -4 AND pt_location = 22][setxy -4 0] ask patients with [xcor < -4 AND pt_location = 21][setxy -4 8] animate-patients-2 move-caregivers end to animate-patients-2 ask patients with [xcor = -4][animate-movetofreespace] end to animate-movetofreespace set xcor xcor + 0.5 if any? other patients-here [set xcor xcor + 1 animate-movetofreespace] end to move-caregivers ask links [transfer-xcor] end to transfer-xcor let temp_xcor [xcor] of end2 let temp_ycor [ycor] of end2 ask end1 [setxy temp_xcor temp_ycor + 2] end ;; =========== ;; World Clock - 1 tick is 10 minutes ;; =========== to move-clock set simticks simticks + 1 ask patients with [pt_location < 91] [set pt_waitingtime pt_waitingtime + 1] ask patients with [xcor < -5][set ycor ycor + 1] ask patients with [pt_location < 14][set label pt_waitingtime] ask patients with [pt_location > 20][set label pt_treatment_time] end ;; =============== ;; Patient Creator - Make new patients ;; =============== to make-newpatients create-patients one-of dist_patient_lv1_fq ;; Make n number of patients where n is one of the distribution for this patient severity [set pt_severity_initial 1 ;; Set variable initial severity to 1 set pt_severity 1 ;; Set variable severity to 1 set pt_treatment_time one-of dist_lv1_treatment_times ;; Pick one of the treatment times and set this patient's treatment time variable to this value set pt_treatment_time_initial pt_treatment_time set pt_arrival_type one-of dist_lv1_arrival_type ;; Set an arrival type set pt_location pt_arrival_type set pt_creation_time simticks ;; Set when we created them set color green ;; Set a color IF pt_arrival_type = 11 [set pt_waitingtime 6] set xcor -16 + random-float 1 set ycor -16 ] create-patients one-of dist_patient_lv2_fq [set pt_severity_initial 2 set pt_severity 2 set pt_treatment_time one-of dist_lv2_treatment_times set pt_treatment_time_initial pt_treatment_time set pt_arrival_type one-of dist_lv2_arrival_type set pt_location pt_arrival_type set pt_creation_time simticks set color orange set label pt_creation_time IF pt_arrival_type = 11 [set pt_waitingtime 6 set color blue] set xcor -14 + random-float 1 set ycor -16 ] create-patients one-of dist_patient_lv3_fq [set pt_severity_initial 3 set pt_severity 3 set pt_treatment_time one-of dist_lv3_treatment_times set pt_treatment_time_initial pt_treatment_time set pt_arrival_type one-of dist_lv3_arrival_type set pt_location pt_arrival_type set pt_creation_time simticks set label pt_creation_time set color red IF pt_arrival_type = 11 [set pt_waitingtime 6] set xcor -12 + random-float 1 set ycor -16 ] end ;; ========================== ;; MOVE PATIENTS TO NEW AREAS ;; ========================== to admit-lvl3patients-resus let temp_resus_spaces resus_size - count patients with [pt_location = 23] IF temp_resus_spaces < 1 [stop] IF count patients with [pt_severity = 3 AND ((pt_location = 11) OR (pt_location = 12))] < 1 [stop] ASK max-one-of patients with [pt_severity = 3 AND ((pt_location = 11) OR (pt_location = 12))][pt_waitingtime] [set pt_location 23] admit-lvl3patients-resus end to move-lvl3patients-maj-resus let temp_resus_spaces resus_size - count patients with [pt_location = 23] IF temp_resus_spaces < 1 [stop] IF count patients with [pt_severity = 3 AND pt_location = 22] < 1 [stop] ASK max-one-of patients with [pt_severity = 3 AND pt_location = 22][pt_waitingtime] [set pt_location 23] end to admit-lvl3patients-major let temp_major_spaces major_size - count patients with [pt_location = 22] IF temp_major_spaces < 1 [stop] IF count patients with [pt_severity = 3 AND ((pt_location = 11) OR (pt_location = 12))] < 1 [stop] ASK max-one-of patients with [pt_severity = 3 AND ((pt_location = 11) OR (pt_location = 12))][pt_waitingtime] [set pt_location 22] admit-lvl3patients-resus end to admit-lvl2patients-major let temp_major_spaces major_size - count patients with [pt_location = 22] IF temp_major_spaces < 1 [stop] IF count patients with [pt_severity = 2 AND ((pt_location = 11) OR (pt_location = 12))] < 1 [stop] ASK max-one-of patients with [pt_severity = 2 AND ((pt_location = 11) OR (pt_location = 12))][pt_waitingtime] [set pt_location 22] admit-lvl2patients-major end to admit-lvl1patients-minor let temp_minor_spaces minor_size - count patients with [pt_location = 21] IF temp_minor_spaces < 1 [stop] IF count patients with [pt_severity = 1 AND ((pt_location = 11) OR (pt_location = 12))] < 1 [stop] ASK max-one-of patients with [pt_severity = 1 AND ((pt_location = 11) OR (pt_location = 12))][pt_waitingtime] [set pt_location 21] admit-lvl1patients-minor end ;; =============================== ;; Allocate caregivers to patients ;; =============================== to allocate-caregivers Ask caregivers [if count out-link-neighbors > 0 [set caregiver_available 0]] ;; If you have a link to a neighbour, mark yourself unavailable Ask caregivers [if count out-link-neighbors = 0 [set caregiver_available 1]] ;; If you don't have any links, mark yourself available Ask patients [if count in-link-neighbors > 0 [set pt_allocated_caregiver 1]] ;; If you do have a linked caregiver, mark yourself allocated Ask patients [if count in-link-neighbors = 0 [set pt_allocated_caregiver 0]] ;; If you don't have any links to a caregiver, mark youself unallocated IF count patients with [pt_allocated_caregiver = 0] = 0 [stop] ;; Stop if there are no patients reporting no caregiver IF count caregivers with [caregiver_available = 1] = 0 [stop] ;; Stop if there are no caregivers reporting themselves available ;; Beginning in resus, if there is an unallocated patient, we ask a caregiver to join with longest wait. IF count patients with [pt_allocated_caregiver = 0 AND pt_location = 23] > 0 [ ask one-of caregivers with [caregiver_available = 1] [create-link-to max-one-of patients with [pt_location = 23 AND pt_allocated_caregiver = 0][pt_waitingtime] set color red allocate-caregivers ]] ;; Repeat for major and minors IF count caregivers with [caregiver_available = 1] = 0 [stop] IF count patients with [pt_allocated_caregiver = 0 AND pt_location = 22] > 0 [ ask one-of caregivers with [caregiver_available = 1] [create-link-to max-one-of patients with [pt_location = 22 AND pt_allocated_caregiver = 0][pt_waitingtime] set color orange allocate-caregivers ]] IF count caregivers with [caregiver_available = 1] = 0 [stop] IF count patients with [pt_allocated_caregiver = 0 AND pt_location = 21] > 0 [ask one-of caregivers with [caregiver_available = 1] [create-link-to max-one-of patients with [pt_location = 21 AND pt_allocated_caregiver = 0][pt_waitingtime] set color green allocate-caregivers ]] ;; Note the nesting of the same function within each IF statement. This means process iterates until all caregivers are allocated or no patients are waiting, thus ensuring all caregivers are allocated end ;; Allocate Minor Caregivers to allocate-minorgivers Ask minorgivers [if count out-link-neighbors > 0 [set minorgiver_available 0]] ;; If you have a link to a neighbour, mark yourself unavailable Ask minorgivers [if count out-link-neighbors = 0 [set minorgiver_available 1]] ;; If you don't have any links, mark yourself available Ask patients [if count in-link-neighbors > 0 [set pt_allocated_caregiver 1]] ;; If you do have a linked caregiver, mark yourself allocated Ask patients [if count in-link-neighbors = 0 [set pt_allocated_caregiver 0]] ;; If you don't have any links to a caregiver, mark youself unallocated IF count patients with [pt_allocated_caregiver = 0] = 0 [stop] ;; Stop if there are no patients reporting no caregiver IF count minorgivers with [minorgiver_available = 1] = 0 [stop] ;; Stop if there are no caregivers reporting themselves available IF count patients with [pt_allocated_caregiver = 0 AND pt_location = 21] > 0 [ask one-of minorgivers with [minorgiver_available = 1] [create-link-to max-one-of patients with [pt_location = 21 AND pt_allocated_caregiver = 0][pt_waitingtime] set color green allocate-minorgivers ]] end ;; ============== ;; Treat Patients ;; ============== to treat-patients ask patients [if count in-link-neighbors > 0 [set pt_allocated_caregiver 1]] ask patients with [pt_allocated_caregiver = 1][set pt_treatment_time pt_treatment_time - 1] end ;; ================== ;; Discharge Patients ;; ================== to discharge-patients ask patients with [pt_treatment_time < 1 AND ((PT_LOCATION = 21) OR (PT_LOCATION = 22) OR (PT_LOCATION = 23))] [set pt_location 91 ask my-in-links [ask end1 [setxy -5 12 set color blue] ask end2 [setxy 16 16 hide-turtle] die] ] ;; Moves patients who have completed treatment to discharged and deletes their link to a caregiver end to calculate-variables IFELSE count patients with [pt_location = 11] = 0 [set waittime_ambulance_avg 0 set waittime_ambulance_max 0] [set waittime_ambulance_avg (sum [pt_waitingtime] of patients with [pt_location = 11] / count patients with [pt_location = 11]) set waittime_ambulance_max (max [pt_waitingtime] of patients with [pt_location = 11]) set waittime_ambulance_avg waittime_ambulance_avg - 6 set waittime_ambulance_max waittime_ambulance_max - 6] IFELSE count patients with [pt_location = 12] = 0 [set waittime_waitroom_avg 0 set waittime_waitroom_avg 0] [set waittime_waitroom_avg (sum [pt_waitingtime] of patients with [pt_location = 12] / count patients with [pt_location = 12]) set waittime_waitroom_max (sum [pt_waitingtime] of patients with [pt_location = 12])] end
There is only one version of this model, created over 11 years ago by Christopher Chiswell.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Simply A&E Flow Model .png | preview | Preview for 'Simply A&E Flow Model ' | over 11 years ago, by Christopher Chiswell | Download |
This model does not have any ancestors.
This model does not have any descendants.