setup project nest js with init icd codes
This commit is contained in:
80
src/icd/icd.controller.ts
Normal file
80
src/icd/icd.controller.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Controller, Get, Post, Query, Logger } from '@nestjs/common';
|
||||
import { IcdService } from './icd.service';
|
||||
import { SearchIcdDto } from './dto/search-icd.dto';
|
||||
|
||||
@Controller('icd')
|
||||
export class IcdController {
|
||||
private readonly logger = new Logger(IcdController.name);
|
||||
|
||||
constructor(private readonly icdService: IcdService) {}
|
||||
|
||||
@Post('import')
|
||||
async importData() {
|
||||
try {
|
||||
this.logger.log('Starting ICD data import...');
|
||||
const result = await this.icdService.importIcdData();
|
||||
return {
|
||||
success: true,
|
||||
message: 'ICD data imported successfully',
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error('Error importing ICD data:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Failed to import ICD data',
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Get('search')
|
||||
async searchIcdCodes(
|
||||
@Query('category') category?: string,
|
||||
@Query('search') search?: string,
|
||||
@Query('page') page?: string,
|
||||
@Query('limit') limit?: string,
|
||||
) {
|
||||
try {
|
||||
const pageNum = page ? parseInt(page, 10) : 1;
|
||||
const limitNum = limit ? parseInt(limit, 10) : 10;
|
||||
|
||||
const result = await this.icdService.findIcdCodes(
|
||||
category,
|
||||
search,
|
||||
pageNum,
|
||||
limitNum,
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
...result,
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error('Error searching ICD codes:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Failed to search ICD codes',
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Get('statistics')
|
||||
async getStatistics() {
|
||||
try {
|
||||
const stats = await this.icdService.getStatistics();
|
||||
return {
|
||||
success: true,
|
||||
data: stats,
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting statistics:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Failed to get statistics',
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user