Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISACC.25.02.11 dev->main #80

Merged
merged 9 commits into from
Feb 11, 2025
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
2 changes: 1 addition & 1 deletion isacc_messaging/models/isacc_fhirdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def __repr__(self):


DEEP_PAST = IsaccFHIRDate("1975-01-01T00:00:00Z")
DEEP_FUTURE = IsaccFHIRDate("2025-01-01T00:00:00Z")
DEEP_FUTURE = IsaccFHIRDate("2050-01-01T00:00:00Z")
2 changes: 1 addition & 1 deletion isacc_messaging/models/isacc_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def mark_followup_extension(self, persist_on_change=True):

save_value = oldest_reply
if not oldest_reply:
# without any pending outgoing messages, add a bogus value deep in the past to keep the patient
# without any pending outgoing messages, add a bogus value deep in the future to keep the patient
# in the search (searching by extension will eliminate patients without said extension)
save_value = DEEP_FUTURE

Expand Down
37 changes: 37 additions & 0 deletions migrations/versions/patch_DEEP_FUTURE_last_unfollowedup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Migration script generated for patch_DEEP_FUTURE_last_unfollowedup
revision = '7542b481-21cb-483c-b72a-6c1502375a65'
down_revision = '17f3b60d-0777-4d0e-bb32-82e670b573a7'

import logging
from isacc_messaging.models.fhir import next_in_bundle
from isacc_messaging.models.isacc_fhirdate import (
IsaccFHIRDate as FHIRDate,
DEEP_FUTURE,
)
from isacc_messaging.models.isacc_patient import (
IsaccPatient as Patient,
LAST_UNFOLLOWEDUP_URL,
)

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


def upgrade():
# Passed up the DEEP_FUTURE date used on patients w/o pending outgoing
# value; corrected in PR #77, but need to migrate any existing patients
# with expired value in their extension.
obsolete_DEEP_FUTURE = FHIRDate("2025-01-01T00:00:00Z")
active_patients = Patient.active_patients()
for json_patient in next_in_bundle(active_patients):
patient = Patient(json_patient)
if patient.get_extension(LAST_UNFOLLOWEDUP_URL, "valueDateTime") != obsolete_DEEP_FUTURE:
continue
patient.mark_followup_extension(persist_on_change=True)
logging.info(f"migration corrected {patient.id} {LAST_UNFOLLOWEDUP_URL}")
logging.info("migration complete")


def downgrade():
# No value in reverting
print('downgraded')

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')