-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfield.go
More file actions
72 lines (65 loc) · 2.44 KB
/
field.go
File metadata and controls
72 lines (65 loc) · 2.44 KB
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
// Copyright 2026 Joshua Jones <joshua.jones.software@gmail.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hl7
// Field represents a single HL7 field, which may contain repetitions
// separated by the repetition separator (typically '~').
//
// A field with value "Smith~Jones" has two repetitions.
// Most fields have a single repetition.
//
// Field is a lightweight value type that scans for repetition
// boundaries on each access rather than caching parsed results.
type Field struct {
Value
}
// RepetitionCount returns the number of repetitions.
func (f Field) RepetitionCount() int {
return countDelimited(f.raw, f.delims.Repetition)
}
// Rep returns the repetition at the given 0-based index.
// Returns an empty Repetition if the index is out of range.
func (f Field) Rep(index int) Repetition {
if index < 0 {
return Repetition{Value: Value{delims: f.delims}}
}
slice := nthSlice(f.raw, f.delims.Repetition, index)
if slice == nil {
return Repetition{Value: Value{delims: f.delims}}
}
return Repetition{Value: Value{raw: slice, delims: f.delims}}
}
// Repetition represents one repetition of a field.
// Repetitions contain components separated by the component separator (typically '^').
//
// Repetition is a lightweight value type that scans for component
// boundaries on each access rather than caching parsed results.
type Repetition struct {
Value
}
// Component returns the component at the given 1-based index.
// Returns an empty Component if the index is out of range.
func (r Repetition) Component(index int) Component {
if index < 1 {
return Component{Value: Value{delims: r.delims}}
}
slice := nthSlice(r.raw, r.delims.Component, index-1)
if slice == nil {
return Component{Value: Value{delims: r.delims}}
}
return Component{Value: Value{raw: slice, delims: r.delims}}
}
// ComponentCount returns the number of components.
func (r Repetition) ComponentCount() int {
return countDelimited(r.raw, r.delims.Component)
}