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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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'
Comment on lines +2 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, where do you get these values from?

Copy link
Author

@pbugni pbugni Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are UUIDs, built into the FHIR Migrations framework.
The most recent migration run is stored in a FHIR Basic object. To generate these automatically, run the following:
dc exec <service> flask migrate <name-of-migration-script-to-generate>

For example, I ran:
dc exec messagingservice flask migrate patch_DEEP_FUTURE_last_unfollowedup

and as it found the down_revision in the DB, fabricated a shell script in migrations/version/<name>.py which included those and boiler plate functions to extend.


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