Skip to content

Link DICOM Study records to Appointment#1380

Merged
MatMoore merged 3 commits intomainfrom
DTOSS-12709-model-changes
Apr 28, 2026
Merged

Link DICOM Study records to Appointment#1380
MatMoore merged 3 commits intomainfrom
DTOSS-12709-model-changes

Conversation

@MatMoore
Copy link
Copy Markdown
Contributor

@MatMoore MatMoore commented Apr 28, 2026

Description

Previously, there was an indirect link from Study to Appointment via GatewayAction, using the source_message_id, but this did not have a foreign key relation to provide integrity and so we couldn't easily make use of the relationship in django.

We will now require the appointment to be set when creating the study.

The previous iteration of the study demo data was using made up source_message_id values, so it's not possible to link historical data to appointments on environments that have run it. As a workaround, the migration just links it to any old appointment, but only on non-prod environments (none of this data is on prod yet).

This migration also adds created_at, updated_at fields so that studies are orderable, and renames order to reading_order in ReadingSessionItem. "order" is a bad name as it is a SQL keyword.

Jira link

https://nhsd-jira.digital.nhs.uk/browse/DTOSS-12709

Review notes

I haven't tested end to end with the gateway yet as I don't have it set up. I'll do that this afternoon unless anyone can vouch for it working in the meantime.

In most of the tests we are not dependent on GatewayAction anymore so I've avoided creating one. There's possibly further simplification that could be done but I didn't want to change things too much at once.

Review checklist

  • Check database queries are correctly scoped to current_provider
  • If this changes the gateway API (/api/v1/), confirm whether it is a breaking change — if so, a new major version (/api/v2/) is required (see ADR-006)

Previously, there was an indirect link from Study to Appointment via
GatewayAction, using the source_message_id, but this did not have a
foreign key relation to provide integrity and so we couldn't easily make
use of the relationship in django.

We will now require the appointment to be set when creating the Study.

The previous iteration of the Study demo data was using made up
source_message_id values, so it's not possible to link historical data to
appointments on environments that have run it. As a workaround, the
migration just links it to any old appointment, but only on non-prod
envirnments (none of this data is on prod yet).

This migration also adds created_at, updated_at fields so that studies
are orderable, and renames order to reading_order in ReadingSessionItem.
"order" is a bad name as it is a SQL keyword.
Make use of the new Study.appointment relation, and get rid of
the old method of looking up a Study by appointment id.
@sonarqubecloud
Copy link
Copy Markdown

@MatMoore MatMoore marked this pull request as ready for review April 28, 2026 11:01
Copy link
Copy Markdown
Contributor

@steventux steventux left a comment

Choose a reason for hiding this comment

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

This looks good to me. Can't see anything wrong or missing.

We likely want to relax the appointment in progress logic when recording dicom data but that's for another PR.

@steventux
Copy link
Copy Markdown
Contributor

I've tested this locally, migrations and seeding data works the association between dicom Study and Appointment is created as expected

@MatMoore MatMoore merged commit af742ad into main Apr 28, 2026
12 checks passed
@MatMoore MatMoore deleted the DTOSS-12709-model-changes branch April 28, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants