Search in sources :

Example 26 with ModuleApi

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

Example 27 with ModuleApi

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

the class PatientDetailsResolverImpl method resolveDoiPatient.

/**
 * DOI har en specialregel som säger att namn och adress skall hämtas från ett DB-intyg i det fall sådant finns
 * utfärdat inom samma Vårdgivare (Integration) eller Vårdenhet (Fristående).
 */
private Patient resolveDoiPatient(Personnummer personnummer, WebCertUser user) {
    PersonSvar personSvar = getPersonSvar(personnummer);
    // Find ALL existing intyg for this patient, filter out so we only have DB left.
    List<Utkast> utkastList = new ArrayList<>();
    if (user.getOrigin().equals(UserOriginType.DJUPINTEGRATION.name())) {
        utkastList.addAll(utkastRepository.findDraftsByPatientAndVardgivareAndStatus(personnummer.getPersonnummer(), user.getValdVardgivare().getId(), UTKAST_STATUSES, Sets.newHashSet("db")));
    } else {
        utkastList.addAll(utkastRepository.findDraftsByPatientAndEnhetAndStatus(personnummer.getPersonnummer(), Arrays.asList(user.getValdVardenhet().getId()), UTKAST_STATUSES, Sets.newHashSet("db")));
    }
    // Use PU and integration parameters for deceased
    if (utkastList.size() > 0) {
        Utkast newest = utkastList.stream().sorted((u1, u2) -> u2.getSenastSparadDatum().compareTo(u1.getSenastSparadDatum())).findFirst().orElseThrow(() -> new IllegalStateException("List was > 0 but findFirst() returned no result."));
        try {
            ModuleApi moduleApi = moduleRegistry.getModuleApi("db");
            Utlatande utlatande = moduleApi.getUtlatandeFromJson(newest.getModel());
            Patient patient = utlatande.getGrundData().getPatient();
            if (personSvar.getStatus() == PersonSvar.Status.FOUND) {
                patient.setSekretessmarkering(personSvar.getPerson().isSekretessmarkering());
            }
            patient.setAvliden((personSvar.getStatus() == PersonSvar.Status.FOUND && personSvar.getPerson().isAvliden()) || (user.getParameters() != null && user.getParameters().isPatientDeceased()) || (personSvar.getStatus() != PersonSvar.Status.FOUND && user.getParameters() == null));
            return patient;
        } catch (ModuleNotFoundException | IOException e) {
            // No usabe DB exist
            return handleDoiNoExistingDb(personnummer, personSvar, user);
        }
    } else {
        // No usabe DB exist
        return handleDoiNoExistingDb(personnummer, personSvar, user);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) ArrayList(java.util.ArrayList) Patient(se.inera.intyg.common.support.model.common.internal.Patient) IOException(java.io.IOException) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar)

Aggregations

ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)27 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)13 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)12 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)11 Test (org.junit.Test)10 IOException (java.io.IOException)8 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)7 Patient (se.inera.intyg.common.support.model.common.internal.Patient)6 ExternalServiceCallException (se.inera.intyg.common.support.modules.support.api.exception.ExternalServiceCallException)5 Personnummer (se.inera.intyg.schemas.contract.Personnummer)5 ArrayList (java.util.ArrayList)3 WebServiceException (javax.xml.ws.WebServiceException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)3 Intyg (se.riv.clinicalprocess.healthcond.certificate.v3.Intyg)3 LocalDateTime (java.time.LocalDateTime)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)2