Search in sources :

Example 31 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class FragaSvarResource method getWebCertUser.

// Create a fake WebCertUser which is authorized for the given care giver and unit
private WebCertUser getWebCertUser(String vardgivarId, String enhetsId) {
    WebCertUser user = new WebCertUser();
    Role role = authoritiesResolver.getRole(AuthoritiesConstants.ROLE_LAKARE);
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setAuthorities(AuthoritiesResolverUtil.toMap(role.getPrivileges(), Privilege::getName));
    user.setHsaId("questionResource");
    user.setNamn("questionResource");
    user.setForskrivarkod("questionResource");
    List<Vardgivare> vardgivarList = new ArrayList<>();
    Vardgivare vardgivare = new Vardgivare(vardgivarId, "questionResource");
    List<Vardenhet> vardenheter = new ArrayList<>();
    Vardenhet enhet = new Vardenhet(enhetsId, "questionResource");
    vardenheter.add(enhet);
    vardgivare.setVardenheter(vardenheter);
    vardgivarList.add(vardgivare);
    user.setVardgivare(vardgivarList);
    user.setValdVardgivare(vardgivare);
    user.setValdVardenhet(enhet);
    return user;
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) ArrayList(java.util.ArrayList) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Vardenhet(se.inera.intyg.infra.integration.hsa.model.Vardenhet) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 32 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class WebcertLoggingSessionRegistryImplTest method testRemoveSessionInformation.

@Test
public void testRemoveSessionInformation() throws Exception {
    final String sessionId = "session-id";
    final String hsaId = "hsa-id";
    final String authenticationScheme = "authenticationScheme";
    final String origin = "origin";
    WebCertUser principal = mock(WebCertUser.class);
    when(principal.getHsaId()).thenReturn(hsaId);
    when(principal.getAuthenticationScheme()).thenReturn(authenticationScheme);
    when(principal.getOrigin()).thenReturn(origin);
    loggingSessionRegistry.registerNewSession(sessionId, principal);
    loggingSessionRegistry.removeSessionInformation(sessionId);
    verify(monitoringService).logUserLogout(hsaId, authenticationScheme);
}
Also used : WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 33 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class IntygModuleApiController method createReplacementCopyRequest.

private CreateReplacementCopyRequest createReplacementCopyRequest(String orgIntygsId, String intygsTyp, CopyIntygRequest request) {
    HoSPersonal hosPerson = createHoSPersonFromUser();
    Patient patient = createPatientFromCopyIntygRequest(request);
    final WebCertUser user = userService.getUser();
    IntegrationParameters parameters = user.getParameters();
    boolean coherentJournaling = parameters != null && parameters.isSjf();
    CreateReplacementCopyRequest req = new CreateReplacementCopyRequest(orgIntygsId, intygsTyp, patient, hosPerson, coherentJournaling);
    // Add new personnummer to request
    addPersonnummerToRequest(req, parameters);
    // Set djupintegrerad flag on request to true if origin is DJUPINTEGRATION
    setDeepIntegrationFlagOnRequest(req);
    return req;
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) Patient(se.inera.intyg.common.support.model.common.internal.Patient) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 34 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.

the class IntygModuleApiController method createRenewal.

/**
 * Create a copy that is a renewal of an existing certificate.
 *
 * @param request
 * @param intygsTyp
 * @param orgIntygsId
 * @return
 */
@POST
@Path("/{intygsTyp}/{intygsId}/fornya")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createRenewal(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
    validateCopyAuthority(intygsTyp);
    LOG.debug("Attempting to create a renewal of {} with id '{}'", intygsTyp, orgIntygsId);
    WebCertUser user = userService.getUser();
    boolean copyOkParam = user.getParameters() == null || user.getParameters().isCopyOk();
    if (!copyOkParam) {
        LOG.info("User is not allowed to request a copy for id '{}' due to false kopieraOK-parameter", orgIntygsId);
        final String message = "Authorization failed due to false kopieraOK-parameter";
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, message);
    }
    if (!request.isValid()) {
        LOG.error("Request to create renewal of '{}' is not valid", orgIntygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
    }
    CreateRenewalCopyRequest serviceRequest = createRenewalCopyRequest(orgIntygsId, intygsTyp, request);
    CreateRenewalCopyResponse serviceResponse = copyUtkastService.createRenewalCopy(serviceRequest);
    LOG.debug("Created a new draft with id: '{}' and type: {}, renewing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
    CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
    return Response.ok().entity(response).build();
}
Also used : CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 35 with WebCertUser

use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser 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();
}
Also used : StatsResponse(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.StatsResponse) ArrayList(java.util.ArrayList) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)217 Test (org.junit.Test)123 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)31 Personnummer (se.inera.intyg.schemas.contract.Personnummer)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)23 Role (se.inera.intyg.infra.security.common.model.Role)18 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)16 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)15 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)15 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 Vardenhet (se.inera.intyg.infra.integration.hsa.model.Vardenhet)14 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)14 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)13 Feature (se.inera.intyg.infra.security.common.model.Feature)13 HashMap (java.util.HashMap)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Path (javax.ws.rs.Path)10