Search in sources :

Example 11 with DimseRSP

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;
}
Also used : Attributes(org.dcm4che3.data.Attributes) PresentationContext(org.dcm4che3.net.pdu.PresentationContext)

Example 12 with DimseRSP

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));
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) LoggerFactory(org.slf4j.LoggerFactory) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONWriter(org.dcm4che3.json.JSONWriter) InvokeValidate(org.dcm4chee.arc.validation.constraints.InvokeValidate) Json(javax.json.Json) org.dcm4che3.data(org.dcm4che3.data) IApplicationEntityCache(org.dcm4che3.conf.api.IApplicationEntityCache) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) CFindSCU(org.dcm4chee.arc.query.scu.CFindSCU) org.dcm4chee.arc.conf(org.dcm4chee.arc.conf) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) StringWriter(java.io.StringWriter) ValidValueOf(org.dcm4chee.arc.validation.constraints.ValidValueOf) org.dcm4che3.net(org.dcm4che3.net) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) TagUtils(org.dcm4che3.util.TagUtils) Suspended(javax.ws.rs.container.Suspended) QIDO(org.dcm4chee.arc.query.util.QIDO) NoCache(org.jboss.resteasy.annotations.cache.NoCache) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) CompletionCallback(javax.ws.rs.container.CompletionCallback) RequestScoped(javax.enterprise.context.RequestScoped) Pattern(javax.validation.constraints.Pattern) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) UriInfo(javax.ws.rs.core.UriInfo) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) IOException(java.io.IOException) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) IOException(java.io.IOException) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException)

Example 13 with DimseRSP

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();
    };
}
Also used : JSONWriter(org.dcm4che3.json.JSONWriter) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) IOException(java.io.IOException)

Example 14 with DimseRSP

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;
}
Also used : DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 15 with DimseRSP

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);
    }
}
Also used : Attributes(org.dcm4che3.data.Attributes) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) IOException(java.io.IOException) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException)

Aggregations

IOException (java.io.IOException)12 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)8 Attributes (org.dcm4che3.data.Attributes)8 DimseRSP (org.dcm4che3.net.DimseRSP)5 AAssociateRQ (org.dcm4che3.net.pdu.AAssociateRQ)5 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)5 Response (javax.ws.rs.core.Response)4 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)4 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)3 Outcome (org.dcm4chee.arc.qmgt.Outcome)3 JsonGenerator (javax.json.stream.JsonGenerator)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 JSONWriter (org.dcm4che3.json.JSONWriter)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1