Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class TagActionMap {

private static final Pattern TAG_SEPARATORS = Pattern.compile("[(),]");
private static final Pattern TAG_SEPARATORS = Pattern.compile("[(),\\s]");

/** A tag pattern resolved to its matching tag value and bit mask. */
private record PatternAction(int tag, int mask, ActionItem action) {
Expand Down Expand Up @@ -55,17 +55,17 @@ public void put(String tag, ActionItem action) {
if (isValidPattern(cleanTag)) {
int patternTag = TagUtils.intFromHexString(cleanTag.replace("X", "0"));
int patternMask = TagUtils.intFromHexString(getMask(cleanTag));
tagPatternAction.put(cleanTag, new PatternAction(patternTag, patternMask, action));
this.tagPatternAction.put(cleanTag, new PatternAction(patternTag, patternMask, action));
}
else {
tagAction.put(TagUtils.intFromHexString(cleanTag), action);
this.tagAction.put(TagUtils.intFromHexString(cleanTag), action);
}
}

public @Nullable ActionItem get(Integer tag) {
ActionItem action = tagAction.get(tag);
ActionItem action = this.tagAction.get(tag);
if (action == null) {
for (PatternAction pattern : tagPatternAction.values()) {
for (PatternAction pattern : this.tagPatternAction.values()) {
if ((tag & pattern.mask()) == pattern.tag()) {
return pattern.action();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
*/
package org.karnak.backend.model.profilepipe;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.dcm4che3.data.Tag;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand All @@ -23,6 +17,12 @@
import org.karnak.backend.model.action.Keep;
import org.karnak.backend.model.action.Remove;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

@DisplayNameGeneration(ReplaceUnderscores.class)
class TagActionMapTest {

Expand Down Expand Up @@ -123,6 +123,36 @@ void returns_null_when_no_entry_matches() {
assertNull(map.get(Tag.StudyDate));
}

@Test
void ignores_spaces_in_an_exact_tag() {
TagActionMap map = new TagActionMap();
Keep keep = new Keep("K");

map.put("(0010, 0010)", keep);

assertSame(keep, map.get(Tag.PatientName));
}

@Test
void ignores_surrounding_and_inner_spaces_in_an_exact_tag() {
TagActionMap map = new TagActionMap();
Keep keep = new Keep("K");

map.put(" ( 0010 , 0010) ", keep);

assertSame(keep, map.get(Tag.PatientName));
}

@Test
void ignores_spaces_in_a_wildcard_pattern() {
TagActionMap map = new TagActionMap();
Remove remove = new Remove("X");

map.put("(0010, XXXX)", remove);

assertSame(remove, map.get(Tag.PatientName));
}

}

@Nested
Expand All @@ -148,4 +178,4 @@ void counts_both_exact_and_pattern_entries() {

}

}
}