@@ -88,11 +88,11 @@ def dispatch_cr(self, cr: CommunicationRequest):
88
88
# In case of unsubcribed patient, mark as unsubscribed
89
89
patient .unsubcribe ()
90
90
cr .status = "on-hold"
91
- c .status = "suspended "
91
+ c .status = "not-done "
92
92
else :
93
93
# For other causes of failed communication, mark the reason for failed request as unknown
94
94
cr .status = "unknown"
95
- c .status = "on-hold "
95
+ c .status = "entered-in-error "
96
96
c .persist ()
97
97
audit_entry (
98
98
f"Updated Communication to status to { c .status } " ,
@@ -246,7 +246,6 @@ def on_twilio_message_status_update(self, values):
246
246
# Callback only occurs on completed Communications
247
247
c = cr .create_communication_from_request (status = "completed" )
248
248
c = Communication (c )
249
-
250
249
new_c = c .persist ()
251
250
audit_entry (
252
251
f"Created Communication resource:" ,
@@ -259,7 +258,7 @@ def on_twilio_message_status_update(self, values):
259
258
else :
260
259
# Update the status of the communication to completed
261
260
comm = Communication (existing_comm )
262
- comm .status = 'completed'
261
+ comm .status = 'completed' if message_status == 'delivered' else 'in-progress'
263
262
updated_comm = comm .persist ()
264
263
audit_entry (
265
264
f"Received /MessageStatus callback with status { message_status } on existing Communication resource" ,
@@ -361,8 +360,12 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
361
360
for telecom_entry in patient .telecom
362
361
)
363
362
except Exception as e :
364
- cr .status = "on-hold "
363
+ cr .status = "unknown "
365
364
skipped_crs .append (cr )
365
+ c = cr .create_communication_from_request ()
366
+ c = Communication (c )
367
+ c .status = "entered-in-error"
368
+ c .persist ()
366
369
audit_entry (
367
370
f"Failed to send the message, { patient } does not have phone number" ,
368
371
extra = {"resource" : f"CommunicationResource/{ cr .id } " , "exception" : e },
@@ -382,6 +385,15 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
382
385
if patient_unsubscribed or not patient .active :
383
386
if patient_unsubscribed :
384
387
cr .status = "on-hold"
388
+ c = cr .create_communication_from_request ()
389
+ c = Communication (c )
390
+ c .status = "not-done"
391
+ new_c = c .persist ()
392
+ audit_entry (
393
+ f"Generated Communication for unsubscribed patient" ,
394
+ extra = {"resource" : f"{ new_c } " },
395
+ level = 'debug'
396
+ )
385
397
else :
386
398
cr .status = "revoked"
387
399
if cr .occurrenceDateTime .date < now :
0 commit comments