Incident Management — Kiến trúc & dữ liệu
Incident Management nằm trên shared Forms, nhưng có workflow và boundary riêng.
Kiến trúc tổng quan
Boundary trên FormInstance
Root persistence là FormInstance, nhưng chỉ các record có FormCategoryId = IncidentManagement thuộc domain này.
| Boundary | Ghi chú |
|---|---|
| Owner | IncidentFormInstance aggregate. |
| Scope | Current Business Unit; customer scope qua account + acknowledgement. |
| Identity | Incident id và incident guid dùng cho detail/history/notification. |
| Owned data | Status, incident fields, notification flags, attendee links, acknowledgement links, generated docs. |
| Read dependencies | Org/Site, course, attendance, account, attendee, contact, notification settings. |
Luồng staff/admin
Luồng customer
Customer không đọc incident trực tiếp theo attendee. Access đi qua FormAcknowledgement:
Quy tắc này giúp customer chỉ thấy incident/attendee liên quan đến acknowledgement của account hiện tại.
PDF và attachment
| Thành phần | Vai trò |
|---|---|
IncidentManagementService.GeneratePdfAsync | Build dataset, gọi Reporting service, lưu generated document. |
BuildPdfDatasetAsync | Gom incident, attendee, acknowledgement, attachment eligible. |
MergePdfAttachmentsAsync | Nối PDF report với PDF attachment khi hợp lệ. |
| Blob service | Lưu attachment, generated document và signature. |
Onsite App webview
Cùng UI/service nhưng truy cập qua Onsite App wrapper:
- Wrapper truyền site identifier(s) và app context; list scope theo đó (single-site ẩn selector, multi-site giới hạn selector).
- Entry "Incident" trên landing page gate bằng quyền incident.
- Attachment view/download/upload chạy trong webview (tablet/mobile), layout list/form thích ứng viewport.
Description template prefill
- Template Description mặc định mỗi incident type lưu trong
form-config-jsonblob (field-prefill format). - Tên blob lưu ở
FormTemplateVersion.PrefillBlobNamecủa version active theo Business Unit; chưa set ⇒ dùng built-in default. - Khi tạo/edit, service materialize Description thành text thuần, resolve placeholder từ dữ liệu incident hiện tại.
Notification integration
Incident tạo notification theo hai điểm chính, xử lý bất đồng bộ:
| Event | Khi nào tạo job | Worker làm gì |
|---|---|---|
IncidentSubmitted | Khi staff submit incident. | Resolve staff/manager recipient của Business Unit, queue một email mỗi recipient với placeholder (incident type, date, time, enterprise/BU/site, attendee names, staff name, link admin portal). Không tạo acknowledgement/portal message. |
IncidentSentToCustomer | Khi staff send approved incident cho customer. | Load incident/contact/template, queue email + SMS theo channel chọn, render placeholder; tạo portal user message nếu contact có portal user id. |
- Template fallback: BU chưa cấu hình template cho event type ⇒ worker render từ built-in default template thay vì skip/fail job.
- Unified customer template: một template duy nhất cho Incident/Accident/Illness; loại cụ thể render qua placeholder.
- Link incident trong email customer trỏ tới customer portal incident list page của Business Unit.
- Xử lý xong recipient ⇒ acknowledgement chuyển status Sent.
History/audit
- Lifecycle actions ghi entity history theo incident guid.
- Snapshot được ghi ở milestone lớn: submit, approve, send to customer, close.
- Staff có route notification history riêng để xem notification jobs liên quan incident.
Tiếp theo: Luồng xử lý trong code.