Example #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) {
   }
 }
Example #2
0
 // Get the dcm4che name of a DICOM element,
 // given the DICOM tag instruction element.
 private static String getDicomElementName(Element element) {
   int tag = getTag(element);
   if (tag == -1) return "UNKNOWN DICOM ELEMENT";
   String tagName = DicomObject.getElementName(tag);
   if (tagName != null) return tagName;
   tagName = element.getAttribute("desc");
   if (!tagName.equals("")) return tagName;
   return "UNKNOWN DICOM ELEMENT";
 }
Example #3
0
 private static String getDicomElementText(int tag, DicomObject dicomObject) {
   if (tag == -1) return "UNKNOWN DICOM ELEMENT";
   try {
     String value = dicomObject.getElementValue(tag);
     if (value != null) return XmlStringUtil.escapeChars(value);
     return "";
   } catch (Exception e) {
   }
   ;
   return "value missing";
 }
Example #4
0
  /**
   * Get a MIRCdocument XML string by parsing an existing MIRCdocument. If the FileObject is an
   * instance of a DicomObject, and the document contains insertion elements (indicating that it has
   * not yet received a DicomObject), insert data from the DicomObject where called for in the
   * MIRCdocument.
   *
   * @param mircDocument the file containing the MIRCdocument XML string.
   * @param fileObject the FileObject to be used to update the MIRCdocument.
   */
  public static String getText(File mircDocument, FileObject fileObject) {
    if (!(fileObject instanceof DicomObject)) return getText(mircDocument);
    DicomObject dicomObject = (DicomObject) fileObject;
    try {
      // get the mircDocument file
      Document templateXML;
      templateXML = XmlUtil.getDocument(mircDocument);
      Element root = templateXML.getDocumentElement();

      if (dicomObject.isManifest()) {
        // This is a TCE manifest. All we do for this object is to
        // set the title, author, abstract, and notes sections.
        // We leave all the other elements intact so they can be
        // processed when an image object is received.
        return insertManifestText(root, dicomObject);
      } else if (dicomObject.isRawData()) {
        if (checkTree(root)) {
          // This MIRCdocument has not been loaded with values from the
          // first non-manifest DicomObject, so we have to process the
          // XML object.
          return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + getElementText(root, dicomObject);
        } else return FileUtil.getFileText(mircDocument);
      } else if (!dicomObject.isImage()) {
        // This is not an image, so we should leave all the elements
        // in the MIRCdocument intact so they can be processed when an
        // image has been received. If we ever want to process KOS or SR
        // objects, we should do it here.
        return getText(mircDocument);
      } else if (checkTree(root)) {
        // This MIRCdocument has not been loaded with values from the
        // first non-manifest DicomObject, so we have to process the
        // XML object.
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + getElementText(root, dicomObject);
      } else {
        // There is nothing to process, just return the document text.
        return FileUtil.getFileText(mircDocument);
      }
    } catch (Exception e) {
      return null;
    }
  }
Example #5
0
  /**
   * Update a MIRCdocument XML string by parsing the string to obtain a MIRCdocument. If the
   * MIRCdocument contains insertion elements, insert data from the DicomObject where called for in
   * the MIRCdocument.
   *
   * @param mircDocument the MIRCdocument XML string.
   * @param dicomObject the object to be used to update the MIRCdocument.
   */
  public static String getText(String mircDocument, DicomObject dicomObject) {

    // Don't insert elements from anything but images.
    if (!dicomObject.isImage()) return mircDocument;

    // It's an image; process the document.
    try {
      // get the mircDocument DOM Document
      Document templateXML;
      templateXML = XmlUtil.getDocumentFromString(mircDocument);
      Element root = templateXML.getDocumentElement();

      if (checkTree(root)) {
        // This MIRCdocument has not been loaded with values from the
        // first non-manifest DicomObject, so we have to process the
        // XML object.
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + getElementText(root, dicomObject);
      }
    } catch (Exception e) {
    }
    return mircDocument;
  }
Example #6
0
 // Create a Log4J log file with a monthly rolling appender and populate
 // it with information from the dataset in a csv format so the log file
 // can be opened and processed with a spreadsheet.
 private void makeTrialLogEntry(String service, DicomObject dicomObject) {
   if (!TrialConfig.log()) return;
   if (processorLog == null) {
     try {
       processorLog = Logger.getLogger("trial");
       processorLog.setAdditivity(false);
       PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd},%d{HH:mm:ss},%m%n");
       File logs = new File(TrialConfig.basepath + TrialConfig.logDirectory);
       logs.mkdirs();
       DailyRollingFileAppender appender =
           new DailyRollingFileAppender(
               layout,
               TrialConfig.basepath
                   + TrialConfig.logDirectory
                   + File.separator
                   + TrialConfig.serviceName
                   + ".csv",
               "'.'yyyy-MM");
       processorLog.addAppender(appender);
       processorLog.setLevel((Level) Level.ALL);
     } catch (Exception e) {
       logger.warn("Unable to instantiate a trial logger");
       processorLog = null;
       return;
     }
   }
   processorLog.info(
       service
           + ","
           + dicomObject.getPatientName()
           + ","
           + dicomObject.getPatientID()
           + ","
           + dicomObject.getModality()
           + ","
           + dicomObject.getSeriesNumber()
           + ","
           + dicomObject.getAcquisitionNumber()
           + ","
           + dicomObject.getInstanceNumber());
 }