How dotimplement/healthchain works
Project Type and Purpose
• HealthChain is an open-source, modular Python SDK and API framework for healthcare AI integration.
• It provides:
– A unified Gateway layer to connect to FHIR servers, CDS Hooks, and SOAP/CDA endpoints.
– A Pipeline framework for NLP/ML workflows on healthcare data.
– An InteropEngine for template-based conversions (CDA ↔ FHIR ↔ HL7v2).
– Synthetic Data Generators and a Sandbox for testing.
– A FastAPI-based HealthChainAPI for hosting services in production.
File Structure & Key Modules
• healthchain/gateway:
– API layer (FastAPI app, endpoints)
– Protocol implementations (FHIR, CDS Hooks, SOAP/CDA)
– Client pools, connection management, event dispatchers
• healthchain/interop:
– ConfigManager, Engines (parsers, generators, template registry)
• healthchain/pipeline:
– Pipeline DSL, preprocessor/postprocessor components, model-router, built-in pipelines
• healthchain/data_generators & healthchain/utils:
– Synthetic data templates, Pydantic validation, helpers
• healthchain/sandbox & cli:
– Sandbox harness, workflow decorators, environment injection, CLI entrypoint
• healthchain/service & healthchain/cli:
– HealthChainAPI assembly, service registration, command-line interface
README Insights
• Emphasizes event-driven, asynchronous architecture (FastAPI + async clients).
• Pydantic models enforce type safety.
• Liquid/Jinja template engine for Interop.
Main Components & Their Interactions
– Registers Gateways (FHIRGateway, CDSHooksService, NoteReaderService)
– Exposes REST endpoints (/fhir/*, /cds/*, /soap/*) via FastAPI
B. Gateway Layer
– FHIRGateway
• Client Pool → external FHIR servers
• Transform hooks (Patient, Observation, etc.)
– CDSHooksService
• Hook definitions → AI logic → returns cards
– NoteReaderService (SOAP)
• WSGI server → accepts CDA XML → dispatch to Interop/Pipelines
C. InteropEngine
– Parsers (CDA XML to intermediate objects)
– Generators (FHIR JSON to CDA, HL7v2)
– Template Registry loading YAML/liquid templates
D. Pipeline Framework
– Data Containers (Document, Tabular)
– Nodes: Preprocessor → NLP model (spaCy, HF) → Postprocessor
– Connectors: CdaConnector, CdsFhirConnector
– Pre-built Pipelines: MedicalCodingPipeline, SummarizationPipeline
E. Synthetic Data & Sandbox
– DataGenerators: Patient, Condition, Medication, Encounter…
– Sandbox UseCase classes + decorators → generate realistic EHR data
– CLI (“healthchain run …”) to spin up sandbox environments
F. External Systems & ML Models
– External EHRs (FHIR servers, CDS Hooks endpoints, SOAP/CDA services)
– AI/ML Models (spaCy, HuggingFace Transformers)
Architectural Patterns & Design Principles
• Modular, plugin-based: each protocol, parser, generator, pipeline component is pluggable.
• Event-driven & async: gateways dispatch events to handlers, pipelines process data asynchronously.
• Template-based interop: Liquid templates for format conversion.
• Type safety: Pydantic models for FHIR resources and internal data structures.
• Separation of concerns: API layer, core engine, data layer, ML components, sandbox.