Project

General

Profile

Actions

Bug #793

open
S- RH

Fertility: patient merge doesn't repoint an active partner link

Bug #793: Fertility: patient merge doesn't repoint an active partner link

Added by SK - 3 days ago. Updated 2 days ago.

Status:
Resolved
Priority:
Normal
Target version:
-
Start date:
11/10/2026
Due date:
% Done:

0%

Estimated time:
Resolved By:

Description

Follow-up from #712 (Fertility couple-level partner linking), found during that work's final code review (2026-11-10) and deliberately NOT fixed there to avoid a risky late design change.

Summary
When a patient who has an active PatientPartnerLink (nuvita-emr) is merged away into another patient record via the existing patient-merge feature, the merge does not repoint the partner link or its participant rows. Every other patient-keyed entity IS repointed during a merge (e.g. ImplantDevice, CareEnrolment) - PatientPartnerLink and its participant table are the exception.

Impact

  • The surviving patient is left with no partner link at all (silently loses the relationship).
  • GetPartner can continue to return the merged-away patient's id, since nothing marks the link as needing repointing.
  • If semen analysis or other partner-attributed data was already recorded against the merged-away patient's id, it may now point at a record that's been merged out of normal use.

Suggested fix
Add PatientPartnerLink/PatientPartnerLinkParticipant repointing to PatientMergeService's merge routine (nuvita-emr/apps/api/src/Nuvita.Emr/Patients/PatientMergeService.cs), with a defined collision rule for the case where the survivor already has its own active link (two real links would need to resolve to one, or the merge should be blocked/flagged for manual review). At minimum, GetPartnerAsync should follow MergedIntoPatientId when the partner side has been merged away.

Reference
#712 (the feature this gap was found during). Design/spec: clinq-docs/modules/emr/specs/2026-11-09-fertility-partner-linking-design.md.

S- Updated by SK - 2 days ago Actions #1

  • Status changed from New to Resolved
  • Resolved By set to SK -

Fixed. PatientMergeService now repoints a patient's active PatientPartnerLink (and its participant row) to the survivor on merge, resolving the collision rule as proposed: if the survivor already holds its own active link, the loser's colliding link is archived in place (not overwritten) rather than blocking or needing manual review. Full unmerge-replay symmetry added too, including restoring an archived link on unmerge unless either side has since picked up a new one.

Code: nuvita-emr apps/api/src/Nuvita.Emr/Patients/PatientMergeService.cs (RepointPartnerLinkAsync / ReplayPartnerLinkAsync / ReplayArchivedPartnerLinkAsync). New test: PatientPartnerLinkPatientMergeTests.cs.

Full EMR backend suite green on the merged tree (3857 passed, 2 pre-existing unrelated skips, 0 failed). Merged to dev: commit ae7bd0e.

S- Updated by SK - 2 days ago Actions #2

  • Assignee changed from SK - to Roshni Harish.

Reassigning to Roshni for verification.

Actions

Also available in: PDF Atom