Search in sources :

Example 1 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImpl method buildCompletionUtkastBuilderResponse.

private CopyUtkastBuilderResponse buildCompletionUtkastBuilderResponse(CreateCompletionCopyRequest copyRequest, String originalIntygId, boolean addRelation) throws ModuleNotFoundException, ModuleException {
    Person patientDetails = updatePatientDetails(copyRequest);
    CopyUtkastBuilderResponse builderResponse;
    if (utkastRepository.exists(originalIntygId)) {
        builderResponse = copyCompletionUtkastBuilder.populateCopyUtkastFromOrignalUtkast(copyRequest, patientDetails, addRelation, false, false);
    } else {
        builderResponse = copyCompletionUtkastBuilder.populateCopyUtkastFromSignedIntyg(copyRequest, patientDetails, addRelation, false, false);
    }
    return builderResponse;
}
Also used : CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Person(se.inera.intyg.infra.integration.pu.model.Person)

Example 2 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImpl method buildReplacementUtkastBuilderResponse.

private CopyUtkastBuilderResponse buildReplacementUtkastBuilderResponse(CreateReplacementCopyRequest replacementCopyRequest, String originalIntygId) throws ModuleNotFoundException, ModuleException {
    Person patientDetails = updatePatientDetails(replacementCopyRequest);
    CopyUtkastBuilderResponse builderResponse;
    if (utkastRepository.exists(originalIntygId)) {
        builderResponse = createReplacementUtkastBuilder.populateCopyUtkastFromOrignalUtkast(replacementCopyRequest, patientDetails, true, replacementCopyRequest.isCoherentJournaling(), true);
    } else {
        builderResponse = createReplacementUtkastBuilder.populateCopyUtkastFromSignedIntyg(replacementCopyRequest, patientDetails, true, replacementCopyRequest.isCoherentJournaling(), true);
    }
    return builderResponse;
}
Also used : CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Person(se.inera.intyg.infra.integration.pu.model.Person)

Example 3 with CopyUtkastBuilderResponse

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

the class CopyUtkastServiceImpl method createReplacementCopy.

@Override
@Transactional("jpaTransactionManager")
public CreateReplacementCopyResponse createReplacementCopy(CreateReplacementCopyRequest replacementRequest) {
    String originalIntygId = replacementRequest.getOriginalIntygId();
    WebCertUser user = userService.getUser();
    LOG.debug("Creating replacement copy of intyg '{}'", originalIntygId);
    try {
        if (intygService.isRevoked(replacementRequest.getOriginalIntygId(), replacementRequest.getTyp(), replacementRequest.isCoherentJournaling())) {
            LOG.debug("Cannot create replacement certificate for id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Can not create replacement copy - Original certificate is revoked");
        }
        verifyNotReplaced(replacementRequest.getOriginalIntygId(), "create replacement");
        verifyNotComplementedWithSigned(replacementRequest.getOriginalIntygId(), "create replacement");
        CopyUtkastBuilderResponse builderResponse = buildReplacementUtkastBuilderResponse(replacementRequest, originalIntygId);
        if (replacementRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedReplacement(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateReplacementCopyResponse(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) 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) CreateReplacementCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateReplacementCopyResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CopyUtkastBuilderResponse

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

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

the class CopyUtkastServiceImpl method createRenewalCopy.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastService#createCopy(se.inera.intyg.webcert.web.service.utkast.
     * dto.
     * CreateRenewalCopyRequest)
     */
@Override
public CreateRenewalCopyResponse createRenewalCopy(CreateRenewalCopyRequest copyRequest) {
    String originalIntygId = copyRequest.getOriginalIntygId();
    LOG.debug("Creating renewal for intyg '{}'", 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 renew certificate with id '{}', the certificate is revoked", originalIntygId);
            throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "Original certificate is revoked");
        }
        verifyNotReplacedWithSigned(copyRequest.getOriginalIntygId(), "create renewal");
        verifyNotComplementedWithSigned(copyRequest.getOriginalIntygId(), "create renewal");
        CopyUtkastBuilderResponse builderResponse = buildRenewalUtkastBuilderResponse(copyRequest, originalIntygId, coherentJournaling);
        if (copyRequest.isDjupintegrerad()) {
            checkIntegreradEnhet(builderResponse);
        }
        Utkast savedUtkast = saveAndNotify(builderResponse, user);
        monitoringService.logIntygCopiedRenewal(savedUtkast.getIntygsId(), originalIntygId);
        return new CreateRenewalCopyResponse(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) CreateRenewalCopyResponse(se.inera.intyg.webcert.web.service.utkast.dto.CreateRenewalCopyResponse) 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)

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