Search in sources :

Example 31 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande in project webcert by sklintyg.

the class IntygServiceImpl method buildIntygContentHolderForUtkast.

// NOTE! INTYG-4086. This method is used when fetching Intyg/Utkast from WC locally. The question is, should we
// replace the patient on the existing model with a freshly fetched one here or not? In case we're storing patient
// info entered manually for non FK-types here, we may end up overwriting a manually stored name etc...
private IntygContentHolder buildIntygContentHolderForUtkast(Utkast utkast, boolean relations) {
    try {
        // INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
        Patient newPatientData = patientDetailsResolver.resolvePatient(utkast.getPatientPersonnummer(), utkast.getIntygsTyp());
        // create an "empty" Patient with personnummer only.
        if (newPatientData == null) {
            newPatientData = new Patient();
            newPatientData.setPersonId(utkast.getPatientPersonnummer());
        }
        // INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
        Utlatande utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), utkast.getModel());
        if (!completeAddressProvided(newPatientData)) {
            // Use the old address data.
            Patient oldPatientData = utlatande.getGrundData().getPatient();
            copyOldAddressToNewPatientData(oldPatientData, newPatientData);
        }
        String updatedModel = moduleRegistry.getModuleApi(utkast.getIntygsTyp()).updateBeforeSave(utkast.getModel(), newPatientData);
        utlatande = modelFacade.getUtlatandeFromInternalModel(utkast.getIntygsTyp(), updatedModel);
        List<Status> statuses = IntygConverterUtil.buildStatusesFromUtkast(utkast);
        Relations certificateRelations = certificateRelationService.getRelations(utkast.getIntygsId());
        final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(newPatientData.getPersonId());
        if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
        }
        final boolean sekretessmarkerad = SekretessStatus.TRUE.equals(sekretessStatus);
        boolean patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
        boolean patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
        return IntygContentHolder.builder().setContents(updatedModel).setUtlatande(utlatande).setStatuses(statuses).setRevoked(utkast.getAterkalladDatum() != null).setRelations(certificateRelations).setCreated(utkast.getSkapad()).setDeceased(isDeceased(utkast.getPatientPersonnummer())).setSekretessmarkering(sekretessmarkerad).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
    } catch (ModuleException | ModuleNotFoundException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) Status(se.inera.intyg.common.support.model.Status) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) 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) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Example 32 with Utlatande

use of se.inera.intyg.common.support.model.common.internal.Utlatande 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

Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)32 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)18 Test (org.junit.Test)16 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)14 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)11 Personnummer (se.inera.intyg.schemas.contract.Personnummer)11 IOException (java.io.IOException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)10 Relation (se.inera.intyg.common.support.model.common.internal.Relation)8 Patient (se.inera.intyg.common.support.model.common.internal.Patient)7 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)7 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)7 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)6 WebcertCertificateRelation (se.inera.intyg.webcert.common.model.WebcertCertificateRelation)6 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)6 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)6 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)5 ValidationMessage (se.inera.intyg.common.support.modules.support.api.dto.ValidationMessage)3