Search in sources :

Example 26 with ModuleNotFoundException

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

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