improvement: all clinic side ui components related to treatment types updated based on the new real world data.

This commit is contained in:
2026-07-07 13:13:04 +03:30
parent 667b08ed0c
commit ed7e7b1d8f
20 changed files with 321 additions and 148 deletions

View File

@@ -1,6 +1,9 @@
/**
* Dev-only: truncate treatment and lab case data (preserves catalog tables).
* Usage: npx ts-node prisma/reset-treatment-data.ts
*
* Safe to run before or after `prisma migrate deploy`: tables that do not yet
* exist are skipped instead of throwing.
*/
import { PrismaClient } from '@prisma/client';
import { config } from 'dotenv';
@@ -16,17 +19,44 @@ if (process.env.NODE_ENV === 'production') {
const prisma = new PrismaClient();
// FK-safe order: children before parents.
const TABLES_IN_ORDER = [
'lab_case_tasks',
'lab_case_sends',
'lab_case_tooth_prosthesis',
'lab_case_details',
'lab_cases',
'treatment_detail_attachments',
'treatment_details',
'treatments',
];
async function tableExists(table: string): Promise<boolean> {
const rows = await prisma.$queryRawUnsafe<Array<{ exists: string | null }>>(
`SELECT to_regclass('public."${table}"')::text AS exists`,
);
return rows[0]?.exists != null;
}
async function main() {
console.log('Truncating treatment and lab case data...');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_tasks" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_sends" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_tooth_prosthesis" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_details" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_cases" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "treatment_detail_attachments" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "treatment_details" CASCADE');
await prisma.$executeRawUnsafe('TRUNCATE TABLE "treatments" CASCADE');
const existing: string[] = [];
for (const table of TABLES_IN_ORDER) {
if (await tableExists(table)) {
existing.push(table);
} else {
console.log(` - skipping "${table}" (does not exist yet)`);
}
}
if (existing.length === 0) {
console.log('No target tables exist yet. Run `prisma migrate deploy` first.');
return;
}
const targets = existing.map((t) => `"${t}"`).join(', ');
await prisma.$executeRawUnsafe(`TRUNCATE TABLE ${targets} CASCADE`);
console.log('Done.');
}