improvement: v1 standalone treatment/case creation made possible.

This commit is contained in:
2026-08-19 15:05:58 +03:30
parent e5c39c6b7e
commit 8bfa8c88fe
39 changed files with 3296 additions and 387 deletions

View File

@@ -8,7 +8,9 @@ import { generateLabCaseTasks } from './lab-case-task.generator';
function buildMockTx(options: {
existingCount?: number;
toothProsthesisRows: Array<{
treatmentDetailId: string;
treatmentDetailId?: string | null;
lineId?: string | null;
sourceKey?: string;
tooth: string;
prosthesisTypeCode: string;
selectionGroupId?: string;
@@ -33,15 +35,27 @@ function buildMockTx(options: {
labCaseToothProsthesis: {
findMany: jest.fn().mockResolvedValue(
options.toothProsthesisRows.map((row) => ({
treatmentDetailId: row.treatmentDetailId,
treatmentDetailId: row.treatmentDetailId ?? null,
lineId: row.lineId ?? null,
sourceKey: row.sourceKey ?? row.treatmentDetailId ?? row.lineId ?? '',
treatmentType: row.treatmentType ?? 'prosthesis',
tooth: row.tooth,
prosthesisTypeCode: row.prosthesisTypeCode,
selectionGroupId: row.selectionGroupId ?? '',
detail: {
id: row.treatmentDetailId,
treatmentType: row.treatmentType ?? 'prosthesis',
toothSelectionGroups: null,
},
detail: row.treatmentDetailId
? {
id: row.treatmentDetailId,
treatmentType: row.treatmentType ?? 'prosthesis',
toothSelectionGroups: null,
}
: null,
line: row.lineId
? {
id: row.lineId,
treatmentType: row.treatmentType ?? 'prosthesis',
toothSelectionGroups: null,
}
: null,
})),
),
},
@@ -219,4 +233,34 @@ describe('generateLabCaseTasks', () => {
expect(count).toBe(0);
expect(tx.labCaseTask.createMany).not.toHaveBeenCalled();
});
it('creates tasks from lab-origin lines using sourceKey and lineId', async () => {
const pfmSteps = stepsFromSeed('pfm_crown');
const { tx, created } = buildMockTx({
toothProsthesisRows: [
{
lineId: 'line-1',
sourceKey: 'line-1',
tooth: '11',
prosthesisTypeCode: 'pfm_crown',
},
{
lineId: 'line-1',
sourceKey: 'line-1',
tooth: '21',
prosthesisTypeCode: 'pfm_crown',
},
],
prosthesisTypes: [{ code: 'pfm_crown', steps: pfmSteps }],
});
const count = await generateLabCaseTasks(tx as never, 'lab-internal-1', 'en');
expect(count).toBe(pfmSteps.length);
expect(created[0]).toMatchObject({
lineId: 'line-1',
sourceKey: 'line-1',
treatmentDetailId: null,
teeth: ['11', '21'],
});
});
});