Type-safe HL7v2 message parsing and validation using Zod v4 schemas.
- Type-safe validation: Full TypeScript support with Zod v4 schemas for all HL7v2 message types
- Multiple HL7 versions: Support for HL7v2 versions, e.g. 2.6 and 2.8
- Comprehensive coverage: Includes all message types, segments, fields, and data types for each version
- Minimum dependencies: Only requires Zod v4 as a peer dependency
- Tree-shakable: Import only the schemas you need with subpath imports
- Zod v4 optimized: Built with the latest Zod v4 features for better performance and TypeScript efficiency
- Optimal performance: Use subpath imports to include only the HL7 version you need
This package requires Zod v4 (minimum version 3.25.0) as a peer dependency.
npm install @rethinkhealth/hl7v2-zod zod@^3.25.0
# or
yarn add @rethinkhealth/hl7v2-zod zod@^3.25.0
# or
pnpm add @rethinkhealth/hl7v2-zod zod@^3.25.0// Import directly from the specific HL7 version you need
import { adt_a01Schema } from "../dist/2.8";
// Parse and validate an ADT_A01 message
const hl7Message = {
MSH: {
"1": "|",
"2": "",
},
// ...
}
try {
const result = adt_a01Schema.parse(hl7Message)
console.log('Valid HL7 message:', result)
} catch (error) {
console.error('Invalid HL7 message:', error)
}Import directly from the specific HL7:
import { adt_a01Schema, segments } from "../dist/2.8";
const { mshSchema, pidSchema } = segments;
adt_a01Schema.parse({
MSH: {
MSH: {
fieldSeparator: "|",
},
},
});
mshSchema.parse({
"1": "MSH",
"2": "|",
// ...
});
pidSchema.parse({
"1": "PID",
// ...
});@rethinkhealth/hl7v2-zod/2.6: All HL7v2.6 schemas@rethinkhealth/hl7v2-zod/2.8: All HL7v2.8 schemas
Each version export contains:
- Message schemas: All HL7 message type schemas (e.g.,
ADT_A01,ORU_R01) - Segment schemas: All HL7 segment schemas (e.g.,
MSH,PID,PV1) - Field schemas: All HL7 field schemas
- Data type schemas: All HL7 data type schemas (e.g.,
AD,CE,CX) - Metadata: Registry metadata for the version
- Node.js 18+
- pnpm (recommended) or npm
- Zod v4 (^3.25.0)
# Install dependencies
pnpm install
# Build the package
pnpm build
# Run type checking
pnpm type-check
# Run linting
pnpm lint
# Fix linting issues
pnpm lint:fix
# Format code
pnpm format
# Fix formatting issues
pnpm format:fix
# Run all checks (lint + format)
pnpm check
# Fix all issues
pnpm check:fix
# Run tests
pnpm testsrc/
├── 2.x/ # HL7v2.x schemas
└── index.ts # Main entry point (utility functions)
Each version directory contains:
messages/: Message type schemassegments/: Segment schemasfields/: Field schemasdatatypes/: Data type schemasregistry.ts: HL7 metadataindex.ts: Version-specific exports
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run the build and test suite
- Submit a pull request
MIT License - see LICENSE file for details.
- Issues: GitHub Issues
- Documentation: GitHub Wiki