hl7v2-cli
Command-line interface for HL7 v2 message manipulation and validation.
Usage
Run first-use diagnostics:
Lint a profile before using it as an interface contract:
Summarize a directory or file corpus:
Redact a message for safe analysis:
Policy files use explicit rules with required reasons:
[[]]
= "PID.3"
= "hash"
= "patient identifier"
[[]]
= "PID.5"
= "drop"
= "patient name"
[[]]
= "OBX.3"
= "retain"
= "observation identifier is needed for analysis"
Rules default to fail-closed: hash and drop rules must match at least one
field unless optional = true is set. Built-in sensitive fields such as
PID.3, PID.5, PID.7, PID.11, PID.13, PID.19, and next-of-kin
fields must be protected when present and cannot be retained.
hl7v2 bundle writes a redacted evidence packet containing:
manifest.jsonREADME.mdmessage.redacted.hl7validation-report.jsonfield-paths.jsonprofile.yamlredaction-receipt.jsonenvironment.jsonreplay.shandreplay.ps1
hl7v2 replay reads the bundle directly, regenerates the validation report
from message.redacted.hl7 and profile.yaml, and fails if it no longer
matches validation-report.json.
Automation contract
The CLI keeps primary command output on stdout. For JSON/YAML evidence commands, stdout is the machine-readable artifact. Stderr is reserved for diagnostics, receipts, and top-level errors.
Evidence commands that produce reports accept --output <path>, --quiet, and
--no-color. Without --output, the report is written to stdout. With
--output, the same artifact is written to the requested file and stdout stays
quiet. --quiet suppresses non-error diagnostics, while top-level errors still
go to stderr.
Exit codes are stable for automation:
| Code | Meaning |
|---|---|
0 |
Success, or a check/report that passed. |
1 |
Validation, profile, doctor, or replay evidence check failed. |
2 |
Parse, profile, config, or policy input error. |
3 |
IO, runtime, or environment error. |
For usage examples, see the examples/ directory in the root of the repository.