Search in sources :

Example 1 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class AbstractUtkastBuilder method populateCopyUtkastFromSignedIntyg.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromSignedIntyg(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
public CopyUtkastBuilderResponse populateCopyUtkastFromSignedIntyg(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    String originalIntygsTyp = copyRequest.getOriginalIntygTyp();
    String intygsTyp = copyRequest.getTyp();
    IntygContentHolder signedIntygHolder = intygService.fetchIntygData(orignalIntygsId, originalIntygsTyp, coherentJournaling);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(originalIntygsTyp);
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(signedIntygHolder.getContents());
    } catch (IOException e) {
        throw new ModuleException("Could not convert orignal certificate to Utlatande", e);
    }
    GrundData grundData = signedIntygHolder.getUtlatande().getGrundData();
    se.inera.intyg.common.support.model.common.internal.Vardenhet vardenhet = grundData.getSkapadAv().getVardenhet();
    if (coherentJournaling && enforceEnhet) {
        verifyEnhetsAuth(vardenhet.getVardgivare().getVardgivarid(), vardenhet.getEnhetsid(), true);
    }
    LOG.debug("Populating copy with details from signed Intyg '{}'", orignalIntygsId);
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(vardenhet.getEnhetsid());
    builderResponse.setOrginalEnhetsNamn(vardenhet.getEnhetsnamn());
    builderResponse.setOrginalVardgivarId(vardenhet.getVardgivare().getVardgivarid());
    builderResponse.setOrginalVardgivarNamn(vardenhet.getVardgivare().getVardgivarnamn());
    ModuleApi moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, intygsTyp, addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        se.inera.intyg.common.support.model.common.internal.Patient patient = signedIntygHolder.getUtlatande().getGrundData().getPatient();
        populatePatientDetailsFromPatient(utkast, patient);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) IOException(java.io.IOException) Relation(se.inera.intyg.common.support.model.common.internal.Relation) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 2 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygServiceTest method testFetchIntygDataHasSentAndRevokedStatusesWhenIntygstjanstIsUnavailableAndDraftHadSentDateAndRevokedDate.

@SuppressWarnings("unchecked")
@Test
public void testFetchIntygDataHasSentAndRevokedStatusesWhenIntygstjanstIsUnavailableAndDraftHadSentDateAndRevokedDate() throws Exception {
    when(moduleFacade.getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenThrow(WebServiceException.class);
    when(utkastRepository.findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenReturn(getIntyg(CERTIFICATE_ID, LocalDateTime.now(), LocalDateTime.now()));
    IntygContentHolder intygContentHolder = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertEquals(intygContentHolder.getStatuses().size(), 3);
    assertEquals(intygContentHolder.getStatuses().get(0).getType(), CertificateState.SENT);
    assertEquals(intygContentHolder.getStatuses().get(1).getType(), CertificateState.CANCELLED);
    assertEquals(intygContentHolder.getStatuses().get(2).getType(), CertificateState.RECEIVED);
    assertNotNull(intygContentHolder.getUtlatande());
    // ensure that correct call is made to moduleFacade
    verify(moduleFacade).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
    // Assert pdl log
    verify(logservice).logReadIntyg(any(LogRequest.class));
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Test(org.junit.Test)

Example 3 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygServiceTest method testFetchIntygDataWithRelationNotFoundInIT.

@Test
public void testFetchIntygDataWithRelationNotFoundInIT() throws Exception {
    when(moduleFacade.getCertificate(any(String.class), any(String.class))).thenThrow(new IntygModuleFacadeException(""));
    when(utkastRepository.findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE)).thenReturn(getIntyg(CERTIFICATE_ID, null, null));
    IntygContentHolder res = intygService.fetchIntygDataWithRelations(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertNotNull(res);
    assertNotNull(res.getRelations());
    verify(moduleFacade).getCertificate(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(utkastRepository).findOneByIntygsIdAndIntygsTyp(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(logservice).logReadIntyg(any(LogRequest.class));
    verify(mockMonitoringService).logIntygRead(CERTIFICATE_ID, CERTIFICATE_TYPE);
    verify(certificateRelationService).getRelations(eq(CERTIFICATE_ID));
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IntygModuleFacadeException(se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException) Test(org.junit.Test)

Example 4 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygServiceTest method testDeceasedIsSetForDeadPatientDjupintegration.

@Test
public void testDeceasedIsSetForDeadPatientDjupintegration() {
    when(webcertUser.getOrigin()).thenReturn(UserOriginType.DJUPINTEGRATION.name());
    when(webcertUser.getParameters()).thenReturn(new IntegrationParameters("", "", "", "", "", "", "", "", "", false, true, false, true));
    when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(buildPatient(false, true));
    IntygContentHolder intygData = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    assertTrue(intygData.isDeceased());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Test(org.junit.Test)

Example 5 with IntygContentHolder

use of se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder in project webcert by sklintyg.

the class IntygServiceTest method testThatIncompletePatientAddressIsNotUsed.

@Test
public void testThatIncompletePatientAddressIsNotUsed() throws Exception {
    // Given
    String postadress = "ttipafpinu-postadress";
    String postort = null;
    String postnummer = null;
    Patient patientWithIncompleteAddress = buildPatient(false, false);
    patientWithIncompleteAddress.setPostadress(postadress);
    patientWithIncompleteAddress.setPostort(postort);
    patientWithIncompleteAddress.setPostnummer(postnummer);
    when(patientDetailsResolver.resolvePatient(any(Personnummer.class), anyString())).thenReturn(patientWithIncompleteAddress);
    // When
    IntygContentHolder intygData = intygService.fetchIntygData(CERTIFICATE_ID, CERTIFICATE_TYPE, false);
    // Then
    ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class);
    verify(moduleApi).updateBeforeSave(anyString(), argumentCaptor.capture());
    assertNotEquals(postadress, argumentCaptor.getValue().getPostadress());
}
Also used : Personnummer(se.inera.intyg.schemas.contract.Personnummer) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Patient(se.inera.intyg.common.support.model.common.internal.Patient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)30 Test (org.junit.Test)23 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)9 Personnummer (se.inera.intyg.schemas.contract.Personnummer)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Patient (se.inera.intyg.common.support.model.common.internal.Patient)5 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)5 CreateDraftCopyHolder (se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder)4 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)4 Person (se.inera.intyg.infra.integration.pu.model.Person)4 LocalDateTime (java.time.LocalDateTime)3 WebServiceException (javax.xml.ws.WebServiceException)3 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)3 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 IntygModuleFacadeException (se.inera.intyg.webcert.web.service.intyg.converter.IntygModuleFacadeException)3 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)3 Response (javax.ws.rs.core.Response)2 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)2 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)2