use of org.dcm4che3.net.DimseRSP in project dcm4che by dcm4che.
the class Association method cecho.
public DimseRSP cecho(String cuid) throws IOException, InterruptedException {
FutureDimseRSP rsp = new FutureDimseRSP(nextMessageID());
PresentationContext pc = pcFor(cuid, null);
checkIsSCU(cuid);
Attributes cechorq = Commands.mkCEchoRQ(rsp.getMessageID(), cuid);
invoke(pc, cechorq, null, rsp, conn.getSendTimeout(), conn.getResponseTimeout());
return rsp;
}
use of org.dcm4che3.net.DimseRSP in project dcm4chee-arc-light by dcm4che.
the class QueryRS method search.
private void search(AsyncResponse ar, Level level, String studyInstanceUID, String seriesInstanceUID, QIDO qido, boolean count) {
ApplicationEntity localAE = device.getApplicationEntity(aet, true);
if (localAE == null || !localAE.isInstalled())
throw new WebApplicationException(errResponse("No such Application Entity: " + aet, Response.Status.NOT_FOUND));
try {
aeCache.findApplicationEntity(externalAET);
QueryAttributes queryAttributes = new QueryAttributes(uriInfo, null);
Attributes keys = queryAttributes.getQueryKeys();
if (!count) {
qido.addReturnTags(queryAttributes);
if (queryAttributes.isIncludeAll()) {
ArchiveDeviceExtension arcdev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
switch(level) {
case MWL:
queryAttributes.addReturnTags(arcdev.getAttributeFilter(Entity.MWL).getSelection(false));
queryAttributes.addReturnTags(arcdev.getAttributeFilter(Entity.Patient).getSelection(false));
break;
case IMAGE:
queryAttributes.addReturnTags(arcdev.getAttributeFilter(Entity.Instance).getSelection(false));
break;
case SERIES:
queryAttributes.addReturnTags(arcdev.getAttributeFilter(Entity.Series).getSelection(false));
break;
case STUDY:
queryAttributes.addReturnTags(arcdev.getAttributeFilter(Entity.Study).getSelection(false));
case PATIENT:
queryAttributes.addReturnTags(arcdev.getAttributeFilter(Entity.Patient).getSelection(false));
}
keys.remove(Tag.TimezoneOffsetFromUTC);
}
}
if (level != Level.MWL)
keys.setString(Tag.QueryRetrieveLevel, VR.CS, level.name());
if (studyInstanceUID != null)
keys.setString(Tag.StudyInstanceUID, VR.UI, studyInstanceUID);
if (seriesInstanceUID != null)
keys.setString(Tag.SeriesInstanceUID, VR.UI, seriesInstanceUID);
EnumSet<QueryOption> queryOptions = EnumSet.of(QueryOption.DATETIME);
if (Boolean.parseBoolean(fuzzymatching))
queryOptions.add(QueryOption.FUZZY);
ar.register((CompletionCallback) throwable -> {
if (as != null)
try {
as.release();
} catch (IOException e) {
LOG.info("{}: Failed to release association:\\n", as, e);
}
});
as = findSCU.openAssociation(localAE, externalAET, level.cuid, queryOptions);
DimseRSP dimseRSP = findSCU.query(as, priority(), findSCU.coerceCFindRQ(as, keys), !count && limit != null ? offset() + limit() : 0, 1, level != Level.MWL ? splitStudyDateRange() : null);
dimseRSP.next();
ar.resume((count ? countResponse(dimseRSP) : responseBuilder(dimseRSP, localAE)).build());
} catch (IllegalStateException | ConfigurationException e) {
throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.NOT_FOUND));
} catch (IOException e) {
throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.BAD_GATEWAY));
} catch (Exception e) {
throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
}
}
use of org.dcm4che3.net.DimseRSP in project dcm4chee-arc-light by dcm4che.
the class QueryRS method writeJSON.
private Object writeJSON(final DimseRSP dimseRSP, ApplicationEntity localAE) {
return (StreamingOutput) out -> {
JsonGenerator gen = Json.createGenerator(out);
JSONWriter writer = localAE.getAEExtensionNotNull(ArchiveAEExtension.class).encodeAsJSONNumber(new JSONWriter(gen));
gen.writeStartArray();
int skip = offset();
int remaining = limit();
try {
Attributes dataset = dimseRSP.getDataset();
dimseRSP.next();
do {
if (skip > 0)
skip--;
else {
writer.write(findSCU.coerceCFindRSP(as, dataset));
if (limit != null && --remaining == 0)
break;
}
dataset = dimseRSP.getDataset();
} while (dimseRSP.next());
} catch (Exception e) {
LOG.warn("Failed to read next C-FIND RSP from {}:\\n", externalAET, e);
}
gen.writeEnd();
gen.flush();
};
}
use of org.dcm4che3.net.DimseRSP in project dcm4chee-arc-light by dcm4che.
the class DiffSCUImpl method checkRSP.
private static int checkRSP(DimseRSP rsp) throws DicomServiceException {
Attributes cmd = rsp.getCommand();
int status = cmd.getInt(Tag.Status, -1);
if (!Status.isPending(status) && status != Status.Success)
throw new DicomServiceException(status, cmd.getString(Tag.ErrorComment));
return status;
}
use of org.dcm4che3.net.DimseRSP in project dcm4chee-arc-light by dcm4che.
the class UpsDimseRS method upsMatching.
private Response upsMatching(QueryRetrieveLevel2 level, String queryAET, String studyInstanceUID, String seriesInstanceUID, InputStream in) {
InputType inputType = InputType.valueOf(headers.getMediaType());
if (inputType == null)
return notAcceptable();
try {
aeCache.findApplicationEntity(moveSCP);
ArchiveAEExtension arcAE = getArchiveAE();
Attributes upsTemplateAttrs = inputType.parse(in);
upsTemplateAttrs.setDate(Tag.ScheduledProcedureStepStartDateTime, VR.DT, scheduledTime());
if (upsLabel != null)
upsTemplateAttrs.setString(Tag.ProcedureStepLabel, VR.LO, upsLabel);
if (queryAET != null && !queryAET.equals(moveSCP))
aeCache.findApplicationEntity(queryAET);
Attributes keys = queryKeys(level, studyInstanceUID, seriesInstanceUID);
EnumSet<QueryOption> queryOptions = EnumSet.of(QueryOption.DATETIME);
if (Boolean.parseBoolean(fuzzymatching))
queryOptions.add(QueryOption.FUZZY);
Association as = null;
String warning;
AtomicInteger count = new AtomicInteger();
Response.Status rspStatus = Response.Status.BAD_GATEWAY;
int matches = 0;
try {
as = findSCU.openAssociation(arcAE.getApplicationEntity(), queryAET, UID.StudyRootQueryRetrieveInformationModelFind, queryOptions);
DimseRSP dimseRSP = findSCU.query(as, parseInt(priority, 0), findSCU.coerceCFindRQ(as, keys), 0, 1, splitStudyDateRange());
dimseRSP.next();
int status;
Attributes ups = new Attributes(upsTemplateAttrs);
do {
status = dimseRSP.getCommand().getInt(Tag.Status, -1);
if (Status.isPending(status)) {
ups = studyInstanceUID == null ? new Attributes(upsTemplateAttrs) : ups;
UPSUtils.updateUPSAttributes(ups, findSCU.coerceCFindRSP(as, dimseRSP.getDataset()), studyInstanceUID, seriesInstanceUID, moveSCP);
matches++;
if (studyInstanceUID == null)
createUPS(arcAE, ups, count);
}
} while (dimseRSP.next());
if (matches > 0 && studyInstanceUID != null)
createUPS(arcAE, ups, count);
warning = warning(status);
} catch (IllegalStateException | IllegalArgumentException | ConfigurationException e) {
rspStatus = Response.Status.NOT_FOUND;
warning = e.getMessage();
} catch (Exception e) {
warning = e.getMessage();
} finally {
if (as != null)
try {
as.release();
} catch (IOException e) {
LOG.info("{}: Failed to release association:\\n", as, e);
}
}
if (warning == null && count.get() > 0)
return Response.accepted(count(count.get())).build();
if (count.get() == 0) {
warning = "No matching Instances found. No Workitem was created.";
rspStatus = Response.Status.NO_CONTENT;
}
Response.ResponseBuilder builder = Response.status(rspStatus).header("Warning", warning);
if (count.get() > 0)
builder.entity(count(count.get()));
return builder.build();
} catch (IllegalStateException | IllegalArgumentException | ConfigurationException e) {
return errResponse(Response.Status.NOT_FOUND, e.getMessage());
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations