Coder Social home page Coder Social logo

golevel7's Introduction

Go Level 7 GoDoc

Overview

Go Level 7 is a decoder / encoder for HL7.

Health Level-7 or HL7 refers to a set of international standards for transfer of clinical and administrative data between software applications used by various healthcare providers. These standards focus on the application layer, which is "layer 7" in the OSI model. -Wikipedia

Features

  • Decode HL7 messages
  • Multiple message support with Split
  • Unmarshal into Go structs
  • Simple query syntax
  • Message validation

Note: Message building is not currently working for MSH segments. Coming soon...

Installation

go get github.com/dshills/golevel7

Usage

Data Location Syntax

segment-name.field-sequence-number.component.subcomponent
Segments are specified using the three letter name (MSH)
Fields are specifified by the sequence number of the HL7 specification (Field 0 is always the segment name)
Components and Subcomponents are 0 based indexes
"" returns the message
"PID" returns the PID segment
"PID.5" returns the 5th field of the PID segment
"PID.5.1" returns the 1st component of the 5th field of the PID segment
"PID.5.1.2" returns the 2nd subcomponent of the 1st component of the 5th field of the PID

Data Extraction / Unmarshal

data := []byte(...) // raw message
type my7 struct {
	FirstName string `hl7:"PID.5.1"`
	LastName  string `hl7:"PID.5.0"`
}
st := my7{}
msg := golevel7.NewMessage(data.Bytes())
err := golevel7.Unmarshal(&st)

Generating Sets Of Decoded Messages

msgs, err := golevel7.NewDecoder(reader).Messages()

// well suited for single or small sets of messages // not well suited for large sets of messages

ms:=golevel7.NewMessageScanner(reader)
for ms.Scan() {
	msg:=ms.Message()
}
if err:=ms.Err(); err!=nil {
	fmt.Fprintln(os.Stderr, "reading messages:", err)
}

Message Query

First matching value val, err := msg.Find("PID.5.1")

All matching values vals, err := msg.FindAll("PID.11.1")


### Message building

```go
	type aMsg struct {
		FirstName string `hl7:"PID.5.1"`
		LastName  string `hl7:"PID.5.0"`
	}
	mi := golevel7.MsgInfo{
		SendingApp:        "MyApp",
		SendingFacility:   "MyPlace",
		ReceivingApp:      "EMR",
		ReceivingFacility: "MedicalPlace",
		MessageType:       "ORM^001",
	}
	msg, err := golevel7.StartMessage(mi)
	am := aMsg{FirstName: "Davin", LastName: "Hills"}
	bstr, err = golevel7.Marshal(msg, &am)

	// Manually

	type MyHL7Message struct {
		SendingApp        string `hl7:"MSH.3"`
		SendingFacility   string `hl7:"MSH.4"`
		ReceivingApp      string `hl7:"MSH.5"`
		ReceivingFacility string `hl7:"MSH.6"`
		MsgDate           string `hl7:"MSH.7"`
		MessageType       string `hl7:"MSH.9"`
		ControlID         string `hl7:"MSH.10"`
		ProcessingID      string `hl7:"MSH.11"`
		VersionID         string `hl7:"MSH.12"`
		FirstName         string `hl7:"PID.5.1"`
		LastName          string `hl7:"PID.5.0"`
	}

	my := MyHL7Message{
		SendingApp:        "MyApp",
		SendingFacility:   "MyPlace",
		ReceivingApp:      "EMR",
		ReceivingFacility: "MedicalPlace",
		MessageType:       "ORM^001",
		MsgDate:           "20151209154606",
		ControlID:         "MSGID1",
		ProcessingID:      "P",
		VersionID:         "2.4",
		FirstName:         "Davin",
		LastName:          "Hills",
	}
	err := golevel7.NewEncoder(writer).Encode(&my)

Message Validation

Message validation is accomplished using the IsValid function. Create a slice of Validation structs and pass them, with the message, to the IsValid function. The first return value is a pass / fail bool. The second return value returns the Validation structs that failed.

A number of validation slices are already defined and can be combined to build custom validation criteria. The NewValidMSH24() function is one example. It returns a set of validations for the MSH segment for version 2.4 of the HL7 specification.

val := []golevel7.Validation{
	Validation{Location: "MSH.0", VCheck: SpecificValue, Value: "MSH"},
	Validation{Location: "MSH.1", VCheck: HasValue},
	Validation{Location: "MSH.2", VCheck: HasValue},
}
msg, err := golevel7.NewDecoder(reader).Message()
valid, failures := msg.IsValid(val)

To Do

  • Better handling of repeating fields for marshal and unmarshal
  • Better handling of repeating segments for marshal and unmarshal

Alternatives

License

Copyright 2015, 2016 Davin Hills. All rights reserved. MIT license. License details can be found in the LICENSE file.

golevel7's People

Contributors

dshills avatar itp-atakan avatar plisitza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

golevel7's Issues

Malformed go.mod

During dependency import :

go: github.com/dshills/[email protected]: parsing go.mod:
	module declares its path as: golevel7
	        but was required as: github.com/dshills/golevel7

In you go.mod you need to replace :
module golevel7

by
module github.com/dshills/golevel7

NewMessage() in Message.go fails for empty input slices

NewMessage() fails, if the input parameter is an empty slice since this new Message is parsed and no MSH is present at this time.

remove:

if err := newMessage.parse(); err != nil {
		log.Fatal(fmt.Sprintf("Parse Error: %+v", err))
	}

or initilize Message before parsing it.

hi! trying to use this to replace something else I have in an older language. actually, the usage of Unmarshall is different than the docs indicate, and doesn't actually parse, etc. I have a branch that fixes this, can I get permission to push a branch? also, do you still have time to maintain this? I'd like to take it over, it's very closely related to what I'm doing.... that said the first PR is quite small, handling many records, db/query-izing this, etc, is something I'm going to do anyway. I'd rather not start from scratch ;)

Parsing utf8 encoded messages

The parse methods in

  • segment.go
  • message.go
  • component.go
  • field.go

do not consider utf8 encoded files.

ch, _, _ := r.ReadRune() ii++

could be changed to

ch, size, _ := r.ReadRune() ii+=size

to correctly read multi byte encoded files.

[Question] Rationale for not returning errors?

Several functions, such as the one below, do not return an error.

func NewMessage(v []byte) *Message {

The nil value is used (such as msg == nil to determine success failure. This appears to lead to awkward error handling and the at least one use of a Fatal call.

I am new to this project, thus if there is a reason inherent to the workings of HL7 then that is something I am now aware of.
Excluding a hard requirement, what is the reason for not returning the idiomatic (and useful) result, err?

Along this lines, it seems like many calls do not handle errors. Is this intentional or a factor of time?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.