Search in sources :

Example 1 with RetrieveContext

use of org.dcm4chee.arc.retrieve.RetrieveContext in project dcm4chee-arc-light by dcm4che.

the class WadoURI method get.

@GET
public void get(@Suspended AsyncResponse ar) {
    if (contentType != null)
        contentTypes = new ContentTypes(contentType);
    logRequest();
    if (aet.equals(getApplicationEntity().getAETitle()))
        validateWebApp();
    try {
        final RetrieveContext ctx = service.newRetrieveContextWADO(HttpServletRequestInfo.valueOf(request), aet, studyUID, seriesUID, objectUID);
        if (request.getHeader(HttpHeaders.IF_MODIFIED_SINCE) == null && request.getHeader(HttpHeaders.IF_UNMODIFIED_SINCE) == null && request.getHeader(HttpHeaders.IF_MATCH) == null && request.getHeader(HttpHeaders.IF_NONE_MATCH) == null) {
            buildResponse(ar, ctx, null);
            return;
        }
        LOG.debug("Query Last Modified date of Instance");
        Date lastModified = service.getLastModified(ctx, ignorePatientUpdates());
        if (lastModified == null) {
            LOG.info("Last Modified date for Study[uid={}] Series[uid={} Instance[uid={}] is unavailable.", studyUID, seriesUID, objectUID);
            throw new WebApplicationException(errResponse("No matches found.", Response.Status.NOT_FOUND));
        }
        LOG.debug("Last Modified date: {}", lastModified);
        Response.ResponseBuilder respBuilder = evaluatePreConditions(lastModified);
        if (respBuilder == null) {
            LOG.debug("Preconditions are not met - build response");
            buildResponse(ar, ctx, lastModified);
        } else {
            Response response = respBuilder.build();
            LOG.debug("Preconditions are met - return status {}", response.getStatus());
            ar.resume(response);
        }
    } catch (Exception e) {
        ar.resume(e);
    }
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) IOException(java.io.IOException)

Example 2 with RetrieveContext

use of org.dcm4chee.arc.retrieve.RetrieveContext in project dcm4chee-arc-light by dcm4che.

the class UPSStoreSCU method calculateMatches.

private RetrieveContext calculateMatches(Attributes ups, String destAET) throws DicomServiceException {
    RetrieveContext retrieveContext = null;
    RetrieveLevel retrieveLevel = RetrieveLevel.of(UPSUtils.getScheduledProcessingCodeParameter(ups, ScopeOfAccumulation.CODE));
    Set<String> suids = new HashSet<>();
    for (Attributes inputInformation : ups.getSequence(Tag.InputInformationSequence)) {
        RetrieveContext tmp = newRetrieveContext(retrieveLevel, inputInformation, destAET, suids);
        if (tmp != null && retrieveService.calculateMatches(tmp)) {
            if (retrieveContext == null) {
                retrieveContext = tmp;
            } else {
                retrieveContext.getMatches().addAll(tmp.getMatches());
                retrieveContext.setNumberOfMatches(retrieveContext.getNumberOfMatches() + tmp.getNumberOfMatches());
            }
        }
    }
    return retrieveContext;
}
Also used : RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext)

Example 3 with RetrieveContext

use of org.dcm4chee.arc.retrieve.RetrieveContext in project dcm4chee-arc-light by dcm4che.

the class UPSStoreSCU method processA.

@Override
protected void processA(UPSContext upsCtx, Attributes ups) throws Exception {
    String destinationAE = destinationAEOf(ups);
    RetrieveContext retrieveContext = calculateMatches(ups, destinationAE);
    if (retrieveContext == null) {
        throw new UPSProcessorException(NOOP_UPS, "No matching Instances found");
    }
    if (retrieveService.restrictRetrieveAccordingTransferCapabilities(retrieveContext)) {
        storeSCU.newRetrieveTaskSTORE(retrieveContext).run();
        String outcomeDescription = retrieveContext.getOutcomeDescription();
        Attributes performedProcedure = getPerformedProcedureStep(upsCtx);
        performedProcedure.setString(Tag.PerformedProcedureStepDescription, VR.LO, outcomeDescription);
        Sequence outputInformationSeq = performedProcedure.getSequence(Tag.OutputInformationSequence);
        for (InstanceLocations match : retrieveContext.getMatches()) {
            if (!retrieveContext.isFailedSOPInstanceUID(match.getSopInstanceUID())) {
                refSOPSequence(outputInformationSeq, match, destinationAE).add(toSOPRef(match));
            }
        }
        if (retrieveContext.status() != Status.Success)
            throw new DicomServiceException(retrieveContext.status(), outcomeDescription);
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) UPSProcessorException(org.dcm4chee.arc.ups.process.UPSProcessorException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 4 with RetrieveContext

use of org.dcm4chee.arc.retrieve.RetrieveContext in project dcm4chee-arc-light by dcm4che.

the class Dcm2Hl7Exporter method scheduleMessage.

private Outcome scheduleMessage(ExportContext exportContext, HL7Application sender, HL7Application receiver) throws Exception {
    String xslStylesheetURI = descriptor.getProperties().get("XSLStylesheetURI");
    if (xslStylesheetURI == null)
        return new Outcome(Task.Status.WARNING, "Missing XSL stylesheet to convert DICOM attributes to HL7 message");
    String msgType = descriptor.getProperties().get("MessageType");
    if (msgType == null)
        return new Outcome(Task.Status.WARNING, "Missing HL7 message type");
    RetrieveContext ctx = retrieveService.newRetrieveContext(exportContext.getAETitle(), exportContext.getStudyInstanceUID(), exportContext.getSeriesInstanceUID(), exportContext.getSopInstanceUID());
    ctx.setHttpServletRequestInfo(exportContext.getHttpServletRequestInfo());
    if (!retrieveService.calculateMatches(ctx))
        return new Outcome(Task.Status.WARNING, noMatches(exportContext));
    ArchiveHL7Message hl7Msg = hl7Message(sender, receiver, ctx, msgType, xslStylesheetURI);
    HL7Message hl7MsgRsp = parseRsp(hl7Sender.sendMessage(sender, receiver, hl7Msg));
    return new Outcome(statusOf(hl7MsgRsp), hl7MsgRsp.toString());
}
Also used : Outcome(org.dcm4chee.arc.qmgt.Outcome) ArchiveHL7Message(org.dcm4chee.arc.hl7.ArchiveHL7Message) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) ArchiveHL7Message(org.dcm4chee.arc.hl7.ArchiveHL7Message) HL7Message(org.dcm4che3.hl7.HL7Message) UnparsedHL7Message(org.dcm4che3.net.hl7.UnparsedHL7Message)

Example 5 with RetrieveContext

use of org.dcm4chee.arc.retrieve.RetrieveContext in project dcm4chee-arc-light by dcm4che.

the class UpdateMetadataScheduler method updateMetadata.

private void updateMetadata(ArchiveDeviceExtension arcDev, Storage storage, Series.MetadataUpdate metadataUpdate, AtomicInteger success, AtomicInteger skipped) {
    try (RetrieveContext ctx = retrieveService.newRetrieveContextSeriesMetadata(metadataUpdate)) {
        if (claim(metadataUpdate, storage) && retrieveService.calculateMatches(ctx)) {
            LOG.debug("Creating/Updating Metadata for Series[pk={}] on {}", metadataUpdate.seriesPk, storage.getStorageDescriptor());
            WriteContext writeCtx = createWriteContext(storage, ctx.getMatches().iterator().next());
            try {
                try (ZipOutputStream out = new ZipOutputStream(storage.openOutputStream(writeCtx))) {
                    for (InstanceLocations match : ctx.getMatches()) {
                        out.putNextEntry(new ZipEntry(match.getSopInstanceUID()));
                        JsonGenerator gen = Json.createGenerator(out);
                        arcDev.encodeAsJSONNumber(new JSONWriter(gen)).write(loadMetadata(ctx, match));
                        gen.flush();
                        out.closeEntry();
                    }
                    out.finish();
                }
                storage.commitStorage(writeCtx);
                ejb.commit(metadataUpdate.seriesPk, createMetadata(writeCtx));
            } catch (Exception e) {
                LOG.warn("Failed to Create/Update Metadata for Series[pk={}] on {}:\n", metadataUpdate.seriesPk, storage.getStorageDescriptor(), e);
                try {
                    ejb.incrementMetadataUpdateFailures(metadataUpdate.seriesPk, nextRetry(arcDev, metadataUpdate.updateFailures));
                } catch (Exception e1) {
                    LOG.warn("Failed to update Metadata Update time", e1);
                }
                try {
                    storage.revokeStorage(writeCtx);
                } catch (Exception e1) {
                    LOG.warn("Failed to revoke storage", e1);
                }
                return;
            }
            LOG.debug("Created/Updated Metadata for Series[pk={}] on {}", metadataUpdate.seriesPk, storage.getStorageDescriptor());
            success.getAndIncrement();
        } else {
            skipped.getAndIncrement();
        }
    } catch (Exception e) {
        LOG.error("Unexpected exception on closing Retrieve Context for {}:\n", metadataUpdate, e);
    }
}
Also used : InstanceLocations(org.dcm4chee.arc.store.InstanceLocations) JSONWriter(org.dcm4che3.json.JSONWriter) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) RetrieveContext(org.dcm4chee.arc.retrieve.RetrieveContext) JsonGenerator(javax.json.stream.JsonGenerator) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) IOException(java.io.IOException) WriteContext(org.dcm4chee.arc.storage.WriteContext)

Aggregations

RetrieveContext (org.dcm4chee.arc.retrieve.RetrieveContext)16 InstanceLocations (org.dcm4chee.arc.store.InstanceLocations)7 IOException (java.io.IOException)5 Outcome (org.dcm4chee.arc.qmgt.Outcome)5 StoreSession (org.dcm4chee.arc.store.StoreSession)4 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)3 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)3 List (java.util.List)2 AsyncResponse (javax.ws.rs.container.AsyncResponse)2 Attributes (org.dcm4che3.data.Attributes)2 Tag (org.dcm4che3.data.Tag)2 DicomInputStream (org.dcm4che3.io.DicomInputStream)2 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)2 RetrieveService (org.dcm4chee.arc.retrieve.RetrieveService)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 java.awt (java.awt)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1