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);
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsDateString, IsEmail, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
||||
import { ErrorCode } from '../../../common/errors';
|
||||
|
||||
function emptyStringToUndefined({ value }: { value: unknown }): unknown {
|
||||
if (typeof value === 'string' && value.trim() === '') {
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export class CreatePatientDto {
|
||||
@IsString()
|
||||
@MinLength(1, { message: ErrorCode.VALIDATION_FIELD_REQUIRED })
|
||||
@@ -18,6 +26,7 @@ export class CreatePatientDto {
|
||||
mobile: string;
|
||||
|
||||
@IsOptional()
|
||||
@Transform(emptyStringToUndefined)
|
||||
@IsEmail({}, { message: ErrorCode.VALIDATION_EMAIL_INVALID })
|
||||
email?: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user