-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.clp
281 lines (252 loc) · 11.1 KB
/
rules.clp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
; Declare initial facts
; At beginning, six idling clinicians
; Templates:
; clinician <clinician_id> <status> <patient>
; clinician_time <clinician_id> <minutes>
; patient <patient_id> <need> <volume>
(deffacts initial-facts
(clinician 0 idle none)
(clinician_time 0 0)
(clinician 1 idle none)
(clinician_time 1 0)
(clinician 2 idle none)
(clinician_time 2 0)
(clinician 3 idle none)
(clinician_time 3 0)
(clinician 4 idle none)
(clinician_time 4 0)
(clinician 5 idle none)
(clinician_time 5 0)
(patient 0 thiopental 0)
(patient 1 als 0)
(patient 2 zero_negative_blood_unit 0)
(patient 3 tourniquet 0)
(patient 4 REBOA 0)
(patient 5 toracotomy 0)
);
; Declare rules
; Rules for K1
(defrule administer_thiopental "Clinician administers thiopental to a patient"
(declare (salience 2))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id thiopental ?volume)
=>
(assert (clinician ?clinician_id working ?patient_id))
; let's assume that a clinician lasts 10 minutes administrating thiopental
(assert (clinician_time ?clinician_id (+ ?time 10)))
(assert (patient ?patient_id check_hypotension ?volume))
(retract ?clinician ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " administers thiopental to patient " ?patient_id crlf)
);
(defrule check_patient_hypotension "Clinician checks patient's tension"
(declare (salience 0))
(patient ?patient_id check_hypotension ?volume)
(clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time)
=>
; let's assume that a clinician checks the patient's tension every 10 minutes for an hour
(assert (clinician_time ?clinician_id (+ ?time 10)))
(retract ?clinician_time)
(printout t "The clinician " ?clinician_id " checks the tension of the patient " ?patient_id crlf)
);
(defrule stop_checking_patient_hypotension "Clinician stops checking patient's tension"
(declare (salience 1))
?patient <- (patient ?patient_id check_hypotension ?volume)
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time&:(> ?time 59))
=>
(assert (clinician ?clinician_id idle none))
(assert (clinician_time ?clinician_id 0))
; the patient is healthy now
(retract ?patient ?clinician ?clinician_time)
(printout t "Patient " ?patient_id " is healthy now" crlf)
);
; Rules for K2
(defrule start_als "Clinician starts ALS process"
(declare (salience 2))
?clinician <- (clinician ?clinician_id idle none)
?patient <- (patient ?patient_id als ?volume)
=>
(assert (clinician ?clinician_id working ?patient_id))
(assert (patient ?patient_id adrenaline ?volume))
(retract ?clinician ?patient)
(printout t "The clinician " ?clinician_id " starts ALS process on patient " ?patient_id crlf)
);
(defrule administer_adrenaline "Clinician administers adrenaline to a patient"
(declare (salience 0))
(patient ?patient_id adrenaline ?volume)
?clinician_time <- (clinician_time ?clinician_id ?time)
(clinician ?clinician_id working ?patient_id)
=>
; let's assume that a clinician administers 5mg (15 minutes total) to the patient
(assert (clinician_time ?clinician_id (+ ?time 3)))
(retract ?clinician_time)
(printout t "The clinician " ?clinician_id " administers adrenaline to patient " ?patient_id crlf)
);
(defrule stop_als "Clinician stops ALS process"
(declare (salience 1))
?patient <- (patient ?patient_id adrenaline ?volume)
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time&:(> ?time 14))
=>
(assert (clinician ?clinician_id idle none))
(assert (clinician_time ?clinician_id 0))
; the patient is healthy now
(retract ?patient ?clinician ?clinician_time)
(printout t "Patient " ?patient_id " is healthy now" crlf)
);
; Rules for K3 and K4
; Rules for K3
(defrule administer_tranexamic_acid "Clinician administers tranexamic acid to a patient"
(declare (salience 7))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id tranexamic_acid ?volume)
=>
(assert (patient ?patient_id fibrinogen ?volume))
(retract ?patient)
(printout t "The clinician " ?clinician_id " administers tranexamic acid to patient " ?patient_id crlf)
);
(defrule administer_fibrinogen "Clinician administers fibrinogen to a patient"
(declare (salience 8))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id fibrinogen ?volume)
=>
(assert (patient ?patient_id zero_negative_blood_unit ?volume))
(retract ?patient)
(printout t "The clinician " ?clinician_id " administers fibrinogen to patient " ?patient_id crlf)
);
(defrule administer_zero_negative_blood_unit "Clinician administers zero negative blood unit to a patient"
(declare (salience 3))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id zero_negative_blood_unit ?volume)
=>
(assert (clinician ?clinician_id working ?patient_id))
(assert (clinician_time ?clinician_id (+ ?time 1)))
(assert (patient ?patient_id zero_negative_blood_unit (+ ?volume 1)))
(retract ?clinician ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " administers zero negative blood unit to patient " ?patient_id crlf)
);
(defrule clinician_administer_zero_negative_blood_unit "Already working clinician administers zero negative blood unit to a patient"
(declare (salience 4))
?patient <- (patient ?patient_id zero_negative_blood_unit ?volume)
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time)
=>
(assert (clinician_time ?clinician_id (+ ?time 1)))
(assert (patient ?patient_id zero_negative_blood_unit (+ ?volume 1)))
(retract ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " administers zero negative blood unit to patient " ?patient_id crlf)
);
(defrule do_not_administer_zero_negative_blood_unit "Stop clinician from administrating zero negative blood unit to a patient"
(declare (salience 5))
?patient <- (patient ?patient_id zero_negative_blood_unit 3)
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time)
=>
(assert (clinician_time ?clinician_id (+ ?time 1)))
(retract ?clinician_time)
);
(defrule administer_MTP "Clinician starts Massive Transfusion Protocol (MTP)"
(declare (salience 6))
?patient <- (patient ?patient_id zero_negative_blood_unit 3)
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id 0)
=>
; clinician can only start MTP when (fibrinogen & tranexamic_acid & 3*zero_negative_blood_unit)
(assert (clinician ?clinician_id idle none))
(assert (clinician_time ?clinician_id 0))
(retract ?patient ?clinician)
(printout t "The clinician " ?clinician_id " starts massive transfusion protocol on patient " ?patient_id crlf)
(printout t "Patient " ?patient_id " is healthy now " crlf)
);
; Rules for K4
(defrule check_missing_drugs "Clinician is notified by missing drug administration"
(declare (salience 7))
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id 5)
?patient <- (patient ?patient_id zero_negative_blood_unit ?volume&:(> ?volume 0))
=>
; clinician checks time and drugs administered
(assert (patient ?patient_id tranexamic_acid ?volume))
(assert (clinician_time ?clinician_id 0))
(retract ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " decides to administer tranexamic acid and fibrinogen to " ?patient_id crlf)
);
; Rules for K5
(defrule apply_tourniquet "Clinician apply thiopental to a patient"
(declare (salience 2))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id tourniquet ?volume)
=>
(assert (clinician ?clinician_id working ?patient_id))
; let's assume that a clinician lasts 5 minutes applying tourniquet
(assert (clinician_time ?clinician_id (+ ?time 5)))
(assert (patient ?patient_id notify_clinician 1))
(retract ?clinician ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " applies tourniquet to patient " ?patient_id crlf)
);
(defrule apply_reboa "Clinician apply REBOA to a patient"
(declare (salience 2))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id REBOA ?volume)
=>
(assert (clinician ?clinician_id working ?patient_id))
; let's assume that a clinician lasts 5 minutes applying REBOA
(assert (clinician_time ?clinician_id (+ ?time 5)))
(assert (patient ?patient_id notify_clinician 1))
(retract ?clinician ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " applies REBOA to patient " ?patient_id crlf)
);
(defrule apply_toracotomy "Clinician apply toracotomy to a patient"
(declare (salience 2))
?clinician <- (clinician ?clinician_id idle none)
?clinician_time <- (clinician_time ?clinician_id ?time)
?patient <- (patient ?patient_id toracotomy ?volume)
=>
(assert (clinician ?clinician_id working ?patient_id))
; let's assume that a clinician lasts 5 minutes applying toracotomy
(assert (clinician_time ?clinician_id (+ ?time 5)))
(assert (patient ?patient_id notify_clinician 1))
(retract ?clinician ?patient ?clinician_time)
(printout t "The clinician " ?clinician_id " applies toracotomy to patient " ?patient_id crlf)
);
; Every 5 min, we check the patient with a tourniquet/REBOA/toracotomy applied, if 15 min has passed, the clinician is notified
; We assume that the clinician is notified 4 times (1 hour)
(defrule check_patient_notification "Check patient time after tourniquet/REBOA/toracotomy"
(declare (salience 0))
(patient ?patient_id notify_clinician ?volume)
(clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time&:(< ?time 15))
=>
(assert (clinician_time ?clinician_id (+ ?time 5)))
(retract ?clinician_time)
);
(defrule notify_clinician "Notify clinician"
(declare (salience 0))
?patient <- (patient ?patient_id notify_clinician ?volume)
(clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time&:(> ?time 14))
=>
(assert (patient ?patient_id notify_clinician (+ ?volume 1)))
(assert (clinician_time ?clinician_id 0))
(retract ?patient ?clinician_time)
(printout t "Notification: Clinician " ?clinician_id ", " (* ?time ?volume) " minutes has passed since the treatment application to patient " ?patient_id crlf)
);
(defrule stop_notification "The clinician is not notified anymore about a patient"
(declare (salience 1))
?patient <- (patient ?patient_id notify_clinician 5)
?clinician <- (clinician ?clinician_id working ?patient_id)
?clinician_time <- (clinician_time ?clinician_id ?time)
=>
(assert (clinician ?clinician_id idle none))
(assert (clinician_time ?clinician_id 0))
; the patient is healthy now
(retract ?patient ?clinician ?clinician_time)
(printout t "Patient " ?patient_id " is healthy now" crlf)
);