Skip to content

Fix incorrect workflow steps state after resuming an appointment started by somebody else#1274

Merged
MatMoore merged 6 commits intomainfrom
DTOSS-12517-fix-confirm-identity-completed-state
Apr 15, 2026
Merged

Fix incorrect workflow steps state after resuming an appointment started by somebody else#1274
MatMoore merged 6 commits intomainfrom
DTOSS-12517-fix-confirm-identity-completed-state

Conversation

@MatMoore
Copy link
Copy Markdown
Contributor

@MatMoore MatMoore commented Mar 31, 2026

Description

We have implemented a rule, is_identity_confirmed_by_user, meaning that an identity check completed by one user doesn't count if a second user takes the appointment over.

This logic is being used to redirect the user to the appropriate step when resuming an appointment, but it was not being applied when rendering the workflow sidebar, creating two bugs:

  • The identity check steps was falsely being marked as completed
  • The following steps were clickable, allowing the identity check to be easily skipped

I've changed this so that the identity check step is correctly marked as not completed, and the following steps are greyed out even if complete.

Screenshot showing disabled but completed steps in the workflow sidebar

Taking over other people's appointments has not been fully considered in the prototype yet, but we have a design ticket to think about this further: https://nhsd-jira.digital.nhs.uk/browse/DTOSS-11468

In the meantime, this change should make the sidebar and redirect behaviour consistent with each other.

It is still possible to bypass workflow steps by hacking the URL, but I've raised DTOSS-12594 to deal with that separately.

Jira link

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

Review notes

Please let me know if there's any improvements that could be made to the tests here. I'd like to ensure we have good coverage, and there might be states I haven't thought of.

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)

@MatMoore MatMoore changed the title Dtoss 12517 fix confirm identity completed state WIP - Fix confirm identity incorrectly showing as completed after resuming Mar 31, 2026
@MatMoore MatMoore changed the title WIP - Fix confirm identity incorrectly showing as completed after resuming WIP - Fix confirm identity incorrectly showing as completed after resuming appointment Mar 31, 2026
Base automatically changed from DTOSS-12517-prevent-other-users-accessing-in-progress-appointments to main March 31, 2026 14:58
@MatMoore MatMoore changed the title WIP - Fix confirm identity incorrectly showing as completed after resuming appointment Fix incorrect workflow steps state after resuming an appointment started by somebody else Apr 1, 2026
@MatMoore MatMoore force-pushed the DTOSS-12517-fix-confirm-identity-completed-state branch 2 times, most recently from 2e33c74 to 5436ce6 Compare April 1, 2026 14:43
for step in AppointmentWorkflowStepCompletion.StepNames:
is_completed = step.name in self.completed_steps
is_current = step.name == active_workflow_step
is_disabled = not all_previous_steps_completed and not is_current
Copy link
Copy Markdown
Contributor Author

@MatMoore MatMoore Apr 1, 2026

Choose a reason for hiding this comment

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

Changed this line so that in the case where the current step is complete it can still be disabled.

In the case of taking over an appointment, completed_steps will include later steps completed by the original user, but not CONFIRM_IDENTITY.

self.appointment.completed_workflow_steps.values_list(
"step_name", flat=True
).distinct()
self.appointment.completed_workflow_steps.filter(
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.

This now filters out CONFIRM_IDENTITY steps completed by someone other than the current user.

@MatMoore MatMoore added the deploy label Apr 1, 2026
@MatMoore MatMoore marked this pull request as ready for review April 1, 2026 14:57
Copy link
Copy Markdown
Contributor

@swebberuk swebberuk left a comment

Choose a reason for hiding this comment

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

Looks good to me. Will need to resolve conflicts before merging.

@swebberuk swebberuk force-pushed the DTOSS-12517-fix-confirm-identity-completed-state branch from f9c18c7 to 5436ce6 Compare April 14, 2026 14:16
Previously this test was mixed in with the test of medical history, but
I'd like to cover everything to do with workflow state in
test_mammogram_workflow.py.

The previous test actually tested a nonsensical situation where pausing
and resuming kicks you back to confirm identity.

This is because the medical history test is jumping into the middle of
an appointment, and AppointmentWorkflowStepCompletion hasn't been
populated properly. This is the case for several other appointment
tests as well. It is likely not causing problems because of
a lax enforcement of workflow state that we should address.

The new version of the test goes through the workflow from the beginning
so the AppointmentWorkflowCompletion data is in the correct state.
When computing the completed workflow steps, don't count Confirm
Identity as completed if it was completed by another user.
- Delegate to AppointmentWorkflowService for this
- Extract out into a different presenter, as AppointmentPresenter has
  too many responsibilities
In the case where a user takes over an appointment from another user,
we redirect them to confirm identity regardless of whether the
other user completed it.

However, if the first user completed later steps, the workflow
sidebar was showing these steps as clickable links, providing
a route to bypass the identity check.

This commit ensures that those later steps will be considered disabled
and the link not rendered.

In this case the steps are both disabled and complete, so we should show
a checked icon, but in grey (to match disabled steps with numbers).
@MatMoore MatMoore force-pushed the DTOSS-12517-fix-confirm-identity-completed-state branch from 5436ce6 to 20110fa Compare April 15, 2026 12:17
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

The review app at this URL has been deleted:
https://pr-1274.manage-breast-screening.non-live.screening.nhs.uk

@MatMoore MatMoore merged commit a6d2061 into main Apr 15, 2026
13 checks passed
@MatMoore MatMoore deleted the DTOSS-12517-fix-confirm-identity-completed-state branch April 15, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants