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

migration for surpassed deep future date #79

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
ivan-c marked this conversation as resolved.
Show resolved Hide resolved

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