Search in sources :

Example 1 with SampleFacade

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));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SampleFacade(de.symeda.sormas.api.sample.SampleFacade) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) SampleDto(de.symeda.sormas.api.sample.SampleDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)1 PathogenTestResultType (de.symeda.sormas.api.sample.PathogenTestResultType)1 SampleDto (de.symeda.sormas.api.sample.SampleDto)1 SampleFacade (de.symeda.sormas.api.sample.SampleFacade)1 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)1 Facility (de.symeda.sormas.backend.infrastructure.facility.Facility)1 Test (org.junit.Test)1