Search in sources :

Example 16 with ModuleNotFoundException

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

the class IntygModuleFacadeImpl method registerCertificate.

@Override
public void registerCertificate(String intygType, String internalIntygJsonModel) throws ModuleException, IntygModuleFacadeException {
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        moduleApi.registerCertificate(internalIntygJsonModel, logicalAddress);
    } catch (ModuleNotFoundException e) {
        LOG.error("ModuleNotFoundException occured for intygstyp '{}' when registering certificate", intygType);
        throw new IntygModuleFacadeException("ModuleNotFoundException occured when registering certificate", e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)

Example 17 with ModuleNotFoundException

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

the class ArendeViewConverter method convertToMedicinsktArendeView.

private List<MedicinsktArendeView> convertToMedicinsktArendeView(List<MedicinsktArende> medicinskaArenden, String intygsId, String intygsTyp) {
    List<MedicinsktArendeView> medicinskaArendenViews = new ArrayList<>();
    if (CollectionUtils.isEmpty(medicinskaArenden)) {
        return medicinskaArendenViews;
    }
    List<String> frageIds = medicinskaArenden.stream().map(MedicinsktArende::getFrageId).distinct().collect(Collectors.toList());
    ModuleApi moduleApi = null;
    try {
        moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    } catch (ModuleNotFoundException e) {
        LOG.error("Module not found for certificate of type {}", intygsTyp);
        Throwables.propagate(e);
    }
    Utlatande utlatande = intygService.fetchIntygData(intygsId, intygsTyp, false).getUtlatande();
    Map<String, List<String>> arendeParameters = moduleApi.getModuleSpecificArendeParameters(utlatande, frageIds);
    for (MedicinsktArende arende : medicinskaArenden) {
        Integer position = getListPositionForInstanceId(arende);
        String jsonPropertyHandle = getJsonPropertyHandle(arende, position, arendeParameters);
        MedicinsktArendeView view = MedicinsktArendeView.builder().setFrageId(arende.getFrageId()).setInstans(arende.getInstans()).setText(arende.getText()).setPosition(Math.max(position - 1, 0)).setJsonPropertyHandle(jsonPropertyHandle).build();
        medicinskaArendenViews.add(view);
    }
    return medicinskaArendenViews;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MedicinsktArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.MedicinsktArendeView)

Example 18 with ModuleNotFoundException

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

the class IntygModuleFacadeTest method testRegisterCertificateModuleNotFoundException.

@Test(expected = IntygModuleFacadeException.class)
public void testRegisterCertificateModuleNotFoundException() throws Exception {
    when(moduleRegistry.getModuleApi(CERTIFICATE_TYPE)).thenThrow(new ModuleNotFoundException());
    moduleFacade.registerCertificate(CERTIFICATE_TYPE, INT_JSON);
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Test(org.junit.Test)

Example 19 with ModuleNotFoundException

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

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

the class CopyUtkastServiceImpl method createUtkastFromTemplate.

@Override
public CreateUtkastFromTemplateResponse createUtkastFromTemplate(CreateUtkastFromTemplateRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating utkast from template certificate '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    boolean coherentJournaling = user != null && user.getParameters() != null && user.getParameters().isSjf();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling)) {
            LOG.debug("Cannot create utkast from template certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        String intygsTyp = copyRequest.getTyp();
        if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
            Personnummer personnummer = copyRequest.containsNyttPatientPersonnummer() ? copyRequest.getNyttPatientPersonnummer() : copyRequest.getPatient().getPersonId();
            Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
            Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
            Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
            if (utkastExists != null && utkastExists) {
                if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Drafts of this type must be unique within this caregiver.");
                }
            }
            if (intygExists != null) {
                if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be globally unique.");
                } else if (intygExists && authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be unique within this caregiver.");
                }
            }
        }
        verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create utkast from template");
        CopyUtkastBuilderResponse builderResponse = buildUtkastFromTemplateBuilderResponse(copyRequest, originalIntygId, true, coherentJournaling);
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        return new CreateUtkastFromTemplateResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Map(java.util.Map) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

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