Skip to content

Commit

Permalink
Refactored method names and docs to more contemporary terms
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-exini committed Oct 12, 2020
1 parent 2bcec5c commit 74641a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/main/scala/com/exini/dicom/streams/CollectFlow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ object CollectFlow {
* elements can be processed correctly according to this information. As an example, an implementation may have
* different graph paths for different modalities and the modality must be known before any elements are processed.
*
* @param whitelist tag paths of data elements to collect. Collection (and hence buffering) will end when the
* @param allowlist tag paths of data elements to collect. Collection (and hence buffering) will end when the
* stream moves past the highest tag number
* @param label a tag for the resulting ElementsPart to separate this from other such elements in the same
* flow
* @param maxBufferSize the maximum allowed size of the buffer (to avoid running out of memory). The flow will fail
* if this limit is exceed. Set to 0 for an unlimited buffer size
* @return A DicomPart Flow which will begin with a ElementsPart part followed by other parts in the flow
*/
def collectFlow(whitelist: Set[_ <: TagTree], label: String, maxBufferSize: Int = 1000000): PartFlow = {
val maxTag = if (whitelist.isEmpty) 0 else whitelist.map(_.head.tag).map(intToUnsignedLong).max
def collectFlow(allowlist: Set[_ <: TagTree], label: String, maxBufferSize: Int = 1000000): PartFlow = {
val maxTag = if (allowlist.isEmpty) 0 else allowlist.map(_.head.tag).map(intToUnsignedLong).max
val tagCondition = (currentPath: TagPath) =>
whitelist.exists(t => t.hasTrunk(currentPath) || t.isTrunkOf(currentPath))
allowlist.exists(t => t.hasTrunk(currentPath) || t.isTrunkOf(currentPath))
val stopCondition = (tagPath: TagPath) =>
whitelist.isEmpty || tagPath.isRoot && intToUnsignedLong(tagPath.tag) > maxTag
allowlist.isEmpty || tagPath.isRoot && intToUnsignedLong(tagPath.tag) > maxTag
collectFlow(tagCondition, stopCondition, label, maxBufferSize)
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/scala/com/exini/dicom/streams/DicomFlows.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,44 +71,44 @@ object DicomFlows {
.takeWhile(_ != DicomEndMarker)

/**
* Filter a stream of dicom parts such that all elements except those with tags in the white list are discarded.
* Filter a stream of dicom parts such that all elements except those with tags in the allow list are discarded.
*
* Note that it is up to the user of this function to make sure the modified DICOM data is valid.
*
* @param whitelist list of tag paths to keep.
* @param allowList list of tag paths to keep.
* @param defaultCondition determines whether to keep or discard elements with no tag path such as the preamble and
* synthetic DICOM parts inserted to hold state.
* @return the associated filter Flow
*/
def whitelistFilter(
whitelist: Set[_ <: TagTree],
def allowFilter(
allowList: Set[_ <: TagTree],
defaultCondition: DicomPart => Boolean = _ => true,
logGroupLengthWarnings: Boolean = true
): PartFlow =
tagFilter(
currentPath => whitelist.exists(t => t.hasTrunk(currentPath) || t.isTrunkOf(currentPath)),
currentPath => allowList.exists(t => t.hasTrunk(currentPath) || t.isTrunkOf(currentPath)),
defaultCondition,
logGroupLengthWarnings
)

/**
* Filter a stream of dicom parts such that elements with tag paths in the black list are discarded. Tag paths in
* the blacklist are removed in the root dataset as well as any sequences, and entire sequences or items in sequences
* Filter a stream of dicom parts such that elements with tag paths in the deny list are discarded. Tag paths in
* the deny list are removed in the root dataset as well as any sequences, and entire sequences or items in sequences
* can be removed.
*
* Note that it is up to the user of this function to make sure the modified DICOM data is valid.
*
* @param blacklist list of tag paths to discard.
* @param denylist list of tag paths to discard.
* @param defaultCondition determines whether to keep or discard elements with no tag path such as the preamble and
* synthetic DICOM parts inserted to hold state.
* @return the associated filter Flow
*/
def blacklistFilter(
blacklist: Set[_ <: TagTree],
def denyFilter(
denylist: Set[_ <: TagTree],
defaultCondition: DicomPart => Boolean = _ => true,
logGroupLengthWarnings: Boolean = true
): PartFlow =
tagFilter(currentPath => !blacklist.exists(_.isTrunkOf(currentPath)), defaultCondition, logGroupLengthWarnings)
tagFilter(currentPath => !denylist.exists(_.isTrunkOf(currentPath)), defaultCondition, logGroupLengthWarnings)

/**
* Filter a stream of dicom parts such that all elements that are group length elements except
Expand Down
26 changes: 13 additions & 13 deletions src/test/scala/com/exini/dicom/streams/DicomFlowsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class DicomFlowsTest
.expectDicomComplete()
}

it should "filter elements matching the blacklist condition when testing with sample dicom files" in {
it should "filter elements matching the deny condition when testing with sample dicom files" in {
val file = new File(getClass.getResource("../data/test001.dcm").toURI)
val source = FileIO
.fromPath(file.toPath)
Expand All @@ -265,7 +265,7 @@ class DicomFlowsTest
.expectHeader(Tag.ImageType)
}

it should "filter leave the dicom file unchanged when blacklist condition does not match any elements" in {
it should "filter leave the dicom file unchanged when deny condition does not match any elements" in {
val file = new File(getClass.getResource("../data/test001.dcm").toURI)
val source = FileIO
.fromPath(file.toPath)
Expand All @@ -281,14 +281,14 @@ class DicomFlowsTest
.expectValueChunk()
}

"The whitelist filter" should "block all elements not on the white list" in {
"The allow filter" should "block all elements not on the allow list" in {
val bytes =
preamble ++ fmiGroupLength(transferSyntaxUID()) ++ transferSyntaxUID() ++ personNameJohnDoe() ++ studyDate()

val source = Source
.single(bytes)
.via(parseFlow)
.via(whitelistFilter(Set(TagTree.fromTag(Tag.StudyDate)), _ => false))
.via(allowFilter(Set(TagTree.fromTag(Tag.StudyDate)), _ => false))

source
.runWith(TestSink.probe[DicomPart])
Expand All @@ -305,7 +305,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(whitelistFilter(Set(TagTree.fromTag(Tag.StudyDate)), _ => false))
.via(allowFilter(Set(TagTree.fromTag(Tag.StudyDate)), _ => false))

source
.runWith(TestSink.probe[DicomPart])
Expand All @@ -319,7 +319,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(whitelistFilter(Set.empty, _ => false))
.via(allowFilter(Set.empty, _ => false))

source
.runWith(TestSink.probe[DicomPart])
Expand All @@ -334,7 +334,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(whitelistFilter(Set(TagTree.fromAnyItem(Tag.DerivationCodeSequence).thenTag(Tag.StudyDate)), _ => false))
.via(allowFilter(Set(TagTree.fromAnyItem(Tag.DerivationCodeSequence).thenTag(Tag.StudyDate)), _ => false))

source
.runWith(TestSink.probe[DicomPart])
Expand All @@ -355,7 +355,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(whitelistFilter(Set(TagTree.fromItem(Tag.DerivationCodeSequence, 2).thenTag(Tag.StudyDate)), _ => false))
.via(allowFilter(Set(TagTree.fromItem(Tag.DerivationCodeSequence, 2).thenTag(Tag.StudyDate)), _ => false))

source
.runWith(TestSink.probe[DicomPart])
Expand All @@ -368,7 +368,7 @@ class DicomFlowsTest
.expectDicomComplete()
}

"The blacklist filter" should "block the entire sequence when a sequence tag is on the black list" in {
"The deny filter" should "block the entire sequence when a sequence tag is on the deny list" in {
val bytes = studyDate() ++
(sequence(Tag.DerivationCodeSequence) ++ item() ++ personNameJohnDoe() ++
(sequence(
Expand All @@ -380,7 +380,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(blacklistFilter(Set(TagTree.fromAnyItem(Tag.DerivationCodeSequence)), _ => false))
.via(denyFilter(Set(TagTree.fromAnyItem(Tag.DerivationCodeSequence)), _ => false))

source
.runWith(TestSink.probe[DicomPart])
Expand All @@ -401,7 +401,7 @@ class DicomFlowsTest
.single(bytes)
.via(parseFlow)
.via(
blacklistFilter(
denyFilter(
Set(TagTree.fromTag(Tag.StudyDate), TagTree.fromItem(Tag.DerivationCodeSequence, 1)),
_ => false
)
Expand All @@ -427,7 +427,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(blacklistFilter(Set(TagTree.fromItem(Tag.DerivationCodeSequence, 1).thenTag(Tag.StudyDate)), _ => true))
.via(denyFilter(Set(TagTree.fromItem(Tag.DerivationCodeSequence, 1).thenTag(Tag.StudyDate)), _ => true))

source
.runWith(TestSink.probe[DicomPart])
Expand Down Expand Up @@ -766,7 +766,7 @@ class DicomFlowsTest
val source = Source
.single(bytes)
.via(parseFlow)
.via(blacklistFilter(Set(TagTree.fromTag(Tag.FileMetaInformationVersion)), _ => true))
.via(denyFilter(Set(TagTree.fromTag(Tag.FileMetaInformationVersion)), _ => true))
.via(fmiGroupLengthFlow)

source
Expand Down

0 comments on commit 74641a7

Please sign in to comment.