Use case #3 testing

This commit is contained in:
Nick Goupinets 2020-11-09 11:07:58 -05:00
parent 4c0fab8cec
commit 5d6ede660b
5 changed files with 42 additions and 37 deletions

View File

@ -96,6 +96,14 @@
</execution>
</executions>
</plugin>
</plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -44,35 +44,14 @@ import java.util.stream.Collectors;
@Service
public class EmpiResourceDaoSvc {
private static final int MAX_MATCHING_PERSONS = 1000;
@Autowired
DaoRegistry myDaoRegistry;
@Autowired
IEmpiSettings myEmpiConfig;
private IFhirResourceDao<IBaseResource> myPatientDao;
private IFhirResourceDao<IBaseResource> myPersonDao;
private IFhirResourceDao<IBaseResource> myPractitionerDao;
@PostConstruct
public void postConstruct() {
myPatientDao = myDaoRegistry.getResourceDao("Patient");
myPersonDao = myDaoRegistry.getResourceDao("Person");
myPractitionerDao = myDaoRegistry.getResourceDao("Practitioner");
}
public IAnyResource readPatient(IIdType theId) {
return (IAnyResource) myPatientDao.read(theId);
}
public IAnyResource readPerson(IIdType theId) {
return (IAnyResource) myPersonDao.read(theId);
}
public IAnyResource readPractitioner(IIdType theId) {
return (IAnyResource) myPractitionerDao.read(theId);
}
public DaoMethodOutcome upsertSourceResource(IAnyResource theSourceResource, String theResourceType) {
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
if (theSourceResource.getIdElement().hasIdPart()) {
@ -87,12 +66,14 @@ public class EmpiResourceDaoSvc {
return (IAnyResource) resourceDao.readByPid(theSourceResourcePid);
}
public Optional<IAnyResource> searchPersonByEid(String theEid) {
public Optional<IAnyResource> searchSourceResourceByEID(String theEid, String theResourceType) {
SearchParameterMap map = new SearchParameterMap();
map.setLoadSynchronous(true);
map.add("identifier", new TokenParam(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem(), theEid));
map.add("active", new TokenParam("true"));
IBundleProvider search = myPersonDao.search(map);
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
IBundleProvider search = resourceDao.search(map);
// Could add the meta tag to the query, but it's probably more efficient to filter on it afterwards since in practice
// it will always be present.
@ -111,7 +92,7 @@ public class EmpiResourceDaoSvc {
list.get(0).getIdElement().getValue() +
", " +
list.get(1).getIdElement().getValue()
);
);
} else {
return Optional.of((IAnyResource) list.get(0));
}

View File

@ -37,6 +37,7 @@ import java.util.Optional;
@Service
public class FindCandidateByEidSvc extends BaseCandidateFinder {
private static final Logger ourLog = Logs.getEmpiTroubleshootingLog();
@Autowired
@ -50,7 +51,7 @@ public class FindCandidateByEidSvc extends BaseCandidateFinder {
List<CanonicalEID> eidFromResource = myEIDHelper.getExternalEid(theBaseResource);
if (!eidFromResource.isEmpty()) {
for (CanonicalEID eid : eidFromResource) {
Optional<IAnyResource> oFoundPerson = myEmpiResourceDaoSvc.searchPersonByEid(eid.getValue());
Optional<IAnyResource> oFoundPerson = myEmpiResourceDaoSvc.searchSourceResourceByEID(eid.getValue(), theBaseResource.getIdElement().getResourceType());
if (oFoundPerson.isPresent()) {
IAnyResource foundPerson = oFoundPerson.get();
Long pidOrNull = myIdHelperService.getPidOrNull(foundPerson);

View File

@ -221,20 +221,35 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
@Test
public void testIncomingPatientWithEidMatchesAnotherPatientWithSameEIDAreLinked() {
// Use Case #3
// Create Use Case #3
Patient patient1 = addExternalEID(buildJanePatient(), "uniqueid");
createPatientAndUpdateLinks(patient1);
// state is now > Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=jane]
List<CanonicalEID> eid = myEidHelper.getExternalEid(patient1);
// state is now > Patient/ID.JANE.123[name=jane & EID = uniqueid] <-- EMPI Link -- Patient/[name=jane & EDI = uniqueid & EMPI_MANAGED = true]
IBundleProvider bundle = myPatientDao.search(new SearchParameterMap());
List<IBaseResource> resources = bundle.getResources(0, bundle.size());
resources.forEach(r -> {
print(r);
assertFalse(myEidHelper.getExternalEid(r).isEmpty());
});
assertEquals(2, resources.size());
Optional<IAnyResource> iAnyResource = myEmpiResourceDaoSvc.searchPersonByEid(eid.get(0).getValue());
assertTrue(iAnyResource.isPresent());
assertTrue(iAnyResource.get().equals(patient1));
IBaseResource testPatient1 = resources.get(0);
IBaseResource testPatient2 = resources.get(1);
assertThat((Patient) testPatient1, is(sameSourceResourceAs((Patient) testPatient2)));
Optional<EmpiLink> empiLinkByTarget = myEmpiLinkDaoSvc.findEmpiLinkByTarget(patient1);
assertTrue(empiLinkByTarget.isPresent());
Patient patient2 = addExternalEID(buildPaulPatient(), "uniqueid");
createPatientAndUpdateLinks(patient2);
// state should be > Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=jane] <--> Patient/uniqueid[name=paul]
// state should be > Patient/ID.JANE.123[name=jane & EID = uniqueid] <--> Patient/[name=jane & EDI = uniqueid] <--> Patient/[name=paul & EDI = uniqueid]
IBundleProvider search = myPatientDao.search(new SearchParameterMap());
search.getResources(0, search.size()).forEach( r -> {
print(r);
}
);
assertThat(patient1, is(sameSourceResourceAs(patient2)));
}

View File

@ -32,7 +32,7 @@ public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test {
badPerson.setActive(false);
myPersonDao.update(badPerson);
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchPersonByEid(TEST_EID);
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person");
assertTrue(foundPerson.isPresent());
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue()));
}
@ -45,7 +45,7 @@ public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test {
Person badPerson = addExternalEID(createPerson(new Person(), false), TEST_EID);
myPersonDao.update(badPerson);
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchPersonByEid(TEST_EID);
Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchSourceResourceByEID(TEST_EID, "Person");
assertTrue(foundPerson.isPresent());
assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue()));
}