This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
query_test.go
57 lines (53 loc) · 1.54 KB
/
query_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dicom_test
import (
"testing"
"github.com/grailbio/go-dicom"
"github.com/grailbio/go-dicom/dicomtag"
"github.com/stretchr/testify/assert"
)
func TestParse0(t *testing.T) {
ds, err := dicom.ReadDataSetFromFile("examples/I_000013.dcm", dicom.ReadOptions{})
if err != nil {
t.Fatal(err)
}
studyUID := "1.2.840.113857.1907.192833.1115.220048"
match, elem, err := dicom.Query(ds, dicom.MustNewElement(dicomtag.StudyInstanceUID, studyUID))
assert.True(t, match)
assert.NoError(t, err)
assert.Equal(t, elem.MustGetString(), studyUID)
}
func TestParseDate(t *testing.T) {
goodDateRanges := []struct {
str string
startISO8601 string
endISO8601 string
}{
{"20170927-20170929", "2017-09-27", "2017-09-29"},
{"-20170929", "0000-01-01", "2017-09-29"},
{"20170927-", "2017-09-27", "9999-12-31"},
}
for _, r := range goodDateRanges {
s, e, err := dicom.ParseDate(r.str)
assert.NoError(t, err)
assert.Equal(t, s.String(), r.startISO8601)
assert.Equal(t, e.String(), r.endISO8601)
}
goodDates := []struct {
str string
iso8601 string
}{
{"20170101", "2017-01-01"},
{"2017.02.03", "2017-02-03"},
}
for _, goodDate := range goodDates {
s, e, err := dicom.ParseDate(goodDate.str)
assert.NoError(t, err, "Date:", goodDate)
assert.Equal(t, s.String(), goodDate.iso8601)
assert.Equal(t, e.Year, dicom.InvalidYear)
}
badDates := []string{"2017.0101", "2017.01", "2017X01.02", "201X0405"}
for _, badDate := range badDates {
_, _, err := dicom.ParseDate(badDate)
assert.Error(t, err, "Date:", badDate)
}
}