From de4abdbab2e80176a6ea6a284b8789010dd789cd Mon Sep 17 00:00:00 2001 From: Daniil <94884910+Filienko@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:35:14 -0800 Subject: [PATCH] Modified logs --- isacc_messaging/api/isacc_record_creator.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/isacc_messaging/api/isacc_record_creator.py b/isacc_messaging/api/isacc_record_creator.py index 4f139ef4..a984f9ca 100644 --- a/isacc_messaging/api/isacc_record_creator.py +++ b/isacc_messaging/api/isacc_record_creator.py @@ -358,23 +358,20 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]: comm = Communication(updated_comm) audit_entry( f"Generated an {comm.status} Communication/{comm.id} for CommunicationRequest/{cr.id}", - extra={"resource": updated_comm}, + extra={"new Communication": updated_comm}, level="debug" ) - # Update the CommunicationRequest as completed, since new Communication was sent - cr.status = "completed" - cr.persist() # If patient unsubscribed, mark as stopped if any( telecom_entry.system.lower() == 'sms' and telecom_entry.period.end for telecom_entry in getattr(patient, 'telecom', []) ): - comm.change_status(status="stopped") + stopped_comm = comm.change_status(status="stopped") errors.append({'id': cr.id, 'error': "Patient unsubscribed"}) audit_entry( f"Updated {comm} to {comm.status}, because patient unsubscribed", - extra={"resource": comm,}, + extra={"Updated Communication": stopped_comm}, level='debug' ) continue @@ -382,10 +379,10 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]: # Otherwise, update according to the feedback from the dispatch try: comm_status, comm_statusReason = self.process_cr(cr, successes) - comm.change_status(status=comm_status) + dispatched_comm = comm.change_status(status=comm_status) audit_entry( f"Updated status of Communication/{comm.id} to {comm_status}", - extra={"resource": f"Communication/{comm.id}", "statusReason": comm_statusReason}, + extra={"dispatched Communication": dispatched_comm, "statusReason": comm_statusReason}, level='debug' ) if comm_status == "in-progress": @@ -395,9 +392,10 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]: # Register an error encountered when sending a message audit_entry( f"Failed to send the message for CommunicationRequest/{cr.id} because {comm_statusReason}", - extra={"resource": f"Communication/{comm.id}", "statusReason": comm_status}, + extra={"Dispatched Communication": dispatched_comm, "statusReason": comm_status}, level='exception' ) + errors.append({'id': cr.id, 'error': comm_statusReason}) except Exception as e: # Register an error when sending a message