Patient management microservice for the HTPI healthcare platform. Handles all patient-related operations including demographics, contact information, and medical records.
- Complete patient demographics management
- Medical Record Number (MRN) generation and validation
- Patient search and filtering
- Duplicate patient detection and merging
- Multi-tenant support with organization isolation
- Soft delete with audit trail
- Real-time event publishing
The service communicates exclusively through NATS messaging:
- Receives patient operation requests
- Sends database requests to MongoDB service
- Publishes patient events for other services
patient.create
- Create new patientpatient.get
- Get patient by ID or MRNpatient.update
- Update patient informationpatient.delete
- Soft delete patientpatient.list
- List patients with paginationpatient.search
- Search patientspatient.merge
- Merge duplicate patientspatient.stats
- Get patient statistics
patient.created
- New patient createdpatient.updated
- Patient information updatedpatient.deleted
- Patient deletedpatient.merged
- Patients merged
- Identifiers: ID, MRN, SSN (encrypted)
- Demographics: Name, DOB, gender, marital status
- Contact: Email, phones, address
- Clinical: Blood type, allergies, medications, conditions
- Administrative: Status, provider, care team
- Email format validation
- Phone number formatting (E.164)
- State code validation (2 characters)
- Postal code validation (XXXXX or XXXXX-XXXX)
- SSN formatting (XXX-XX-XXXX)
{
"request_id": "req-123",
"org_id": "org-456",
"patient": {
"first_name": "John",
"last_name": "Doe",
"date_of_birth": "1980-01-15",
"gender": "M",
"email": "john.doe@example.com",
"phone": "555-123-4567",
"address": {
"street1": "123 Main St",
"city": "Springfield",
"state": "IL",
"postal_code": "62701"
}
}
}
{
"request_id": "req-124",
"org_id": "org-456",
"query": "john",
"search_fields": ["first_name", "last_name", "email"],
"page": 1,
"page_size": 20
}
{
"request_id": "req-125",
"org_id": "org-456",
"group_by": "status",
"start_date": "2024-01-01",
"end_date": "2024-12-31"
}
# NATS Configuration
NATS_URL=nats://localhost:4222
NATS_USER=patients_service
NATS_PASS=secure_password
# Service Configuration
LOG_LEVEL=INFO
ENVIRONMENT=production
PATIENT_ID_PREFIX=PAT
# Performance
MAX_CONCURRENT_REQUESTS=100
REQUEST_TIMEOUT=30
railway up
docker build -t htpi-patients-service .
docker run -e NATS_URL=nats://host:4222 htpi-patients-service
docker-compose up -d
The service exposes health status via NATS:
- Topic:
health.check
orpatients-service.health
- Returns: Service status, version, uptime
All operations are scoped by org_id
:
- Patients are isolated by organization
- MRN uniqueness is per organization
- Email uniqueness is per organization
- SSN should be encrypted before storage
- Soft deletes preserve audit trail
- PHI handling complies with HIPAA requirements