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,7 +1,10 @@
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Controller, Get, Query, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { TreatmentCatalogService } from './treatment-catalog.service';
import {
TreatmentCatalogContext,
TreatmentCatalogService,
} from './treatment-catalog.service';
@ApiTags('treatment-catalog')
@ApiBearerAuth('JWT-auth')
@@ -12,8 +15,24 @@ export class TreatmentCatalogController {
@Get()
@ApiOperation({ summary: 'List active treatment types with localized labels' })
async list(@Req() req: { user?: { language?: string | null } }) {
const data = await this.treatmentCatalogService.list(req.user?.language);
@ApiQuery({
name: 'context',
required: false,
enum: ['appointment', 'treatment'],
description: 'Filter to types selectable in the given context',
})
async list(
@Req() req: { user?: { language?: string | null } },
@Query('context') context?: string,
) {
const normalizedContext =
context === 'appointment' || context === 'treatment'
? (context as TreatmentCatalogContext)
: undefined;
const data = await this.treatmentCatalogService.list(
req.user?.language,
normalizedContext,
);
return { success: true, data };
}
}

View File

@@ -7,12 +7,16 @@ import {
normalizeCatalogLocale,
} from '../catalog/catalog-label.service';
export type TreatmentCatalogContext = 'appointment' | 'treatment';
export type TreatmentTypeCatalogEntry = {
id: string;
code: string;
labDependent: boolean;
sortOrder: number;
label: string;
availableInAppointments: boolean;
availableInTreatment: boolean;
};
@Injectable()
@@ -33,7 +37,14 @@ export class TreatmentCatalogService implements OnModuleInit {
const rows = await this.prisma.treatmentType.findMany({
where: { isActive: true },
orderBy: [{ sortOrder: 'asc' }, { code: 'asc' }],
select: { id: true, code: true, labDependent: true, sortOrder: true },
select: {
id: true,
code: true,
labDependent: true,
sortOrder: true,
availableInAppointments: true,
availableInTreatment: true,
},
});
this.byCode = new Map(
@@ -45,17 +56,26 @@ export class TreatmentCatalogService implements OnModuleInit {
labDependent: row.labDependent,
sortOrder: row.sortOrder,
label: row.code,
availableInAppointments: row.availableInAppointments,
availableInTreatment: row.availableInTreatment,
},
]),
);
this.loaded = true;
}
async list(localeInput?: string | null): Promise<TreatmentTypeCatalogEntry[]> {
async list(
localeInput?: string | null,
context?: TreatmentCatalogContext | null,
): Promise<TreatmentTypeCatalogEntry[]> {
await this.ensureLabels(localeInput);
return [...this.byCode.values()].sort(
(a, b) => a.sortOrder - b.sortOrder || a.code.localeCompare(b.code),
);
return [...this.byCode.values()]
.filter((entry) => {
if (context === 'appointment') return entry.availableInAppointments;
if (context === 'treatment') return entry.availableInTreatment;
return true;
})
.sort((a, b) => a.sortOrder - b.sortOrder || a.code.localeCompare(b.code));
}
private async ensureLabels(localeInput?: string | null) {