TreatmentType and ProsthesisType database shcema and data updated. Lab dispatch wired through new data.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { TreatmentCatalogService } from './treatment-catalog.service';
|
||||
@@ -11,11 +11,9 @@ export class TreatmentCatalogController {
|
||||
constructor(private readonly treatmentCatalogService: TreatmentCatalogService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'List treatment types from the catalog (data-driven)' })
|
||||
list() {
|
||||
return {
|
||||
success: true,
|
||||
data: this.treatmentCatalogService.list(),
|
||||
};
|
||||
@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);
|
||||
return { success: true, data };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import { BadRequestException, Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { CatalogEntityKind } from '@prisma/client';
|
||||
import { PrismaService } from '../../../prisma/prisma.service';
|
||||
import {
|
||||
CatalogLabelService,
|
||||
normalizeCatalogLocale,
|
||||
} from '../catalog/catalog-label.service';
|
||||
|
||||
export type TreatmentTypeCatalogEntry = {
|
||||
id: string;
|
||||
code: string;
|
||||
labDependent: boolean;
|
||||
sortOrder: number;
|
||||
label: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
@@ -13,7 +20,10 @@ export class TreatmentCatalogService implements OnModuleInit {
|
||||
private loaded = false;
|
||||
private byCode = new Map<string, TreatmentTypeCatalogEntry>();
|
||||
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly catalogLabels: CatalogLabelService,
|
||||
) {}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.refresh();
|
||||
@@ -21,17 +31,46 @@ export class TreatmentCatalogService implements OnModuleInit {
|
||||
|
||||
async refresh(): Promise<void> {
|
||||
const rows = await this.prisma.treatmentType.findMany({
|
||||
where: { isActive: true },
|
||||
orderBy: [{ sortOrder: 'asc' }, { code: 'asc' }],
|
||||
select: { id: true, code: true, labDependent: true, sortOrder: true },
|
||||
});
|
||||
|
||||
this.byCode = new Map(rows.map((row) => [row.code, row]));
|
||||
this.byCode = new Map(
|
||||
rows.map((row) => [
|
||||
row.code,
|
||||
{
|
||||
id: row.id,
|
||||
code: row.code,
|
||||
labDependent: row.labDependent,
|
||||
sortOrder: row.sortOrder,
|
||||
label: row.code,
|
||||
},
|
||||
]),
|
||||
);
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
list(): TreatmentTypeCatalogEntry[] {
|
||||
async list(localeInput?: string | null): Promise<TreatmentTypeCatalogEntry[]> {
|
||||
await this.ensureLabels(localeInput);
|
||||
return [...this.byCode.values()].sort(
|
||||
(a, b) => a.sortOrder - b.sortOrder || a.code.localeCompare(b.code),
|
||||
);
|
||||
}
|
||||
|
||||
private async ensureLabels(localeInput?: string | null) {
|
||||
this.ensureLoaded();
|
||||
return [...this.byCode.values()];
|
||||
const locale = normalizeCatalogLocale(localeInput);
|
||||
const codes = [...this.byCode.keys()];
|
||||
const labels = await this.catalogLabels.resolveLabels(
|
||||
CatalogEntityKind.TREATMENT_TYPE,
|
||||
codes,
|
||||
locale,
|
||||
);
|
||||
|
||||
for (const [code, entry] of this.byCode) {
|
||||
entry.label = labels.get(code) ?? entry.code;
|
||||
}
|
||||
}
|
||||
|
||||
getByCode(code: string): TreatmentTypeCatalogEntry | undefined {
|
||||
|
||||
Reference in New Issue
Block a user