@@ -14,10 +14,10 @@ export class MChartsService {
14
14
constructor (
15
15
@InjectRepository ( M_Charts )
16
16
private readonly chartsRepository : Repository < M_Charts > ,
17
- @InjectRepository ( Histories )
18
- private readonly historiesRepository : Repository < Histories > ,
19
17
@InjectRepository ( M_Complaints )
20
18
private readonly complaintsRepository : Repository < M_Complaints > ,
19
+ @InjectRepository ( Histories )
20
+ private readonly historiesRepository : Repository < Histories > ,
21
21
@InjectRepository ( Orders )
22
22
private readonly ordersRepository : Repository < Orders > ,
23
23
) { }
@@ -47,27 +47,20 @@ export class MChartsService {
47
47
async createHistory ( chartId : number , historyDto : CreateHistoryDto ) {
48
48
const chart = await this . chartsRepository . findOne ( {
49
49
where : { id : chartId } ,
50
- relations : { patient : true } ,
50
+ relations : { patient : { history : true } } ,
51
51
} ) ;
52
52
53
53
if ( ! chart ) {
54
54
throw new NotFoundException ( ) ;
55
55
}
56
56
57
- const existingHistory = await this . historiesRepository . findOne ( {
58
- where : { patient : { id : chart . patient . id } } ,
57
+ return await this . historiesRepository . save ( {
58
+ patient : {
59
+ id : chart . patient . id ,
60
+ } ,
61
+ ...chart . patient . history ,
62
+ ...historyDto ,
59
63
} ) ;
60
-
61
- if ( existingHistory ) {
62
- Object . assign ( existingHistory , historyDto ) ;
63
- return this . historiesRepository . save ( existingHistory ) ;
64
- } else {
65
- const newHistory = this . historiesRepository . create ( {
66
- ...historyDto ,
67
- patient : { id : chart . patient . id } ,
68
- } ) ;
69
- return this . historiesRepository . save ( newHistory ) ;
70
- }
71
64
}
72
65
73
66
async updateStatus ( chartId : number ) {
0 commit comments