Exemplo n.º 1
0
 // Load the anonymizer.properties file.
 // This function is called whenever the Clinical Trial Service is restarted,
 // allowing new anonymization scripts to be loaded.
 private void initialize() {
   reinitialize = false;
   try {
     File propFile = new File(TrialConfig.basepath + TrialConfig.dicomAnonymizerFilename);
     dicomAnonymizerProperties = new Properties();
     dicomAnonymizerProperties.load(new FileInputStream(propFile));
     File lkupFile = new File(TrialConfig.basepath + TrialConfig.lookupTableFilename);
     lookupTableProperties = new Properties();
     try {
       lookupTableProperties.load(new FileInputStream(lkupFile));
     } catch (Exception ex) {
       lookupTableProperties = null;
     }
     if (TrialConfig.dicomImportAnonymizerEnabled())
       Log.message(processorServiceName + ": DicomAnonymizer initialized");
     else Log.message(processorServiceName + ": DicomAnonymizer not enabled");
   } catch (Exception e) {
     Log.message(processorServiceName + ": Unable to configure the DicomAnonymizer");
   }
 }
Exemplo n.º 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();
      }
    }
  }