@omersx/bemms 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +203 -2
- package/drizzle.config.ts +11 -0
- package/next.config.ts +51 -0
- package/package.json +99 -3
- package/postcss.config.mjs +7 -0
- package/public/hospital_demo_devices.csv +32 -0
- package/public/icons/icon-192.png +0 -0
- package/public/icons/icon-512.png +0 -0
- package/public/icons/icon-maskable-512.png +0 -0
- package/public/manifest.webmanifest +31 -0
- package/public/sw.js +177 -0
- package/src/app/(auth)/layout.tsx +20 -0
- package/src/app/(auth)/login/page.tsx +135 -0
- package/src/app/(dashboard)/admin/audit-logs/page.tsx +178 -0
- package/src/app/(dashboard)/admin/data/page.tsx +37 -0
- package/src/app/(dashboard)/admin/departments/[deptId]/edit/page.tsx +206 -0
- package/src/app/(dashboard)/admin/departments/[deptId]/page.tsx +71 -0
- package/src/app/(dashboard)/admin/departments/new/page.tsx +6 -0
- package/src/app/(dashboard)/admin/departments/page.tsx +6 -0
- package/src/app/(dashboard)/admin/general/page.tsx +374 -0
- package/src/app/(dashboard)/admin/hospitals/[hospitalId]/edit/page.tsx +304 -0
- package/src/app/(dashboard)/admin/hospitals/[hospitalId]/page.tsx +94 -0
- package/src/app/(dashboard)/admin/hospitals/new/page.tsx +302 -0
- package/src/app/(dashboard)/admin/hospitals/page.tsx +6 -0
- package/src/app/(dashboard)/admin/layout.tsx +49 -0
- package/src/app/(dashboard)/admin/organizations/[orgId]/edit/page.tsx +172 -0
- package/src/app/(dashboard)/admin/organizations/[orgId]/page.tsx +82 -0
- package/src/app/(dashboard)/admin/organizations/new/page.tsx +150 -0
- package/src/app/(dashboard)/admin/organizations/page.tsx +6 -0
- package/src/app/(dashboard)/admin/page.tsx +258 -0
- package/src/app/(dashboard)/admin/roles/page.tsx +153 -0
- package/src/app/(dashboard)/admin/settings/page.tsx +69 -0
- package/src/app/(dashboard)/admin/users/[userId]/edit/page.tsx +153 -0
- package/src/app/(dashboard)/admin/users/[userId]/page.tsx +317 -0
- package/src/app/(dashboard)/admin/users/invite/page.tsx +3 -0
- package/src/app/(dashboard)/admin/users/new/page.tsx +5 -0
- package/src/app/(dashboard)/admin/users/page.tsx +23 -0
- package/src/app/(dashboard)/dashboard/page.tsx +462 -0
- package/src/app/(dashboard)/departments/[deptId]/page.tsx +39 -0
- package/src/app/(dashboard)/departments/new/page.tsx +330 -0
- package/src/app/(dashboard)/departments/page.tsx +52 -0
- package/src/app/(dashboard)/devices/[id]/edit/page.tsx +131 -0
- package/src/app/(dashboard)/devices/[id]/page.tsx +408 -0
- package/src/app/(dashboard)/devices/[id]/qr/page.tsx +54 -0
- package/src/app/(dashboard)/devices/new/page.tsx +382 -0
- package/src/app/(dashboard)/devices/page.tsx +80 -0
- package/src/app/(dashboard)/engineering-team/page.tsx +41 -0
- package/src/app/(dashboard)/layout.tsx +43 -0
- package/src/app/(dashboard)/maintenance/checklists/page.tsx +57 -0
- package/src/app/(dashboard)/maintenance/page.tsx +231 -0
- package/src/app/(dashboard)/maintenance/plans/page.tsx +142 -0
- package/src/app/(dashboard)/maintenance/tasks/[id]/page.tsx +997 -0
- package/src/app/(dashboard)/maintenance/tasks/page.tsx +119 -0
- package/src/app/(dashboard)/more/page.tsx +310 -0
- package/src/app/(dashboard)/my-department/page.tsx +151 -0
- package/src/app/(dashboard)/notifications/notification-list.tsx +103 -0
- package/src/app/(dashboard)/notifications/page.tsx +59 -0
- package/src/app/(dashboard)/profile/page.tsx +27 -0
- package/src/app/(dashboard)/reports/costs/page.tsx +127 -0
- package/src/app/(dashboard)/reports/history/page.tsx +105 -0
- package/src/app/(dashboard)/reports/inventory/page.tsx +116 -0
- package/src/app/(dashboard)/reports/maintenance/page.tsx +136 -0
- package/src/app/(dashboard)/reports/page.tsx +120 -0
- package/src/app/(dashboard)/reports/tickets/page.tsx +139 -0
- package/src/app/(dashboard)/reports/workload/page.tsx +135 -0
- package/src/app/(dashboard)/rounds/[id]/page.tsx +197 -0
- package/src/app/(dashboard)/rounds/history/page.tsx +82 -0
- package/src/app/(dashboard)/rounds/page.tsx +107 -0
- package/src/app/(dashboard)/scan/[code]/page.tsx +154 -0
- package/src/app/(dashboard)/scan/page.tsx +73 -0
- package/src/app/(dashboard)/team/page.tsx +42 -0
- package/src/app/(dashboard)/tickets/[id]/page.tsx +465 -0
- package/src/app/(dashboard)/tickets/create/page.tsx +722 -0
- package/src/app/(dashboard)/tickets/page.tsx +55 -0
- package/src/app/(dashboard)/tickets/triage/page.tsx +161 -0
- package/src/app/api/admin/data/export/route.ts +316 -0
- package/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/src/app/api/health/route.ts +46 -0
- package/src/app/api/notifications/sse/route.ts +91 -0
- package/src/app/api/notifications/subscribe/route.ts +54 -0
- package/src/app/api/notifications/vapid-key/route.ts +7 -0
- package/src/app/api/reports/export/route.ts +102 -0
- package/src/app/api/tickets/[id]/attachments/route.ts +129 -0
- package/src/app/api/tickets/[id]/live-sync/route.ts +52 -0
- package/src/app/error.tsx +54 -0
- package/src/app/globals.css +89 -0
- package/src/app/layout.tsx +59 -0
- package/src/app/not-found.tsx +32 -0
- package/src/app/page.tsx +5 -0
- package/src/components/admin/add-department-user-dialog.tsx +759 -0
- package/src/components/admin/add-engineer-dialog.tsx +773 -0
- package/src/components/admin/add-user-type-dialog.tsx +89 -0
- package/src/components/admin/audit-log-export.tsx +113 -0
- package/src/components/admin/audit-log-filters.tsx +255 -0
- package/src/components/admin/audit-log-table.tsx +383 -0
- package/src/components/admin/data-management/danger-zone.tsx +301 -0
- package/src/components/admin/data-management/data-management-tabs.tsx +61 -0
- package/src/components/admin/data-management/export-center.tsx +301 -0
- package/src/components/admin/data-management/import-wizard.tsx +558 -0
- package/src/components/admin/settings-forms/features-form.tsx +115 -0
- package/src/components/admin/settings-forms/health-panel.tsx +182 -0
- package/src/components/admin/settings-forms/localization-form.tsx +203 -0
- package/src/components/admin/settings-forms/retention-form.tsx +164 -0
- package/src/components/admin/settings-forms/security-form.tsx +186 -0
- package/src/components/admin/system-settings-tabs.tsx +88 -0
- package/src/components/admin/user-role-dialog.tsx +293 -0
- package/src/components/admin/user-status-dialog.tsx +166 -0
- package/src/components/admin/users-page-client.tsx +514 -0
- package/src/components/dashboard/action-buttons.tsx +93 -0
- package/src/components/dashboard/admin-alerts.tsx +86 -0
- package/src/components/dashboard/availability-alerts.tsx +65 -0
- package/src/components/dashboard/maintenance-due-list.tsx +87 -0
- package/src/components/dashboard/round-widget.tsx +110 -0
- package/src/components/dashboard/stat-card.tsx +38 -0
- package/src/components/dashboard/ticket-list-compact.tsx +86 -0
- package/src/components/departments/department-cards-view.tsx +244 -0
- package/src/components/departments/department-detail-view.tsx +467 -0
- package/src/components/departments/department-visuals.tsx +190 -0
- package/src/components/departments/my-department-view.tsx +333 -0
- package/src/components/devices/change-status-dialog.tsx +146 -0
- package/src/components/devices/device-action-buttons.tsx +125 -0
- package/src/components/devices/device-availability-banner.tsx +59 -0
- package/src/components/devices/device-badges.tsx +55 -0
- package/src/components/devices/device-documents-tab.tsx +93 -0
- package/src/components/devices/device-maintenance-tab.tsx +113 -0
- package/src/components/devices/device-mini-qr.tsx +109 -0
- package/src/components/devices/device-qr-card.tsx +187 -0
- package/src/components/devices/device-signatures-tab.tsx +607 -0
- package/src/components/devices/device-tickets-tab.tsx +139 -0
- package/src/components/devices/device-timelines.tsx +124 -0
- package/src/components/devices/qr-camera-scanner.tsx +167 -0
- package/src/components/devices/qr-code-display.tsx +139 -0
- package/src/components/devices/quick-add-category-dialog.tsx +135 -0
- package/src/components/devices/quick-add-manufacturer-dialog.tsx +212 -0
- package/src/components/devices/transfer-device-dialog.tsx +190 -0
- package/src/components/layout/header.tsx +80 -0
- package/src/components/layout/mobile-nav.tsx +91 -0
- package/src/components/layout/more-item-badge.tsx +15 -0
- package/src/components/layout/nav-badge.tsx +72 -0
- package/src/components/layout/sidebar.tsx +297 -0
- package/src/components/maintenance/maintenance-badges.tsx +579 -0
- package/src/components/maintenance/maintenance-nav.tsx +107 -0
- package/src/components/maintenance/parts-costs-manager.tsx +909 -0
- package/src/components/maintenance/signature-card.tsx +413 -0
- package/src/components/maintenance/task-action-bar.tsx +955 -0
- package/src/components/notifications/notification-bell.tsx +367 -0
- package/src/components/notifications/notification-item.tsx +93 -0
- package/src/components/notifications/notification-preferences.tsx +182 -0
- package/src/components/profile/user-profile-view.tsx +626 -0
- package/src/components/providers/nav-counts-provider.tsx +235 -0
- package/src/components/providers/session-provider.tsx +7 -0
- package/src/components/providers/theme-provider.tsx +124 -0
- package/src/components/pwa/install-prompt.tsx +82 -0
- package/src/components/pwa/sw-register.tsx +43 -0
- package/src/components/reports/export-button.tsx +62 -0
- package/src/components/reports/filter-chips.tsx +47 -0
- package/src/components/reports/summary-cards.tsx +40 -0
- package/src/components/reports/transparency-header.tsx +54 -0
- package/src/components/rounds/department-visit-sheet.tsx +199 -0
- package/src/components/rounds/mention-textarea.tsx +187 -0
- package/src/components/rounds/round-calendar.tsx +233 -0
- package/src/components/rounds/round-department-list.tsx +281 -0
- package/src/components/rounds/round-history-client.tsx +218 -0
- package/src/components/rounds/start-round-card.tsx +184 -0
- package/src/components/shared/confirm-dialog.tsx +67 -0
- package/src/components/shared/data-table.tsx +104 -0
- package/src/components/shared/page-header.tsx +20 -0
- package/src/components/shared/sign-out-button.tsx +52 -0
- package/src/components/shared/status-badge.tsx +42 -0
- package/src/components/shared/table-search.tsx +55 -0
- package/src/components/signatures/sign-action-dialog.tsx +253 -0
- package/src/components/signatures/signature-history.tsx +121 -0
- package/src/components/signatures/signature-status-panel.tsx +164 -0
- package/src/components/team/department-coverage.tsx +141 -0
- package/src/components/team/edit-engineer-dialog.tsx +242 -0
- package/src/components/team/engineer-card.tsx +180 -0
- package/src/components/team/engineer-details-dialog.tsx +432 -0
- package/src/components/team/schedule-calendar.tsx +204 -0
- package/src/components/team/staff-engineer-team-view.tsx +368 -0
- package/src/components/team/team-header-stats.tsx +88 -0
- package/src/components/team/team-page-client.tsx +216 -0
- package/src/components/theme/theme-selector-card.tsx +63 -0
- package/src/components/theme/theme-toggle.tsx +65 -0
- package/src/components/tickets/staff-status-label.tsx +58 -0
- package/src/components/tickets/staff-ticket-card.tsx +109 -0
- package/src/components/tickets/staff-ticket-progress-tracker.tsx +405 -0
- package/src/components/tickets/staff-tickets-view.tsx +182 -0
- package/src/components/tickets/ticket-action-buttons.tsx +873 -0
- package/src/components/tickets/ticket-auto-refresh.tsx +197 -0
- package/src/components/tickets/ticket-badges.tsx +43 -0
- package/src/components/tickets/ticket-card.tsx +197 -0
- package/src/components/tickets/ticket-cards-view.tsx +395 -0
- package/src/components/tickets/ticket-comment-section.tsx +684 -0
- package/src/components/tickets/ticket-dispatch-status.tsx +184 -0
- package/src/components/tickets/ticket-list-auto-refresh.tsx +55 -0
- package/src/components/tickets/ticket-reporter-profile.tsx +235 -0
- package/src/components/tickets/ticket-signatures-panel.tsx +32 -0
- package/src/components/tickets/ticket-timeline.tsx +131 -0
- package/src/components/tickets/ticket-triage-panel.tsx +124 -0
- package/src/components/tickets/tickets-nav.tsx +107 -0
- package/src/components/ui/avatar.tsx +43 -0
- package/src/components/ui/badge.tsx +34 -0
- package/src/components/ui/button.tsx +58 -0
- package/src/components/ui/card.tsx +77 -0
- package/src/components/ui/checkbox.tsx +31 -0
- package/src/components/ui/dialog.tsx +123 -0
- package/src/components/ui/dropdown-menu.tsx +126 -0
- package/src/components/ui/form.tsx +179 -0
- package/src/components/ui/input.tsx +24 -0
- package/src/components/ui/label.tsx +27 -0
- package/src/components/ui/popover.tsx +34 -0
- package/src/components/ui/progress.tsx +36 -0
- package/src/components/ui/scroll-area.tsx +47 -0
- package/src/components/ui/select.tsx +160 -0
- package/src/components/ui/separator.tsx +25 -0
- package/src/components/ui/sheet.tsx +131 -0
- package/src/components/ui/switch.tsx +30 -0
- package/src/components/ui/table.tsx +121 -0
- package/src/components/ui/tabs.tsx +62 -0
- package/src/components/ui/textarea.tsx +23 -0
- package/src/components/ui/tooltip.tsx +27 -0
- package/src/lib/actions/__tests__/devices.test.ts +176 -0
- package/src/lib/actions/__tests__/signatures.test.ts +303 -0
- package/src/lib/actions/__tests__/tickets.test.ts +243 -0
- package/src/lib/actions/audit-logs.ts +298 -0
- package/src/lib/actions/checklists.ts +429 -0
- package/src/lib/actions/dashboard.ts +358 -0
- package/src/lib/actions/data-management.ts +723 -0
- package/src/lib/actions/departments.ts +369 -0
- package/src/lib/actions/device-categories.ts +117 -0
- package/src/lib/actions/devices.ts +748 -0
- package/src/lib/actions/engineer-rounds.ts +973 -0
- package/src/lib/actions/engineers.ts +285 -0
- package/src/lib/actions/hospitals.ts +148 -0
- package/src/lib/actions/locations.ts +115 -0
- package/src/lib/actions/maintenance-plans.ts +316 -0
- package/src/lib/actions/maintenance-tasks.ts +415 -0
- package/src/lib/actions/manufacturers.ts +132 -0
- package/src/lib/actions/nav-counts.ts +144 -0
- package/src/lib/actions/notifications.ts +136 -0
- package/src/lib/actions/organizations.ts +99 -0
- package/src/lib/actions/qr.ts +147 -0
- package/src/lib/actions/report-history.ts +77 -0
- package/src/lib/actions/reports.ts +192 -0
- package/src/lib/actions/roles.ts +32 -0
- package/src/lib/actions/signature-auth.ts +377 -0
- package/src/lib/actions/signatures.ts +532 -0
- package/src/lib/actions/system-settings.ts +274 -0
- package/src/lib/actions/tickets.ts +1445 -0
- package/src/lib/actions/users.ts +740 -0
- package/src/lib/audit/index.ts +103 -0
- package/src/lib/auth/__tests__/rbac.test.ts +33 -0
- package/src/lib/auth/index.ts +338 -0
- package/src/lib/auth/password.ts +10 -0
- package/src/lib/auth/rbac.ts +103 -0
- package/src/lib/auth/types.ts +57 -0
- package/src/lib/constants/departments.ts +16 -0
- package/src/lib/constants/manufacturers.ts +32 -0
- package/src/lib/db/index.ts +23 -0
- package/src/lib/db/schema/audit-logs.ts +42 -0
- package/src/lib/db/schema/departments.ts +39 -0
- package/src/lib/db/schema/device-categories.ts +38 -0
- package/src/lib/db/schema/devices.ts +195 -0
- package/src/lib/db/schema/engineer-profiles.ts +63 -0
- package/src/lib/db/schema/engineer-rounds.ts +115 -0
- package/src/lib/db/schema/enums.ts +148 -0
- package/src/lib/db/schema/hospitals.ts +34 -0
- package/src/lib/db/schema/index.ts +24 -0
- package/src/lib/db/schema/locations.ts +46 -0
- package/src/lib/db/schema/maintenance-plans.ts +99 -0
- package/src/lib/db/schema/maintenance-records.ts +161 -0
- package/src/lib/db/schema/maintenance-tasks.ts +196 -0
- package/src/lib/db/schema/manufacturers.ts +60 -0
- package/src/lib/db/schema/notifications.ts +48 -0
- package/src/lib/db/schema/organizations.ts +24 -0
- package/src/lib/db/schema/report-history.ts +28 -0
- package/src/lib/db/schema/roles.ts +59 -0
- package/src/lib/db/schema/sessions.ts +46 -0
- package/src/lib/db/schema/signature-events.ts +48 -0
- package/src/lib/db/schema/signature-policies.ts +60 -0
- package/src/lib/db/schema/signatures.ts +87 -0
- package/src/lib/db/schema/tickets.ts +169 -0
- package/src/lib/db/schema/user-assignments.ts +85 -0
- package/src/lib/db/schema/users.ts +39 -0
- package/src/lib/db/seed.ts +131 -0
- package/src/lib/logger/__tests__/logger.test.ts +154 -0
- package/src/lib/logger/formatters.ts +159 -0
- package/src/lib/logger/index.ts +184 -0
- package/src/lib/logger/types.ts +48 -0
- package/src/lib/notifications/create.ts +71 -0
- package/src/lib/notifications/dispatcher.ts +490 -0
- package/src/lib/notifications/index.ts +7 -0
- package/src/lib/notifications/push-sender.ts +128 -0
- package/src/lib/notifications/push.ts +64 -0
- package/src/lib/notifications/triggers.ts +166 -0
- package/src/lib/utils/__tests__/crypto.test.ts +30 -0
- package/src/lib/utils/__tests__/export.test.ts +55 -0
- package/src/lib/utils/__tests__/nav-badge.test.ts +147 -0
- package/src/lib/utils/__tests__/staff-status.test.ts +50 -0
- package/src/lib/utils/attestations.ts +19 -0
- package/src/lib/utils/crypto.ts +18 -0
- package/src/lib/utils/csv-parser.ts +181 -0
- package/src/lib/utils/export.ts +45 -0
- package/src/lib/utils/nav-badge.ts +225 -0
- package/src/lib/utils/sound.ts +152 -0
- package/src/lib/utils/staff-status.ts +115 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/validators/__tests__/auth.test.ts +127 -0
- package/src/lib/validators/__tests__/data-management.test.ts +182 -0
- package/src/lib/validators/__tests__/devices-profile.test.ts +129 -0
- package/src/lib/validators/__tests__/devices.test.ts +98 -0
- package/src/lib/validators/__tests__/engineer-rounds.test.ts +170 -0
- package/src/lib/validators/__tests__/maintenance.test.ts +178 -0
- package/src/lib/validators/__tests__/signatures.test.ts +154 -0
- package/src/lib/validators/__tests__/system-settings.test.ts +119 -0
- package/src/lib/validators/__tests__/tickets.test.ts +176 -0
- package/src/lib/validators/__tests__/users.test.ts +92 -0
- package/src/lib/validators/auth.ts +32 -0
- package/src/lib/validators/data-management.ts +67 -0
- package/src/lib/validators/departments.ts +14 -0
- package/src/lib/validators/devices.ts +94 -0
- package/src/lib/validators/engineer-rounds.ts +70 -0
- package/src/lib/validators/hospitals.ts +17 -0
- package/src/lib/validators/locations.ts +15 -0
- package/src/lib/validators/maintenance.ts +211 -0
- package/src/lib/validators/organizations.ts +11 -0
- package/src/lib/validators/reports.ts +31 -0
- package/src/lib/validators/signatures.ts +49 -0
- package/src/lib/validators/system-settings.ts +55 -0
- package/src/lib/validators/tickets.ts +125 -0
- package/src/lib/validators/users.ts +43 -0
- package/src/middleware.ts +45 -0
- package/tailwind.config.ts +76 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { pgEnum } from 'drizzle-orm/pg-core';
|
|
2
|
+
|
|
3
|
+
export const organizationStatusEnum = pgEnum('organization_status', ['active', 'archived']);
|
|
4
|
+
export const hospitalStatusEnum = pgEnum('hospital_status', ['active', 'inactive', 'archived']);
|
|
5
|
+
export const departmentStatusEnum = pgEnum('department_status', ['active', 'inactive', 'archived']);
|
|
6
|
+
export const locationTypeEnum = pgEnum('location_type', ['building', 'floor', 'room', 'area', 'workshop', 'store', 'other']);
|
|
7
|
+
export const locationStatusEnum = pgEnum('location_status', ['active', 'inactive', 'archived']);
|
|
8
|
+
export const userAccountStatusEnum = pgEnum('user_account_status', ['invited', 'active', 'suspended', 'deactivated', 'archived']);
|
|
9
|
+
export const roleStatusEnum = pgEnum('role_status', ['active', 'inactive', 'archived']);
|
|
10
|
+
export const scopeTypeEnum = pgEnum('scope_type', ['organization', 'hospital', 'department', 'location', 'assigned_work', 'category']);
|
|
11
|
+
export const assignmentStatusEnum = pgEnum('assignment_status', ['active', 'revoked', 'expired']);
|
|
12
|
+
export const permissionModuleEnum = pgEnum('permission_module', ['DEVICES', 'TICKETS', 'MAINTENANCE', 'PM_CALIBRATION', 'SIGNATURES', 'REPORTS', 'ADMIN', 'AUDIT']);
|
|
13
|
+
export const permissionActionEnum = pgEnum('permission_action', ['VIEW', 'CREATE', 'EDIT', 'ASSIGN', 'APPROVE', 'SIGN', 'RELEASE', 'ARCHIVE', 'EXPORT', 'MANAGE_POLICY']);
|
|
14
|
+
export const auditActionTypeEnum = pgEnum('audit_action_type', ['CREATE', 'UPDATE', 'DEACTIVATE', 'ARCHIVE', 'TRANSFER', 'PURGE', 'SIGN', 'POLICY_CHANGE', 'LOGIN', 'LOGOUT', 'FAILED_LOGIN']);
|
|
15
|
+
|
|
16
|
+
// Phase 3: Device Management enums
|
|
17
|
+
export const riskClassificationEnum = pgEnum('risk_classification', ['class_i', 'class_iia', 'class_iib', 'class_iii']);
|
|
18
|
+
export const criticalityLevelEnum = pgEnum('criticality_level', ['critical', 'high', 'medium', 'low']);
|
|
19
|
+
export const deviceStatusCodeEnum = pgEnum('device_status_code', [
|
|
20
|
+
'operational', 'operational_with_limitations', 'under_maintenance', 'under_repair',
|
|
21
|
+
'waiting_for_parts', 'awaiting_release', 'out_of_service', 'standby', 'decommissioned'
|
|
22
|
+
]);
|
|
23
|
+
export const deviceLifecycleStatusEnum = pgEnum('device_lifecycle_status', ['active', 'decommissioned', 'archived']);
|
|
24
|
+
export const qrLabelStatusEnum = pgEnum('qr_label_status', ['active', 'replaced', 'revoked']);
|
|
25
|
+
export const deviceDocumentCategoryEnum = pgEnum('device_document_category', [
|
|
26
|
+
'user_manual', 'service_manual', 'calibration_certificate', 'warranty_doc',
|
|
27
|
+
'photo', 'inspection_report', 'other'
|
|
28
|
+
]);
|
|
29
|
+
export const documentVisibilityEnum = pgEnum('document_visibility', ['public_department', 'biomedical_only', 'admin_only']);
|
|
30
|
+
export const transferReasonEnum = pgEnum('transfer_reason', [
|
|
31
|
+
'relocation', 'temporary_loan', 'department_change', 'correction',
|
|
32
|
+
'replacement', 'workshop', 'storage', 'other'
|
|
33
|
+
]);
|
|
34
|
+
export const refDataStatusEnum = pgEnum('ref_data_status', ['active', 'archived']);
|
|
35
|
+
|
|
36
|
+
// Phase 4: Helpdesk Tickets enums
|
|
37
|
+
export const ticketStatusCodeEnum = pgEnum('ticket_status_code', [
|
|
38
|
+
'new', 'acknowledged', 'in_triage', 'in_progress',
|
|
39
|
+
'waiting_requester', 'waiting_parts_vendor',
|
|
40
|
+
'resolved', 'closed', 'cancelled'
|
|
41
|
+
]);
|
|
42
|
+
export const ticketPriorityCodeEnum = pgEnum('ticket_priority_code', [
|
|
43
|
+
'p1_critical', 'p2_high', 'p3_normal', 'p4_low'
|
|
44
|
+
]);
|
|
45
|
+
export const ticketTypeCodeEnum = pgEnum('ticket_type_code', [
|
|
46
|
+
'device_problem', 'urgent_equipment_concern', 'maintenance_request',
|
|
47
|
+
'inspection_request', 'calibration_request', 'pm_followup'
|
|
48
|
+
]);
|
|
49
|
+
export const ticketSourceEnum = pgEnum('ticket_source', [
|
|
50
|
+
'qr_scan', 'department_device_selection', 'device_profile', 'manual_entry', 'import'
|
|
51
|
+
]);
|
|
52
|
+
export const reportedImpactCodeEnum = pgEnum('reported_impact_code', [
|
|
53
|
+
'device_usable', 'device_not_usable', 'patient_care_affected'
|
|
54
|
+
]);
|
|
55
|
+
export const reporterProblemCategoryCodeEnum = pgEnum('reporter_problem_category_code', [
|
|
56
|
+
'power_issue', 'device_not_starting', 'display_interface', 'alarm_problem',
|
|
57
|
+
'sensor_accessory', 'electrical_concern', 'mechanical_damage',
|
|
58
|
+
'software_configuration', 'performance_concern', 'maintenance_request', 'other'
|
|
59
|
+
]);
|
|
60
|
+
export const maintenanceTypeCodeEnum = pgEnum('maintenance_type_code', [
|
|
61
|
+
'preventive_maintenance', 'corrective_maintenance', 'troubleshooting',
|
|
62
|
+
'inspection', 'calibration', 'electrical_safety_testing',
|
|
63
|
+
'performance_testing', 'installation_commissioning',
|
|
64
|
+
'software_configuration', 'decommissioning'
|
|
65
|
+
]);
|
|
66
|
+
export const technicalProblemCategoryCodeEnum = pgEnum('technical_problem_category_code', [
|
|
67
|
+
'electrical_power', 'display_user_interface', 'alarm_safety',
|
|
68
|
+
'sensor_measurement', 'mechanical', 'software_configuration',
|
|
69
|
+
'performance_output', 'accessory_consumable', 'physical_damage',
|
|
70
|
+
'communication_network', 'no_fault_found', 'other'
|
|
71
|
+
]);
|
|
72
|
+
export const ticketCommentVisibilityEnum = pgEnum('ticket_comment_visibility', [
|
|
73
|
+
'public', 'internal', 'restricted'
|
|
74
|
+
]);
|
|
75
|
+
export const ticketEventTypeEnum = pgEnum('ticket_event_type', [
|
|
76
|
+
'created', 'acknowledged', 'triaged', 'assigned', 'reassigned',
|
|
77
|
+
'accepted', 'status_changed', 'priority_changed', 'waiting_for_info',
|
|
78
|
+
'info_received', 'maintenance_task_linked', 'resolved', 'closed',
|
|
79
|
+
'cancelled', 'reopened'
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
// Phase 5: Maintenance enums
|
|
83
|
+
export const maintenanceTaskStatusCodeEnum = pgEnum('maintenance_task_status_code', [
|
|
84
|
+
'draft', 'assigned', 'in_progress', 'waiting_dependency',
|
|
85
|
+
'work_complete', 'awaiting_review', 'returned_for_rework',
|
|
86
|
+
'awaiting_release', 'closed', 'cancelled'
|
|
87
|
+
]);
|
|
88
|
+
export const maintenancePlanStatusEnum = pgEnum('maintenance_plan_status', [
|
|
89
|
+
'active', 'paused', 'archived'
|
|
90
|
+
]);
|
|
91
|
+
export const pmCalculationMethodEnum = pgEnum('pm_calculation_method', [
|
|
92
|
+
'fixed_calendar', 'completion_based'
|
|
93
|
+
]);
|
|
94
|
+
export const occurrenceDueStateEnum = pgEnum('occurrence_due_state', [
|
|
95
|
+
'scheduled', 'due_soon', 'due_today', 'overdue', 'completed', 'deferred', 'cancelled'
|
|
96
|
+
]);
|
|
97
|
+
export const checklistResultCodeEnum = pgEnum('checklist_result_code', [
|
|
98
|
+
'passed', 'failed', 'not_applicable', 'requires_follow_up'
|
|
99
|
+
]);
|
|
100
|
+
export const maintenanceFinalResultCodeEnum = pgEnum('maintenance_final_result_code', [
|
|
101
|
+
'passed', 'passed_with_limitations', 'failed', 'no_fault_found',
|
|
102
|
+
'decommission_recommended', 'requires_external_service'
|
|
103
|
+
]);
|
|
104
|
+
export const signaturePurposeEnum = pgEnum('signature_purpose', [
|
|
105
|
+
'accept', 'perform', 'review', 'approve', 'release',
|
|
106
|
+
'resolve', 'close', 'reject', 'amend', 'void'
|
|
107
|
+
]);
|
|
108
|
+
export const signatureAuthMethodEnum = pgEnum('signature_auth_method', [
|
|
109
|
+
'password_reauth', 'signing_pin', 'passkey', 'session_challenge'
|
|
110
|
+
]);
|
|
111
|
+
export const signatureStatusEnum = pgEnum('signature_status', [
|
|
112
|
+
'active', 'superseded', 'rejected', 'voided'
|
|
113
|
+
]);
|
|
114
|
+
export const costTypeEnum = pgEnum('cost_type', [
|
|
115
|
+
'part', 'vendor_service', 'labor', 'transport', 'other'
|
|
116
|
+
]);
|
|
117
|
+
export const recordVersionEntityTypeEnum = pgEnum('record_version_entity_type', [
|
|
118
|
+
'maintenance_record', 'device_status_change', 'calibration_record',
|
|
119
|
+
'test_record', 'ticket_resolution', 'engineer_round'
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
// Phase 7: Notification enums
|
|
123
|
+
export const notificationTypeEnum = pgEnum('notification_type', [
|
|
124
|
+
'ticket_created', 'ticket_accepted',
|
|
125
|
+
'ticket_assigned', 'ticket_updated', 'ticket_comment',
|
|
126
|
+
'pm_due_soon', 'pm_overdue', 'calibration_due',
|
|
127
|
+
'task_review_required', 'task_approved', 'task_rejected',
|
|
128
|
+
'device_status_changed', 'sla_warning', 'system_alert'
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
// Phase 9: Electronic Signatures – Events & Policies
|
|
132
|
+
export const signatureEventTypeEnum = pgEnum('signature_event_type', [
|
|
133
|
+
'created', 'reviewed', 'approved', 'rejected',
|
|
134
|
+
'amended', 'superseded', 'voided'
|
|
135
|
+
]);
|
|
136
|
+
export const signaturePolicyActionEnum = pgEnum('signature_policy_action', [
|
|
137
|
+
'complete_corrective', 'complete_pm', 'complete_calibration',
|
|
138
|
+
'complete_testing', 'release_device', 'change_device_status',
|
|
139
|
+
'resolve_ticket', 'close_ticket', 'approve_exception'
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
// Phase 13: Engineer's Round enums
|
|
143
|
+
export const roundStatusEnum = pgEnum('round_status', [
|
|
144
|
+
'scheduled', 'in_progress', 'completed', 'missed', 'cancelled'
|
|
145
|
+
]);
|
|
146
|
+
export const roundVisitStatusEnum = pgEnum('round_visit_status', [
|
|
147
|
+
'pending', 'completed', 'skipped'
|
|
148
|
+
]);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { pgTable, uuid, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { relations } from 'drizzle-orm';
|
|
3
|
+
import { hospitalStatusEnum } from './enums';
|
|
4
|
+
import { organizations } from './organizations';
|
|
5
|
+
import { departments } from './departments';
|
|
6
|
+
|
|
7
|
+
export const hospitals = pgTable('hospitals', {
|
|
8
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
9
|
+
organizationId: uuid('organization_id').notNull().references(() => organizations.id),
|
|
10
|
+
name: text('name').notNull(),
|
|
11
|
+
code: text('code').notNull(),
|
|
12
|
+
address: text('address'),
|
|
13
|
+
city: text('city'),
|
|
14
|
+
country: text('country'),
|
|
15
|
+
phone: text('phone'),
|
|
16
|
+
email: text('email'),
|
|
17
|
+
timezone: text('timezone'),
|
|
18
|
+
status: hospitalStatusEnum('status').default('active'),
|
|
19
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
20
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
|
21
|
+
createdByUserId: uuid('created_by_user_id'),
|
|
22
|
+
updatedByUserId: uuid('updated_by_user_id'),
|
|
23
|
+
}, (t) => ({
|
|
24
|
+
orgCodeIdx: uniqueIndex('hospital_org_code_idx').on(t.organizationId, t.code),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export const hospitalsRelations = relations(hospitals, ({ one, many }) => ({
|
|
28
|
+
organization: one(organizations, {
|
|
29
|
+
fields: [hospitals.organizationId],
|
|
30
|
+
references: [organizations.id],
|
|
31
|
+
}),
|
|
32
|
+
departments: many(departments),
|
|
33
|
+
}));
|
|
34
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './enums';
|
|
2
|
+
export * from './organizations';
|
|
3
|
+
export * from './hospitals';
|
|
4
|
+
export * from './departments';
|
|
5
|
+
export * from './locations';
|
|
6
|
+
export * from './users';
|
|
7
|
+
export * from './roles';
|
|
8
|
+
export * from './user-assignments';
|
|
9
|
+
export * from './sessions';
|
|
10
|
+
export * from './audit-logs';
|
|
11
|
+
export * from './device-categories';
|
|
12
|
+
export * from './manufacturers';
|
|
13
|
+
export * from './devices';
|
|
14
|
+
export * from './engineer-rounds';
|
|
15
|
+
export * from './tickets';
|
|
16
|
+
export * from './maintenance-plans';
|
|
17
|
+
export * from './maintenance-tasks';
|
|
18
|
+
export * from './maintenance-records';
|
|
19
|
+
export * from './signatures';
|
|
20
|
+
export * from './signature-events';
|
|
21
|
+
export * from './signature-policies';
|
|
22
|
+
export * from './report-history';
|
|
23
|
+
export * from './notifications';
|
|
24
|
+
export * from './engineer-profiles';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { pgTable, uuid, text, timestamp, AnyPgColumn } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { relations } from 'drizzle-orm';
|
|
3
|
+
import { locationTypeEnum, locationStatusEnum } from './enums';
|
|
4
|
+
import { organizations } from './organizations';
|
|
5
|
+
import { hospitals } from './hospitals';
|
|
6
|
+
import { departments } from './departments';
|
|
7
|
+
|
|
8
|
+
export const locations = pgTable('locations', {
|
|
9
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
10
|
+
organizationId: uuid('organization_id').notNull().references(() => organizations.id),
|
|
11
|
+
hospitalId: uuid('hospital_id').notNull().references(() => hospitals.id),
|
|
12
|
+
departmentId: uuid('department_id').notNull().references(() => departments.id),
|
|
13
|
+
parentLocationId: uuid('parent_location_id').references((): AnyPgColumn => locations.id),
|
|
14
|
+
locationType: locationTypeEnum('location_type').notNull(),
|
|
15
|
+
name: text('name').notNull(),
|
|
16
|
+
code: text('code'),
|
|
17
|
+
status: locationStatusEnum('status').default('active'),
|
|
18
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
19
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
|
20
|
+
createdByUserId: uuid('created_by_user_id'),
|
|
21
|
+
updatedByUserId: uuid('updated_by_user_id'),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const locationsRelations = relations(locations, ({ one, many }) => ({
|
|
25
|
+
organization: one(organizations, {
|
|
26
|
+
fields: [locations.organizationId],
|
|
27
|
+
references: [organizations.id],
|
|
28
|
+
}),
|
|
29
|
+
hospital: one(hospitals, {
|
|
30
|
+
fields: [locations.hospitalId],
|
|
31
|
+
references: [hospitals.id],
|
|
32
|
+
}),
|
|
33
|
+
department: one(departments, {
|
|
34
|
+
fields: [locations.departmentId],
|
|
35
|
+
references: [departments.id],
|
|
36
|
+
}),
|
|
37
|
+
parentLocation: one(locations, {
|
|
38
|
+
fields: [locations.parentLocationId],
|
|
39
|
+
references: [locations.id],
|
|
40
|
+
relationName: 'parentChildLocations',
|
|
41
|
+
}),
|
|
42
|
+
childLocations: many(locations, {
|
|
43
|
+
relationName: 'parentChildLocations',
|
|
44
|
+
}),
|
|
45
|
+
}));
|
|
46
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { pgTable, uuid, text, timestamp, integer, jsonb, index } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { relations } from 'drizzle-orm';
|
|
3
|
+
import {
|
|
4
|
+
maintenanceTypeCodeEnum,
|
|
5
|
+
pmCalculationMethodEnum,
|
|
6
|
+
maintenancePlanStatusEnum,
|
|
7
|
+
occurrenceDueStateEnum,
|
|
8
|
+
} from './enums';
|
|
9
|
+
import { organizations } from './organizations';
|
|
10
|
+
import { hospitals } from './hospitals';
|
|
11
|
+
import { departments } from './departments';
|
|
12
|
+
import { devices } from './devices';
|
|
13
|
+
import { users } from './users';
|
|
14
|
+
|
|
15
|
+
// ── Maintenance Plans ──────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
export const maintenancePlans = pgTable('maintenance_plans', {
|
|
18
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
19
|
+
organizationId: uuid('organization_id').notNull().references(() => organizations.id),
|
|
20
|
+
hospitalId: uuid('hospital_id').notNull().references(() => hospitals.id),
|
|
21
|
+
departmentId: uuid('department_id').references(() => departments.id),
|
|
22
|
+
deviceId: uuid('device_id').notNull().references(() => devices.id),
|
|
23
|
+
|
|
24
|
+
planTypeCode: maintenanceTypeCodeEnum('plan_type_code').default('preventive_maintenance'),
|
|
25
|
+
title: text('title'),
|
|
26
|
+
checklistTemplateVersionId: uuid('checklist_template_version_id'),
|
|
27
|
+
calculationMethod: pmCalculationMethodEnum('calculation_method').default('fixed_calendar').notNull(),
|
|
28
|
+
frequencyInterval: integer('frequency_interval').notNull(),
|
|
29
|
+
frequencyUnit: text('frequency_unit').notNull(),
|
|
30
|
+
|
|
31
|
+
startBaselineDate: timestamp('start_baseline_date', { withTimezone: true }).notNull(),
|
|
32
|
+
nextDueDate: timestamp('next_due_date', { withTimezone: true }).notNull(),
|
|
33
|
+
leadTimeDays: integer('lead_time_days').default(30),
|
|
34
|
+
lastQualifyingRecordId: uuid('last_qualifying_record_id'),
|
|
35
|
+
|
|
36
|
+
assignedEngineerUserId: uuid('assigned_engineer_user_id').references(() => users.id),
|
|
37
|
+
assignedTeamId: uuid('assigned_team_id'),
|
|
38
|
+
|
|
39
|
+
status: maintenancePlanStatusEnum('status').default('active').notNull(),
|
|
40
|
+
pauseReason: text('pause_reason'),
|
|
41
|
+
archiveReason: text('archive_reason'),
|
|
42
|
+
deviceSnapshot: jsonb('device_snapshot'),
|
|
43
|
+
instructions: text('instructions'),
|
|
44
|
+
|
|
45
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
46
|
+
createdByUserId: uuid('created_by_user_id').references(() => users.id),
|
|
47
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
|
48
|
+
updatedByUserId: uuid('updated_by_user_id').references(() => users.id),
|
|
49
|
+
}, (t) => ({
|
|
50
|
+
lookupIdx: index('idx_maintenance_plans_lookup').on(t.organizationId, t.hospitalId, t.departmentId, t.status),
|
|
51
|
+
deviceIdx: index('idx_maintenance_plans_device').on(t.deviceId, t.status),
|
|
52
|
+
dueIdx: index('idx_maintenance_plans_due').on(t.organizationId, t.nextDueDate),
|
|
53
|
+
assigneeIdx: index('idx_maintenance_plans_assignee').on(t.assignedEngineerUserId, t.status),
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
export const maintenancePlansRelations = relations(maintenancePlans, ({ one, many }) => ({
|
|
57
|
+
organization: one(organizations, { fields: [maintenancePlans.organizationId], references: [organizations.id] }),
|
|
58
|
+
hospital: one(hospitals, { fields: [maintenancePlans.hospitalId], references: [hospitals.id] }),
|
|
59
|
+
department: one(departments, { fields: [maintenancePlans.departmentId], references: [departments.id] }),
|
|
60
|
+
device: one(devices, { fields: [maintenancePlans.deviceId], references: [devices.id] }),
|
|
61
|
+
assignedEngineer: one(users, { fields: [maintenancePlans.assignedEngineerUserId], references: [users.id], relationName: 'maintenancePlansAssignedEngineer' }),
|
|
62
|
+
createdByUser: one(users, { fields: [maintenancePlans.createdByUserId], references: [users.id], relationName: 'maintenancePlansCreatedByUser' }),
|
|
63
|
+
updatedByUser: one(users, { fields: [maintenancePlans.updatedByUserId], references: [users.id], relationName: 'maintenancePlansUpdatedByUser' }),
|
|
64
|
+
occurrences: many(maintenanceScheduleOccurrences),
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
// ── Maintenance Schedule Occurrences ──────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
export const maintenanceScheduleOccurrences = pgTable('maintenance_schedule_occurrences', {
|
|
70
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
71
|
+
maintenancePlanId: uuid('maintenance_plan_id').notNull().references(() => maintenancePlans.id, { onDelete: 'cascade' }),
|
|
72
|
+
deviceId: uuid('device_id').notNull().references(() => devices.id),
|
|
73
|
+
|
|
74
|
+
originalDueDate: timestamp('original_due_date', { withTimezone: true }).notNull(),
|
|
75
|
+
currentDueDate: timestamp('current_due_date', { withTimezone: true }).notNull(),
|
|
76
|
+
dueState: occurrenceDueStateEnum('due_state').default('scheduled').notNull(),
|
|
77
|
+
|
|
78
|
+
generatedTaskId: uuid('generated_task_id'),
|
|
79
|
+
generatedAt: timestamp('generated_at', { withTimezone: true }),
|
|
80
|
+
qualifyingRecordId: uuid('qualifying_record_id'),
|
|
81
|
+
|
|
82
|
+
deferredAt: timestamp('deferred_at', { withTimezone: true }),
|
|
83
|
+
deferralReason: text('deferral_reason'),
|
|
84
|
+
deferredByUserId: uuid('deferred_by_user_id').references(() => users.id),
|
|
85
|
+
|
|
86
|
+
cancelledAt: timestamp('cancelled_at', { withTimezone: true }),
|
|
87
|
+
cancellationReason: text('cancellation_reason'),
|
|
88
|
+
}, (t) => ({
|
|
89
|
+
planIdx: index('idx_maintenance_occurrences_plan').on(t.maintenancePlanId, t.dueState),
|
|
90
|
+
deviceIdx: index('idx_maintenance_occurrences_device').on(t.deviceId, t.dueState),
|
|
91
|
+
dueDateIdx: index('idx_maintenance_occurrences_due').on(t.currentDueDate, t.dueState),
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
export const maintenanceScheduleOccurrencesRelations = relations(maintenanceScheduleOccurrences, ({ one }) => ({
|
|
95
|
+
maintenancePlan: one(maintenancePlans, { fields: [maintenanceScheduleOccurrences.maintenancePlanId], references: [maintenancePlans.id] }),
|
|
96
|
+
device: one(devices, { fields: [maintenanceScheduleOccurrences.deviceId], references: [devices.id] }),
|
|
97
|
+
deferredByUser: one(users, { fields: [maintenanceScheduleOccurrences.deferredByUserId], references: [users.id], relationName: 'occurrencesDeferredByUser' }),
|
|
98
|
+
}));
|
|
99
|
+
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { pgTable, uuid, text, timestamp, integer, boolean, AnyPgColumn, index } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { relations } from 'drizzle-orm';
|
|
3
|
+
import {
|
|
4
|
+
maintenanceTypeCodeEnum,
|
|
5
|
+
technicalProblemCategoryCodeEnum,
|
|
6
|
+
maintenanceFinalResultCodeEnum,
|
|
7
|
+
deviceStatusCodeEnum,
|
|
8
|
+
costTypeEnum,
|
|
9
|
+
} from './enums';
|
|
10
|
+
import { organizations } from './organizations';
|
|
11
|
+
import { devices } from './devices';
|
|
12
|
+
import { maintenanceTasks } from './maintenance-tasks';
|
|
13
|
+
import { serviceTickets } from './tickets';
|
|
14
|
+
import { users } from './users';
|
|
15
|
+
|
|
16
|
+
// ── Maintenance Records ───────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
export const maintenanceRecords = pgTable('maintenance_records', {
|
|
19
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
20
|
+
recordNumber: text('record_number').notNull().unique(),
|
|
21
|
+
organizationId: uuid('organization_id').notNull().references(() => organizations.id),
|
|
22
|
+
deviceId: uuid('device_id').notNull().references(() => devices.id),
|
|
23
|
+
maintenanceTaskId: uuid('maintenance_task_id').notNull().references(() => maintenanceTasks.id),
|
|
24
|
+
serviceTicketId: uuid('service_ticket_id').references(() => serviceTickets.id),
|
|
25
|
+
maintenanceType: maintenanceTypeCodeEnum('maintenance_type').notNull(),
|
|
26
|
+
technicalCategory: technicalProblemCategoryCodeEnum('technical_category'),
|
|
27
|
+
diagnosis: text('diagnosis'),
|
|
28
|
+
rootCause: text('root_cause'),
|
|
29
|
+
workPerformed: text('work_performed'),
|
|
30
|
+
findings: text('findings'),
|
|
31
|
+
recommendations: text('recommendations'),
|
|
32
|
+
finalResultCode: maintenanceFinalResultCodeEnum('final_result_code').notNull(),
|
|
33
|
+
finalDeviceStatusCode: deviceStatusCodeEnum('final_device_status_code').notNull(),
|
|
34
|
+
calibrationCertificateNumber: text('calibration_certificate_number'),
|
|
35
|
+
calibrationValidUntil: timestamp('calibration_valid_until', { withTimezone: true }),
|
|
36
|
+
nextMaintenanceDateProposal: timestamp('next_maintenance_date_proposal', { withTimezone: true }),
|
|
37
|
+
startedAt: timestamp('started_at', { withTimezone: true }).notNull(),
|
|
38
|
+
completedAt: timestamp('completed_at', { withTimezone: true }).notNull(),
|
|
39
|
+
currentVersionNumber: integer('current_version_number').default(1).notNull(),
|
|
40
|
+
isFinalized: boolean('is_finalized').default(false).notNull(),
|
|
41
|
+
isAmended: boolean('is_amended').default(false).notNull(),
|
|
42
|
+
originalRecordId: uuid('original_record_id').references((): AnyPgColumn => maintenanceRecords.id),
|
|
43
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
44
|
+
createdByUserId: uuid('created_by_user_id').references(() => users.id),
|
|
45
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
|
|
46
|
+
}, (t) => ({
|
|
47
|
+
deviceIdx: index('idx_maintenance_records_device').on(t.deviceId, t.completedAt),
|
|
48
|
+
recordNumIdx: index('idx_maintenance_records_number').on(t.organizationId, t.recordNumber),
|
|
49
|
+
taskIdx: index('idx_maintenance_records_task').on(t.maintenanceTaskId),
|
|
50
|
+
ticketIdx: index('idx_maintenance_records_ticket').on(t.serviceTicketId),
|
|
51
|
+
lookupIdx: index('idx_maintenance_records_lookup').on(t.organizationId, t.finalResultCode),
|
|
52
|
+
calValidIdx: index('idx_maintenance_records_cal_valid').on(t.calibrationValidUntil),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
export const maintenanceRecordsRelations = relations(maintenanceRecords, ({ one, many }) => ({
|
|
56
|
+
organization: one(organizations, {
|
|
57
|
+
fields: [maintenanceRecords.organizationId],
|
|
58
|
+
references: [organizations.id],
|
|
59
|
+
}),
|
|
60
|
+
device: one(devices, {
|
|
61
|
+
fields: [maintenanceRecords.deviceId],
|
|
62
|
+
references: [devices.id],
|
|
63
|
+
}),
|
|
64
|
+
maintenanceTask: one(maintenanceTasks, {
|
|
65
|
+
fields: [maintenanceRecords.maintenanceTaskId],
|
|
66
|
+
references: [maintenanceTasks.id],
|
|
67
|
+
}),
|
|
68
|
+
serviceTicket: one(serviceTickets, {
|
|
69
|
+
fields: [maintenanceRecords.serviceTicketId],
|
|
70
|
+
references: [serviceTickets.id],
|
|
71
|
+
}),
|
|
72
|
+
createdByUser: one(users, {
|
|
73
|
+
fields: [maintenanceRecords.createdByUserId],
|
|
74
|
+
references: [users.id],
|
|
75
|
+
relationName: 'maintenanceRecordsCreatedByUser',
|
|
76
|
+
}),
|
|
77
|
+
originalRecord: one(maintenanceRecords, {
|
|
78
|
+
fields: [maintenanceRecords.originalRecordId],
|
|
79
|
+
references: [maintenanceRecords.id],
|
|
80
|
+
relationName: 'maintenanceRecordAmendments',
|
|
81
|
+
}),
|
|
82
|
+
amendments: many(maintenanceRecords, {
|
|
83
|
+
relationName: 'maintenanceRecordAmendments',
|
|
84
|
+
}),
|
|
85
|
+
parts: many(maintenanceParts),
|
|
86
|
+
costs: many(maintenanceCosts),
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
// ── Maintenance Parts ─────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
export const maintenanceParts = pgTable('maintenance_parts', {
|
|
92
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
93
|
+
maintenanceTaskId: uuid('maintenance_task_id').notNull().references(() => maintenanceTasks.id),
|
|
94
|
+
maintenanceRecordId: uuid('maintenance_record_id').references(() => maintenanceRecords.id),
|
|
95
|
+
partNumber: text('part_number').notNull(),
|
|
96
|
+
partName: text('part_name').notNull(),
|
|
97
|
+
quantity: integer('quantity').default(1).notNull(),
|
|
98
|
+
unitCost: integer('unit_cost'),
|
|
99
|
+
currency: text('currency').default('USD'),
|
|
100
|
+
supplierName: text('supplier_name'),
|
|
101
|
+
notes: text('notes'),
|
|
102
|
+
recordedByUserId: uuid('recorded_by_user_id').references(() => users.id),
|
|
103
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
|
|
104
|
+
}, (t) => ({
|
|
105
|
+
taskIdx: index('idx_maintenance_parts_task').on(t.maintenanceTaskId),
|
|
106
|
+
recordIdx: index('idx_maintenance_parts_record').on(t.maintenanceRecordId),
|
|
107
|
+
partNumIdx: index('idx_maintenance_parts_number').on(t.partNumber),
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
export const maintenancePartsRelations = relations(maintenanceParts, ({ one }) => ({
|
|
111
|
+
maintenanceTask: one(maintenanceTasks, {
|
|
112
|
+
fields: [maintenanceParts.maintenanceTaskId],
|
|
113
|
+
references: [maintenanceTasks.id],
|
|
114
|
+
}),
|
|
115
|
+
maintenanceRecord: one(maintenanceRecords, {
|
|
116
|
+
fields: [maintenanceParts.maintenanceRecordId],
|
|
117
|
+
references: [maintenanceRecords.id],
|
|
118
|
+
}),
|
|
119
|
+
recordedByUser: one(users, {
|
|
120
|
+
fields: [maintenanceParts.recordedByUserId],
|
|
121
|
+
references: [users.id],
|
|
122
|
+
relationName: 'maintenancePartsRecordedByUser',
|
|
123
|
+
}),
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
// ── Maintenance Costs ─────────────────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
export const maintenanceCosts = pgTable('maintenance_costs', {
|
|
129
|
+
id: uuid('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
130
|
+
maintenanceTaskId: uuid('maintenance_task_id').notNull().references(() => maintenanceTasks.id),
|
|
131
|
+
maintenanceRecordId: uuid('maintenance_record_id').references(() => maintenanceRecords.id),
|
|
132
|
+
costType: costTypeEnum('cost_type').notNull(),
|
|
133
|
+
amount: integer('amount').notNull(),
|
|
134
|
+
currency: text('currency').default('USD'),
|
|
135
|
+
vendorName: text('vendor_name'),
|
|
136
|
+
invoiceNumber: text('invoice_number'),
|
|
137
|
+
description: text('description'),
|
|
138
|
+
recordedByUserId: uuid('recorded_by_user_id').references(() => users.id),
|
|
139
|
+
recordedAt: timestamp('recorded_at', { withTimezone: true }).defaultNow().notNull(),
|
|
140
|
+
}, (t) => ({
|
|
141
|
+
taskIdx: index('idx_maintenance_costs_task').on(t.maintenanceTaskId),
|
|
142
|
+
recordIdx: index('idx_maintenance_costs_record').on(t.maintenanceRecordId),
|
|
143
|
+
costTypeIdx: index('idx_maintenance_costs_type').on(t.costType),
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
export const maintenanceCostsRelations = relations(maintenanceCosts, ({ one }) => ({
|
|
147
|
+
maintenanceTask: one(maintenanceTasks, {
|
|
148
|
+
fields: [maintenanceCosts.maintenanceTaskId],
|
|
149
|
+
references: [maintenanceTasks.id],
|
|
150
|
+
}),
|
|
151
|
+
maintenanceRecord: one(maintenanceRecords, {
|
|
152
|
+
fields: [maintenanceCosts.maintenanceRecordId],
|
|
153
|
+
references: [maintenanceRecords.id],
|
|
154
|
+
}),
|
|
155
|
+
recordedByUser: one(users, {
|
|
156
|
+
fields: [maintenanceCosts.recordedByUserId],
|
|
157
|
+
references: [users.id],
|
|
158
|
+
relationName: 'maintenanceCostsRecordedByUser',
|
|
159
|
+
}),
|
|
160
|
+
}));
|
|
161
|
+
|