|
@@ -213,38 +213,28 @@ func DeleteCheck(id int64) error {
|
213
|
213
|
func GetDialysiTotal(startime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (models.PatientPrescriptionCountStruct, error) {
|
214
|
214
|
counts := models.PatientPrescriptionCountStruct{}
|
215
|
215
|
|
216
|
|
- db := XTReadDB().Table("xt_dialysis_order as x").Where("x.status = 1")
|
217
|
|
- table := XTReadDB().Table("xt_paitents as s").Where("s.status = 1")
|
218
|
|
- fmt.Println(table)
|
|
216
|
+ db := XTReadDB().Table("xt_dialysis_order as x").Select("count(x.id) as count").Joins("Join xt_dialysis_prescription as prescription On x.dialysis_date = prescription.record_date AND x.patient_id = prescription.patient_id AND prescription.status = 1 AND prescription.mode_id > 0").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? AND x.status = 1", startime, endtime, orgid)
|
219
|
217
|
|
220
|
218
|
if lapsetotype > 0 {
|
221
|
|
- err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? and s.lapseto = ?", startime, endtime, orgid, lapsetotype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
219
|
+ err = db.Where("x.user_org_id = ? and s.lapseto = ?", startime, endtime, orgid, lapsetotype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
222
|
220
|
}
|
223
|
221
|
if lapsetotype == 0 {
|
224
|
|
- err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? ", startime, endtime, orgid).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
222
|
+ err = db.Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
225
|
223
|
}
|
226
|
224
|
|
227
|
225
|
if sourcetype > 0 {
|
228
|
|
- err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? and s.source = ?", startime, endtime, orgid, sourcetype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
226
|
+ err = db.Where("x.user_org_id = ? and s.source = ?", startime, endtime, orgid, sourcetype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
229
|
227
|
}
|
230
|
228
|
|
231
|
229
|
if sourcetype == 0 {
|
232
|
|
- err = db.Select("count(x.id) as count").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ?", startime, endtime, orgid).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
|
230
|
+ err = db.Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
|
233
|
231
|
}
|
234
|
232
|
|
235
|
233
|
return counts, err
|
236
|
234
|
}
|
237
|
235
|
|
238
|
236
|
func GetDialysisCountMode(starttime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
|
239
|
|
-
|
240
|
|
- //err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
|
241
|
|
- //return counts, err
|
242
|
|
-
|
243
|
237
|
db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
|
244
|
|
- table := readDb.Table("xt_schedule as s").Where("s.status = 1")
|
245
|
|
- fmt.Println(table)
|
246
|
|
- p := readDb.Table("xt_patients as p").Where("p.status = 1")
|
247
|
|
- fmt.Println(p)
|
248
|
238
|
if starttime > 0 {
|
249
|
239
|
db = db.Where("o.dialysis_date >=?", starttime)
|
250
|
240
|
}
|
|
@@ -260,7 +250,7 @@ func GetDialysisCountMode(starttime int64, endtime int64, orgid int64, lapsetoty
|
260
|
250
|
if sourcetype > 0 {
|
261
|
251
|
db = db.Where("p.source = ?", sourcetype)
|
262
|
252
|
}
|
263
|
|
- err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id and s.schedule_date = o.dialysis_date and s.status= 1").Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
|
|
253
|
+ err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.status= 1 AND s.record_date >= ? AND s.record_date <= ? AND AND s.mode_id > 0 ", starttime, endtime).Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
|
264
|
254
|
return counts, err
|
265
|
255
|
}
|
266
|
256
|
|
|
@@ -287,13 +277,14 @@ func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64, lapseto
|
287
|
277
|
}
|
288
|
278
|
|
289
|
279
|
func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
|
290
|
|
-
|
291
|
280
|
db := XTReadDB().Table("xt_patients as x")
|
292
|
281
|
if sourcetype == 0 {
|
|
282
|
+
|
293
|
283
|
err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
|
294
|
284
|
|
295
|
285
|
}
|
296
|
286
|
if sourcetype > 0 {
|
|
287
|
+
|
297
|
288
|
err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
|
298
|
289
|
}
|
299
|
290
|
return patients, err
|
|
@@ -629,10 +620,6 @@ func GetPrescritionByName(orgid int64, patient_id int64, startime int64, endtime
|
629
|
620
|
func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64) (blood []*models.TreatDialysisOrder, total int64, err error) {
|
630
|
621
|
|
631
|
622
|
db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
|
632
|
|
- table := XTReadDB().Table("xt_schedule as s")
|
633
|
|
- fmt.Println(table)
|
634
|
|
- p := XTReadDB().Table("xt_patients as p")
|
635
|
|
- fmt.Println(p)
|
636
|
623
|
sql := "from_unixtime(o.dialysis_date, '%Y%m%d') AS date"
|
637
|
624
|
|
638
|
625
|
if orgID > 0 {
|
|
@@ -651,7 +638,7 @@ func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, li
|
651
|
638
|
db = db.Where("p.lapseto = ?", lapseto)
|
652
|
639
|
}
|
653
|
640
|
offset := (page - 1) * limit
|
654
|
|
- err = db.Group("o.dialysis_date").Select(sql).Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1").Count(&total).Offset(offset).Limit(limit).Scan(&blood).Error
|
|
641
|
+ err = db.Group("o.dialysis_date").Select(sql).Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.record_date = o.dialysis_date and s.status =1").Count(&total).Offset(offset).Limit(limit).Scan(&blood).Error
|
655
|
642
|
return blood, total, err
|
656
|
643
|
|
657
|
644
|
}
|
|
@@ -676,7 +663,7 @@ func GetTreatList(orgid int64, startime int64, endtime int64, lapseto int64) (tt
|
676
|
663
|
if lapseto > 0 {
|
677
|
664
|
db = db.Where("p.lapseto = ?", lapseto)
|
678
|
665
|
}
|
679
|
|
- err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
|
|
666
|
+ err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.record_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
|
680
|
667
|
return ttd, err
|
681
|
668
|
}
|
682
|
669
|
|
|
@@ -685,7 +672,7 @@ func GetStatistics(orgID int64, startime int64, endtime int64, modeID int64) (dt
|
685
|
672
|
sql := "s.mode_id,from_unixtime(o.dialysis_date, '%Y%m%d') as date, count(o.dialysis_date) as number"
|
686
|
673
|
datesql := " o.dialysis_date as date"
|
687
|
674
|
group := "from_unixtime(o.dialysis_date, '%Y%m%d')"
|
688
|
|
- db = db.Table(" xt_dialysis_order AS o").Joins("left join xt_schedule as s on o.patient_id = s.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1")
|
|
675
|
+ db = db.Table(" xt_dialysis_order AS o").Joins("join xt_dialysis_prescription as s on o.patient_id = s.patient_id").Where("s.record_date = o.dialysis_date and s.status =1")
|
689
|
676
|
if orgID > 0 {
|
690
|
677
|
db = db.Where("o.user_org_id = ?", orgID)
|
691
|
678
|
}
|