Search in sources :

Example 1 with PrepareRedirectToIntyg

use of se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg in project webcert by sklintyg.

the class IntygIntegrationController method handleRedirectToIntyg.

Response handleRedirectToIntyg(UriInfo uriInfo, String intygTyp, String intygId, String enhetId, WebCertUser user) {
    try {
        // Call service
        PrepareRedirectToIntyg prepareRedirectInfo = integrationService.prepareRedirectToIntyg(intygTyp, intygId, user);
        // Persist reference
        handleReference(intygId, user.getParameters().getReference());
        if (Strings.nullToEmpty(enhetId).trim().isEmpty()) {
            if (userHasExactlyOneSelectableVardenhet(user)) {
                user.changeValdVardenhet(user.getVardgivare().get(0).getVardenheter().get(0).getId());
                updateUserWithActiveFeatures(user);
                LOG.debug("Redirecting to view intyg {} of type {}", intygId, intygTyp);
                return buildRedirectResponse(uriInfo, prepareRedirectInfo);
            }
            // Set state parameter telling us that we have been redirected to 'enhetsvaljaren'
            user.getParameters().getState().setRedirectToEnhetsval(true);
            LOG.warn("Deep integration request does not contain an 'enhet', redirecting to enhet selection page!");
            return buildChooseUnitResponse(uriInfo, prepareRedirectInfo);
        } else {
            if (user.changeValdVardenhet(enhetId)) {
                updateUserWithActiveFeatures(user);
                LOG.debug("Redirecting to view intyg {} of type {}", intygId, intygTyp);
                return buildRedirectResponse(uriInfo, prepareRedirectInfo);
            }
            LOG.warn("Validation failed for deep-integration request because user {} is not authorized for enhet {}", user.getHsaId(), enhetId);
            return buildAuthorizedErrorResponse(uriInfo);
        }
    } catch (WebCertServiceException e) {
        if (e.getErrorCode().equals(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND)) {
            LOG.error(e.getMessage());
            return buildNoContentErrorResponse(uriInfo);
        } else {
            throw e;
        }
    }
}
Also used : PrepareRedirectToIntyg(se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 2 with PrepareRedirectToIntyg

use of se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg in project webcert by sklintyg.

the class ViewIntegrationController method handleRedirectToIntyg.

// private stuff
private Response handleRedirectToIntyg(UriInfo uriInfo, String intygId, String enhetId, WebCertUser user) {
    // Call service
    PrepareRedirectToIntyg prepareRedirectToIntyg = integrationService.prepareRedirectToIntyg(null, intygId, user);
    // Update user with health care unit
    boolean isUpdated = user.changeValdVardenhet(enhetId);
    if (!isUpdated) {
        LOG.warn("Validation failed for request because user {} is not authorized for enhet {}", user.getHsaId(), enhetId);
        return buildErrorResponse(uriInfo);
    }
    // Update user with current active features
    updateUserWithActiveFeatures(user);
    LOG.debug("Redirecting to view intyg {} of type {}", prepareRedirectToIntyg.getIntygId(), prepareRedirectToIntyg.getIntygTyp());
    return buildRedirectResponse(uriInfo, prepareRedirectToIntyg);
}
Also used : PrepareRedirectToIntyg(se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg)

Example 3 with PrepareRedirectToIntyg

use of se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg in project webcert by sklintyg.

the class IntygIntegrationControllerTest method createPrepareRedirectToIntyg.

private PrepareRedirectToIntyg createPrepareRedirectToIntyg() {
    PrepareRedirectToIntyg redirect = new PrepareRedirectToIntyg();
    redirect.setIntygId(INTYGSID);
    redirect.setIntygTyp(INTYGSTYP);
    redirect.setUtkast(true);
    return redirect;
}
Also used : PrepareRedirectToIntyg(se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg)

Example 4 with PrepareRedirectToIntyg

use of se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg in project webcert by sklintyg.

the class IntygIntegrationServiceImplTest method prepareRedirectToIntygSuccess.

@Test
public void prepareRedirectToIntygSuccess() {
    // given
    when(utkastRepository.findOne(anyString())).thenReturn(createUtkast());
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.FALSE);
    IntegrationParameters parameters = new IntegrationParameters(null, null, ALTERNATE_SSN, "Nollan", null, "Nollansson", "Nollgatan", "000000", "Nollby", false, false, false, false);
    WebCertUser user = createDefaultUser();
    user.setParameters(parameters);
    // when
    PrepareRedirectToIntyg prepareRedirectToIntyg = testee.prepareRedirectToIntyg(INTYGSTYP, INTYGSID, user);
    // then
    verify(utkastRepository).findOne(anyString());
    verify(patientDetailsResolver).getSekretessStatus(any(Personnummer.class));
    assertEquals(INTYGSTYP, prepareRedirectToIntyg.getIntygTyp());
    assertEquals(INTYGSID, prepareRedirectToIntyg.getIntygId());
    assertTrue(prepareRedirectToIntyg.isUtkast());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) PrepareRedirectToIntyg(se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 5 with PrepareRedirectToIntyg

use of se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg in project webcert by sklintyg.

the class IntygIntegrationServiceImplTest method userIsAuthorizedToHandleSekretessmarkeradPatient.

@Test
public void userIsAuthorizedToHandleSekretessmarkeradPatient() {
    // given
    when(utkastRepository.findOne(anyString())).thenReturn(createUtkast());
    when(patientDetailsResolver.getSekretessStatus(any(Personnummer.class))).thenReturn(SekretessStatus.TRUE);
    IntegrationParameters parameters = new IntegrationParameters(null, null, ALTERNATE_SSN, "Nollan", null, "Nollansson", "Nollgatan", "000000", "Nollby", false, false, false, false);
    Privilege p = createPrivilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, // p1 is restricted to these intygstyper
    Arrays.asList("lisjp", "ts-bas"), Arrays.asList(createRequestOrigin(UserOriginType.DJUPINTEGRATION.name(), Arrays.asList("lisjp")), createRequestOrigin(UserOriginType.DJUPINTEGRATION.name(), Arrays.asList("ts-bas"))));
    WebCertUser user = createDefaultUser();
    user.setParameters(parameters);
    user.getAuthorities().put(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, p);
    // when
    PrepareRedirectToIntyg prepareRedirectToIntyg = testee.prepareRedirectToIntyg(INTYGSTYP, INTYGSID, user);
    // then
    verify(utkastRepository).findOne(anyString());
    verify(patientDetailsResolver).getSekretessStatus(any(Personnummer.class));
    assertEquals(INTYGSTYP, prepareRedirectToIntyg.getIntygTyp());
    assertEquals(INTYGSID, prepareRedirectToIntyg.getIntygId());
    assertTrue(prepareRedirectToIntyg.isUtkast());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) PrepareRedirectToIntyg(se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg) Privilege(se.inera.intyg.infra.security.common.model.Privilege) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

PrepareRedirectToIntyg (se.inera.intyg.webcert.web.web.controller.integration.dto.PrepareRedirectToIntyg)6 Test (org.junit.Test)2 Personnummer (se.inera.intyg.schemas.contract.Personnummer)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)2 Privilege (se.inera.intyg.infra.security.common.model.Privilege)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1