Skip to content

Commit

Permalink
Merge pull request #78 from uwcirg/bugfix/correct-next-outgoing
Browse files Browse the repository at this point in the history
adjust user's next-outgoing extension AFTER communication request status change
  • Loading branch information
pbugni authored Jan 15, 2025
2 parents 9e7630f + b46af32 commit dc2740b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ ENV FLASK_APP=isacc_messaging.app:create_app() \

EXPOSE "${PORT}"

CMD gunicorn --bind "0.0.0.0:${PORT:-8000}" ${FLASK_APP}
CMD flask upgrade && gunicorn --bind "0.0.0.0:${PORT:-8000}" ${FLASK_APP}
10 changes: 4 additions & 6 deletions isacc_messaging/api/isacc_record_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,18 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
sent = 0
for cr_json in next_in_bundle(result):
cr = CommunicationRequest(cr_json)
# as that message was likely the next-outgoing for the patient,
# update the extension used to track next-outgoing-message time
patient = resolve_reference(cr.recipient[0].reference)
patient.mark_next_outgoing()

# Do not interact with CR if the patient is inactive or sending date is past the cutoff
if not patient.active or cr.occurrenceDateTime.date < cutoff:
cr.status = "revoked"
cr.persist()
revoked_reason = ""
revoked_reason = "Past the cutoff"
if not patient.active:
revoked_reason = "Recipient is not active"
else:
revoked_reason = "Past the cutoff"
cr.report_cr_status(status_reason=revoked_reason)
errors.append({'id': cr.id, 'error': revoked_reason})
patient.mark_next_outgoing() # update given state change
continue

# Otherwise, create a communication
Expand All @@ -384,6 +380,7 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
extra={"Updated Communication": stopped_comm},
level='debug'
)
patient.mark_next_outgoing() # update given state change
continue

# Otherwise, update according to the feedback from the dispatch
Expand Down Expand Up @@ -419,6 +416,7 @@ def execute_requests(self) -> Tuple[List[dict], List[dict]]:
extra={"resource": f"Communication/{comm.id}", "statusReason": e},
level='exception'
)
patient.mark_next_outgoing() # update given state change

# Flooding system on occasions such as a holiday message to all,
# leads to an overwhelmed system. Restrict the flood by processing
Expand Down
24 changes: 24 additions & 0 deletions migrations/versions/recalculate-next-outgoing-times.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Migration script generated for recalculate-next-outgoing-times
revision = '17f3b60d-0777-4d0e-bb32-82e670b573a7'
down_revision = 'None'

import logging
from isacc_messaging.models.fhir import next_in_bundle
from isacc_messaging.models.isacc_patient import IsaccPatient as Patient

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')


def upgrade():
# iterate over active patients; confirm/set next-outgoing extension
active_patients = Patient.active_patients()
for json_patient in next_in_bundle(active_patients):
patient = Patient(json_patient)
patient.mark_next_outgoing(persist_on_change=True)
logging.info('corrected next-outgoing-times')


def downgrade():
# Nothing to undo
logging.info('downgraded')

0 comments on commit dc2740b

Please sign in to comment.