use of de.symeda.sormas.api.sample.SampleFacade in project SORMAS-Project by hzi-braunschweig.
the class SampleFacadeEjbTest method testGetNewTestResultCountByResultType.
@Test
public void testGetNewTestResultCountByResultType() {
RDCFEntities rdcf = creator.createRDCFEntities();
UserReferenceDto user = creator.createUser(rdcf).toReference();
PersonReferenceDto person1 = creator.createPerson("Heinz", "First").toReference();
PersonReferenceDto person2 = creator.createPerson("Heinz", "Second").toReference();
CaseDataDto case1 = creator.createCase(user, person1, rdcf);
CaseDataDto case2 = creator.createCase(user, person2, rdcf);
List<Long> caseIds = getCaseService().getAllIds(null);
// no existing samples
SampleFacade sampleFacade = getSampleFacade();
Map<PathogenTestResultType, Long> resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
assertEquals(new Long(0), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
// one pending sample with in one case
Facility lab = creator.createFacility("facility", rdcf.region, rdcf.district, rdcf.community);
creator.createSample(case1.toReference(), user, lab);
resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
assertEquals(new Long(1), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
assertEquals(new Long(1), resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
// one pending sample in each of two cases
creator.createSample(case2.toReference(), user, lab);
resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
assertEquals(new Long(2), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
assertEquals(new Long(2), resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
// one pending sample in each of two cases
// and one positive sample in one of the two cases
SampleDto sample = creator.createSample(case1.toReference(), user, lab);
sample.setPathogenTestResult(PathogenTestResultType.POSITIVE);
sampleFacade.saveSample(sample);
resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
assertEquals(new Long(2), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
assertEquals(new Long(1), resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
assertEquals(new Long(1), resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
}
Aggregations