Survivorship 3

This commit is contained in:
Nick 2021-01-06 18:02:04 -05:00
parent 49e3dedf77
commit 19341a17b7
8 changed files with 137 additions and 39 deletions

View File

@ -92,6 +92,10 @@ public class MdmLinkUpdaterSvcImpl implements IMdmLinkUpdaterSvc {
mdmLink.setMatchResult(theMatchResult);
mdmLink.setLinkSource(MdmLinkSourceEnum.MANUAL);
myMdmLinkDaoSvc.save(mdmLink);
// TODO NG MDM Since it's a manual link update, we need to allow the caller to optionally override this behavior with what they thing should go into the golden resource
myMdmSurvivorshipService.applySurvivorshipRulesToGoldenResource(theSourceResource, theGoldenResource, theMdmContext);
myMdmResourceDaoSvc.upsertGoldenResource(theGoldenResource, theMdmContext.getResourceType());
if (theMatchResult == MdmMatchResultEnum.NO_MATCH) {
// Need to find a new Golden Resource to link this target to

View File

@ -1,13 +1,38 @@
package ca.uhn.fhir.jpa.mdm.svc;
/*-
* #%L
* HAPI FHIR JPA Server - 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.context.FhirContext;
import ca.uhn.fhir.mdm.api.IMdmSurvivorshipService;
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IBase;
import org.springframework.beans.factory.annotation.Autowired;
public class MdmSurvivorshipSvcImpl implements IMdmSurvivorshipService {
@Autowired
private FhirContext myFhirContext;
@Override
public <T extends IBase> void applySurvivorshipRulesToGoldenResource(T theTargetResource, T theGoldenResource, MdmTransactionContext theMdmTransactionContext) {
// survivorship logic placeholder
// TerserUtil.cloneFields(myFhirContext, (IBaseResource) theTargetResource, (IBaseResource) theGoldenResource);
}
}

View File

@ -151,11 +151,10 @@ public class MdmGoldenResourceMergerSvcTest extends BaseMdmR4Test {
populatePatient(myFromGoldenPatient);
Patient mergedSourcePatient = mergeGoldenPatients();
// TODO NG - Revisit when rules are ready
// HumanName returnedName = mergedSourcePatient.getNameFirstRep();
// assertEquals(GIVEN_NAME, returnedName.getGivenAsSingleString());
// assertEquals(FAMILY_NAME, returnedName.getFamily());
// assertEquals(POSTAL_CODE, mergedSourcePatient.getAddressFirstRep().getPostalCode());
HumanName returnedName = mergedSourcePatient.getNameFirstRep();
assertEquals(GIVEN_NAME, returnedName.getGivenAsSingleString());
assertEquals(FAMILY_NAME, returnedName.getFamily());
assertEquals(POSTAL_CODE, mergedSourcePatient.getAddressFirstRep().getPostalCode());
}
@Test
@ -376,21 +375,20 @@ public class MdmGoldenResourceMergerSvcTest extends BaseMdmR4Test {
@Test
public void testMergeNames() {
// TODO NG - Revisit when rules are available
// myFromSourcePatient.addName().addGiven("Jim");
// myFromSourcePatient.getNameFirstRep().addGiven("George");
// assertThat(myFromSourcePatient.getName(), hasSize(1));
// assertThat(myFromSourcePatient.getName().get(0).getGiven(), hasSize(2));
//
// myToSourcePatient.addName().addGiven("Jeff");
// myToSourcePatient.getNameFirstRep().addGiven("George");
// assertThat(myToSourcePatient.getName(), hasSize(1));
// assertThat(myToSourcePatient.getName().get(0).getGiven(), hasSize(2));
//
// Patient mergedSourcePatient = mergeSourcePatients();
// assertThat(mergedSourcePatient.getName(), hasSize(2));
// assertThat(mergedSourcePatient.getName().get(0).getGiven(), hasSize(2));
// assertThat(mergedSourcePatient.getName().get(1).getGiven(), hasSize(2));
myFromGoldenPatient.addName().addGiven("Jim");
myFromGoldenPatient.getNameFirstRep().addGiven("George");
assertThat(myFromGoldenPatient.getName(), hasSize(1));
assertThat(myFromGoldenPatient.getName().get(0).getGiven(), hasSize(2));
myToGoldenPatient.addName().addGiven("Jeff");
myToGoldenPatient.getNameFirstRep().addGiven("George");
assertThat(myToGoldenPatient.getName(), hasSize(1));
assertThat(myToGoldenPatient.getName().get(0).getGiven(), hasSize(2));
Patient mergedSourcePatient = mergeGoldenPatients();
assertThat(mergedSourcePatient.getName(), hasSize(2));
assertThat(mergedSourcePatient.getName().get(0).getGiven(), hasSize(2));
assertThat(mergedSourcePatient.getName().get(1).getGiven(), hasSize(2));
}
@Test

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.mdm.api;
/*-
* #%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.mdm.model.MdmTransactionContext;
import org.hl7.fhir.instance.model.api.IBase;

View File

@ -60,10 +60,8 @@ public class PrimitiveTypeEqualsPredicate implements BiPredicate {
if (val1 == null && val2 == null) {
continue;
}
if (val1 == null && val2 != null) {
return false;
}
if (val1 != null && val2 == null) {
if (val1 == null || val2 == null) {
return false;
}
@ -73,13 +71,12 @@ public class PrimitiveTypeEqualsPredicate implements BiPredicate {
if (actualVal1 == null && actualVal2 == null) {
continue;
}
if (actualVal1 == null && actualVal2 != null) {
if (actualVal1 == null) {
return false;
}
if (!actualVal1.equals(actualVal2)) {
return false;
}
}
return true;

View File

@ -88,8 +88,7 @@ final class TerserUtil {
continue;
}
BaseRuntimeElementCompositeDefinition<?> compositeDefinition = (BaseRuntimeElementCompositeDefinition<?>) childDefinition.getChildByName(field);
IBase newFieldValue = compositeDefinition.newInstance();
IBase newFieldValue = childDefinition.getChildByName(field).newInstance();
terser.cloneInto(theFromFieldValue, newFieldValue, true);
theToFieldValues.add(newFieldValue);

View File

@ -0,0 +1,65 @@
package ca.uhn.fhir.mdm.util;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.mdm.BaseR4Test;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.*;
class TerserUtilTest extends BaseR4Test {
@Test
void testCloneEidIntoResource() {
Identifier identifier = new Identifier().setSystem("http://org.com/sys").setValue("123");
Patient p1 = new Patient();
p1.addIdentifier(identifier);
Patient p2 = new Patient();
RuntimeResourceDefinition definition = ourFhirContext.getResourceDefinition(p1);
TerserUtil.cloneEidIntoResource(ourFhirContext, definition.getChildByName("identifier"), identifier, p2);
assertEquals(1, p2.getIdentifier().size());
assertEquals(p1.getIdentifier().get(0).getSystem(), p2.getIdentifier().get(0).getSystem());
assertEquals(p1.getIdentifier().get(0).getValue(), p2.getIdentifier().get(0).getValue());
}
// @Test
void testCloneFields() {
Patient p1 = buildJohny();
Patient p2 = new Patient();
// TerserUtil.cloneFields(ourFhirContext, p1, p2);
assertTrue(p2.getIdentifier().isEmpty());
assertNull(p2.getId());
assertEquals(1, p2.getName().size());
assertEquals(p1.getName().get(0).getNameAsSingleString(), p2.getName().get(0).getNameAsSingleString());
}
// @Test
void testAnotherCloneFields() {
Patient p1 = new Patient();
Patient p2 = new Patient();
p1.addName().addGiven("Joe");
p1.getNameFirstRep().addGiven("George");
assertThat(p1.getName(), hasSize(1));
assertThat(p1.getName().get(0).getGiven(), hasSize(2));
p2.addName().addGiven("Jeff");
p2.getNameFirstRep().addGiven("George");
assertThat(p2.getName(), hasSize(1));
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
// TerserUtil.cloneFields(ourFhirContext, p1, p2);
assertThat(p2.getName(), hasSize(2));
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
assertThat(p2.getName().get(1).getGiven(), hasSize(2));
}
}

View File

@ -1,10 +0,0 @@
package ca.uhn.fhir.mdm.util;
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
public class TestUtils {
public static MdmTransactionContext createDummyContext() {
MdmTransactionContext context = new MdmTransactionContext();
return context;
}
}