Skip to content
Snippets Groups Projects
Commit a8d6c360 authored by roshan's avatar roshan
Browse files

fix for create and update doctor

parent a0f8ee78
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,7 @@ export class DoctorService {
*/
async addDoctor(payload: CreateDoctorDto) {
try {
if (payload.doctorRegNo || payload.hprCode) {
const existingDoctor = await this.prisma.doctor_master.findFirst({
where: {
OR: [
......@@ -85,6 +86,7 @@ export class DoctorService {
400,
);
}
}
// Resolve city_id and state_id from pincode_master
let resolvedCityId: string | null = null;
......@@ -180,6 +182,7 @@ export class DoctorService {
longitude,
} = dto;
try {
if (doctorRegNo || hprCode) {
// Check for duplicate doctorRegNo or hprCode within hospital
const existingDoctor = await this.prisma.doctor_master.findFirst({
where: {
......@@ -192,24 +195,38 @@ export class DoctorService {
errorCode.DATA_NOT_FOUND,
);
}
const pincodeMaster = await this.prisma.pincode_master.findUnique({
}
// Resolve city_id and state_id from pincode_master
let resolvedCityId: string | null = null;
let resolvedStateId: string | null = null;
if (pincodeId) {
const pincodeRecord = await this.prisma.pincode_master.findUnique({
where: { id: pincodeId },
select: { city_id: true, state_id: true },
});
if (pincodeRecord) {
resolvedCityId = pincodeRecord.city_id;
resolvedStateId = pincodeRecord.state_id;
}
}
const data = {
name: doctorName,
registration_no: doctorRegNo,
registration_no: doctorRegNo ?? null,
speciality_id: doctorSpecialityId,
doctor_contact: contactNo,
hpr_code: hprCode,
doctor_email_id: emailId,
pan_no: panNo,
address: address,
pincode_id: pincodeId,
doctor_contact: contactNo ?? null,
hpr_code: hprCode ?? null,
doctor_email_id: emailId ?? null,
//@ts-ignore
pan_no: panNo ?? null,
address: address ?? null,
pincode_id: pincodeId ?? null,
latitude: latitude ?? null,
longitude: longitude ?? null,
state_id: pincodeMaster?.state_id ?? null,
city_id: pincodeMaster?.city_id ?? null,
is_active: true,
state_id: resolvedStateId,
city_id: resolvedCityId,
created_by: userId ?? '',
updated_by: userId ?? '',
};
......@@ -257,11 +274,12 @@ export class DoctorService {
listDoctorsRequestDto: ListDoctorsRequestDto,
): Promise<PaginatedDoctorsResponseDto> {
try {
const { doctorName, doctorRegNo, emailId, mobileNo, hprCode, panNo, page, limit } =
const { doctorName, doctorRegNo, specialityId, emailId, mobileNo, hprCode, panNo, page, limit } =
listDoctorsRequestDto;
const whereCondition: Record<string, string> = {};
const whereCondition: Record<string, any> = {};
if (specialityId) whereCondition.speciality_id = specialityId;
if (doctorRegNo) whereCondition.registration_no = doctorRegNo;
if (emailId) whereCondition.doctor_email_id = emailId;
if (mobileNo) whereCondition.doctor_contact = mobileNo;
......
......@@ -61,7 +61,6 @@ export class CreateDoctorDto {
})
@IsOptional()
@IsString()
@IsNotEmpty({ message: 'Contact number is required' })
contactNo?: string;
@ApiProperty({
......@@ -71,7 +70,6 @@ export class CreateDoctorDto {
})
@IsOptional()
@IsString()
@IsNotEmpty({ message: 'Doctor registration number is required' })
doctorRegNo?: string;
@ApiProperty({
......@@ -81,7 +79,6 @@ export class CreateDoctorDto {
})
@IsOptional()
@IsString()
@IsNotEmpty({ message: 'HPR code is required' })
hprCode?: string;
@ApiProperty({
......@@ -91,7 +88,6 @@ export class CreateDoctorDto {
})
@IsOptional()
@IsString()
@IsNotEmpty({ message: 'PAN number is required' })
panNo?: string;
@ApiProperty({
......@@ -101,7 +97,6 @@ export class CreateDoctorDto {
})
@IsOptional()
@IsString()
@IsNotEmpty({ message: 'Address is required' })
address?: string;
@ApiProperty({
......
......@@ -9,6 +9,7 @@ import {
IsString,
IsNumber,
IsOptional,
IsUUID,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
......@@ -69,6 +70,15 @@ export class ListDoctorsRequestDto {
@IsString()
panNo?: string;
@ApiProperty({
description: 'Speciality ID',
example: '550e8400-e29b-41d4-a716-446655440002',
required: false,
})
@IsUUID()
@IsOptional()
specialityId?: string;
@IsNumber()
@ApiProperty({
example: 1,
......
......@@ -26,12 +26,12 @@ export class UpdateDoctorRequestDto {
@ApiProperty({ example: 'uuid', description: 'Doctor ID' })
doctorId: string;
@IsUUID()
@IsNotEmpty({ message: 'User ID must be a valid UUID' })
@ApiProperty({
example: '2733a326-f4e2-4005-ad18-3b8f67a7613c',
description: 'User ID',
description: 'UUID of the user who updates the doctor record',
example: 'admin-uuid-1234',
})
@IsUUID()
@IsNotEmpty({ message: 'userId is required' })
userId: string;
@IsNotEmpty({ message: 'Doctor name should not be empty' })
......@@ -42,8 +42,8 @@ export class UpdateDoctorRequestDto {
})
doctorName: string;
@IsNotEmpty({ message: 'Doctor registration should not be empty' })
@IsString({ message: 'Doctor registration number must be a string' })
@IsOptional()
@ApiProperty({
example: 'DRREG-112',
description: 'Registration number of the doctor',
......@@ -63,12 +63,12 @@ export class UpdateDoctorRequestDto {
example: ['uuid1', 'uuid2'],
required: false,
})
@IsNotEmpty({ message: 'List of qualification UUIDs should not be empty' })
@IsOptional()
@IsArray()
@IsUUID('all', { each: true })
doctorQualificationIds: string[];
@IsNotEmpty({ message: 'Contact number should not be empty' })
@IsOptional()
@IsString({ message: 'Contact number must be a string' })
@ApiProperty({
example: '7208806389',
......@@ -76,7 +76,7 @@ export class UpdateDoctorRequestDto {
})
contactNo: string;
@IsNotEmpty({ message: 'HPR code should not be empty' })
@IsOptional()
@IsString({ message: 'HPR code must be a string' })
@ApiProperty({
example: 'HPR-112',
......@@ -84,7 +84,7 @@ export class UpdateDoctorRequestDto {
})
hprCode: string;
@IsNotEmpty({ message: 'Email ID should not be empty' })
@IsOptional()
@IsEmail({}, { message: 'Invalid email format' })
@ApiProperty({
example: 'niveus@example.com',
......@@ -92,7 +92,7 @@ export class UpdateDoctorRequestDto {
})
emailId: string;
@IsNotEmpty({ message: 'Pan number should not be empty' })
@IsOptional()
@IsString({ message: 'Pan number must be a string' })
@ApiProperty({
example: 'HSLDY8769P',
......@@ -100,7 +100,7 @@ export class UpdateDoctorRequestDto {
})
panNo: string;
@IsNotEmpty({ message: 'Address should not be empty' })
@IsOptional()
@IsString({ message: 'Address must be a string' })
@ApiProperty({
example: 'Mumbai',
......@@ -108,6 +108,7 @@ export class UpdateDoctorRequestDto {
})
address: string;
@IsOptional()
@IsUUID()
@IsNotEmpty({ message: 'Pincode ID must be a valid UUID' })
@ApiProperty({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment