Search in sources :

Example 1 with RejectionNote

use of org.dcm4chee.arc.conf.RejectionNote in project dcm4chee-arc-light by dcm4che.

the class RejectionServiceImpl method onExport.

public void onExport(@Observes ExportContext ctx) {
    ExporterDescriptor desc = ctx.getExporter().getExporterDescriptor();
    if (ctx.getException() != null || !desc.isRejectForDataRetentionExpiry() || ctx.getOutcome().getStatus() != Task.Status.COMPLETED)
        return;
    ApplicationEntity ae = getApplicationEntity(desc.getAETitle());
    if (ae == null || !ae.isInstalled()) {
        LOG.warn("No such Application Entity: {}", desc.getAETitle());
        return;
    }
    ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
    RejectionNote rn = arcDev.getRejectionNote(RejectionNote.Type.DATA_RETENTION_POLICY_EXPIRED);
    if (rn == null) {
        LOG.warn("Data Retention Policy Expired Rejection Note not configured.");
        return;
    }
    LOG.info("Export completed, invoke rejection of objects.");
    try {
        if (ejb.claimExpired(ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ExpirationState.REJECTED))
            reject(ae, ctx.getAETitle(), ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID(), rn, ctx.getHttpServletRequestInfo());
    } catch (Exception e) {
        LOG.warn("Rejection of Expired Study[UID={}], Series[UID={}], SOPInstance[UID={}] failed.\n", ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID(), e);
        ejb.claimExpired(ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ExpirationState.FAILED_TO_REJECT);
    }
}
Also used : ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor) RejectionNote(org.dcm4chee.arc.conf.RejectionNote)

Example 2 with RejectionNote

use of org.dcm4chee.arc.conf.RejectionNote in project dcm4chee-arc-light by dcm4che.

the class QueryRejectionNotes method query.

@GET
@NoCache
@Produces("application/json")
public Response query() {
    logRequest();
    try {
        return Response.ok((StreamingOutput) out -> {
            JsonGenerator gen = Json.createGenerator(out);
            gen.writeStartArray();
            for (RejectionNote rjNote : sortedRejectionNotes()) {
                Code code = rjNote.getRejectionNoteCode();
                JsonWriter writer = new JsonWriter(gen);
                gen.writeStartObject();
                writer.writeNotNullOrDef("label", rjNote.getRejectionNoteLabel(), null);
                writer.writeNotNullOrDef("type", rjNote.getRejectionNoteType(), null);
                writer.writeNotNullOrDef("codeValue", code.getCodeValue(), null);
                writer.writeNotNullOrDef("codingSchemeDesignator", code.getCodingSchemeDesignator(), null);
                writer.writeNotNullOrDef("codeMeaning", code.getCodeMeaning(), null);
                gen.writeEnd();
            }
            gen.writeEnd();
            gen.flush();
        }).build();
    } catch (IllegalStateException e) {
        return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) Code(org.dcm4che3.data.Code) JsonWriter(org.dcm4che3.conf.json.JsonWriter) RejectionNote(org.dcm4chee.arc.conf.RejectionNote) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 3 with RejectionNote

use of org.dcm4chee.arc.conf.RejectionNote in project dcm4chee-arc-light by dcm4che.

the class RejectRS method reject.

private Response reject(String studyUID, String seriesUID, String objectUID, String findscp, String codeValue, String designator) {
    logRequest();
    ApplicationEntity localAE = device.getApplicationEntity(aet, true);
    if (localAE == null || !localAE.isInstalled())
        return errResponse("No such Application Entity: " + aet, Response.Status.NOT_FOUND);
    try {
        ApplicationEntity storescpAE = aeCache.findApplicationEntity(storescp);
        ArchiveDeviceExtension arcDev = localAE.getDevice().getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
        Code code = new Code(codeValue, designator, null, "?");
        RejectionNote rjNote = arcDev.getRejectionNote(code);
        if (rjNote == null)
            return errResponse("No such Rejection Note : " + code, Response.Status.NOT_FOUND);
        List<Attributes> matches;
        try {
            matches = findSCU.findInstance(localAE, findscp, priority(), studyUID, seriesUID, objectUID, Tag.SOPClassUID, Tag.SOPInstanceUID, Tag.StudyDate, Tag.StudyTime, Tag.AccessionNumber, Tag.IssuerOfAccessionNumberSequence, Tag.PatientID, Tag.IssuerOfPatientID, Tag.PatientName, Tag.PatientBirthDate, Tag.PatientSex, Tag.StudyID, Tag.StudyInstanceUID, Tag.SeriesInstanceUID);
        } catch (DicomServiceException e) {
            return failed(e.getStatus(), e.getMessage(), null);
        } catch (IOException e) {
            return errResponse(e.getMessage(), Response.Status.BAD_GATEWAY);
        } catch (Exception e) {
            return failed(Status.ProcessingFailure, e.getMessage(), null);
        }
        if (matches.isEmpty())
            return errResponse("No matches found for rejection", Response.Status.NOT_FOUND);
        KOSBuilder builder = new KOSBuilder(rjNote.getRejectionNoteCode(), 999, 1);
        matches.forEach(builder::addInstanceRef);
        Attributes kos = builder.getAttributes();
        try {
            Attributes cmd = storeSCU.store(localAE, storescpAE, priority(), kos);
            int status = cmd.getInt(Tag.Status, -1);
            String errorComment = cmd.getString(Tag.ErrorComment);
            boolean studyDeleted = seriesUID == null;
            rejectionNoteSentEvent.fire(new RejectionNoteSent(request, localAE, storescpAE, kos, studyDeleted, status, errorComment));
            switch(status) {
                case Status.Success:
                case Status.CoercionOfDataElements:
                case Status.ElementsDiscarded:
                case Status.DataSetDoesNotMatchSOPClassWarning:
                    return success(status, errorComment, matches);
                default:
                    return failed(status, errorComment, matches);
            }
        } catch (IOException e) {
            return errResponse(e.getMessage(), Response.Status.BAD_GATEWAY);
        } catch (Exception e) {
            return failed(Status.ProcessingFailure, e.getMessage(), matches);
        }
    } catch (ConfigurationException e) {
        return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : Attributes(org.dcm4che3.data.Attributes) IOException(java.io.IOException) KOSBuilder(org.dcm4chee.arc.query.util.KOSBuilder) RejectionNoteSent(org.dcm4chee.arc.event.RejectionNoteSent) Code(org.dcm4che3.data.Code) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) IOException(java.io.IOException) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) RejectionNote(org.dcm4chee.arc.conf.RejectionNote)

Example 4 with RejectionNote

use of org.dcm4chee.arc.conf.RejectionNote in project dcm4chee-arc-light by dcm4che.

the class StgCmtEJB method isRejectionNoteDataRetentionPolicyExpired.

private boolean isRejectionNoteDataRetentionPolicyExpired(Instance inst) {
    if (!inst.getSopClassUID().equals(UID.KeyObjectSelectionDocumentStorage) || inst.getConceptNameCode() == null)
        return false;
    ArchiveDeviceExtension arcdev = device.getDeviceExtension(ArchiveDeviceExtension.class);
    RejectionNote rjnote = arcdev.getRejectionNote(inst.getConceptNameCode().getCode());
    return rjnote != null && rjnote.getRejectionNoteType() == RejectionNote.Type.DATA_RETENTION_POLICY_EXPIRED;
}
Also used : ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) RejectionNote(org.dcm4chee.arc.conf.RejectionNote)

Example 5 with RejectionNote

use of org.dcm4chee.arc.conf.RejectionNote in project dcm4chee-arc-light by dcm4che.

the class AuditService method spoolStoreEvent.

void spoolStoreEvent(StoreContext ctx) {
    try {
        if (ctx.getRejectedInstance() != null) {
            LOG.info("Suppress audit on receive of instances rejected by a previous received Rejection Note : {}", ctx.getRejectedInstance());
            return;
        }
        RejectionNote rejectionNote = ctx.getRejectionNote();
        if (rejectionNote != null && !rejectionNote.isRevokeRejection()) {
            spoolInstancesDeleted(ctx, null);
            return;
        }
        if (isDuplicateReceivedInstance(ctx)) {
            if (rejectionNote != null && rejectionNote.isRevokeRejection())
                spoolInstancesStored(ctx);
            return;
        }
        if (ctx.getAttributes() == null) {
            LOG.warn("Instances stored is not audited as store context attributes are not set. " + (ctx.getException() != null ? ctx.getException().getMessage() : null));
            return;
        }
        spoolInstancesStored(ctx);
    } catch (Exception e) {
        LOG.warn("Failed to spool Store Event.\n", e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) IOException(java.io.IOException) RejectionNote(org.dcm4chee.arc.conf.RejectionNote)

Aggregations

RejectionNote (org.dcm4chee.arc.conf.RejectionNote)8 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)5 Code (org.dcm4che3.data.Code)4 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)3 IOException (java.io.IOException)2 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 JsonGenerator (javax.json.stream.JsonGenerator)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 JsonWriter (org.dcm4che3.conf.json.JsonWriter)1 Attributes (org.dcm4che3.data.Attributes)1 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)1 MergeMWLQueryParam (org.dcm4chee.arc.MergeMWLQueryParam)1 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)1 ExporterDescriptor (org.dcm4chee.arc.conf.ExporterDescriptor)1 RejectionNoteSent (org.dcm4chee.arc.event.RejectionNoteSent)1 ProcedureContext (org.dcm4chee.arc.procedure.ProcedureContext)1 KOSBuilder (org.dcm4chee.arc.query.util.KOSBuilder)1