Skip to content

Commit

Permalink
Modify flow no longer produces elements for empty streams
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlSjostrand committed May 26, 2017
1 parent 160f7f4 commit d3677d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/scala/se/nimsa/dcm4che/streams/DicomFlows.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ object DicomFlows {
var sequenceDepth = 0
var bigEndian = false
var explicitVR = true
var hasAttributes = false

def updateSyntax(header: DicomHeader): Unit = {
bigEndian = header.bigEndian
explicitVR = header.explicitVR
hasAttributes = true
}

def headerAndValue(tag: Int): List[DicomPart] = {
Expand Down Expand Up @@ -291,11 +293,13 @@ object DicomFlows {
case s: DicomSequenceDelimitation =>
sequenceDepth -= 1
s :: Nil
case DicomEndMarker =>
case DicomEndMarker if hasAttributes =>
modificationsLeft
.filter(_.insert)
.sortBy(_.tag)
.flatMap(modification => headerAndValue(modification.tag))
case DicomEndMarker =>
Nil
case part =>
part :: Nil
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/scala/se/nimsa/dcm4che/streams/DicomFlowsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,17 @@ class DicomFlowsTest extends TestKit(ActorSystem("DicomAttributesSinkSpec")) wit
.expectHeader(Tag.PatientName, VR.PN, patientNameJohnDoe.length - 8)
.expectValueChunk(patientNameJohnDoe.drop(8))
.expectDicomComplete()
}

it should "not insert attributes if dataset contains no attributes" in {
val source = Source.empty
.via(new DicomPartFlow())
.via(modifyFlow(TagModification(Tag.SeriesDate, _ => studyDate.drop(8), insert = true)))

source.runWith(TestSink.probe[DicomPart])
.expectDicomComplete()
}

"The deflate flow" should "recreate the dicom parts of a dataset which has been deflated and inflated again" in {
val bytes = fmiGroupLength(tsuidExplicitLE) ++ tsuidExplicitLE ++ patientNameJohnDoe ++ studyDate

Expand Down

0 comments on commit d3677d7

Please sign in to comment.