hl7parse
Public Attributes | List of all members
node_t Struct Reference

primary storage type of a delimited element More...

#include <node.h>

Collaboration diagram for node_t:
Collaboration graph
[legend]

Public Attributes

node_type_t type
 
int id
 
struct node_tparent
 
struct node_t ** children
 
int num_children
 
int _num_children_allocated
 
unsigned char * data
 
size_t length
 
int pos
 

Detailed Description

primary storage type of a delimited element

Every hl7 element (regardless of place in the hirarchy) is represented by a node_t. The node_t.type defines where in the hirarchy the node is. Every node_t has a parent node.

The top level node of a parsed HL7 message is always of type message_t. The Hirarchy looks like this:

The delimiters shown above are the standard delimiters. The HL7 file may define different delimiters which are read and accounted for by the parser.

Every node has potential children indicated by node_t.num_children (0 means none) and has a parent (special case is message_t which is always the root of the structure and is the partent of node_type_t SEGMENT).

This also means, that some node types (node_t.type) need to be treated specially.

creating a node

To create a valid node_t you need to know it's data and length.

Example:

char *data = "abc";
int length = 4; // must include \0
node_t *n = create_node_t(FIELD, data, length, 0);
// you may also create an empty node like this
node_t *n = create_node_t(FIELD, NULL, 0, 0);

node_t takes owenship of the pointer pointing to data. be aware of the fact that when you free a node then all children and it's data will get freed.

Example:

char *data = "abc";
int length = 4; // must include \0
node_t *n = create_node_t(FIELD, data, length, 0);
// free it
// NOTE: data points to NULL now

using the api

You should use the api to manage relationships between children and parents. this will make sure you don't get any dangling nodes in your structure.

Example:

int ret = -1;
message_t *root = create_message_t(NULL); // will create a message and meta with default delimiters
node_t *n = create_node(SEGMENT, "PID", 4, 0);
ret = message_append(&root, n);
if (ret != 0) {
// whoopsie, something went wrong
return;
}
// create PID-1(1) segment
node_t *pid1 = create_node(FIELDLIST, NULL, 0 , 0);
node_t *pid11 = create_node(FIELD, "DATA", 5 , 0);
ret = node_append(&n, n1);
ret = node_append(&n1, n11);
// from node_util.h
char *str = messate_to_string(root);
printf("%s\n", str);
free(str);
free_message(root); // frees all children

checking for children

if (node->num_children > 0)
// we have some children

getting the parent

message_t has a very similar structure (lacking data but having file metadata). when accessing the parent of a SEGMENT, then the parent should be casted into message_t*.

if (node->type == SEGMENT)
message_t* parent = (message_t*) node->parent;
else
node_t* parent = node->parent;

Member Data Documentation

◆ _num_children_allocated

int node_t::_num_children_allocated

number of allocated elements in children

◆ children

struct node_t** node_t::children

array of child nodes

◆ data

unsigned char* node_t::data

byte array of raw data, should be NULL if there is no data and "\0" when empty

◆ id

int node_t::id

unique id of the node

◆ length

size_t node_t::length

number of bytes in data

◆ num_children

int node_t::num_children

number of elements in children

◆ parent

struct node_t* node_t::parent

pointer to parent node, should never be NULL

◆ pos

int node_t::pos

element position from the beginning of the segment in bytes, this might go away

◆ type

node_type_t node_t::type

the type of the node


The documentation for this struct was generated from the following file: