Product EngineeringFeaturesMS Word IntegrationBackend

Data Model

Database schema and data relationships for MS Word Integration

👤 Aditya Naresh📅 Updated: Mar 18, 2026🏷️ reporting

Data Model

The MS Word Integration feature uses three primary database tables to manage external editing sessions, track file storage, and maintain report relationships.

Core Tables

External Report Edits

The main table tracking external editing sessions:

ColumnTypeDefaultNullableDescription
idbigintauto_incrementNoPrimary key
word_file_pathlongtext''NoS3 path to the uploaded Word document
pdf_file_pathlongtext''NoS3 path to the converted PDF document
auth_tokenlongtext-NoJWT token for session authentication
is_activesmallint0NoFlag indicating if the edit session is currently active
created_atbigint-NoCreation timestamp
updated_atbigint-NoLast update timestamp
author_idint-YesReference to the lab user currently editing (FK to labUser.labUserId)
lab_report_idint-NoReference to the associated lab report (FK to labReportRelation.labReportId)

Indexes:

  • external_re_lab_rep_b50252_idx on (lab_report_id, author_id)

Key Fields:

  • word_file_path: S3 path to the uploaded Word document
  • pdf_file_path: S3 path to the converted PDF document
  • auth_token: JWT token for session authentication
  • is_active: Flag indicating if the edit session is currently active
  • author_id: Reference to the lab user currently editing
  • lab_report_id: Reference to the associated lab report

Lab Report Relation

Links to the main lab report table (partial schema shown):

ColumnTypeDefaultNullableDescription
labReportIdintauto_incrementNoPrimary key
isPartialFillint-NoSet to 1 when report is edited externally
lastUpdateddatetime(6)-YesTimestamp of last modification
completedTestsint-NoSet to 1 to indicate partial completion
billId_idint-YesForeign key to billing table
collectedSampleId_idint-YesForeign key to collected samples
docForId_idint-YesForeign key to doctor information
labId_idint1NoForeign key to lab information
labUserId_idint-YesForeign key to lab user
orgId_idint-YesForeign key to organization
profileTestId_idint-YesForeign key to profile test
reportFormatId_idint-YesForeign key to report format
reportID_idint-NoForeign key to report definition
reportMetaId_idint-YesForeign key to report metadata
submittedBy_idint-YesForeign key to submitting user
userDetailsId_idint-YesForeign key to patient details

Relevant Fields for MS Word Integration:

  • isPartialFill: Set to 1 when report is edited externally
  • completedTests: Set to 1 to indicate partial completion
  • lastUpdated: Timestamp of last modification

Report Results

Stores individual test result values (used for placeholder data):

ColumnTypeDefaultNullableDescription
valueIdintauto_incrementNoPrimary key
profileTestIdint-NoReference to the test profile
valuelongtext-NoThe test result value
orderint-NoDisplay order of the result
indexint-NoIndex position in results
highlightint-NoFlag for highlighting the result
automatedValueint-NoFlag indicating if value is automated
dictionaryId_idint-YesForeign key to test dictionary (FK to testDictionary.id)
reportForId_idint-NoForeign key to lab report (FK to labReportRelation.labReportId)

Data Relationships

Placeholder Data Mapping

The system maps database fields to template placeholders using the following relationships:

PlaceholderSource TableField PathDescription
patient_nameuserDetailsfullNamePatient's full name
patient_iduserDetailslabUserIdPatient ID
patient_genderuserDetailssexPatient gender
patient_ageuserDetailsagePatient age
patient_dobuserDetailsdateOfBirthDate of birth
test_nameallTeststestNameTest name
test_codeallTeststestCodeTest code
lab_namelabslabNameLab name
lab_addresslabslabAddressLab address
report_timecalculatedcurrent_timeCurrent timestamp
registration_timebillingbillTimeBill creation time

Session Management

Session States

  • Created: Initial state when edit session is started
  • Active: User is currently editing the document
  • Inactive: Session has been ended or timed out

Concurrency Control

  • Only one active session per lab report
  • Authorship can be transferred using "Take Authorship" feature
  • Sessions automatically expire after inactivity

File Storage

S3 Path Structure

ExternalReportEdit/
├── {patient_id}/
│   ├── {timestamp}_{patient_name}.docx
│   └── {timestamp}_{patient_name}.pdf

File Lifecycle

  1. Template Download: Original template fetched from S3
  2. Processing: Placeholders replaced, temporary file created
  3. Upload: Edited files uploaded to S3 with patient-specific paths
  4. Cleanup: Temporary files removed, final paths stored in database

Data Validation

  • File Type Validation: Only .docx and .pdf files accepted
  • Size Limits: Configurable maximum file sizes
  • Path Sanitization: S3 paths validated and sanitized
  • Token Validation: JWT tokens verified for each API call

On this page