Пример #1
0
  // Initialize and start the SCP
  private static void startSCP(ObjectProcessor op) {
    if (scp != null) {
      // There is already a storage SCP; stop it.
      // This throws an exception, but ignore it.
      try {
        scp.stop();
      } catch (Exception ignore) {
      }
      scp = null;
    }

    // Now get a new SCP with the new params.
    scp = getDicomStore();

    // Start listening.
    scp.addDicomEventListener(op);

    // And start the scp.
    try {
      scp.start();
      Log.message(
          dicomImportServiceName
              + ": "
              + TrialConfig.getDicomStoreAETitle()
              + " Storage SCP started on port "
              + TrialConfig.getDicomStorePort());
    } catch (Exception e) {
      Log.message(dicomImportServiceName + ": SCP failed to start<br>" + e.getMessage());
    }
  }
Пример #2
0
  // Look through the dicom-import directory and process
  // all the files there. Note that these are actual files,
  // not queue elements.
  private void processDicomImportFiles() {
    File importDirFile = new File(TrialConfig.basepath + TrialConfig.dicomImportDir);
    if (!importDirFile.exists()) return;
    File[] files = importDirFile.listFiles();
    for (int k = 0; k < files.length; k++) {
      File next = files[k];
      if (files[k].canRead() && files[k].canWrite()) {
        try {
          boolean forceQuarantine = false;
          httpExportDirectories = TrialConfig.getHttpExportDirectories();
          httpExportDirectoryFiles = TrialConfig.getHttpExportDirectoryFiles();
          // If enabled, anonymize.
          // Note: in normal clinical trials, the anonymizer is enabled and de-identified
          // images are transmitted by the HttpExportProcessor.
          // For normal research applications, images are not anonymized and the document
          // creates directories of identified and de-identified images. In this situation,
          // the anonymizer is disabled and the document takes care of de-identifying the
          // images.
          // Note: in research applications, the document takes its elements from the
          // identified (e.g., containing PHI) image, so such documents contain PHI.
          if (TrialConfig.dicomImportAnonymizerEnabled()) {
            String exceptions =
                DicomAnonymizer.anonymize(
                    next,
                    next,
                    dicomAnonymizerProperties,
                    lookupTableProperties,
                    new LocalRemapper(),
                    false,
                    false);
            if (!exceptions.equals("")) {
              if (exceptions.indexOf("!quarantine!") != -1) {
                Log.message(
                    "<font color=\"red\">DicomAnonymizer quarantine call:<br>"
                        + next.getName()
                        + "</font>");
                forceQuarantine = true;
              } else if (exceptions.indexOf("!error!") != -1) {
                Log.message(
                    "<font color=\"red\">DicomAnonymizer error call: "
                        + exceptions
                        + "<br>"
                        + next.getName()
                        + "</font>");
                forceQuarantine = true;
              } else {
                // Note: the anonymizer logs the exception list to Log4J,
                // so we just have to log it to the displayed log.
                Log.message("Anonymization exceptions: " + exceptions + "<br>" + next.getName());
              }
            } else {
              Log.message(
                  "<font color=\"blue\">Anonymization complete"
                      + "<br>"
                      + next.getName()
                      + "</font>");
            }
          }
          if (!forceQuarantine) {
            // get the document for this study or create it if necessary
            DicomObject nextObject = new DicomObject(next);
            MircDocument td = new MircDocument(nextObject);
            // put in the object and store the updated document
            td.insert(
                nextObject,
                TrialConfig.allowOverwrite(),
                TrialConfig.dicomImportAnonymizerEnabled(),
                dicomAnonymizerProperties,
                lookupTableProperties);

            // export the object
            if (httpExportDirectoryFiles != null) {
              for (int i = 0; i < httpExportDirectoryFiles.length; i++) {
                try {
                  ExportQueueElement eqe = ExportQueueElement.createEQE(nextObject);
                  eqe.queue(httpExportDirectoryFiles[i]);
                } catch (Exception e) {
                  Log.message(
                      processorServiceName
                          + ": "
                          + httpExportDirectories[i]
                          + " export failed:"
                          + next.getName());
                  logger.warn(httpExportDirectories[i] + " export failed:" + next.getName());
                }
              }
            }
            if (!queueForDatabase(nextObject))
              Log.message(Quarantine.file(next, processorServiceName));
            else Log.message(processorServiceName + ": Processing complete: " + next.getName());

            // log the event if logging is enabled
            makeTrialLogEntry("dicom-import", nextObject);
          }

          // if the file still exists, then either the object was
          // set for quarantining or there is a bug somewhere;
          // log it and quarantine the file so we don't
          // fall into an infinite loop.
          if (next.exists()) {
            logger.warn("Forced quarantine: " + next);
            Log.message(Quarantine.file(next, processorServiceName));
          }
        } catch (Exception e) {
          Log.message(
              processorServiceName
                  + ": Error during processing: "
                  + next.getName()
                  + "  - "
                  + e.getMessage());
          logger.warn("Error during processing: object quarantined: " + next.getName(), e);
          Log.message(Quarantine.file(next, processorServiceName));
        }
        yield();
      }
    }
  }