hl7parse
Classes | Typedefs | Enumerations | Functions
meta.h File Reference

hl7 meta data structures for message_t More...

#include <stdio.h>
#include "bom.h"
Include dependency graph for meta.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hl7_meta_t
 HL7 Seperator configuration. More...
 

Typedefs

typedef struct hl7_meta_t hl7_meta_t
 HL7 Seperator configuration. More...
 
typedef enum line_delimiter_t line_delimiter_t
 possible line endings
 

Enumerations

enum  line_delimiter_t { DELIM_NONE = 0, DELIM_CR, DELIM_LF, DELIM_CRLF }
 possible line endings More...
 

Functions

hl7_meta_tinit_hl7_meta_t (void)
 initialize the seperator data structure More...
 
char * hl7_meta_string (hl7_meta_t *meta)
 generate printable string of the meta data More...
 
void free_hl7_meta (hl7_meta_t *hl7_meta)
 free the data structure More...
 
line_delimiter_t find_line_delimiter (FILE *fd)
 find line delimiter More...
 
int read_meta (hl7_meta_t *hl7_meta, FILE *fd)
 read up until the 2nd field delimiter More...
 

Detailed Description

hl7 meta data structures for message_t

meta_t contains information in all hl7 separators of a file and the BOM.

read_meta() can detect the delimiters of a file pointed to by *fd.

find_line_delimiter() will seek the first CR or LF and will detect if CRLF is present. In case of CRLF the attribute crlf is set to 1 else 0 or -1 (initial value when no detection has happened yet).

https://docs.microsoft.com/en-us/biztalk/adapters-and-accelerators/accelerator-hl7/message-delimiters

Delimiter Value Usage
Segment terminator <cr> 0x0D A carriage return terminates a segment record. You cannot change this value.
Field separator | A pipe character separates two adjacent data fields within a segment. This character also separates the segment ID from the first data field in each segment.
Component separator ^ A hat character separates adjacent components of data fields where allowed by the HL7 standard.
Repetition separator ~ A tilde character separates multiple occurrences of components or subcomponents in a field where allowed by the HL7 standard.
Escape character\ You use an escape character with any field that conforms to an ST, TX, or FT data type, or with the data (fourth) component of the ED data type. If no escape characters exist in a message, you can omit this character. However, you must include it if you use subcomponents in the message.
Subcomponent separator & An ampersand character separates adjacent subcomponents of data fields where allowed by the HL7 standard. If there are no subcomponents, then you can omit this character.

Typedef Documentation

◆ hl7_meta_t

typedef struct hl7_meta_t hl7_meta_t

HL7 Seperator configuration.

See also
meta.h

Enumeration Type Documentation

◆ line_delimiter_t

possible line endings

Enumerator
DELIM_NONE 

undefined, not found

DELIM_CR 

Default HL7: 0x0D

DELIM_LF 

Unix: 0x0A

DELIM_CRLF 

Windows: 0x0D, 0x0A (must be other than all others ;)

Function Documentation

◆ find_line_delimiter()

line_delimiter_t find_line_delimiter ( FILE *  fd)

find line delimiter

This method will forward an FILE pointer upon it finds the first \n, \r or EOF. The FILE pointer will be restored to it's original position.

Parameters
fdfile pointer at theb eginnign of a file
Returns
0 if unknown.

◆ free_hl7_meta()

void free_hl7_meta ( hl7_meta_t hl7_meta)

free the data structure

make sure nothing points to the elements in this structure. All elements in the structure will be freed (including bom).

Parameters
hl7_metathe meta structure

◆ hl7_meta_string()

char* hl7_meta_string ( hl7_meta_t meta)

generate printable string of the meta data

Parameters
metaa hopefully populated meta data struct
Returns
formatted string

◆ init_hl7_meta_t()

hl7_meta_t* init_hl7_meta_t ( void  )

initialize the seperator data structure

Returns
initialized hl7_meta_t struct

◆ read_meta()

int read_meta ( hl7_meta_t hl7_meta,
FILE *  fd 
)

read up until the 2nd field delimiter

read up to 8 bytes to find all hl7 delimiters. This method assumes that it is reading an MSH segment (file pointer must be positioned at 'M').

Do not use it on any other hl7 segment!

This metod will detect all separators if they are defined. If not, separators will be left at the default.

The user must make sure to parse the right segment. fd must be pointing to the start character of an MSH or MSA segment.

The file pointer is reset at the end of this method and reset back to the byte after the BOM.

If no BOM detection has been done and meta->bom still is NULL, we'll run detect_bom() first. To prevent this, initialize the bom object with a length of 0.

Todo:
check if file length, there might only be 5 characters in it or less. handle error condition.
Note
do not re-use hl7_meta for different files, always detect separators before parsing.
this method fails if there is only one field separator, i.e. MSH| will return 1. even tho it may or maynot be a valid hl7 file MSH-2 is not followed by MSH-1 and therefore a reliable detection is not possible.

Return codes:

  • 0: success
  • 1: the field delimiter was not found after the delimiters
  • 2: premature file end
  • 3: file does not begin with MSH
Parameters
hl7_metapointer to an empty metadata structure
fdfile pointer pointing to the beginning of MSH or MSA segment
Returns
0 on succes, error code otherwise