-
Notifications
You must be signed in to change notification settings - Fork 4
/
coder.go
115 lines (105 loc) · 1.96 KB
/
coder.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package hl7
import (
"fmt"
"strconv"
"strings"
)
type RegistryLookup = map[string]any
type Registry interface {
Version() string
ControlSegment(string) (any, bool)
Segment(string) (any, bool)
Trigger(string) (any, bool)
DataType(string) (any, bool)
}
const tagName = "hl7"
type structType byte
const (
structUnknown structType = iota
structTrigger
structTriggerGroup // Trigger Sub-Type
structSegment
structDataType
)
type tag struct {
Order int32
Name string
Format string
Type structType
Meta bool
Omit bool
NoEscape bool
Sequence bool
FieldSep bool
FieldChars bool
Present bool
}
const hl7MetaName = "HL7"
func parseTag(fieldName, v string) (tag, error) {
t := tag{}
if len(v) == 0 {
return t, nil
}
t.Present = true
ss := strings.Split(v, ",")
s0 := ss[0]
sN := ss[1:]
if len(s0) > 0 {
i, err := strconv.ParseInt(s0, 10, 32)
if err != nil {
return t, fmt.Errorf("field %q: unable to parse tag position: %w", fieldName, err)
}
t.Order = int32(i)
}
switch fieldName {
case hl7MetaName:
t.Meta = true
}
for _, vv := range sN {
k, v, _ := strings.Cut(vv, "=")
switch k {
default:
return t, fmt.Errorf("field %q: unknown tag value %q", fieldName, vv)
case "name":
t.Name = v
case "type":
switch v {
default:
return t, fmt.Errorf("field %q: unknown type tag value %q", fieldName, vv)
case "t":
t.Type = structTrigger
case "tg":
t.Type = structTriggerGroup
case "s":
t.Type = structSegment
case "d":
t.Type = structDataType
}
case "format":
t.Format = v
case "noescape":
t.NoEscape = true
case "omit":
t.Omit = true
case "seq":
t.Sequence = true
case "required":
// TODO.
case "conditional":
// TODO.
case "len":
// TODO.
case "max":
// TODO.
case "display":
// TODO.
case "table":
// TODO.
case "fieldsep":
t.FieldSep = true
case "fieldchars":
t.FieldChars = true
}
}
return t, nil
}