migration_import
Optional, installable/removable module that consumes a DPMF v0.1 file produced by dental-bridge and hydrates the current clinic with the extracted data. Issue #78.
Status
- Installable: yes
- Auto-install: no (admin activates from the modules page)
- Removable: yes (own Alembic branch, uninstall round-trip green)
- Depends:
patients,schedules,treatment_plan,billing,payments,media.verifactuis intentionally not independsso PT/FR clinics can import without it.
What it does
- Operator uploads a
.dpmfile (raw / zstd / encrypted). - The module validates the file (magic bytes → decrypt → decompress → integrity hash → format version gate).
- The operator reviews a preview (entity counts, sample rows, DPMF warnings, total binaries expected from
_files). - The operator confirms; mappers run as a BackgroundTask and call each target module's service.
- The external sync agent (lives in dental-bridge) uploads each binary one by one against
POST /jobs/{id}/binaries; matched by sha256 they land inmediastorage with full thumbnails / MIME validation.
Architecture highlights
- Idempotent: every persisted DentalPin row gets an
entity_mappingsrow keyed by(clinic_id, source_system, canonical_uuid, entity_type). Re-running a job is a no-op. verifactuopt-in at runtime: the fiscal-document mapper detects the module at runtime viamodule_registry.is_loaded(...). Legal hashes (Hash / HashControl / ATCUD / QR) are preserved only when (a) verifactu is loaded AND (b) the operator ticked "Importar datos legales Verifactu" in the preview.- Mapper coverage today:
patient,professional,patient_document,payment,fiscal_document. Everything else lands inraw_entitiesfor forward-compatibility — a future module rehydrates from there without re-importing. - Multi-tenant safe: every query filters
clinic_id. The importer never trusts theclinic_id/tenant_labelrecorded in the DPMF —ctx.clinic_idwins. - No rollback in v1: documented in the UI. Admin restores from backup if a partial import is unrecoverable.
See also
- Module CLAUDE:
backend/app/modules/migration_import/CLAUDE.md - Technical overview:
docs/technical/migration_import/overview.md - Events:
docs/technical/migration_import/events.md - Permissions:
docs/technical/migration_import/permissions.md - User manual (ES/EN):
docs/user-manual/{en,es}/migration_import/