-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
295 additions
and
23 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
backend/src/km-charts/const/default-km-chart-find-options.const.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FindManyOptions } from 'typeorm'; | ||
import { KM_Charts } from '../entity/km-charts.entity'; | ||
|
||
export const DEFAULT_KM_CHART_FIND_OPTIONS: FindManyOptions<KM_Charts> = { | ||
select: { | ||
prescriptions: { | ||
id: true, | ||
doses: true, | ||
dosesCountByDay: true, | ||
dosesDay: true, | ||
dosesTotal: true, | ||
memo: true, | ||
medicine: { | ||
id: true, | ||
name: true, | ||
deletedAt: true, | ||
}, | ||
}, | ||
}, | ||
relations: { | ||
complaints: true, | ||
prescriptions: { | ||
medicine: true, | ||
}, | ||
}, | ||
withDeleted: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CreateVitalSignDto } from './create-vital-sign.dto'; | ||
import { CreateKMComplaintDto } from '../../km-complaints/dto/create-km-complaint.dto'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { ValidateNested } from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
import { CreateHistoryDto } from 'src/patients/histories/dto/create-history.dto'; | ||
|
||
export class CreatePrediagnosisDto { | ||
@ApiProperty({ type: CreateVitalSignDto }) | ||
@ValidateNested() | ||
@Type(() => CreateVitalSignDto) | ||
vistalSign: CreateVitalSignDto; | ||
|
||
@ApiProperty({ type: CreateKMComplaintDto }) | ||
@ValidateNested() | ||
@Type(() => CreateKMComplaintDto) | ||
complaint: CreateKMComplaintDto; | ||
|
||
@ApiProperty({ type: CreateHistoryDto }) | ||
@ValidateNested() | ||
@Type(() => CreateHistoryDto) | ||
history: CreateHistoryDto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { PickType } from '@nestjs/mapped-types'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsInt, IsNumber, IsString } from 'class-validator'; | ||
import { KM_Charts } from '../entity/km-charts.entity'; | ||
|
||
export class CreateVitalSignDto extends PickType(KM_Charts, [ | ||
'spO2', | ||
'heartRate', | ||
'bodyTemperature', | ||
'diastoleBloodPressure', | ||
'bloodGlucose', | ||
'afterMeals', | ||
'vsMemo', | ||
]) { | ||
@ApiProperty({ | ||
description: 'SpO2', | ||
example: 0, | ||
}) | ||
@IsNumber() | ||
spO2: number; | ||
|
||
@ApiProperty({ | ||
description: 'Heart Rate', | ||
example: 0, | ||
}) | ||
@IsInt() | ||
heartRate: number; | ||
|
||
@ApiProperty({ | ||
description: 'Body Temporature', | ||
example: 36.5, | ||
}) | ||
@IsNumber() | ||
bodyTemperature: number; | ||
|
||
@ApiProperty({ | ||
description: '수축기', | ||
example: 184, | ||
}) | ||
@IsInt() | ||
systoleBloodPressure: number; | ||
|
||
@ApiProperty({ | ||
description: '이완기', | ||
example: 80, | ||
}) | ||
@IsInt() | ||
diastoleBloodPressure: number; | ||
|
||
@ApiProperty({ | ||
description: '혈당', | ||
example: 90, | ||
}) | ||
@IsInt() | ||
bloodGlucose: number; | ||
|
||
@ApiProperty({ | ||
description: '식후', | ||
example: 9, | ||
}) | ||
@IsInt() | ||
afterMeals: number; | ||
|
||
@ApiProperty({ | ||
description: 'V/S 메모', | ||
example: '대기하실 동안 맥심커피 드심', | ||
}) | ||
@IsString() | ||
vsMemo: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { Body, Controller, HttpStatus, Param, Post } from '@nestjs/common'; | ||
import { KmChartsService } from './km-charts.service'; | ||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
import { CreatePrediagnosisDto } from './dto/create-prediagnosis.dto'; | ||
|
||
@ApiTags('한의과') | ||
@Controller('km/charts') | ||
export class KmChartsController { | ||
constructor(private readonly kmChartsService: KmChartsService) {} | ||
|
||
@Post('/:chartId/prediagnosis') | ||
@ApiOperation({ | ||
summary: '예진 완료', | ||
}) | ||
@ApiResponse({ | ||
status: HttpStatus.OK, | ||
description: '예진 완료되었습니다.', | ||
}) | ||
async createPrediagnosis( | ||
@Param('chartId') chartId: number, | ||
@Body() createPrediagnosisDto: CreatePrediagnosisDto, | ||
) { | ||
const vitalSign = await this.kmChartsService.createVitalSign( | ||
chartId, | ||
createPrediagnosisDto.vistalSign, | ||
); | ||
const complaint = await this.kmChartsService.createComplaint( | ||
chartId, | ||
createPrediagnosisDto.complaint, | ||
); | ||
const history = await this.kmChartsService.createHistory( | ||
chartId, | ||
createPrediagnosisDto.history, | ||
); | ||
|
||
await this.kmChartsService.updateStatus(chartId, 2); | ||
|
||
return { | ||
vitalSign, | ||
history, | ||
complaint, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,97 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { KM_Charts } from './entity/km-charts.entity'; | ||
import { KM_Complaints } from 'src/km-complaints/entity/km-complaints.entity'; | ||
import { Histories } from 'src/patients/histories/entity/histories.entity'; | ||
import { Orders } from 'src/orders/entity/orders.entity'; | ||
import { Repository } from 'typeorm'; | ||
import { CreateVitalSignDto } from './dto/create-vital-sign.dto'; | ||
import { CreateKMComplaintDto } from '../km-complaints/dto/create-km-complaint.dto'; | ||
import { CreateHistoryDto } from '../patients/histories/dto/create-history.dto'; | ||
|
||
@Injectable() | ||
export class KmChartsService {} | ||
export class KmChartsService { | ||
constructor( | ||
@InjectRepository(KM_Charts) | ||
private readonly chartsRepository: Repository<KM_Charts>, | ||
@InjectRepository(KM_Complaints) | ||
private readonly complaintsRepository: Repository<KM_Complaints>, | ||
@InjectRepository(Histories) | ||
private readonly historiesRepository: Repository<Histories>, | ||
@InjectRepository(Orders) | ||
private readonly ordersRepository: Repository<Orders>, | ||
) {} | ||
async createVitalSign(chartId: number, vitalSignDto: CreateVitalSignDto) { | ||
const chart = await this.chartsRepository.findOne({ | ||
where: { id: chartId }, | ||
}); | ||
|
||
if (!chart) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
return await this.chartsRepository.save({ | ||
...chart, | ||
...vitalSignDto, | ||
}); | ||
} | ||
|
||
async createComplaint(chartId: number, complaintDto: CreateKMComplaintDto) { | ||
const chart = await this.chartsRepository.findOne({ | ||
where: { id: chartId }, | ||
relations: { patient: true }, | ||
}); | ||
|
||
if (!chart) { | ||
throw new NotFoundException('Chart not found'); | ||
} | ||
|
||
const complaint = this.complaintsRepository.create({ | ||
...complaintDto, | ||
chart, | ||
patient: { id: chart.patient.id }, | ||
}); | ||
return this.complaintsRepository.save(complaint); | ||
} | ||
|
||
async createHistory(chartId: number, historyDto: CreateHistoryDto) { | ||
const chart = await this.chartsRepository.findOne({ | ||
where: { id: chartId }, | ||
relations: { patient: { history: true } }, | ||
}); | ||
|
||
if (!chart) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
return await this.historiesRepository.save({ | ||
patient: { | ||
id: chart.patient.id, | ||
}, | ||
...chart.patient.history, | ||
...historyDto, | ||
}); | ||
} | ||
|
||
async updateStatus(chartId: number, status: number) { | ||
const chart = await this.chartsRepository.findOne({ | ||
where: { id: chartId }, | ||
}); | ||
|
||
if (!chart) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
chart.status = status; | ||
await this.chartsRepository.save(chart); | ||
|
||
const order = await this.ordersRepository.findOne({ | ||
where: { kmChart: { id: chartId } }, | ||
}); | ||
|
||
order.status = status; | ||
await this.ordersRepository.save(order); | ||
|
||
return chart; | ||
} | ||
} |
Oops, something went wrong.