Template Management
Components and functionality for managing MS Word templates
Template Management
The template management system allows administrators and users to upload, configure, and manage Microsoft Word templates used for external report editing.
Overview
Templates are .docx files that contain placeholders for dynamic data replacement. The system provides a comprehensive interface for template lifecycle management.
Key Components
UploadWordTemplate Component
Location: ...TemplateAndSnippetManagement/components/CreateOrUpdateTemplateAndSnippet/UploadWordTemplate.tsx
Purpose: Handles DOCX file upload and validation
Features:
- Drag-and-drop file upload
- File type validation (.docx only)
- Size limit enforcement (50MB)
- Progress indication
UI Elements:
<FileInput
id="allow-microsoft-integration"
label={t("Upload Microsoft Word Template (.docx)")}
accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
onChange={handleFileChange}
value={selectedFile}
/>Template Configuration
Form Fields:
- Template name
- Description
- Category/Department
- Access permissions
- Version information
Validation Rules:
- Required fields: name, file
- File format: DOCX only
- Size limits: Configurable per lab
Template Storage
S3 Organization
Path Structure:
templates/
├── radiology/
│ ├── chest_xray_v1.docx
│ ├── mri_brain_v2.docx
│ └── ultrasound_abdomen_v1.docx
├── cardiology/
│ ├── echo_report.docx
│ └── stress_test.docx
└── laboratory/
├── chemistry_panel.docx
└── hematology_report.docxMetadata Storage
Database Fields:
template_id: Unique identifiername: Display namedescription: Optional descriptions3_path: Full S3 path to filefile_size: Size in bytesuploaded_by: User ID of uploaderupload_date: Timestampversion: Version numberis_active: Enable/disable flag
Template Selection
In Report Modal
UI Component: Template dropdown in report editing interface
Selection Logic:
- Filter by department/test type
- Show recently used templates first
- Display template preview (optional)
- Validate user permissions
Default Templates:
- Lab-specific default templates
- Department-specific templates
- Fallback to generic templates
Template Versioning
Version Control
Features:
- Automatic version increment on upload
- Version history tracking
- Rollback to previous versions
- Version comparison
Implementation:
interface TemplateVersion {
version: number;
s3_path: string;
uploaded_by: number;
upload_date: string;
changes: string;
}Version Management UI
- Version dropdown in template editor
- Diff view between versions
- Restore previous version
- Archive old versions
Access Control
Permission Levels
Roles:
- Admin: Full CRUD operations
- Lab Manager: Create, edit own templates
- Technician: Use templates, limited editing
- Doctor: Read-only access
Permission Matrix:
| Action | Admin | Lab Manager | Technician | Doctor |
|---|---|---|---|---|
| Create | ✅ | ✅ | ❌ | ❌ |
| Edit | ✅ | ✅ | ⚠️ | ❌ |
| Delete | ✅ | ⚠️ | ❌ | ❌ |
| Use | ✅ | ✅ | ✅ | ✅ |
Lab-Specific Templates
- Templates scoped to specific labs
- Inheritance from parent organizations
- Override capabilities for customization
Template Validation
Pre-Upload Validation
Checks:
- File format verification (OOXML signature)
- Size limits (configurable)
- Malware scanning
- Placeholder syntax validation
Error Messages:
- "Invalid file format. Please upload a .docx file."
- "File size exceeds maximum limit of 50MB."
- "File contains malware. Upload rejected."
Post-Upload Processing
Operations:
- Extract placeholder variables
- Generate preview thumbnail
- Index for search
- Cache metadata
Search and Discovery
Template Search
Search Criteria:
- Name (partial match)
- Department
- Tags/keywords
- Upload date range
- Uploader
Advanced Filters:
- File size range
- Usage frequency
- Rating/reviews
- Lab-specific
Template Gallery
UI Features:
- Grid/list view toggle
- Sort by popularity, date, name
- Preview thumbnails
- Usage statistics
- Favorite/bookmark functionality
Usage Analytics
Tracking Metrics
Collected Data:
- Template usage count
- User adoption rates
- Edit session duration
- Success/failure rates
- Popular placeholders
Reporting:
- Usage dashboards
- Template performance metrics
- User behavior analytics
- Optimization recommendations
Template Maintenance
Cleanup Operations
Automated Tasks:
- Remove unused templates (after grace period)
- Compress old versions
- Update search indexes
- Validate file integrity
Manual Operations:
- Bulk template operations
- Permission updates
- Category reorganization
- Archive management
Backup and Recovery
Backup Strategy:
- Daily S3 backups
- Database snapshots
- Version history preservation
- Disaster recovery procedures
Integration with External Systems
Document Management Systems
- Integration with SharePoint/OneDrive
- Google Drive synchronization
- Version control systems (Git)
- Document collaboration platforms
API Integrations
Endpoints:
GET /api/templates: List available templatesPOST /api/templates: Upload new templatePUT /api/templates/{id}: Update templateDELETE /api/templates/{id}: Delete template
Webhook Support:
- Template upload notifications
- Usage tracking events
- Validation failure alerts
Best Practices
Template Creation Guidelines
Recommendations:
- Use consistent placeholder naming
- Include all relevant data fields
- Test with sample data
- Document placeholder usage
- Version control templates
Performance Optimization
Tips:
- Minimize template file sizes
- Use efficient placeholder patterns
- Cache frequently used templates
- Optimize search indexes
- Monitor usage patterns
Troubleshooting
Common Issues
Upload Failures:
- Check file format and size
- Verify network connectivity
- Review permission settings
Template Not Found:
- Check S3 bucket permissions
- Verify file path correctness
- Review access control settings
Placeholder Issues:
- Validate placeholder syntax
- Check data availability
- Review template formatting
Code Repository
The template management components are implemented in the livehealth-frontend repository.