Skip to content

No dedicated patient-merge event; consumers must rely on the incidental SaveServiceEvent<PersonMergeLog> #6195

Description

@dkayiwa

Summary

There is no dedicated patient-merge domain event. Consumers that need to react to a merge (read-store/CDC projections, cache invalidation, analytics) must depend on an incidental side effect rather than a first-class signal.

Environment

Problem

PatientService.mergePatients matches none of those method-name patterns, so no merge event is published. A merge currently surfaces only as a collection of incidental events:

  • VoidServiceEvent for the loser patient (voidPatient),
  • per-record SaveServiceEvents for the types that are reassigned through the proxy (encounters, visits, programs, non-encounter obs),
  • a SaveServiceEvent<PersonMergeLog> from the final savePersonMergeLog(...) call.

A consumer wanting to handle "a merge happened" has to key off SaveServiceEvent<PersonMergeLog> and read getWinner() / getLoser(). That works, but it is a dependency on an implementation detail (that the merge log is persisted through the service proxy) rather than a documented contract — a future refactor of how the merge log is saved would silently break every such consumer, with no event and no error.

Suggested fix

Publish a first-class merge event — e.g. a MergeServiceEvent carrying the winner and loser Person/Patient, fired from mergePatients after the transaction's work is complete — or extend OpenmrsServiceEventAdvice to recognise mergePatients. This gives consumers a stable, documented signal instead of relying on the PersonMergeLog save.

Related

Closely related to the data-completeness bug where mergePatients does not reassign Conditions/Allergies/MedicationDispenses (#6194) — fixing that also makes per-record save events fire for those types during a merge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions