feature: a minimal v1 backend implemented for treatments feature.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import { IsDateString, IsNumber, IsOptional, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
export class CreateTreatmentHistoryDto {
|
||||
@IsString()
|
||||
@MaxLength(120)
|
||||
title: string;
|
||||
|
||||
@IsString()
|
||||
@MaxLength(40)
|
||||
status: string;
|
||||
|
||||
@IsDateString()
|
||||
treatmentAt: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(20)
|
||||
tooth?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(1000)
|
||||
notes?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
totalCost?: number;
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import { CreatePatientDto } from './dto/create-patient.dto';
|
||||
import { ListPatientsDto } from './dto/list-patients.dto';
|
||||
import { UpdatePatientDto } from './dto/update-patient.dto';
|
||||
import { PatientsService } from './patients.service';
|
||||
import { CreateTreatmentHistoryDto } from './dto/create-treatment-history.dto';
|
||||
|
||||
@ApiTags('patients')
|
||||
@ApiBearerAuth('JWT-auth')
|
||||
@@ -52,26 +51,4 @@ export class PatientsController {
|
||||
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
||||
return this.patientsService.update(id, updatePatientDto, organizationId);
|
||||
}
|
||||
|
||||
@Get(':id/treatments')
|
||||
@ApiOperation({ summary: 'Get patient treatment history' })
|
||||
findTreatments(
|
||||
@Param('id') id: string,
|
||||
@Query('limit', new ParseIntPipe({ optional: true })) limit = 20,
|
||||
@Req() req,
|
||||
) {
|
||||
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
||||
return this.patientsService.findTreatments(id, organizationId, limit);
|
||||
}
|
||||
|
||||
@Post(':id/treatments')
|
||||
@ApiOperation({ summary: 'Add treatment history item for a patient' })
|
||||
addTreatment(
|
||||
@Param('id') id: string,
|
||||
@Body() dto: CreateTreatmentHistoryDto,
|
||||
@Req() req,
|
||||
) {
|
||||
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
||||
return this.patientsService.addTreatment(id, dto, organizationId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { PrismaService } from '../../../prisma/prisma.service';
|
||||
import { CreatePatientDto } from './dto/create-patient.dto';
|
||||
import { ListPatientsDto } from './dto/list-patients.dto';
|
||||
import { UpdatePatientDto } from './dto/update-patient.dto';
|
||||
import { CreateTreatmentHistoryDto } from './dto/create-treatment-history.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PatientsService {
|
||||
@@ -89,36 +88,6 @@ export class PatientsService {
|
||||
return { success: true, data: patient };
|
||||
}
|
||||
|
||||
async findTreatments(patientId: string, organizationId: string, limit = 20) {
|
||||
await this.ensurePatient(patientId, organizationId);
|
||||
|
||||
const items = await this.prisma.patientTreatmentHistory.findMany({
|
||||
where: { patientId },
|
||||
orderBy: [{ treatmentAt: 'desc' }],
|
||||
take: limit,
|
||||
});
|
||||
|
||||
return { success: true, data: items };
|
||||
}
|
||||
|
||||
async addTreatment(
|
||||
patientId: string,
|
||||
dto: CreateTreatmentHistoryDto,
|
||||
organizationId: string,
|
||||
) {
|
||||
await this.ensurePatient(patientId, organizationId);
|
||||
|
||||
const treatment = await this.prisma.patientTreatmentHistory.create({
|
||||
data: {
|
||||
...dto,
|
||||
treatmentAt: new Date(dto.treatmentAt),
|
||||
patientId,
|
||||
},
|
||||
});
|
||||
|
||||
return { success: true, data: treatment };
|
||||
}
|
||||
|
||||
private async ensurePatient(id: string, organizationId: string) {
|
||||
const patient = await this.prisma.patient.findFirst({
|
||||
where: { id, organizationId },
|
||||
|
||||
Reference in New Issue
Block a user