Download the PHP package dolmatovdev/laravel-x12-parser without Composer
On this page you can find all versions of the php package dolmatovdev/laravel-x12-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dolmatovdev/laravel-x12-parser
More information about dolmatovdev/laravel-x12-parser
Files in dolmatovdev/laravel-x12-parser
Package laravel-x12-parser
Short Description Laravel package for X12 file processing with validation, parsing, and JSON conversion
License MIT
Informations about the package laravel-x12-parser
Laravel X12 Parser Package
A comprehensive Laravel package for processing X12 files with validation, parsing, and JSON conversion capabilities. Built with clean architecture principles and optimized for maintainability.
Author: Danila Dolmatov (LinkedIn)
๐ Features
- ANSI X12 File Parsing: Parse ANSI files into structured data
- Validation: Comprehensive validation for different transaction types
- JSON Conversion: Convert ANSI files to/from JSON format
- File Building: Generate ANSI files from structured data
- Transaction Support: Currently supports 270 (Eligibility/Benefit Inquiry)
- Extensible: Easy to add support for other transaction types
- Laravel Integration: Full Laravel integration with facades and service providers
- Console Commands: Artisan commands for file processing operations
- Input Sanitization: Advanced security with input validation and sanitization
- Custom File Naming: Dynamic file naming with placeholders and patterns
- Clean Architecture: Optimized codebase with shared traits and reduced duplication
- Configuration-Driven: Flexible configuration system with fallbacks
๐ Requirements
- PHP 8.1+
- Laravel 10.0+ or 11.0+
๐ฆ Installation
-
Install via Composer:
-
Publish Configuration (Optional):
- Publish Stubs (Optional):
๐ง Configuration
The package configuration is located in config/x12-parser.php:
๐ฏ Usage
Using the Facade
Using Dependency Injection
Using DTOs
Using Transaction-Specific Delimiters
Console Commands
The package provides several Artisan commands for X12 file processing:
Available Commands:
-
x12:parse {file}- Parse X12 file to JSON--output=- Save output to file (optional)--pretty- Pretty print JSON output
-
x12:validate {file}- Validate X12 file structure and content x12:build {json-file}- Build X12 file from JSON data--output=- Save output to file (optional)--type=270- Transaction type (default: 270)
Using Custom File Naming
๐ Supported Transaction Types
270 - Eligibility/Benefit Inquiry
The 270 transaction is used to inquire about a subscriber's eligibility and benefits.
Required Segments:
ISA- Interchange Control HeaderGS- Functional Group HeaderST- Transaction Set HeaderBHT- Beginning of Hierarchical TransactionHL- Hierarchical LevelNM1- Subscriber NameSE- Transaction Set TrailerGE- Functional Group TrailerIEA- Interchange Control Trailer
Optional Segments:
TRN- Subscriber Trace NumberDMG- Subscriber DemographicsDTP- Date/Time ReferenceEQ- Subscriber Eligibility or Benefit InquiryQTY- Quantity
Sample 270 File:
๐งช Testing
Run the test suite:
Test Examples
๐ Validation
The package provides comprehensive validation for ANSI files:
Validation Features:
- Segment Order: Ensures segments appear in the correct order
- Required Segments: Validates all required segments are present
- Element Format: Validates element formats and lengths
- Business Rules: Enforces business logic specific to each transaction type
- Input Sanitization: Removes control characters and validates X12-safe content
Validation Result:
๐๏ธ Architecture
The package follows clean architecture principles with optimized code organization:
Key Architectural Improvements:
- Shared Traits:
HasDelimitersandHasConfigtraits eliminate code duplication - Configuration-Driven: All services use centralized configuration with fallbacks
- Clean Separation: Clear separation between parsing, validation, and building
- Extensible Design: Easy to add new transaction types and validators
- Optimized Performance: Reduced memory footprint and improved execution speed
๐ง Extending the Package
Adding New Transaction Types
-
Create Validator:
- Update Configuration:
The ValidatorFactory will automatically load the new validator from configuration.
๐ API Reference
AnsiParserService
| Method | Description |
|---|---|
parseFile(string $filePath): array |
Parse ANSI file to array |
parseFileToJson(string $filePath, bool $prettyPrint = true): string |
Parse ANSI file to JSON |
buildFromJson(array $jsonData, string $transactionType = '270'): string |
Build ANSI from JSON |
buildFrom270DTO(Eligibility270DTO $dto): string |
Build ANSI from DTO |
saveToFile(string $content, string $filePath): bool |
Save content to file |
buildAndSaveWithAutoName(array $jsonData, string $transactionType, array $data, ?string $customPattern, ?string $outputDirectory): string |
Build and save with auto-generated filename |
generateFileName(string $transactionType, array $data, ?string $customPattern): string |
Generate filename for transaction type |
getAvailablePlaceholders(): array |
Get available placeholders for file naming |
resetSequence(): void |
Reset sequence counter |
setSequence(int $sequence): void |
Set sequence counter |
validateFile(string $filePath): ValidationResult |
Validate file |
getSupportedTransactionTypes(): array |
Get supported types |
isTransactionTypeSupported(string $transactionType): bool |
Check if transaction type is supported |
getFileInfo(string $filePath): array |
Get file information without full parsing |
Parser & X12Builder
Both classes use the HasDelimiters trait, providing these methods:
| Method | Description |
|---|---|
setDelimitersForTransaction(string $transactionType): void |
Set delimiters from config |
setDelimiters(array $delimiters): void |
Set custom delimiters |
getDelimiters(): array |
Get current delimiters |
getDefaultDelimiters(): array |
Get default delimiters |
ValidationResult
| Property | Type | Description | |
|---|---|---|---|
success |
bool | Whether validation was successful | |
data |
array | null | Parsed data (if successful) |
errors |
array | Validation errors | |
warnings |
array | Validation warnings | |
transactionType |
string | null | Detected transaction type |
Eligibility270DTO
| Property | Type | Description | |
|---|---|---|---|
subscriberId |
string | Subscriber's unique identifier | |
subscriberFirstName |
string | Subscriber's first name | |
subscriberLastName |
string | Subscriber's last name | |
subscriberDateOfBirth |
string | null | Date of birth (YYYYMMDD) |
subscriberGender |
string | null | Gender (M/F) |
inquiries |
array | Benefit inquiries |
๐ Performance & Optimization
Recent Improvements:
- Code Duplication Reduced: ~7% reduction in total lines of code
- Shared Traits: Eliminated duplicate delimiter and configuration handling
- Optimized Configuration: Centralized config access with intelligent fallbacks
- Improved Memory Usage: Better resource management and reduced overhead
- Enhanced Testability: Instance-based services instead of static methods
Best Practices:
- Use Configuration: Leverage the configuration system for customization
- Leverage Traits: Extend functionality using the provided traits
- Input Sanitization: Always use the built-in sanitization for security
- Error Handling: Implement proper exception handling for production use
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
This package is open-sourced software licensed under the MIT License. See the LICENSE file for the full license text.
MIT License
License Summary
- License Type: MIT License
- Copyright: ยฉ 2024 Danila Dolmatov
- Permissions:
- โ Commercial use
- โ Modification
- โ Distribution
- โ Private use
- Limitations:
- โ No liability
- โ No warranty
- Conditions: Include license and copyright notice
For more information about the MIT License, visit opensource.org/licenses/MIT.
๐ Links
- X12.org - Official X12 standards
- 270 Transaction Specification
- Laravel Documentation
๐ Support
For support, please open an issue on GitHub or contact Danila Dolmatov on LinkedIn.
All versions of laravel-x12-parser with dependencies
laravel/framework Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0