|
@@ -431,3 +431,62 @@ func GetPrescritionByName(orgid int64, keywords string, startime int64, endtime
|
431
|
431
|
err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
|
432
|
432
|
return prescription, total, err
|
433
|
433
|
}
|
|
434
|
+
|
|
435
|
+func GetStatistics(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, total int64, err error) {
|
|
436
|
+ db := readDb
|
|
437
|
+ sql := "s.mode_id,from_unixtime(s.record_date, '%Y%m%d') as date, count(s.record_date) as number"
|
|
438
|
+ datesql := "s.record_date as date"
|
|
439
|
+ group := "from_unixtime(s.record_date, '%Y%m%d')"
|
|
440
|
+ db = db.Table("xt_dialysis_prescription as s")
|
|
441
|
+ if orgID > 0 {
|
|
442
|
+ db = db.Where("s.user_org_id = ?", orgID)
|
|
443
|
+ }
|
|
444
|
+ if modeID > 0 {
|
|
445
|
+ db = db.Where("s.mode_id=?", modeID)
|
|
446
|
+ }
|
|
447
|
+ if startime > 0 {
|
|
448
|
+ db = db.Where("s.record_date>=?", startime)
|
|
449
|
+ }
|
|
450
|
+ if endtime > 0 {
|
|
451
|
+ db = db.Where("s.record_date<=?", endtime)
|
|
452
|
+ }
|
|
453
|
+ db = db.Where("s.status=1")
|
|
454
|
+
|
|
455
|
+ if lapseto > 0 {
|
|
456
|
+ joinString := "JOIN xt_patients as p ON s.patient_id=p.id and p.lapseto=? and p.status=1"
|
|
457
|
+ joinParams := make([]interface{}, 0)
|
|
458
|
+ joinParams = append(joinParams, lapseto)
|
|
459
|
+ if orgID > 0 {
|
|
460
|
+ joinString += "AND p.user_org_id=?"
|
|
461
|
+ joinParams = append(joinParams, orgID)
|
|
462
|
+ }
|
|
463
|
+
|
|
464
|
+ db = db.Joins(joinString, joinParams...)
|
|
465
|
+ }
|
|
466
|
+
|
|
467
|
+ err = db.Select("s.mode_id, count(s.mode_id) as number").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
|
|
468
|
+ if err != nil {
|
|
469
|
+ return
|
|
470
|
+ }
|
|
471
|
+
|
|
472
|
+ offset := (page - 1) * limit
|
|
473
|
+
|
|
474
|
+ var ds []*DialysisTotalDataStruct
|
|
475
|
+ err = db.Select(datesql).Group(group).Count(&total).Order("date asc").Offset(offset).Limit(limit).Find(&ds).Error
|
|
476
|
+ if err != nil {
|
|
477
|
+ return
|
|
478
|
+ }
|
|
479
|
+
|
|
480
|
+ dates := make([]string, 0)
|
|
481
|
+ if len(ds) > 0 {
|
|
482
|
+ for _, d := range ds {
|
|
483
|
+ dates = append(dates, d.Date)
|
|
484
|
+ }
|
|
485
|
+
|
|
486
|
+ db = db.Where("s.record_date IN (?)", dates)
|
|
487
|
+
|
|
488
|
+ }
|
|
489
|
+
|
|
490
|
+ err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, mode_id").Find(&dtd).Error
|
|
491
|
+ return
|
|
492
|
+}
|