Search in sources :

Example 6 with CopyIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateUtkastFromTemplate.

@Test
public void testCreateUtkastFromTemplate() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    final String newCertificateType = "newCertificateType";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    addFeatures(user, newCertificateType, AuthoritiesConstants.FEATURE_HANTERA_INTYGSUTKAST);
    addPrivileges(user, newCertificateType, AuthoritiesConstants.PRIVILEGE_SKRIVA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateUtkastFromTemplateRequest> captor = ArgumentCaptor.forClass(CreateUtkastFromTemplateRequest.class);
    when(copyUtkastService.createUtkastFromTemplate(captor.capture())).thenReturn(new CreateUtkastFromTemplateResponse(newCertificateType, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createUtkastFromTemplate(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID, newCertificateType);
    verify(copyUtkastService).createUtkastFromTemplate(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
    assertEquals(newCertificateType, ((CopyIntygResponse) response.getEntity()).getIntygsTyp());
}
Also used : CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) 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) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateUtkastFromTemplateRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 7 with CopyIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse 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)

Example 8 with CopyIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testCreateRenewalCopyWithNewPatientReservnummerDefaultsToPreviousPersonnummer.

/**
 * Verify that a non-valid personnr/samordningsnummer (i.e a "reservnummer") supplied as NyttPatientPersonnummer
 * will not be applied to the new utkast.
 */
@Test
public void testCreateRenewalCopyWithNewPatientReservnummerDefaultsToPreviousPersonnummer() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    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 String newReservnummer = "A20090122";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    user.setParameters(new IntegrationParameters(null, null, newReservnummer, fornamn, mellannamn, efternamn, postadress, postnummer, postort, false, false, false, true));
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_FORNYA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateRenewalCopyRequest> captor = ArgumentCaptor.forClass(CreateRenewalCopyRequest.class);
    when(copyUtkastService.createRenewalCopy(captor.capture())).thenReturn(new CreateRenewalCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createRenewal(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createRenewalCopy(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());
    assertNull(captor.getValue().getNyttPatientPersonnummer());
}
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) CreateRenewalCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser) Test(org.junit.Test)

Example 9 with CopyIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.

the class IntygModuleApiControllerTest method testReplaceIntyg.

@Test
public void testReplaceIntyg() {
    final String personnummer = "191212121212";
    final String newIntygId = "newIntygId";
    CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
    copyIntygRequest.setPatientPersonnummer(createPnr(personnummer));
    WebCertUser user = new WebCertUser();
    addFeatures(user, CERTIFICATE_TYPE, AuthoritiesConstants.FEATURE_FORNYA_INTYG);
    addPrivileges(user, CERTIFICATE_TYPE, AuthoritiesConstants.PRIVILEGE_ERSATTA_INTYG);
    user.setOrigin("NORMAL");
    ArgumentCaptor<CreateReplacementCopyRequest> captor = ArgumentCaptor.forClass(CreateReplacementCopyRequest.class);
    when(copyUtkastService.createReplacementCopy(captor.capture())).thenReturn(new CreateReplacementCopyResponse(CERTIFICATE_TYPE, newIntygId, CERTIFICATE_ID));
    when(webcertUserService.getUser()).thenReturn(user);
    Response response = moduleApiController.createReplacement(copyIntygRequest, CERTIFICATE_TYPE, CERTIFICATE_ID);
    verify(copyUtkastService).createReplacementCopy(any());
    verifyNoMoreInteractions(copyUtkastService);
    assertEquals(newIntygId, ((CopyIntygResponse) response.getEntity()).getIntygsUtkastId());
}
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) CopyIntygRequest(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest) CreateReplacementCopyRequest(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest) 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 10 with CopyIntygResponse

use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.

the class IntygModuleApiController method createUtkastFromTemplate.

/**
 * Create a new utkast from a template.
 * <p>
 * Usually (but not necessarily) the template is of a different intygType than the new utkast.
 */
@POST
@Path("/{intygsTyp}/{intygsId}/{newIntygsTyp}/create")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createUtkastFromTemplate(CopyIntygRequest request, @PathParam("intygsTyp") String orgIntygsTyp, @PathParam("intygsId") String orgIntygsId, @PathParam("newIntygsTyp") String newIntygsTyp) {
    validateCreateUtkastFromTemplateAuthority(newIntygsTyp);
    LOG.debug("Attempting to create a new certificate with type {} from certificate with type {} and id '{}'", newIntygsTyp, orgIntygsTyp, orgIntygsId);
    WebCertUser user = userService.getUser();
    boolean copyOkParam = user.getParameters() == null || user.getParameters().isCopyOk();
    if (!copyOkParam) {
        LOG.info("User is not allowed to request a copy for id '{}' due to false kopieraOK-parameter", orgIntygsId);
        final String message = "Authorization failed due to false kopieraOK-parameter";
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, message);
    }
    if (!request.isValid()) {
        LOG.error("Request to create utkast from certificate '{}' as template is not valid", orgIntygsId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
    }
    CreateUtkastFromTemplateRequest serviceRequest = createUtkastFromDifferentIntygTypeRequest(orgIntygsId, newIntygsTyp, orgIntygsTyp, request);
    CreateUtkastFromTemplateResponse serviceResponse = copyUtkastService.createUtkastFromTemplate(serviceRequest);
    LOG.debug("Created a new draft with id: '{}' and type: {} from certificate with type: {} and id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsTyp, orgIntygsId);
    CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
    return Response.ok().entity(response).build();
}
Also used : CopyIntygResponse(se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Aggregations

CopyIntygResponse (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse)10 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)8 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)6 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)6 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)6 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)6 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)6 CopyIntygRequest (se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygRequest)6 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)4 IntegrationParameters (se.inera.intyg.webcert.web.web.controller.integration.dto.IntegrationParameters)4 CreateRenewalCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyRequest)3 CreateCompletionCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyRequest)1 CreateReplacementCopyRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyRequest)1 CreateUtkastFromTemplateRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest)1