TreatmentType and ProsthesisType database shcema and data updated. Lab dispatch wired through new data.
This commit is contained in:
@@ -16,7 +16,7 @@ export class TasksController {
|
||||
@ApiOperation({ summary: 'List lab tasks (owner: all, staff: assigned only)' })
|
||||
list(@Query() query: ListLabTasksDto, @Req() req) {
|
||||
const organizationId = this.tasksService.getOrganizationIdFromUser(req.user);
|
||||
return this.tasksService.list(organizationId, req.user.id, query);
|
||||
return this.tasksService.list(organizationId, req.user.id, query, req.user.language);
|
||||
}
|
||||
|
||||
@Patch(':taskId')
|
||||
@@ -27,6 +27,12 @@ export class TasksController {
|
||||
@Req() req,
|
||||
) {
|
||||
const organizationId = this.tasksService.getOrganizationIdFromUser(req.user);
|
||||
return this.tasksService.updateStatus(taskId, dto, organizationId, req.user.id);
|
||||
return this.tasksService.updateStatus(
|
||||
taskId,
|
||||
dto,
|
||||
organizationId,
|
||||
req.user.id,
|
||||
req.user.language,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,12 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { LabTaskStatus, Prisma } from '@prisma/client';
|
||||
import { CatalogEntityKind, LabTaskStatus, Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../../../prisma/prisma.service';
|
||||
import {
|
||||
CatalogLabelService,
|
||||
normalizeCatalogLocale,
|
||||
} from '../catalog/catalog-label.service';
|
||||
import { ListLabTasksDto, UpdateLabTaskDto } from './dto/tasks.dto';
|
||||
|
||||
const taskListInclude = {
|
||||
@@ -24,7 +28,10 @@ const taskListInclude = {
|
||||
|
||||
@Injectable()
|
||||
export class TasksService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly catalogLabels: CatalogLabelService,
|
||||
) {}
|
||||
|
||||
getOrganizationIdFromUser(user: { organizationId?: string }) {
|
||||
if (!user?.organizationId) {
|
||||
@@ -33,7 +40,12 @@ export class TasksService {
|
||||
return user.organizationId;
|
||||
}
|
||||
|
||||
async list(labOrganizationId: string, actorUserId: string, query: ListLabTasksDto) {
|
||||
async list(
|
||||
labOrganizationId: string,
|
||||
actorUserId: string,
|
||||
query: ListLabTasksDto,
|
||||
localeInput?: string | null,
|
||||
) {
|
||||
await this.assertCanReadTasks(actorUserId, labOrganizationId);
|
||||
|
||||
const membership = await this.getMembership(actorUserId, labOrganizationId);
|
||||
@@ -71,10 +83,18 @@ export class TasksService {
|
||||
this.prisma.labCaseTask.count({ where }),
|
||||
]);
|
||||
|
||||
const locale = normalizeCatalogLocale(localeInput);
|
||||
const prosthesisCodes = [...new Set(items.map((t) => t.prosthesisTypeCode).filter(Boolean))];
|
||||
const prosthesisLabels = await this.catalogLabels.resolveLabels(
|
||||
CatalogEntityKind.PROSTHESIS_TYPE,
|
||||
prosthesisCodes,
|
||||
locale,
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
items: items.map((task) => this.mapTaskListItem(task)),
|
||||
items: items.map((task) => this.mapTaskListItem(task, prosthesisLabels)),
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
@@ -90,6 +110,7 @@ export class TasksService {
|
||||
dto: UpdateLabTaskDto,
|
||||
labOrganizationId: string,
|
||||
actorUserId: string,
|
||||
localeInput?: string | null,
|
||||
) {
|
||||
await this.assertCanEditTasks(actorUserId, labOrganizationId);
|
||||
|
||||
@@ -123,17 +144,28 @@ export class TasksService {
|
||||
include: taskListInclude,
|
||||
});
|
||||
|
||||
return { success: true, data: this.mapTaskListItem(updated) };
|
||||
const locale = normalizeCatalogLocale(localeInput);
|
||||
const prosthesisLabels = await this.catalogLabels.resolveLabels(
|
||||
CatalogEntityKind.PROSTHESIS_TYPE,
|
||||
[updated.prosthesisTypeCode],
|
||||
locale,
|
||||
);
|
||||
|
||||
return { success: true, data: this.mapTaskListItem(updated, prosthesisLabels) };
|
||||
}
|
||||
|
||||
private mapTaskListItem(
|
||||
task: Prisma.LabCaseTaskGetPayload<{ include: typeof taskListInclude }>,
|
||||
prosthesisLabels: Map<string, string>,
|
||||
) {
|
||||
return {
|
||||
id: task.id,
|
||||
labCaseId: task.labCaseId,
|
||||
tooth: task.tooth,
|
||||
treatmentType: task.treatmentType,
|
||||
prosthesisTypeCode: task.prosthesisTypeCode,
|
||||
prosthesisTypeLabel:
|
||||
prosthesisLabels.get(task.prosthesisTypeCode) ?? task.prosthesisTypeCode,
|
||||
stepOrder: task.stepOrder,
|
||||
stepLabel: task.stepLabel,
|
||||
status: task.status,
|
||||
|
||||
Reference in New Issue
Block a user