Author: Dr. Mohamed El Fadil — BRAINSAIT برينسايت Founder & Lead Development and Innovations Date: 2025-05-12 Purpose: Template and detailed guide for building a full-stack Agentic Healthcare RCM & EHR system from scratch using FHIR, HL7, Cloudflare MCP, and AI-powered automation.
- Overview
- Core Components
- System Architecture
- Technology Stack
- Getting Started (New!)
- Backend Setup
- Frontend Setup
- Integration with FHIR & HL7
- MCP Server & Client Setup
- Agentic Workflow Design
- Security & Compliance
- Deployment & Scaling
- Development Workflow (New!)
- Continuous Monitoring & Feedback
- Troubleshooting Guide (New!)
- Appendices & Resources
The HealthLinc Ecosystem is a modular, secure, and intelligent platform for managing healthcare records and financial workflows. It combines modern interoperability (FHIR, HL7), cloud-native scalability (Cloudflare Workers), and an intelligent agent-based system (LINC agents) for automation and efficiency.
- RCM Module: Insurance, billing, claims, denials.
- EHR Module: Patient charts, observations, clinical notes.
- FHIR/HL7 Gateway: Interoperability layer.
- MCP Server: Context-aware inference routing.
- Agentic AI: Autonomous LINC agents for task handling.
- DocuLinc: Enhanced clinical documentation for medical necessity.
- MatchLinc: Diagnosis-procedure matching validation.
- ReviewerLinc: Fee schedule management and contract alignment.
- ClaimTrackerLinc: Claim tracking with duplicate detection.
- Clinician Portal: Interface for doctors/staff.
- Patient Portal: Self-service and records access.
graph TD
Frontend["Frontend (SwiftUI/Web)"]
MCP_Client["MCP Client (e.g., CoMasterLinc)"]
MCP_Server["MCP Server (Cloudflare Worker + KV)"]
LINC["LINC Agents Layer"]
FHIR["FHIR/HL7 APIs"]
Healthcare["Healthcare Systems"]
Frontend --> MCP_Client
MCP_Client --> MCP_Server
MCP_Server --> LINC
LINC --> FHIR
FHIR <--> Healthcare
subgraph "LINC Agents"
ClaimLinc["ClaimLinc"]
RecordLinc["RecordLinc"]
AuthLinc["AuthLinc"]
NotifyLinc["NotifyLinc"]
DocuLinc["DocuLinc"]
MatchLinc["MatchLinc"]
ReviewerLinc["ReviewerLinc"]
ClaimTrackerLinc["ClaimTrackerLinc"]
end
| Layer | Technology |
|---|---|
| Frontend | SwiftUI (macOS, iPadOS, iOS), HTML/CSS/JS |
| Backend | FastAPI, Node.js (optional) |
| AI Agents | Python (LangChain/OpenAI/Claude SDKs) |
| Interoperability | FHIR (R4+), HL7 v2.x, HAPI FHIR |
| Serverless | Cloudflare Workers, KV storage |
| Automation | GitHub Actions, Docker, Coolify |
| Monitoring | Grafana, Loki, Promtail |
| Security | JWT, Bearer Tokens, TLS, GDPR/HIPAA |
- Docker and Docker Compose
- Node.js 18+
- Python 3.11+
- Cloudflare Workers account (for MCP)
- OpenAI API key or Anthropic API key
-
Clone the repository:
git clone https://github.com/Fadil369/HealthLinc.git cd HealthLinc -
Create environment variables:
# Copy sample env files cp .env.example .env -
Set up your API keys in
.env:OPENAI_API_KEY=your_openai_api_key JWT_SECRET=your_secure_jwt_secret -
Start the development environment:
# Start all services docker compose up -d # Or use the helper script ./scripts/run.ps1
-
Access the applications:
- Patient Portal: http://localhost:3000
- Clinician Portal: http://localhost:4000
- FHIR Gateway: http://localhost:8000
-
Clone MCP Server template (e.g.,
brainsait-mcp-secure-worker) -
Set up Cloudflare Worker project:
wrangler init healthlinc-mcp wrangler login wrangler publish
-
Add secure KV storage for token access:
wrangler kv:namespace create "HEALTHLINC_TOKENS" -
Add MCP token validation logic:
// index.ts async function authorize(request) { const token = request.headers.get("Authorization"); // compare against KV }
- Create a new project
HealthLincApp - Create
MCPClient.swift:- Handles SSE/REST requests to MCP Server
- UI Components:
PatientCardViewClaimSubmissionViewChatAgentViewfor AI agents
-
Use
hapi-fhirorfirely-serverfor FHIR backend. -
HL7 listener (MirthConnect) to transform v2.x into FHIR JSON.
-
Endpoint examples:
GET /fhir/Patient/123 POST /fhir/Claim
-
Worker endpoint:
POST /query -> MCP routes to LINC Agent -
Client (CoMasterLinc) handles UI and decisioning
-
Example call:
curl -X POST https://mcp.healthlinc.workers.dev/query \ -H "Authorization: Bearer {token}" \ -d '{"agent":"ClaimLinc","task":"submit","data":{...}}'
Each LINC Agent is:
- Stateless containerized service
- Uses structured
task+context+goalformat - Runs AI-powered logic using OpenAI or Claude API
- Logs via DocuLinc
Example agent repo structure:
agent-claimlinc/
├── main.py
├── Dockerfile
├── config.yaml
└── prompts/
└── submit_claim.txt
- Bearer Token via KV store
- Enforce HTTPS + IP filtering
- Encrypt all logs (DocuLinc)
- GDPR consent records
-
Use Coolify for private deployments
-
Deploy agents as Docker containers:
docker compose up -d
-
Auto-scale MCP with Cloudflare
-
Add Cloudflare Tunnel for secure LAN access
main: Production-ready codedevelop: Integration branch for featuresfeature/*: Feature branches
- Create feature branch from
develop - Implement changes with tests
- Submit PR to
develop - Ensure CI passes
- Require code review
- Merge to
develop
- Create release branch from
develop - Run final tests
- Version bump in package files
- Merge to
main - Tag release (e.g.,
v1.0.0) - Deploy to production
- Grafana dashboard
- Loki + Promtail for logs
- Telegram notifications via NotifierLinc
- MCP Inspector UI for visual graph of agent responses
- Ensure ports are not in use by other services
- Check network isolation settings in docker-compose.yml
- Verify environment variables are properly set
- Check JWT_SECRET consistency across services
- Verify token expiration settings
- Enable debug logs in AuthLinc
- Validate FHIR resource formats against schema
- Check FHIR server connectivity
- Review permissions for FHIR operations
- Ensure MCP Server is accessible
- Verify agent configurations
- Check network connectivity between containers