use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.
the class IntygModuleApiController method createReplacement.
/**
* Create a copy that is a replacement (ersättning) of an existing certificate.
*/
@POST
@Path("/{intygsTyp}/{intygsId}/ersatt")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createReplacement(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
validateReplaceAuthority(intygsTyp);
LOG.debug("Attempting to create a replacement of {} with id '{}'", intygsTyp, orgIntygsId);
if (!request.isValid()) {
LOG.error("Request to create replacement of '{}' is not valid", orgIntygsId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
}
CreateReplacementCopyRequest serviceRequest = createReplacementCopyRequest(orgIntygsId, intygsTyp, request);
CreateReplacementCopyResponse serviceResponse = copyUtkastService.createReplacementCopy(serviceRequest);
LOG.debug("Created a new replacement draft with id: '{}' and type: {}, replacing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
return Response.ok().entity(response).build();
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.
the class IntygModuleApiController method createRenewal.
/**
* Create a copy that is a renewal of an existing certificate.
*
* @param request
* @param intygsTyp
* @param orgIntygsId
* @return
*/
@POST
@Path("/{intygsTyp}/{intygsId}/fornya")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createRenewal(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
validateCopyAuthority(intygsTyp);
LOG.debug("Attempting to create a renewal of {} with id '{}'", intygsTyp, 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 renewal of '{}' is not valid", orgIntygsId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
}
CreateRenewalCopyRequest serviceRequest = createRenewalCopyRequest(orgIntygsId, intygsTyp, request);
CreateRenewalCopyResponse serviceResponse = copyUtkastService.createRenewalCopy(serviceRequest);
LOG.debug("Created a new draft with id: '{}' and type: {}, renewing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
return Response.ok().entity(response).build();
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.
the class IntygModuleApiController method createCompletion.
/**
* Create a copy that completes an existing certificate.
*/
@POST
@Path("/{intygsTyp}/{intygsId}/komplettera")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON + UTF_8_CHARSET)
public Response createCompletion(CopyIntygRequest request, @PathParam("intygsTyp") String intygsTyp, @PathParam("intygsId") String orgIntygsId) {
authoritiesValidator.given(getWebCertUserService().getUser(), intygsTyp).features(AuthoritiesConstants.FEATURE_FORNYA_INTYG).privilege(AuthoritiesConstants.PRIVILEGE_SVARA_MED_NYTT_INTYG).orThrow();
LOG.debug("Attempting to create a completion of {} with id '{}'", intygsTyp, orgIntygsId);
if (!request.isValid()) {
LOG.error("Request to create completion of '{}' is not valid", orgIntygsId);
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Missing vital arguments in payload");
}
String meddelandeId = arendeService.getLatestMeddelandeIdForCurrentCareUnit(orgIntygsId);
CreateCompletionCopyRequest serviceRequest = createCompletionCopyRequest(orgIntygsId, intygsTyp, meddelandeId, request);
CreateCompletionCopyResponse serviceResponse = copyUtkastService.createCompletion(serviceRequest);
LOG.debug("Created a new draft with id: '{}' and type: {}, completing certificate with id '{}'.", serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType(), orgIntygsId);
CopyIntygResponse response = new CopyIntygResponse(serviceResponse.getNewDraftIntygId(), serviceResponse.getNewDraftIntygType());
return Response.ok().entity(response).build();
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testCreateRenewal.
@Test
public void testCreateRenewal() {
final String newDraftIntygId = "newDraftIntygId";
final String personnummer = "191212121212";
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";
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_FORNYA_INTYG);
user.setOrigin("NORMAL");
ArgumentCaptor<CreateRenewalCopyRequest> captor = ArgumentCaptor.forClass(CreateRenewalCopyRequest.class);
when(copyUtkastService.createRenewalCopy(captor.capture())).thenReturn(new CreateRenewalCopyResponse(CERTIFICATE_TYPE, newDraftIntygId, CERTIFICATE_ID));
when(webcertUserService.getUser()).thenReturn(user);
Response response = moduleApiController.createRenewal(request, CERTIFICATE_TYPE, CERTIFICATE_ID);
verify(copyUtkastService).createRenewalCopy(any());
verifyNoMoreInteractions(copyUtkastService);
assertEquals(newDraftIntygId, ((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());
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.CopyIntygResponse in project webcert by sklintyg.
the class IntygModuleApiControllerTest method testCreateRenewalWithNewPatientInfo.
@Test
public void testCreateRenewalWithNewPatientInfo() {
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 newPersonnummer = "201212121212";
CopyIntygRequest copyIntygRequest = new CopyIntygRequest();
copyIntygRequest.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_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());
assertEquals(newPersonnummer, captor.getValue().getNyttPatientPersonnummer().getPersonnummer());
}
Aggregations