Example #1
0
func (q Query) Count(m hl7parser.Message) int {
	if !q.HasSegmentOffset && !q.HasField {
		return len(m.Segments(q.Segment))
	}

	s := m.Segment(q.Segment, q.SegmentOffset)
	if !q.HasField {
		return len(s)
	}

	if len(s) <= q.Field+1 {
		return 0
	}
	f := s[q.Field+1]
	if !q.HasFieldOffset && !q.HasComponent {
		return len(f)
	}

	if len(f) <= q.FieldOffset {
		return 0
	}
	fi := f[q.FieldOffset]
	if !q.HasComponent {
		return len(fi)
	}

	if len(fi) <= q.Component {
		return 0
	}
	c := fi[q.Component]
	if !q.HasSubComponent {
		return len(c)
	}

	if len(c) <= q.SubComponent {
		return 0
	}

	return 1
}
Example #2
0
func (q Query) Get(m hl7parser.Message) (string, bool) {
	s := m.Segment(q.Segment, q.SegmentOffset)

	if len(s) <= q.Field+1 {
		return "", false
	}
	f := s[q.Field+1]

	if len(f) <= q.FieldOffset {
		return "", false
	}
	fi := f[q.FieldOffset]

	if len(fi) <= q.Component {
		return "", false
	}
	c := fi[q.Component]

	if len(c) <= q.SubComponent {
		return "", false
	}

	return string(c[q.SubComponent]), true
}