Search in sources :

Example 41 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class UtkastServiceImpl method deleteUnsignedDraft.

@Override
@Transactional
public void deleteUnsignedDraft(String intygId, long version) {
    LOG.debug("Deleting utkast '{}'", intygId);
    Utkast utkast = utkastRepository.findOne(intygId);
    // check that the draft exists
    if (utkast == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The draft could not be deleted since it could not be found");
    }
    // check that the draft hasn't been modified concurrently
    if (utkast.getVersion() != version) {
        LOG.debug("Utkast '{}' was concurrently modified", intygId);
        throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
    }
    // check that the draft is still unsigned
    if (!isTheDraftStillADraft(utkast.getStatus())) {
        LOG.error("Intyg '{}' can not be deleted since it is no longer a draft", intygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "The draft can not be deleted since it is no longer a draft");
    }
    // Delete draft from repository
    utkastRepository.delete(utkast);
    LOG.debug("Deleted draft '{}'", utkast.getIntygsId());
    // Audit log
    monitoringService.logUtkastDeleted(utkast.getIntygsId(), utkast.getIntygsTyp());
    // Notify stakeholders when a draft is deleted
    sendNotification(utkast, Event.DELETED);
    LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
    logService.logDeleteIntyg(logRequest);
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class UtkastServiceImpl method createNewDraft.

@Override
public Utkast createNewDraft(CreateNewDraftRequest request) {
    populateRequestWithIntygId(request);
    request.setStatus(UtkastStatus.DRAFT_INCOMPLETE);
    String intygType = request.getIntygType();
    CreateNewDraftHolder draftRequest = createModuleRequest(request);
    String intygJsonModel = getPopulatedModelFromIntygModule(intygType, draftRequest);
    Utkast savedUtkast = persistNewDraft(request, intygJsonModel);
    // Persist the referens if supplied
    if (!Strings.isNullOrEmpty(request.getReferens())) {
        referensService.saveReferens(request.getIntygId(), request.getReferens());
    }
    monitoringService.logUtkastCreated(savedUtkast.getIntygsId(), savedUtkast.getIntygsTyp(), savedUtkast.getEnhetsId(), savedUtkast.getSkapadAv().getHsaId());
    // Notify stakeholders when a draft has been created
    sendNotification(savedUtkast, Event.CREATED);
    // Create a PDL log for this action
    LogUser logUser = createLogUser(request);
    logCreateDraftPDL(savedUtkast, logUser);
    return savedUtkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) LogUser(se.inera.intyg.webcert.web.service.log.dto.LogUser) CreateNewDraftHolder(se.inera.intyg.common.support.modules.support.api.dto.CreateNewDraftHolder)

Example 43 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class UtkastServiceImpl method setNotifiedOnDraft.

@Override
@Transactional
public Utkast setNotifiedOnDraft(String intygsId, long version, Boolean notified) {
    Utkast utkast = utkastRepository.findOne(intygsId);
    if (utkast == null) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Could not find Utkast with id: " + intygsId);
    }
    // check that the draft hasn't been modified concurrently
    if (utkast.getVersion() != version) {
        LOG.debug("Utkast '{}' was concurrently modified", intygsId);
        throw new OptimisticLockException(utkast.getSenastSparadAv().getNamn());
    }
    utkast.setVidarebefordrad(notified);
    return saveDraft(utkast);
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class UtkastServiceImpl method setKlarForSigneraAndSendStatusMessage.

@Override
@Transactional
public void setKlarForSigneraAndSendStatusMessage(String intygsId, String intygType) {
    validateUserAllowedToSendKFSignNotification(intygsId, intygType);
    Utkast utkast = getIntygAsDraft(intygsId, intygType);
    if (utkast.getKlartForSigneringDatum() == null) {
        notificationService.sendNotificationForDraftReadyToSign(utkast);
        utkast.setKlartForSigneringDatum(LocalDateTime.now());
        monitoringService.logUtkastMarkedAsReadyToSignNotificationSent(intygsId, intygType);
        saveDraft(utkast);
        LOG.debug("Sent, saved and logged utkast '{}' ready to sign", intygsId);
    }
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with Utkast

use of se.inera.intyg.webcert.persistence.utkast.model.Utkast in project webcert by sklintyg.

the class UtkastServiceImpl method getIntygAsDraft.

private Utkast getIntygAsDraft(String intygsId, String intygType) {
    LOG.debug("Fetching utkast '{}'", intygsId);
    Utkast utkast = utkastRepository.findOneByIntygsIdAndIntygsTyp(intygsId, intygType);
    if (utkast == null) {
        LOG.warn("Utkast '{}' of type {} was not found", intygsId, intygType);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "Utkast could not be found");
    }
    return utkast;
}
Also used : Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException)

Aggregations

Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)171 Test (org.junit.Test)88 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)34 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 Personnummer (se.inera.intyg.schemas.contract.Personnummer)21 Signatur (se.inera.intyg.webcert.persistence.utkast.model.Signatur)21 VardpersonReferens (se.inera.intyg.webcert.persistence.utkast.model.VardpersonReferens)21 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)18 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)17 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)16 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)14 CreateNewDraftRequest (se.inera.intyg.webcert.web.service.utkast.dto.CreateNewDraftRequest)13 Patient (se.inera.intyg.common.support.model.common.internal.Patient)12 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)12 ListIntygEntry (se.inera.intyg.webcert.web.web.controller.api.dto.ListIntygEntry)12 Transactional (org.springframework.transaction.annotation.Transactional)11 ModuleNotFoundException (se.inera.intyg.common.support.modules.registry.ModuleNotFoundException)11 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)11 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)10 ArrayList (java.util.ArrayList)9