Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ A Go library for parsing, transforming, and validating HL7 version 2.x messages

Zero external dependencies. Requires Go 1.23+.

> [!WARNING]
> The code in this project is mostly generated by an AI tool (Claude Code). This project is intended as a personal experiment to observe the efficacy of generative AI tools in software development. All code has been reviewed by a human, and the implemented algorithms were developed using instruction from a human.

```go
msg, _ := hl7.ParseMessage(rawBytes)

Expand Down
27 changes: 19 additions & 8 deletions accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package hl7

import "strconv"
import (
"strconv"
"unsafe"
)

// Location represents a specific position in an HL7 message hierarchy.
// All indices are 0-based internally. The string representation uses
Expand All @@ -38,21 +41,29 @@ type Location struct {
// Location{Segment: "OBX", SegmentIndex: 1, Field: 5}.String() // "OBX(1)-5"
// Location{Segment: "PID", Field: 3, Repetition: 1}.String() // "PID-3[1]"
func (loc Location) String() string {
s := loc.Segment
b := make([]byte, len(loc.Segment), 110)
copy(b, []byte(loc.Segment))
if loc.SegmentIndex > 0 {
s += "(" + strconv.Itoa(loc.SegmentIndex) + ")"
b = append(b, '(')
b = strconv.AppendInt(b, int64(loc.SegmentIndex), 10)
b = append(b, ')')
}
s += "-" + strconv.Itoa(loc.Field)
b = append(b, '-')
b = strconv.AppendInt(b, int64(loc.Field), 10)
if loc.Repetition > 0 {
s += "[" + strconv.Itoa(loc.Repetition) + "]"
b = append(b, '[')
b = strconv.AppendInt(b, int64(loc.Repetition), 10)
b = append(b, ']')
}
if loc.Component > 0 {
s += "." + strconv.Itoa(loc.Component)
b = append(b, '.')
b = strconv.AppendInt(b, int64(loc.Component), 10)
}
if loc.SubComponent > 0 {
s += "." + strconv.Itoa(loc.SubComponent)
b = append(b, '.')
b = strconv.AppendInt(b, int64(loc.SubComponent), 10)
}
return s
return unsafe.String(unsafe.SliceData(b), len(b))
}

// ParseLocation parses a terser-style location string into a Location.
Expand Down
15 changes: 15 additions & 0 deletions accessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,21 @@ func TestMessageGetPresentButEmptyField(t *testing.T) {
}
}

func BenchmarkLocationString(b *testing.B) {
l := Location{
Segment: "PID",
SegmentIndex: 123,
Field: 123,
Repetition: 123,
Component: 123,
SubComponent: 123,
}

for b.Loop() {
_ = l.String()
}
}

func BenchmarkParseLocation(b *testing.B) {
inputs := []struct {
name string
Expand Down
Loading