Exemplo n.º 1
0
 // Process a DICOM file.
 private void process(DicomObject dicomObject) {
   try {
     dicomObject.setExtension(".dcm");
     // get the document for this study or create it if necessary
     MircDocument td = new MircDocument(dicomObject);
     // Put in the object and store the updated document.
     // Note that since all http imports should have been
     // anonymized before transmission over the internet,
     // we assume that is the case. There is no way to tell.
     td.insert(dicomObject, TrialConfig.allowOverwrite(), true, null, null);
     // export the image via DICOM if in auto mode
     dicomExportDirectories = TrialConfig.getDicomExportDirectories();
     dicomExportDirectoryFiles = TrialConfig.getDicomExportDirectoryFiles();
     if (TrialConfig.getDicomExportMode().equals("auto") && (dicomExportDirectoryFiles != null)) {
       for (int i = 0; i < dicomExportDirectoryFiles.length; i++) {
         try {
           ExportQueueElement eqe = ExportQueueElement.createEQE(dicomObject);
           eqe.queue(dicomExportDirectoryFiles[i]);
         } catch (Exception e) {
           String name = dicomObject.getFile().getName();
           Log.message(
               processorServiceName
                   + ": "
                   + dicomExportDirectories[i]
                   + " DICOM export failed:"
                   + name);
           logger.warn(dicomExportDirectories[i] + " DICOM export failed:" + name);
         }
       }
     }
     // log the object if logging is enabled
     makeTrialLogEntry("http-import", dicomObject);
   } catch (Exception notDicom) {
   }
 }
Exemplo n.º 2
0
 // Queue a file for the DatabaseExportService.
 private boolean queueForDatabase(FileObject fileObject) {
   if (TrialConfig.getDatabaseExportMode().equals("auto")) {
     File databaseExportDirectoryFile = TrialConfig.getDatabaseExportDirectoryFile();
     try {
       ExportQueueElement eqe = ExportQueueElement.createEQE(fileObject);
       eqe.queue(databaseExportDirectoryFile);
     } catch (Exception e) {
       Log.message(
           processorServiceName
               + ": Unable to queue "
               + fileObject.getFile().getName()
               + " for database export");
       logger.warn("Unable to queue " + fileObject.getFile().getName() + " for database export");
     }
   }
   return true;
 }
Exemplo n.º 3
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();
      }
    }
  }