mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-16 09:55:09 +00:00
WIP
This commit is contained in:
parent
d467c1c79b
commit
891a6304d0
@ -139,7 +139,7 @@ public class FhirResourceDaoCodeSystemR4 extends BaseHapiFhirResourceDao<CodeSys
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing,
|
||||
public ResourceTable 4updateEntity(RequestDetails theRequest, IBaseResource theResource, IBasePersistedResource theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing,
|
||||
boolean theUpdateVersion, TransactionDetails theTransactionDetails, boolean theForceUpdate, boolean theCreateNewHistoryEntry) {
|
||||
ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theTransactionDetails, theForceUpdate, theCreateNewHistoryEntry);
|
||||
|
||||
|
@ -111,7 +111,6 @@ public class MdmMessageHandler implements MessageHandler {
|
||||
IBaseResource targetResource = theMsg.getPayload(myFhirContext);
|
||||
ResourceOperationMessage outgoingMsg = new ResourceOperationMessage(myFhirContext, targetResource, theMsg.getOperationType());
|
||||
outgoingMsg.setTransactionId(theMsg.getTransactionId());
|
||||
mdmContext.getMdmLinkChangeEvent().setTargetResourceId(targetResource);
|
||||
|
||||
HookParams params = new HookParams()
|
||||
.add(ResourceOperationMessage.class, outgoingMsg)
|
||||
|
@ -78,6 +78,8 @@ public class MdmMatchLinkSvc {
|
||||
private MdmTransactionContext doMdmUpdate(IAnyResource theResource, MdmTransactionContext theMdmTransactionContext) {
|
||||
CandidateList candidateList = myMdmGoldenResourceFindingSvc.findGoldenResourceCandidates(theResource);
|
||||
|
||||
theMdmTransactionContext.getMdmLinkChangeEvent().setTargetResourceId(theResource);
|
||||
|
||||
if (candidateList.isEmpty()) {
|
||||
handleMdmWithNoCandidates(theResource, theMdmTransactionContext);
|
||||
} else if (candidateList.exactlyOneMatch()) {
|
||||
@ -143,6 +145,8 @@ public class MdmMatchLinkSvc {
|
||||
if (myGoldenResourceHelper.isPotentialDuplicate(goldenResource, theTargetResource)) {
|
||||
log(theMdmTransactionContext, "Duplicate detected based on the fact that both resources have different external EIDs.");
|
||||
IAnyResource newGoldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(theTargetResource, theMdmTransactionContext);
|
||||
theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(newGoldenResource);
|
||||
|
||||
myMdmLinkSvc.updateLink(newGoldenResource, theTargetResource, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
|
||||
myMdmLinkSvc.updateLink(newGoldenResource, goldenResource, MdmMatchOutcome.POSSIBLE_DUPLICATE, MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
|
||||
} else {
|
||||
@ -150,6 +154,8 @@ public class MdmMatchLinkSvc {
|
||||
myGoldenResourceHelper.handleExternalEidAddition(goldenResource, theTargetResource, theMdmTransactionContext);
|
||||
myEidUpdateService.applySurvivorshipRulesAndSaveGoldenResource(theTargetResource, goldenResource, theMdmTransactionContext);
|
||||
}
|
||||
|
||||
theMdmTransactionContext.getMdmLinkChangeEvent().setGoldenResourceId(goldenResource);
|
||||
myMdmLinkSvc.updateLink(goldenResource, theTargetResource, theGoldenResourceCandidate.getMatchResult(), MdmLinkSourceEnum.AUTO, theMdmTransactionContext);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4;
|
||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
import ca.uhn.fhir.mdm.api.MdmLinkChangeEvent;
|
||||
import ca.uhn.fhir.mdm.model.CanonicalEID;
|
||||
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
|
||||
import ca.uhn.fhir.mdm.rules.config.MdmSettings;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
@ -53,7 +54,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
@ -84,9 +87,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test {
|
||||
assertNotNull(resourceOperationMessage);
|
||||
assertEquals(pr.getId(), resourceOperationMessage.getId());
|
||||
|
||||
MdmLink example = new MdmLink();
|
||||
example.setSourcePid(pr.getIdElement().getIdPartAsLong());
|
||||
MdmLink link = myMdmLinkDao.findAll(Example.of(example)).get(0);
|
||||
MdmLink link = getLinkByTargetId(pr);
|
||||
|
||||
MdmLinkChangeEvent linkChangeEvent = myMdmHelper.getAfterMdmLatch().getLatchInvocationParameterOfType(MdmLinkChangeEvent.class);
|
||||
assertNotNull(linkChangeEvent);
|
||||
@ -94,39 +95,30 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test {
|
||||
assertEquals(link.getSourcePid(), new IdDt(linkChangeEvent.getTargetResourceId()).getIdPartAsLong());
|
||||
}
|
||||
|
||||
private MdmLink getLinkByTargetId(IBaseResource theResource) {
|
||||
MdmLink example = new MdmLink();
|
||||
example.setSourcePid(theResource.getIdElement().getIdPartAsLong());
|
||||
return myMdmLinkDao.findAll(Example.of(example)).get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLinkChangeEvent() throws InterruptedException {
|
||||
Patient patient1 = addExternalEID(buildJanePatient(), "eid-1");
|
||||
patient1 = createPatientAndUpdateLinks(patient1);
|
||||
myMdmHelper.createWithLatch(patient1);
|
||||
|
||||
MdmTransactionContext ctx = createContextForCreate("Patient");
|
||||
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient1, ctx);
|
||||
ourLog.info(ctx.getMdmLinkChangeEvent().toString());
|
||||
assertEquals(patient1.getIdElement().getValue(), ctx.getMdmLinkChangeEvent().getTargetResourceId());
|
||||
assertEquals(getLinkByTargetId(patient1).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkChangeEvent().getGoldenResourceId()).getIdPartAsLong());
|
||||
|
||||
Patient patient2 = addExternalEID(buildJanePatient(), "eid-2");
|
||||
patient2 = createPatientAndUpdateLinks(patient2);
|
||||
|
||||
MdmLinkChangeEvent linkChangeEvent = myMdmHelper.getAfterMdmLatch().getLatchInvocationParameterOfType(MdmLinkChangeEvent.class);
|
||||
assertNotNull(linkChangeEvent);
|
||||
// assertEquals(link.getGoldenResourcePid(), new IdDt(linkChangeEvent.getGoldenResourceId()).getIdPartAsLong());
|
||||
// assertEquals(link.getSourcePid(), new IdDt(linkChangeEvent.getTargetResourceId()).getIdPartAsLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateLinkChangeEvent() throws InterruptedException {
|
||||
fail();
|
||||
|
||||
Practitioner pr = buildPractitionerWithNameAndId("Young", "AC-DC");
|
||||
myMdmHelper.createWithLatch(pr);
|
||||
|
||||
ResourceOperationMessage resourceOperationMessage = myMdmHelper.getAfterMdmLatch().getLatchInvocationParameterOfType(ResourceOperationMessage.class);
|
||||
assertNotNull(resourceOperationMessage);
|
||||
assertEquals(pr.getId(), resourceOperationMessage.getId());
|
||||
|
||||
MdmLink example = new MdmLink();
|
||||
example.setSourcePid(pr.getIdElement().getIdPartAsLong());
|
||||
MdmLink link = myMdmLinkDao.findAll(Example.of(example)).get(0);
|
||||
|
||||
MdmLinkChangeEvent linkChangeEvent = myMdmHelper.getAfterMdmLatch().getLatchInvocationParameterOfType(MdmLinkChangeEvent.class);
|
||||
assertNotNull(linkChangeEvent);
|
||||
assertEquals(link.getGoldenResourcePid(), new IdDt(linkChangeEvent.getGoldenResourceId()).getIdPartAsLong());
|
||||
assertEquals(link.getSourcePid(), new IdDt(linkChangeEvent.getTargetResourceId()).getIdPartAsLong());
|
||||
myMdmHelper.createWithLatch(patient2);
|
||||
ctx = createContextForCreate("Patient");
|
||||
myMdmMatchLinkSvc.updateMdmLinksForMdmSource(patient2, ctx);
|
||||
ourLog.info(ctx.getMdmLinkChangeEvent().toString());
|
||||
assertEquals(patient2.getIdElement().getValue(), ctx.getMdmLinkChangeEvent().getTargetResourceId());
|
||||
assertEquals(getLinkByTargetId(patient2).getGoldenResourcePid(), new IdDt(ctx.getMdmLinkChangeEvent().getGoldenResourceId()).getIdPartAsLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,16 +1,40 @@
|
||||
package ca.uhn.fhir.mdm.api;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
/*-
|
||||
* #%L
|
||||
* HAPI FHIR - Master Data Management
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2021 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%
|
||||
*/
|
||||
|
||||
import ca.uhn.fhir.model.api.IModelJson;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MdmLinkChangeEvent {
|
||||
public class MdmLinkChangeEvent implements IModelJson {
|
||||
|
||||
@JsonProperty(value = "targetResourceId")
|
||||
private String myTargetResourceId;
|
||||
@JsonProperty(value = "goldenResourceId")
|
||||
private String myGoldenResourceId;
|
||||
@JsonProperty(value = "duplicateResourceIds")
|
||||
private Set<String> myDuplicateGoldenResourceIds = new HashSet<>();
|
||||
|
||||
public String getGoldenResourceId() {
|
||||
@ -64,4 +88,12 @@ public class MdmLinkChangeEvent {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MdmLinkChangeEvent{" +
|
||||
"myTargetResourceId='" + myTargetResourceId + '\'' +
|
||||
", myGoldenResourceId='" + myGoldenResourceId + '\'' +
|
||||
", myDuplicateGoldenResourceIds=" + myDuplicateGoldenResourceIds +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -103,4 +103,5 @@ public class MdmTransactionContext {
|
||||
public void setMdmLinkChangeEvent(MdmLinkChangeEvent theMdmLinkChangeEvent) {
|
||||
myMdmLinkChangeEvent = theMdmLinkChangeEvent;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user