pub struct Rule {
pub path: Path,
pub action: Action,
}Expand description
One HL7 path and what to do at it.
The path is an er7::Path, so its notation and semantics are er7’s
(that crate’s spec §8.1): an omitted occurrence index means every
segment of that name and every repetition of that field, which is
what lets OBX-5 cover a message with forty results.
A rule whose action is Action::Keep accepts the position it
names; a rule with any other action rejects it. Where both name the
same leaf, the rejecting one wins, whichever order they are in (D19,
spec §2.4).
Example:
use er7_redact::{Action, Rule};
let rule = Rule::new("PID-5", Action::redacted())?;
assert_eq!(rule.path.segment, "PID");
assert_eq!(rule.to_string(), "PID-5 replace REDACTED");
// Or read one as a policy file spells it.
assert_eq!(Rule::parse("PID-7 first 4")?.action, Action::First(4));Fields§
§path: PathWhere the rule applies.
action: ActionWhat it does there.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn new(path: &str, action: Action) -> Result<Rule, Error>
pub fn new(path: &str, action: Action) -> Result<Rule, Error>
A rule from a path and an action.
§Errors
Error::Er7 wrapping er7::Error::BadPath when path is not
an HL7 path — a zero index, a missing field number, trailing text.
Sourcepub fn parse(line: &str) -> Result<Rule, Error>
pub fn parse(line: &str) -> Result<Rule, Error>
Read one policy line: a path, whitespace, an action (spec §6).
Example:
use er7_redact::{Action, Rule};
let rule = Rule::parse(" OBX[2]-5 replace NOT ON FILE ")?;
assert_eq!(rule.path.to_string(), "OBX[2]-5");
assert_eq!(rule.action, Action::Replace("NOT ON FILE".to_string()));
assert!(Rule::parse("PID-5").is_err()); // no action
assert!(Rule::parse("PID-0 clear").is_err()); // not a path§Errors
Error::BadPolicy naming the rule and the problem: a line with
no action, an action that does not exist, or a path that is not a
path.