Platform interoperability — solution design
Document version: 1.2
Date: 2026-04-04
Status: Normative companion to SPEC.md
Related documents:
- Specification: SPEC.md
- Technical Requirements: TECHNICAL_REQUIREMENTS.md
- API Documentation: API_DOCS.md
- Event Model: EVENT_MODEL.md
- System design baseline: ../baseline/SOLUTION_DESIGN_BASELINE.md
- FHIR-first Standard (normative): ../platform/FHIR_FIRST_STANDARD.md
- AI Platform (normative): ../platform/AI_PLATFORM.md
1. Architecture Overview
This layer extends the core platform with:
- A FHIR Gateway Service providing a consolidated FHIR R4 surface
- An HL7 v2 Interop Service to ingest/emit v2 messages and map them to canonical FHIR
- An AI Orchestrator Service (
ai-orchestrator) for assistive AI behind Kong (policy, retrieval, provider adapters, audit events) - Licensed add-on services (diagnostics, engagement, financial)
┌──────────────────────────────────────────────────────────────────────────────┐
│ NEXT.JS WEB APP │
│ Clinician UI (core + add-ons) Patient Portal UI │
└─────────────────────────────────┬────────────────────────────────────────────┘
│ HTTPS
┌────────▼─────────┐
│ API GATEWAY │ (Kong)
│ JWT Validation │
│ Rate Limiting │
│ Route Dispatch │
└──┬───────────┬────┘
│ │
│ │
┌─────────────▼─┐ ┌───▼──────────────────┐
│ REST APIs │ │ FHIR R4 Base │
│ /v1/* │ │ /fhir/R4/* │
└──────┬─────────┘ └──────────┬───────────┘
│ │
┌──────────▼──────────┐ ┌──────────▼──────────┐
│ Core domain services │ │ fhir-gateway │
│ (per-domain REST) │ │ routing + aggregation│
└──────────┬──────────┘ └──────────┬──────────┘
│ │
│ ┌──────▼────────────────────────────┐
│ │ HL7 v2 / Partner Integrations │
│ │ hl7v2-interop (MLLP) │
│ └──────────┬────────────────────────┘
│ │
│ │ External Systems
│ │ ADT / ORM / ORU
│ │ DICOMweb / PACS
│ │ Payer / Clearinghouse
│ │
│ ┌──────────▼──────────────────────────┐
│ │ ai-orchestrator │
│ │ Kong /v1/ai/* → models (hosted/on-prem)│
│ └──────────┬──────────────────────────┘
│ │ Model vendors (contracted)
│
┌────────────▼────────────────────────────────────────────────────────┐
│ NATS JetStream Event Bus │
│ Subjects: clinical.* | diag.* | engage.* | billing.* | interop.* | ai.* │
└────────────┬────────────────────────────────────────────────────────┘
│
┌────────────▼────────────────────────────────────────────────────────┐
│ Per-service PostgreSQL + shared Redis + MinIO │
└──────────────────────────────────────────────────────────────────────┘
2. Design principles
| Principle | Application |
|---|---|
| FHIR-first | All clinically meaningful facts are exposed via FHIR R4 interactions and mapped per ../platform/FHIR_FIRST_STANDARD.md. |
| Bounded contexts | Each service owns its schema and workflow state; the gateway does not introduce a shared DB. |
| Multi-tenancy everywhere | tenantId is enforced on REST, FHIR, events, and integration processing. |
| Policy-controlled exposure | ABAC is enforced at FHIR boundary; portal access uses a constrained surface and release rules. |
| Event-driven decoupling | NATS JetStream subjects provide durable distribution and replay for integration workers and projections. |
| Idempotent integrations | HL7v2 engine stores message control IDs, de-duplicates, and can safely retry processing. |
| Assistive AI | Model access only via ai-orchestrator behind Kong; ABAC-scoped retrieval; human acceptance for record writes per AI_PLATFORM.md. |
3. Key Components
3.1 fhir-gateway
Responsibilities
- Provide a single FHIR base endpoint:
/fhir/R4/* - Publish consolidated
CapabilityStatement - Route requests to the owning service(s) per SPEC.md §6
- Apply cross-cutting enforcement:
- JWT validation (inherited) + resource-level RBAC/ABAC
- tenant resolution + node scoping
- consistent
OperationOutcomeerror format
Implementation approach
- NestJS HTTP service behind Kong
- Modular router mapping resource types → service adapters
- For “overlapping” resources (notably
ObservationandDiagnosticReport), gateway supports:- query routing by category/profile when safe
- fan-out + merge for searches where ownership is split
Persistence
- No clinical persistence (stateless)
- Optional short-lived cache of conformance artifacts (Redis)
Folder structure (recommended)
fhir-gateway/
src/
app.module.ts
fhir/
fhir.controller.ts # /fhir/R4/* (proxy)
capability/
capability.service.ts
routing/
resource-router.ts
ownership-map.ts
adapters/
registration.adapter.ts
scheduling.adapter.ts
vitals.adapter.ts
results.adapter.ts
...
validation/
search-params.validator.ts
operationoutcome.mapper.ts
3.1.1 Ghasi e-prescribing gateway (e-prescribing-gateway) and medication FHIR routing
Normative overview: ../GHASI_EPRESCRIBING_GATEWAY.md.
The Ghasi e-prescribing gateway is not the same component as the generic FHIR edge. It implements national / enterprise medication interoperability (prescriber platforms ↔ pharmacies): FHIR R4 façade under Kong /v1/ghasi-e-prescribing-gateway, idempotency, ETags, Subscription delivery with outbox/DLQ, multi-tenant enforcement, and NATS events.
Decision (B1 — dual entrypoint):
| Traffic | Entry | Owning deployable for MedicationRequest / MedicationDispense in this path |
|---|---|---|
General FHIR interop (/fhir/R4) | Partner-facing unified FHIR API | pharmacy per ownership-map.ts — domain FHIR projection |
| Ghasi e-prescribing (national) | /v1/ghasi-e-prescribing-gateway | e-prescribing-gateway — interop system of record per ADR-0044 |
Integrators must use /v1/ghasi-e-prescribing-gateway for gateway-mediated prescribing/dispensing workflows. /fhir/R4 medication resources remain the canonical FHIR route to the pharmacy domain service and do not subsume subscription SLAs or gateway persistence.
3.2 hl7v2-interop
Responsibilities
- MLLP listener(s) per tenant/facility connector
- Parse HL7 v2 messages and persist an immutable message log
- Map messages to canonical FHIR resources and call the
fhir-gateway - Emit integration events for observability and downstream workflows
Supported message sets (baseline)
- ADT: A01/A04/A08/A03/A40
- ORM: orders outbound and ACK ingestion (where applicable)
- ORU: results inbound and deduplication
Persistence (minimum tables)
interop_connectorshl7_messages(raw + parsed metadata)hl7_processing_attemptshl7_resource_links(message → created/updated FHIR resource ids)
Folder structure (recommended)
hl7v2-interop/
src/
app.module.ts
connectors/
connectors.controller.ts
connectors.service.ts
entities/
mllp/
mllp.server.ts
mllp.session.ts
parsing/
hl7.parser.ts
segments/
mapping/
adt.mapper.ts
orm.mapper.ts
oru.mapper.ts
processing/
inbound.processor.ts
outbound.publisher.ts
audit/
events/
3.3 ai-orchestrator (platform.ai)
Responsibilities
- Expose AI HTTP APIs only behind Kong (e.g.
/v1/ai/...); no vendor API keys in browser clients (FR-AI-003). - Enforce licensing, tenant/org context, and ABAC/minimum necessary before retrieving PHI for prompts (FR-AI-002).
- Orchestrate model adapters (cloud or on-prem); apply quotas, rate limits, and circuit breaking (FR-NFR-016, FR-NFR-015).
- Support tool-calling only to allow-listed internal services (e.g. FHIR read/search, terminology) using existing service auth.
- Emit audit-friendly events (sanitized by default) per AI_PLATFORM.md §6 (FR-AI-006).
- Record provenance metadata when modules persist accepted outputs (FR-AI-005).
Persistence (minimum)
ai_requests(correlation id, tenant_id, actor_id, feature_key, status, timestamps, no raw PHI in default columns)ai_policy_snapshotsor config references (effective policy version per tenant/node)- Optional encrypted blob store for opt-in prompt/response retention per tenant policy (FR-NFR-018)
Normative detail: AI_PLATFORM.md, FR-AI-001..010 and FR-NFR-015..018 in ../../core/EHR_FUNCTIONAL_REQUIREMENTS.md.
Folder structure (recommended)
ai-orchestrator/
src/
app.module.ts
policy/
retrieval/ # RAG / FHIR-allowed fetchers
providers/ # vendor adapters
tools/ # allow-listed internal HTTP clients
audit/
events/
4. Add-on Microservices — Design Summaries
This section defines implementation-level design anchors for add-on and interop services. Detailed module behavior remains normative in the per-module specs.
4.1 immunizations (Module: clinical.immunizations)
Canonical FHIR resources: Immunization, optional ImmunizationRecommendation
Primary workflows: record administration/history; query by patient/date; optional forecast generation hooks
Database schema (minimum)
immunizations(FHIR-backed JSON + indexed columns)id,tenant_id,patient_id,occurrence_at,status,vaccine_system,vaccine_code,lot_number?,performer_id?,version,created_at,updated_at
immunization_forecasts(optional)id,tenant_id,patient_id,generated_at,payload_json
Events
clinical.immunizations.eventswith types:ghasi.immunizations.recorded,...updated,...refused,...forecast.updated
4.2 care-plans-service (Module: clinical.care-plans)
Canonical FHIR resources: CarePlan, Goal, optional Task
Primary workflows: plan lifecycle; goals; activities/progress; review/closure
Database schema (minimum)
care_plansid,tenant_id,patient_id,status,period_start?,period_end?,category_code?,title?,payload_json,version,created_at,updated_at
care_plan_goalsid,care_plan_id,tenant_id,status,description,target_due?,payload_json,version
care_plan_activities(optional if modeling Task locally)id,care_plan_id,tenant_id,status,kind,payload_json,version
Events
clinical.careplans.eventswith types:ghasi.careplans.plan.created,...updated,...reviewed,...activity.completed
4.3 messaging (Module: engage.messaging)
Canonical FHIR resources: Communication (and optionally CommunicationRequest)
Primary workflows: thread + message + read receipt; patient-linked messages; escalation; PHI-safe notifications
Database schema (minimum)
message_threads:id,tenant_id,node_id?,patient_id?,encounter_id?,created_atthread_participants:id,thread_id,participant_type,participant_idmessages:id,thread_id,sender_id,sent_at,urgency,body,statusmessage_read_receipts:id,message_id,user_id,read_atmessage_attachments:id,message_id,file_ref,mime_type,size_bytes,hash,scan_status
Events
- JetStream stream
engage.messaging.eventswith CloudEvents types:ghasi.messaging.sent,ghasi.messaging.replied,ghasi.messaging.read,ghasi.messaging.escalated— see specs/modules/messaging/EVENT_MODEL.md and interop EVENT_MODEL.md §5.5.
Outbound notifications (push / SMS / email)
- Channel orchestration and provider ports are specified in specs/modules/messaging/NOTIFICATIONS_PLATFORM.md (normative companion to messaging SPEC FR-MSG-009..012).
4.4 patient-portal-api (Module: engage.patient-portal)
Purpose
- Patient-facing API surface that:
- enforces portal-specific policies (release rules, redaction)
- reads clinical facts via FHIR gateway
- writes appointment requests to Scheduling
- writes messaging requests to Messaging
Database schema (minimum)
portal_accounts:id,tenant_id,patient_id,idp_subject,status,created_atportal_access_events:id,portal_account_id,event_type,resource_type?,resource_id?,occurred_atdemographics_update_requests:id,tenant_id,patient_id,requested_changes_json,status,requested_at,reviewed_at?
Events
engage.portal.eventswith types:ghasi.portal.login,...record.viewed,...appointment.requested,...result.viewed
4.5 laboratory-lis (Module: diag.laboratory)
Canonical FHIR resources: ServiceRequest, Specimen, Observation, DiagnosticReport, optional Task
Primary workflows: accessioning; specimen lifecycle; manual entry; verify; release
Database schema (minimum)
test_catalog_items:id,tenant_id,name,loinc_code?,specimen_type,payload_jsonaccessions:id,tenant_id,accession_number,patient_id,encounter_id?,priority,created_atspecimens:id,tenant_id,accession_id,type_code,status,collected_at?,received_at?,payload_jsonlab_results:id,tenant_id,accession_id,test_code,status,value_json,entered_by,verified_by?,version
Events
diag.lis.eventswith types:ghasi.lis.accessioned,...specimen.collected,...result.verified,...result.released
4.6 radiology-pacs (Module: diag.radiology)
Canonical FHIR resources: ImagingStudy, DiagnosticReport, ServiceRequest
Primary workflows: study metadata sync; report lifecycle; viewer launch
Database schema (minimum)
pacs_endpoints:id,tenant_id,node_id?,name,qido_url,wado_url,stow_url?,auth_mode,config_jsonimaging_studies:id,tenant_id,patient_id,encounter_id?,order_id?,started_at,modality,pacs_study_uid,payload_jsonradiology_reports:id,tenant_id,imaging_study_id,status,authored_at,content,version,payload_json
Events
diag.radiology.eventswith types:ghasi.radiology.study.available,...report.received,...report.amended,...critical.flagged
4.7 Financial Services (Billing / Insurance / Claims)
These services are designed as workflow orchestrators and integration adapters with FHIR financial resources as canonical meaning.
billing (Module: billing.rcm)
FHIR resources: Account, ChargeItem, Invoice, PaymentNotice, PaymentReconciliation
Schema (minimum): charges, accounts, invoices, invoice_items, payments, adjustments, price_lists
insurance (Module: billing.insurance)
FHIR resources: Coverage, CoverageEligibilityRequest/Response
Schema (minimum): coverages, eligibility_transactions, authorizations, payers
claims (Module: billing.claims)
FHIR resources: Claim, ClaimResponse, ExplanationOfBenefit, PaymentReconciliation
Schema (minimum): claims, claim_submissions, remittances, denial_cases, claim_attachments
5. API Gateway (Kong) Routing (Design)
The platform continues the Kong gateway model:
/v1/*routes to service REST APIs/fhir/R4/*routes tofhir-gateway/interop/hl7v2/*routes tohl7v2-interop(admin + metrics; MLLP is not via Kong)
See API_DOCS.md for the routing table.
6. Implementation Plan (Solution Design View)
The step-by-step plan is captured in TECHNICAL_REQUIREMENTS.md and the per-module specs. Suggested implementation increments:
- FHIR Gateway scaffold + CapabilityStatement
- FHIR enablement for core clinical services (read-first, then write)
- HL7 v2 engine baseline (ADT + ORU) + message store + dedupe
- Add-on services scaffolding + REST + FHIR
- Portal (policy-filtered FHIR reads + appointment requests + messaging)
- Diagnostic integrations (LIS + PACS adapters)
- Financial baseline (billing + insurance + claims) + adapter seams
- E2E & contract tests + deployment hardening