Skip to main content

Document Service — Migration Plan

Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template


1. Migration Context

The document-service supersedes the legacy "DMS" module embedded in the ghasi-ehr monolith. Legacy document handling was fragmented:

  • PDF generation was client-side in some modules (PHI exposure risk)
  • Template definitions were stored in unversioned JSONB blobs
  • No virus scanning on uploads
  • FHIR DocumentReference was created inconsistently or not at all
  • No unified audit trail for document access

2. Migration Phases

Phase 0 — Bootstrap

TaskOwnerNotes
Deploy document-service with DB migrationsPlatform teamNo tenants migrated yet
Seed platform reference templatesPlatform teamGeneral Test Requisition + other platform forms
Configure object storage buckets + KMS keysPlatform teamSeparate buckets per region
Configure ClamAVPlatform teamVirus definition update schedule set

Phase 1 — Template Migration

TaskOwnerNotes
Export legacy template definitions from monolithData engineeringExtract template JSONB blobs
Transform to DocumentTemplateVersion.definition schemaData engineeringMap layout + binding fields
Import as draft versionsData migration scriptpnpm migration:import-templates
Clinical review and publishClinical informaticsEach tenant signs off on migrated templates

Phase 2 — Document Artifact Migration

TaskOwnerNotes
Export legacy PDF artifacts from monolith storageData engineeringTenant-scoped paths
Copy to new object storage layout /{tenantId}/documents/Data migration scriptVia S3 copy API
Create DocumentReference + Binary FHIR resources for eachData migration scriptpnpm migration:create-fhir-refs
Validate migrated DocumentReference listClinical informaticsSpot-check per tenant

Phase 3 — Cutover

TaskOwnerNotes
Route generate / upload calls to document-serviceKong routing changeFeature flag per tenant
Disable legacy document generation in monolithEngineeringAfter document-service validated for tenant
Migrate document access audit trailAudit teamHistorical records imported to audit-service
Validate audit completenessComplianceHIPAA accounting of disclosures check

Phase 4 — Legacy Deprecation

TaskOwnerNotes
Remove legacy DMS module from monolithEngineeringAfter all tenants migrated
Archive legacy PDF storage (legal hold)SREKeep per retention policy; mark as archived

3. Rollback Plan

PhaseRollback action
Phase 0Drop document-service DB schema and object storage buckets; no tenants affected
Phase 1Re-import templates; no production traffic yet
Phase 2Remove newly created FHIR resources; restore from legacy storage backup
Phase 3 per tenantFeature flag disables document-service for that tenant; route back to monolith
Phase 4Restore monolith DMS module from backup; re-enable legacy routing

4. Data Migration Scripts

ScriptPurpose
scripts/migration/import-templates.tsImport legacy template JSONB blobs as DocumentTemplate + DocumentTemplateVersion rows
scripts/migration/copy-artifacts.tsCopy legacy PDF blobs to new object storage layout
scripts/migration/create-fhir-refs.tsCreate DocumentReference + Binary for migrated artifacts
scripts/migration/validate-migration.tsVerify document count + spot-check metadata per tenant
scripts/migration/seed-platform-templates.tsImport platform reference template catalog

5. Open Questions

  • Agreed priority order for tenant template migration (which tenants first).
  • Retention policy for legacy monolith PDF storage after migration (legal hold duration).