Skip to content

Commit d2a0a3c

Browse files
authored
feat(BE): 한의과 예진 생성 API 구현 (#84)
* feat: chartNumber 생성 로직 한의과 중복 추가 * feat: 한의과 예진 생성 API 구현
1 parent edd89a9 commit d2a0a3c

10 files changed

+301
-24
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { FindManyOptions } from 'typeorm';
2+
import { KM_Charts } from '../entity/km-charts.entity';
3+
4+
export const DEFAULT_KM_CHART_FIND_OPTIONS: FindManyOptions<KM_Charts> = {
5+
select: {
6+
prescriptions: {
7+
id: true,
8+
doses: true,
9+
dosesCountByDay: true,
10+
dosesDay: true,
11+
dosesTotal: true,
12+
memo: true,
13+
medicine: {
14+
id: true,
15+
name: true,
16+
deletedAt: true,
17+
},
18+
},
19+
},
20+
relations: {
21+
complaints: true,
22+
prescriptions: {
23+
medicine: true,
24+
},
25+
},
26+
withDeleted: true,
27+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CreateVitalSignDto } from './create-vital-sign.dto';
2+
import { CreateKMComplaintDto } from '../../km-complaints/dto/create-km-complaint.dto';
3+
import { ApiProperty } from '@nestjs/swagger';
4+
import { ValidateNested } from 'class-validator';
5+
import { Type } from 'class-transformer';
6+
import { CreateHistoryDto } from 'src/patients/histories/dto/create-history.dto';
7+
8+
export class CreatePrediagnosisDto {
9+
@ApiProperty({ type: CreateVitalSignDto })
10+
@ValidateNested()
11+
@Type(() => CreateVitalSignDto)
12+
vistalSign: CreateVitalSignDto;
13+
14+
@ApiProperty({ type: CreateKMComplaintDto })
15+
@ValidateNested()
16+
@Type(() => CreateKMComplaintDto)
17+
complaint: CreateKMComplaintDto;
18+
19+
@ApiProperty({ type: CreateHistoryDto })
20+
@ValidateNested()
21+
@Type(() => CreateHistoryDto)
22+
history: CreateHistoryDto;
23+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { PickType } from '@nestjs/mapped-types';
2+
import { ApiProperty } from '@nestjs/swagger';
3+
import { IsInt, IsNumber, IsString } from 'class-validator';
4+
import { KM_Charts } from '../entity/km-charts.entity';
5+
6+
export class CreateVitalSignDto extends PickType(KM_Charts, [
7+
'spO2',
8+
'heartRate',
9+
'bodyTemperature',
10+
'diastoleBloodPressure',
11+
'bloodGlucose',
12+
'afterMeals',
13+
'vsMemo',
14+
]) {
15+
@ApiProperty({
16+
description: 'SpO2',
17+
example: 0,
18+
})
19+
@IsNumber()
20+
spO2: number;
21+
22+
@ApiProperty({
23+
description: 'Heart Rate',
24+
example: 0,
25+
})
26+
@IsInt()
27+
heartRate: number;
28+
29+
@ApiProperty({
30+
description: 'Body Temporature',
31+
example: 36.5,
32+
})
33+
@IsNumber()
34+
bodyTemperature: number;
35+
36+
@ApiProperty({
37+
description: '수축기',
38+
example: 184,
39+
})
40+
@IsInt()
41+
systoleBloodPressure: number;
42+
43+
@ApiProperty({
44+
description: '이완기',
45+
example: 80,
46+
})
47+
@IsInt()
48+
diastoleBloodPressure: number;
49+
50+
@ApiProperty({
51+
description: '혈당',
52+
example: 90,
53+
})
54+
@IsInt()
55+
bloodGlucose: number;
56+
57+
@ApiProperty({
58+
description: '식후',
59+
example: 9,
60+
})
61+
@IsInt()
62+
afterMeals: number;
63+
64+
@ApiProperty({
65+
description: 'V/S 메모',
66+
example: '대기하실 동안 맥심커피 드심',
67+
})
68+
@IsString()
69+
vsMemo: string;
70+
}

backend/src/km-charts/entity/km-charts.entity.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { IsInt, IsNumber, IsString } from 'class-validator';
21
import { BaseModel } from 'src/common/entity/base.entity';
32
import { KM_Complaints } from 'src/km-complaints/entity/km-complaints.entity';
43
import { KM_Prescriptions } from 'src/km-prescriptions/entity/km-prescriotions.entity';
@@ -18,83 +17,70 @@ export class KM_Charts extends BaseModel {
1817
type: 'bigint',
1918
unique: true,
2019
})
21-
@IsString()
2220
chartNumber: string;
2321

2422
@Column({
2523
default: 1,
2624
})
27-
@IsInt()
2825
status: number;
2926

3027
@Column({
3128
nullable: true,
3229
})
33-
@IsNumber()
3430
spO2: number;
3531

3632
@Column({
3733
nullable: true,
3834
})
39-
@IsInt()
4035
heartRate: number;
4136

4237
@Column('float', {
4338
nullable: true,
4439
})
45-
@IsNumber()
4640
bodyTemperature: number;
4741

4842
@Column({
4943
nullable: true,
5044
})
51-
@IsInt()
5245
systoleBloodPressure: number;
5346

5447
@Column({
5548
nullable: true,
5649
})
57-
@IsInt()
5850
diastoleBloodPressure: number;
5951

6052
@Column({
6153
nullable: true,
6254
})
63-
@IsInt()
6455
bloodGlucose: number;
6556

6657
@Column({
6758
nullable: true,
6859
})
69-
@IsInt()
7060
afterMeals: number;
7161

7262
@Column({
7363
length: 500,
7464
nullable: true,
7565
})
76-
@IsString()
7766
impression: string;
7867

7968
@Column({
8069
length: 500,
8170
nullable: true,
8271
})
83-
@IsString()
8472
presentIllness: string;
8573

8674
@Column({
8775
length: 500,
8876
nullable: true,
8977
})
90-
@IsString()
9178
treatmentNote: string;
9279

9380
@Column({
9481
length: 30,
9582
nullable: true,
9683
})
97-
@IsString()
9884
vsMemo: string;
9985

10086
@OneToMany(() => KM_Complaints, (complaint) => complaint.chart)
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
import { Controller } from '@nestjs/common';
1+
import { Body, Controller, HttpStatus, Param, Post } from '@nestjs/common';
22
import { KmChartsService } from './km-charts.service';
3+
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
4+
import { CreatePrediagnosisDto } from './dto/create-prediagnosis.dto';
35

6+
@ApiTags('한의과')
47
@Controller('km/charts')
58
export class KmChartsController {
69
constructor(private readonly kmChartsService: KmChartsService) {}
10+
11+
@Post('/:chartId/prediagnosis')
12+
@ApiOperation({
13+
summary: '예진 완료',
14+
})
15+
@ApiResponse({
16+
status: HttpStatus.OK,
17+
description: '예진 완료되었습니다.',
18+
})
19+
async createPrediagnosis(
20+
@Param('chartId') chartId: number,
21+
@Body() createPrediagnosisDto: CreatePrediagnosisDto,
22+
) {
23+
const vitalSign = await this.kmChartsService.createVitalSign(
24+
chartId,
25+
createPrediagnosisDto.vistalSign,
26+
);
27+
const complaint = await this.kmChartsService.createComplaint(
28+
chartId,
29+
createPrediagnosisDto.complaint,
30+
);
31+
const history = await this.kmChartsService.createHistory(
32+
chartId,
33+
createPrediagnosisDto.history,
34+
);
35+
36+
await this.kmChartsService.updateStatus(chartId, 2);
37+
38+
return {
39+
vitalSign,
40+
history,
41+
complaint,
42+
};
43+
}
744
}

backend/src/km-charts/km-charts.module.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import { KmChartsService } from './km-charts.service';
33
import { KmChartsController } from './km-charts.controller';
44
import { KM_Charts } from './entity/km-charts.entity';
55
import { TypeOrmModule } from '@nestjs/typeorm';
6+
import { Histories } from 'src/patients/histories/entity/histories.entity';
7+
import { KM_Complaints } from 'src/km-complaints/entity/km-complaints.entity';
8+
import { Orders } from 'src/orders/entity/orders.entity';
9+
import { MComplaintsService } from 'src/m-complaints/m-complaints.service';
610

711
@Module({
8-
imports: [TypeOrmModule.forFeature([KM_Charts])],
12+
imports: [
13+
TypeOrmModule.forFeature([KM_Charts, Histories, KM_Complaints, Orders]),
14+
],
915
controllers: [KmChartsController],
10-
providers: [KmChartsService],
16+
providers: [KmChartsService, MComplaintsService],
1117
})
1218
export class KmChartsModule {}
Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,97 @@
1-
import { Injectable } from '@nestjs/common';
1+
import { Injectable, NotFoundException } from '@nestjs/common';
2+
import { InjectRepository } from '@nestjs/typeorm';
3+
import { KM_Charts } from './entity/km-charts.entity';
4+
import { KM_Complaints } from 'src/km-complaints/entity/km-complaints.entity';
5+
import { Histories } from 'src/patients/histories/entity/histories.entity';
6+
import { Orders } from 'src/orders/entity/orders.entity';
7+
import { Repository } from 'typeorm';
8+
import { CreateVitalSignDto } from './dto/create-vital-sign.dto';
9+
import { CreateKMComplaintDto } from '../km-complaints/dto/create-km-complaint.dto';
10+
import { CreateHistoryDto } from '../patients/histories/dto/create-history.dto';
211

312
@Injectable()
4-
export class KmChartsService {}
13+
export class KmChartsService {
14+
constructor(
15+
@InjectRepository(KM_Charts)
16+
private readonly chartsRepository: Repository<KM_Charts>,
17+
@InjectRepository(KM_Complaints)
18+
private readonly complaintsRepository: Repository<KM_Complaints>,
19+
@InjectRepository(Histories)
20+
private readonly historiesRepository: Repository<Histories>,
21+
@InjectRepository(Orders)
22+
private readonly ordersRepository: Repository<Orders>,
23+
) {}
24+
async createVitalSign(chartId: number, vitalSignDto: CreateVitalSignDto) {
25+
const chart = await this.chartsRepository.findOne({
26+
where: { id: chartId },
27+
});
28+
29+
if (!chart) {
30+
throw new NotFoundException();
31+
}
32+
33+
return await this.chartsRepository.save({
34+
...chart,
35+
...vitalSignDto,
36+
});
37+
}
38+
39+
async createComplaint(chartId: number, complaintDto: CreateKMComplaintDto) {
40+
const chart = await this.chartsRepository.findOne({
41+
where: { id: chartId },
42+
relations: { patient: true },
43+
});
44+
45+
if (!chart) {
46+
throw new NotFoundException('Chart not found');
47+
}
48+
49+
const complaint = this.complaintsRepository.create({
50+
...complaintDto,
51+
chart,
52+
patient: { id: chart.patient.id },
53+
});
54+
return this.complaintsRepository.save(complaint);
55+
}
56+
57+
async createHistory(chartId: number, historyDto: CreateHistoryDto) {
58+
const chart = await this.chartsRepository.findOne({
59+
where: { id: chartId },
60+
relations: { patient: { history: true } },
61+
});
62+
63+
if (!chart) {
64+
throw new NotFoundException();
65+
}
66+
67+
return await this.historiesRepository.save({
68+
patient: {
69+
id: chart.patient.id,
70+
},
71+
...chart.patient.history,
72+
...historyDto,
73+
});
74+
}
75+
76+
async updateStatus(chartId: number, status: number) {
77+
const chart = await this.chartsRepository.findOne({
78+
where: { id: chartId },
79+
});
80+
81+
if (!chart) {
82+
throw new NotFoundException();
83+
}
84+
85+
chart.status = status;
86+
await this.chartsRepository.save(chart);
87+
88+
const order = await this.ordersRepository.findOne({
89+
where: { kmChart: { id: chartId } },
90+
});
91+
92+
order.status = status;
93+
await this.ordersRepository.save(order);
94+
95+
return chart;
96+
}
97+
}

0 commit comments

Comments
 (0)