2026-08-19 01:43:50 +03:30
|
|
|
import { HttpStatus } from '@nestjs/common';
|
|
|
|
|
import { AppException, ErrorCode } from '../../common/errors';
|
2026-07-06 20:40:19 +03:30
|
|
|
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)) {
|
2026-08-19 01:43:50 +03:30
|
|
|
throw new AppException(ErrorCode.TREATMENT_TOOTH_PROSTHESIS_INCOMPLETE, HttpStatus.BAD_REQUEST);
|
2026-07-06 20:40:19 +03:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|