Skip to content

Commit

Permalink
feat: 한의과 예진 생성 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeeezae committed Sep 3, 2024
1 parent 6ee9dc1 commit 26651a5
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 23 deletions.
27 changes: 27 additions & 0 deletions backend/src/km-charts/const/default-km-chart-find-options.const.ts
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,
};
23 changes: 23 additions & 0 deletions backend/src/km-charts/dto/create-prediagnosis.dto.ts
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;
}
70 changes: 70 additions & 0 deletions backend/src/km-charts/dto/create-vital-sign.dto.ts
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;
}
14 changes: 0 additions & 14 deletions backend/src/km-charts/entity/km-charts.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IsInt, IsNumber, IsString } from 'class-validator';
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';
Expand All @@ -18,83 +17,70 @@ export class KM_Charts extends BaseModel {
type: 'bigint',
unique: true,
})
@IsString()
chartNumber: string;

@Column({
default: 1,
})
@IsInt()
status: number;

@Column({
nullable: true,
})
@IsNumber()
spO2: number;

@Column({
nullable: true,
})
@IsInt()
heartRate: number;

@Column('float', {
nullable: true,
})
@IsNumber()
bodyTemperature: number;

@Column({
nullable: true,
})
@IsInt()
systoleBloodPressure: number;

@Column({
nullable: true,
})
@IsInt()
diastoleBloodPressure: number;

@Column({
nullable: true,
})
@IsInt()
bloodGlucose: number;

@Column({
nullable: true,
})
@IsInt()
afterMeals: number;

@Column({
length: 500,
nullable: true,
})
@IsString()
impression: string;

@Column({
length: 500,
nullable: true,
})
@IsString()
presentIllness: string;

@Column({
length: 500,
nullable: true,
})
@IsString()
treatmentNote: string;

@Column({
length: 30,
nullable: true,
})
@IsString()
vsMemo: string;

@OneToMany(() => KM_Complaints, (complaint) => complaint.chart)
Expand Down
39 changes: 38 additions & 1 deletion backend/src/km-charts/km-charts.controller.ts
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,
};
}
}
10 changes: 8 additions & 2 deletions backend/src/km-charts/km-charts.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { KmChartsService } from './km-charts.service';
import { KmChartsController } from './km-charts.controller';
import { KM_Charts } from './entity/km-charts.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
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';

@Module({
imports: [TypeOrmModule.forFeature([KM_Charts])],
imports: [
TypeOrmModule.forFeature([KM_Charts, Histories, KM_Complaints, Orders]),
],
controllers: [KmChartsController],
providers: [KmChartsService],
providers: [KmChartsService, MComplaintsService],
})
export class KmChartsModule {}
97 changes: 95 additions & 2 deletions backend/src/km-charts/km-charts.service.ts
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;
}
}
Loading

0 comments on commit 26651a5

Please sign in to comment.