Skip to content

Commit

Permalink
Fixed code for use case #3 test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nvg-smile committed Nov 9, 2020
1 parent 5d6ede6 commit ac3b1e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@

import ca.uhn.fhir.empi.api.EmpiConstants;
import ca.uhn.fhir.empi.api.IEmpiSettings;
import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.empi.util.EmpiUtil;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.param.TokenParam;
Expand Down Expand Up @@ -70,7 +72,9 @@ public Optional<IAnyResource> searchSourceResourceByEID(String theEid, String th
SearchParameterMap map = new SearchParameterMap();
map.setLoadSynchronous(true);
map.add("identifier", new TokenParam(myEmpiConfig.getEmpiRules().getEnterpriseEIDSystem(), theEid));
map.add("active", new TokenParam("true"));
// TODO NG - During person dedup do we set this to false? We might be setting a person to inactive...
// map.add("active", new TokenParam("true"));
map.add("_tag", new TokenParam(EmpiConstants.SYSTEM_EMPI_MANAGED, EmpiConstants.CODE_HAPI_EMPI_MANAGED));

IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
IBundleProvider search = resourceDao.search(map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,28 @@ public void testIncomingPatientWithEidMatchesAnotherPatientWithSameEIDAreLinked(
Patient patient1 = addExternalEID(buildJanePatient(), "uniqueid");
createPatientAndUpdateLinks(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());

IBaseResource testPatient1 = resources.get(0);
IBaseResource testPatient2 = resources.get(1);
{
// 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());

assertThat((Patient) testPatient1, is(sameSourceResourceAs((Patient) testPatient2)));
IBaseResource testPatient1 = resources.get(0);
IBaseResource testPatient2 = resources.get(1);

Optional<EmpiLink> empiLinkByTarget = myEmpiLinkDaoSvc.findEmpiLinkByTarget(patient1);
assertTrue(empiLinkByTarget.isPresent());
assertThat((Patient) testPatient1, is(sameSourceResourceAs((Patient) testPatient2)));

Patient patient2 = addExternalEID(buildPaulPatient(), "uniqueid");
Optional<EmpiLink> empiLinkByTarget = myEmpiLinkDaoSvc.findEmpiLinkByTarget(patient1);
assertTrue(empiLinkByTarget.isPresent());
System.out.println(empiLinkByTarget.get());
}
Patient patient2 = buildPaulPatient();
patient2.setActive(true);
patient2 = addExternalEID(patient2, "uniqueid");
createPatientAndUpdateLinks(patient2);
// 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());
Expand Down

0 comments on commit ac3b1e3

Please sign in to comment.