Search in sources :

Example 26 with Patient

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

the class UtkastServiceImplTest method testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException.

@Test(expected = WebCertServiceException.class)
public void testUpdatePatientOnDraftNoMedarbetaruppdragThrowsException() throws Exception {
    utkast.setEnhetsId("<unknownenhet>");
    Patient newPatient = getUpdatedPatient();
    UpdatePatientOnDraftRequest request = new UpdatePatientOnDraftRequest(newPatient.getPersonId(), utkast.getIntygsId(), utkast.getVersion());
    WebCertUser user = createUser();
    Utlatande utlatande = mock(Utlatande.class);
    GrundData grunddata = new GrundData();
    grunddata.setPatient(defaultPatient);
    grunddata.setSkapadAv(new HoSPersonal());
    // Make a spy out of the utkast so we can verify invocations on the setters with proper names further down.
    utkast = spy(utkast);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
    when(userService.getUser()).thenReturn(user);
    draftService.updatePatientOnDraft(request);
    verifyNoMoreInteractions(mockUtkastRepository, notificationService);
}
Also used : HoSPersonal(se.inera.intyg.common.support.model.common.internal.HoSPersonal) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Patient(se.inera.intyg.common.support.model.common.internal.Patient) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) UpdatePatientOnDraftRequest(se.inera.intyg.webcert.web.service.utkast.dto.UpdatePatientOnDraftRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 27 with Patient

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

the class UtkastServiceImplTest method getUpdatedPatient.

private Patient getUpdatedPatient() {
    Patient newPatient = new Patient();
    newPatient.setEfternamn("updated lastName");
    newPatient.setMellannamn("updated middle-name");
    newPatient.setFornamn("updated firstName");
    newPatient.setFullstandigtNamn("updated full name");
    newPatient.setPersonId(createPnr("19121272-1212"));
    newPatient.setPostadress("updated postal address");
    newPatient.setPostnummer("1111111");
    newPatient.setPostort("updated post city");
    return newPatient;
}
Also used : Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 28 with Patient

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

Example 29 with Patient

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

the class PatientDetailsResolverImpl method toPatientFromPersonSvar.

private Patient toPatientFromPersonSvar(Personnummer personnummer, PersonSvar personSvar) {
    Patient patient = buildBasePatient(personnummer, personSvar);
    // Address
    patient.setPostadress(personSvar.getPerson().getPostadress());
    patient.setPostnummer(personSvar.getPerson().getPostnummer());
    patient.setPostort(personSvar.getPerson().getPostort());
    return patient;
}
Also used : Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 30 with Patient

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

the class PatientDetailsResolverImpl method toPatientFromParameters.

private Patient toPatientFromParameters(Personnummer personnummer, IntegrationParameters parameters) {
    Patient patient = buildBasePatientFromParameters(personnummer, parameters);
    patient.setPostadress(parameters.getPostadress());
    patient.setPostnummer(parameters.getPostnummer());
    patient.setPostort(parameters.getPostort());
    patient.setAvliden(parameters.isPatientDeceased());
    return patient;
}
Also used : Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Aggregations

Patient (se.inera.intyg.common.support.model.common.internal.Patient)62 Test (org.junit.Test)28 Personnummer (se.inera.intyg.schemas.contract.Personnummer)28 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 HoSPersonal (se.inera.intyg.common.support.model.common.internal.HoSPersonal)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)7 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)6 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)5 Vardgivare (se.inera.intyg.common.support.model.common.internal.Vardgivare)5 Vardgivare (se.inera.intyg.infra.integration.hsa.model.Vardgivare)5 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)5 Relations (se.inera.intyg.webcert.web.web.controller.api.dto.Relations)5 IOException (java.io.IOException)4 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)4 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)4 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)4 PersonSvar (se.inera.intyg.infra.integration.pu.model.PersonSvar)4