improvement: attachment selection for lab dispatch added. attachment preview added to cases feature.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
-- Per-shipment attachment selection: only checked files are visible to the lab.
|
||||
CREATE TABLE "lab_case_attachments" (
|
||||
"labCaseId" TEXT NOT NULL,
|
||||
"attachmentId" TEXT NOT NULL,
|
||||
CONSTRAINT "lab_case_attachments_pkey" PRIMARY KEY ("labCaseId", "attachmentId")
|
||||
);
|
||||
|
||||
CREATE INDEX "lab_case_attachments_attachmentId_idx" ON "lab_case_attachments"("attachmentId");
|
||||
|
||||
ALTER TABLE "lab_case_attachments"
|
||||
ADD CONSTRAINT "lab_case_attachments_labCaseId_fkey"
|
||||
FOREIGN KEY ("labCaseId") REFERENCES "lab_cases"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "lab_case_attachments"
|
||||
ADD CONSTRAINT "lab_case_attachments_attachmentId_fkey"
|
||||
FOREIGN KEY ("attachmentId") REFERENCES "treatment_detail_attachments"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -23,6 +23,7 @@ const prisma = new PrismaClient();
|
||||
const TABLES_IN_ORDER = [
|
||||
'lab_case_task_status_events',
|
||||
'lab_case_comments',
|
||||
'lab_case_attachments',
|
||||
'lab_case_tasks',
|
||||
'lab_case_sends',
|
||||
'lab_case_tooth_prosthesis',
|
||||
@@ -31,6 +32,7 @@ const TABLES_IN_ORDER = [
|
||||
'treatment_detail_attachments',
|
||||
'treatment_details',
|
||||
'treatments',
|
||||
'appointments',
|
||||
];
|
||||
|
||||
async function tableExists(table: string): Promise<boolean> {
|
||||
|
||||
@@ -179,6 +179,7 @@ model TreatmentDetailAttachment {
|
||||
storagePath String
|
||||
|
||||
detail TreatmentDetail? @relation(fields: [detailId], references: [id], onDelete: Cascade)
|
||||
labCaseLinks LabCaseAttachment[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@ -201,11 +202,24 @@ model LabCase {
|
||||
tasks LabCaseTask[]
|
||||
toothProsthesis LabCaseToothProsthesis[]
|
||||
comments LabCaseComment[]
|
||||
attachments LabCaseAttachment[]
|
||||
|
||||
@@index([treatmentId, sortOrder])
|
||||
@@map("lab_cases")
|
||||
}
|
||||
|
||||
model LabCaseAttachment {
|
||||
labCaseId String
|
||||
attachmentId String
|
||||
|
||||
labCase LabCase @relation(fields: [labCaseId], references: [id], onDelete: Cascade)
|
||||
attachment TreatmentDetailAttachment @relation(fields: [attachmentId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([labCaseId, attachmentId])
|
||||
@@index([attachmentId])
|
||||
@@map("lab_case_attachments")
|
||||
}
|
||||
|
||||
model LabCaseDetail {
|
||||
labCaseId String
|
||||
treatmentDetailId String @unique
|
||||
|
||||
@@ -14,8 +14,12 @@ const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const counts = {
|
||||
labCaseTaskStatusEvents: await prisma.labCaseTaskStatusEvent.count(),
|
||||
labCaseComments: await prisma.labCaseComment.count(),
|
||||
labCaseAttachments: await prisma.labCaseAttachment.count(),
|
||||
labCaseTasks: await prisma.labCaseTask.count(),
|
||||
labCaseSends: await prisma.labCaseSend.count(),
|
||||
labCaseToothProsthesis: await prisma.labCaseToothProsthesis.count(),
|
||||
labCaseDetails: await prisma.labCaseDetail.count(),
|
||||
labCases: await prisma.labCase.count(),
|
||||
attachments: await prisma.treatmentDetailAttachment.count(),
|
||||
@@ -27,8 +31,12 @@ async function main() {
|
||||
console.log('Current row counts:', counts);
|
||||
|
||||
await prisma.$transaction([
|
||||
prisma.labCaseTaskStatusEvent.deleteMany(),
|
||||
prisma.labCaseComment.deleteMany(),
|
||||
prisma.labCaseAttachment.deleteMany(),
|
||||
prisma.labCaseTask.deleteMany(),
|
||||
prisma.labCaseSend.deleteMany(),
|
||||
prisma.labCaseToothProsthesis.deleteMany(),
|
||||
prisma.labCaseDetail.deleteMany(),
|
||||
prisma.labCase.deleteMany(),
|
||||
prisma.treatmentDetailAttachment.deleteMany(),
|
||||
@@ -37,7 +45,9 @@ async function main() {
|
||||
prisma.appointment.deleteMany(),
|
||||
]);
|
||||
|
||||
console.log('✅ Cleared appointments, treatments, lab cases, tasks, and attachments.');
|
||||
console.log(
|
||||
'✅ Cleared appointments, treatments, lab cases, tasks, comments, attachments, and related rows.',
|
||||
);
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user