fhir-hl7-validator
npx machina-cli add skill 1Mangesh1/hipaa-guardian/fhir-hl7-validator --openclawFHIR & HL7 Validator
Healthcare data format validation skill for AI agents. Validates FHIR R5 resources, HL7 v2 messages, and CDA clinical documents. Ensures healthcare data interchange compliance with HL7 standards and identifies schema violations, missing required fields, and interoperability issues.
Capabilities
- FHIR Validation - Validate FHIR R5 resources against official schemas
- HL7 Message Parsing - Parse and validate HL7 v2.x messages (ADT, ORU, OBX, RXO)
- CDA Document Validation - Validate Clinical Document Architecture (CDA) R2 documents
- Schema Compliance - Check resources against FHIR specification and UK Core
- Data Type Validation - Verify FHIR data types (Identifier, CodeableConcept, Reference, etc.)
- Reference Resolution - Validate internal and external references
- Cardinality Checking - Ensure required vs. optional field compliance
- Terminology Validation - Check value sets and coding systems (SNOMED CT, LOINC, ICD-10)
- Interoperability Analysis - Identify implementation guide adherence
- Error Reporting - Generate detailed validation error reports with remediation
Usage
/fhir-hl7-validator [command] [target] [options]
Commands
validate-fhir <file>- Validate FHIR JSON/XML resourcevalidate-hl7 <file>- Validate HL7 v2 messagevalidate-cda <file>- Validate CDA clinical documentparse-fhir <file>- Parse and display FHIR resource structureparse-hl7 <file>- Parse and display HL7 segmentscheck-references <file>- Validate all resource referencescheck-terminology <file>- Validate coding systems and value setsbulk-validate <directory>- Validate multiple filesreport <output-format>- Generate validation report (JSON, markdown, HTML)
Options
--version <ver>- FHIR version (default: R5; also 4.0, 3.0)--variant <name>- Implementation guide (e.g., uk-core, us-core)--strict- Enforce must-support constraints--terminology-check- Validate coding systems (enables online lookup)--output <file>- Write report to file--format <type>- Output format: json, markdown, html, xml
Workflow
Follow this workflow when invoked:
Step 1: Identify Healthcare Data Type
Ask user to specify:
- Data format (FHIR, HL7 v2, CDA)
- FHIR version or HL7 dialect
- Implementation guide/profile (if applicable)
- Data source (EHR, lab system, imaging system)
Step 2: Validate Structure
Check:
- JSON/XML well-formedness
- Required elements present
- Data type conformance
- Cardinality compliance (min/max occurrences)
- Pattern and regex validation
Step 3: Semantic Validation
Verify:
- Code system membership (SNOMED CT, LOINC, ICD-10, etc.)
- Reference consistency (local vs. external)
- Identifier uniqueness and format
- Date/time format accuracy (ISO 8601)
- Quantity unit validity
Step 4: Interoperability Check
Ensure compliance with:
- FHIR implementation guides
- US Core or UK Core profiles
- HL7 message specifications
- Clinical data interchange standards
Step 5: Generate Report
Provide:
- List of validation errors with line numbers
- Severity level (error, warning, info)
- Remediation guidance
- Reference to relevant standards
FHIR Resource Examples
Patient Resource
{
"resourceType": "Patient",
"id": "example",
"identifier": [
{
"system": "http://example.org/medical-record",
"value": "12345"
}
],
"name": [
{
"use": "official",
"given": ["Jane"],
"family": "Doe"
}
],
"birthDate": "1990-01-15",
"address": [
{
"use": "home",
"line": ["123 Main St"],
"city": "Springfield",
"state": "IL",
"postalCode": "62701"
}
]
}
Observation Resource
{
"resourceType": "Observation",
"id": "example",
"status": "final",
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "39156-5",
"display": "BMI"
}
]
},
"subject": {
"reference": "Patient/example"
},
"valueQuantity": {
"value": 24.5,
"unit": "kg/m2",
"system": "http://unitsofmeasure.org",
"code": "kg/m2"
}
}
HL7 v2 Segment Examples
ADT Message (Patient Admission)
MSH|^~\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|202502071350||ADT^A01|123456|P|2.5
PID^^^12345||JaneDoe||19900115|F|||123 Main St^^Springfield^IL^62701|||||||S
PV1||I|ICU^FL2^BED01|||||||||||||||||||||||||||
Common Validation Errors
| Error | Cause | Solution |
|---|---|---|
| Missing required element | Element marked cardinality: 1..1 not present | Add the required element |
| Invalid data type | Value doesn't match specified type | Convert to correct type (e.g., date to YYYY-MM-DD) |
| Unknown code system | Code not in specified value set | Use code from official code system (SNOMED CT, LOINC) |
| Broken reference | Reference target doesn't exist | Verify reference path and ID |
| Invalid identifier format | ID format doesn't match pattern | Follow system-specific identifier format |
Standards & Implementation Guides
- FHIR R5 (http://hl7.org/fhir/R5/)
- HL7 v2.5.1 (http://www.hl7.org/)
- CDA R2 (https://www.hl7.org/implement/standards/cdar2/)
- US Core (http://www.hl7.org/fhir/us/core/)
- UK Core (https://digital.nhs.uk/developer/api-catalogue/fhir-uk-core)
- SNOMED CT (https://www.snomed.org/)
- LOINC (https://loinc.org/)
- ICD-10 (https://www.cdc.gov/nchs/icd/icd10cm.htm)
References
- Fast Healthcare Interoperability Resources (FHIR) - R5 Specification
- HL7 Version 2.5.1 - Standard for Healthcare Data Exchange
- Clinical Document Architecture R2 - CDA Specification
- NIST SP 800-66 Rev. 2 - HIPAA Security Implementation Guidance
- HL7 FHIR Implementation Guides
Source
git clone https://github.com/1Mangesh1/hipaa-guardian/blob/main/skills/fhir-hl7-validator/SKILL.mdView on GitHub Overview
Validates FHIR R5 resources, HL7 v2 messages, and CDA documents to ensure healthcare data interchange compliance. It detects schema violations, missing required fields, references, and interoperability gaps, and provides actionable remediation.
How This Skill Works
When invoked, the skill identifies the healthcare data type (FHIR, HL7 v2, or CDA), validates structure (JSON/XML or HL7 segments), performs semantic validation (terminology, references, and datatypes), checks interoperability against profiles like US Core or UK Core, and finally generates a detailed report with errors and remediation guidance.
When to Use It
- Validate a FHIR resource (R5) against official schemas and a chosen implementation guide
- Parse and validate HL7 v2.x messages (e.g., ADT, ORU, OBX, RXO) for conformance
- Validate CDA clinical documents to ensure document structure and constraints are met
- Check references, terminology, and must-support constraints across resources
- Generate comprehensive validation reports for compliance and remediation
Quick Start
- Step 1: Identify data type and version (e.g., /fhir-hl7-validator validate-fhir <file> with --version R5 and --variant uk-core)
- Step 2: Optionally enable terminology checks and strict validation (e.g., --terminology-check --strict)
- Step 3: Produce a report to file (e.g., --report or --output <file>) and review remediation guidance
Best Practices
- Specify the correct FHIR version and implementation guide with --version and --variant
- Enable terminology validation (--terminology-check) to verify value sets and coding systems
- Use bulk-validate for validating multiple files in a directory
- Review errors with line numbers and follow the remediation guidance
- Use --strict to enforce must-support constraints and stricter validation
Example Use Cases
- Validate a FHIR R5 Patient resource against the uk-core profile
- Parse a FHIR resource to inspect its structure and fields
- Validate an HL7 v2 ADT message for segment integrity and data types
- Validate a CDA R2 document against its schema and constraints
- Generate a JSON validation report for a batch of FHIR/HL7/CDA files