modified MdmLinkDaoJpaImpl.convertToLongIds so that it returns all pi… (#5244)
* modified MdmLinkDaoJpaImpl.convertToLongIds so that it returns all pid that is related to a forced id. added tests for above changes * joined helper methods * joined helper methods
This commit is contained in:
parent
9ded67fb4d
commit
db6d8092f2
|
@ -411,8 +411,9 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private List<Long> convertToLongIds(List<IIdType> theMdmHistorySearchParameters) {
|
private List<Long> convertToLongIds(List<IIdType> theMdmHistorySearchParameters) {
|
||||||
return theMdmHistorySearchParameters.stream()
|
return myIdHelperService
|
||||||
.map(id -> myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), id))
|
.getPidsOrThrowException(RequestPartitionId.allPartitions(), theMdmHistorySearchParameters)
|
||||||
|
.stream()
|
||||||
.map(JpaPid::getId)
|
.map(JpaPid::getId)
|
||||||
.collect(Collectors.toUnmodifiableList());
|
.collect(Collectors.toUnmodifiableList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,20 +41,13 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
|
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
|
||||||
import ca.uhn.fhir.rest.param.TokenParam;
|
import ca.uhn.fhir.rest.param.TokenParam;
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||||
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.model.CodeableConcept;
|
import org.hl7.fhir.r4.model.*;
|
||||||
import org.hl7.fhir.r4.model.ContactPoint;
|
|
||||||
import org.hl7.fhir.r4.model.DateType;
|
|
||||||
import org.hl7.fhir.r4.model.Medication;
|
|
||||||
import org.hl7.fhir.r4.model.Observation;
|
|
||||||
import org.hl7.fhir.r4.model.Organization;
|
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
|
||||||
import org.hl7.fhir.r4.model.Practitioner;
|
|
||||||
import org.hl7.fhir.r4.model.Reference;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
@ -662,4 +655,23 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
|
||||||
|
|
||||||
return myMdmLinkDao.save(mdmLink);
|
return myMdmLinkDao.save(mdmLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IBaseResource createResourceWithId(IBaseResource theResource, String theId, Enumerations.ResourceType theResourceType){
|
||||||
|
theResource.setId(theId);
|
||||||
|
DaoMethodOutcome daoMethodOutcome = null;
|
||||||
|
switch (theResourceType){
|
||||||
|
case PATIENT:
|
||||||
|
((Patient) theResource).setActive(true);
|
||||||
|
daoMethodOutcome = myPatientDao.update((Patient) theResource, new SystemRequestDetails());
|
||||||
|
break;
|
||||||
|
case PRACTITIONER:
|
||||||
|
((Practitioner) theResource).setActive(true);
|
||||||
|
daoMethodOutcome = myPractitionerDao.update((Practitioner) theResource, new SystemRequestDetails());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException("This method haven't been setup for: " + theResourceType);
|
||||||
|
}
|
||||||
|
theResource.setId(daoMethodOutcome.getId());
|
||||||
|
return theResource;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@ import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
|
||||||
import ca.uhn.fhir.mdm.model.MdmPidTuple;
|
import ca.uhn.fhir.mdm.model.MdmPidTuple;
|
||||||
import ca.uhn.fhir.mdm.rules.json.MdmRulesJson;
|
import ca.uhn.fhir.mdm.rules.json.MdmRulesJson;
|
||||||
import org.hibernate.envers.RevisionType;
|
import org.hibernate.envers.RevisionType;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.r4.model.Enumerations;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
|
import org.hl7.fhir.r4.model.Practitioner;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -214,6 +217,31 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test {
|
||||||
assertThrows(IllegalArgumentException.class, () -> myMdmLinkDaoSvc.findMdmLinkHistory(new MdmHistorySearchParameters()));
|
assertThrows(IllegalArgumentException.class, () -> myMdmLinkDaoSvc.findMdmLinkHistory(new MdmHistorySearchParameters()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHistoryForIdWithMultipleMatches(){
|
||||||
|
// setup
|
||||||
|
String commonId = "p123";
|
||||||
|
|
||||||
|
// Patient/p123 and its golden resource
|
||||||
|
Patient goldenPatient = createPatient();
|
||||||
|
Patient sourcePatient = (Patient) createResourceWithId(new Patient(), commonId, Enumerations.ResourceType.PATIENT);
|
||||||
|
|
||||||
|
MdmLink mdmPatientLink = linkGoldenAndSourceResource(MdmMatchResultEnum.MATCH, goldenPatient, sourcePatient);
|
||||||
|
JpaPid goldenPatientId = mdmPatientLink.getGoldenResourcePersistenceId();
|
||||||
|
// Practitioner/p123 and its golden resource
|
||||||
|
Practitioner goldenPractitioner = createPractitioner(new Practitioner());
|
||||||
|
Practitioner sourcePractitioner = (Practitioner) createResourceWithId(new Practitioner(), commonId, Enumerations.ResourceType.PRACTITIONER);
|
||||||
|
|
||||||
|
linkGoldenAndSourceResource(MdmMatchResultEnum.MATCH, goldenPractitioner, sourcePractitioner);
|
||||||
|
|
||||||
|
// execute
|
||||||
|
MdmHistorySearchParameters mdmHistorySearchParameters = new MdmHistorySearchParameters().setSourceIds(List.of(commonId));
|
||||||
|
List<MdmLinkWithRevision<MdmLink>> actualMdmLinkRevisions = myMdmLinkDaoSvc.findMdmLinkHistory(mdmHistorySearchParameters);
|
||||||
|
|
||||||
|
// verify
|
||||||
|
assertEquals(2, actualMdmLinkRevisions.size(), "Both Patient/p123 and Practitioner/p123 should be returned");
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static List<String> getIdsFromMdmLinks(Function<MdmLink, JpaPid> getIdFunction, MdmLink... mdmLinks) {
|
private static List<String> getIdsFromMdmLinks(Function<MdmLink, JpaPid> getIdFunction, MdmLink... mdmLinks) {
|
||||||
return Arrays.stream(mdmLinks)
|
return Arrays.stream(mdmLinks)
|
||||||
|
@ -271,16 +299,18 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test {
|
||||||
|
|
||||||
return IntStream.range(0, numTargetPatients).mapToObj(myInt -> {
|
return IntStream.range(0, numTargetPatients).mapToObj(myInt -> {
|
||||||
final Patient targetPatient = createPatient();
|
final Patient targetPatient = createPatient();
|
||||||
|
return linkGoldenAndSourceResource(theFirstMdmMatchResultEnum, goldenPatient, targetPatient);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MdmLink linkGoldenAndSourceResource(MdmMatchResultEnum theFirstMdmMatchResultEnum, IBaseResource theGoldenResource, IBaseResource theTargetResource) {
|
||||||
MdmLink mdmLink = (MdmLink) myMdmLinkDaoSvc.newMdmLink();
|
MdmLink mdmLink = (MdmLink) myMdmLinkDaoSvc.newMdmLink();
|
||||||
mdmLink.setLinkSource(MdmLinkSourceEnum.MANUAL);
|
mdmLink.setLinkSource(MdmLinkSourceEnum.MANUAL);
|
||||||
mdmLink.setMatchResult(theFirstMdmMatchResultEnum);
|
mdmLink.setMatchResult(theFirstMdmMatchResultEnum);
|
||||||
mdmLink.setCreated(new Date());
|
mdmLink.setCreated(new Date());
|
||||||
mdmLink.setUpdated(new Date());
|
mdmLink.setUpdated(new Date());
|
||||||
mdmLink.setGoldenResourcePersistenceId(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient)));
|
mdmLink.setGoldenResourcePersistenceId(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), theGoldenResource)));
|
||||||
mdmLink.setSourcePersistenceId(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), targetPatient)));
|
mdmLink.setSourcePersistenceId(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), theTargetResource)));
|
||||||
return myMdmLinkDao.save(mdmLink);
|
return myMdmLinkDao.save(mdmLink);
|
||||||
|
|
||||||
}).toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue