Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
648e40e
provider layer refactoring
mrdnctrk Nov 11, 2025
58d368b
spotless
mrdnctrk Nov 11, 2025
8df2ffb
mergeresourceprovidersvc interface and integration
mrdnctrk Nov 12, 2025
1054ccb
merge validation service replace patientdao
mrdnctrk Nov 12, 2025
72dc09f
Add extension-based link service for generic resource merge tracking
mrdnctrk Nov 13, 2025
0b692f5
Add IResourceLinkService interface and PatientNativeLinkService imple…
mrdnctrk Nov 13, 2025
530220e
Add ResourceLinkServiceFactory for routing link service implementations
mrdnctrk Nov 13, 2025
c7666fb
Inject ResourceLinkServiceFactory into merge services and fix test st…
mrdnctrk Nov 13, 2025
20567cc
Refactor MergeValidationService to use IResourceLinkService abstraction
mrdnctrk Nov 13, 2025
2e1e1e6
Refactor merge configuration to follow batch2 job pattern
mrdnctrk Nov 14, 2025
354e951
Refactor MergeResourceHelper to use generic identifier copying with F…
mrdnctrk Nov 14, 2025
ba36da7
Refactor MergeResourceHelper to use generic active field handling wit…
mrdnctrk Nov 17, 2025
05230ea
Refactor MergeResourceHelper to use generic target resource preparation
mrdnctrk Nov 17, 2025
2f6931f
Refactor updateMergedResourcesAfterReferencesReplaced to use dynamic …
mrdnctrk Nov 17, 2025
8221c68
Refactor validateSourceAndTargetAreSuitableForMerge to use FhirTerser…
mrdnctrk Nov 17, 2025
9e1a0d1
Refactor hasAllIdentifiers to use generic IBaseResource with FhirTerser
mrdnctrk Nov 17, 2025
968d401
Refactor MergeValidationResult to use generic IBaseResource
mrdnctrk Nov 17, 2025
5816479
Refactor ResourceMergeService to use generic IBaseResource instead of…
mrdnctrk Nov 17, 2025
af5c1e1
Refactor $hapi-fhir-merge operation to use constants for parameter names
mrdnctrk Nov 18, 2025
d985a38
Refactor MergeOperationInputParameterNames to support operation-speci…
mrdnctrk Nov 18, 2025
7a3312d
Make MergeProvenanceSvc operation-aware by passing parameter names to…
mrdnctrk Nov 18, 2025
a6ea66c
Refactor MergeValidationService to support generic resource types for…
mrdnctrk Nov 18, 2025
7fad495
Use string literals for parameter names in GenericMergeR4Test
mrdnctrk Nov 18, 2025
633f8b2
Refactor MergeUpdateTaskReducerStep to support generic resource types…
mrdnctrk Nov 20, 2025
b95880e
Refactor merge operations to use fieldExists() for safer active field…
mrdnctrk Nov 20, 2025
6f4e759
Add comprehensive test infrastructure for generic resource merge oper…
mrdnctrk Nov 20, 2025
61705b3
Refactor: Move result resource creation from createTestData() to buil…
mrdnctrk Nov 21, 2025
e14fda8
Replace production constants with string literals in generic merge te…
mrdnctrk Nov 21, 2025
46b6219
Refactor merge test infrastructure: move validation to scenarios and …
mrdnctrk Nov 21, 2025
2c3d36a
Simplify validation method signatures by removing redundant scenario …
mrdnctrk Nov 21, 2025
b74a8af
Remove MergeTestScenario interface and simplify test hierarchy
mrdnctrk Nov 21, 2025
0b8e223
Refactor: Remove unused referencePath parameter from ReferencingResou…
mrdnctrk Nov 24, 2025
58c682a
Refactor: Simplify reference setup with hardcoded convenience methods
mrdnctrk Nov 24, 2025
bef7a98
Remove varargs overload of withReferences() method to simplify API
mrdnctrk Nov 24, 2025
b8c1678
Rename ReferencingResourceConfig to ReferencingTestResourceType
mrdnctrk Nov 24, 2025
2f41584
Refactor: Remove string-based createResourceWithIdentifiers and ident…
mrdnctrk Nov 24, 2025
9c9915d
Refactor: Make deleteSource and preview builder fields instead of par…
mrdnctrk Nov 24, 2025
8b7e7b5
Refactor: Remove unnecessary defensive copies in merge test scenarios
mrdnctrk Nov 24, 2025
83fd8f2
Refactor: Add scenario-based callMergeOperation overload
mrdnctrk Nov 24, 2025
70e31bc
Refactor: Rename createReferencingResource parameter for clarity
mrdnctrk Nov 24, 2025
2b361e7
Refactor: Simplify calculateExpectedIdentifiersAfterMerge to use fiel…
mrdnctrk Nov 24, 2025
5a2b136
Add deep identifier validation with assertIdentifiers method
mrdnctrk Nov 24, 2025
3f85139
Refactor: Make expected identifier calculation lazy
mrdnctrk Nov 24, 2025
1f691c1
Add test scenarios for empty identifier edge cases
mrdnctrk Nov 24, 2025
a1fc39c
Add support for custom result resource identifiers in merge tests
mrdnctrk Nov 24, 2025
e87ccd4
Refactor assertReferencesUpdated to validate target references properly
mrdnctrk Nov 24, 2025
ca919ce
Extract duplicate result resource creation logic into helper method
mrdnctrk Nov 24, 2025
5f1f132
Make withResultResource accept boolean parameter for explicit control
mrdnctrk Nov 25, 2025
53f9ed0
Refactor: Rename getSourceId/getTargetId to getVersionlessSourceId/ge…
mrdnctrk Nov 25, 2025
7834d40
Implement assertMergeProvenanceCreated by delegating to ReplaceRefere…
mrdnctrk Nov 25, 2025
2294a4e
Refactor reference validation methods to reduce boilerplate
mrdnctrk Nov 25, 2025
bcdefe5
Consolidate provenance tests and simplify validation API
mrdnctrk Nov 25, 2025
c60d072
Improve async task validation in generic merge tests
mrdnctrk Nov 25, 2025
cec748f
Enhance validateSyncMergeOutcome to match PatientMergeR4Test validation
mrdnctrk Nov 26, 2025
6c0f958
Add input parameter validation to generic merge tests
mrdnctrk Nov 26, 2025
739ad94
Refactor merge validation to use zero-parameter methods
mrdnctrk Nov 26, 2025
d92dde1
Remove unused imports from generic merge test files
mrdnctrk Nov 26, 2025
05d28d8
Enhance link service test coverage with edge cases
mrdnctrk Nov 26, 2025
aa354ee
Use stored myInputParameters field directly in assertMergeProvenanceC…
mrdnctrk Nov 26, 2025
91586d8
Consolidate provenance validation into validateResourcesAfterMerge()
mrdnctrk Nov 26, 2025
fddcc36
Refactor active field validation and remove unnecessary target assertion
mrdnctrk Nov 26, 2025
5745296
Simplify error handling tests and rename createResourceWithIdentifiers
mrdnctrk Nov 26, 2025
4e4e11f
Add active field validations to ResourceMergeServiceTest
mrdnctrk Nov 26, 2025
97ccc47
Enhance error message validation in generic merge tests
mrdnctrk Nov 26, 2025
b7a0e1b
Remove test counts from generic merge test documentation
mrdnctrk Nov 27, 2025
df7f6cf
Consolidate provenance agent validation into AbstractMergeTestScenario
mrdnctrk Nov 27, 2025
1eca214
Add GAP #2: Provenance Agent Interceptor empty error test
mrdnctrk Nov 27, 2025
7f3b283
Add withMultipleReferencingResources(int) overload for cleaner API
mrdnctrk Nov 27, 2025
3813cf1
Refactor validateTaskOutput to handle zero-reference case gracefully
mrdnctrk Nov 27, 2025
343e5d7
Add GAP #6: Multiple target matches error test
mrdnctrk Nov 28, 2025
f2bb2d0
Add GAP #7: Multiple source matches error test
mrdnctrk Nov 28, 2025
9ffdfb9
Add GAP #5: Concurrent modification during async job test
mrdnctrk Nov 28, 2025
4a6936c
Fix referencing resources created with versioned IDs
mrdnctrk Nov 28, 2025
f57a1de
Add test for empty merge parameters validation
mrdnctrk Nov 28, 2025
8c96212
Add error message validation to merge parameter tests
mrdnctrk Nov 28, 2025
95f330d
Refactor: Create helper method for merge exception validation
mrdnctrk Nov 28, 2025
e6bd527
Refactor additional merge error tests to use callMergeAndValidateExce…
mrdnctrk Nov 28, 2025
e21bceb
Add base helper for merge exception validation and refactor 5 tests
mrdnctrk Nov 28, 2025
97c1d6c
Refactor merge test validation orchestration into scenario class
mrdnctrk Dec 1, 2025
c270546
Refactor: Reorganize test methods in AbstractGenericMergeR4Test
mrdnctrk Dec 1, 2025
0be110b
Refactor: Standardize error handling test method names
mrdnctrk Dec 1, 2025
9dc4efa
Refactor: Standardize success test method names to end with _succeeds
mrdnctrk Dec 1, 2025
c368f04
Refactor: Use helper method for provenance interceptor error test
mrdnctrk Dec 1, 2025
616cb8e
Refactor: Merge identifier resolution tests and remove redundancy
mrdnctrk Dec 1, 2025
89c558a
Fix: Revert provenance interceptor test to use inline validation
mrdnctrk Dec 1, 2025
c539407
Add test for target no-op update edge case in merge operation
mrdnctrk Dec 1, 2025
9996867
Refactor: Remove redundant observation-specific tests already covered…
mrdnctrk Dec 1, 2025
7e6eeee
Add Patient merge test using generic merge framework
mrdnctrk Dec 1, 2025
056b986
delete md file
mrdnctrk Dec 1, 2025
2a6c693
uncommit files
mrdnctrk Dec 1, 2025
ec8d66c
more
mrdnctrk Dec 1, 2025
ce5f512
renaming
mrdnctrk Dec 2, 2025
e23199a
Refactor: Store only IDs in AbstractMergeTestScenario for memory effi…
mrdnctrk Dec 6, 2025
e0c6351
spotless
mrdnctrk Dec 6, 2025
df0d28a
Add validation for identifier element in merge operations
mrdnctrk Dec 10, 2025
48cfe2c
Refactor merge test helpers to eliminate code duplication
mrdnctrk Dec 11, 2025
be70717
Add resource type validation for merge operations
mrdnctrk Dec 11, 2025
b14b95d
spotless
mrdnctrk Dec 11, 2025
e352366
Use resource-type-specific provenance reason codes for merge operations
mrdnctrk Dec 11, 2025
6f53154
revert config to original in test
mrdnctrk Dec 15, 2025
e6e16ce
Add tests for merge operation error condition in R5 and DSTU3
mrdnctrk Dec 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
package ca.uhn.fhir.jpa.config.r4;

import ca.uhn.fhir.batch2.api.IJobCoordinator;
import ca.uhn.fhir.batch2.jobs.merge.ExtensionBasedLinkService;
import ca.uhn.fhir.batch2.jobs.merge.MergeResourceHelper;
import ca.uhn.fhir.batch2.jobs.merge.PatientNativeLinkService;
import ca.uhn.fhir.batch2.jobs.merge.ResourceLinkServiceFactory;
import ca.uhn.fhir.batch2.util.Batch2TaskHelper;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
Expand All @@ -28,6 +32,7 @@
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.api.svc.IMergeOperationProviderSvc;
import ca.uhn.fhir.jpa.config.GeneratedDaoAndResourceProviderConfigR4;
import ca.uhn.fhir.jpa.config.JpaConfig;
import ca.uhn.fhir.jpa.dao.ITransactionProcessorVersionAdapter;
Expand All @@ -38,6 +43,7 @@
import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
import ca.uhn.fhir.jpa.provider.IReplaceReferencesSvc;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.jpa.provider.merge.MergeOperationProviderSvc;
import ca.uhn.fhir.jpa.provider.merge.MergeValidationService;
import ca.uhn.fhir.jpa.provider.merge.PatientMergeProvider;
import ca.uhn.fhir.jpa.provider.merge.ResourceMergeService;
Expand Down Expand Up @@ -112,15 +118,42 @@ public ITermLoaderSvc termLoaderService(
}

@Bean
public MergeValidationService mergeValidationService(FhirContext theFhirContext, DaoRegistry theDaoRegistry) {
return new MergeValidationService(theFhirContext, theDaoRegistry);
public MergeValidationService mergeValidationService(
FhirContext theFhirContext,
DaoRegistry theDaoRegistry,
ResourceLinkServiceFactory theResourceLinkServiceFactory) {
return new MergeValidationService(theFhirContext, theDaoRegistry, theResourceLinkServiceFactory);
}

@Bean
public MergeProvenanceSvc mergeProvenanceSvc(DaoRegistry theDaoRegistry) {
return new MergeProvenanceSvc(theDaoRegistry);
}

@Bean
public PatientNativeLinkService patientNativeLinkService() {
return new PatientNativeLinkService();
}

@Bean
public ExtensionBasedLinkService extensionBasedLinkService() {
return new ExtensionBasedLinkService();
}

@Bean
public ResourceLinkServiceFactory resourceLinkServiceFactory(
PatientNativeLinkService thePatientService, ExtensionBasedLinkService theExtensionService) {
return new ResourceLinkServiceFactory(thePatientService, theExtensionService);
}

@Bean
public MergeResourceHelper mergeResourceHelper(
DaoRegistry theDaoRegistry,
MergeProvenanceSvc theMergeProvenanceSvc,
ResourceLinkServiceFactory theResourceLinkServiceFactory) {
return new MergeResourceHelper(theDaoRegistry, theMergeProvenanceSvc, theResourceLinkServiceFactory);
}

@Bean
public ResourceMergeService resourceMergeService(
DaoRegistry theDaoRegistry,
Expand All @@ -131,7 +164,8 @@ public ResourceMergeService resourceMergeService(
Batch2TaskHelper theBatch2TaskHelper,
JpaStorageSettings theStorageSettings,
MergeValidationService theMergeValidationService,
MergeProvenanceSvc theMergeProvenanceSvc) {
MergeProvenanceSvc theMergeProvenanceSvc,
MergeResourceHelper theMergeResourceHelper) {

return new ResourceMergeService(
theStorageSettings,
Expand All @@ -142,7 +176,8 @@ public ResourceMergeService resourceMergeService(
theJobCoordinator,
theBatch2TaskHelper,
theMergeValidationService,
theMergeProvenanceSvc);
theMergeProvenanceSvc,
theMergeResourceHelper);
}

@Bean
Expand All @@ -160,19 +195,25 @@ public ResourceUndoMergeService resourceUndoMergeService(
theRequestPartitionHelperSvc);
}

@Bean
public IMergeOperationProviderSvc mergeOperationProviderSvc(
FhirContext theFhirContext,
ResourceMergeService theResourceMergeService,
IInterceptorBroadcaster theInterceptorBroadcaster,
JpaStorageSettings theStorageSettings) {

return new MergeOperationProviderSvc(
theFhirContext, theResourceMergeService, theInterceptorBroadcaster, theStorageSettings);
}

@Bean
public PatientMergeProvider patientMergeProvider(
FhirContext theFhirContext,
DaoRegistry theDaoRegistry,
ResourceMergeService theResourceMergeService,
ResourceUndoMergeService theResourceUndoMergeService,
IInterceptorBroadcaster theInterceptorBroadcaster) {
IMergeOperationProviderSvc theMergeOperationProviderSvc,
ResourceUndoMergeService theResourceUndoMergeService) {

return new PatientMergeProvider(
theFhirContext,
theDaoRegistry,
theResourceMergeService,
theResourceUndoMergeService,
theInterceptorBroadcaster);
theFhirContext, theDaoRegistry, theMergeOperationProviderSvc, theResourceUndoMergeService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.model.api.IProvenanceAgent;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import java.util.List;

Expand Down Expand Up @@ -98,9 +100,10 @@ public void setOriginalInputParameters(IBaseResource theOriginalInputParameters)
public MergeJobParameters asMergeJobParameters(
FhirContext theFhirContext,
JpaStorageSettings theStorageSettings,
Patient theSourceResource,
Patient theTargetResource,
RequestPartitionId thePartitionId) {
IBaseResource theSourceResource,
IBaseResource theTargetResource,
RequestPartitionId thePartitionId,
String theOperationName) {
MergeJobParameters retval = new MergeJobParameters();
retval.setOriginalInputParameters(
theFhirContext.newJsonParser().encodeResourceToString(myOriginalInputParameters));
Expand All @@ -110,6 +113,57 @@ public MergeJobParameters asMergeJobParameters(
retval.setPartitionId(thePartitionId);
retval.setProvenanceAgents(ProvenanceAgentJson.from(myProvenanceAgents, theFhirContext));
retval.setCreateProvenance(myCreateProvenance);
retval.setOperationName(theOperationName);
return retval;
}

/**
* Static factory method to create MergeOperationInputParameters from operation parameters.
* Version-agnostic - uses IBase for identifiers to support all FHIR versions.
*
* @param theSourceIdentifiers List of source resource identifiers (IBase to support all FHIR versions)
* @param theTargetIdentifiers List of target resource identifiers (IBase to support all FHIR versions)
* @param theSourceResource Reference to the source resource
* @param theTargetResource Reference to the target resource
* @param thePreview Preview mode flag
* @param theDeleteSource Delete source flag
* @param theResultResource Result resource template
* @param theResourceLimit Resource processing limit
* @param theProvenanceAgents Provenance agents for tracking
* @param theOriginalInputParameters Original input parameters for audit trail
* @return Populated MergeOperationInputParameters object
*/
public static MergeOperationInputParameters from(
List<IBase> theSourceIdentifiers,
List<IBase> theTargetIdentifiers,
IBaseReference theSourceResource,
IBaseReference theTargetResource,
IPrimitiveType<Boolean> thePreview,
IPrimitiveType<Boolean> theDeleteSource,
IBaseResource theResultResource,
int theResourceLimit,
List<IProvenanceAgent> theProvenanceAgents,
IBaseResource theOriginalInputParameters) {

MergeOperationInputParameters parameters = new MergeOperationInputParameters(theResourceLimit);

// Set common parameters (identifiers and resource references)
MergeOperationsCommonInputParameters.setParameters(
parameters, theSourceIdentifiers, theTargetIdentifiers, theSourceResource, theTargetResource);

// Set merge-specific parameters
parameters.setPreview(thePreview != null && thePreview.getValue());
parameters.setDeleteSource(theDeleteSource != null && theDeleteSource.getValue());

if (theResultResource != null) {
// Pass in a copy of the result resource as we don't want it to be modified.
// It will be returned back to the client as part of the response.
parameters.setResultResource(theResultResource);
}

parameters.setProvenanceAgents(theProvenanceAgents);
parameters.setOriginalInputParameters(theOriginalInputParameters);

return parameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Created by claude-sonnet-4-5
/*-
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2025 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package ca.uhn.fhir.jpa.provider.merge;

import ca.uhn.fhir.batch2.jobs.merge.MergeResourceHelper;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.api.svc.IMergeOperationProviderSvc;
import ca.uhn.fhir.jpa.interceptor.ProvenanceAgentsPointcutUtil;
import ca.uhn.fhir.model.api.IProvenanceAgent;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.util.ParametersUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import java.util.List;

import static ca.uhn.fhir.jpa.provider.BaseJpaProvider.endRequest;
import static ca.uhn.fhir.jpa.provider.BaseJpaProvider.startRequest;
import static ca.uhn.fhir.rest.server.provider.ProviderConstants.OPERATION_MERGE_OUTPUT_PARAM_RESULT;

/**
* Service that handles the common logic for merge operations across different resource types.
* This service extracts the shared merge operation logic that was previously duplicated
* in resource-specific providers.
*/
public class MergeOperationProviderSvc implements IMergeOperationProviderSvc {

private final FhirContext myFhirContext;
private final ResourceMergeService myResourceMergeService;
private final IInterceptorBroadcaster myInterceptorBroadcaster;
private final JpaStorageSettings myStorageSettings;

public MergeOperationProviderSvc(
FhirContext theFhirContext,
ResourceMergeService theResourceMergeService,
IInterceptorBroadcaster theInterceptorBroadcaster,
JpaStorageSettings theStorageSettings) {
myFhirContext = theFhirContext;
myResourceMergeService = theResourceMergeService;
myInterceptorBroadcaster = theInterceptorBroadcaster;
myStorageSettings = theStorageSettings;
}

/**
* Executes a merge operation for any resource type.
*
* @param theSourceIdentifiers Source resource identifiers
* @param theTargetIdentifiers Target resource identifiers
* @param theSourceReference Source resource reference
* @param theTargetReference Target resource reference
* @param thePreview Preview mode flag
* @param theDeleteSource Delete source flag
* @param theResultResource Optional result resource provided by client
* @param theResourceLimit Optional batch size limit
* @param theRequestDetails Servlet request details containing HTTP request/response and context
* @return Parameters resource containing merge operation results
*/
@Override
public IBaseParameters merge(
List<IBase> theSourceIdentifiers,
List<IBase> theTargetIdentifiers,
IBaseReference theSourceReference,
IBaseReference theTargetReference,
IPrimitiveType<Boolean> thePreview,
IPrimitiveType<Boolean> theDeleteSource,
IBaseResource theResultResource,
IPrimitiveType<Integer> theResourceLimit,
ServletRequestDetails theRequestDetails) {

HttpServletRequest servletRequest = theRequestDetails.getServletRequest();
HttpServletResponse servletResponse = theRequestDetails.getServletResponse();

startRequest(servletRequest);
try {
int resourceLimit = MergeResourceHelper.setResourceLimitFromParameter(myStorageSettings, theResourceLimit);

List<IProvenanceAgent> provenanceAgents =
ProvenanceAgentsPointcutUtil.ifHasCallHooks(theRequestDetails, myInterceptorBroadcaster);

FhirTerser terser = myFhirContext.newTerser();
IBaseResource resultResourceCopy = theResultResource != null ? terser.clone(theResultResource) : null;
IBaseResource originalParametersCopy = terser.clone(theRequestDetails.getResource());

MergeOperationInputParameters mergeOperationParameters = MergeOperationInputParameters.from(
theSourceIdentifiers,
theTargetIdentifiers,
theSourceReference,
theTargetReference,
thePreview,
theDeleteSource,
resultResourceCopy,
resourceLimit,
provenanceAgents,
originalParametersCopy);

MergeOperationOutcome mergeOutcome =
myResourceMergeService.merge(mergeOperationParameters, theRequestDetails);
servletResponse.setStatus(mergeOutcome.getHttpStatusCode());
return buildMergeOperationOutputParameters(mergeOutcome, theRequestDetails.getResource());
} finally {
endRequest(servletRequest);
}
}

private IBaseParameters buildMergeOperationOutputParameters(
MergeOperationOutcome theMergeOutcome, IBaseResource theInputParameters) {

IBaseParameters retVal = ParametersUtil.newInstance(myFhirContext);
ParametersUtil.addParameterToParameters(
myFhirContext,
retVal,
ca.uhn.fhir.rest.server.provider.ProviderConstants.OPERATION_MERGE_OUTPUT_PARAM_INPUT,
theInputParameters);

ParametersUtil.addParameterToParameters(
myFhirContext,
retVal,
ca.uhn.fhir.rest.server.provider.ProviderConstants.OPERATION_MERGE_OUTPUT_PARAM_OUTCOME,
theMergeOutcome.getOperationOutcome());

if (theMergeOutcome.getUpdatedTargetResource() != null) {
ParametersUtil.addParameterToParameters(
myFhirContext,
retVal,
OPERATION_MERGE_OUTPUT_PARAM_RESULT,
theMergeOutcome.getUpdatedTargetResource());
}

if (theMergeOutcome.getTask() != null) {
ParametersUtil.addParameterToParameters(
myFhirContext,
retVal,
ca.uhn.fhir.rest.server.provider.ProviderConstants.OPERATION_MERGE_OUTPUT_PARAM_TASK,
theMergeOutcome.getTask());
}
return retVal;
}
}
Loading
Loading