Merge branch 'master' into feature/cases

This commit is contained in:
2026-07-10 15:26:36 +03:30
68 changed files with 2497 additions and 604 deletions

View File

@@ -329,7 +329,7 @@ export class TreatmentsService {
throw new NotFoundException('Save treatment details before creating lab cases');
}
const detailIds = dto.labCases.flatMap((lc) => lc.treatmentDetailIds);
const detailIds = dto.labCases.map((lc) => lc.treatmentDetailId);
const uniqueDetailIds = new Set(detailIds);
if (uniqueDetailIds.size !== detailIds.length) {
throw new BadRequestException('Each treatment detail can belong to only one lab case');
@@ -356,9 +356,9 @@ export class TreatmentsService {
}
for (const row of lc.toothProsthesis ?? []) {
if (!lc.treatmentDetailIds.includes(row.treatmentDetailId)) {
if (lc.treatmentDetailId !== row.treatmentDetailId) {
throw new BadRequestException(
'Tooth prosthesis must reference a detail included in this lab case',
'Tooth prosthesis must reference the lab case treatment detail',
);
}
const detail = detailById.get(row.treatmentDetailId);
@@ -416,11 +416,11 @@ export class TreatmentsService {
});
await tx.labCaseDetail.deleteMany({ where: { labCaseId: row.id } });
await tx.labCaseDetail.createMany({
data: lc.treatmentDetailIds.map((treatmentDetailId) => ({
await tx.labCaseDetail.create({
data: {
labCaseId: row.id,
treatmentDetailId,
})),
treatmentDetailId: lc.treatmentDetailId,
},
});
await tx.labCaseToothProsthesis.deleteMany({ where: { labCaseId: row.id } });
@@ -441,7 +441,7 @@ export class TreatmentsService {
const validAttachments = await tx.treatmentDetailAttachment.findMany({
where: {
id: { in: attachmentIds },
detailId: { in: lc.treatmentDetailIds },
detailId: lc.treatmentDetailId,
},
select: { id: true },
});
@@ -502,7 +502,11 @@ export class TreatmentsService {
}
if (labCase.details.length === 0) {
throw new BadRequestException('Lab case must include at least one treatment detail');
throw new BadRequestException('Lab case must include a treatment detail');
}
if (labCase.details.length > 1) {
throw new BadRequestException('Lab case can include only one treatment detail');
}
assertCompleteToothProsthesisMap(labCase);
@@ -811,13 +815,15 @@ export class TreatmentsService {
clientId: lc.clientKey ?? lc.id,
destinationOrganizationId: lc.destinationOrganizationId ?? null,
sentAt: lc.sentAt?.toISOString() ?? null,
treatmentDetailIds: lc.details?.map((d) => d.treatmentDetailId) ?? [],
details: (lc.details ?? []).map((d) => ({
id: d.detail?.id ?? d.treatmentDetailId,
clientId: d.detail?.clientKey ?? d.treatmentDetailId,
treatmentType: d.detail?.treatmentType ?? '',
teeth: d.detail ? normalizeTeeth(d.detail.teeth) : [],
})),
treatmentDetailId: lc.details?.[0]?.treatmentDetailId ?? null,
detail: lc.details?.[0]
? {
id: lc.details[0].detail?.id ?? lc.details[0].treatmentDetailId,
clientId: lc.details[0].detail?.clientKey ?? lc.details[0].treatmentDetailId,
treatmentType: lc.details[0].detail?.treatmentType ?? '',
teeth: lc.details[0].detail ? normalizeTeeth(lc.details[0].detail.teeth) : [],
}
: null,
toothProsthesis: (lc.toothProsthesis ?? []).map((tp) => ({
treatmentDetailId: tp.treatmentDetailId,
tooth: tp.tooth,