improvement: treatment UX fully overhauled.
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { LinkStatus } from '@prisma/client';
|
||||
import { LabTaskStatus, LinkStatus } from '@prisma/client';
|
||||
import { createReadStream, existsSync, mkdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { randomUUID } from 'crypto';
|
||||
@@ -36,6 +36,7 @@ const treatmentInclude = {
|
||||
orderBy: [{ sentAt: 'asc' as const }],
|
||||
include: { organization: { select: { id: true, name: true } } },
|
||||
},
|
||||
tasks: { select: { id: true, status: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -64,6 +65,7 @@ const treatmentInclude = {
|
||||
},
|
||||
},
|
||||
},
|
||||
tasks: { select: { id: true, status: true } },
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -124,14 +126,25 @@ export class TreatmentsService {
|
||||
await this.assertCanReadTreatment(actorUserId, organizationId);
|
||||
await this.ensurePatientExists(patientId);
|
||||
|
||||
const membership = await this.getMembership(actorUserId, organizationId);
|
||||
const isOwner = membership?.isOwner ?? false;
|
||||
|
||||
const items = await this.prisma.treatment.findMany({
|
||||
where: {
|
||||
patientId,
|
||||
organizationId,
|
||||
details: { some: {} },
|
||||
...(isOwner
|
||||
? {}
|
||||
: {
|
||||
OR: [
|
||||
{ providerUserId: actorUserId },
|
||||
{ appointment: { is: { providerUserId: actorUserId } } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
include: treatmentInclude,
|
||||
orderBy: [{ treatmentAt: 'desc' }],
|
||||
orderBy: [{ treatmentAt: 'desc' }, { createdAt: 'desc' }],
|
||||
take: Math.min(Math.max(limit, 1), 100),
|
||||
});
|
||||
|
||||
@@ -205,7 +218,7 @@ export class TreatmentsService {
|
||||
title,
|
||||
treatmentAt: appointment.startAt,
|
||||
patientId: appointment.patientId,
|
||||
providerUserId: appointment.providerUserId,
|
||||
providerUserId: actorUserId,
|
||||
},
|
||||
})
|
||||
: await tx.treatment.create({
|
||||
@@ -213,7 +226,7 @@ export class TreatmentsService {
|
||||
organizationId,
|
||||
patientId: appointment.patientId,
|
||||
appointmentId: appointment.id,
|
||||
providerUserId: appointment.providerUserId,
|
||||
providerUserId: actorUserId,
|
||||
title,
|
||||
treatmentAt: appointment.startAt,
|
||||
},
|
||||
@@ -566,6 +579,7 @@ export class TreatmentsService {
|
||||
include: { organization: { select: { id: true, name: true } } },
|
||||
},
|
||||
toothProsthesis: true,
|
||||
tasks: { select: { id: true, status: true } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -758,10 +772,12 @@ export class TreatmentsService {
|
||||
sentAt: Date;
|
||||
organization?: { id: string; name: string };
|
||||
}>;
|
||||
tasks?: Array<{ id: string; status: LabTaskStatus }>;
|
||||
};
|
||||
} | null;
|
||||
}) {
|
||||
const labCase = d.labCaseLink?.labCase;
|
||||
const taskProgress = this.mapTaskProgress(labCase?.tasks ?? []);
|
||||
return {
|
||||
id: d.id,
|
||||
clientId: d.clientKey ?? d.id,
|
||||
@@ -772,6 +788,7 @@ export class TreatmentsService {
|
||||
labCaseId: labCase?.id ?? null,
|
||||
sentAt: labCase?.sentAt?.toISOString() ?? null,
|
||||
destinationOrganizationId: labCase?.destinationOrganizationId ?? null,
|
||||
taskProgress,
|
||||
sends:
|
||||
labCase?.sends.map((s) => ({
|
||||
organizationId: s.organizationId,
|
||||
@@ -846,6 +863,12 @@ export class TreatmentsService {
|
||||
};
|
||||
}
|
||||
|
||||
private mapTaskProgress(tasks: Array<{ status: LabTaskStatus }>) {
|
||||
const total = tasks.length;
|
||||
const completed = tasks.filter((task) => task.status === LabTaskStatus.COMPLETED).length;
|
||||
return { completed, total };
|
||||
}
|
||||
|
||||
private mapAttachment(a: {
|
||||
id: string;
|
||||
fileName: string;
|
||||
|
||||
Reference in New Issue
Block a user