Commits

Kevin A. Archie  committed 5e5c3f0

removed Predicate from TagPattern because of override ambiguity; write LO instead of UN

  • Participants
  • Parent commits 039aa16

Comments (0)

Files changed (2)

File src/main/java/org/nrg/dcm/edit/Assignment.java

 import java.util.SortedSet;
 
 import org.dcm4che2.data.DicomObject;
+import org.dcm4che2.data.VR;
 import org.dcm4che2.util.TagUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Objects;
 import com.google.common.collect.Sets;
  * @author Kevin A. Archie <karchie@wustl.edu>
  */
 public class Assignment extends AbstractOperation {
+    private final Logger logger = LoggerFactory.getLogger(Assignment.class);
     private final TagPattern pattern;
     private final Value value;
 
     public Assignment(final TagPattern tagpat, final Value value) {
-	super("Assign");
-	this.pattern = tagpat;
-	this.value = value;
+        super("Assign");
+        this.pattern = tagpat;
+        this.value = value;
     }
-    
+
     public Assignment(final int tag, final Value value) {
-	this(new TagPattern(tag), value);
+        this(new TagPattern(tag), value);
     }
 
     public Assignment(final Integer tag, final Value value) {
      * @see org.nrg.dcm.edit.Operation#affects(int)
      */
     public boolean affects(final int tag) {
-	return pattern.apply(tag);
+        return pattern.apply(tag);
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.nrg.dcm.edit.Operation#getTopTag()
      */
     public int getTopTag() {
-	final SortedSet<Integer> tags = Sets.newTreeSet(value.getTags());
-	tags.add(pattern.getTopTag());
-	return tags.last();
+        final SortedSet<Integer> tags = Sets.newTreeSet(value.getTags());
+        tags.add(pattern.getTopTag());
+        return tags.last();
     }
-    
+
     /*
      * (non-Javadoc)
      * @see java.lang.Object#equals(java.lang.Object)
      * @see org.nrg.dcm.edit.Operation#makeAction(org.dcm4che2.data.DicomObject)
      */
     public Action makeAction(final DicomObject o) throws ScriptEvaluationException {
-	final String v = value.on(o);
-	return new Action() {
-	    public void apply() throws ScriptEvaluationException {
-		for (final int tag : pattern.apply(o)) {
-		    try {
-			o.putString(new int[]{tag}, o.vrOf(tag), v);
+        final String v = value.on(o);
+        return new Action() {
+            public void apply() throws ScriptEvaluationException {
+                for (final int tag : pattern.apply(o)) {
+                    VR vr = o.vrOf(tag);
+                    if (VR.UN.equals(vr)) {
+                        logger.debug("VR for {} is UN; writing as LO instead", TagUtils.toString(tag));
+                        vr = VR.LO;
+                    }
+                    try {
+                        o.putString(new int[]{tag}, vr, v);
 
-		    } catch (UnsupportedOperationException e) {
-			throw new ScriptEvaluationException("Unable to set attribute "
-				+ TagUtils.toString(tag) + " to \"" + v + "\"", e);
-		    }
-		}
+                    } catch (UnsupportedOperationException e) {
+                        throw new ScriptEvaluationException("Unable to set attribute "
+                                + TagUtils.toString(tag) + " (VR " + vr + ") to \"" + v + "\"", e);
+                    }
+                }
 
-	    }
+            }
             public String toString() {
                 return MessageFormat.format("{0}: {1} := {2}",
                         new Object[]{getName(), pattern, v});

File src/main/java/org/nrg/dcm/edit/TagPattern.java

 /**
- * Copyright (c) 2012 Radiologics, Inc.
+ * Copyright (c) 2012 Washington University
  */
 package org.nrg.dcm.edit;
 
 import org.dcm4che2.data.DicomObject;
 
 import com.google.common.base.Function;
-import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 
  * @author Kevin A. Archie <karchie@wustl.edu>
  *
  */
-public class TagPattern implements Predicate<Integer>,Function<DicomObject,Iterable<Integer>> {
+public class TagPattern implements Function<DicomObject,Iterable<Integer>> {
     public static final Character ANY_DIGIT = Character.valueOf('X');
     public static final Character EVEN_DIGIT = Character.valueOf('@');
     public static final Character ODD_DIGIT = Character.valueOf('#');
      * @see com.google.common.base.Predicate#apply(java.lang.Object)
      */
     public boolean apply(@Nullable Integer tag) {
-	if (null == tag) {
-	    return false;
-	}
-	final long t = tag & 0xffffffffL;
-	return (t & exactMask) == exactPart
-		&& matchesMod2(t, evenMask, 0)
-		&& matchesMod2(t, oddMask, 1);
+        if (null == tag) {
+            return false;
+        }
+
+        final long t = tag & 0xffffffffL;
+        return (t & exactMask) == exactPart
+                && matchesMod2(t, evenMask, 0)
+                && matchesMod2(t, oddMask, 1);
     }
     
     /**