Search in sources :

Example 11 with ModuleApi

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

the class UtkastModelToXmlConverterServiceImpl method utkastToJAXBObject.

private Intyg utkastToJAXBObject(String intygsTyp, String json) {
    try {
        ModuleApi moduleApi = intygModuleRegistry.getModuleApi(intygsTyp);
        Utlatande utlatandeFromJson = moduleApi.getUtlatandeFromJson(json);
        return moduleApi.getIntygFromUtlatande(utlatandeFromJson);
    } catch (ModuleNotFoundException | IOException | ModuleException e) {
        LOG.error("Error building Intyg JAXB object from Utkast. Message: {}", e.getMessage());
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

Example 12 with ModuleApi

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

the class PatientDetailsResolverTest method testSosDoiIntygIntegrationWithExistingDBIntygAndPuUnavailable.

/**
 * DOI - Integration. DB finns, PU saknas. Namn och adress från DB-intyget, avliden från integrationsparam.
 */
@Test
public void testSosDoiIntygIntegrationWithExistingDBIntygAndPuUnavailable() throws ModuleNotFoundException, IOException {
    when(puService.getPerson(any(Personnummer.class))).thenReturn(buildErrorPersonSvar());
    when(webCertUserService.getUser()).thenReturn(integratedWebCertUser);
    when(integratedWebCertUser.getValdVardgivare()).thenReturn(new Vardgivare("vg-1", "vardgivare-1"));
    List<Utkast> drafts = buildSosDBDrafts();
    when(utkastRepository.findDraftsByPatientAndVardgivareAndStatus(anyString(), anyString(), anyList(), anySet())).thenReturn(drafts);
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(buildSosDoiUtlatande());
    when(moduleRegistry.getModuleApi("db")).thenReturn(moduleApi);
    Patient patient = testee.resolvePatient(PNR, "doi");
    assertEquals(PNR.getPersonnummer(), patient.getPersonId().getPersonnummer());
    assertEquals(DB_FNAMN, patient.getFornamn());
    assertEquals(DB_MNAMN, patient.getMellannamn());
    assertEquals(DB_ENAMN, patient.getEfternamn());
    assertEquals(DB_POST_ADDR, patient.getPostadress());
    assertEquals(DB_POST_NR, patient.getPostnummer());
    assertEquals(DB_POST_ORT, patient.getPostort());
    assertEquals(INTEGR_AVLIDEN, patient.isAvliden());
    assertEquals(false, patient.isSekretessmarkering());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Test(org.junit.Test)

Example 13 with ModuleApi

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

the class PatientDetailsResolverTest method testSosDoiIntygFristaendeWithExistingDBIntygAndPuUnavailable.

/**
 * DOI - Fristående. DB finns, PU saknas. Namn och adress från DB-intyget. Avliden vet vi egentligen inte...
 */
@Test
public void testSosDoiIntygFristaendeWithExistingDBIntygAndPuUnavailable() throws ModuleNotFoundException, IOException {
    when(puService.getPerson(any(Personnummer.class))).thenReturn(buildErrorPersonSvar());
    when(webCertUserService.getUser()).thenReturn(freeWebCertUser);
    when(freeWebCertUser.getValdVardenhet()).thenReturn(buildVardenhet());
    List<Utkast> drafts = buildSosDBDrafts();
    when(utkastRepository.findDraftsByPatientAndEnhetAndStatus(anyString(), anyList(), anyList(), anySet())).thenReturn(drafts);
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(buildSosDoiUtlatande());
    when(moduleRegistry.getModuleApi("db")).thenReturn(moduleApi);
    Patient patient = testee.resolvePatient(PNR, "doi");
    assertEquals(PNR.getPersonnummer(), patient.getPersonId().getPersonnummer());
    assertEquals(DB_FNAMN, patient.getFornamn());
    assertEquals(DB_MNAMN, patient.getMellannamn());
    assertEquals(DB_ENAMN, patient.getEfternamn());
    assertEquals(DB_POST_ADDR, patient.getPostadress());
    assertEquals(DB_POST_NR, patient.getPostnummer());
    assertEquals(DB_POST_ORT, patient.getPostort());
    // Vi har ingen möjlighet att känna till avliden i det här fallet, men eftersom det är ett DB/DOI så kan vi utgå
    // från att patienten är avliden.
    assertEquals(true, patient.isAvliden());
    assertEquals(false, patient.isSekretessmarkering());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Test(org.junit.Test)

Example 14 with ModuleApi

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

the class PatientDetailsResolverTest method testSosDoiIntygIntegrationWithExistingDBIntygAndPuOk.

// - Dödsorsaksintyg - //
/**
 * DOI - Integration. DB finns, PU finns. Namn och adress från DB-intyget, avliden/sekr från PU.
 */
@Test
public void testSosDoiIntygIntegrationWithExistingDBIntygAndPuOk() throws ModuleNotFoundException, IOException {
    when(puService.getPerson(any(Personnummer.class))).thenReturn(buildPersonSvar());
    when(webCertUserService.getUser()).thenReturn(integratedWebCertUser);
    when(integratedWebCertUser.getValdVardgivare()).thenReturn(new Vardgivare("vg-1", "vardgivare-1"));
    List<Utkast> drafts = buildSosDBDrafts();
    when(utkastRepository.findDraftsByPatientAndVardgivareAndStatus(anyString(), anyString(), anyList(), anySet())).thenReturn(drafts);
    ModuleApi moduleApi = mock(ModuleApi.class);
    when(moduleApi.getUtlatandeFromJson(anyString())).thenReturn(buildSosDoiUtlatande());
    when(moduleRegistry.getModuleApi("db")).thenReturn(moduleApi);
    Patient patient = testee.resolvePatient(PNR, "doi");
    assertEquals(PNR.getPersonnummer(), patient.getPersonId().getPersonnummer());
    assertEquals(DB_FNAMN, patient.getFornamn());
    assertEquals(DB_MNAMN, patient.getMellannamn());
    assertEquals(DB_ENAMN, patient.getEfternamn());
    assertEquals(DB_POST_ADDR, patient.getPostadress());
    assertEquals(DB_POST_NR, patient.getPostnummer());
    assertEquals(DB_POST_ORT, patient.getPostort());
    assertEquals(PU_AVLIDEN || INTEGR_AVLIDEN, patient.isAvliden());
    assertEquals(false, patient.isSekretessmarkering());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Vardgivare(se.inera.intyg.infra.integration.hsa.model.Vardgivare) Test(org.junit.Test)

Example 15 with ModuleApi

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

the class IntygServiceImpl method getIntygData.

/**
 * Builds a IntygContentHolder by first trying to get the Intyg from intygstjansten. If
 * not found or the Intygstjanst couldn't be reached, the local Utkast - if available -
 * will be used instead.
 * <p>
 * Note that even when found, we check if we need to decorate the response with data from the utkast in order
 * to mitigate async send states. (E.g. a send may be in resend due to 3rd party issues, in that case decorate with
 * data about sent state from the Utkast)
 *
 * @param relations
 */
private IntygContentHolder getIntygData(String intygId, String typ, boolean relations) {
    try {
        CertificateResponse certificate = modelFacade.getCertificate(intygId, typ);
        String internalIntygJsonModel = certificate.getInternalModel();
        final Personnummer personId = certificate.getUtlatande().getGrundData().getPatient().getPersonId();
        // INTYG-4086: Patient object populated according to ruleset for the intygstyp at hand.
        // Since an FK-intyg never will have anything other than personId, try to fetch all using ruleset
        Patient newPatientData = patientDetailsResolver.resolvePatient(personId, typ);
        Utlatande utlatande = null;
        boolean patientNameChanged = false;
        boolean patientAddressChanged = false;
        try {
            utlatande = moduleRegistry.getModuleApi(typ).getUtlatandeFromJson(internalIntygJsonModel);
            patientNameChanged = patientDetailsResolver.isPatientNamedChanged(utlatande.getGrundData().getPatient(), newPatientData);
            patientAddressChanged = patientDetailsResolver.isPatientAddressChanged(utlatande.getGrundData().getPatient(), newPatientData);
        } catch (IOException e) {
            LOG.error("Failed to getUtlatandeFromJson intygsId {} while checking for updated patient information", intygId);
        }
        // parameters were available.
        if (newPatientData != null) {
            // Get the module api and use the "updateBeforeSave" to update the outbound "model" with the
            // Patient object.
            ModuleApi moduleApi = moduleRegistry.getModuleApi(typ);
            // INTYG-5354, INTYG-5380: Don't use incomplete address from external data sources (PU/js).
            if (!completeAddressProvided(newPatientData)) {
                // Use the old address data.
                Patient oldPatientData = utlatande.getGrundData().getPatient();
                copyOldAddressToNewPatientData(oldPatientData, newPatientData);
            }
            internalIntygJsonModel = moduleApi.updateBeforeSave(internalIntygJsonModel, newPatientData);
        }
        utkastIntygDecorator.decorateWithUtkastStatus(certificate);
        Relations certificateRelations = intygRelationHelper.getRelationsForIntyg(intygId);
        final SekretessStatus sekretessStatus = patientDetailsResolver.getSekretessStatus(personId);
        if (SekretessStatus.UNDEFINED.equals(sekretessStatus)) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.PU_PROBLEM, "Sekretesstatus could not be fetched from the PU service");
        }
        final boolean sekretessmarkering = SekretessStatus.TRUE.equals(sekretessStatus);
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        final LocalDateTime created = utkast != null ? utkast.getSkapad() : null;
        return IntygContentHolder.builder().setContents(internalIntygJsonModel).setUtlatande(certificate.getUtlatande()).setStatuses(certificate.getMetaData().getStatus()).setRevoked(certificate.isRevoked()).setRelations(certificateRelations).setCreated(created).setDeceased(isDeceased(personId)).setSekretessmarkering(sekretessmarkering).setPatientNameChangedInPU(patientNameChanged).setPatientAddressChangedInPU(patientAddressChanged).build();
    } catch (IntygModuleFacadeException me) {
        // It's possible the Intygstjanst hasn't received the Intyg yet, look for it locally before rethrowing
        // exception
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        if (utkast == null) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
        }
        return buildIntygContentHolderForUtkast(utkast, relations);
    } catch (WebServiceException wse) {
        // Something went wrong communication-wise, try to find a matching Utkast instead.
        Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygId, typ);
        if (utkast == null) {
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Cannot get intyg. Intygstjansten was not reachable and the Utkast could " + "not be found, perhaps it was issued by a non-webcert system?");
        }
        return buildIntygContentHolderForUtkast(utkast, relations);
    } catch (ModuleNotFoundException | ModuleException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) SekretessStatus(se.inera.intyg.webcert.common.model.SekretessStatus) WebServiceException(javax.xml.ws.WebServiceException) CertificateResponse(se.inera.intyg.common.support.modules.support.api.dto.CertificateResponse) Patient(se.inera.intyg.common.support.model.common.internal.Patient) Relations(se.inera.intyg.webcert.web.web.controller.api.dto.Relations) IOException(java.io.IOException) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException)

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