Exemplo n.º 1
0
  /**
   * Update the indexes for this object. This stage tracks the following data:
   *
   * <ul>
   *   <li>Processing date (today)
   *   <li>PatientID
   *   <li>StudyInstanceUID
   *   <li>SeriesInstanceUID
   *   <li>SOPInstanceUID
   * </ul>
   *
   * It creates table entries for the values in this object. IDs which are not unique may be
   * overwritten by subsequent objects (e.g. duplicates). Thus, the tables contain only records of
   * unique objects that have been processed.
   *
   * @param fileObject the object to process.
   * @return the same FileObject if the result is true; otherwise null.
   */
  public FileObject process(FileObject fileObject) {

    lastFileIn = new File(fileObject.getFile().getAbsolutePath());
    lastTimeIn = System.currentTimeMillis();

    try {
      if (fileObject instanceof DicomObject) {
        DicomObject dob = (DicomObject) fileObject;

        String date = StringUtil.getDate("");
        String patientID = dob.getPatientID();
        String studyInstanceUID = dob.getStudyInstanceUID();
        String seriesInstanceUID = dob.getSeriesInstanceUID();
        String sopInstanceUID = dob.getSOPInstanceUID();

        index(dateIndex, date, patientID);
        index(patientIndex, patientID, studyInstanceUID);
        index(studyIndex, studyInstanceUID, seriesInstanceUID);
        index(seriesIndex, seriesInstanceUID, sopInstanceUID);

        recman.commit();
      }
    } catch (Exception skip) {
      logger.debug("Unable to process " + fileObject.getFile());
    }

    lastFileOut = new File(fileObject.getFile().getAbsolutePath());
    lastTimeOut = System.currentTimeMillis();
    return fileObject;
  }
Exemplo n.º 2
0
  /**
   * Check a DicomObject and record any failing lookups in the database.
   *
   * @param fileObject the object to process.
   * @return the same FileObject if the result is true; otherwise null.
   */
  public FileObject process(FileObject fileObject) {
    String cmd;

    lastFileIn = new File(fileObject.getFile().getAbsolutePath());
    lastTimeIn = System.currentTimeMillis();

    if (fileObject instanceof DicomObject) {
      DicomObject dob = (DicomObject) fileObject;
      if (dcmScriptFile != null) {
        DAScript daScript = DAScript.getInstance(dcmScriptFile);
        scriptTable = new ScriptTable(daScript);
        lutProps = LookupTable.getProperties(lutFile);
        synchronized (this) {
          Dataset ds = dob.getDataset();
          charset = ds.getSpecificCharacterSet();
          boolean ok = checkDataset(ds);
          if (!ok) {
            try {
              recman.commit();
            } catch (Exception unable) {
            }
            ;
            if (quarantine != null) quarantine.insert(fileObject);
            return null;
          }
        }
      }
    }
    lastFileOut = new File(fileObject.getFile().getAbsolutePath());
    lastTimeOut = System.currentTimeMillis();
    return fileObject;
  }
Exemplo n.º 3
0
  /**
   * Get the tag for a DICOM element. This method supports dcm4che names as well as hex strings,
   * with or without enclosing parentheses or square brackets and with or without a comma separating
   * the group and the element numbers. This method also supports private group names defined in the
   * script. This method differs from the DicomObject method of the same name in that it also
   * supports names for private group elements in the form 0009[ID]02, where ID is the block owner
   * ID. Examples of element specifications containing block owner IDs are:
   *
   * <ul>
   *   <li>9,[blockID]02
   *   <li>(9,[blockID]02)
   *   <li>[9,[blockID]02]
   *   <li>0009[blockID]02
   * </ul>
   *
   * @param name the dcm4che element name or coded hex value.
   * @return the tag, or zero if the name cannot be parsed as an element specification
   */
  public int getElementTag(String name) {
    if (name == null) return 0;
    name = name.trim();
    int k = name.length() - 1;
    if (name.startsWith("[") && name.endsWith("]")) name = name.substring(1, k).trim();
    else if (name.startsWith("(") && name.endsWith(")")) name = name.substring(1, k).trim();

    // Try it as a standard element specification
    int tag = DicomObject.getElementTag(name);
    if (tag != 0) return tag;

    // Try it as a private element name
    Integer tagInteger = privateElementNames.get(name);
    if (tagInteger != null) return tagInteger.intValue();

    // Try to match it as a private group element with a block specification
    Matcher matcher = pgPattern.matcher(name);
    if (matcher.matches()) {
      int group = StringUtil.getHexInt(matcher.group(1));
      if ((group & 1) == 1) {

        // It's a private group; get the block ID and the element offset
        String blockID = matcher.group(2).toUpperCase();
        int elem = StringUtil.getHexInt(matcher.group(3));

        // Now get the tag of the private group creator
        int creatorTag = pgIndex.getTagForID(group, blockID);
        if (creatorTag != 0) {
          return (group << 16) | ((creatorTag & 0xFF) << 8) | (elem & 0xFF);
        }
      }
    }

    // Try to match it as a private creator element with a block specification
    matcher = pcPattern.matcher(name);
    if (matcher.matches()) {
      int group = StringUtil.getHexInt(matcher.group(1));
      if ((group & 1) == 1) {

        // It's a private group; get the block ID
        String blockID = matcher.group(2).toUpperCase();

        // Now get the tag of the private group creator
        int creatorTag = pgIndex.getTagForID(group, blockID);
        if (creatorTag != 0) return creatorTag;
      }
    }
    return 0;
  }
Exemplo n.º 4
0
  private boolean checkDataset(Dataset ds) {
    boolean ok = true;
    for (Iterator it = ds.iterator(); it.hasNext(); ) {
      DcmElement el = (DcmElement) it.next();
      int tag = 0;
      try {
        tag = el.tag();
      } catch (Exception useZero) {
      }
      String command = scriptTable.get(new Integer(tag));
      if (command != null) {
        if (el.vr() == VRs.SQ) {
          Matcher processMatcher = processPattern.matcher(command);
          if (processMatcher.find()) {
            int i = 0;
            Dataset child;
            while ((child = el.getItem(i++)) != null) {
              ok &= checkDataset(child);
            }
          }
        } else {
          Matcher lookupMatcher = lookupPattern.matcher(command);
          // logger.info("Parsing: "+command);
          while (lookupMatcher.find()) {

            int nGroups = lookupMatcher.groupCount();
            String element = lookupMatcher.group(1).trim();
            String keyType = lookupMatcher.group(2).trim() + "/";
            String action = (nGroups > 2) ? lookupMatcher.group(3).trim() : "";
            String regex = (nGroups > 3) ? lookupMatcher.group(4).trim() : "";

            // logger.info("...nGroups  = "+nGroups);
            // logger.info("...element: |"+element+"|");
            // logger.info("...keyType: |"+keyType+"|");
            // logger.info("...action : |"+action+"|");
            // logger.info("...regex:   |"+regex+"|");

            int targetTag = (element.equals("this") ? tag : DicomObject.getElementTag(element));
            String targetValue = handleNull(ds.getString(targetTag));

            if (!targetValue.equals("")) {
              String key = keyType + targetValue;
              if (lutProps.getProperty(key) == null) {
                boolean there = false;
                if (action.equals("keep")
                    || action.equals("skip")
                    || action.equals("remove")
                    || action.equals("empty")
                    || action.equals("default")) there = true;
                else if (action.equals("ignore")) {
                  regex = removeQuotes(regex);
                  there = targetValue.matches(regex);
                }
                try {
                  if (!there) {
                    index.insert(key, keyType, true);
                    ok = false;
                  }
                } catch (Exception ignore) {
                }
              }
            }
          }
        }
      }
    }
    return ok;
  }