Search in sources :

Example 1 with GroupableItem

use of se.inera.intyg.webcert.common.model.GroupableItem in project webcert by sklintyg.

the class UtkastRepositoryTest method testCountIntygWithStatusesGroupedByEnhetsId.

@Test
public void testCountIntygWithStatusesGroupedByEnhetsId() {
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_1_ID, UtkastStatus.DRAFT_INCOMPLETE));
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_2_ID, UtkastStatus.DRAFT_COMPLETE));
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_3_ID, UtkastStatus.DRAFT_COMPLETE));
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_1_ID, UtkastStatus.DRAFT_COMPLETE));
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_2_ID, UtkastStatus.DRAFT_COMPLETE));
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_1_ID, UtkastStatus.DRAFT_INCOMPLETE));
    utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_3_ID, UtkastStatus.SIGNED));
    List<GroupableItem> result = utkastRepository.getIntygWithStatusesByEnhetsId(Arrays.asList(UtkastTestUtil.ENHET_1_ID), Arrays.asList(UtkastStatus.DRAFT_COMPLETE, UtkastStatus.DRAFT_INCOMPLETE), Stream.of(UtkastTestUtil.INTYGSTYP_FK7263).collect(Collectors.toCollection(HashSet::new)));
    assertThat(result.size(), is(3));
    GroupableItem resObjs = result.get(0);
    assertThat(resObjs.getEnhetsId(), equalTo(UtkastTestUtil.ENHET_1_ID));
    assertThat(resObjs.getPersonnummer(), equalTo(PERSON_NUMMER.getPersonnummerWithDash()));
    assertThat(resObjs.getIntygsTyp(), equalTo("fk7263"));
}
Also used : GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with GroupableItem

use of se.inera.intyg.webcert.common.model.GroupableItem in project webcert by sklintyg.

the class ArendeRepositoryTest method testCountUnhandledGroupedByEnhetIdsAndIntygstyper.

@Test
public void testCountUnhandledGroupedByEnhetIdsAndIntygstyper() {
    // Question on enhet 1
    repo.save(buildArende("signeratAv", "enhet1", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT));
    // Answer on enhet 1
    repo.save(buildArende("signeratAv", "enhet1", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", "svarPaMeddelandeId", "FKASSA", LocalDate.now(), ArendeAmne.KONTKT));
    // Closed question on enhet 1
    repo.save(buildArende("signeratAv", "enhet1", Status.CLOSED, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT));
    // Reminder on enhet 1
    repo.save(buildArende("signeratAv", "enhet1", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.PAMINN));
    // Question on enhet 1
    repo.save(buildArende("signeratAv", "enhet1", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT));
    // Question on enhet 2
    repo.save(buildArende("signeratAv", "enhet2", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT));
    // Question on enhet 3
    repo.save(buildArende("signeratAv", "enhet3", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT));
    // Question with type 2
    Arende arendeType2 = buildArende("signeratAv", "enhet1", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT);
    arendeType2.setIntygTyp("INTYG_TYP_2");
    repo.save(arendeType2);
    // Question with type 3
    Arende arendeType3 = buildArende("signeratAv", "enhet1", Status.PENDING_INTERNAL_ACTION, "paminnelseMeddelandeId", null, "FKASSA", LocalDate.now(), ArendeAmne.KONTKT);
    arendeType2.setIntygTyp("INTYG_TYP_3");
    repo.save(arendeType3);
    List<String> enhetsIds = Arrays.asList("enhet1", "enhet2");
    Set<String> intygsTyper = new HashSet<>(Arrays.asList("INTYG_TYP", "INTYG_TYP_2"));
    List<GroupableItem> res = repo.getUnhandledByEnhetIdsAndIntygstyper(enhetsIds, intygsTyper);
    assertNotNull(res);
    assertEquals(4, res.size());
// assertEquals("enhet1", res.get(0)[0]);
// assertEquals(new Long(3), res.get(0)[1]);
// assertEquals("enhet2", res.get(1)[0]);
// assertEquals(new Long(1), res.get(1)[1]);
}
Also used : GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with GroupableItem

use of se.inera.intyg.webcert.common.model.GroupableItem in project webcert by sklintyg.

the class UtkastServiceImpl method getNbrOfUnsignedDraftsByCareUnits.

@Override
@Transactional(readOnly = true)
public Map<String, Long> getNbrOfUnsignedDraftsByCareUnits(List<String> careUnitIds) {
    Map<String, Long> resultsMap = new HashMap<>();
    if (careUnitIds == null || careUnitIds.isEmpty()) {
        LOG.warn("No ids for Vardenheter was supplied");
        return resultsMap;
    }
    WebCertUser user = webCertUserService.getUser();
    // Get intygstyper from write privilege
    Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG);
    List<GroupableItem> resultArr = utkastRepository.getIntygWithStatusesByEnhetsId(careUnitIds, ALL_DRAFT_STATUSES, intygsTyper);
    return statisticsGroupByUtil.toSekretessFilteredMap(resultArr);
}
Also used : GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with GroupableItem

use of se.inera.intyg.webcert.common.model.GroupableItem in project webcert by sklintyg.

the class StatisticsGroupByUtil method toSekretessFilteredMap.

/**
 * Takes a list of object[] where each object[] is one of utkast, fraga/svar or arende represented as:
 *
 * [0] id (unique, this is what we want to count per enhetsId)
 * [1] enhetsId
 * [2] personnummer
 *
 * This method will filter out any items belonging to a patient having sekretessmarkering and return the result as a
 * map: EnhetsId -> number of id for that unit.
 *
 * @param groupableItems
 *            Each item is an array of: id, enhetsId, personnummer, intygsTyp.
 * @return
 *         Map with enhetsId -> count, with personummer being sekretessmarkerade has been removed.
 */
public Map<String, Long> toSekretessFilteredMap(List<GroupableItem> groupableItems) {
    if (groupableItems == null || groupableItems.size() == 0) {
        return new HashMap<>();
    }
    List<GroupableItem> filteredGroupableItems = getFilteredGroupableItemList(groupableItems);
    WebCertUser user = webCertUserService.getUser();
    Map<Personnummer, SekretessStatus> sekretessStatusMap = patientDetailsResolver.getSekretessStatusForList(getPersonummerList(filteredGroupableItems));
    // update sekretess status
    filteredGroupableItems.forEach(item -> item.setSekretessStatus(sekretessStatusMap.get(createPnr(item.getPersonnummer()))));
    return filteredGroupableItems.stream().filter(item -> item.getSekretessStatus() != SekretessStatus.UNDEFINED).filter(item -> authoritiesValidator.given(user, item.getIntygsTyp()).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, item.getSekretessStatus() == SekretessStatus.TRUE).isVerified()).collect(Collectors.groupingBy(GroupableItem::getEnhetsId, Collectors.counting()));
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) AuthoritiesValidator(se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) PatientDetailsResolver(se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) WebCertUserService(se.inera.intyg.webcert.web.service.user.WebCertUserService) Collectors(java.util.stream.Collectors) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) Component(org.springframework.stereotype.Component) List(java.util.List) Map(java.util.Map) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) AuthoritiesConstants(se.inera.intyg.infra.security.common.model.AuthoritiesConstants) GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) HashMap(java.util.HashMap) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 5 with GroupableItem

use of se.inera.intyg.webcert.common.model.GroupableItem in project webcert by sklintyg.

the class StatisticsGroupByUtilTest method testFilterAndGroupForThreeResultsOfSameUnitTwoIsSekrForOfWhichOneIsTS.

@Test
public void testFilterAndGroupForThreeResultsOfSameUnitTwoIsSekrForOfWhichOneIsTS() {
    when(webCertUserService.getUser()).thenReturn(createUser());
    List<GroupableItem> queryResult = new ArrayList<>();
    // No S. All can see.
    queryResult.add(new GroupableItem("id-1", HSA1, PNR1, FK7263));
    // Is S, LAKARE can see.
    queryResult.add(new GroupableItem("id-2", HSA1, PNR2, FK7263));
    // Should be OK
    queryResult.add(new GroupableItem("id-3", HSA1, PNR1, TSBAS));
    // Should be filtered away
    queryResult.add(new GroupableItem("id-4", HSA1, PNR2, TSBAS));
    Map<String, Long> result = testee.toSekretessFilteredMap(queryResult);
    assertEquals(1, result.size());
    assertEquals(new Long(3L), result.get(HSA1));
}
Also used : GroupableItem(se.inera.intyg.webcert.common.model.GroupableItem) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

GroupableItem (se.inera.intyg.webcert.common.model.GroupableItem)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1 Transactional (org.springframework.transaction.annotation.Transactional)1 AuthoritiesValidator (se.inera.intyg.infra.security.authorities.validation.AuthoritiesValidator)1 AuthoritiesConstants (se.inera.intyg.infra.security.common.model.AuthoritiesConstants)1 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)1 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)1 PatientDetailsResolver (se.inera.intyg.webcert.web.service.patient.PatientDetailsResolver)1 WebCertUserService (se.inera.intyg.webcert.web.service.user.WebCertUserService)1