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

fixes in hospital search

parent 0a07782e
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
const encryptedFields = {
user: ['hashemail'],
doctor_master: ['pan_no'],
hospitals: ['pan_no'],
};
export default encryptedFields;
......@@ -6,9 +6,13 @@
**/
import { Expose, Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import { HospitalItemDto } from './hospital-list-item.dto';
export class GetHospitalListResponseDto extends PartialType(HospitalItemDto) {
}
/**
*
*/
......@@ -21,10 +25,10 @@ export class GetHospitalsResponseDto {
totalCount: number;
@Expose()
@Type(() => HospitalItemDto)
@Type(() => GetHospitalListResponseDto)
@ApiProperty({
type: [HospitalItemDto],
type: [GetHospitalListResponseDto],
description: 'List of hospitals',
})
list: HospitalItemDto[];
list: GetHospitalListResponseDto[];
}
......@@ -51,7 +51,7 @@ export class HospitalController {
requestBody: GetHospitalsRequestDto,
});
const { hospitalName, hospitalId, emailId } = GetHospitalsRequestDto;
let hospitals: GetHospitalsResponseDto | null = null;
let hospitals: GetHospitalsResponseDto = { list: [], totalCount: 0 };
if (hospitalName) {
hospitals = await this.hospitalService.getHospitalsByName(
......@@ -67,12 +67,6 @@ export class HospitalController {
);
}
if (
!hospitals ||
(Array.isArray(hospitals.list) && hospitals.list.length === 0)
) {
throw new AppException('No Data Found', errorCode.DATA_NOT_FOUND);
}
return hospitals;
}
}
......@@ -12,7 +12,7 @@ import {
GetHospitalsRequestDto,
} from './dto/get-hospitals/get-hospital-list-request.dto';
import {
GetHospitalsResponseDto,
GetHospitalsResponseDto
} from './dto/get-hospitals/get-hospital-list-response.dto';
import { Decimal } from '@prisma/client/runtime/library';
......@@ -37,27 +37,20 @@ export class HospitalService {
*/
transformHospitalData(rawHospitals: any[]) {
return rawHospitals.map((h) => ({
id: h.id,
id: h.hospital_id,
hospitalName: h.name,
hospitalNo: h.hospital_no,
rohiniId: h.rohini_id,
hfrId: h.hfr_id,
name: h.name,
hospitalRegNo: h.registration_no,
type: h.hospital_type_master?.name ? h.hospital_type_master.name : null,
propreitorName: h.propreitor_name,
panNo: h.pan_no,
address: h.address,
locality: h.locality,
pincode:
h.pincode_id === h.pincode_master?.id ? h.pincode_master.name : null,
state: h.state_master?.name ? h.state_master.name : null,
city: h.city_master?.name ? h.city_master.name : null,
pincode: h.pincode_master?.name ? h.pincode_master.name : null,
contactNo: h.contact,
emailId: h.email_id,
website: h.website,
isHospitalRegistered: h.is_hospital_registered,
registrationNo: h.registration_no,
registrationAuthority: h.registration_authority,
registeredFrom: h.registered_from,
registeredTill: h.registered_till,
latitude: new Decimal(h.latitude).toNumber(),
longitude: new Decimal(h.longitude).toNumber(),
contactNo: h.contact_hash,
isEPDEnabled: h.is_epd_enabled,
isNonNetwork: h.is_non_network,
status: h.status,
remarks: h.remarks,
stateId: h.state_id,
......@@ -98,14 +91,10 @@ export class HospitalService {
const { limit: take, offset: skip } = await this.pagination(page, limit);
const where: Record<string, any> = {};
if (status) {
where.status = status;
}
where.OR_CONDITION = {
state_id: stateId,
city_id: cityId,
pincode_id: pincodeId,
};
if (status) where.status = status;
if (stateId) where.state_id = stateId;
if (cityId) where.city_id = cityId;
if (pincodeId) where.pincode_id = pincodeId;
try {
const data = await fuzzySearch<any>(this.prisma, 'hospitals', {
......@@ -117,6 +106,9 @@ export class HospitalService {
where,
include: {
pincode_master: true,
state_master: true,
city_master: true,
hospital_type_master: true
},
primaryKey: 'hospital_id',
});
......@@ -125,7 +117,6 @@ export class HospitalService {
list: this.transformHospitalData(data.data),
};
} catch (error) {
console.error('Error fetching hospitals:', error.stack);
this.logger.error('Error fetching hospitals:', error);
handlePrismaError(error);
}
......@@ -151,6 +142,9 @@ export class HospitalService {
take,
include: {
pincode_master: true,
state_master: true,
city_master: true,
hospital_type_master: true
},
}),
this.prisma.hospitals.count({
......@@ -182,6 +176,9 @@ export class HospitalService {
take,
include: {
pincode_master: true,
state_master: true,
city_master: true,
hospital_type_master: true
},
}),
this.prisma.hospitals.count({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment