Search in sources :

Example 16 with Status

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

Aggregations

Status (se.inera.intyg.common.support.model.Status)16 Test (org.junit.Test)7 UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)6 ArrayList (java.util.ArrayList)5 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 Fk7263Utlatande (se.inera.intyg.common.fk7263.model.internal.Fk7263Utlatande)3 ApplicationOrigin (se.inera.intyg.common.support.modules.support.ApplicationOrigin)3 CertificateResponse (se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse)3 ValidationStatus (se.inera.intyg.common.support.modules.support.api.dto.ValidationStatus)3 CustomObjectMapper (se.inera.intyg.common.util.integration.json.CustomObjectMapper)3 Patient (se.inera.intyg.common.support.model.common.internal.Patient)2 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)2 CertificateMetaData (se.inera.intyg.common.support.modules.support.api.dto.CertificateMetaData)2 PdfResponse (se.inera.intyg.common.support.modules.support.api.dto.PdfResponse)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 IntygPdf (se.inera.intyg.webcert.web.service.intyg.dto.IntygPdf)2 BeforeClass (org.junit.BeforeClass)1 DbUtlatande (se.inera.intyg.common.db.model.internal.DbUtlatande)1 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)1