78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
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')
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('patients')
|
|
export class PatientsController {
|
|
constructor(private readonly patientsService: PatientsService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a patient for current organization' })
|
|
create(@Body() createPatientDto: CreatePatientDto, @Req() req) {
|
|
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
|
return this.patientsService.create(createPatientDto, organizationId);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List patients with search and pagination' })
|
|
findAll(@Query() query: ListPatientsDto, @Req() req) {
|
|
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
|
return this.patientsService.findAll(query, organizationId);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get one patient by id' })
|
|
findOne(@Param('id') id: string, @Req() req) {
|
|
const organizationId = this.patientsService.getOrganizationIdFromUser(req.user);
|
|
return this.patientsService.findOne(id, organizationId);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update patient' })
|
|
update(@Param('id') id: string, @Body() updatePatientDto: UpdatePatientDto, @Req() req) {
|
|
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);
|
|
}
|
|
}
|