hl7parse
|
hl7 address structures and utilities More...
Go to the source code of this file.
Classes | |
struct | hl7_addr_t |
hl7 element address More... | |
struct | seg_count |
keep track of the number of the same segments in a message_t More... | |
Typedefs | |
typedef struct hl7_addr_t | hl7_addr_t |
hl7 element address More... | |
typedef struct seg_count | seg_count_t |
keep track of the number of the same segments in a message_t More... | |
Functions | |
hl7_addr_t * | reset_addr (hl7_addr_t *addr) |
reset to default values More... | |
hl7_addr_t * | create_addr () |
create address structure More... | |
hl7_addr_t * | addr_from_string (char *str) |
parse string adresss More... | |
int | set_addr_from_string (char *str, hl7_addr_t **ret_addr) |
set address by string More... | |
char * | addr_to_string (hl7_addr_t *addr) |
create a string representation of the address More... | |
void | free_addr (hl7_addr_t *addr) |
free hl7_addr_t struct More... | |
void | addr_dump (hl7_addr_t *addr) |
dispaly address More... | |
hl7_addr_t * | clone_addr (hl7_addr_t *addr) |
clone an address More... | |
seg_count_t * | create_seg_count () |
Create segment struct. More... | |
void | free_seg_count (seg_count_t *segc) |
free segment count struct More... | |
int | add_seg_count (char *segment, seg_count_t *segc) |
increment count for segment More... | |
int | get_seg_count (char *segment, seg_count_t *segc) |
get count for segment name More... | |
hl7 address structures and utilities
Parse address strings into hl7_addr_t and vice versa. All string addresses start with 1
for the first element. This is an end-user interface. All internal addresses in hl7_addr_t start with 0
whereis -1
means undefined
.
-1
. If a address string is parsed with set_addr_from_string, all elements which remain at -1
have not been specified in the string (thus are unset).String addresses are written i nthe following format, they are translated into an efficient struct hl7_addr_t:
typedef struct hl7_addr_t hl7_addr_t |
hl7 element address
All addresses start with 0
. -1
means undefined (not specified when a string was converted to hl7_addr_t).
Some obvious defaults must be taken into account by the user. For example, if field
is -1
, then it always should be treated as 0
, because there is no element with an undefined number of fields (repetitions), if not specified, the first element hast to be used.
Same for seg_count
, if it is not specified (and therefore equals -1
) the first index 0
is meant.
typedef struct seg_count seg_count_t |
keep track of the number of the same segments in a message_t
This struct keeps track of the number of segments with the same name. This is important when search certain elements, to make sure we do not overrun buffers.
All memory is allocated dynamically, _allocated
keeps track of the length of allocated space in count
and segments
. length
keeps track of the used elements.
The count of a segment
can be foudn at the same index in count
.
int add_seg_count | ( | char * | segment, |
seg_count_t * | segc | ||
) |
increment count for segment
This method dynamically allocates more memory for segment and count if required
segment | string segment |
segc | segment struct |
void addr_dump | ( | hl7_addr_t * | addr | ) |
dispaly address
Debug method, will printf() the content of hl7_addr_t
addr | address to dump |
hl7_addr_t* addr_from_string | ( | char * | str | ) |
parse string adresss
shorthand for set_addr_from_string() which also allocates hl7_addr_t.
str | string address, see create_addr for format |
char* addr_to_string | ( | hl7_addr_t * | addr | ) |
create a string representation of the address
Allocates memory for a string and rturns the string representation of addr.
addr | our address |
hl7_addr_t* clone_addr | ( | hl7_addr_t * | addr | ) |
clone an address
You must make sure to completely deallocate the newly created address,
addr | address to clone |
hl7_addr_t* create_addr | ( | ) |
create address structure
malloc() an hl7_addr_t struct and set all values to default values (reset_addr())
seg_count_t* create_seg_count | ( | ) |
Create segment struct.
void free_addr | ( | hl7_addr_t * | addr | ) |
free hl7_addr_t struct
addr | address to free |
void free_seg_count | ( | seg_count_t * | segc | ) |
free segment count struct
segc | strcut to clear |
int get_seg_count | ( | char * | segment, |
seg_count_t * | segc | ||
) |
get count for segment name
get the count for a specific segment
segment | string name of the segment |
segc | segment struct |
hl7_addr_t* reset_addr | ( | hl7_addr_t * | addr | ) |
reset to default values
set all values ot -1
and segment to NULL
.
addr | address struct to reset |
int set_addr_from_string | ( | char * | str, |
hl7_addr_t ** | ret_addr | ||
) |
set address by string
Parses a string address, and returns ret_addr srtuct containing the string definition. ret_addr will first be reset.
returns 0
on succes and the following error codes otherwise:
-1
: string length 0-2
: segment count not ended by )
-3
: field address must start with -
-4
: field address is not a digit-5
: expected (
or .
after field-6
: invalid field address, must at least set SEG-N-7
: field repetition (
must be followed by digit-8
: field repetition may only contain digits between (
and )
-9
: premature end in field repetition (fieldlist)-10
: preamture end, expecting component address after .
-11
: value error, only digits allowed in component address after .
-12
: premature end, comp address is empty-13
: invalid character followed after comp-14
: '.' for subcomp must be followed by an address, end of string reached-15
: premature end, subcomp address is emptystr | string address |
ret_addr | address struct which will contain the string address |