improvement: appointment dialog UX improved.
This commit is contained in:
@@ -104,11 +104,18 @@ export class AppointmentsService {
|
||||
patient: {
|
||||
select: { id: true, firstName: true, lastName: true, mobile: true },
|
||||
},
|
||||
treatment: { select: { id: true } },
|
||||
},
|
||||
orderBy: [{ startAt: 'asc' }],
|
||||
});
|
||||
|
||||
return { success: true, data: items };
|
||||
return {
|
||||
success: true,
|
||||
data: items.map(({ treatment, ...appointment }) => ({
|
||||
...appointment,
|
||||
hasTreatment: Boolean(treatment),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
async create(
|
||||
@@ -202,6 +209,18 @@ export class AppointmentsService {
|
||||
const providerUserId = dto.providerUserId ?? existing.providerUserId;
|
||||
const purpose = dto.purpose ?? existing.purpose;
|
||||
|
||||
if (dto.patientId && dto.patientId !== existing.patientId) {
|
||||
const linkedTreatment = await this.prisma.treatment.findUnique({
|
||||
where: { appointmentId: id },
|
||||
select: { id: true },
|
||||
});
|
||||
if (linkedTreatment) {
|
||||
throw new BadRequestException(
|
||||
'Cannot change the patient while a treatment is linked to this appointment',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.treatmentCatalog.assertKnownTreatmentType(purpose);
|
||||
|
||||
await this.ensurePatientInOrg(patientId, organizationId);
|
||||
|
||||
Reference in New Issue
Block a user