Empi merge persons fixes (#1882)
This commit is contained in:
parent
201c3a6187
commit
61f1b57b2a
|
@ -28,6 +28,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
@ -315,6 +316,55 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
|
||||||
assertEquals(3, myKeepPerson.getLink().size());
|
assertEquals(3, myKeepPerson.getLink().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeNames() {
|
||||||
|
myDeletePerson.addName().addGiven("Jim");
|
||||||
|
myDeletePerson.getNameFirstRep().addGiven("George");
|
||||||
|
assertThat(myDeletePerson.getName(), hasSize(1));
|
||||||
|
assertThat(myDeletePerson.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
|
||||||
|
myKeepPerson.addName().addGiven("Jeff");
|
||||||
|
myKeepPerson.getNameFirstRep().addGiven("George");
|
||||||
|
assertThat(myKeepPerson.getName(), hasSize(1));
|
||||||
|
assertThat(myKeepPerson.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
|
||||||
|
mergePersons();
|
||||||
|
assertThat(myKeepPerson.getName(), hasSize(2));
|
||||||
|
assertThat(myKeepPerson.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
assertThat(myKeepPerson.getName().get(1).getGiven(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeNamesAllSame() {
|
||||||
|
myDeletePerson.addName().addGiven("Jim");
|
||||||
|
myDeletePerson.getNameFirstRep().addGiven("George");
|
||||||
|
assertThat(myDeletePerson.getName(), hasSize(1));
|
||||||
|
assertThat(myDeletePerson.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
|
||||||
|
myKeepPerson.addName().addGiven("Jim");
|
||||||
|
myKeepPerson.getNameFirstRep().addGiven("George");
|
||||||
|
assertThat(myKeepPerson.getName(), hasSize(1));
|
||||||
|
assertThat(myKeepPerson.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
|
||||||
|
mergePersons();
|
||||||
|
assertThat(myKeepPerson.getName(), hasSize(1));
|
||||||
|
assertThat(myKeepPerson.getName().get(0).getGiven(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMergeIdentities() {
|
||||||
|
myDeletePerson.addIdentifier().setValue("aaa");
|
||||||
|
myDeletePerson.addIdentifier().setValue("bbb");
|
||||||
|
assertThat(myDeletePerson.getIdentifier(), hasSize(2));
|
||||||
|
|
||||||
|
myKeepPerson.addIdentifier().setValue("aaa");
|
||||||
|
myKeepPerson.addIdentifier().setValue("ccc");
|
||||||
|
assertThat(myKeepPerson.getIdentifier(), hasSize(2));
|
||||||
|
|
||||||
|
mergePersons();
|
||||||
|
assertThat(myKeepPerson.getIdentifier(), hasSize(3));
|
||||||
|
}
|
||||||
|
|
||||||
private EmpiLink createEmpiLink(Person thePerson, Patient theTargetPatient) {
|
private EmpiLink createEmpiLink(Person thePerson, Patient theTargetPatient) {
|
||||||
thePerson.addLink().setTarget(new Reference(theTargetPatient));
|
thePerson.addLink().setTarget(new Reference(theTargetPatient));
|
||||||
return myEmpiLinkDaoSvc.createOrUpdateLinkEntity(thePerson, theTargetPatient, EmpiMatchResultEnum.POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate());
|
return myEmpiLinkDaoSvc.createOrUpdateLinkEntity(thePerson, theTargetPatient, EmpiMatchResultEnum.POSSIBLE_MATCH, EmpiLinkSourceEnum.AUTO, createContextForCreate());
|
||||||
|
|
|
@ -34,7 +34,10 @@ import org.hl7.fhir.instance.model.api.IBaseCoding;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseReference;
|
import org.hl7.fhir.instance.model.api.IBaseReference;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.hl7.fhir.r4.model.Address;
|
||||||
import org.hl7.fhir.r4.model.Coding;
|
import org.hl7.fhir.r4.model.Coding;
|
||||||
|
import org.hl7.fhir.r4.model.ContactPoint;
|
||||||
|
import org.hl7.fhir.r4.model.HumanName;
|
||||||
import org.hl7.fhir.r4.model.Identifier;
|
import org.hl7.fhir.r4.model.Identifier;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.hl7.fhir.r4.model.Person;
|
import org.hl7.fhir.r4.model.Person;
|
||||||
|
@ -45,8 +48,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -476,15 +482,11 @@ public class PersonHelper {
|
||||||
private void mergeR4PersonFields(IBaseResource thePersonToDelete, IBaseResource thePersonToKeep) {
|
private void mergeR4PersonFields(IBaseResource thePersonToDelete, IBaseResource thePersonToKeep) {
|
||||||
Person fromPerson = (Person) thePersonToDelete;
|
Person fromPerson = (Person) thePersonToDelete;
|
||||||
Person toPerson = (Person) thePersonToKeep;
|
Person toPerson = (Person) thePersonToKeep;
|
||||||
if (!toPerson.hasName()) {
|
|
||||||
toPerson.setName(fromPerson.getName());
|
mergeElementList(fromPerson, toPerson, HumanName.class, Person::getName, HumanName::equalsDeep);
|
||||||
}
|
mergeElementList(fromPerson, toPerson, Identifier.class, Person::getIdentifier, Identifier::equalsDeep);
|
||||||
if (!toPerson.hasAddress()) {
|
mergeElementList(fromPerson, toPerson, Address.class, Person::getAddress, Address::equalsDeep);
|
||||||
toPerson.setAddress(fromPerson.getAddress());
|
mergeElementList(fromPerson, toPerson, ContactPoint.class, Person::getTelecom, ContactPoint::equalsDeep);
|
||||||
}
|
|
||||||
if (!toPerson.hasTelecom()) {
|
|
||||||
toPerson.setTelecom(fromPerson.getTelecom());
|
|
||||||
}
|
|
||||||
if (!toPerson.hasBirthDate()) {
|
if (!toPerson.hasBirthDate()) {
|
||||||
toPerson.setBirthDate(fromPerson.getBirthDate());
|
toPerson.setBirthDate(fromPerson.getBirthDate());
|
||||||
}
|
}
|
||||||
|
@ -496,19 +498,28 @@ public class PersonHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <P,T> void mergeElementList(P fromPerson, P toPerson, Class<T> theBase, Function<P, List<T>> theGetList, BiPredicate<T, T> theEquals) {
|
||||||
|
List<T> fromList = theGetList.apply(fromPerson);
|
||||||
|
List<T> toList = theGetList.apply(toPerson);
|
||||||
|
List<T> itemsToAdd = new ArrayList<>();
|
||||||
|
|
||||||
|
for (T fromItem : fromList) {
|
||||||
|
if (toList.stream().noneMatch(t -> theEquals.test(fromItem, t))) {
|
||||||
|
itemsToAdd.add(fromItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toList.addAll(itemsToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
private void mergeDstu3PersonFields(IBaseResource thePersonToDelete, IBaseResource thePersonToKeep) {
|
private void mergeDstu3PersonFields(IBaseResource thePersonToDelete, IBaseResource thePersonToKeep) {
|
||||||
org.hl7.fhir.dstu3.model.Person fromPerson = (org.hl7.fhir.dstu3.model.Person) thePersonToDelete;
|
org.hl7.fhir.dstu3.model.Person fromPerson = (org.hl7.fhir.dstu3.model.Person) thePersonToDelete;
|
||||||
org.hl7.fhir.dstu3.model.Person toPerson = (org.hl7.fhir.dstu3.model.Person) thePersonToKeep;
|
org.hl7.fhir.dstu3.model.Person toPerson = (org.hl7.fhir.dstu3.model.Person) thePersonToKeep;
|
||||||
if (!toPerson.hasName()) {
|
|
||||||
toPerson.setName(fromPerson.getName());
|
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.HumanName.class, org.hl7.fhir.dstu3.model.Person::getName, org.hl7.fhir.dstu3.model.HumanName::equalsDeep);
|
||||||
}
|
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.Identifier.class, org.hl7.fhir.dstu3.model.Person::getIdentifier, org.hl7.fhir.dstu3.model.Identifier::equalsDeep);
|
||||||
if (!toPerson.hasAddress()) {
|
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.Address.class, org.hl7.fhir.dstu3.model.Person::getAddress, org.hl7.fhir.dstu3.model.Address::equalsDeep);
|
||||||
toPerson.setAddress(fromPerson.getAddress());
|
mergeElementList(fromPerson, toPerson, org.hl7.fhir.dstu3.model.ContactPoint.class, org.hl7.fhir.dstu3.model.Person::getTelecom, org.hl7.fhir.dstu3.model.ContactPoint::equalsDeep);
|
||||||
}
|
|
||||||
if (!toPerson.hasTelecom()) {
|
|
||||||
toPerson.setTelecom(fromPerson.getTelecom());
|
|
||||||
}
|
|
||||||
if (!toPerson.hasBirthDate()) {
|
if (!toPerson.hasBirthDate()) {
|
||||||
toPerson.setBirthDate(fromPerson.getBirthDate());
|
toPerson.setBirthDate(fromPerson.getBirthDate());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue