Skip to content

Conversation

@mrdnctrk
Copy link
Collaborator

@mrdnctrk mrdnctrk commented Jan 16, 2026

Summary

This pull request extends the $hapi.fhir.undo-merge operation to support any FHIR resource type, not just Patient resources. Previously, this operation was only available at Patient/$hapi.fhir.undo-merge. Now it can be invoked on any resource type via {resourceType}/$hapi.fhir.undo-merge (e.g., Practitioner/$hapi.fhir.undo-merge, Organization/$hapi.fhir.undo-merge).

Parameter Names

The generic operation uses resource-agnostic parameter names, following the same pattern as the $hapi.fhir.merge operation:

Generic Name Patient-Specific Name
source-resource source-patient
target-resource target-patient
source-resource-identifier source-patient-identifier
target-resource-identifier target-patient-identifier

Example: Generic (Practitioner)

POST /Practitioner/$hapi.fhir.undo-merge
{
  "resourceType": "Parameters",
  "parameter": [
    { "name": "source-resource", "valueReference": { "reference": "Practitioner/100" } },
    { "name": "target-resource", "valueReference": { "reference": "Practitioner/200" } }
  ]
}

Example: Patient (backward compatible)

POST /Patient/$hapi.fhir.undo-merge
{
  "resourceType": "Parameters",
  "parameter": [
    { "name": "source-patient", "valueReference": { "reference": "Patient/2" } },
    { "name": "target-patient", "valueReference": { "reference": "Patient/3" } }
  ]
}

Backward Compatibility

For Patient resources, both parameter name styles are supported:

  • Generic names: source-resource, target-resource, etc.
  • Patient-specific names: source-patient, target-patient, etc.

Mixing parameter name styles will not work; use either all generic names or all patient-specific names.

Changes

  • Extended $hapi.fhir.undo-merge to support all resource types through BaseJpaResourceProvider
  • Moved undo-merge logic from PatientMergeProvider to MergeOperationProviderSvc via IMergeOperationProviderSvc.undoMerge()
  • Added MergeOperationParametersUtil.undoInputParametersFromParameters() and undoInputParametersFromOperationParameters() for parameter extraction
  • Updated ResourceUndoMergeService.undoMerge() to accept parameter names, enabling support for both generic and patient-specific names
  • Updated provenance lookup to try multiple parameter name sets for Patient resources

issue: #7477

@robogary
Copy link
Contributor

Formatting check succeeded!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request makes the $hapi.fhir.undo-merge operation generic, enabling it to work with any FHIR resource type (not just Patient resources). The implementation maintains backward compatibility for Patient resources, which can use either patient-specific or generic parameter names.

Changes:

  • Extended $hapi.fhir.undo-merge to support all resource types through BaseJpaResourceProvider
  • Added backward compatibility logic to handle both patient-specific and generic parameter names for Patient resources
  • Updated provenance lookup to try multiple parameter name sets for Patient resources

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
MergeProvenanceSvc.java Modified findProvenanceByTargetIdAndSourceIdentifiers to support multiple parameter name sets for backward compatibility
AbstractMergeOperationInputParameterNames.java Added getParameterNamesForResourceType() to return applicable parameter names for a given resource type
BaseJpaResourceProvider.java Added generic resourceUndoMerge() operation for all resource types
IMergeOperationProviderSvc.java Added undoMerge() interface method
MergeOperationTestHelper.java Added callUndoMergeOperation() helper method for testing
AbstractMergeTestScenario.java Added undo-merge parameter building and operation calling methods; fixed DAO lookup to be generic
PractitionerUndoMergeR4Test.java New test class for Practitioner undo-merge operations
PatientUndoMergeR4Test.java Refactored to extend abstract base class; added cross-endpoint compatibility tests
AbstractGenericUndoMergeR4Test.java New abstract base test class providing common undo-merge test methods
ResourceUndoMergeService.java Updated to accept parameter names dynamically instead of hardcoding Patient names
PatientMergeProvider.java Removed patient-specific undo-merge method (moved to generic provider)
MergeOperationProviderSvc.java Added generic undoMerge() implementation with backward compatibility logic
MergeOperationParametersUtil.java Added utility methods for extracting undo-merge parameters from Parameters resources
JpaR4Config.java Updated bean configuration to wire undo-merge service into merge operation provider

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mrdnctrk mrdnctrk force-pushed the emre-generic-undo-merge-rebased-2 branch from 5d7dcc6 to d0eaecd Compare January 16, 2026 17:10
@mrdnctrk mrdnctrk marked this pull request as ready for review January 16, 2026 17:23
* @param theResourceLimit Resource limit for the operation
* @return UndoMergeOperationInputParameters ready for use with ResourceUndoMergeService
*/
public static UndoMergeOperationInputParameters undoInputParametersFromParameters(
Copy link
Collaborator

Choose a reason for hiding this comment

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

All new methods below don't have unit test coverage. It would be nice to have at least partial unit test coverage for them.

Comment on lines +540 to +549
/**
* Builds undo-merge operation parameters using this scenario's configuration.
* Uses resource IDs by default for both source and target.
*
* @return the operation input parameters
*/
@Nonnull
public Parameters buildUndoMergeParameters() {
return buildUndoMergeParameters(true, true);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

trivial: unused method, can be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants