Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#93/today-department
Browse files Browse the repository at this point in the history
  • Loading branch information
yeeezae authored Sep 7, 2024
2 parents eab3e07 + 265b2e6 commit 4e6cec0
Show file tree
Hide file tree
Showing 26 changed files with 442 additions and 138 deletions.
4 changes: 2 additions & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { M_Charts } from './m-charts/entity/m-charts.entity';
import { MComplaintsModule } from './m-complaints/m-complaints.module';
import { M_Complaints } from './m-complaints/entity/m-complaints.entity';
import { MPrescriptionsModule } from './m-prescriptions/m-prescriptions.module';
import { M_Prescriptions } from './m-prescriptions/entity/m-prescriotions.entity';
import { M_Prescriptions } from './m-prescriptions/entity/m-prescriptions.entity';
import { HistoriesModule } from './patients/histories/histories.module';
import { Histories } from './patients/histories/entity/histories.entity';
import { Users } from './users/entity/users.entity';
Expand All @@ -30,7 +30,7 @@ import { KmComplaintsModule } from './km-complaints/km-complaints.module';
import { KmPrescriptionsModule } from './km-prescriptions/km-prescriptions.module';
import { KmMedicinesModule } from './km-medicines/km-medicines.module';
import { KM_Complaints } from './km-complaints/entity/km-complaints.entity';
import { KM_Prescriptions } from './km-prescriptions/entity/km-prescriotions.entity';
import { KM_Prescriptions } from './km-prescriptions/entity/km-prescriptions.entity';
import { KM_Medicines } from './km-medicines/entity/km-medicines.entity';
import {
ENV_DB_DATABASE_KEY,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/km-charts/entity/km-charts.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseModel } from 'src/common/entity/base.entity';
import { KM_Complaints } from 'src/km-complaints/entity/km-complaints.entity';
import { KM_Prescriptions } from 'src/km-prescriptions/entity/km-prescriotions.entity';
import { KM_Prescriptions } from 'src/km-prescriptions/entity/km-prescriptions.entity';
import { Patients } from 'src/patients/entity/patients.entity';
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';

Expand Down
54 changes: 52 additions & 2 deletions backend/src/km-charts/km-charts.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { Body, Controller, Get, HttpStatus, Param, Post } from '@nestjs/common';
import {
Body,
Controller,
Get,
HttpStatus,
NotFoundException,
Param,
ParseIntPipe,
Post,
} from '@nestjs/common';
import { KmChartsService } from './km-charts.service';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CreatePrediagnosisDto } from './dto/create-prediagnosis.dto';
import { KmPrescriptionsService } from 'src/km-prescriptions/km-prescriptions.service';
import { CreateKMPrescriptionDto } from 'src/km-prescriptions/dto/create-km-prescription.dto';
import { KmMedicinesService } from 'src/km-medicines/km-medicines.service';

@ApiTags('한의과')
@Controller('km/charts')
export class KmChartsController {
constructor(private readonly chartsService: KmChartsService) {}
constructor(
private readonly chartsService: KmChartsService,
private readonly prescriptionsService: KmPrescriptionsService,
private readonly medicinesService: KmMedicinesService,
) {}

@Post('/:chartId/prediagnosis')
@ApiOperation({
Expand Down Expand Up @@ -89,4 +105,38 @@ export class KmChartsController {
getPastChart(@Param('chartId') chartId: number) {
return this.chartsService.getPastChart(chartId);
}

@Post(':chartId/prescriptions')
@ApiOperation({
summary: '처방 생성',
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description:
'존재하지 않는 약품입니다. <small>medicineId에 해당하는 약품이 없는 경우</small>',
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
})
async postPrescription(
@Param('chartId', ParseIntPipe) chartId: number,
@Body() createPrescriptionDto: CreateKMPrescriptionDto,
) {
const chartExists = await this.chartsService.checkChartExistsById(chartId);
if (!chartExists) {
throw new NotFoundException();
}

const medicineExists = await this.medicinesService.checkMedicineExistsById(
createPrescriptionDto.medicineId,
);
if (!medicineExists) {
throw new NotFoundException('존재하지 않는 약품입니다.');
}

return await this.prescriptionsService.createPrescription(
chartId,
createPrescriptionDto,
);
}
}
22 changes: 20 additions & 2 deletions backend/src/km-charts/km-charts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@ import { Histories } from 'src/patients/histories/entity/histories.entity';
import { KM_Complaints } from 'src/km-complaints/entity/km-complaints.entity';
import { Orders } from 'src/orders/entity/orders.entity';
import { MComplaintsService } from 'src/m-complaints/m-complaints.service';
import { KmPrescriptionsService } from 'src/km-prescriptions/km-prescriptions.service';
import { KmMedicinesService } from 'src/km-medicines/km-medicines.service';
import { KM_Prescriptions } from 'src/km-prescriptions/entity/km-prescriptions.entity';
import { KM_Medicines } from 'src/km-medicines/entity/km-medicines.entity';
import { CommonService } from 'src/common/common.service';

@Module({
imports: [
TypeOrmModule.forFeature([KM_Charts, Histories, KM_Complaints, Orders]),
TypeOrmModule.forFeature([
KM_Charts,
Histories,
KM_Complaints,
Orders,
KM_Prescriptions,
KM_Medicines,
]),
],
controllers: [KmChartsController],
providers: [KmChartsService, MComplaintsService],
providers: [
KmChartsService,
MComplaintsService,
KmPrescriptionsService,
KmMedicinesService,
CommonService,
],
})
export class KmChartsModule {}
6 changes: 6 additions & 0 deletions backend/src/km-charts/km-charts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ export class KmChartsService {
where: { id: chartId },
});
}

async checkChartExistsById(id: number) {
return this.chartsRepository.exists({
where: { id },
});
}
}
74 changes: 74 additions & 0 deletions backend/src/km-medicines/dto/update-km-medicine.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
IsInt,
IsOptional,
IsString,
Length,
MaxLength,
Min,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { CreateKMMedicineDto } from './create-km-medicine.dto';
import { PartialType } from '@nestjs/mapped-types';

export class UpdateKMMedicineDto extends PartialType(CreateKMMedicineDto) {
@ApiProperty({
description: '약품명',
example: '수정한 갈근탕연조엑스(단미엑스혼합제) S02',
})
@IsString()
@Length(2, 40)
name: string;

@ApiProperty({
description: '적응증',
example:
'감기, 몸살, 뒷목과 등이 뻣뻣하게 아픔, 머리와 얼굴이 아픈 증상, 갈증, 설사, 피부 발진, 비염, 부비동염, 급성 기관지염, 급성 후두염, 성홍열, 대장염',
required: false,
})
@IsString()
@MaxLength(1000)
indication: string;

@ApiProperty({
description: '사무실 재고',
example: 5,
required: false,
})
@IsInt()
@Min(0)
stationQuantity: number;

@ApiProperty({
description: '서울역 재고',
example: 20,
})
@IsInt()
@Min(0)
officeQuantity: number;

@ApiProperty({
description: '포장단위',
example: 10,
})
@IsInt()
@Min(0)
packaging: number;

@ApiProperty({
description: '총량',
example: 200,
})
@IsInt()
@Min(0)
totalAmount: number;

@ApiProperty({
description:
"사진 - <em>image 속성 없으면 사진 변경 안 함, image='' 빈 값으로 보내면 사진 삭제</em>",
type: 'string',
format: 'binary',
required: false,
})
@IsOptional()
image?: any;
}
2 changes: 1 addition & 1 deletion backend/src/km-medicines/entity/km-medicines.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseModel } from 'src/common/entity/base.entity';
import { KM_Prescriptions } from 'src/km-prescriptions/entity/km-prescriotions.entity';
import { KM_Prescriptions } from 'src/km-prescriptions/entity/km-prescriptions.entity';
import { Column, DeleteDateColumn, Entity, OneToMany } from 'typeorm';

@Entity()
Expand Down
23 changes: 23 additions & 0 deletions backend/src/km-medicines/km-medicines.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
HttpStatus,
Param,
ParseIntPipe,
Patch,
Post,
Query,
UploadedFile,
Expand All @@ -21,6 +22,7 @@ import {
} from '@nestjs/swagger';
import { CreateKMMedicineDto } from './dto/create-km-medicine.dto';
import { PaginateKMMedicineDto } from './dto/paginate-km-medicine.dto';
import { UpdateKMMedicineDto } from './dto/update-km-medicine.dto';

@ApiTags('한의과')
@Controller('km/medicines')
Expand Down Expand Up @@ -60,6 +62,27 @@ export class KmMedicinesController {
return await this.medicinesService.createMedicine(createMedicineDto, image);
}

@Patch(':medicineId')
@UseInterceptors(FileInterceptor('image'))
@ApiConsumes('multipart/form-data')
@ApiOperation({
summary: '약품 수정',
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
})
async patchMedicine(
@Param('medicineId', ParseIntPipe) medicineId: number,
@Body() updateMedicineDto: UpdateKMMedicineDto,
@UploadedFile() image: Express.Multer.File,
) {
return this.medicinesService.updateMedicine(
medicineId,
updateMedicineDto,
image,
);
}

@Delete(':medicineId')
@ApiOperation({
summary: '약품 삭제',
Expand Down
43 changes: 43 additions & 0 deletions backend/src/km-medicines/km-medicines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@aws-sdk/client-s3';
import { PaginateKMMedicineDto } from './dto/paginate-km-medicine.dto';
import { CommonService } from 'src/common/common.service';
import { UpdateKMMedicineDto } from './dto/update-km-medicine.dto';

@Injectable()
export class KmMedicinesService {
Expand Down Expand Up @@ -61,6 +62,42 @@ export class KmMedicinesService {
});
}

async updateMedicine(
medicineId: number,
medicineDto: UpdateKMMedicineDto,
image: Express.Multer.File,
) {
const medicine = await this.medicinesRepository.findOne({
where: { id: medicineId },
});

if (!medicine) {
throw new NotFoundException();
}

// 사진 변경 (이미 있으면 삭제 후 업로드)
if (!medicineDto.hasOwnProperty('image') && image) {
if (medicine.image) {
await this.deleteUploadedImage(medicine.image);
}
const imagePath = await this.uploadImage(image, medicineDto.name);
medicineDto.image = imagePath;
}

// 사진 삭제
if (medicineDto.hasOwnProperty('image') && !image && medicine.image) {
await this.deleteUploadedImage(medicine.image);
medicineDto.image = null;
}

const newMedicine = await this.medicinesRepository.preload({
id: medicineId,
...medicineDto,
});

return await this.medicinesRepository.save(newMedicine);
}

async deleteMedicine(medicineId: number) {
const medicine = await this.medicinesRepository.findOne({
where: { id: medicineId },
Expand Down Expand Up @@ -136,4 +173,10 @@ export class KmMedicinesService {
throw new BadRequestException(error);
}
}

async checkMedicineExistsById(id: number) {
return this.medicinesRepository.exists({
where: { id },
});
}
}
55 changes: 55 additions & 0 deletions backend/src/km-prescriptions/dto/create-km-prescription.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { PickType } from '@nestjs/mapped-types';
import { KM_Prescriptions } from '../entity/km-prescriptions.entity';
import { IsInt, IsNumber, IsOptional, IsString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class CreateKMPrescriptionDto extends PickType(KM_Prescriptions, [
'doses',
'dosesCountByDay',
'dosesDay',
'dosesTime',
'memo',
]) {
@ApiProperty({
description: '1회 투약량',
example: 1,
})
@IsNumber()
doses: number;

@ApiProperty({
description: '1일 복용횟수',
example: 'tid',
})
@IsString()
dosesCountByDay: string;

@ApiProperty({
description: '복용 일수',
example: 5,
})
@IsInt()
dosesDay: number;

@ApiProperty({
description: '복용 시간',
example: '식전',
})
@IsString()
dosesTime: string;

@ApiProperty({
description: '메모',
example: '',
})
@IsString()
@IsOptional()
memo: string;

@ApiProperty({
description: '약품 ID',
example: 1,
})
@IsNumber()
medicineId: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export class KM_Prescriptions extends BaseModel {
@IsInt()
dosesDay: number;

@Column()
@IsInt()
dosesTime: number;
@Column('char', {
length: 10,
})
@IsString()
dosesTime: string;

@Column('float')
@IsNumber()
Expand Down
Loading

0 comments on commit 4e6cec0

Please sign in to comment.