Skip to content

Link previous mammograms to appointment instead of participant#875

Merged
swebberuk merged 1 commit intomainfrom
DTOSS-11959-appointment-mammogram
Jan 14, 2026
Merged

Link previous mammograms to appointment instead of participant#875
swebberuk merged 1 commit intomainfrom
DTOSS-11959-appointment-mammogram

Conversation

@swebberuk
Copy link
Copy Markdown
Contributor

@swebberuk swebberuk commented Jan 7, 2026

Description

Details of previous mammograms are currently linked directly to a participant. Details are stored in participants_participantreportedmammogram, which has a participant_id column.

This ticket links previous mammograms to an appointment.

Replaced participant_id column with appointment_id column in participants_participantreportedmammogram.

Updates seed data .yaml files to move previous_mammograms from participant to appointment.

Jira link

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

Review notes

Review checklist

  • Check database queries are correctly scoped to current_provider

@swebberuk swebberuk force-pushed the DTOSS-11959-appointment-mammogram branch 3 times, most recently from f67dfdd to 23aaf10 Compare January 12, 2026 11:15
@swebberuk swebberuk changed the title [wip] Dtoss 11959 appointment mammogram Link previous mammograms to appointment instead of participant Jan 12, 2026
@swebberuk swebberuk marked this pull request as ready for review January 12, 2026 11:27
@swebberuk swebberuk requested a review from a team January 12, 2026 11:27
@swebberuk
Copy link
Copy Markdown
Contributor Author

swebberuk commented Jan 12, 2026

SonarQube reports duplicated code in 0054_appointmentreportedmammogram_and_more.py and test_participant_reported_mammogram_views.py.

Do we want to find a way to avoid these warnings, or instead is there a way we can ignore them for this PR?

https://sonarcloud.io/component_measures?id=NHSDigital_dtos-manage-breast-screening&pullRequest=875&metric=new_duplicated_lines_density&view=list

from manage_breast_screening.core.views.generic import (
AddWithAuditView,
DeleteWithAuditView,
UpdateWithAuditView,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could rename this file to appointment_reported_mammogram_views.py, and also rename test_participant_reported_mammogram_views.py to test_appointment_reported_mammogram_views.py.

Didn't want to do that yet in case the renaming confused merges and code reviews, as same files have also been altered for "appointments can't proceed if previous mammogram is within 6 months".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not an issue if we keep the name the same 🙂

@MatMoore
Copy link
Copy Markdown
Contributor

SonarQube reports duplicated code in 0054_appointmentreportedmammogram_and_more.py and test_participant_reported_mammogram_views.py.

Do we want to find a way to avoid these warnings, or instead is there a way we can ignore them for this PR?

https://sonarcloud.io/component_measures?id=NHSDigital_dtos-manage-breast-screening&pullRequest=875&metric=new_duplicated_lines_density&view=list

I think we should ignore all tests and all migrations. Do you want to add it the "Duplication exclusions" in general settings?

@pytest.fixture
def reported_earlier(self):
return ParticipantReportedMammogram(
return AppointmentReportedMammogram(
Copy link
Copy Markdown
Contributor

@MatMoore MatMoore Jan 12, 2026

Choose a reason for hiding this comment

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

Sorry to be annoying, but can we keep the name as it was?

The name was originally meant to distinguish from confirmed mammograms. Even though we're now storing the appointment it was reported in, it's still the participant that reported it, and that's significant because details might be missing or inaccurate when the participant can't recall

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, no problem.

Now keeping participants_participantreportedmammogram table, rather than replacing it with participants_appointmentreportedmammogram. Class names remain unchanged.

Replaced participant_id column with appointment_id column in participants_participantreportedmammogram.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah - and we let users edit and update reported mammograms, but we probably don't want to let updates happen to confirmed mammograms.

migrations.AddField(
model_name='participantreportedmammogram',
name='appointment',
field=models.ForeignKey(default='e0a973c8-8630-4cf2-9313-333da3f3c590', on_delete=django.db.models.deletion.PROTECT, related_name='reported_mammograms', to='participants.appointment'),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had to specify a default value in migration script for new appointment_id column, as is not-nullable. Used randomly generated UUID. Hoping this is okay, as don't yet have live data that we need to manage the migration of.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The other way to do it is add it as nullable, then have a RunSQL to populate it, then make it non nullable.

Don't mind skipping that for now though. Ideally I want to squash or recreate the old migrations at some point prior to go live.

migrations.AddField(
model_name='participantreportedmammogram',
name='appointment',
field=models.ForeignKey(default='e0a973c8-8630-4cf2-9313-333da3f3c590', on_delete=django.db.models.deletion.PROTECT, related_name='reported_mammograms', to='participants.appointment'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The other way to do it is add it as nullable, then have a RunSQL to populate it, then make it non nullable.

Don't mind skipping that for now though. Ideally I want to squash or recreate the old migrations at some point prior to go live.

@swebberuk swebberuk force-pushed the DTOSS-11959-appointment-mammogram branch 2 times, most recently from 9a0b8f9 to 69ba361 Compare January 14, 2026 12:35
Replaced participant_id with appointment_id in participants_participantreportedmammogram

Moved previous_mammograms from participant to appointment for seed_demo_data
@swebberuk swebberuk force-pushed the DTOSS-11959-appointment-mammogram branch from 69ba361 to dae7507 Compare January 14, 2026 12:36
@sonarqubecloud
Copy link
Copy Markdown

@swebberuk swebberuk merged commit 614c375 into main Jan 14, 2026
14 checks passed
@swebberuk swebberuk deleted the DTOSS-11959-appointment-mammogram branch January 14, 2026 12:42
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.

3 participants