Search in sources :

Example 56 with WebCertServiceException

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

the class SendMessageToCareResponderImpl method sendMessageToCare.

@Override
public SendMessageToCareResponseType sendMessageToCare(String logicalAddress, SendMessageToCareType request) {
    LOG.debug("Received new message to care");
    SendMessageToCareResponseType response = new SendMessageToCareResponseType();
    ResultType result = new ResultType();
    try {
        arendeService.processIncomingMessage(ArendeConverter.convert(request));
        result.setResultCode(ResultCodeType.OK);
    } catch (WebCertServiceException e) {
        result.setResultCode(ResultCodeType.ERROR);
        switch(e.getErrorCode()) {
            case INVALID_STATE:
            case DATA_NOT_FOUND:
            case EXTERNAL_SYSTEM_PROBLEM:
                result.setErrorId(ErrorIdType.VALIDATION_ERROR);
                result.setResultText(e.getMessage());
                LOG.warn("{}: {}", e.getErrorCode().name(), e.getMessage());
                break;
            default:
                result.setErrorId(ErrorIdType.APPLICATION_ERROR);
                result.setResultText(e.getMessage());
                LOG.error("Could not process incoming message to care. Cause is: {}", e.getMessage());
                break;
        }
    }
    response.setResult(result);
    return response;
}
Also used : SendMessageToCareResponseType(se.riv.clinicalprocess.healthcond.certificate.sendMessageToCare.v2.SendMessageToCareResponseType) ResultType(se.riv.clinicalprocess.healthcond.certificate.v3.ResultType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 57 with WebCertServiceException

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

the class IntygModuleApiController method createUtkastFromTemplate.

/**
 * Create a new utkast from a template.
 * <p>
 * Usually (but not necessarily) the template is of a different intygType than the new utkast.
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createUtkastFromTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) {
    validateCreateUtkastFromTemplateAuthority(newIntygsTyp);
    LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, 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 utkast from certificate '{}' as template is not valid", orgIntygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
    }
    CreateUtkastFromTemplateRequest serviceRequest = createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request);
    CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromTemplate(serviceRequest);
    LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, 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 58 with WebCertServiceException

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

the class UtkastModuleApiController method klientSigneraUtkast.

/**
 * Signera utkast.
 *
 * @param biljettId biljett id
 * @return BiljettResponse
 */
@POST
@Path("/{intygsTyp}/{biljettId}/signeraklient")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse klientSigneraUtkast(@PathParam("intygsTyp") String intygsTyp, @PathParam("biljettId") String biljettId, @Context HttpServletRequest request, byte[] rawSignatur) {
    verifyIsAuthorizedToSignIntyg(intygsTyp);
    LOG.debug("Signerar intyg med biljettId {}", biljettId);
    if (rawSignatur.length == 0) {
        LOG.error("Inkommande signatur parameter saknas");
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Signatur saknas");
    }
    String rawSignaturString = fromBytesToString(rawSignatur);
    SignaturTicket ticket;
    try {
        ticket = signaturService.clientSignature(biljettId, rawSignaturString);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        ticket = signaturService.ticketStatus(biljettId);
        monitoringLogService.logUtkastConcurrentlyEdited(ticket.getIntygsId(), intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
    return new SignaturTicketResponse(ticket);
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) SignaturTicketResponse(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 59 with WebCertServiceException

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

the class UtkastModuleApiController method getDraft.

/**
 * Returns the draft certificate as JSON identified by the intygId.
 *
 * @param intygsId The id of the certificate
 * @return a JSON object
 */
@GET
@Path("/{intygsTyp}/{intygsId}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getDraft(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @Context HttpServletRequest request) {
    LOG.debug("Retrieving Intyg with id {} and type {}", intygsId, intygsTyp);
    Utkast utkast = utkastService.getDraft(intygsId, intygsTyp);
    Patient resolvedPatient = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), intygsTyp);
    if (resolvedPatient == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Could not resolve Patient in PU-service when opening draft.");
    }
    authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST).privilege(AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG).orThrow();
    verifySekretessmarkering(intygsTyp, utkast.getEnhetsId(), resolvedPatient);
    request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
    DraftHolder draftHolder = new DraftHolder();
    draftHolder.setVersion(utkast.getVersion());
    draftHolder.setVidarebefordrad(utkast.getVidarebefordrad());
    draftHolder.setStatus(utkast.getStatus());
    draftHolder.setEnhetsNamn(utkast.getEnhetsNamn());
    draftHolder.setVardgivareNamn(utkast.getVardgivarNamn());
    draftHolder.setLatestTextVersion(intygTextsService.getLatestVersion(utkast.getIntygsTyp()));
    Relations relations1 = certificateRelationService.getRelations(utkast.getIntygsId());
    draftHolder.setRelations(relations1);
    draftHolder.setKlartForSigneringDatum(utkast.getKlartForSigneringDatum());
    draftHolder.setCreated(utkast.getSkapad());
    // The patientResolved is unnecessary?
    draftHolder.setPatientResolved(true);
    draftHolder.setSekretessmarkering(resolvedPatient.isSekretessmarkering());
    draftHolder.setAvliden(resolvedPatient.isAvliden());
    // Businesss logic below should not be here inside a controller.. Should preferably be moved in the future.
    try {
        try {
            Utlatande utlatande = moduleRegistry.getModuleApi(intygsTyp).getUtlatandeFromJson(utkast.getModel());
            draftHolder.setPatientNameChangedInPU(patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), resolvedPatient));
            draftHolder.setPatientAddressChangedInPU(patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), resolvedPatient));
        } catch (IOException e) {
            LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygsId);
        }
        if (!completeAddressProvided(resolvedPatient)) {
            // Overwrite retrieved address data with saved one.
            Patient oldPatientData = null;
            try {
                oldPatientData = moduleRegistry.getModuleApi(intygsTyp).getUtlatandeFromJson(utkast.getModel()).getGrundData().getPatient();
            } catch (IOException e) {
                LOG.error("Error while using the module api to convert json to Utlatande for intygsId {}", intygsId);
            }
            copyOldAddressToNewPatientData(oldPatientData, resolvedPatient);
        }
        // Update the internal model with the resolved patient. This means the draft may be updated
        // with new patient info on the next auto-save!
        String updatedModel = moduleRegistry.getModuleApi(intygsTyp).updateBeforeSave(utkast.getModel(), resolvedPatient);
        utkast.setModel(updatedModel);
        draftHolder.setContent(utkast.getModel());
        return Response.ok(draftHolder).build();
    } catch (ModuleException | ModuleNotFoundException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e.getMessage());
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) DraftHolder(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.DraftHolder) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 60 with WebCertServiceException

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

the class UtkastModuleApiController method serverSigneraUtkastMedGrp.

/**
 * Signera utkast mha Bank ID GRP API.
 *
 * @param intygsId intyg id
 * @return SignaturTicketResponse
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{version}/grp/signeraserver")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public SignaturTicketResponse serverSigneraUtkastMedGrp(@PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String intygsId, @PathParam("version") long version, @Context HttpServletRequest request) {
    verifyIsAuthorizedToSignIntyg(intygsTyp);
    SignaturTicket ticket;
    try {
        ticket = grpSignaturService.startGrpAuthentication(intygsId, version);
    } catch (OptimisticLockException | OptimisticLockingFailureException e) {
        monitoringLogService.logUtkastConcurrentlyEdited(intygsId, intygsTyp);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.CONCURRENT_MODIFICATION, e.getMessage());
    }
    request.getSession(true).removeAttribute(LAST_SAVED_DRAFT);
    return new SignaturTicketResponse(ticket);
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) OptimisticLockException(javax.persistence.OptimisticLockException) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) SignaturTicketResponse(se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) 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