<commit_before># Go Level 7 [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/dshills/golevel7)

## 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
* Unmarshal into Go structs
* Simple query syntax

## 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

###	To extract data from a message
```go
	data := []byte(...) // raw message
	type my7 struct {
		FirstName string `hl7:"PID.5.1"`
		LastName  string `hl7:"PID.5.0"`
	}
	st := my7{}

	err := Unmarshal(data, &st)
```

### To decode an HL7 message into the Message struct
```go
	data := []byte(...) // raw message
	msg, err := Decode(data)
```

### To query the Message
```go
	data := []byte(...) // raw message
	msg, err := Decode(data)
	val,err := Retrieve(msg, "PID.5.1")
```

## To Do

* message encoding
* ACK building
* message validation
* elegant way to extract repeating segments and fields

## Alternatives

* [gohl7](https://github.com/yehezkel/gohl7)

## License
Copyright 2015, 2016 <NAME>. All rights reserved.
MIT license. License details can be found in the LICENSE file.

<commit_msg>Updated README for validations<commit_after># Go Level 7 [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/dshills/golevel7)

## 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
* Unmarshal into Go structs
* Simple query syntax

## 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

```go
data := []byte(...) // raw message
type my7 struct {
	FirstName string `hl7:"PID.5.1"`
	LastName  string `hl7:"PID.5.0"`
}
st := my7{}

err := Unmarshal(data, &st)
```

### Parse / Decode

```go
data := []byte(...) // raw message
msg, err := Decode(data)
```

### Message Query

```go
data := []byte(...) // raw message
msg, err := Decode(data)
val,err := Retrieve(msg, "PID.5.1")
```

### 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.

```go
val := []Validation{
	Validation{Location: "MSH.0", VCheck: SpecificValue, Value: "MSH"},
	Validation{Location: "MSH.1", VCheck: HasValue},
	Validation{Location: "MSH.2", VCheck: HasValue},
}
data := []byte(...) // raw message
msg, err := Decode(data)
valid, failures := IsValid(msg, val)
```

## To Do

* message encoding
* ACK building
* elegant way to extract repeating segments and fields

## Alternatives

* [gohl7](https://github.com/yehezkel/gohl7)

## License
Copyright 2015, 2016 <NAME>. All rights reserved.
MIT license. License details can be found in the LICENSE file.


{'fraction_non_alphanumeric': 0.10860103626943005, 'fraction_numerical': 0.02010362694300518, 'mean_word_length': 4.167023554603855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '696564', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1443, 'n_words': 604}