hl7parse
Classes | Typedefs | Functions
address.h File Reference

hl7 address structures and utilities More...

This graph shows which files directly or indirectly include this file:

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_treset_addr (hl7_addr_t *addr)
 reset to default values More...
 
hl7_addr_tcreate_addr ()
 create address structure More...
 
hl7_addr_taddr_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_tclone_addr (hl7_addr_t *addr)
 clone an address More...
 
seg_count_tcreate_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...
 

Detailed Description

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.

Note
All elements in hl7_addr_t are intialized to -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).

HL7 adressing

String addresses are written i nthe following format, they are translated into an efficient struct hl7_addr_t:

SEG(3)-1(2).3.4
^ ^ ^ ^ ^ ^
| | | | | +-- optional: hl7_addr_t.subcmp (delimited by &)
| | | | +---- optional: hl7_addr_t.comp (delimited by ^)
| | | +------- optional: hl7_addr_t.field (delimited by ~)
| | +--------- optional: hl7_addr_t.fieldlist (delimited by |)
| +------------ optional: hl7_addr_t.seg_count (segement repetition)
+--------------- required: hl7_addr_t.segment (delimited by \r)

Typedef Documentation

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

◆ seg_count_t

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.

Function Documentation

◆ add_seg_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

Note
segments must be 3 char long strings. no bounds checking is done
Parameters
segmentstring segment
segcsegment struct
Returns
new count for provided segment

◆ addr_dump()

void addr_dump ( hl7_addr_t addr)

dispaly address

Debug method, will printf() the content of hl7_addr_t

Parameters
addraddress to dump

◆ addr_from_string()

hl7_addr_t* addr_from_string ( char *  str)

parse string adresss

shorthand for set_addr_from_string() which also allocates hl7_addr_t.

See also
set_addr_from_string()
Parameters
strstring address, see create_addr for format
Returns
parsed address as structure, NULL on error

◆ addr_to_string()

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.

Parameters
addrour address
Returns
string representation of address

◆ clone_addr()

hl7_addr_t* clone_addr ( hl7_addr_t addr)

clone an address

You must make sure to completely deallocate the newly created address,

See also
free_add().
Parameters
addraddress to clone
Returns
copy of address

◆ create_addr()

hl7_addr_t* create_addr ( )

create address structure

malloc() an hl7_addr_t struct and set all values to default values (reset_addr())

Returns
empty address struct

◆ create_seg_count()

seg_count_t* create_seg_count ( )

Create segment struct.

Returns
seg_count_t struct with allocated memory

◆ free_addr()

void free_addr ( hl7_addr_t addr)

free hl7_addr_t struct

Parameters
addraddress to free

◆ free_seg_count()

void free_seg_count ( seg_count_t segc)

free segment count struct

Parameters
segcstrcut to clear

◆ get_seg_count()

int get_seg_count ( char *  segment,
seg_count_t segc 
)

get count for segment name

get the count for a specific segment

Parameters
segmentstring name of the segment
segcsegment struct
Returns
count for segment, 0 if not found

◆ reset_addr()

hl7_addr_t* reset_addr ( hl7_addr_t addr)

reset to default values

set all values ot -1 and segment to NULL.

Parameters
addraddress struct to reset

◆ set_addr_from_string()

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 empty
Parameters
strstring address
ret_addraddress struct which will contain the string address
Returns
0 on success, error code otherwise