Module query

Source
Expand description

Human-readable location queries for HL7 messages.

i.e. parsing “PID.5.1” to get the value of the first component of the fifth field

§Querying HL7 messages

This module provides utilities for querying HL7 messages. This is useful for extracting specific values from an HL7 message, such as the patient’s name or the ordering provider’s name without having to manually traverse the message.

§Location queries

A location query is a string that describes the location of a value within an HL7 message. The query is made up of the segment name, field index, repeat index, component index, and subcomponent index. Each part of the query is separated by a period (.), and each index is enclosed in square brackets ([]). For example, the query PID.5[1].1 would refer to the first subcomponent of the first component of the first repeat of the fifth field of the PID segment.

§Examples

use hl7_parser::query::LocationQuery;
let query = LocationQuery::parse("MSH[1].2[3].4.5").unwrap();
assert_eq!(query.segment, "MSH");
assert_eq!(query.segment_index, Some(1));
assert_eq!(query.field, Some(2));
assert_eq!(query.repeat, Some(3));
assert_eq!(query.component, Some(4));
assert_eq!(query.subcomponent, Some(5));
use hl7_parser::query::LocationQuery;
let query = LocationQuery::parse("MSH.2.4").unwrap();
assert_eq!(query.segment, "MSH");
assert_eq!(query.segment_index, None);
assert_eq!(query.field, Some(2));
assert_eq!(query.repeat, None);
assert_eq!(query.component, Some(4));
assert_eq!(query.subcomponent, None);

§Building location queries

A location query can also be built using a builder pattern. This is useful when you want to ensure that the query is valid at before using it.

use hl7_parser::query::LocationQueryBuilder;
let query = LocationQueryBuilder::new()
   .segment("MSH")
   .segment_index(1)
   .field(2)
   .repeat(3)
   .component(4)
   .subcomponent(5)
   .build()
   .unwrap();
assert_eq!(query.to_string(), "MSH[1].2[3].4.5");

Structs§

LocationQuery
A location query that describes the location of a value within an HL7 message. The query is made up of the segment name, field index, repeat index, component index, and subcomponent index. Each part of the query is separated by a period (.), and each index is enclosed in square brackets ([]). For example, the query PID.5[1].1 would refer to the first subcomponent of the first component of the first repeat of the fifth field of the PID segment.
LocationQueryBuilder
A builder for creating a location query with error checking.
LocationQueryResultDisplay
Display the result of a location query, using the separators to decode escape sequences

Enums§

LocationQueryBuildError
Errors that can occur when building a location query
LocationQueryResult
A result of a location query. This can be a segment, field, repeat, component, or subcomponent. The result contains a reference to the corresponding part of the message. The result can be used to get the raw value of the part of the message, or to display the value using the separators to decode escape sequences.
QueryParseError
An error that can occur when parsing a query

Functions§

parse_location_query
Parse a location query from a string