hl7parse
Classes | Typedefs | Enumerations | Functions
search.h File Reference

hl7 search utilities More...

#include "address.h"
#include "meta.h"
Include dependency graph for search.h:

Go to the source code of this file.

Classes

struct  flags_t
 command line parameters More...
 
struct  result_item_t
 search result More...
 
struct  search_res_t
 holds 0-N result items More...
 

Typedefs

typedef struct flags_t flags_t
 command line parameters More...
 
typedef enum search_mode_t search_mode_t
 search modes
 
typedef struct result_item_t result_item_t
 search result More...
 
typedef struct search_res_t search_res_t
 holds 0-N result items More...
 

Enumerations

enum  search_mode_t { SEARCH_SUBSTRING = 0, SEARCH_SEGMENT = 1, SEARCH_NODE = 2 }
 search modes More...
 

Functions

const char * version_search ()
 search version information
 
flags_tcreate_flags_t ()
 create default values for flags_t More...
 
search_res_tcreate_search_res (unsigned char *search_term)
 initiaizes a result container More...
 
void free_search_res (search_res_t *sr)
 frees all data associated with search result More...
 
hl7_addr_t ** parse_address (char *addrstr, int *length)
 parse address string More...
 
void free_addr_arr (hl7_addr_t **addr)
 free address array More...
 
int search_file (char *filename, flags_t flags)
 search for files More...
 
int search_substring (FILE *fd, search_res_t *sr)
 search substring More...
 
int search_segment (FILE *fd, search_res_t *sr)
 this search variant is a line based search More...
 
int search_subnodes (node_t *fieldlist, search_res_t *sr, int line_num, hl7_meta_t *meta, int segment_rep)
 
int search_node (FILE *fd, search_res_t *sr)
 parse line and find in sub elements More...
 
void print_json_value (result_item_t *item, flags_t flags)
 JSON value, entities escaped. More...
 
void print_xml_value (result_item_t *item, flags_t flags)
 XML value, entities escaped. More...
 
void output_json (result_item_t *item, flags_t flags, int last)
 print a result item as json More...
 
void output_xml (result_item_t *item, flags_t flags)
 print a result item as xml More...
 
void output_csv (result_item_t *item, flags_t flags)
 print a result item as csv More...
 
void output_string (result_item_t *item, flags_t flags)
 printf a result More...
 

Detailed Description

hl7 search utilities

Typedef Documentation

◆ flags_t

typedef struct flags_t flags_t

command line parameters

this structure holds the command line parameters.

◆ result_item_t

typedef struct result_item_t result_item_t

search result

pos is the position in the line (SEARCH_SEGMENT/SEARCH_SUBSTRING) or position in the segment (SEARCH_NODE)

◆ search_res_t

typedef struct search_res_t search_res_t

holds 0-N result items

Holds relevant search parameters and result items. This is used as buffer during search over various files.

Enumeration Type Documentation

◆ search_mode_t

search modes

Enumerator
SEARCH_SUBSTRING 

stupid, dumb case insensitive search over file

SEARCH_SEGMENT 

search only lines which start with segment name

SEARCH_NODE 

parse segments and search in specific fields

Function Documentation

◆ create_flags_t()

flags_t* create_flags_t ( )

create default values for flags_t

  • v: verbose
  • s: search term
  • n: greedy
  • o=json: json output
  • o=xml: xml output
  • o=csv: csv output
  • a: address to search in
  • search_term (with s)
  • address string (with a)
  • q: quiet, only for console output, displays values only
  • d: base64 decode values
  • f: output file
  • output_file_value, name of the output file
  • FILE* output_file handle,
  • i: case insensitive search

◆ create_search_res()

search_res_t* create_search_res ( unsigned char *  search_term)

initiaizes a result container

Parameters
search_termstring to search for
Returns
an empty result contrainer

◆ free_addr_arr()

void free_addr_arr ( hl7_addr_t **  addr)

free address array

will free al lelements and the array itself.

Parameters
[out]addraddress array

◆ free_search_res()

void free_search_res ( search_res_t sr)

frees all data associated with search result

make sure to allocate data for every item.

Parameters
[out]srsearch result struct

◆ output_csv()

void output_csv ( result_item_t item,
flags_t  flags 
)

print a result item as csv

Parameters
itemthe item to print
flagscommand line search flags

◆ output_json()

void output_json ( result_item_t item,
flags_t  flags,
int  last 
)

print a result item as json

Parameters
itemthe item to print
flagscommand line search flags
last1 if this is the last record, so we can ommit the the comma after the object

◆ output_string()

void output_string ( result_item_t item,
flags_t  flags 
)

printf a result

Parameters
itemthe result item to print
flagscommand line arguments

◆ output_xml()

void output_xml ( result_item_t item,
flags_t  flags 
)

print a result item as xml

Parameters
itemthe item to print
flagscommand line search flags

◆ parse_address()

hl7_addr_t** parse_address ( char *  addrstr,
int *  length 
)

parse address string

split address strings by spaces.

The array is terminated by a sentinel.

Parameters
addrstraddress string to parse
lengthlength of string
Returns
array of addresses

◆ print_json_value()

void print_json_value ( result_item_t item,
flags_t  flags 
)

JSON value, entities escaped.

Escape all "</tt> characters with <tt>\\\\</tt> + <tt>" inside the string.

Parameters
itemitem containing item->str with data and item->length
flagscommand line search flags
Returns
json string value

◆ print_xml_value()

void print_xml_value ( result_item_t item,
flags_t  flags 
)

XML value, entities escaped.

make sure to escape all vital xml entities and wrap a tag around the value.

Special character gets replaced by escaped form
Ampersand & &
Less-than < <
Greater-than > >
Quotes " "
Apostrophe ' '
Parameters
itemiem containing item->str with data and item->length
flagscommand line search flags
Returns
xml tag as string

◆ search_file()

int search_file ( char *  filename,
flags_t  flags 
)

search for files

Return codes:

  • 0: success
  • 11: failed to open file
  • 12: failed to parse meta data
    See also
    read_meta()
  • 13: invalid address
    See also
    parse_address()
  • 14: invalid/unknown search mode
  • 2*: general error in SEARCH_SUBSTRING,
    See also
    search_substring()
  • 3*: general error in SEARCH_SEGMENT,
    See also
    search_segment()
  • 4*: general error in SEARCH_NODE,
    See also
    search_node()
    Parameters
    filenamefile to search
    flagssearch configuration
    Returns
    0 on success, error code otherwise

◆ search_node()

int search_node ( FILE *  fd,
search_res_t sr 
)

parse line and find in sub elements

Error codes:

  • 41: failed to read metadata
    See also
    read_meta()
  • 42: failed to parse segment
  • 43: failed to search subnodes
    See also
    search_subnodes()
    Parameters
    fdfile to search in, seeking from the current position
    [out]srsearch result container
    Returns
    0 on success, 40-49 on error

◆ search_segment()

int search_segment ( FILE *  fd,
search_res_t sr 
)

this search variant is a line based search

We fetch every line, compare the segment name with the ones which are sought after. If the segment name matches with one in the addr definitions we do a substring search.

If the greedy option is set, we are searching for all occourances of sr->search_term. If not, the function returns upon the first match or when the end of file is reached.

Results are stored in sr. sr->length holds the number of results, sr->items is an array of search results.

The user must take care to properly deallocate sr after use.

See also
free_search_res()

Return Codes:

  • 30: failed to allocate memory
  • 31: failed to detect delimiters
  • 32: no line delimiter found, we do not accept one line files
Parameters
fdfile to search in, seeking from the current position
[out]srsearch result container
Returns
0 on success, 30-39 on error

◆ search_subnodes()

int search_subnodes ( node_t fieldlist,
search_res_t sr,
int  line_num,
hl7_meta_t meta,
int  segment_rep 
)

search sub nodes

concatenates all sub nodes of an address and searches for substring in sr->search_term. if sr->search_term is NULL, then the concatenated line is returned as new sr->items.

Return Codes:

  • 1: failed to search sub_nodes
    See also
    _search_subnodes()
    Parameters
    fieldlistthe base node to search in
    [out]srpointer to search result
    line_numneeded to add positional information to sr
    metathe current hl7 file meta data
    segment_repsegment repetition, all == -1
    Returns
    int 0 on success

◆ search_substring()

int search_substring ( FILE *  fd,
search_res_t sr 
)

search substring

Todo:
not implemented
Parameters
fdfile to search in, seeking from the current position
[out]srsearch result container
Returns
0 on success, 20-29 on error