use er7_redact::{Action, Policy, Redactor};
fn main() -> Result<(), er7_redact::Error> {
let text = "MSH|^~\\&|LAB\rPID|1||\"\"";
let policy = Policy::accept_all()
.with("PID-1", Action::redacted())?
.with("PID-2", Action::redacted())?
.with("PID-3", Action::redacted())?
.with("PID-9", Action::redacted())?;
let mut message = er7::parse(text)?;
let report = Redactor::new(policy).redact(&mut message);
assert_eq!(message.to_er7(), "MSH|^~\\&|LAB\rPID|REDACTED||\"\"");
assert_eq!(report.len(), 1);
assert!(message.segment("PID").unwrap().field(2).unwrap().is_empty());
assert!(message.segment("PID").unwrap().field(3).unwrap().is_null());
assert!(message.segment("PID").unwrap().field(9).is_none());
let mut message = er7::parse("MSH|^~\\&|LAB\rPID|1||9||SMITH^JOHN")?;
let policy = Policy::accept_all().with("PID-5", Action::Null)?;
Redactor::new(policy).redact(&mut message);
assert_eq!(message.to_er7(), "MSH|^~\\&|LAB\rPID|1||9||\"\"");
let mut message = er7::parse("MSH|^~\\&|LAB\rPID|1||9||SMITH^JOHN")?;
let policy = Policy::accept_all().with("PID-5", Action::Clear)?;
Redactor::new(policy).redact(&mut message);
assert_eq!(message.to_er7(), "MSH|^~\\&|LAB\rPID|1||9||^");
println!("absent, empty, and null all survived redaction unchanged");
Ok(())
}