Search in sources :

Example 21 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class UtkastServiceImpl method deleteUnsignedDraft.

@Override
@Transactional
public void deleteUnsignedDraft(String intygId, long version) {
    LOG.debug("Deleting utkast '{}'", intygId);
    Utkast utkast = utkastRepository.findOne(intygId);
    // check that the draft exists
    if (utkast == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The draft could not be deleted since it could not be found");
    }
    // check that the draft hasn't been modified concurrently
    if (utkast.getVersion() != version) {
        LOG.debug("Utkast '{}' was concurrently modified", intygId);
        throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
    }
    // check that the draft is still unsigned
    if (!isTheDraftStillADraft(utkast.getStatus())) {
        LOG.error("Intyg '{}' can not be deleted since it is no longer a draft", intygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "The draft can not be deleted since it is no longer a draft");
    }
    // Delete draft from repository
    utkastRepository.delete(utkast);
    LOG.debug("Deleted draft '{}'", utkast.getIntygsId());
    // Audit log
    monitoringService.logUtkastDeleted(utkast.getIntygsId(), utkast.getIntygsTyp());
    // Notify stakeholders when a draft is deleted
    sendNotification(utkast, Event.DELETED);
    LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
    logService.logDeleteIntyg(logRequest);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class UtkastServiceImpl method setNotifiedOnDraft.

@Override
@Transactional
public Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified) {
    Utkast utkast = utkastRepository.findOne(intygsId);
    if (utkast == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find Utkast with id: " + intygsId);
    }
    // check that the draft hasn't been modified concurrently
    if (utkast.getVersion() != version) {
        LOG.debug("Utkast '{}' was concurrently modified", intygsId);
        throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
    }
    utkast.setVidarebefordrad(notified);
    return saveDraft(utkast);
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class UtkastServiceImpl method getIntygAsDraft.

private Utkast getIntygAsDraft(String intygsId, String intygType) {
    LOG.debug("Fetching utkast '{}'", intygsId);
    Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygsId, intygType);
    if (utkast == null) {
        LOG.warn("Utkast '{}' of type {} was not found", intygsId, intygType);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Utkast could not be found");
    }
    return utkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 24 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class UtkastServiceImpl method validateDraft.

@Override
public DraftValidation validateDraft(String intygId, String intygType, String draftAsJson) {
    LOG.debug("Validating Intyg '{}' with type '{}'", intygId, intygType);
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        ValidateDraftResponse validateDraftResponse = moduleApi.validateDraft(draftAsJson);
        return convertToDraftValidation(validateDraftResponse);
    } catch (ModuleException | ModuleNotFoundException me) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 25 with WebCertServiceException

use of se.inera.intyg.webcert.common.service.exception.WebCertServiceException in project webcert by sklintyg.

the class UtkastApiController method createUtkast.

/**
 * Create a new draft.
 */
@POST
@Path("/{intygsTyp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createUtkast(@PathParam("intygsTyp") String intygsTyp, CreateUtkastRequest request) {
    try {
        if (moduleRegistry.getIntygModule(intygsTyp).isDeprecated()) {
            LOG.error("Request for deprecated module {}", intygsTyp);
            return Response.status(Status.BAD_REQUEST).build();
        }
    } catch (ModuleNotFoundException e) {
        LOG.error("Request for unknown module {}", intygsTyp);
        return Response.status(Status.BAD_REQUEST).build();
    }
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(request.getPatientPersonnummer());
    if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not fetch sekretesstatus for patient from PU service");
    }
    // INTYG-4086: If the patient is sekretessmarkerad, we need an additional check.
    boolean sekr = sekretessStatus == SekretessStatus.TRUE;
    if (sekr) {
        authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).privilege(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User missing required privilege or cannot handle sekretessmarkerad patient"));
    }
    if (!request.isValid()) {
        LOG.error("Request is invalid: " + request.toString());
        return Response.status(Status.BAD_REQUEST).build();
    }
    LOG.debug("Attempting to create draft of type '{}'", intygsTyp);
    if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
        Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(request.getPatientPersonnummer(), getWebCertUserService().getUser());
        Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
        Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
        if (utkastExists != null && utkastExists) {
            if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
        if (intygExists != null) {
            if (authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
                return Response.status(Status.BAD_REQUEST).build();
            } else if (intygExists && authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
    }
    CreateNewDraftRequest serviceRequest = createServiceRequest(request);
    Utkast utkast = utkastService.createNewDraft(serviceRequest);
    LOG.debug("Created a new draft of type '{}' with id '{}'", intygsTyp, utkast.getIntygsId());
    return Response.ok().entity(utkast).build();
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CreateNewDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)85 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)35 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)16 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)14 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)14 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)13 OptimisticLockException (javax.persistence.OptimisticLockException)12 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)10 SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)10 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)9 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)7 Transactional (org.springframework.transaction.annotation.Transactional)7 POST (javax.ws.rs.POST)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)6 LocalDateTime (java.time.LocalDateTime)5