Search in sources :

Example 6 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class UtkastServiceImpl method updateUtkastModel.

private void updateUtkastModel(Utkast utkast, String modelJson) {
    WebCertUser user = webCertUserService.getUser();
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(utkast.getIntygsTyp());
        GrundData grundData = moduleApi.getUtlatandeFromJson(modelJson).getGrundData();
        Vardenhet vardenhetFromJson = grundData.getSkapadAv().getVardenhet();
        HoSPersonal hosPerson = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, vardenhetFromJson);
        utkast.setSenastSparadAv(UpdateUserUtil.createVardpersonFromWebCertUser(user));
        utkast.setPatientPersonnummer(grundData.getPatient().getPersonId());
        String updatedInternal = moduleApi.updateBeforeSave(modelJson, hosPerson);
        // String updatedInternalWithResolvedPatient = moduleApi.updateBeforeSave(updatedInternal,
        // updatedPatientForSaving);
        utkast.setModel(updatedInternal);
        updatePatientNameFromModel(utkast, grundData.getPatient());
    } catch (ModuleException | ModuleNotFoundException | IOException e) {
        if (e.getCause() != null && e.getCause().getCause() != null) {
            // This error message is helpful when debugging save problems.
            LOG.debug(e.getCause().getCause().getMessage());
        }
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, "Could not update with HoS personal", e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 7 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException 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 8 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException 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)

Example 9 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class UtkastModelToXmlConverterServiceImpl method utkastToJAXBObject.

private Intyg utkastToJAXBObject(String intygsTyp, String json) {
    try {
        ModuleApi moduleApi = intygModuleRegistry.getModuleApi(intygsTyp);
        Utlatande utlatandeFromJson = moduleApi.getUtlatandeFromJson(json);
        return moduleApi.getIntygFromUtlatande(utlatandeFromJson);
    } catch (ModuleNotFoundException | IOException | ModuleException e) {
        LOG.error("Error building Intyg JAXB object from Utkast. Message: {}", e.getMessage());
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

Example 10 with ModuleNotFoundException

use of se.inera.intyg.common.support.modules.registry.ModuleNotFoundException in project webcert by sklintyg.

the class UtkastBootstrapBean method init.

@PostConstruct
public void init() throws IOException {
    for (Resource resource : getResourceListing("classpath*:module-bootstrap-certificate/*.xml")) {
        try {
            String moduleName = resource.getFilename().split("__")[0];
            LOG.info("Bootstrapping certificate '{}' from module ", resource.getFilename(), moduleName);
            Utlatande utlatande = buildUtlatande(resource, moduleName);
            if (utkastRepo.findOne(utlatande.getId()) == null) {
                utkastRepo.save(createUtkast(utlatande));
                switch(utlatande.getTyp()) {
                    case Fk7263EntryPoint.MODULE_ID:
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, true, false));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.WEBCERT, false, false));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, false, true));
                        fragaRepo.save(createFragaSvar(utlatande, FrageStallare.FORSAKRINGSKASSAN, false, false));
                        break;
                    case TsBasEntryPoint.MODULE_ID:
                    case TsDiabetesEntryPoint.MODULE_ID:
                        // These certificates does not support arende or fragaSvar
                        break;
                    default:
                        // SIT certificates
                        setupArende(utlatande, true, true, FrageStallare.FORSAKRINGSKASSAN);
                        setupArende(utlatande, false, false, FrageStallare.WEBCERT);
                        setupArende(utlatande, false, false, FrageStallare.FORSAKRINGSKASSAN);
                        break;
                }
            }
        } catch (ModuleException | ModuleNotFoundException | IOException e) {
            LOG.error("Could not bootstrap {}", resource.getFilename(), e);
        }
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)26 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)16 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)14 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)12 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 IOException (java.io.IOException)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 Test (org.junit.Test)5 Patient (se.inera.intyg.common.support.model.common.internal.Patient)4 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)4 ArrayList (java.util.ArrayList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SekretessStatus (se.inera.intyg.webcert.common.model.SekretessStatus)3 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)3 LocalDateTime (java.time.LocalDateTime)2 Map (java.util.Map)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Status (se.inera.intyg.common.support.model.Status)2