Search in sources :

Example 31 with WebCertServiceException

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

the class FragestallareConverterUtil method partToFrageStallarKod.

public static String partToFrageStallarKod(String partCode) {
    try {
        PartToFragestallare partToFragestallare = PartToFragestallare.valueOf(partCode);
        FrageStallare ret = FrageStallare.getByKod(partToFragestallare.fragestallarKod);
        return ret.getKod();
    } catch (IllegalArgumentException ie) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid PartCode found when converting Arende");
    }
}
Also used : FrageStallare(se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 32 with WebCertServiceException

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

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Utlatande utkastsParams = parameters.getUtlatande();
    // Redo this: Build a full Vårdgivare -> Vårdenhet -> Mottagning tree and then check.
    String invokingUserHsaId = utkastsParams.getSkapadAv().getPersonalId().getExtension();
    String invokingUnitHsaId = utkastsParams.getSkapadAv().getEnhet().getEnhetsId().getExtension();
    IntygUser user;
    try {
        user = webcertUserDetailsService.loadUserByHsaId(invokingUserHsaId);
    } catch (Exception e) {
        return createMIUErrorResponse(utkastsParams);
    }
    // Validate draft parameters
    ResultValidator resultsValidator = validator.validate(utkastsParams);
    if (resultsValidator.hasErrors()) {
        return createValidationErrorResponse(resultsValidator);
    }
    ResultValidator appErrorsValidator = validator.validateApplicationErrors(utkastsParams, user);
    if (appErrorsValidator.hasErrors()) {
        return createApplicationErrorResponse(appErrorsValidator);
    }
    LOG.debug("Creating draft for invoker '{}' on unit '{}'", invokingUserHsaId, invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!checkMIU(user, invokingUnitHsaId)) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = utkastsParams.getTypAvUtlatande().getCode().toLowerCase();
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft reques"));
    final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp + " kan inte utfärdas för patienter med sekretessmarkering", ErrorIdType.APPLICATION_ERROR);
    }
    Map<String, Map<String, Boolean>> intygstypToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
    String uniqueErrorString = AuthoritiesHelperUtil.validateMustBeUnique(user, intygsTyp, intygstypToBoolean);
    if (!uniqueErrorString.isEmpty()) {
        return createErrorResponse(uniqueErrorString, ErrorIdType.APPLICATION_ERROR);
    }
    if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_TAK_KONTROLL).isVerified()) {
        // Check if invoking health care unit has required TAK
        SchemaVersion schemaVersion = integreradeEnheterRegistry.getSchemaVersion(invokingUnitHsaId, intygsTyp).orElse(SchemaVersion.VERSION_1);
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, schemaVersion, user);
        if (!takResult.isValid()) {
            String error = Joiner.on("; ").join(takResult.getErrorMessages());
            return createErrorResponse(error, ErrorIdType.APPLICATION_ERROR);
        }
    }
    // Create the draft
    Utkast utkast = createNewDraft(utkastsParams, user);
    return createSuccessResponse(utkast.getIntygsId());
}
Also used : SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) SchemaVersion(se.inera.intyg.common.support.modules.support.api.notification.SchemaVersion) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v1.Utlatande) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Map(java.util.Map)

Example 33 with WebCertServiceException

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

the class CreateDraftCertificateResponderImpl method createDraftCertificate.

@Override
public CreateDraftCertificateResponseType createDraftCertificate(String logicalAddress, CreateDraftCertificateType parameters) {
    Intyg utkastsParams = parameters.getIntyg();
    String invokingUserHsaId = utkastsParams.getSkapadAv().getPersonalId().getExtension();
    String invokingUnitHsaId = utkastsParams.getSkapadAv().getEnhet().getEnhetsId().getExtension();
    IntygUser user;
    try {
        user = webcertUserDetailsService.loadUserByHsaId(invokingUserHsaId);
    } catch (Exception e) {
        return createMIUErrorResponse(utkastsParams);
    }
    // Validate draft parameters
    ResultValidator resultsValidator = validator.validate(utkastsParams);
    if (resultsValidator.hasErrors()) {
        return createValidationErrorResponse(resultsValidator);
    }
    ResultValidator appErrorsValidator = validator.validateApplicationErrors(utkastsParams, user);
    if (appErrorsValidator.hasErrors()) {
        return createApplicationErrorResponse(appErrorsValidator);
    }
    LOG.debug("Creating draft for invoker '{}' on unit '{}'", utkastsParams.getSkapadAv().getPersonalId().getExtension(), invokingUnitHsaId);
    // Check if the invoking health personal has MIU rights on care unit
    if (!HoSPersonHelper.findVardenhetEllerMottagning(user, invokingUnitHsaId).isPresent()) {
        return createMIUErrorResponse(utkastsParams);
    }
    user.changeValdVardenhet(invokingUnitHsaId);
    String intygsTyp = moduleRegistry.getModuleIdFromExternalId(utkastsParams.getTypAvIntyg().getCode());
    Personnummer personnummer = Personnummer.createPersonnummer(utkastsParams.getPatient().getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Failed to create valid personnummer for createDraft request"));
    SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personnummer);
    if (AuthoritiesHelperUtil.mayNotCreateUtkastForSekretessMarkerad(sekretessStatus, user, intygsTyp)) {
        return createErrorResponse("Intygstypen " + intygsTyp.toUpperCase() + " kan inte utfärdas för patienter med sekretessmarkering", ErrorIdType.APPLICATION_ERROR);
    }
    Map<String, Map<String, Boolean>> intygstypToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
    String uniqueErrorString = AuthoritiesHelperUtil.validateMustBeUnique(user, intygsTyp, intygstypToBoolean);
    if (!uniqueErrorString.isEmpty()) {
        return createErrorResponse(uniqueErrorString, ErrorIdType.APPLICATION_ERROR);
    }
    if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_TAK_KONTROLL).isVerified()) {
        // Check if invoking health care unit has required TAK
        TakResult takResult = takService.verifyTakningForCareUnit(invokingUnitHsaId, intygsTyp, SchemaVersion.VERSION_3, user);
        if (!takResult.isValid()) {
            String error = Joiner.on("; ").join(takResult.getErrorMessages());
            return createErrorResponse(error, ErrorIdType.APPLICATION_ERROR);
        }
    }
    // Create the draft
    Utkast utkast = createNewDraft(utkastsParams, user);
    return createSuccessResponse(utkast.getIntygsId(), invokingUnitHsaId);
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Intyg(se.riv.clinicalprocess.healthcond.certificate.createdraftcertificateresponder.v3.Intyg) ResultValidator(se.inera.intyg.webcert.web.integration.validators.ResultValidator) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) TakResult(se.inera.intyg.webcert.integration.tak.model.TakResult) Map(java.util.Map) IntygUser(se.inera.intyg.infra.security.common.model.IntygUser) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 34 with WebCertServiceException

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

the class ElegWebCertUserDetailsService method decorateWebcertUserWithSekretessMarkering.

private void decorateWebcertUserWithSekretessMarkering(WebCertUser webCertUser, HoSPersonType hosPerson) {
    // Make sure we have a valid personnr to work with..
    Personnummer personNummer = Personnummer.createPersonnummer(hosPerson.getPersonId().getExtension()).orElseThrow(() -> new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, String.format("Can't determine sekretesstatus for invalid personId %s", hosPerson.getPersonId().getExtension())));
    PersonSvar person = puService.getPerson(personNummer);
    if (person.getStatus() == PersonSvar.Status.FOUND) {
        webCertUser.setSekretessMarkerad(person.getPerson().isSekretessmarkering());
    } else {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, String.format("PU replied with %s - Sekretesstatus cannot be determined for person %s", person.getStatus(), personNummer.getPersonnummerWithDash()));
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 35 with WebCertServiceException

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

the class SignaturServiceImplTest method serverSignatureFailureUniqueIntyg.

@Test
public void serverSignatureFailureUniqueIntyg() {
    Feature f = new Feature();
    f.setIntygstyper(ImmutableList.of(INTYG_TYPE));
    f.setGlobal(true);
    user.getFeatures().put(AuthoritiesConstants.FEATURE_UNIKT_INTYG, f);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    Utkast otherUtkast = createUtkast("otherId", 1L, INTYG_TYPE, UtkastStatus.SIGNED, "", null, "otherEnhet", PERSON_ID);
    otherUtkast.setSignatur(new Signatur());
    when(mockUtkastRepository.findAllByPatientPersonnummerAndIntygsTypIn(any(String.class), anySet())).thenReturn(ImmutableList.of(otherUtkast));
    try {
        intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
    } catch (WebCertServiceException e) {
        assertEquals(WebCertServiceErrorCodeEnum.INVALID_STATE_INTYG_EXISTS, e.getErrorCode());
    }
}
Also used : Signatur(se.inera.intyg.webcert.persistence.utkast.model.Signatur) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Feature(se.inera.intyg.infra.security.common.model.Feature) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Test(org.junit.Test)

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