hl7

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

go-hl7 build status

Golang library for handling hl7 2.x Procotol

Install

go get github.com/DRK-Blutspende-BaWueHe/go-hl7

Features

  • Encoding
    • UTF8
    • ASCII
    • Windows1250
    • Windows1251
    • Windows1252
    • DOS852
    • DOS855
    • DOS866
    • ISO8859_1
  • Timezone Support
  • Marshal/Unmarshal function

Quick Start

The following Go code decodes a hl7 read from a File.

fileData, err := ioutil.ReadFile("tbd.hl7")
if err != nil {
  log.Fatal(err)
}

var message 
err := hl7.Unmarshal(
    []byte(filedata),
    &message,
    hl7.EncodingUTF8,
    hl7.TimezoneEuropeBerlin)

if err != nil {
   log.Fatal(err)
}

The following Go code encodes a hl7 message.

marshalledMessageBytes, err := hl7.Marshal(
    message,
    hl7.StandardFieldSeparator,
    hl7.EncodingASCII,
    hl7.TimezoneEuropeBerlin,
    hl7.StandardNotation)

if err != nil {
   log.Fatal(err)
}

To identify the version and type of the message, you can use the IdentifyMessage function.

var data string
messageType, protocolVersion, err := hl7.IdentifyMessage(
    []byte(data),
    hl7.EncodingUTF8,
)

Custom Messages and Segments

Segment Definition

You can define custom segments with the hl7 annotation. Field #0 is the Segment-identifier itself, here AL1.

// HL7 v2.4 - AL1 - Patient allergy information
// https://hl7-definition.caristix.com/v2/HL7v2.4/Segments/AL1
type AL1 struct {
    SetId               CE        `hl7:"1"`
    AllergenTypeCode    CE        `hl7:"2"`
    AllergenCode        CE        `hl7:"3"`
    AllergySeverityCode CE        `hl7:"4"`
    AllergyReactionCode string    `hl7:"5"`
    IdentificationDate  time.Time `hl7:"6,shortdate"`
}
Message Defintion

Messages are an arrangement of Segments. Use struct and []struct to group the records like so. You can then use these messages as target in the unmarshal-operation:

// HL7 v2.4 - SSU_U03 - Specimen status update
// https://hl7-definition.caristix.com/v2/HL7v2.4/TriggerEvents/SSU_U03
type SSU_U03 struct {
    MSH               MSH `hl7:"MSH" json:"MSH"`
    EquipmentDetail   EQU `hl7:"EQU" json:"EquipmentDetail"`
    SpecimenContainer []struct {
        SpecimenContainerDetail SAC `hl7:"SAC" json:"SpecimenContainerDetail"`
        ObservationResult       OBX `hl7:"OBX" json:"ObservationResult"`
    }
    Role ROL `hl7:"ROL,optional" json:"Role"`
}

Documentation

Index

Constants

View Source
const (
	ANNOTATION_FIELDSEPARATOR = "fieldseparator"
	ANNOTATION_DELIMITER      = "delimiter" // annotation that triggers the delimiters in the scanner to be reset
	ANNOTATION_REQUIRED       = "require"   // field-annotation: by default all fields are optinal
	ANNOTATION_OPTIONAL       = "optional"  // record-annotation: by default all records are mandatory
	ANNOTATION_SEQUENCE       = "sequence"  // indicating that a sequence number should be generated (output only)
	ANNOTATION_LONGDATE       = "longdate"
)
View Source
const ShortNotation = 2
View Source
const StandardNotation = 1

Variables

View Source
var EOF = fmt.Errorf("EOF")

Functions

func EncodeCharsetToUTF8From

func EncodeCharsetToUTF8From(charmap *charmap.Charmap, data []byte) ([]byte, error)

func IdentifyMessage added in v0.0.3

func IdentifyMessage(messageData []byte, encoding Encoding) (string, string, error)

func Marshal

func Marshal(message interface{}, fieldSeparator FieldSeparator, enc Encoding, tz Timezone, notation Notation) ([][]byte, error)

Marshal - wrap datastructure to code

func Unmarshal

func Unmarshal(messageData []byte, targetStruct interface{}, enc Encoding, tz Timezone) error

Types

type Delimiters

type Delimiters struct {
	Composite string
	Sub       string
	SubSub    string
	Repeat    string
	Escape    string
}

HL7 Format delimiters https://blog.interfaceware.com/hl7-delimiter-redefinitions/

type Encoding

type Encoding int
const EncodingASCII Encoding = 2
const EncodingDOS852 Encoding = 6
const EncodingDOS855 Encoding = 7
const EncodingDOS866 Encoding = 8
const EncodingISO8859_1 Encoding = 9
const EncodingUTF8 Encoding = 1
const EncodingWindows1250 Encoding = 3
const EncodingWindows1251 Encoding = 4
const EncodingWindows1252 Encoding = 5

type Error

type Error string

type FieldSeparator added in v0.0.7

type FieldSeparator string
const StandardFieldSeparator FieldSeparator = "|"

type LineBreak

type LineBreak int
const CR LineBreak = 0x13
const CRLF LineBreak = 0x1310
const LF LineBreak = 0x10

type Notation

type Notation int
Notation defines how the output format is build

ShortNotation will skip all delimiters to the right of the last value StandardNotation will always produce as many delimiters as there are values in the export-format

type OutputRecord

type OutputRecord struct {
	Field, Repeat, Component int
	Value                    string
}

type OutputRecords

type OutputRecords []OutputRecord

func (OutputRecords) Len

func (or OutputRecords) Len() int

used for sorting

func (OutputRecords) Less

func (or OutputRecords) Less(i, j int) bool

func (OutputRecords) Swap

func (or OutputRecords) Swap(i, j int)

type RETV

type RETV int
const (
	OK         RETV = 1
	UNEXPECTED RETV = 2 // an exit that wont abort processing. used for skipping optional records
	ERROR      RETV = 3 // a definite error that stops the process
)

func ParseStruct

func ParseStruct(bufferedInputLines []string, depth int, currentInputLine int, targetStruct interface{}, enc Encoding, tz Timezone, delimiters Delimiters) (int, RETV, error)

HL7 delimimters (default, rewritten at startup) https://blog.interfaceware.com/hl7-delimiter-redefinitions/ This function takes a string and a struct and matches the annotated fields to the string-input

type Timezone

type Timezone string
const TimezoneEuropeBerlin Timezone = "Europe/Berlin"
const TimezoneEuropeBudapest Timezone = "Europe/Budapest"
const TimezoneEuropeLondon Timezone = "Europe/London"
const TimezoneUTC Timezone = "UTC"

Directories

Path Synopsis
lib
hl7v23
Standard implementation for the lis2a2 protocol according to standard in every detail, will work for most with some tinkering....
Standard implementation for the lis2a2 protocol according to standard in every detail, will work for most with some tinkering....

Jump to

Keyboard shortcuts

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