Testing HL7-FHIR Pipelines: A Strategy Using Mocking and Boundary Definition
Testing HL7-to-FHIR Pipelines Without a Hospital: Mocking HAPI FHIR with respx
Summary
Based on building an open-source pipeline that converts legacy HL7 v2.5 messages into FHIR R4 resources, the author explains a reliable testing methodology for environments lacking access to live hospital systems. The article details how unit and integration tests use `respx` to mock external dependencies (HAPI FHIR server or MLLP connection), demonstrating a concrete method of verifying processes at separated boundaries.
Details
The author built an open-source Maternity HL7-to-FHIR pipeline that converts legacy HL7 v2.5 messages into R4 resources with Australian and European FHIR profiles, utilizing a three-layer architecture: Mirth Connect (HL7 ingestion), FastAPI (FHIR transformation), and HAPI FHIR Server (persistence). The focus is on the testing methodology when live hospital environments or servers are unavailable. Traditional end-to-end (E2E) testing required multiple components (Mirth, HAPI FHIR server), leading to slow CI/CD pipelines and flaky tests. The author leveraged the clear boundary—where FastAPI receives flat JSON payloads instead of MLLP messages—to separate concerns. Unit tests verify only transformation logic using Pydantic models. Crucially, integration tests use `httpx.AsyncClient` and `respx` to mock HTTP communication with HAPI FHIR. This allows comprehensive testing of the entire request lifecycle (validation, transformation, client calls) without needing a live server or Docker container, ensuring reliability while maintaining speed.
Original content copyright by respective publishers