WIP Refactoring 3

This commit is contained in:
Nick Goupinets 2020-11-06 17:02:07 -05:00
parent 27afbe93b3
commit 9422ba7a02
2 changed files with 27 additions and 3 deletions

View File

@ -8,10 +8,12 @@ import ca.uhn.fhir.empi.model.CanonicalEID;
import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.empi.util.PersonHelper;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
import ca.uhn.fhir.jpa.entity.EmpiLink;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.Identifier;
@ -35,8 +37,7 @@ import static ca.uhn.fhir.empi.api.EmpiMatchResultEnum.POSSIBLE_DUPLICATE;
import static ca.uhn.fhir.empi.api.EmpiMatchResultEnum.POSSIBLE_MATCH;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.*;
import static org.slf4j.LoggerFactory.getLogger;
public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
@ -48,6 +49,9 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
@Autowired
private PersonHelper myPersonHelper;
@Autowired
private EmpiResourceDaoSvc myEmpiResourceDaoSvc; // TODO NG - remove?
@BeforeEach
public void before() {
super.loadEmpiSearchParameters();
@ -222,6 +226,12 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
createPatientAndUpdateLinks(patient1);
// state is now > Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=jane]
List<CanonicalEID> eid = myEidHelper.getExternalEid(patient1);
Optional<IAnyResource> iAnyResource = myEmpiResourceDaoSvc.searchPersonByEid(eid.get(0).getValue());
assertTrue(iAnyResource.isPresent());
assertTrue(iAnyResource.get().equals(patient1));
Patient patient2 = addExternalEID(buildPaulPatient(), "uniqueid");
createPatientAndUpdateLinks(patient2);
// state should be > Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=paul]
@ -518,6 +528,10 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
assertThat(jane, is(sameSourceResourceAs(paul)));
}
private void print(IBaseResource theResource) {
System.out.println(myFhirContext.newJsonParser().encodeResourceToString(theResource));
}
@Test
//Test Case #2
public void testSinglyLinkedPersonThatGetsAnUpdatedEidSimplyUpdatesEID() {
@ -525,7 +539,10 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
String EID_2 = "456";
Patient paul = createPatientAndUpdateLinks(addExternalEID(buildPaulPatient(), EID_1));
print(paul);
Patient originalPaulPatient = (Patient) getSourceResourceFromTargetResource(paul);
print(originalPaulPatient);
String oldEid = myEidHelper.getExternalEid(originalPaulPatient).get(0).getValue();
assertThat(oldEid, is(equalTo(EID_1)));

View File

@ -55,6 +55,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Function;
@ -278,9 +279,15 @@ public class PersonHelper {
for (IBase base : sourceResourceIdentifiers) {
Optional<IPrimitiveType> system = fhirPath.evaluateFirst(base, "system", IPrimitiveType.class);
if (system.isPresent()) {
if (system.get().equals(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem())) {
String empiSystem = myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem();
String baseSystem = system.get().getValueAsString();
if (Objects.equals(baseSystem, empiSystem)) {
cloneExternalEidIntoNewSourceResource(sourceResourceIdentifier, base, newSourceResource);
} else {
ourLog.debug(String.format("System %s differs from system in the EMPI rules %s", baseSystem, empiSystem));
}
} else {
ourLog.debug("System is missing, skipping");
}
}
}