Search in sources :

Example 26 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class IntygServiceImpl method listCertificatesForCareWithQA.

@Override
public List<IntygWithNotificationsResponse> listCertificatesForCareWithQA(IntygWithNotificationsRequest request) {
    List<Utkast> utkastList;
    if (request.shouldUseEnhetId()) {
        utkastList = utkastRepository.findDraftsByPatientAndEnhetAndStatus(DaoUtil.formatPnrForPersistence(request.getPersonnummer()), request.getEnhetId(), Arrays.asList(UtkastStatus.values()), moduleRegistry.listAllModules().stream().map(IntygModule::getId).collect(Collectors.toSet()));
    } else {
        utkastList = utkastRepository.findDraftsByPatientAndVardgivareAndStatus(DaoUtil.formatPnrForPersistence(request.getPersonnummer()), request.getVardgivarId(), Arrays.asList(UtkastStatus.values()), moduleRegistry.listAllModules().stream().map(IntygModule::getId).collect(Collectors.toSet()));
    }
    List<IntygWithNotificationsResponse> res = new ArrayList<>();
    for (Utkast utkast : utkastList) {
        List<Handelse> notifications = notificationService.getNotifications(utkast.getIntygsId());
        String ref = referensService.getReferensForIntygsId(utkast.getIntygsId());
        notifications = notifications.stream().filter(handelse -> {
            if (request.getStartDate() != null && handelse.getTimestamp().isBefore(request.getStartDate())) {
                return false;
            }
            if (request.getEndDate() != null && handelse.getTimestamp().isAfter(request.getEndDate())) {
                return false;
            }
            return true;
        }).collect(Collectors.toList());
        // this time span
        if ((request.getStartDate() != null || request.getEndDate() != null) && notifications.isEmpty()) {
            continue;
        }
        try {
            ModuleApi api = moduleRegistry.getModuleApi(utkast.getIntygsTyp());
            Intyg intyg = api.getIntygFromUtlatande(api.getUtlatandeFromJson(utkast.getModel()));
            Pair<ArendeCount, ArendeCount> arenden = fragorOchSvarCreator.createArenden(utkast.getIntygsId(), utkast.getIntygsTyp());
            res.add(new IntygWithNotificationsResponse(intyg, notifications, arenden.getLeft(), arenden.getRight(), ref));
        } catch (ModuleNotFoundException | ModuleException | IOException e) {
            LOG.error("Could not convert intyg {} to external format", utkast.getIntygsId());
        }
    }
    return res;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Intyg(se.riv.clinicalprocess.healthcond.certificate.v3.Intyg) ArendeCount(se.inera.intyg.common.support.modules.support.api.notification.ArendeCount) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) IntygWithNotificationsResponse(se.inera.intyg.webcert.web.service.intyg.dto.IntygWithNotificationsResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Handelse(se.inera.intyg.webcert.persistence.handelse.model.Handelse)

Example 27 with ModuleException

use of se.inera.intyg.common.support.modules.support.api.exception.ModuleException in project webcert by sklintyg.

the class IntygModuleFacadeImpl method convertFromInternalToPdfDocument.

@Override
public IntygPdf convertFromInternalToPdfDocument(String intygType, String internalIntygJsonModel, List<Status> statuses, boolean isEmployer) throws IntygModuleFacadeException {
    boolean isUtkast = isUtkast(statuses);
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        PdfResponse pdfResponse;
        if (!isEmployer) {
            pdfResponse = moduleApi.pdf(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, isUtkast);
        } else {
            pdfResponse = moduleApi.pdfEmployer(internalIntygJsonModel, statuses, ApplicationOrigin.WEBCERT, Collections.emptyList(), isUtkast);
        }
        return new IntygPdf(pdfResponse.getPdfData(), pdfResponse.getFilename());
    } catch (ModuleException me) {
        LOG.error("ModuleException occured when when generating PDF document from internal");
        throw new IntygModuleFacadeException("ModuleException occured when generating PDF document from internal", me);
    } catch (ModuleNotFoundException e) {
        LOG.error("ModuleNotFoundException occured for intygstyp '{}' when generating PDF document from internal", 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) IntygPdf(se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) PdfResponse(se.inera.intyg.common.support.modules.support.api.dto.PdfResponse)

Aggregations

ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)27 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)16 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)14 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)13 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 IOException (java.io.IOException)9 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 Test (org.junit.Test)6 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)6 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)6 Transactional (org.springframework.transaction.annotation.Transactional)4 Patient (se.inera.intyg.common.support.model.common.internal.Patient)4 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)4 Personnummer (se.inera.intyg.schemas.contract.Personnummer)3 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)3 LocalDateTime (java.time.LocalDateTime)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 WebServiceException (javax.xml.ws.WebServiceException)2 Status (se.inera.intyg.common.support.model.Status)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2