|
@@ -2,11 +2,12 @@ package service
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"XT_New/models"
|
|
5
|
+ "fmt"
|
5
|
6
|
"github.com/jinzhu/gorm"
|
6
|
7
|
)
|
7
|
8
|
|
8
|
9
|
func GetDialysisParametersByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, schedulDate int64) ([]*models.DialysisParameter, error, int64) {
|
9
|
|
-
|
|
10
|
+ fmt.Println("scheduletye ======================", schedulType)
|
10
|
11
|
var patients []*models.Patients
|
11
|
12
|
getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
|
12
|
13
|
if getPatientErr != nil {
|
|
@@ -34,7 +35,6 @@ func GetDialysisParametersByKeyword(orgID int64, keyword string, schedulType int
|
34
|
35
|
}
|
35
|
36
|
if partitionType > 0 {
|
36
|
37
|
db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
|
37
|
|
- // db = db.Where("partition_id = ?", partitionType)
|
38
|
38
|
}
|
39
|
39
|
if schedulDate > 0 {
|
40
|
40
|
db = db.Where("schedule_date = ?", schedulDate)
|
|
@@ -49,7 +49,6 @@ func GetDialysisParameter(orgID int64, schedulDate int64, schedulType int64, par
|
49
|
49
|
db := readDb.
|
50
|
50
|
Model(&models.MonitorDialysisSchedule{}).
|
51
|
51
|
Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
52
|
|
- // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
|
53
|
52
|
Preload("TreatmentMode", "status = 1").
|
54
|
53
|
Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
|
55
|
54
|
Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
|
|
@@ -68,7 +67,6 @@ func GetDialysisParameter(orgID int64, schedulDate int64, schedulType int64, par
|
68
|
67
|
}
|
69
|
68
|
if partitionType > 0 {
|
70
|
69
|
db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ? and xt_device_number.status = 1", partitionType)
|
71
|
|
- // db = db.Where("partition_id = ?", partitionType)
|
72
|
70
|
}
|
73
|
71
|
offset := (page - 1) * limit
|
74
|
72
|
err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error
|
|
@@ -109,3 +107,170 @@ func GetWareHouseOutList(startime int64, endtime int64, orgid int64) (warehouse
|
109
|
107
|
err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.count,x.warehouse_out_order_number,x.sys_record_time,s.specification_name,t.type_name").Joins("left join xt_good_information as s on s.id = x.good_id").Where("s.status = 1 and s.org_id = ?", orgid).Joins("left join xt_goods_type as t on t.id = x.good_type_id").Order("x.id desc").Scan(&warehouse).Error
|
110
|
108
|
return warehouse, err
|
111
|
109
|
}
|
|
110
|
+
|
|
111
|
+func GetAllMaterial(startime int64, endtime int64, orgid int64) (reducedetail []*models.XtAutomaticReduceDetail, err error) {
|
|
112
|
+
|
|
113
|
+ db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
|
|
114
|
+ if startime > 0 {
|
|
115
|
+ db = db.Where("x.record_time>=?", startime)
|
|
116
|
+ }
|
|
117
|
+ if endtime > 0 {
|
|
118
|
+ db = db.Where("x.record_time<=?", endtime)
|
|
119
|
+ }
|
|
120
|
+ if orgid > 0 {
|
|
121
|
+ db = db.Where("x.org_id = ?", orgid)
|
|
122
|
+ }
|
|
123
|
+ err = db.Select("x.patient_id,x.record_time,x.good_id,t.type_name").Joins("left join xt_goods_type as t on t.id = x.good_type_id").Group("x.good_type_id").Scan(&reducedetail).Error
|
|
124
|
+ return reducedetail, err
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+func GetCollectList(limit int64, page int64, partitionType int64, schedulType int64, schedulDate int64, orgID int64, keyword string) ([]*models.DialysisParameter, error, int64) {
|
|
128
|
+
|
|
129
|
+ var patients []*models.Patients
|
|
130
|
+ getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
|
|
131
|
+ if getPatientErr != nil {
|
|
132
|
+ return nil, getPatientErr, 0
|
|
133
|
+ }
|
|
134
|
+ patientIDs := make([]int64, len(patients))
|
|
135
|
+ for index, patient := range patients {
|
|
136
|
+ patientIDs[index] = patient.ID
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ db := readDb.
|
|
140
|
+ Model(&models.DialysisSchedule{}).
|
|
141
|
+ Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
142
|
+ // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
|
|
143
|
+ Preload("TreatmentMode", "status = 1").
|
|
144
|
+ Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
|
|
145
|
+ Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
|
|
146
|
+ Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
|
|
147
|
+ Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
|
|
148
|
+ Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
|
|
149
|
+ Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
|
|
150
|
+ db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
|
|
151
|
+ if schedulType > 0 {
|
|
152
|
+ db = db.Where("schedule_type = ?", schedulType)
|
|
153
|
+ }
|
|
154
|
+ if partitionType > 0 {
|
|
155
|
+ db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
|
|
156
|
+ // db = db.Where("partition_id = ?", partitionType)
|
|
157
|
+ }
|
|
158
|
+ if schedulDate > 0 {
|
|
159
|
+ db = db.Where("schedule_date = ?", schedulDate)
|
|
160
|
+ }
|
|
161
|
+ var schedules []*models.DialysisParameter
|
|
162
|
+ total := int64(0)
|
|
163
|
+ err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
|
|
164
|
+ return schedules, err, total
|
|
165
|
+}
|
|
166
|
+
|
|
167
|
+func GetDialysisConsumables(startime int64, endtime int64, orgid int64) (reducedetail []*models.XtAutomaticReduceDetail, err error) {
|
|
168
|
+
|
|
169
|
+ db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
|
|
170
|
+ table := XTReadDB().Table("xt_warehouse_out_info as f").Where("f.status = 1 and f.org_id = ?", orgid)
|
|
171
|
+ fmt.Println(table)
|
|
172
|
+ if startime > 0 {
|
|
173
|
+ db = db.Where("x.record_time >=?", startime)
|
|
174
|
+ }
|
|
175
|
+ if endtime > 0 {
|
|
176
|
+ db = db.Where("x.record_time <=?", endtime)
|
|
177
|
+ }
|
|
178
|
+ if orgid > 0 {
|
|
179
|
+ db = db.Where("x.org_id =?", orgid)
|
|
180
|
+ }
|
|
181
|
+ err = db.Select("x.patient_id,f.count,x.good_id,x.good_type_id,t.specification_name,s.type_name").Joins("left join xt_good_information as t on t.id = x.good_id").Where("t.org_id = ? and t.status = 1", orgid).Joins("left join xt_goods_type as s on s.id = x.good_type_id").Joins("left join xt_warehouse_out_info as f on f.id = x.warehouse_out_id").Scan(&reducedetail).Error
|
|
182
|
+ return reducedetail, err
|
|
183
|
+}
|
|
184
|
+
|
|
185
|
+func GetBatchCollection(orgID int64, schIDs []string) (schedules []*models.DialysisParameter, err error) {
|
|
186
|
+
|
|
187
|
+ db := readDb.
|
|
188
|
+ Model(&models.DialysisSchedule{}).
|
|
189
|
+ Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
|
|
190
|
+ // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
|
|
191
|
+ Preload("TreatmentMode", "status = 1").
|
|
192
|
+ Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
|
|
193
|
+ Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
|
|
194
|
+ Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
|
|
195
|
+ Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
|
|
196
|
+ Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
|
|
197
|
+ Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
|
|
198
|
+ db = db.Where("xt_schedule.status = 1 AND id in (?)", schIDs)
|
|
199
|
+ err = db.Order("schedule_date desc").Find(&schedules).Error
|
|
200
|
+ return schedules, err
|
|
201
|
+}
|
|
202
|
+
|
|
203
|
+func GetAnticoagulantCount(startime int64, endtime int64, orgid int64) (prescriptionCount []*models.DialysisPrescriptionCount, err error) {
|
|
204
|
+
|
|
205
|
+ db := XTReadDB().Table("xt_dialysis_prescription as x").Where("x.status = 1")
|
|
206
|
+ if orgid > 0 {
|
|
207
|
+ db = db.Where("x.user_org_id = ?", orgid)
|
|
208
|
+ }
|
|
209
|
+ if startime > 0 {
|
|
210
|
+ db = db.Where("x.record_date >= ?", startime)
|
|
211
|
+ }
|
|
212
|
+ if endtime > 0 {
|
|
213
|
+ db = db.Where("x.record_date<=?", endtime)
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ err = db.Select("x.patient_id,x.anticoagulant,x.record_date,count(id) as count").Group("x.anticoagulant").Scan(&prescriptionCount).Error
|
|
217
|
+ return prescriptionCount, err
|
|
218
|
+}
|
|
219
|
+
|
|
220
|
+func GetDialysisTodaySchedulePatient(orgid int64, startime int64, page int64, limit int64) (schedule []*models.XtSchedule, err error) {
|
|
221
|
+ offset := (page - 1) * limit
|
|
222
|
+ err = XTReadDB().Model(&schedule).Where("user_org_id = ? and schedule_date = ? and status = 1", orgid, startime).Offset(offset).Limit(limit).Find(&schedule).Error
|
|
223
|
+ return schedule, err
|
|
224
|
+}
|
|
225
|
+
|
|
226
|
+func GetToDayDialysisPrescription(patientid int64, orgid int64, startime int64) (*models.XtDialysisPrescription, error) {
|
|
227
|
+ prescription := models.XtDialysisPrescription{}
|
|
228
|
+ err := XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, startime).Find(&prescription).Error
|
|
229
|
+ if err == gorm.ErrRecordNotFound {
|
|
230
|
+ return nil, err
|
|
231
|
+ }
|
|
232
|
+ if err != nil {
|
|
233
|
+ return nil, err
|
|
234
|
+ }
|
|
235
|
+ return &prescription, nil
|
|
236
|
+
|
|
237
|
+}
|
|
238
|
+
|
|
239
|
+func GetLastDialysisPrescription(patientid int64, orgid int64) (models.XtDialysisPrescription, error) {
|
|
240
|
+
|
|
241
|
+ prescription := models.XtDialysisPrescription{}
|
|
242
|
+ err = XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Last(&prescription).Error
|
|
243
|
+ return prescription, err
|
|
244
|
+}
|
|
245
|
+
|
|
246
|
+func GetLastAssessmentBeforDialysis(patientid int64, orgid int64) (models.PredialysisEvaluation, error) {
|
|
247
|
+
|
|
248
|
+ evaluation := models.PredialysisEvaluation{}
|
|
249
|
+ err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Last(&evaluation).Error
|
|
250
|
+ return evaluation, err
|
|
251
|
+}
|
|
252
|
+
|
|
253
|
+func GetDialysisPrescriptionList(patientid int64, orgid int64, startime int64) (models.XtDialysisPrescription, error) {
|
|
254
|
+ prescription := models.XtDialysisPrescription{}
|
|
255
|
+ err := XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientid, orgid, startime).Find(&prescription).Error
|
|
256
|
+ return prescription, err
|
|
257
|
+}
|
|
258
|
+
|
|
259
|
+func GetTodayAssessmentBeforDialysis(patientid int64, orgid int64, startime int64) (*models.PredialysisEvaluation, error) {
|
|
260
|
+
|
|
261
|
+ evaluation := models.PredialysisEvaluation{}
|
|
262
|
+ err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and assessment_date = ? and status = 1", patientid, orgid, startime).Find(&evaluation).Error
|
|
263
|
+ if err == gorm.ErrRecordNotFound {
|
|
264
|
+ return nil, err
|
|
265
|
+ }
|
|
266
|
+ if err != nil {
|
|
267
|
+ return nil, err
|
|
268
|
+ }
|
|
269
|
+ return &evaluation, nil
|
|
270
|
+}
|
|
271
|
+
|
|
272
|
+func GetAssessmentBeforDialysisByStartime(patientid int64, orgid int64, startime int64) (models.PredialysisEvaluation, error) {
|
|
273
|
+ evaluation := models.PredialysisEvaluation{}
|
|
274
|
+ err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and assessment_date = ? and status = 1", patientid, orgid, startime).Find(&evaluation).Error
|
|
275
|
+ return evaluation, err
|
|
276
|
+}
|