Search in sources :

Example 1 with CreateCompletionCopyResponse

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

the class CopyUtkastServiceImpl method createCompletion.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastService#createCopy(se.inera.intyg.webcert.web.service.utkast.
     * dto.
     * CreateNewDraftCopyRequest)
     */
@Override
public CreateCompletionCopyResponse createCompletion(CreateCompletionCopyRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating completion to intyg '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getTyp(), false)) {
            LOG.debug("Cannot create completion copy of certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        CopyUtkastBuilderResponse builderResponse = buildCompletionUtkastBuilderResponse(copyRequest, originalIntygId, true);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedCompletion(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateCompletionCopyResponse(savedUtkast.getIntygsTyp(), savedUtkast.getIntygsId(), originalIntygId);
    } catch (ModuleException | ModuleNotFoundException me) {
        LOG.error("Module exception occured when trying to make a copy of " + originalIntygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, me);
    }
}
Also used : ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Example 2 with CreateCompletionCopyResponse

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

the class CopyUtkastServiceImplTest method testCreateCompletion.

@Test
public void testCreateCompletion() throws Exception {
    final String reference = "ref";
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(reference, "", "", "", "", "", "", "", "", true, false, false, true));
    when(userService.getUser()).thenReturn(user);
    when(mockUtkastRepository.exists(INTYG_ID)).thenReturn(Boolean.TRUE);
    CopyUtkastBuilderResponse resp = createCopyUtkastBuilderResponse();
    when(copyCompletionUtkastBuilder.populateCopyUtkastFromOrignalUtkast(any(CreateCompletionCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), eq(false))).thenReturn(resp);
    CreateCompletionCopyRequest copyReq = buildCompletionRequest();
    CreateCompletionCopyResponse copyResp = copyService.createCompletion(copyReq);
    assertNotNull(copyResp);
    assertEquals(INTYG_COPY_ID, copyResp.getNewDraftIntygId());
    assertEquals(INTYG_TYPE, copyResp.getNewDraftIntygType());
    assertEquals(INTYG_ID, copyResp.getOriginalIntygId());
    verify(mockPUService).getPerson(PATIENT_SSN);
    verify(copyCompletionUtkastBuilder).populateCopyUtkastFromOrignalUtkast(any(CreateCompletionCopyRequest.class), any(Person.class), any(boolean.class), any(boolean.class), 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) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) CreateCompletionCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) 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 3 with CreateCompletionCopyResponse

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

the class IntygModuleApiControllerTest method testCreateNewCompletion.

@Test
public void testCreateNewCompletion() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    final String meddelandeId = "meddelandeId";
    final String newPersonnummer = "201212121212";
    final String efternamn = "efternamn";
    final String fornamn = "fornamn";
    final String mellannamn = "mellannamn";
    final String postadress = "postadress";
    final String postort = "postort";
    final String postnummer = "postnummer";
    final CopyIntygRequest request = new CopyIntygRequest();
    request.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(null, null, newPersonnummer, fornamn, mellannamn, efternamn, postadress, postnummer, postort, false, false, false, true));
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_SVARA_MED_NYTT_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateCompletionCopyRequest> captor = ArgumentCaptor.forClass(CreateCompletionCopyRequest.class);
    when(copyUtkastService.createCompletion(captor.capture())).thenReturn(new CreateCompletionCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createCompletion(request, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createCompletion(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
    assertEquals(personnummer, captor.getValue().getPatient().getPersonId().getPersonnummer());
    assertEquals(fornamn, captor.getValue().getPatient().getFornamn());
    assertEquals(efternamn, captor.getValue().getPatient().getEfternamn());
    assertEquals(mellannamn, captor.getValue().getPatient().getMellannamn());
    assertEquals(postadress, captor.getValue().getPatient().getPostadress());
    assertEquals(postnummer, captor.getValue().getPatient().getPostnummer());
    assertEquals(postort, captor.getValue().getPatient().getPostort());
    assertEquals(newPersonnummer, captor.getValue().getNyttPatientPersonnummer().getPersonnummer());
}
Also used : Response(javax.ws.rs.core.Response) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) IntegrationParameters(se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateCompletionCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest) CreateCompletionCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)3 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)3 Test (org.junit.Test)2 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)2 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)2 CreateCompletionCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest)2 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)2 Response (javax.ws.rs.core.Response)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)1 Person (se.inera.intyg.infra.integration.pu.model.Person)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)1 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)1 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)1 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)1 CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)1