Search in sources :

Example 1 with CreateUtkastFromTemplateResponse

use of se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse 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 2 with CreateUtkastFromTemplateResponse

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

the class CopyUtkastServiceImpl method createUtkastFromTemplate.

@Override
public CreateUtkastFromTemplateResponse createUtkastFromTemplate(CreateUtkastFromTemplateRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating utkast from template certificate '{}'", originalIntygId);
    WebCertUser user = userService.getUser();
    boolean coherentJournaling = user != null && user.getParameters() != null && user.getParameters().isSjf();
    try {
        if (intygService.isRevoked(copyRequest.getOriginalIntygId(), copyRequest.getOriginalIntygTyp(), coherentJournaling)) {
            LOG.debug("Cannot create utkast from template certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        String intygsTyp = copyRequest.getTyp();
        if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG, AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG, AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
            Personnummer personnummer = copyRequest.containsNyttPatientPersonnummer() ? copyRequest.getNyttPatientPersonnummer() : copyRequest.getPatient().getPersonId();
            Map<String, Map<String, Boolean>> intygstypToStringToBoolean = utkastService.checkIfPersonHasExistingIntyg(personnummer, user);
            Boolean utkastExists = intygstypToStringToBoolean.get("utkast").get(intygsTyp);
            Boolean intygExists = intygstypToStringToBoolean.get("intyg").get(intygsTyp);
            if (utkastExists != null && utkastExists) {
                if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_UTKAST_INOM_VG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Drafts of this type must be unique within this caregiver.");
                }
            }
            if (intygExists != null) {
                if (authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be globally unique.");
                } else if (intygExists && authoritiesValidator.given(user, intygsTyp).features(AuthoritiesConstants.FEATURE_UNIKT_INTYG_INOM_VG).isVerified()) {
                    throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Certificates of this type must be unique within this caregiver.");
                }
            }
        }
        verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create utkast from template");
        CopyUtkastBuilderResponse builderResponse = buildUtkastFromTemplateBuilderResponse(copyRequest, originalIntygId, true, coherentJournaling);
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        return new CreateUtkastFromTemplateResponse(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 : CreateUtkastFromTemplateResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Personnummer(se.inera.intyg.schemas.contract.Personnummer) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Map(java.util.Map) WebCertUser(se.inera.intyg.webcert.web.service.user.dto.WebCertUser)

Aggregations

WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)2 CreateUtkastFromTemplateResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateResponse)2 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)1 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)1 Personnummer (se.inera.intyg.schemas.contract.Personnummer)1 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)1 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)1 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)1 CreateCompletionCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateCompletionCopyResponse)1 CreateRenewalCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse)1 CreateReplacementCopyResponse (se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse)1 CreateUtkastFromTemplateRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateUtkastFromTemplateRequest)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