EHR Search Microservice Architecture Design
Overview
This architecture design outlines the development of a microservice search functionality that dynamically routes search requests to different Electronic Health Record (EHR) applications. The system is designed to handle patient record searches initially, with extensibility for future search record types.
Architecture Components
1. Core Microservices
1.1 Search Gateway Service
- Purpose: Entry point for all search requests
- Responsibilities:
- Request validation and authentication
- Request routing
- Response aggregation and formatting
- Rate limiting and throttling
- API versioning
1.2 Search Router Service
- Purpose: Intelligent routing of search requests to appropriate EHR systems
- Responsibilities:
- Dynamic endpoint discovery
- Request transformation and mapping
- Fallback routing strategies
1.3 EHR Adapter Service
- Purpose: Standardizes communication with different EHR systems
- Responsibilities:
- EHR-specific protocol translation
- Data format standardization
- Authentication and authorization handling
- Connection pooling and management
- Error handling and retry logic
2. Supporting Services
2.1 Configuration Service
- Purpose: Centralized configuration management
- Responsibilities:
- EHR endpoint configurations
- Search query mappings
- Authentication credentials
2.2 Discovery Service
- Purpose: Service discovery and health monitoring
- Responsibilities:
- EHR endpoint registration
- Health check monitoring
- Service availability tracking
- Dynamic endpoint updates
2.3 Authentication & Authorization Service
- Purpose: Centralized security management
- Responsibilities:
- User authentication
- Permission validation
- EHR-specific credential management
- Audit logging
- Token management
3. Data Layer
3.1 Cache Layer
- Purpose: Improve response times and reduce EHR load
- Technology: Redis or Memcached
- Responsibilities:
- Frequently accessed data caching
- Search result caching
- Session management
- Rate limiting counters
System Architecture Diagram
┌─────────────────────────────────────────────────────────────────────────────┐
│ Client Applications │
└─────────────────────┬───────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ API Gateway / Load Balancer │
└─────────────────────┬───────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Search Gateway Service │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────────────────┐ │
│ │ Authentication│ │ Rate Limiting │ │ Request Validation │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────────────────┘ │
└─────────────────────┬───────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Search Router Service │
│ ┌─────────────────┐ ┌── ───────────────┐ ┌─────────────────────────────┐ │
│ │ EHR Discovery │ │ Health Monitor │ │ Intelligent Routing │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────────────────┘ │
└─────────────────────┬───────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ EHR Systems │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ EHR-1 │ │ EHR-2 │ │ EHR-3 │ │ EHR-N │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Data Flow
1. Search Request Flow
Client → API Gateway → Search Gateway → Search Router → EHR Adapter → EHR System
2. Response Flow
EHR System → EHR Adapter → Search Router → Search Gateway → API Gateway → Client
3. Caching Flow
Search Request → Check Cache → If Miss: Query EHR → Store in Cache → Return Result
Technology Stack Recommendations
Backend Services
- Runtime: Node.js
- Framework: Express.js, Nestjs
- Communication: REST APIs, gRPC for internal services
Data Storage
- Database: mysql
- Cache: Redis or Memcached
Infrastructure
- Containerization: Docker
- Monitoring: Prometheus + Grafana
API Design
Search Endpoint
POST /api/v1/search
Content-Type: application/json
{
"query": "patient search criteria",
"searchType": "patient_record",
"filters": {
"dateRange": "2024-01-01 to 2024-12-31",
"location": "hospital_id",
"recordType": "all"
},
"pagination": {
"page": 1,
"limit": 20
}
}
Response Format
{
"requestId": "uuid",
"status": "success",
"data": {
"results": [...],
"totalCount": 150,
"page": 1,
"limit": 20
},
"metadata": {
"searchTime": "150ms",
"sources": ["EHR-1", "EHR-2"],
"cacheHit": false
}
}
Configuration Management
EHR Endpoint Configuration
ehr_systems:
ehr_1:
name: "Hospital A EHR"
base_url: "https://ehr1.hospital.com/api"
search_endpoint: "/search/patients"
authentication:
type: "oauth2"
client_id: "search_service"
client_secret: "encrypted_secret"
rate_limit:
requests_per_minute: 100
timeout: 30
retry_attempts: 3
ehr_2:
name: "Clinic B EHR"
base_url: "https://ehr2.clinic.com/api"
search_endpoint: "/v2/patient-search"
authentication:
type: "api_key"
api_key: "encrypted_api_key"
rate_limit:
requests_per_minute: 50
timeout: 25
retry_attempts: 2