Bug #793
openFertility: patient merge doesn't repoint an active partner link
0%
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.