This directory contains sample code demonstrating how to use HL7kit for common healthcare integration scenarios. Each file is self-contained and covers a specific topic.
import HL7v2Kit
// Parse a message
let message = try HL7v2Message.parse("MSH|^~\\&|App|Fac|App|Fac|20240101||ADT^A01|CTL001|P|2.5.1")
// Build a message
let built = try HL7v2MessageBuilder()
.msh { $0.sendingApplication("App").messageType("ADT", triggerEvent: "A01").messageControlID("ID1").processingID("P").version("2.5.1") }
.segment("PID") { $0.field(2, value: "MRN001^^^Hosp^MR").field(4, value: "Smith^John") }
.build()
// Validate
try message.validate()| File | Topics Covered |
|---|---|
| QuickStart.swift | Parsing, building, validating, inspecting messages, FHIR overview |
| CommonUseCases.swift | ADT workflows, ORU lab results, ORM orders, ACK responses, batch processing |
| IntegrationExamples.swift | v2→v3 CDA transformation, FHIR resources, JSON/XML serialization, CLI usage |
| PerformanceOptimization.swift | Object pooling, string interning, streaming, compression, benchmarking |
| iOSExamples.swift | SwiftUI/UIKit views, notifications, background processing, local storage |
| macOSExamples.swift | AppKit windows, menu bar, AppleScript, batch processing, CLI integration |
- SwiftUI Components:
HL7MessageView,FHIRPatientCard,MessageListView - UIKit Controllers:
HL7MessageViewControllerwith table view - Notifications: Background processing notifications with
NotificationManager - Background Tasks:
BackgroundMessageProcessorfor processing while app is not active - Local Storage:
iOSMessageStoragefor document directory file management
- AppKit Windows:
HL7MessageWindowControllerwith split view and table view - Menu Bar:
HL7MenuBarManagerfor status bar integration - AppleScript:
AppleScriptSupportfor automation - Service Menu:
HL7ServiceProviderfor system-wide services - Batch Processing:
BatchFileProcessorwith progress reporting - Document-Based:
HL7Documentclass for document-based applications - CLI Integration:
CLIIntegrationfor running command-line tools
HL7kit is organized into four modules. Import only the ones you need:
import HL7Core // Shared protocols, logging, security, persistence
import HL7v2Kit // HL7 v2.x message parsing, building, validation, MLLP
import HL7v3Kit // HL7 v3.x / CDA document processing, vocabulary
import FHIRkit // FHIR R4 resources, REST client, search, validation# Build the framework
swift build
# Run the CLI tool
swift run hl7 --help
# Run tests
swift test
# Run tests with coverage
swift test --enable-code-coverage# Validate a message
swift run hl7 validate path/to/message.hl7
# Inspect message structure
swift run hl7 inspect path/to/message.hl7
# Convert formats
swift run hl7 convert path/to/message.hl7
# Batch process a directory
swift run hl7 batch path/to/directory --operation validate
# Conformance check
swift run hl7 conformance path/to/message.hl7 --profile ADT_A01For visual learners, check out our comprehensive video tutorial series:
- Video Tutorials Guide — Complete video tutorial scripts and guides covering:
- Introduction to HL7kit (3 videos)
- HL7 v2.x mastery (4 videos)
- HL7 v3.x and CDA documents (3 videos)
- FHIR integration (3 videos)
- Platform-specific features (3 videos)
- Advanced topics (3 videos)
- Architecture Guide — Module design and data flow
- Integration Guide — Shared services and common patterns
- Performance Guide — Optimization techniques and benchmarks
- Security Guide — Encryption, signing, HIPAA compliance
- Migration Guide — Upgrading between versions
- Character Encoding — Multi-encoding support
- Concurrency Model — Actor-based thread safety