hl7parse
|
experimental hl7 editing methods More...
Go to the source code of this file.
Functions | |
int | node_append_child (node_t *parent, node_t *node) |
append child More... | |
node_t * | node_insert_child_at (node_t *parent, node_t *child, int pos) |
unimplemented: set a child at the sold position More... | |
int | node_remove (node_t *node) |
unimplemented: remove a node More... | |
node_t * | node_remove_child (node_t *parent, node_t *child, int pos) |
unimplemented: remove a child from the children array More... | |
node_t * | node_create_n_append (node_t *parent) |
create and append and empty child node More... | |
node_t * | node_pad_children (node_t *parent, int count) |
create empty child nodes until count is reached More... | |
node_t * | node_create_empty (node_type_t type) |
create an empty node More... | |
unsigned char * | node_to_string (node_t *node, hl7_meta_t *meta, int *length) |
convert node structure into string More... | |
int | message_to_file (message_t *message, char *filename) |
write contents of message to file More... | |
unsigned char * | message_to_string (message_t *message) |
convert message structure to hl7 file More... | |
int | node_set_data (node_t *node, unsigned char *data, int length) |
update date of a node More... | |
int | node_set_string (node_t *node, char *data) |
set string data to node More... | |
int | node_get_by_addr (message_t *message, hl7_addr_t *addr, node_t **node) |
find a node by address More... | |
int | node_set_by_addr (message_t *message, hl7_addr_t *addr, unsigned char *value, int length) |
set a value by address More... | |
experimental hl7 editing methods
Node manipulation utilities
int message_to_file | ( | message_t * | message, |
char * | filename | ||
) |
write contents of message to file
same as message_to_string()
but writing to a file directly.
This message returns the bytes writte on sucess or a negative integer on error.
Error codes:
-1
: failed to open file for writing-2
: failed to convert segment to stringmessage | input to convert to string and write to file |
filename | string to file name where result shall be written |
unsigned char* message_to_string | ( | message_t * | message | ) |
convert message structure to hl7 file
returns a string containing all segments covnerted to string, separated by delimiters defined in meta.
If you want to use different line or field separators, you may change these in meta before passing it into this method.
This method will return a string buffer on success, or NULL on error.
message | input to convert to string |
append child
parent | the parent node to append a child to |
node | the ndoe to append to parent |
Node manipulation utilities
node_t* node_create_empty | ( | node_type_t | type | ) |
create an empty node
for type FIELDIST
, always create at least one field child node.
NULL
on FIELDLIST
which seems a bit strange.type | node type to create |
create and append and empty child node
Special treatement for FIELDLIST
, a FIELD
node is always appended and returned.
parent | the parent node to append a child to |
int node_get_by_addr | ( | message_t * | message, |
hl7_addr_t * | addr, | ||
node_t ** | node | ||
) |
find a node by address
The address of the found node will be set in the 3rd parameter. If the node could not be found, the return value will currespond to the node level where we could not find anything.
Let's say, the segment does not exist, then we return SEGMENT
. If the fieldlist is shorter than addr->fieldlist, then we return FIELDLIST
, etc.
Return codes: if the node cannot be found, the return code will correspond to the node type where we faild to traverse.
message | root node |
addr | address to search for |
node | this pointer contains the result node or NULL if not found |
unimplemented: set a child at the sold position
This function set a child at pos
.
We have cases to handle
parent | the parent node to append a child to |
child | the ndoe to append to parent |
pos | insert at this position |
create empty child nodes until count is reached
pad the children array until count is reached. care must be taken with node type NODELIST
which should always get a single empty child in the node list iself.
parent | parent node |
count | number to pad children to |
int node_remove | ( | node_t * | node | ) |
unimplemented: remove a node
this method will check parent and remove the reference from the children array, moving all elements after the removed one 1 slot to the front.
All child nodes (if any) are also deleted.
node | to remove from tree |
unimplemented: remove a child from the children array
find node, move all subsequent children one slot to the left, adjust num_children and return a reference to the removed node for de-allocation or further use.
parent | the parent node to append a child to |
child | the ndoe to append to parent |
pos | insert at this position |
int node_set_by_addr | ( | message_t * | message, |
hl7_addr_t * | addr, | ||
unsigned char * | value, | ||
int | length | ||
) |
set a value by address
This method creates a node structure if it does not exist.
Then it sets the value to the provided value.
If the node already existed, the method will destroy (deallocate) the old node and replace it with the new one.
return codes:
1
: Failed to allocate fieldlist2
: Failed to allocate field3
: Failed to set data on field4
: Failed to pad children on field (Comp)5
: Failed to set data on comp6
: Failed to pad children on field (subcmp)7
: Failed to set data on subcomp21
: tryed to add a component to a field that already has data22
: tryed to add a sub-component to a component that already has datamessage | root node to traverse to |
addr | address of the new node |
value | array of the new node's content |
length | of value |
int node_set_data | ( | node_t * | node, |
unsigned char * | data, | ||
int | length | ||
) |
update date of a node
Checks and frees already associated data.
Then allocates memory for the data and assoiates it with the node, length is udpated (length is the actual length, if you are setting a string, you have to count the \0
as well).
node | |
data | array buffer to set data of node to |
length | of the array buffer |
int node_set_string | ( | node_t * | node, |
char * | data | ||
) |
set string data to node
convenience function for node_set_data()
. This method takes care of tracking the data length. It will copy all data up until the first \0
character).
node | |
data |
unsigned char* node_to_string | ( | node_t * | node, |
hl7_meta_t * | meta, | ||
int * | length | ||
) |
convert node structure into string
This method concatenates a whole tree into a string. It can be used anywhere in the tree structure from SEGMENT
downwards.
If you want to use specific delimiters, make sure to create a custom meta_t structure. Otherwise (using default delimiter as of HL7 specification) just provice a default created with init_hl7_meta_t().
The length of the string is returned in the pointer of parameter 3 length
, however, the return string os \0
delimited.
node | root node |
meta | delimiter definitions |
length | returns the length of the output string |