예제 #1
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;
  }
예제 #2
0
 public ScriptTable(DAScript script) {
   super();
   Document scriptXML = script.toXML();
   Element scriptRoot = scriptXML.getDocumentElement();
   Node child = scriptRoot.getFirstChild();
   while (child != null) {
     if ((child instanceof Element) && child.getNodeName().equals("e")) {
       Element eChild = (Element) child;
       if (eChild.getAttribute("en").equals("T")) {
         int tag = StringUtil.getHexInt(eChild.getAttribute("t"));
         String command = eChild.getTextContent();
         Matcher processMatcher = processPattern.matcher(command);
         Matcher lookupMatcher = lookupPattern.matcher(command);
         Integer tagInteger = new Integer(tag);
         if (processMatcher.find() || lookupMatcher.find()) {
           this.put(tagInteger, command);
         }
       }
     }
     child = child.getNextSibling();
   }
 }