Search in sources :

Example 36 with WebCertServiceException

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

the class FragaSvarServiceImpl method saveSvar.

@Override
public FragaSvar saveSvar(Long fragaSvarsId, String svarsText) {
    // Input sanity check
    if (Strings.isNullOrEmpty(svarsText)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "SvarsText cannot be empty!");
    }
    // Look up entity in repository
    FragaSvar fragaSvar = lookupFragaSvar(fragaSvarsId);
    // Is user authorized to save an answer to this question?
    verifyEnhetsAuth(fragaSvar.getVardperson().getEnhetsId(), false);
    if (!fragaSvar.getStatus().equals(Status.PENDING_INTERNAL_ACTION)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid state for saving answer(" + fragaSvar.getStatus() + ")");
    }
    // Implement Business Rule FS-007
    if (Amne.PAMINNELSE.equals(fragaSvar.getAmne())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer");
    }
    if (Amne.KOMPLETTERING_AV_LAKARINTYG.equals(fragaSvar.getAmne())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FragaSvar with id " + fragaSvar.getInternReferens().toString() + " has invalid Amne(" + fragaSvar.getAmne() + ") for saving answer");
    }
    LocalDateTime now = LocalDateTime.now();
    WebCertUser user = webCertUserService.getUser();
    // Ok, lets save the answer
    fragaSvar.setVardAktorHsaId(user.getHsaId());
    fragaSvar.setVardAktorNamn(user.getNamn());
    fragaSvar.setSvarsText(svarsText);
    fragaSvar.setSvarSkickadDatum(now);
    fragaSvar.setStatus(Status.CLOSED);
    fragaSvar.setSvarSigneringsDatum(now);
    FragaSvar saved = fragaSvarRepository.save(fragaSvar);
    sendFragaSvarToExternalParty(saved);
    arendeDraftService.delete(fragaSvar.getIntygsReferens().getIntygsId(), Long.toString(fragaSvar.getInternReferens()));
    return saved;
}
Also used : LocalDateTime(java.time.LocalDateTime) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 37 with WebCertServiceException

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

the class FragaSvarServiceImpl method saveNewQuestion.

@Override
public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) {
    // Argument check
    if (Strings.isNullOrEmpty(frageText)) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!");
    }
    if (amne == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!");
    } else if (!VALID_VARD_AMNEN.contains(amne)) {
        // Businessrule RE-013
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
    }
    // Fetch from Intygstjansten. Note that if Intygstjansten is unresponsive, the Intyg will be loaded from WebCert
    // if possible.
    IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false);
    WebCertUser user = webCertUserService.getUser();
    // Get vardperson that posed the question
    // Is user authorized to save an answer to this question?
    verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false);
    // Verksamhetsregel FS-001 (Is the certificate sent to FK)
    if (!isCertificateSentToFK(intyg.getStatuses())) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!");
    }
    // Verify that certificate is not revoked
    if (intyg.isRevoked()) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!");
    }
    IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande());
    HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null);
    Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal);
    FragaSvar fraga = new FragaSvar();
    fraga.setFrageStallare(FrageStallare.WEBCERT.getKod());
    fraga.setAmne(amne);
    fraga.setFrageText(frageText);
    LocalDateTime now = LocalDateTime.now();
    fraga.setFrageSkickadDatum(now);
    fraga.setFrageSigneringsDatum(now);
    fraga.setIntygsReferens(intygsReferens);
    fraga.setVardperson(vardPerson);
    fraga.setStatus(Status.PENDING_EXTERNAL_ACTION);
    fraga.setVardAktorHsaId(user.getHsaId());
    fraga.setVardAktorNamn(user.getNamn());
    // Ok, lets save the question
    FragaSvar saved = fragaSvarRepository.save(fraga);
    // Send to external party (FK)
    SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType();
    QuestionToFkType question = FKQuestionConverter.convert(saved);
    // Remove ASAP.
    if ("true".equalsIgnoreCase(forceFullstandigtNamn)) {
        question.getLakarutlatande().getPatient().setFullstandigtNamn("---");
    }
    sendType.setQuestion(question);
    AttributedURIType logicalAddress = new AttributedURIType();
    logicalAddress.setValue(sendQuestionToFkLogicalAddress);
    SendMedicalCertificateQuestionResponseType response;
    try {
        response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType);
    } catch (SOAPFaultException e) {
        LOGGER.error("Failed to send question to FK, error was: " + e.getMessage());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage());
    }
    if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) {
        LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString());
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult().getErrorText());
    }
    monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardAktorHsaId(), saved.getAmne());
    // Notify stakeholders
    sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE);
    arendeDraftService.delete(intygId, null);
    return saved;
}
Also used : Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) LocalDateTime(java.time.LocalDateTime) AttributedURIType(org.w3.wsaddressing10.AttributedURIType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) QuestionToFkType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.QuestionToFkType) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) SendMedicalCertificateQuestionType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionType) SendMedicalCertificateQuestionResponseType(se.inera.ifv.insuranceprocess.healthreporting.sendmedicalcertificatequestionresponder.v1.SendMedicalCertificateQuestionResponseType) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 38 with WebCertServiceException

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

the class FragaSvarServiceImpl method validateSekretessmarkering.

/**
 * If there is at least one fragaSvar in the response, we fetch the personId and check for sekretessmarkering.
 */
private void validateSekretessmarkering(String intygsId, List<FragaSvar> fragaSvarList, WebCertUser user) {
    if (fragaSvarList.size() > 0) {
        Personnummer pnr = fragaSvarList.get(0).getIntygsReferens().getPatientId();
        String intygsTyp = fragaSvarList.get(0).getIntygsReferens().getIntygsTyp();
        SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(pnr);
        if (sekretessStatus == SekretessStatus.UNDEFINED) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Cannot list fraga/svar for '" + intygsId + "'. PU service unavailable or personnummer " + pnr.getPersonnummerHash() + " not valid");
        }
        authoritiesValidator.given(user, intygsTyp).privilegeIf(AuthoritiesConstants.PRIVILEGE_HANTERA_SEKRETESSMARKERAD_PATIENT, sekretessStatus == SekretessStatus.TRUE).orThrow(new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM_SEKRETESSMARKERING, "User is not allowed to handle sekretessmarkerad patient"));
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 39 with WebCertServiceException

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

the class IntygServiceImpl method revokeIntyg.

/*
     * (non-Javadoc)
     *
     * @see se.inera.intyg.webcert.web.service.intyg.IntygService#revokeIntyg(java.lang.String, java.lang.String)
     */
@Override
public IntygServiceResult revokeIntyg(String intygsId, String intygsTyp, String revokeMessage, String reason) {
    LOG.debug("Attempting to revoke intyg {}", intygsId);
    IntygContentHolder intyg = getIntygData(intygsId, intygsTyp, false);
    verifyEnhetsAuth(intyg.getUtlatande(), true);
    verifyIsSigned(intyg.getStatuses());
    if (intyg.isRevoked()) {
        LOG.debug("Certificate with id '{}' is already revoked", intygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificate is already revoked");
    }
    try {
        certificateSenderService.revokeCertificate(intygsId, modelFacade.getRevokeCertificateRequest(intygsTyp, intyg.getUtlatande(), IntygConverterUtil.buildHosPersonalFromWebCertUser(webCertUserService.getUser(), null), revokeMessage), intygsTyp);
        whenSuccessfulRevoke(intyg.getUtlatande(), reason);
        return IntygServiceResult.OK;
    } catch (CertificateSenderException | ModuleException | IntygModuleFacadeException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.UNKNOWN_INTERNAL_PROBLEM, e.getMessage());
    }
}
Also used : IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) CertificateSenderException(se.inera.intyg.webcert.web.service.certificatesender.CertificateSenderException)

Example 40 with WebCertServiceException

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

the class IntygServiceImpl method fetchIntygAsPdf.

@Override
public IntygPdf fetchIntygAsPdf(String intygsId, String intygsTyp, boolean isEmployer) {
    try {
        LOG.debug("Fetching intyg '{}' as PDF", intygsId);
        IntygContentHolder intyg = getIntygDataPreferWebcert(intygsId, intygsTyp);
        // 
        verifyPuServiceAvailable(intyg);
        boolean coherentJournaling = userIsDjupintegreradWithSjf();
        if (!coherentJournaling) {
            verifyEnhetsAuth(intyg.getUtlatande(), true);
        }
        IntygPdf intygPdf = modelFacade.convertFromInternalToPdfDocument(intygsTyp, intyg.getContents(), intyg.getStatuses(), isEmployer);
        // Log print as PDF to PDL log
        logPdfPrinting(intyg, coherentJournaling);
        return intygPdf;
    } catch (IntygModuleFacadeException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

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