Search in sources :

Example 11 with PersonSvar

use of se.inera.intyg.infra.integration.pu.model.PersonSvar in project webcert by sklintyg.

the class PersonApiController method getPersonuppgifter.

@GET
@Path("/{personnummer}")
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response getPersonuppgifter(@PathParam("personnummer") String personnummerIn) {
    try {
        Personnummer personnummer = createPnr(personnummerIn);
        LOG.debug("Hämtar personuppgifter för: {}", personnummer.getPersonnummerHash());
        PersonSvar personSvar = puService.getPerson(personnummer);
        monitoringService.logPULookup(personnummer, personSvar.getStatus().name());
        return Response.ok(new PersonuppgifterResponse(personSvar)).build();
    } catch (InvalidPersonNummerException e) {
        LOG.error(e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) InvalidPersonNummerException(se.inera.intyg.schemas.contract.InvalidPersonNummerException) PersonuppgifterResponse(se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with PersonSvar

use of se.inera.intyg.infra.integration.pu.model.PersonSvar in project webcert by sklintyg.

the class NotificationPatientEnricher method enrichWithPatient.

public void enrichWithPatient(Intyg intyg) throws TemporaryException {
    // INTYG-4190, hämta patientens uppgifter från PU-tjänsten och klistra in i utlåtandet.
    String intygsTyp = intyg.getTyp().getCode();
    switch(intygsTyp.toLowerCase()) {
        case "luse":
        case "luae_na":
        case "luae_fs":
        case "lisjp":
            String personId = intyg.getPatient().getPersonId().getExtension();
            Personnummer personnummer = Personnummer.createPersonnummer(personId).orElseThrow(() -> new IllegalArgumentException("Cannot create Personummer object from personId: " + personId));
            PersonSvar personSvar = puService.getPerson(personnummer);
            if (personSvar.getStatus() == PersonSvar.Status.FOUND) {
                if (!personSvar.getPerson().isSekretessmarkering()) {
                    intyg.setPatient(buildPatientFromPersonSvar(personSvar.getPerson()));
                } else {
                    intyg.getPatient().setEfternamn(SEKRETESSMARKERING);
                    intyg.getPatient().setFornamn(EMPTY_STRING);
                    intyg.getPatient().setMellannamn(EMPTY_STRING);
                    intyg.getPatient().setPostadress(EMPTY_STRING);
                    intyg.getPatient().setPostnummer(EMPTY_STRING);
                    intyg.getPatient().setPostort(EMPTY_STRING);
                }
            } else if (personSvar.getStatus() == PersonSvar.Status.ERROR) {
                throw new TemporaryException(new IllegalStateException("Could not query PU-service for enriching notification with patient data."));
            } else {
                LOG.warn("PU-service returned NOT_FOUND for personnummer: {}, not enriching notification.", personnummer.getPersonnummerHash());
            }
            break;
        default:
            // Do nothing
            break;
    }
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) TemporaryException(se.inera.intyg.webcert.common.sender.exception.TemporaryException) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar)

Example 13 with PersonSvar

use of se.inera.intyg.infra.integration.pu.model.PersonSvar in project webcert by sklintyg.

the class PatientDetailsResolverImpl method resolveFkPatient.

/*
     * I: Info om avliden från både PU-tjänst och journalsystem.
     */
private Patient resolveFkPatient(Personnummer personnummer, WebCertUser user) {
    PersonSvar personSvar = getPersonSvar(personnummer);
    Patient patient = personSvar.getStatus() == PersonSvar.Status.FOUND ? toPatientFromPersonSvarNameOnly(personnummer, personSvar) : resolveFkPatientPuUnavailable(personnummer, user);
    if (patient != null) {
        patient.setAvliden(patient.isAvliden() || Optional.ofNullable(user.getParameters()).map(IntegrationParameters::isPatientDeceased).orElse(false));
    }
    return patient;
}
Also used : Patient(se.inera.intyg.common.support.model.common.internal.Patient) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar)

Example 14 with PersonSvar

use of se.inera.intyg.infra.integration.pu.model.PersonSvar in project webcert by sklintyg.

the class PatientDetailsResolverImpl method resolveDbPatient.

/**
 * Integration: Namn, s-markering från PU-tjänst & info om avliden. Journalsystem för adress.
 * Free: PU-tjänsten (alla uppgifter)
 */
private Patient resolveDbPatient(Personnummer personnummer, WebCertUser user) {
    PersonSvar personSvar = getPersonSvar(personnummer);
    Patient patient = null;
    // NORMAL and DJUPINTEGRATION uses only PU for db
    if (personSvar.getStatus() == PersonSvar.Status.FOUND) {
        patient = toPatientFromPersonSvar(personnummer, personSvar);
    }
    return patient;
}
Also used : Patient(se.inera.intyg.common.support.model.common.internal.Patient) PersonSvar(se.inera.intyg.infra.integration.pu.model.PersonSvar)

Example 15 with PersonSvar

use of se.inera.intyg.infra.integration.pu.model.PersonSvar 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

PersonSvar (se.inera.intyg.infra.integration.pu.model.PersonSvar)16 Personnummer (se.inera.intyg.schemas.contract.Personnummer)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)4 Person (se.inera.intyg.infra.integration.pu.model.Person)4 PersonuppgifterResponse (se.inera.intyg.webcert.web.web.controller.api.dto.PersonuppgifterResponse)4 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 Before (org.junit.Before)2 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)1 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)1 InvalidPersonNummerException (se.inera.intyg.schemas.contract.InvalidPersonNummerException)1 TemporaryException (se.inera.intyg.webcert.common.sender.exception.TemporaryException)1