Skip to content

Commit

Permalink
Support for AT Tag (#153)
Browse files Browse the repository at this point in the history
This fixes #143 by parsing elements with VR=AT as Ints (instead of the default fallback of parsing as strings).
  • Loading branch information
suyashkumar authored Dec 15, 2020
1 parent 2e5d754 commit 327782b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func readValue(r dicomio.Reader, t tag.Tag, vr string, vl uint32, isImplicit boo
return readString(r, t, vr, vl)
case tag.VRDate:
return readDate(r, t, vr, vl)
case tag.VRUInt16List, tag.VRUInt32List, tag.VRInt16List, tag.VRInt32List:
case tag.VRUInt16List, tag.VRUInt32List, tag.VRInt16List, tag.VRInt32List, tag.VRTagList:
return readInt(r, t, vr, vl)
case tag.VRSequence:
return readSequence(r, t, vr, vl)
Expand Down Expand Up @@ -459,7 +459,7 @@ func readInt(r dicomio.Reader, t tag.Tag, vr string, vl uint32) (Value, error) {
retVal := &intsValue{value: make([]int, 0, vl/2)}
for !r.IsLimitExhausted() {
switch vr {
case "US":
case "US", "AT":
val, err := r.ReadUInt16()
if err != nil {
return nil, err
Expand Down
7 changes: 3 additions & 4 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func verifyValueType(t tag.Tag, value Value, vr string) error {
valueType := value.ValueType()
var ok bool
switch vr {
case "US", "UL", "SL", "SS":
case "US", "UL", "SL", "SS", "AT":
ok = valueType == Ints
case "SQ":
ok = valueType == Sequences
Expand All @@ -272,8 +272,6 @@ func verifyValueType(t tag.Tag, value Value, vr string) error {
}
case "FL", "FD":
ok = valueType == Floats
case "AT":
fallthrough
default:
ok = valueType == Strings
}
Expand Down Expand Up @@ -450,7 +448,8 @@ func writeBytes(w dicomio.Writer, values []byte, vr string) error {
func writeInts(w dicomio.Writer, values []int, vr string) error {
for _, value := range values {
switch vr {
case "US", "SS":
// TODO(suyashkumar): consider additional validation of VR=AT elements.
case "US", "SS", "AT":
if err := w.WriteUInt16(uint16(value)); err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import (
"github.com/suyashkumar/dicom/pkg/uid"
)

// TestWrite tests the write package by ensuring that it is consistent with the
// Parse implementation. In particular, it is tested by writing out known
// collections of Element and reading them back in using the Parse API and
// ensuing the read in collection is equal to the initial collection.
//
// This also serves to test that the Parse implementation is consistent with the
// Write implementation (e.g. it kinda goes both ways and covers Parse too).
func TestWrite(t *testing.T) {
cases := []struct {
name string
Expand All @@ -34,6 +41,7 @@ func TestWrite(t *testing.T) {
mustNewElement(tag.PatientName, []string{"Bob", "Jones"}),
mustNewElement(tag.Rows, []int{128}),
mustNewElement(tag.FloatingPointValue, []float64{128.10}),
mustNewElement(tag.DimensionIndexPointer, []int{32, 36950}),
}},
expectedError: nil,
},
Expand Down

0 comments on commit 327782b

Please sign in to comment.