Search in sources :

Example 1 with UtkastStatus

use of se.inera.intyg.webcert.common.model.UtkastStatus in project webcert by sklintyg.

the class UtkastRepositoryTest method testGetIntygsStatus.

@Test
public void testGetIntygsStatus() {
    Utkast intyg3 = utkastRepository.save(UtkastTestUtil.buildUtkast(UtkastTestUtil.ENHET_3_ID, UtkastStatus.DRAFT_COMPLETE));
    UtkastStatus status = utkastRepository.getIntygsStatus(intyg3.getIntygsId());
    assertThat(status, is(UtkastStatus.DRAFT_COMPLETE));
}
Also used : UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Test(org.junit.Test)

Example 2 with UtkastStatus

use of se.inera.intyg.webcert.common.model.UtkastStatus in project webcert by sklintyg.

the class IntygResource method deleteDraftsByEnhet.

@DELETE
@Path("/enhet/{enhetsId}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteDraftsByEnhet(@PathParam("enhetsId") String enhetsId) {
    List<String> enhetsIds = new ArrayList<>();
    enhetsIds.add(enhetsId);
    List<UtkastStatus> statuses = new ArrayList<>();
    statuses.add(UtkastStatus.DRAFT_INCOMPLETE);
    statuses.add(UtkastStatus.DRAFT_COMPLETE);
    List<Utkast> utkast = utkastRepository.findByEnhetsIdsAndStatuses(enhetsIds, statuses);
    if (utkast != null) {
        for (Utkast u : utkast) {
            deleteDraftAndRelatedQAs(u);
        }
    }
    return Response.ok().build();
}
Also used : UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) XPath(javax.xml.xpath.XPath) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 3 with UtkastStatus

use of se.inera.intyg.webcert.common.model.UtkastStatus in project webcert by sklintyg.

the class UtkastServiceImpl method saveDraft.

@Override
@Transactional("jpaTransactionManager")
public SaveDraftResponse saveDraft(String intygId, long version, String draftAsJson, boolean createPdlLogEvent) {
    LOG.debug("Saving and validating utkast '{}'", intygId);
    Utkast utkast = utkastRepository.findOne(intygId);
    if (utkast == null) {
        LOG.warn("Utkast '{}' was not found", intygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.DATA_NOT_FOUND, "The utkast 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 a draft
    if (!isTheDraftStillADraft(utkast.getStatus())) {
        LOG.error("Utkast '{}' can not be updated since it is no longer in draft mode", intygId);
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INVALID_STATE, "This utkast can not be updated since it is no longer in draft mode");
    }
    String intygType = utkast.getIntygsTyp();
    // Keep persisted json for comparsion
    String persistedJson = utkast.getModel();
    // Update draft with user information
    updateUtkastModel(utkast, draftAsJson);
    // Is draft valid?
    DraftValidation draftValidation = validateDraft(intygId, intygType, draftAsJson);
    UtkastStatus utkastStatus = draftValidation.isDraftValid() ? UtkastStatus.DRAFT_COMPLETE : UtkastStatus.DRAFT_INCOMPLETE;
    utkast.setStatus(utkastStatus);
    // Save the updated draft
    utkast = saveDraft(utkast);
    LOG.debug("Utkast '{}' updated", utkast.getIntygsId());
    if (createPdlLogEvent) {
        LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(utkast);
        logService.logUpdateIntyg(logRequest);
        monitoringService.logUtkastEdited(utkast.getIntygsId(), utkast.getIntygsTyp());
    }
    // Notify stakeholders when a draft has been changed/updated
    try {
        ModuleApi moduleApi = moduleRegistry.getModuleApi(intygType);
        if (moduleApi.shouldNotify(persistedJson, draftAsJson)) {
            LOG.debug("*** Detected changes in model, sending notification! ***");
            sendNotification(utkast, Event.CHANGED);
        }
    } catch (ModuleException | ModuleNotFoundException e) {
        throw new WebCertServiceException(WebCertServiceErrorCodeEnum.MODULE_PROBLEM, e);
    }
    // Flush JPA changes, to make sure the version attribute is updated
    utkastRepository.flush();
    return new SaveDraftResponse(utkast.getVersion(), utkastStatus);
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) ModuleNotFoundException(se.inera.intyg.common.support.modules.registry.ModuleNotFoundException) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) OptimisticLockException(javax.persistence.OptimisticLockException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) WebCertServiceException(se.inera.intyg.webcert.common.service.exception.WebCertServiceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with UtkastStatus

use of se.inera.intyg.webcert.common.model.UtkastStatus in project webcert by sklintyg.

the class AbstractUtkastBuilder method populateCopyUtkastFromSignedIntyg.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromSignedIntyg(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
public CopyUtkastBuilderResponse populateCopyUtkastFromSignedIntyg(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    String originalIntygsTyp = copyRequest.getOriginalIntygTyp();
    String intygsTyp = copyRequest.getTyp();
    IntygContentHolder signedIntygHolder = intygService.fetchIntygData(orignalIntygsId, originalIntygsTyp, coherentJournaling);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(originalIntygsTyp);
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(signedIntygHolder.getContents());
    } catch (IOException e) {
        throw new ModuleException("Could not convert orignal certificate to Utlatande", e);
    }
    GrundData grundData = signedIntygHolder.getUtlatande().getGrundData();
    se.inera.intyg.common.support.model.common.internal.Vardenhet vardenhet = grundData.getSkapadAv().getVardenhet();
    if (coherentJournaling && enforceEnhet) {
        verifyEnhetsAuth(vardenhet.getVardgivare().getVardgivarid(), vardenhet.getEnhetsid(), true);
    }
    LOG.debug("Populating copy with details from signed Intyg '{}'", orignalIntygsId);
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(vardenhet.getEnhetsid());
    builderResponse.setOrginalEnhetsNamn(vardenhet.getEnhetsnamn());
    builderResponse.setOrginalVardgivarId(vardenhet.getVardgivare().getVardgivarid());
    builderResponse.setOrginalVardgivarNamn(vardenhet.getVardgivare().getVardgivarnamn());
    ModuleApi moduleApi = moduleRegistry.getModuleApi(intygsTyp);
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, intygsTyp, addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        se.inera.intyg.common.support.model.common.internal.Patient patient = signedIntygHolder.getUtlatande().getGrundData().getPatient();
        populatePatientDetailsFromPatient(utkast, patient);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Vardenhet(se.inera.intyg.common.support.model.common.internal.Vardenhet) IOException(java.io.IOException) Relation(se.inera.intyg.common.support.model.common.internal.Relation) IntygContentHolder(se.inera.intyg.webcert.web.service.intyg.dto.IntygContentHolder) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) GrundData(se.inera.intyg.common.support.model.common.internal.GrundData) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Patient(se.inera.intyg.common.support.model.common.internal.Patient)

Example 5 with UtkastStatus

use of se.inera.intyg.webcert.common.model.UtkastStatus in project webcert by sklintyg.

the class AbstractUtkastBuilder method populateCopyUtkastFromOrignalUtkast.

/*
     * (non-Javadoc)
     *
     * @see
     * se.inera.intyg.webcert.web.service.utkast.CopyUtkastBuilder#populateCopyUtkastFromOrignalUtkast(se.inera.intyg.
     * webcert.web.service.utkast.dto.CreateNewDraftCopyRequest, se.inera.intyg.webcert.integration.pu.model.Person)
     */
@Override
@Transactional(value = "jpaTransactionManager", readOnly = true)
public CopyUtkastBuilderResponse populateCopyUtkastFromOrignalUtkast(T copyRequest, Person patientDetails, boolean addRelation, boolean coherentJournaling, boolean enforceEnhet) throws ModuleNotFoundException, ModuleException {
    String orignalIntygsId = copyRequest.getOriginalIntygId();
    Utkast orgUtkast = utkastRepository.findOne(orignalIntygsId);
    ModuleApi orgModuleApi = moduleRegistry.getModuleApi(copyRequest.getOriginalIntygTyp());
    Utlatande orgUtlatande;
    try {
        orgUtlatande = orgModuleApi.getUtlatandeFromJson(orgUtkast.getModel());
    } catch (IOException e) {
        throw new ModuleException("Could not convert original certificate to Utlatande", e);
    }
    // Perform enhets auth if coherent journaling is not active.
    if (!coherentJournaling || enforceEnhet) {
        verifyEnhetsAuth(orgUtkast.getVardgivarId(), orgUtkast.getEnhetsId(), true);
    } else {
        LogRequest logRequest = LogRequestFactory.createLogRequestFromUtkast(orgUtkast, coherentJournaling);
        logService.logReadIntyg(logRequest);
    }
    CopyUtkastBuilderResponse builderResponse = new CopyUtkastBuilderResponse();
    builderResponse.setOrginalEnhetsId(orgUtkast.getEnhetsId());
    builderResponse.setOrginalEnhetsNamn(orgUtkast.getEnhetsNamn());
    builderResponse.setOrginalVardgivarId(orgUtkast.getVardgivarId());
    builderResponse.setOrginalVardgivarNamn(orgUtkast.getVardgivarNamn());
    LOG.debug("Populating copy with details from Utkast '{}'", orignalIntygsId);
    ModuleApi moduleApi = moduleRegistry.getModuleApi(copyRequest.getTyp());
    // Set relation to null if not applicable
    Relation relation = createRelation(copyRequest);
    String newDraftCopyId = intygsIdStrategy.createId();
    String draftCopyJson = getInternalModel(orgUtlatande, moduleApi, copyRequest, patientDetails, relation, newDraftCopyId);
    UtkastStatus utkastStatus = validateDraft(moduleApi, draftCopyJson);
    Utkast utkast = buildUtkastCopy(copyRequest, newDraftCopyId, copyRequest.getTyp(), addRelation, relation, draftCopyJson, utkastStatus);
    if (patientDetails != null) {
        populatePatientDetailsFromPerson(utkast, patientDetails);
    } else {
        populatePatientDetailsFromUtkast(utkast, orgUtkast);
    }
    replacePatientPersonnummerWithNew(utkast, copyRequest);
    builderResponse.setUtkastCopy(utkast);
    return builderResponse;
}
Also used : ModuleApi(se.inera.intyg.common.support.modules.support.api.ModuleApi) LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) UtkastStatus(se.inera.intyg.webcert.common.model.UtkastStatus) Relation(se.inera.intyg.common.support.model.common.internal.Relation) CopyUtkastBuilderResponse(se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) Utlatande(se.inera.intyg.common.support.model.common.internal.Utlatande) IOException(java.io.IOException) ModuleException(se.inera.intyg.common.support.modules.support.api.exception.ModuleException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UtkastStatus (se.inera.intyg.webcert.common.model.UtkastStatus)6 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)6 ModuleApi (se.inera.intyg.common.support.modules.support.api.ModuleApi)3 ModuleException (se.inera.intyg.common.support.modules.support.api.exception.ModuleException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Relation (se.inera.intyg.common.support.model.common.internal.Relation)2 Utlatande (se.inera.intyg.common.support.model.common.internal.Utlatande)2 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)2 CopyUtkastBuilderResponse (se.inera.intyg.webcert.web.service.utkast.dto.CopyUtkastBuilderResponse)2 OptimisticLockException (javax.persistence.OptimisticLockException)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 XPath (javax.xml.xpath.XPath)1 Test (org.junit.Test)1 GrundData (se.inera.intyg.common.support.model.common.internal.GrundData)1 Patient (se.inera.intyg.common.support.model.common.internal.Patient)1 Vardenhet (se.inera.intyg.common.support.model.common.internal.Vardenhet)1