use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class WadoRS method buildResponse.
private void buildResponse(Target target, int[] frameList, int[] attributePath, AsyncResponse ar, Output output, final RetrieveContext ctx, Date lastModified) throws IOException {
LOG.debug("Query for matching {}", target);
service.calculateMatches(ctx);
LOG.info("retrieve{}: {} Matches", target, ctx.getNumberOfMatches());
if (ctx.getNumberOfMatches() == 0)
throw new WebApplicationException(errResponse("No matches found.", Response.Status.NOT_FOUND));
// Collection<InstanceLocations> notAccessable = service.removeNotAccessableMatches(ctx);
responseStatus = Response.Status.OK;
if (frameList != null) {
Attributes attrs = ctx.getMatches().get(0).getAttributes();
if (!attrs.containsValue(Tag.Rows))
throw new WebApplicationException(errResponse("Not an image.", Response.Status.NOT_FOUND));
frameList = adjustFrameList(frameList, attrs.getInt(Tag.NumberOfFrames, 1));
if (frameList.length == 0)
throw new WebApplicationException(errResponse("No such frame.", Response.Status.NOT_FOUND));
}
output = output.adjust(this, frameList, ctx);
Collection<InstanceLocations> notAccepted = output.removeNotAcceptedMatches(this, ctx, frameList, attributePath);
if (ctx.getMatches().isEmpty()) {
Response errResp = notAccepted.isEmpty() ? errResponse("No matches found.", Response.Status.NOT_FOUND) : errResponse("Not accepted instances present.", Response.Status.NOT_ACCEPTABLE);
throw new WebApplicationException(errResp);
}
if (!notAccepted.isEmpty())
responseStatus = Response.Status.PARTIAL_CONTENT;
if (lastModified == null)
lastModified = service.getLastModifiedFromMatches(ctx, ignorePatientUpdate);
retrieveStart.fire(ctx);
ar.register((CompletionCallback) throwable -> {
SafeClose.close(compressedMFPixelDataOutput);
SafeClose.close(uncompressedFramesOutput);
SafeClose.close(compressedFramesOutput);
SafeClose.close(decompressFramesOutput);
purgeSpoolDirectory();
ctx.getRetrieveService().updateLocations(ctx);
ctx.setException(throwable);
retrieveEnd.fire(ctx);
});
Object entity = output.entity(this, target, ctx, frameList, attributePath);
ar.resume(output.response(this, lastModified, entity).build());
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class WadoRS method writeZIP.
private Object writeZIP(RetrieveContext ctx) {
AttributesFormat pathFormat = new AttributesFormat(ctx.getLocalApplicationEntity().getAEExtensionNotNull(ArchiveAEExtension.class).wadoZIPEntryNameFormat());
final Collection<InstanceLocations> insts = ctx.getMatches();
return (StreamingOutput) out -> {
try {
Set<String> dirPaths = new HashSet<>();
ZipOutputStream zip = new ZipOutputStream(out);
try (DicomDirWriter dicomDirWriter = dicomDirWriter()) {
for (InstanceLocations inst : insts) {
String name = pathFormat.format(inst.getAttributes());
addDirEntries(zip, name, dirPaths);
zip.putNextEntry(new ZipEntry(name));
DicomObjectOutput output = new DicomObjectOutput(ctx, inst, acceptableZipTransferSyntaxes);
output.write(zip);
zip.closeEntry();
if (dicomDirWriter != null) {
addDicomDirRecords(dicomDirWriter, output.getFileMetaInformation(), inst.getAttributes(), toFileIDs(name));
}
}
}
if (dicomdirPath != null) {
zip.putNextEntry(new ZipEntry("DICOMDIR"));
Files.copy(dicomdirPath, zip);
zip.closeEntry();
}
zip.finish();
zip.flush();
} catch (Exception e) {
throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
}
};
}
use of org.dcm4chee.arc.store.InstanceLocations 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.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class CStoreForwardTask method createInstanceLocations.
private InstanceLocations createInstanceLocations(StoreContext storeCtx) {
Instance inst = storeCtx.getStoredInstance();
Series series = inst.getSeries();
Study study = series.getStudy();
Patient patient = study.getPatient();
Attributes instAttrs = inst.getAttributes();
Attributes seriesAttrs = series.getAttributes();
Attributes studyAttrs = study.getAttributes();
Attributes patAttrs = patient.getAttributes();
Attributes.unifyCharacterSets(patAttrs, studyAttrs, seriesAttrs, instAttrs);
instAttrs.addAll(seriesAttrs, true);
instAttrs.addAll(studyAttrs, true);
instAttrs.addAll(patAttrs, true);
RetrieveService service = ctx.getRetrieveService();
InstanceLocations instanceLocations = service.newInstanceLocations(instAttrs);
instanceLocations.getLocations().addAll(locations(storeCtx));
return instanceLocations;
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class CStoreSCUImpl method createAARQ.
private AAssociateRQ createAARQ(RetrieveContext ctx) {
AAssociateRQ aarq = new AAssociateRQ();
ApplicationEntity localAE = ctx.getLocalApplicationEntity();
ApplicationEntity destAE = ctx.getDestinationAE();
if (!localAE.isMasqueradeCallingAETitle(ctx.getDestinationAETitle()))
aarq.setCallingAET(ctx.getCallingAET());
boolean noDestinationRestriction = destAE.getTransferCapabilitiesWithRole(SCP).isEmpty();
for (Iterator<InstanceLocations> iter = ctx.getMatches().iterator(); iter.hasNext(); ) {
InstanceLocations inst = iter.next();
String cuid = inst.getSopClassUID();
TransferCapability localTC = localAE.getTransferCapabilityFor(cuid, SCU);
TransferCapability destTC = noDestinationRestriction ? null : destAE.getTransferCapabilityFor(cuid, SCP);
if (!aarq.containsPresentationContextFor(cuid) && !isVideo(inst)) {
if (noDestinationRestriction) {
addPresentationContext(aarq, cuid, UID.ImplicitVRLittleEndian, localTC);
addPresentationContext(aarq, cuid, UID.ExplicitVRLittleEndian, localTC);
} else {
addPresentationContext(aarq, cuid, UID.ImplicitVRLittleEndian, localTC, destTC);
addPresentationContext(aarq, cuid, UID.ExplicitVRLittleEndian, localTC, destTC);
}
}
for (Location location : inst.getLocations()) {
String tsuid = location.getTransferSyntaxUID();
if (!tsuid.equals(UID.ImplicitVRLittleEndian) && !tsuid.equals(UID.ExplicitVRLittleEndian))
if (noDestinationRestriction) {
addPresentationContext(aarq, cuid, tsuid, localTC);
} else {
addPresentationContext(aarq, cuid, tsuid, localTC, destTC);
}
}
}
return aarq;
}
Aggregations