Search in sources :

Example 11 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImplTest method testCreateRenewal.

@Test
public void testCreateRenewal() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.TRUE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(false))).thenReturn(resp);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.SIGNED))).thenReturn(Optional.empty());
    CreateRenewalCopyRequest copyReq = buildRenewalRequest();
    CreateRenewalCopyResponse renewalResponse = copyService.createRenewalCopy(copyReq);
    assertNotNull(renewalResponse);
    assertEquals(INTYG_COPY_ID, renewalResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalResponse.getNewDraftIntygType());
    assertEquals(INTYG_ID, renewalResponse.getOriginalIntygId());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateRenewalCopyRequest.class), any(Person.class), any(boolean.class), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 12 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImplTest method testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg.

@Test(expected = WebCertServiceException.class)
public void testCreateReplacementCopyFailedIfAlreadyReplacedBySignedIntyg() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    WebcertCertificateRelation ersattRelation = new WebcertCertificateRelation(INTYG_ID, RelationKod.ERSATT, LocalDateTime.now(), UtkastStatus.SIGNED);
    when(certificateRelationService.getNewestRelationOfType(INTYG_ID, RelationKod.ERSATT, Arrays.asList(UtkastStatus.values()))).thenReturn(Optional.of(ersattRelation));
    CreateReplacementCopyRequest copyReq = buildReplacementCopyRequest();
    CreateReplacementCopyResponse copyResp = copyService.createReplacementCopy(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(createReplacementUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateReplacementCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(true));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(logService).logCreateIntyg(any(LogRequest.class));
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebcertCertificateRelation(se.inera.intyg.webcert.common.model.WebcertCertificateRelation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Person(se.inera.intyg.infra.integration.pu.model.Person) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Test(org.junit.Test)

Example 13 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImplTest method testCreateRenewalWhenIntegrated.

@Test
public void testCreateRenewalWhenIntegrated() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest renewRequest = buildRenewalRequest();
    renewRequest.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalCopyResponse = copyService.createRenewalCopy(renewRequest);
    assertNotNull(renewalCopyResponse);
    assertEquals(INTYG_COPY_ID, renewalCopyResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalCopyResponse.getNewDraftIntygType());
    verifyZeroInteractions(mockPUService);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(referensService).saveReferens(eq(INTYG_COPY_ID), eq(reference));
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
    // Assert pdl log
    verify(logService).logCreateIntyg(any(LogRequest.class));
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 14 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImplTest method testCreateCopyWhenIntegratedAndWithUpdatedSSN.

@Test
public void testCreateCopyWhenIntegratedAndWithUpdatedSSN() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", false, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.FALSE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(createRenewalCopyUtkastBuilder.populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false))).thenReturn(resp);
    CreateRenewalCopyRequest copyReq = buildRenewalRequest();
    copyReq.setNyttPatientPersonnummer(PATIENT_NEW_SSN);
    copyReq.setDjupintegrerad(true);
    CreateRenewalCopyResponse renewalCopyResponse = copyService.createRenewalCopy(copyReq);
    assertNotNull(renewalCopyResponse);
    assertEquals(INTYG_COPY_ID, renewalCopyResponse.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, renewalCopyResponse.getNewDraftIntygType());
    verifyZeroInteractions(mockPUService);
    verify(createRenewalCopyUtkastBuilder).populateCopyUtkastFromSignedIntyg(any(CreateRenewalCopyRequest.class), isNull(), eq(false), eq(false), eq(false));
    verify(mockUtkastRepository).save(any(Utkast.class));
    verify(mockIntegreradeEnheterRegistry).addIfSameVardgivareButDifferentUnits(any(String.class), any(IntegreradEnhetEntry.class), anyString());
    verify(mockNotificationService).sendNotificationForDraftCreated(any(Utkast.class));
    verify(userService).getUser();
    verify(intygService).isRevoked(INTYG_ID, INTYG_TYPE, false);
    // Assert pdl log
    verify(logService).logCreateIntyg(any(LogRequest.class));
}
Also used : IntegreradEnhetEntry(se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 15 with CopyUtkastBuilderResponse

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

the class CreateRenewalCopyUtkastBuilderImplTest method testPopulateRenewalUtkastFromSignedIntygWithNoPatientDetails.

@Test
public void testPopulateRenewalUtkastFromSignedIntygWithNoPatientDetails() throws Exception {
    IntygContentHolder ich = createIntygContentHolder();
    when(mockIntygService.fetchIntygData(INTYG_ID, INTYG_TYPE, false)).thenReturn(ich);
    CreateRenewalCopyRequest renewalRequest = buildRenewalRequest();
    when(mockModuleApi.createRenewalFromTemplate(any(CreateDraftCopyHolder.class), any())).thenReturn(INTYG_JSON);
    ValidateDraftResponse vdr = new ValidateDraftResponse(ValidationStatus.VALID, new ArrayList<>());
    when(mockModuleApi.validateDraft(anyString())).thenReturn(vdr);
    CopyUtkastBuilderResponse builderResponse = renewalBuilder.populateCopyUtkastFromSignedIntyg(renewalRequest, null, false, false, false);
    assertNotNull(builderResponse.getUtkastCopy());
    assertNotNull(builderResponse.getUtkastCopy().getModel());
    assertEquals(INTYG_TYPE, builderResponse.getUtkastCopy().getIntygsTyp());
    assertEquals(PATIENT_SSN, builderResponse.getUtkastCopy().getPatientPersonnummer());
    assertEquals("Test", builderResponse.getUtkastCopy().getPatientFornamn());
    assertNull(builderResponse.getUtkastCopy().getPatientMellannamn());
    assertEquals("Testorsson", builderResponse.getUtkastCopy().getPatientEfternamn());
}
Also used : CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) CreateDraftCopyHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder) ValidateDraftResponse(se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse) Test(org.junit.Test)

Aggregations

CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)26 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)17 Test (org.junit.Test)15 Person (se.inera.intyg.infra.integration.pu.model.Person)14 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)11 ValidateDraftResponse (se.inera.intyg.common.support.modules.support.api.dto.ValidateDraftResponse)8 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 CreateDraftCopyHolder (se.inera.intyg.common.support.modules.support.api.dto.CreateDraftCopyHolder)7 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)7 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)6 IntygContentHolder (se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder)5 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)5 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)5 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)4 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 IntegreradEnhetEntry (se.inera.intyg.webcert.web.integration.registry.dto.IntegreradEnhetEntry)3 CreateCompletionCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest)3 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)3 IOException (java.io.IOException)2