use of se.inera.intyg.webcert.web.web.controller.moduleapi.dto.StatsResponse in project webcert by sklintyg.
the class StatModuleApiController method getStatistics.
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getStatistics() {
StatsResponse statsResponse = new StatsResponse();
WebCertUser user = getWebCertUserService().getUser();
if (user == null) {
LOG.warn("getStatistics was called, but webcertUser was null!");
return Response.ok(statsResponse).build();
} else if (UserOriginType.DJUPINTEGRATION.name().equals(user.getOrigin())) {
LOG.debug("getStatistics was called, but webcertUser origin is DJUPINTEGRATION - returning empty answer");
return Response.ok(statsResponse).build();
}
List<String> allUnitIds = user.getIdsOfAllVardenheter();
if (allUnitIds == null || allUnitIds.isEmpty()) {
LOG.warn("getStatistics was called by user {} that have no id:s of vardenheter present in the user context: {}", user.getHsaId(), user.getAsJson());
return Response.ok(statsResponse).build();
}
Set<String> intygsTyper = authoritiesHelper.getIntygstyperForPrivilege(user, AuthoritiesConstants.PRIVILEGE_VISA_INTYG);
Map<String, Long> fragaSvarStatsMap = fragaSvarService.getNbrOfUnhandledFragaSvarForCareUnits(allUnitIds, intygsTyper);
Map<String, Long> arendeStatsMap = arendeService.getNbrOfUnhandledArendenForCareUnits(allUnitIds, intygsTyper);
Map<String, Long> mergedMap = mergeArendeAndFragaSvarMaps(fragaSvarStatsMap, arendeStatsMap);
Map<String, Long> intygStatsMap = intygDraftService.getNbrOfUnsignedDraftsByCareUnits(allUnitIds);
List<String> unitIdsOfSelected = user.getIdsOfSelectedVardenhet();
List<String> unitIdsOfNotSelected = new ArrayList<>(allUnitIds);
unitIdsOfNotSelected.removeAll(unitIdsOfSelected);
long fragaSvarOnOtherUnitThanTheSelected = calcSumFromSelectedUnits(unitIdsOfNotSelected, mergedMap);
statsResponse.setTotalNbrOfUnhandledFragaSvarOnOtherThanSelected(fragaSvarOnOtherUnitThanTheSelected);
long fragaSvarOnSelected = calcSumFromSelectedUnits(unitIdsOfSelected, mergedMap);
statsResponse.setTotalNbrOfUnhandledFragaSvarOnSelected(fragaSvarOnSelected);
long unsignedDraftsOnOtherThanSelected = calcSumFromSelectedUnits(unitIdsOfNotSelected, intygStatsMap);
statsResponse.setTotalNbrOfUnsignedDraftsOnOtherThanSelected(unsignedDraftsOnOtherThanSelected);
long unsignedDraftsOnSelected = getSafeStatValueFromMap(user.getValdVardenhet().getId(), intygStatsMap);
statsResponse.setTotalNbrOfUnsignedDraftsOnSelected(unsignedDraftsOnSelected);
populateStatsResponseWithVardgivarStats(statsResponse, user.getVardgivare(), intygStatsMap, mergedMap);
return Response.ok(statsResponse).build();
}
use of se.inera.intyg.webcert.web.web.controller.moduleapi.dto.StatsResponse in project webcert by sklintyg.
the class StatModuleApiControllerTest method testWebcertUserIsDjupintegrerad.
@Test
public void testWebcertUserIsDjupintegrerad() {
mockUser.setOrigin(UserOriginType.DJUPINTEGRATION.name());
Response response = statController.getStatistics();
assertNotNull(response);
verify(webCertUserService).getUser();
verifyZeroInteractions(authoritiesHelper);
verifyZeroInteractions(fragaSvarService);
verifyZeroInteractions(arendeService);
verifyZeroInteractions(intygDraftService);
assertEquals(OK, response.getStatus());
StatsResponse statsResponse = (StatsResponse) response.getEntity();
assertNotNull(statsResponse);
assertEquals(0, statsResponse.getTotalNbrOfUnhandledFragaSvarOnSelected());
assertEquals(0, statsResponse.getTotalNbrOfUnhandledFragaSvarOnOtherThanSelected());
assertEquals(0, statsResponse.getTotalNbrOfUnsignedDraftsOnSelected());
assertEquals(0, statsResponse.getTotalNbrOfUnsignedDraftsOnOtherThanSelected());
}
use of se.inera.intyg.webcert.web.web.controller.moduleapi.dto.StatsResponse in project webcert by sklintyg.
the class StatModuleApiControllerTest method testGetStatisticsWithSelectedUnitVE1.
@Test
public void testGetStatisticsWithSelectedUnitVE1() {
mockUser.setValdVardenhet(ve1);
when(fragaSvarService.getNbrOfUnhandledFragaSvarForCareUnits(anyList(), anySet())).thenReturn(fragaSvarStatsMap);
when(arendeService.getNbrOfUnhandledArendenForCareUnits(anyList(), anySet())).thenReturn(arendeStatsMap);
when(intygDraftService.getNbrOfUnsignedDraftsByCareUnits(anyList())).thenReturn(intygStatsMap);
Response response = statController.getStatistics();
verify(webCertUserService).getUser();
verify(fragaSvarService).getNbrOfUnhandledFragaSvarForCareUnits(listCaptor.capture(), intygsTypSetCaptor.capture());
List<String> listArgs = listCaptor.getValue();
assertEquals(7, listArgs.size());
assertNotNull(response);
assertEquals(OK, response.getStatus());
StatsResponse statsResponse = (StatsResponse) response.getEntity();
assertNotNull(statsResponse);
assertEquals(16, statsResponse.getTotalNbrOfUnhandledFragaSvarOnSelected());
assertEquals(6, statsResponse.getTotalNbrOfUnhandledFragaSvarOnOtherThanSelected());
assertEquals(0, statsResponse.getTotalNbrOfUnsignedDraftsOnSelected());
assertEquals(2, statsResponse.getTotalNbrOfUnsignedDraftsOnOtherThanSelected());
StatsResponse refStatsResponse = getReference("StatModuleApiControllerTest/reference.json");
assertEquals(refStatsResponse.toString(), statsResponse.toString());
}
use of se.inera.intyg.webcert.web.web.controller.moduleapi.dto.StatsResponse in project webcert by sklintyg.
the class StatModuleApiControllerTest method testGetStatisticsWithSelectedUnitVE2.
@Test
public void testGetStatisticsWithSelectedUnitVE2() {
mockUser.setValdVardenhet(ve2);
when(fragaSvarService.getNbrOfUnhandledFragaSvarForCareUnits(anyList(), anySet())).thenReturn(fragaSvarStatsMap);
when(arendeService.getNbrOfUnhandledArendenForCareUnits(anyList(), anySet())).thenReturn(arendeStatsMap);
when(intygDraftService.getNbrOfUnsignedDraftsByCareUnits(anyList())).thenReturn(intygStatsMap);
Response response = statController.getStatistics();
assertNotNull(response);
assertEquals(OK, response.getStatus());
StatsResponse statsResponse = (StatsResponse) response.getEntity();
assertNotNull(statsResponse);
assertEquals(4, statsResponse.getTotalNbrOfUnhandledFragaSvarOnSelected());
assertEquals(18, statsResponse.getTotalNbrOfUnhandledFragaSvarOnOtherThanSelected());
assertEquals(2, statsResponse.getTotalNbrOfUnsignedDraftsOnSelected());
assertEquals(3, statsResponse.getTotalNbrOfUnsignedDraftsOnOtherThanSelected());
}
use of se.inera.intyg.webcert.web.web.controller.moduleapi.dto.StatsResponse in project webcert by sklintyg.
the class StatModuleApiControllerTest method testGetStatisticsWithSelectedUnitVE3.
@Test
public void testGetStatisticsWithSelectedUnitVE3() {
mockUser.setValdVardenhet(ve3);
when(fragaSvarService.getNbrOfUnhandledFragaSvarForCareUnits(anyList(), anySet())).thenReturn(fragaSvarStatsMap);
when(arendeService.getNbrOfUnhandledArendenForCareUnits(anyList(), anySet())).thenReturn(arendeStatsMap);
when(intygDraftService.getNbrOfUnsignedDraftsByCareUnits(anyList())).thenReturn(intygStatsMap);
Response response = statController.getStatistics();
assertNotNull(response);
assertEquals(OK, response.getStatus());
StatsResponse statsResponse = (StatsResponse) response.getEntity();
assertNotNull(statsResponse);
assertEquals(2, statsResponse.getTotalNbrOfUnhandledFragaSvarOnSelected());
assertEquals(20, statsResponse.getTotalNbrOfUnhandledFragaSvarOnOtherThanSelected());
assertEquals(0, statsResponse.getTotalNbrOfUnsignedDraftsOnSelected());
assertEquals(5, statsResponse.getTotalNbrOfUnsignedDraftsOnOtherThanSelected());
}
Aggregations