Resolved MergePersonsR4Test failures

This commit is contained in:
Nick Goupinets 2020-11-16 17:42:09 -05:00
parent 799f6adecb
commit 9a481242c7
2 changed files with 77 additions and 40 deletions

View File

@ -1,7 +1,13 @@
package ca.uhn.fhir.jpa.empi.provider;
import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.util.AssuranceLevelUtil;
import ca.uhn.fhir.empi.util.EmpiUtil;
import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Patient;
@ -9,12 +15,12 @@ import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ -39,20 +45,35 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
@Test
public void testMerge() {
IBaseResource mergedSourcePatient = myEmpiProviderR4.mergeGoldenResources(myFromSourcePatientId, myToSourcePatientId, myRequestDetails);
Patient mergedSourcePatient = (Patient) myEmpiProviderR4.mergeGoldenResources(myFromSourcePatientId,
myToSourcePatientId, myRequestDetails);
assertTrue(EmpiUtil.isGoldenRecord(myFromSourcePatient));
assertEquals(myToSourcePatient.getIdElement(), mergedSourcePatient.getIdElement());
//assertThat(mergedSourcePatient, is(sameSourceResourceAs(myToSourcePatient)));
assertThat(mergedSourcePatient, is(sameSourceResourceAs(myToSourcePatient)));
assertEquals(1, getAllRedirectedGoldenPatients().size());
assertEquals(1, getAllGoldenPatients().size());
Patient fromSourcePatient = myPatientDao.read(myFromSourcePatient.getIdElement().toUnqualifiedVersionless());
assertThat(fromSourcePatient.getActive(), is(false));
assertTrue(EmpiUtil.isGoldenRecordRedirected(fromSourcePatient));
//TODO GGG eventually this will need to check a redirect... this is a hack which doesnt work
Optional<Identifier> redirect = fromSourcePatient.getIdentifier().stream().filter(theIdentifier -> theIdentifier.getSystem().equals("REDIRECT")).findFirst();
assertThat(redirect.get().getValue(), is(equalTo(myToSourcePatient.getIdElement().toUnqualified().getValue())));
// Optional<Identifier> redirect = fromSourcePatient.getIdentifier().stream().filter(theIdentifier -> theIdentifier.getSystem().equals("REDIRECT")).findFirst();
// assertThat(redirect.get().getValue(), is(equalTo(myToSourcePatient.getIdElement().toUnqualified().getValue())));
List<EmpiLink> links = myEmpiLinkDaoSvc.findEmpiLinksByTarget(myFromSourcePatient);
assertThat(links, hasSize(1));
EmpiLink link = links.get(0);
assertEquals(link.getTargetPid(), myFromSourcePatient.getIdElement().toUnqualifiedVersionless().getIdPartAsLong());
assertEquals(link.getSourceResourcePid(), myToSourcePatient.getIdElement().toUnqualifiedVersionless().getIdPartAsLong());
assertEquals(link.getMatchResult(), EmpiMatchResultEnum.REDIRECT);
assertEquals(link.getLinkSource(), EmpiLinkSourceEnum.MANUAL);
// assertThat(links.get(0).getAssurance(), is (AssuranceLevelUtil.getAssuranceLevel(EmpiMatchResultEnum.REDIRECT, EmpiLinkSourceEnum.MANUAL).toR4()));
//List<Person.PersonLinkComponent> links = fromSourcePatient.getLink();
//assertThat(links, hasSize(1));
//assertThat(links.get(0).getTarget().getReference(), is (myToSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
//assertThat(links.get(0).getTarget().getReference(), is (myToSourcePatient.getIdElement().toUnqualifiedVersionless().getValue()));
//assertThat(links.get(0).getAssurance(), is (AssuranceLevelUtil.getAssuranceLevel(EmpiMatchResultEnum.REDIRECT, EmpiLinkSourceEnum.MANUAL).toR4()));
}
@ -64,22 +85,23 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
myEmpiProviderR4.mergeGoldenResources(fromPersonId, toPersonId, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("Only EMPI managed resources can be merged. Empi managed resource have the HAPI-EMPI tag.", e.getMessage());
assertEquals("Only MDM managed resources can be merged. MDM managed resources must have the HAPI-MDM tag.", e.getMessage());
}
}
@Test
public void testMergePatients() {
try {
StringType patientId = new StringType(createPatient().getIdElement().getValue());
StringType otherPatientId = new StringType(createPatient().getIdElement().getValue());
myEmpiProviderR4.mergeGoldenResources(patientId, otherPatientId, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), endsWith("must have form Person/<id> where <id> is the id of the person"));
}
}
// INVALID ANYMORE - we support merging patients to patients now
// @Test
// public void testMergePatients() {
// try {
// StringType patientId = new StringType(createPatient().getIdElement().getValue());
// StringType otherPatientId = new StringType(createPatient().getIdElement().getValue());
// myEmpiProviderR4.mergeGoldenResources(patientId, otherPatientId, myRequestDetails);
// fail();
// } catch (InvalidRequestException e) {
// assertThat(e.getMessage(), endsWith("must have form Person/<id> where <id> is the id of the person"));
// }
//
// }
@Test
public void testNullParams() {
@ -87,48 +109,56 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test {
myEmpiProviderR4.mergeGoldenResources(null, null, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("fromPersonId cannot be null", e.getMessage());
assertEquals("fromGoldenResourceId cannot be null", e.getMessage());
}
try {
myEmpiProviderR4.mergeGoldenResources(null, myToSourcePatientId, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("fromPersonId cannot be null", e.getMessage());
assertEquals("fromGoldenResourceId cannot be null", e.getMessage());
}
try {
myEmpiProviderR4.mergeGoldenResources(myFromSourcePatientId, null, myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("toPersonId cannot be null", e.getMessage());
assertEquals("toGoldenResourceId cannot be null", e.getMessage());
}
}
@Test
public void testBadParams() {
try {
myEmpiProviderR4.mergeGoldenResources(new StringType("Patient/1"), new StringType("Patient/2"), myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), endsWith(" must have form Person/<id> where <id> is the id of the person"));
}
try {
myEmpiProviderR4.mergeGoldenResources(myFromSourcePatientId, new StringType("Patient/2"), myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), endsWith(" must have form Person/<id> where <id> is the id of the person"));
}
print(myFromSourcePatient);
print(myToSourcePatient);
// TODO NG - THESE ARE NOW INVALID
// try {
// myEmpiProviderR4.mergeGoldenResources(new StringType("Patient/1"), new StringType("Patient/2"), myRequestDetails);
// fail();
// } catch (InvalidRequestException e) {
// assertThat(e.getMessage(), endsWith(" must have form Person/<id> where <id> is the id of the person"));
// }
//
// try {
// myEmpiProviderR4.mergeGoldenResources(myFromSourcePatientId, new StringType("Patient/2"), myRequestDetails);
// fail();
// } catch (InvalidRequestException e) {
// assertThat(e.getMessage(), endsWith(" must have form Person/<id> where <id> is the id of the person"));
// }
try {
myEmpiProviderR4.mergeGoldenResources(new StringType("Person/1"), new StringType("Person/1"), myRequestDetails);
fail();
} catch (InvalidRequestException e) {
assertEquals("fromPersonId must be different from toPersonId", e.getMessage());
}
try {
myEmpiProviderR4.mergeGoldenResources(new StringType("Person/abc"), myToSourcePatientId, myRequestDetails);
fail();
} catch (ResourceNotFoundException e) {
assertEquals("Resource Person/abc is not known", e.getMessage());
}
try {
myEmpiProviderR4.mergeGoldenResources(myFromSourcePatientId, new StringType("Person/abc"), myRequestDetails);
fail();

View File

@ -151,7 +151,9 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
validateMergeParameters(theFromGoldenResourceId, theToGoldenResourceId);
return myEmpiControllerSvc.mergeGoldenResources(theFromGoldenResourceId.getValue(), theToGoldenResourceId.getValue(),
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS, theFromGoldenResourceId.getValue()));
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.MERGE_PERSONS,
getResourceType(ProviderConstants.MDM_MERGE_GR_FROM_GOLDEN_RESOURCE_ID, theFromGoldenResourceId.getValue()))
);
}
@Operation(name = ProviderConstants.MDM_UPDATE_LINK)
@ -163,7 +165,8 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
return myEmpiControllerSvc.updateLink(theGoldenResourceId.getValueNotNull(), theResourceId.getValue(),
theMatchResult.getValue(),
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.UPDATE_LINK,
getResourceType(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, theGoldenResourceId.getValue())));
getResourceType(ProviderConstants.MDM_UPDATE_LINK_GOLDEN_RESOURCE_ID, theGoldenResourceId.getValue()))
);
}
@Operation(name = ProviderConstants.MDM_CLEAR, returnParameters = {
@ -193,7 +196,9 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
Stream<EmpiLinkJson> empiLinkJson = myEmpiControllerSvc.queryLinks(extractStringOrNull(theGoldenResourceId),
extractStringOrNull(theResourceId), extractStringOrNull(theMatchResult), extractStringOrNull(theLinkSource),
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS, theGoldenResourceId.getValue()));
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.QUERY_LINKS,
getResourceType(ProviderConstants.MDM_QUERY_LINKS_GOLDEN_RESOURCE_ID, theGoldenResourceId.getValue()))
);
return (Parameters) parametersFromEmpiLinks(empiLinkJson, true);
}
@ -212,7 +217,9 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
validateNotDuplicateParameters(theGoldenResourceId, theResourceId);
myEmpiControllerSvc.notDuplicateGoldenResource(theGoldenResourceId.getValue(), theResourceId.getValue(),
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE, theGoldenResourceId.getValue()));
createMdmContext(theRequestDetails, MdmTransactionContext.OperationType.NOT_DUPLICATE,
getResourceType(ProviderConstants.MDM_QUERY_LINKS_GOLDEN_RESOURCE_ID, theGoldenResourceId.getValue()))
);
Parameters retval = (Parameters) ParametersUtil.newInstance(myFhirContext);
ParametersUtil.addParameterToParametersBoolean(myFhirContext, retval, "success", true);