Product EngineeringFeaturesMS Word IntegrationBackend

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

ComponentPurposeLocation
WordEditViewMain API endpoint for edit sessionsreport/views/external_report_edits.py
WordEditAgentViewFile upload handlingreport/views/external_report_edits.py
ExternalReportEditsSession and file tracking modelreport/models/external_report_edits.py
replace_placeholders_in_docx_streamTemplate processing utilityreport/external_report_edit_utils.py

Data Flow

  1. Session Creation: User clicks "Edit in Microsoft Word" → API creates ExternalReportEdits record
  2. Template Download: System fetches template, replaces placeholders, generates presigned URL
  3. Word Launch: Frontend uses winword: protocol to open document in Microsoft Word
  4. File Upload: Word saves → uploads both DOCX and PDF to S3 via API
  5. Report Update: Lab report marked as partially completed, PDF stored as final report

Key Source Locations

LayerPathDescription
Viewscrelio-app/report/views/external_report_edits.pyAPI endpoints for session management and file uploads
Modelscrelio-app/report/models/external_report_edits.pyData models and placeholder replacement logic
Utilscrelio-app/report/external_report_edit_utils.pyDOCX processing and placeholder replacement
Serializerscrelio-app/report/serializers/default_serializers.pyData 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

On this page