TreatmentType and ProsthesisType database shcema and data updated. Lab dispatch wired through new data.

This commit is contained in:
2026-07-06 20:40:19 +03:30
parent 3e81c110a3
commit 667b08ed0c
48 changed files with 1813 additions and 275 deletions

View File

@@ -0,0 +1,37 @@
import { BadRequestException } from '@nestjs/common';
import { normalizeTeeth } from './treatment.utils';
export type LabCaseProsthesisLink = {
treatmentDetailId: string;
detail: { id: string; treatmentType: string; teeth: unknown };
};
export type LabCaseToothProsthesisRow = {
treatmentDetailId: string;
tooth: string;
prosthesisTypeCode: string;
};
export function assertCompleteToothProsthesisMap(labCase: {
details: LabCaseProsthesisLink[];
toothProsthesis: LabCaseToothProsthesisRow[];
}) {
const prosthesisByKey = new Set(
labCase.toothProsthesis.map((tp) => `${tp.treatmentDetailId}:${tp.tooth}`),
);
for (const link of labCase.details) {
if (link.detail.treatmentType !== 'prosthesis') {
continue;
}
const teeth = normalizeTeeth(link.detail.teeth);
for (const tooth of teeth) {
const key = `${link.treatmentDetailId}:${tooth}`;
if (!prosthesisByKey.has(key)) {
throw new BadRequestException(
`Each tooth must have a prosthesis type before sending (missing tooth ${tooth})`,
);
}
}
}
}