Search in sources :

Example 26 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class StgCmtImpl method scheduleStorageCommit.

@Override
public void scheduleStorageCommit(ExportContext ctx, ExporterDescriptor descriptor) {
    String stgCmtSCPAETitle = descriptor.getStgCmtSCPAETitle();
    if (stgCmtSCPAETitle != null) {
        ApplicationEntity ae = device.getApplicationEntity(ctx.getAETitle(), true);
        Attributes actionInfo = createActionInfo(ctx, ae);
        scheduleNAction(ae.getCallingAETitle(stgCmtSCPAETitle), stgCmtSCPAETitle, actionInfo, ctx, descriptor.getExporterID(), new Date());
    }
}
Also used : Attributes(org.dcm4che3.data.Attributes) Date(java.util.Date)

Example 27 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class IANSCURS method ian.

private Response ian(String studyUID, String seriesUID, String sopUID, String externalAET) {
    logRequest();
    ApplicationEntity ae = device.getApplicationEntity(aet, true);
    if (ae == null || !ae.isInstalled())
        return errResponse("No such Application Entity: " + aet, Response.Status.NOT_FOUND);
    Response.Status rspStatus = Response.Status.BAD_GATEWAY;
    try {
        ApplicationEntity remoteAE = aeCache.findApplicationEntity(externalAET);
        Attributes ian = queryService.createIAN(ae, studyUID, new String[] { seriesUID }, sopUID, null, null, null);
        if (ian == null)
            return errResponse("No matching instances", Response.Status.NOT_FOUND);
        DimseRSP dimseRSP = ianSCU.sendIANRQ(ae, remoteAE, UIDUtils.createUID(), ian);
        dimseRSP.next();
        if (dimseRSP.getCommand().getInt(Tag.Status, -1) == Status.Success)
            rspStatus = Response.Status.OK;
        return Response.status(rspStatus).entity(entity(ian, dimseRSP)).build();
    } catch (ConfigurationException e) {
        return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (IOException e) {
        return errResponse(e.getMessage(), rspStatus);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : Response(javax.ws.rs.core.Response) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) DimseRSP(org.dcm4che3.net.DimseRSP) Attributes(org.dcm4che3.data.Attributes) IOException(java.io.IOException) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) IOException(java.io.IOException)

Example 28 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class IANScheduler method scheduleIAN.

public void scheduleIAN(ExportContext ctx, ExporterDescriptor descriptor) {
    ApplicationEntity ae = device.getApplicationEntity(ctx.getAETitle(), true);
    Attributes ian = queryService.createIAN(ae, ctx.getStudyInstanceUID(), null, null, descriptor.getRetrieveAETitles(), descriptor.getRetrieveLocationUID(), descriptor.getInstanceAvailability());
    if (ian != null)
        for (String remoteAET : descriptor.getIanDestinations()) ejb.scheduleMessage(ctx.getAETitle(), ian, remoteAET, new Date(), null);
}
Also used : ApplicationEntity(org.dcm4che3.net.ApplicationEntity) Date(java.util.Date)

Example 29 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class IANScheduler method execute.

@Override
protected void execute() {
    ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
    int fetchSize = arcDev.getIanTaskFetchSize();
    long ianTaskPk = 0;
    List<IanTask> ianTasks;
    Attributes ian;
    do {
        ianTasks = ejb.fetchIANTasksForMPPS(device.getDeviceName(), ianTaskPk, fetchSize);
        for (IanTask ianTask : ianTasks) {
            if (getPollingInterval() == null)
                return;
            try {
                ianTaskPk = ianTask.getPk();
                ApplicationEntity ae = device.getApplicationEntity(ianTask.getCallingAET(), true);
                LOG.info("Check availability of {}", ianTask.getMpps());
                ian = createIANForMPPS(ae, ianTask.getMpps(), true);
                if (ian != null) {
                    LOG.info("Schedule {}", ianTask);
                    ejb.scheduleIANTask(ianTask, ian);
                }
            } catch (Exception e) {
                LOG.warn("Failed to process {}", ianTask, e);
            }
        }
    } while (ianTasks.size() == fetchSize);
    do {
        ianTasks = ejb.fetchIANTasksForStudy(device.getDeviceName(), fetchSize);
        for (IanTask ianTask : ianTasks) {
            if (getPollingInterval() == null)
                return;
            try {
                ApplicationEntity ae = device.getApplicationEntity(ianTask.getCallingAET(), true);
                if (ianTask.getMpps() == null) {
                    ian = queryService.createIAN(ae, ianTask.getStudyInstanceUID(), null, null, null, null, null);
                    if (ian != null) {
                        LOG.info("Schedule {}", ianTask);
                        ejb.scheduleIANTask(ianTask, ian);
                    } else {
                        LOG.info("Ignore {} without referenced objects", ianTask);
                        ejb.removeIANTask(ianTask);
                    }
                } else {
                    if (ae.getAEExtension(ArchiveAEExtension.class).ianOnTimeout() && (ian = createIANForMPPS(ae, ianTask.getMpps(), false)) != null) {
                        LOG.warn("Timeout for {} exceeded - schedule IAN for available instances", ianTask);
                        ejb.scheduleIANTask(ianTask, ian);
                    } else {
                        LOG.warn("Timeout for {} exceeded - no IAN", ianTask);
                        ejb.removeIANTask(ianTask);
                    }
                }
            } catch (Exception e) {
                LOG.warn("Failed to process {}", ianTask, e);
            }
        }
    } while (ianTasks.size() == fetchSize);
}
Also used : ApplicationEntity(org.dcm4che3.net.ApplicationEntity)

Example 30 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class ExportCSVRS method exportFromCSV.

Response exportFromCSV(String aet, String exporterID, int studyUIDField, Integer seriesUIDField, InputStream in) {
    logRequest();
    Response.Status status = Response.Status.BAD_REQUEST;
    try {
        if (studyUIDField < 1)
            return errResponse(status, "CSV field for Study Instance UID should be greater than or equal to 1");
        if (seriesUIDField != null) {
            if (studyUIDField == seriesUIDField)
                return errResponse(status, "CSV fields for Study and Series Instance UIDs should be different");
            if (seriesUIDField < 1)
                return errResponse(status, "CSV field for Series Instance UID should be greater than or equal to 1");
        }
        ApplicationEntity ae = device.getApplicationEntity(aet, true);
        if (ae == null || !ae.isInstalled())
            return errResponse(Response.Status.NOT_FOUND, "No such Application Entity: " + aet);
        ArchiveDeviceExtension arcDev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
        ExporterDescriptor exporter = arcDev.getExporterDescriptor(exporterID);
        if (exporter == null)
            return errResponse(Response.Status.NOT_FOUND, "No such Exporter: " + exporterID);
        int count = 0;
        String warning = null;
        int csvUploadChunkSize = arcDev.getCSVUploadChunkSize();
        List<StudySeriesInfo> studySeries = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            CSVParser parser = new CSVParser(reader, CSVFormat.DEFAULT.builder().setDelimiter(csvDelimiter()).build())) {
            boolean header = true;
            for (CSVRecord csvRecord : parser) {
                if (csvRecord.size() == 0 || csvRecord.get(0).isEmpty())
                    continue;
                String studyUID = csvRecord.get(studyUIDField - 1).replaceAll("\"", "");
                if (header && studyUID.chars().allMatch(Character::isLetter)) {
                    header = false;
                    continue;
                }
                if (!arcDev.isValidateUID() || validateUID(studyUID)) {
                    StudySeriesInfo studySeriesInfo = new StudySeriesInfo(studyUID);
                    addSeriesUID(studySeriesInfo, csvRecord, seriesUIDField, arcDev);
                    studySeries.add(studySeriesInfo);
                }
                if (studySeries.size() == csvUploadChunkSize) {
                    count += scheduleExportTasks(exporter, studySeries, scheduledTime());
                    studySeries.clear();
                }
            }
            if (!studySeries.isEmpty())
                count += scheduleExportTasks(exporter, studySeries, scheduledTime());
            if (count == 0) {
                warning = "Empty file or Incorrect field position or Not a CSV file or Invalid UIDs.";
                status = Response.Status.NO_CONTENT;
            }
        } catch (Exception e) {
            warning = e.getMessage();
            status = Response.Status.INTERNAL_SERVER_ERROR;
        }
        if (warning == null && count > 0)
            return Response.accepted(count(count)).build();
        LOG.info("Response {} caused by {}", status, warning);
        Response.ResponseBuilder builder = Response.status(status).header("Warning", warning);
        if (count > 0)
            builder.entity(count(count));
        return builder.build();
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : ArrayList(java.util.ArrayList) Response(javax.ws.rs.core.Response) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) CSVParser(org.apache.commons.csv.CSVParser) CSVRecord(org.apache.commons.csv.CSVRecord) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor)

Aggregations

ApplicationEntity (org.dcm4che3.net.ApplicationEntity)58 IOException (java.io.IOException)18 Attributes (org.dcm4che3.data.Attributes)18 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)15 AAssociateRQ (org.dcm4che3.net.pdu.AAssociateRQ)14 Response (javax.ws.rs.core.Response)13 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)13 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)12 Query (org.dcm4chee.arc.query.Query)12 QueryContext (org.dcm4chee.arc.query.QueryContext)12 Device (org.dcm4che3.net.Device)11 StoreSession (org.dcm4chee.arc.store.StoreSession)10 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)9 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)9 PresentationContext (org.dcm4che3.net.pdu.PresentationContext)7 StoreContext (org.dcm4chee.arc.store.StoreContext)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Outcome (org.dcm4chee.arc.qmgt.Outcome)6 java.util (java.util)5