Overview
Architecture summary, data flow, and key source locations for the MS Word Integration module
👤 Aditya Naresh📅 Updated: Mar 18, 2026🏷️ reporting
Backend Overview
For a user-facing overview of MS Word Integration (what it is and how it works), see the MS Word Integration Overview.
The MS Word Integration module enables external editing of radiology reports using Microsoft Word templates. It provides a secure, session-based system for downloading templates, replacing placeholders with patient data, and uploading edited documents back to the system.
Architecture Summary
Key Components
| Component | Purpose | Location |
|---|---|---|
WordEditView | Main API endpoint for edit sessions | report/views/external_report_edits.py |
WordEditAgentView | File upload handling | report/views/external_report_edits.py |
ExternalReportEdits | Session and file tracking model | report/models/external_report_edits.py |
replace_placeholders_in_docx_stream | Template processing utility | report/external_report_edit_utils.py |
Data Flow
- Session Creation: User clicks "Edit in Microsoft Word" → API creates
ExternalReportEditsrecord - Template Download: System fetches template, replaces placeholders, generates presigned URL
- Word Launch: Frontend uses
winword:protocol to open document in Microsoft Word - File Upload: Word saves → uploads both DOCX and PDF to S3 via API
- Report Update: Lab report marked as partially completed, PDF stored as final report
Key Source Locations
| Layer | Path | Description |
|---|---|---|
| Views | crelio-app/report/views/external_report_edits.py | API endpoints for session management and file uploads |
| Models | crelio-app/report/models/external_report_edits.py | Data models and placeholder replacement logic |
| Utils | crelio-app/report/external_report_edit_utils.py | DOCX processing and placeholder replacement |
| Serializers | crelio-app/report/serializers/default_serializers.py | Data serialization for API responses |
Dependencies
- python-docx: For DOCX file manipulation and placeholder replacement
- Django Storage: For S3 file upload/download operations
- Django ORM: For database operations on external edit sessions
- JWT Tokens: For session authentication and authorization
Security Considerations
- Session Tokens: Each edit session has a unique authentication token
- File Validation: Uploaded files are validated for type and content
- Access Control: Only authorized lab users can access edit sessions
- Timeout Handling: Sessions expire after inactivity to prevent locks
- Audit Trail: All file operations are logged for compliance