func FirstName(t *testing.T, message string) string {
	t.Helper()
	pid := PID(t, message)
	return pid.PatientName[0].GivenName.String()
}
FirstName returns the patient first name from the message.
package testhl7
import (
	"fmt"
	"strconv"
	"testing"
	"time"
	"github.com/google/simhospital/pkg/hl7"
)
func Parse(t *testing.T, message string) *hl7.Message {
	t.Helper()
	mo := hl7.NewParseMessageOptions()
	mo.TimezoneLoc = time.UTC
	m, err := hl7.ParseMessageWithOptions([]byte(message), mo)
	if err != nil {
		t.Fatalf("ParseMessageWithOptions(%s, %v) failed with %v", message, mo, err)
	}
	if m == nil {
		t.Fatalf("ParseMessageWithOptions(%s, %v) got nil message, want non nil", message, mo)
	}
	return m
}
func Fields(t *testing.T, messages []string, f func(*testing.T, string) string) []string {
	t.Helper()
	var result []string
	for _, m := range messages {
		result = append(result, f(t, m))
	}
	return result
}
func TimeFields(t *testing.T, messages []string, f func(*testing.T, string) *time.Time) []*time.Time {
	t.Helper()
	var result []*time.Time
	for _, m := range messages {
		result = append(result, f(t, m))
	}
	return result
}
func MSH(t *testing.T, message string) *hl7.MSH {
	t.Helper()
	m := Parse(t, message)
	msh, err := m.MSH()
	if err != nil {
		t.Fatalf("MSH() failed with %v", err)
	}
	if msh == nil {
		t.Fatal("MSH() got nil MSH segment, want non nil")
	}
	return msh
}
func OBX(t *testing.T, message string) *hl7.OBX {
	t.Helper()
	m := Parse(t, message)
	obx, err := m.OBX()
	if err != nil {
		t.Fatalf("OBX() failed with %v", err)
	}
	if obx == nil {
		t.Fatal("OBX() got nil OBX segment, want non nil")
	}
	return obx
}
func OBR(t *testing.T, message string) *hl7.OBR {
	t.Helper()
	m := Parse(t, message)
	obx, err := m.OBR()
	if err != nil {
		t.Fatalf("OBR() failed with %v", err)
	}
	if obx == nil {
		t.Fatal("OBR() got nil OBR segment, want non nil")
	}
	return obx
}
func MSA(t *testing.T, message string) *hl7.MSA {
	t.Helper()
	m := Parse(t, message)
	msa, err := m.MSA()
	if err != nil {
		t.Fatalf("MSA() failed with %v", err)
	}
	if msa == nil {
		t.Fatal("MSA() got nil MSA segment, want non nil")
	}
	return msa
}
func EVN(t *testing.T, message string) *hl7.EVN {
	t.Helper()
	m := Parse(t, message)
	evn, err := m.EVN()
	if err != nil {
		t.Fatalf("EVN() failed with %v", err)
	}
	if evn == nil {
		t.Fatal("EVN() got nil EVN segment, want non nil")
	}
	return evn
}
func PV1(t *testing.T, message string) *hl7.PV1 {
	t.Helper()
	m := Parse(t, message)
	pv1, err := m.PV1()
	if err != nil {
		t.Fatalf("PV1() failed with %v", err)
	}
	if pv1 == nil {
		t.Fatal("PV1() got nil PV1 segment, want non nil")
	}
	return pv1
}
func PID(t *testing.T, message string) *hl7.PID {
	t.Helper()
	m := Parse(t, message)
	pid, err := m.PID()
	if err != nil {
		t.Fatalf("PID() failed with %v", err)
	}
	if pid == nil {
		t.Fatal("PID() got nil PID segment, want non nil")
	}
	return pid
}
func PV2(t *testing.T, message string) *hl7.PV2 {
	t.Helper()
	m := Parse(t, message)
	pv2, err := m.PV2()
	if err != nil {
		t.Fatalf("PV2() failed with %v", err)
	}
	if pv2 == nil {
		t.Fatal("PV2() got nil PV2 segment, want non nil")
	}
	return pv2
}
func PV2OrNil(t *testing.T, message string) *hl7.PV2 {
	t.Helper()
	m := Parse(t, message)
	pv2, err := m.PV2()
	if err != nil {
		t.Fatalf("PV2() failed with %v", err)
	}
	return pv2
}
func TXA(t *testing.T, message string) *hl7.TXA {
	t.Helper()
	m := Parse(t, message)
	txa, err := m.TXA()
	if err != nil {
		t.Fatalf("TXA() failed with %v", err)
	}
	return txa
}
func AllDG1(t *testing.T, message string) []*hl7.DG1 {
	t.Helper()
	m := Parse(t, message)
	dg1, err := m.AllDG1()
	if err != nil {
		t.Fatalf("AllDG1() failed with %v", err)
	}
	return dg1
}
func AllPR1(t *testing.T, message string) []*hl7.PR1 {
	t.Helper()
	m := Parse(t, message)
	pr1, err := m.AllPR1()
	if err != nil {
		t.Fatalf("AllPR1() failed with %v", err)
	}
	return pr1
}
func AllAL1(t *testing.T, message string) []*hl7.AL1 {
	t.Helper()
	m := Parse(t, message)
	al1, err := m.AllAL1()
	if err != nil {
		t.Fatalf("AllAL1() failed with %v", err)
	}
	return al1
}
func AllOBX(t *testing.T, message string) []*hl7.OBX {
	t.Helper()
	m := Parse(t, message)
	obx, err := m.AllOBX()
	if err != nil {
		t.Fatalf("AllOBX() failed with %v", err)
	}
	return obx
}
func ORC(t *testing.T, message string) *hl7.ORC {
	t.Helper()
	m := Parse(t, message)
	orc, err := m.ORC()
	if err != nil {
		t.Fatalf("ORC() failed with %v", err)
	}
	if orc == nil {
		t.Fatal("ORC() got nil ORC segment, want non nil")
	}
	return orc
}
func MRG(t *testing.T, message string) *hl7.MRG {
	t.Helper()
	m := Parse(t, message)
	mrg, err := m.MRG()
	if err != nil {
		t.Fatalf("MRG() failed with %v", err)
	}
	if mrg == nil {
		t.Fatal("MRG() got nil ORC segment, want non nil")
	}
	return mrg
}
func MessageDateTime(t *testing.T, message string) time.Time {
	t.Helper()
	msh := MSH(t, message)
	return msh.DateTimeOfMessage.Time.UTC()
}
func PlacerNumber(t *testing.T, message string) string {
	t.Helper()
	orc := ORC(t, message)
	return orc.PlacerOrderNumber.EntityIdentifier.String()
}
func DeathIndicator(t *testing.T, message string) string {
	t.Helper()
	pid := PID(t, message)
	return pid.PatientDeathIndicator.String()
}
func DeathTime(t *testing.T, message string) *time.Time {
	t.Helper()
	pid := PID(t, message)
	if pid.PatientDeathDateAndTime == nil {
		return nil
	}
	return &pid.PatientDeathDateAndTime.Time
}
func OrderStatus(t *testing.T, message string) string {
	t.Helper()
	orc := ORC(t, message)
	return orc.OrderStatus.String()
}
func OBXSetID(t *testing.T, obx *hl7.OBX) string {
	t.Helper()
	return strconv.Itoa(int(obx.SetIDOBX.Value))
}
func ValueType(t *testing.T, obx *hl7.OBX) string {
	t.Helper()
	return obx.ValueType.String()
}
func OBXResultStatus(t *testing.T, obx *hl7.OBX) string {
	t.Helper()
	return obx.ObservationResultStatus.String()
}
func OBXFieldsFromOBXs(t *testing.T, obxs []*hl7.OBX, f func(*testing.T, *hl7.OBX) string) []string {
	var fromOBX []string
	for _, o := range obxs {
		fromOBX = append(fromOBX, f(t, o))
	}
	return fromOBX
}
func OBXFields(t *testing.T, messages []string, f func(*testing.T, *hl7.OBX) string) [][]string {
	t.Helper()
	var result [][]string
	for _, m := range messages {
		obxs := AllOBX(t, m)
		fromOBX := OBXFieldsFromOBXs(t, obxs, f)
		result = append(result, fromOBX)
	}
	return result
}
func MessageControlIDFromMSH(t *testing.T, message string) string {
	t.Helper()
	msh := MSH(t, message)
	return msh.MessageControlID.String()
}
func MessageControlIDFromMSA(t *testing.T, message string) string {
	t.Helper()
	msa := MSA(t, message)
	return msa.MessageControlID.String()
}
func PointOfCare(t *testing.T, message string) string {
	t.Helper()
	pv1 := PV1(t, message)
	return pv1.AssignedPatientLocation.PointOfCare.String()
}
func AccountStatus(t *testing.T, message string) string {
	t.Helper()
	pv1 := PV1(t, message)
	return pv1.AccountStatus.String()
}
func PatientClass(t *testing.T, message string) string {
	t.Helper()
	pv1 := PV1(t, message)
	return pv1.PatientClass.String()
}
func VisitNumber(t *testing.T, message string) string {
	t.Helper()
	pv1 := PV1(t, message)
	return pv1.VisitNumber.IDNumber.String()
}
func EventDateTime(t *testing.T, message string) time.Time {
	t.Helper()
	evn := EVN(t, message)
	return evn.RecordedDateTime.Time.UTC()
}