Bug #794
openFertility: quick-register partner dialog skips duplicate-patient guard, can orphan a patient record
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
PartnerSearchOrCreateDialog (nuvita-opd, shared by the registration screen's "Partner" section and the Fertility tab's Link control) has a "Register new" option that quick-creates a brand-new patient on submit. Two problems:
- It skips the platform's existing duplicate-patient guard/match-candidate check that the main registration flow runs - so the same real person can end up registered twice, as two separate patient records with two separate MRNs, if staff don't search first.
- When used from the registration screen's own Partner section, the quick-created partner patient is created immediately on dialog submit - before the main patient being registered is actually saved. If that main registration is then abandoned or fails validation, the quick-created partner patient is left behind as an orphan record (never linked to anyone, but with a real MRN).
Impact
Data-quality/compliance risk in a regulated system - duplicate or orphaned patient records with real MRNs, requiring manual cleanup, and risking clinical confusion if staff later work from the wrong duplicate.
Suggested fix (either, needs a product/design call)
- Run the same duplicate-match check the main registration flow uses before quick-creating a partner, surfacing candidates for staff to pick from instead; and/or
- Defer the partner's creation until the main patient's registration has actually committed (mirroring how the LINK itself is already deferred in this flow), rather than creating it eagerly on dialog submit.
Reference
#712 (the feature this gap was found during). File: nuvita-opd/apps/portal/src/components/patients/PartnerSearchOrCreateDialog.tsx.
S- Updated by SK - 2 days ago
- Status changed from New to Resolved
- Resolved By set to SK -
Fixed suggestion #1 only (the ticket says either suffices): PartnerSearchOrCreateDialog's "Register new" tab now runs the same near-duplicate check (name+phone, debounced) the main registration page uses via useMatchCandidates, with an inline candidate list offering "Use this patient" (same onLinked callback the Search tab already uses) or "None of these, register as new" (recorded with rejectedDuplicateCandidateIds for the audit trail). A follow-up review fix adds a visible notice when the duplicate check itself errors out, instead of silently rendering identical to "no duplicates found."
NOT addressed: suggestion #2 (deferring the partner's creation until the main patient's registration actually commits). The orphan-record risk if a registration is abandoned after the partner dialog is submitted still exists - reopen a separate ticket if that risk needs closing too.
Code: nuvita-opd apps/portal/src/components/patients/PartnerSearchOrCreateDialog.tsx(.test.tsx). Full OPD portal suite green on the merged tree (446 files / 5075 tests, type-check clean). Merged to dev: commit ddcd7060.