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);
}
}
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;
}
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);
}
}
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());
}
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);
}
}
Aggregations