Skip to content

Commit

Permalink
Handling communications for unsubscribed patients
Browse files Browse the repository at this point in the history
  • Loading branch information
Filienko committed Feb 15, 2024
1 parent 16d2794 commit b78cce8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions isacc_messaging/api/isacc_record_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def dispatch_cr(self, cr: CommunicationRequest):
# In case of unsubcribed patient, mark as unsubscribed
patient.unsubcribe()
cr.status = "on-hold"
c.status = "suspended"
c.status = "not-done"
else:
# For other causes of failed communication, mark the reason for failed request as unknown
cr.status = "unknown"
c.status = "on-hold"
c.status = "entered-in-error"
c.persist()
audit_entry(
f"Updated Communication to status to {c.status}",
Expand Down Expand Up @@ -246,7 +246,6 @@ def on_twilio_message_status_update(self, values):
# Callback only occurs on completed Communications
c = cr.create_communication_from_request(status="completed")
c = Communication(c)

new_c = c.persist()
audit_entry(
f"Created Communication resource:",
Expand All @@ -259,7 +258,7 @@ def on_twilio_message_status_update(self, values):
else:
# Update the status of the communication to completed
comm = Communication(existing_comm)
comm.status = 'completed'
comm.status = 'completed' if message_status == 'delivered' else 'in-progress'
updated_comm = comm.persist()
audit_entry(
f"Received /MessageStatus callback with status {message_status} on existing Communication resource",
Expand Down Expand Up @@ -361,8 +360,12 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
for telecom_entry in patient.telecom
)
except Exception as e:
cr.status = "on-hold"
cr.status = "unknown"
skipped_crs.append(cr)
c = cr.create_communication_from_request()
c = Communication(c)
c.status = "entered-in-error"
c.persist()
audit_entry(
f"Failed to send the message, {patient} does not have phone number",
extra={"resource": f"CommunicationResource/{cr.id}", "exception": e},
Expand All @@ -382,6 +385,15 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
if patient_unsubscribed or not patient.active:
if patient_unsubscribed:
cr.status = "on-hold"
c = cr.create_communication_from_request()
c = Communication(c)
c.status = "not-done"
new_c = c.persist()
audit_entry(
f"Generated Communication for unsubscribed patient",
extra={"resource": f"{new_c}"},
level='debug'
)
else:
cr.status = "revoked"
if cr.occurrenceDateTime.date < now:
Expand Down

0 comments on commit b78cce8

Please sign in to comment.