From a2e1bb57fa637814dd9304200bea730f5a94964e Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 12 Jan 2021 14:15:04 -0500 Subject: [PATCH] Survivorship 7 --- .../uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java | 2 ++ .../provider/MdmProviderMergeGoldenResourcesR4Test.java | 8 ++++---- .../java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java | 4 ++-- .../java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java | 8 ++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java index 108ea4ee8e5..1c008f1caf1 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/GoldenResourceMergerSvcImpl.java @@ -73,6 +73,8 @@ public class GoldenResourceMergerSvcImpl implements IGoldenResourceMergerSvc { //Merge the links from the FROM to the TO resource. Clean up dangling links. mergeGoldenResourceLinks(theFromGoldenResource, theToGoldenResource, toGoldenResourcePid, theMdmTransactionContext); + //Save changes to the golden resource + myMdmResourceDaoSvc.upsertGoldenResource(theToGoldenResource, resourceType); //Create the new REDIRECT link addMergeLink(toGoldenResourcePid, fromGoldenResourcePid, resourceType); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergeGoldenResourcesR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergeGoldenResourcesR4Test.java index ad7c3c20e8c..325d7a013a1 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergeGoldenResourcesR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMergeGoldenResourcesR4Test.java @@ -51,13 +51,12 @@ public class MdmProviderMergeGoldenResourcesR4Test extends BaseProviderR4Test { assertEquals(myFromGoldenPatient.getName().size(), mergedSourcePatient.getName().size()); assertEquals(myFromGoldenPatient.getName().get(0).getNameAsSingleString(), mergedSourcePatient.getName().get(0).getNameAsSingleString()); - assertEquals(myFromGoldenPatient.getCommunication().size(), mergedSourcePatient.getCommunication().size()); assertEquals(myFromGoldenPatient.getExtension().size(), mergedSourcePatient.getExtension().size()); - Patient fromSourcePatient = myPatientDao.read(myFromGoldenPatient.getIdElement().toUnqualifiedVersionless()); - assertEquals(fromSourcePatient.getName().size(), mergedSourcePatient.getName().size()); - assertEquals(fromSourcePatient.getName().get(0).getNameAsSingleString(), mergedSourcePatient.getName().get(0).getNameAsSingleString()); + Patient toGoldenPatient = myPatientDao.read(myToGoldenPatient.getIdElement().toUnqualifiedVersionless()); + assertEquals(toGoldenPatient.getName().size(), mergedSourcePatient.getName().size()); + assertEquals(toGoldenPatient.getName().get(0).getNameAsSingleString(), mergedSourcePatient.getName().get(0).getNameAsSingleString()); } @@ -99,6 +98,7 @@ public class MdmProviderMergeGoldenResourcesR4Test extends BaseProviderR4Test { Patient mergedSourcePatient = (Patient) myMdmProvider.mergeGoldenResources(myFromGoldenPatientId, myToGoldenPatientId, myFromGoldenPatient, myRequestDetails); + myFromGoldenPatient = (Patient) myPatientDao.read(myFromGoldenPatient.getIdElement().toUnqualifiedVersionless()); assertTrue(!MdmResourceUtil.isGoldenRecord(myFromGoldenPatient)); assertTrue(MdmResourceUtil.isGoldenRecordRedirected(myFromGoldenPatient)); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java index 949c40530dc..06eb9ebe9d4 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmMatchLinkSvcTest.java @@ -346,7 +346,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test { //In a normal situation, janePatient2 would just match to jane patient, but here we need to hack it so they are their //own individual GoldenResource for the purpose of this test. - IAnyResource goldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(janePatient2, new MdmTransactionContext()); + IAnyResource goldenResource = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(janePatient2, new MdmTransactionContext(MdmTransactionContext.OperationType.CREATE_RESOURCE)); myMdmLinkSvc.updateLink(goldenResource, janePatient2, MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH, MdmLinkSourceEnum.AUTO, createContextForCreate("Patient")); assertThat(janePatient, is(not(sameGoldenResourceAs(janePatient2)))); @@ -437,7 +437,7 @@ public class MdmMatchLinkSvcTest extends BaseMdmR4Test { public void testCreateGoldenResourceFromMdmTarget() { // Create Use Case #2 - adding patient with no EID Patient janePatient = buildJanePatient(); - Patient janeGoldenResourcePatient = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(janePatient, new MdmTransactionContext()); + Patient janeGoldenResourcePatient = myGoldenResourceHelper.createGoldenResourceFromMdmSourceResource(janePatient, new MdmTransactionContext(MdmTransactionContext.OperationType.CREATE_RESOURCE)); // golden record now contains HAPI-generated EID and HAPI tag assertTrue(MdmResourceUtil.isMdmManaged(janeGoldenResourcePatient)); diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java index ae8c179263d..a2fb07fe200 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/model/MdmTransactionContext.java @@ -52,11 +52,15 @@ public class MdmTransactionContext { public MdmTransactionContext() { } - public MdmTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation) { - myTransactionLogMessages = theTransactionLogMessages; + public MdmTransactionContext(OperationType theRestOperation) { myRestOperation = theRestOperation; } + public MdmTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation) { + this(theRestOperation); + myTransactionLogMessages = theTransactionLogMessages; + } + public MdmTransactionContext(TransactionLogMessages theTransactionLogMessages, OperationType theRestOperation, String theResourceType) { this(theTransactionLogMessages, theRestOperation); setResourceType(theResourceType);