-
Notifications
You must be signed in to change notification settings - Fork 23
/
message.go
52 lines (41 loc) · 808 Bytes
/
message.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
package hl7 // import "fknsrs.biz/p/hl7"
import (
"github.com/facebookgo/stackerr"
)
type (
Message []Segment
Segment []Field
Field []FieldItem
FieldItem []Component
Component []Subcomponent
Subcomponent string
)
func (m Message) Segments(name string) []Segment {
var a []Segment
for _, s := range m {
if string(s[0][0][0][0]) == name {
a = append(a, s)
}
}
return a
}
func (m Message) Segment(name string, index int) Segment {
i := 0
for _, s := range m {
if string(s[0][0][0][0]) == name {
if i == index {
return s
}
i++
}
}
return nil
}
func (m Message) Query(s string) (res string, ok bool, err error) {
q, err := ParseQuery(s)
if err != nil {
return "", false, stackerr.Wrap(err)
}
res, ok = q.Get(m)
return res, ok, nil
}