### Question:
EmpiResourceDaoSvc { public Optional<IAnyResource> searchPersonByEid(String theEid) { 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); List<IBaseResource> list = search.getResources(0, MAX_MATCHING_PERSONS).stream() .filter(EmpiUtil::isEmpiManaged) .collect(Collectors.toList()); if (list.isEmpty()) { return Optional.empty(); } else if (list.size() > 1) { throw new InternalErrorException("Found more than one active " + EmpiConstants.CODE_HAPI_EMPI_MANAGED + " Person with EID " + theEid + ": " + list.get(0).getIdElement().getValue() + ", " + list.get(1).getIdElement().getValue() ); } else { return Optional.of((IAnyResource) list.get(0)); } }  @PostConstruct void postConstruct(); IAnyResource readPatient(IIdType theId); IAnyResource readPerson(IIdType theId); IAnyResource readPractitioner(IIdType theId); DaoMethodOutcome updatePerson(IAnyResource thePerson); IAnyResource readPersonByPid(ResourcePersistentId thePersonPid); Optional<IAnyResource> searchPersonByEid(String theEid);  }### Answer:
@Test public void testSearchPersonByEidExcludesInactive() { Person goodPerson = addExternalEID(createPerson(), TEST_EID); myPersonDao.update(goodPerson); Person badPerson = addExternalEID(createPerson(), TEST_EID); badPerson.setActive(false); myPersonDao.update(badPerson); Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchPersonByEid(TEST_EID); assertTrue(foundPerson.isPresent()); assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue())); }
@Test public void testSearchPersonByEidExcludesNonEmpiManaged() { Person goodPerson = addExternalEID(createPerson(), TEST_EID); myPersonDao.update(goodPerson); Person badPerson = addExternalEID(createPerson(new Person(), false), TEST_EID); myPersonDao.update(badPerson); Optional<IAnyResource> foundPerson = myResourceDaoSvc.searchPersonByEid(TEST_EID); assertTrue(foundPerson.isPresent()); assertThat(foundPerson.get().getIdElement().toUnqualifiedVersionless().getValue(), is(goodPerson.getIdElement().toUnqualifiedVersionless().getValue())); }