hl7

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Build Status Coverage Status GoDoc

Overview

HL7v2 stands for "Health Level 7: Version 2" - a specification for shuttling clinical data around and between medical institutions. While working on Medtasker with Nimblic, I've written this library for reading the protocol and querying the messages it contains.

I have a blog post on my website if you'd like to hear a bit more of the story.

Install

$ go get github.com/nwehr/hl7

New Features

This fork adds the ability to Unpack() a Message or Segment into a struct using tags

package main

import (
	"fmt"
	"github.com/nwehr/hl7"
	"strings"
	"time"
)

var testMessage = strings.Replace(`MSH|^~\&||GA0000||VAERS PROCESSOR|20010331605||ORU^R01|20010422GA03|T|2.3.1|||AL|
PID|||1234^^^^SR~1234-12^^^^LR~00725^^^^MR||Doe^John^Fitzgerald^JR^^^L||20001007|M||2106-3^White^HL70005|||(678) 555-1212^^PRN|
NK1|1|Jones^Jane^Lee^^RN|VAB^Vaccine administered by (Name)^HL70063|
NK1|2|Jones^Jane^Lee^^RN|FVP^Form completed by (Name)-Vaccine provider^HL70063|||(404) 554-9097^^WPN|
ORC|CN|||||||||||1234567^Welby^Marcus^J^Jr^Dr.^MD^L|||||||||Peachtree Clinic||(404) 554-9097^^WPN||
OBR|1|||^CDC VAERS-1 (FDA) Report|||20010316|
OBX|1|NM|21612-7^Reported Patient Age^LN||05|mo^month^ANSI|
`, "\n", "\r", -1)

func main() {
	m, _, _ := hl7.ParseMessage([]byte(testMessage))

	patient := struct {
		First  string    `hl7:"PID-5-2"`
		Last   string    `hl7:"PID-5-1"`
		Middle string    `hl7:"PID-5-3"`
		DOB    time.Time `hl7:"PID-7"`
		Gender string    `hl7:"PID-8"`
	}{}

	m.Unpack(&patient)

	fmt.Printf("%+v", patient)
}

License

3-clause BSD. A copy is included with the source.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Locale *time.Location

Functions

func ParseMessage

func ParseMessage(buf []byte) (Message, *Delimiters, error)

ParseMessage takes input as a `[]byte`, and returns the whole message, the control characters (as `*Delimiters`), and maybe an error.

func ParseMessageWithSeperator

func ParseMessageWithSeperator(buf []byte, sep byte) (Message, *Delimiters, error)

Types

type Component

type Component []RepeatedComponent

func (Component) SliceOfStrings

func (c Component) SliceOfStrings() []string

func (Component) String

func (c Component) String() string

type Delimiters

type Delimiters struct {
	Field, Component, Repeat, Escape, RepeatedComponent byte
}

type ErrInvalidHeader

type ErrInvalidHeader error

ErrInvalidHeader is returned if a message doesn't start with "MSH", or the header isn't exactly the correct length, or any of the control characters aren't unique

type ErrTooShort

type ErrTooShort error

ErrTooShort is returned if a message isn't long enough to contain a valid header

type Field

type Field []RepeatedField

func (Field) SliceOfStrings

func (f Field) SliceOfStrings() []string

func (Field) String

func (f Field) String() string

type Message

type Message []Segment

func (*Message) Pack

func (m *Message) Pack(in interface{}) (err error)

func (Message) Query

func (m Message) Query(query string) (res string, err error)

func (Message) QuerySlice

func (m Message) QuerySlice(query string) ([]string, error)

func (Message) Segment

func (m Message) Segment(name string, offset int) Segment

func (Message) Segments

func (m Message) Segments(name string) []Segment

func (*Message) SetString

func (m *Message) SetString(query string, value string) error

func (Message) String

func (m Message) String() string

func (Message) Unpack

func (m Message) Unpack(out interface{}) (err error)

type Query

type Query struct {
	Segment string

	HasSegmentOffset bool
	SegmentOffset    int

	HasField    bool
	IsRestField bool
	Field       int

	HasRepeatedField bool
	RepeatedField    int

	HasComponent    bool
	IsRestComponent bool
	Component       int

	HasRepeatedComponent    bool
	IsRestRepeatedComponent bool
	RepeatedComponent       int
}

func NewQuery

func NewQuery(segment string, segmentOffset, field, repeatedField, component, repeatedComponent int) Query

func ParseQuery

func ParseQuery(s string) (*Query, error)

func (Query) Count

func (q Query) Count(m Message) int

func (Query) Spew

func (q Query) Spew()

func (Query) String

func (q Query) String() string

type RepeatedComponent

type RepeatedComponent string

type RepeatedField

type RepeatedField []Component

func (RepeatedField) SliceOfStrings

func (f RepeatedField) SliceOfStrings() []string

func (RepeatedField) String

func (f RepeatedField) String() string

type Segment

type Segment []Field

func (Segment) Query

func (s Segment) Query(query string) (string, error)

func (Segment) QuerySlice

func (s Segment) QuerySlice(query string) ([]string, error)

func (Segment) SliceOfStrigs

func (s Segment) SliceOfStrigs() []string

func (Segment) String

func (s Segment) String() string

func (Segment) Tag added in v0.0.2

func (s Segment) Tag() string

func (Segment) Unpack

func (s Segment) Unpack(out interface{}) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL