-
Notifications
You must be signed in to change notification settings - Fork 46
/
messagefind_test.go
87 lines (75 loc) · 1.46 KB
/
messagefind_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package golevel7
import "testing"
func TestFind(t *testing.T) {
data, err := readFile("./testdata/msg3.hl7")
if err != nil {
t.Fatal(err)
}
msg := &Message{Value: []rune(string(data))}
msg.parse()
if err != nil {
t.Fatal(err)
}
val, err := msg.Find("OBR.4.3")
if err != nil {
t.Error(err)
}
if val != "CPT-4" {
t.Errorf("Expected CPT-4 got %s\n", val)
}
val, err = msg.Find("OBX.3.3")
if err != nil {
t.Error(err)
}
if val != "LOINC" {
t.Errorf("Expected LOINC got %s\n", val)
}
}
func TestFindAll(t *testing.T) {
data, err := readFile("./testdata/msg3.hl7")
if err != nil {
t.Fatal(err)
}
msg := &Message{Value: []rune(string(data))}
msg.parse()
if err != nil {
t.Fatal(err)
}
vals, err := msg.FindAll("OBX.1")
if err != nil {
t.Error(err)
}
if len(vals) != 4 {
t.Fatalf("Expected 4 got %d\n", len(vals))
}
if vals[0] != "1" {
t.Errorf("Expected 1 got %s\n", vals[0])
}
if vals[1] != "2" {
t.Errorf("Expected 2 got %s\n", vals[1])
}
if vals[2] != "3" {
t.Errorf("Expected 3 got %s\n", vals[2])
}
if vals[3] != "4" {
t.Errorf("Expected 4 got %s\n", vals[3])
}
}
func TestRepFields(t *testing.T) {
data, err := readFile("./testdata/msg.hl7")
if err != nil {
t.Fatal(err)
}
msg := &Message{Value: []rune(string(data))}
msg.parse()
if err != nil {
t.Fatal(err)
}
vals, err := msg.FindAll("PID.11.3")
if err != nil {
t.Error(err)
}
if len(vals) != 2 {
t.Errorf("Expected 2 got %d\n", len(vals))
}
}