Skip to main content

fhir_search/
lib.rs

1// SPDX-FileCopyrightText: Cadasto B.V.
2// SPDX-License-Identifier: BUSL-1.1
3
4//! The FHIR R4 search value grammar (<https://hl7.org/fhir/R4/search.html>,
5//! ยง3.1.1.4).
6//!
7//! A search parameter's value reaches a server percent-decoded and is then
8//! read in two steps. [`escape::split`] cuts it into the alternatives of an
9//! `OR` at every `,` no `\` escapes, and each alternative is read by the
10//! grammar of its parameter type: [`escape::unescape`] for a string or a
11//! uri, [`token::Token`] and [`token::OfType`] for a token,
12//! [`date::DateValue`] for a date, whose [`prefix::Prefix`] is shared with
13//! the other ordered types. [`string::StringMatch`] is how a string value
14//! matches a field.
15//!
16//! No error and no `Debug` output carries a value: a code may be an
17//! identifier and a date a birth date.
18//!
19//! ```
20//! use fhir_search::date::DateValue;
21//! use fhir_search::escape::split;
22//! use fhir_search::prefix::Prefix;
23//! use fhir_search::token::{System, Token};
24//!
25//! let tokens: Vec<Token> = split(r"http://loinc.org|8480-6,a\,b", ',')
26//!     .iter()
27//!     .map(|part| Token::parse(part))
28//!     .collect::<Result<_, _>>()?;
29//! assert_eq!(tokens[0].system(), System::Is("http://loinc.org"));
30//! assert_eq!(tokens[1].code(), Some("a,b"));
31//!
32//! let date = DateValue::parse("ge2026-12")?;
33//! assert_eq!(date.prefix(), Prefix::Ge);
34//! let range = date.date().range();
35//! assert_eq!(range.low().to_string(), "2026-12");
36//! assert_eq!(range.high().map(ToString::to_string).as_deref(), Some("2027-01"));
37//! # Ok::<(), Box<dyn std::error::Error>>(())
38//! ```
39#![doc(test(attr(deny(warnings))))]
40
41pub mod date;
42pub mod escape;
43pub mod prefix;
44pub mod string;
45pub mod token;