XMLWAN 4 years ago
parent
commit
991764c549

+ 33 - 0
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -636,3 +636,36 @@ func (this *CommonApiController) GetPrescritionByName() {
636 636
 		"total":   total,
637 637
 	})
638 638
 }
639
+
640
+func (this *CommonApiController) GetStatistics() {
641
+	adminUser := this.GetAdminUserInfo()
642
+	orgId := adminUser.CurrentOrgId
643
+	fmt.Println("orgid", orgId)
644
+	startime := this.GetString("start_time")
645
+	fmt.Println(startime)
646
+	endtime := this.GetString("end_time")
647
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
648
+	fmt.Println("parseDateErr", parseDateErr)
649
+	statime := startDate.Unix()
650
+	fmt.Println("开始时间", statime)
651
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
652
+	entime := endDate.Unix()
653
+	fmt.Println("结束日期", entime)
654
+	value, _ := this.GetInt64("value")
655
+	fmt.Println("value", value)
656
+	limit, _ := this.GetInt64("limit")
657
+	fmt.Println("limit", limit)
658
+	page, _ := this.GetInt64("page")
659
+	fmt.Println("page", page)
660
+	modeId, _ := this.GetInt64("mode_id")
661
+	statistics, ttd, total, err := service.GetStatistics(orgId, statime, entime, value, limit, page, modeId)
662
+	if err != nil {
663
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
664
+		return
665
+	}
666
+	this.ServeSuccessJSON(map[string]interface{}{
667
+		"statistics": statistics,
668
+		"ttd":        ttd,
669
+		"total":      total,
670
+	})
671
+}

+ 1 - 0
controllers/new_mobile_api_controllers/common_api_router.go View File

@@ -33,4 +33,5 @@ func CommonApiControllersRegisterRouters() {
33 33
 	beego.Router("/com/api/getlastchecklist", &CommonApiController{}, "Get:GetLastCheckList")
34 34
 	beego.Router("/com/api/getdialysisdetailbyid", &CommonApiController{}, "Get:GetDialysisDetailById")
35 35
 	beego.Router("/com/api/getprescriptionbyname", &CommonApiController{}, "Get:GetPrescritionByName")
36
+	beego.Router("/com/api/getstatistics", &CommonApiController{}, "Get:GetStatistics")
36 37
 }

+ 33 - 0
controllers/new_mobile_api_controllers/new_common_api_controller.go View File

@@ -262,3 +262,36 @@ func (this *NewCommonApiController) ToSearchPatient() {
262 262
 		"total":   total,
263 263
 	})
264 264
 }
265
+
266
+func (this *NewCommonApiController) GetAllPatientsMode() {
267
+	adminUser := this.GetMobileAdminUserInfo()
268
+	orgId := adminUser.Org.Id
269
+	startime := this.GetString("startime")
270
+	fmt.Println(startime)
271
+	endtime := this.GetString("endtime")
272
+	startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
273
+	fmt.Println("parseDateErr", parseDateErr)
274
+	statime := startDate.Unix()
275
+	fmt.Println("开始时间", statime)
276
+	endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
277
+	entime := endDate.Unix()
278
+	fmt.Println("结束日期", entime)
279
+	value, _ := this.GetInt64("value")
280
+	fmt.Println("value", value)
281
+	limit, _ := this.GetInt64("limit")
282
+	fmt.Println("limit", limit)
283
+	page, _ := this.GetInt64("page")
284
+	fmt.Println("page", page)
285
+	modeId, _ := this.GetInt64("mode_id")
286
+	fmt.Println("modeId", modeId)
287
+	statistics, ttd, total, err := service.GetStatistics(orgId, statime, entime, value, limit, page, modeId)
288
+	if err != nil {
289
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
290
+		return
291
+	}
292
+	this.ServeSuccessJSON(map[string]interface{}{
293
+		"statistics": statistics,
294
+		"ttd":        ttd,
295
+		"total":      total,
296
+	})
297
+}

+ 1 - 0
controllers/new_mobile_api_controllers/new_common_api_router.go View File

@@ -14,4 +14,5 @@ func NewCommonApiControllersRegisterRouters() {
14 14
 	beego.Router("/m/api/getprescriptionlist", &NewCommonApiController{}, "Get:GetPrescriptionlist")
15 15
 	beego.Router("/m/api/getmobilepatientdetail", &NewCommonApiController{}, "Get:GetMobilePatientDetail")
16 16
 	beego.Router("/m/api/tosearchpatient", &NewCommonApiController{}, "Get:ToSearchPatient")
17
+	beego.Router("/m/api/getallpatientsmode", &NewCommonApiController{}, "Get:GetAllPatientsMode")
17 18
 }

+ 6 - 0
models/common_models.go View File

@@ -283,3 +283,9 @@ type BloodDialysisPrescription struct {
283 283
 func (BloodDialysisPrescription) TableName() string {
284 284
 	return "xt_dialysis_prescription"
285 285
 }
286
+
287
+type DialysisTotalDataStruct struct {
288
+	Date   string `json:"date"`
289
+	Number string `json:"number"`
290
+	ModeID string `json:"mode_id"`
291
+}

+ 59 - 0
service/common_service.go View File

@@ -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
+}