hl7parse
|
The goal of lib7
is to be a fast hl7 parser library that can deal with basically any hl7 files as long as the delimiters are used apropriately.
Features:
malloc()
and getc()
to a minimum, these seem to be the 2 bottle necks when parsing hl7 filesMSH-1
(default |
) and MSH-2
(default ^~\&
)C
/C++
applications and language bindingsIt is used as a library for 7view
(a Qt5 base hl7 viewer) and as library for Python 3 bindings which can be used for experimentation and rapid development.
For lib7
being quick at parsing hl7 files, the following compromises have been made:
lib7
has no understanding encodings, these high level functionality must be implemented by the userlib7
has no understanding of encodings, see point 1lib7
does not care about hl7 schemas, this is actually a feature since real world experience shows, that many system produce hl7 files that are structurally invalidIf you just want to use lib7
as a shared library the library is built as lib7.so
with a corresponding lib7.h
.
In the above example there is some magic happening which you may or may not like.
message_t->meta
contains delimiter information about a hl7 file. If this structure is not explicitly initialized and set, then the parser tries to read the delimiter information from the file. This is a feature but might fail on malformed hl7 files. For example, some hl7 files start with MSH|||||
:meta_t->sep_field
which defaults to |
|
we assume default separator characters ^~\&
, this might be wrong\r
but in the wild it may also be \n
or \r\n
). if the line separator is \r\n
(Windows, 2 character delimiter) the meta_t->crlf
is set to 1
else 0
. meta_t->crlf
is initially set to -1
which means the parser has to guess at the first encounter of a newline character.If you know the separators in a file and do not trust the autodetection (or the file defines wrong separators in MSH-1
and MSH-2
) then you have 2 options:
To have better control over separators, you may initialize meta_t
first:
See 7parse.c for an example implementation.
You may also manually detect the separators, then check and adjust, for example:
See 7pdf.c for an example.