XMLWAN 4 years ago
parent
commit
bd04041cfc

+ 171 - 21
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -70,25 +70,33 @@ func (this *CommonApiController) SaveConfiguration() {
70 70
 	sort := dataBody["sort"].(string)
71 71
 	sorts, err := strconv.ParseInt(sort, 10, 64)
72 72
 	fmt.Println("sort", sort)
73
-	standard := models.XtQualityControlStandard{
74
-		InspectionMajor: inspectionmajor,
75
-		InspectionMinor: inspectionMinor,
76
-		MinRange:        minrange,
77
-		LargeRange:      largerange,
78
-		Sort:            sorts,
79
-		UserOrgId:       orgid,
80
-		Status:          1,
81
-		CreatedTime:     time.Now().Unix(),
82
-	}
83
-	fmt.Println(standard)
84
-	err = service.SaveInspection(&standard)
85
-	if err != nil {
86
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
73
+
74
+	_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
75
+	if errcode == gorm.ErrRecordNotFound {
76
+		standard := models.XtQualityControlStandard{
77
+			InspectionMajor: inspectionmajor,
78
+			InspectionMinor: inspectionMinor,
79
+			MinRange:        minrange,
80
+			LargeRange:      largerange,
81
+			Sort:            sorts,
82
+			UserOrgId:       orgid,
83
+			Status:          1,
84
+			CreatedTime:     time.Now().Unix(),
85
+		}
86
+		fmt.Println(standard)
87
+		err = service.SaveInspection(&standard)
88
+		if err != nil {
89
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
90
+			return
91
+		}
92
+		this.ServeSuccessJSON(map[string]interface{}{
93
+			"standard": standard,
94
+		})
95
+	} else if errcode == nil {
96
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
87 97
 		return
88 98
 	}
89
-	this.ServeSuccessJSON(map[string]interface{}{
90
-		"standard": standard,
91
-	})
99
+
92 100
 }
93 101
 
94 102
 func (this *CommonApiController) GetConfigurationlist() {
@@ -147,7 +155,15 @@ func (this *CommonApiController) UpdateConfiguration() {
147 155
 	largerange := dataBody["large_range"].(string)
148 156
 	fmt.Println("largerange", largerange)
149 157
 	sort := int64(dataBody["sort"].(float64))
150
-
158
+	fmt.Println("排序", sort)
159
+	adminInfo := this.GetAdminUserInfo()
160
+	orgId := adminInfo.CurrentOrgId
161
+	configuration, err := service.GetConfigurationByIdTwo(inspectionmajor, inspectionMinor, orgId)
162
+	fmt.Println("err", err)
163
+	if configuration.ID > 0 && configuration.ID != id {
164
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
165
+		return
166
+	}
151 167
 	standard := models.XtQualityControlStandard{
152 168
 		InspectionMajor: inspectionmajor,
153 169
 		InspectionMinor: inspectionMinor,
@@ -219,7 +235,7 @@ func (this *CommonApiController) SaveCheckConfiguration() {
219 235
 	sort := dataBody["sort"].(string)
220 236
 	sorts, err := strconv.ParseInt(sort, 10, 64)
221 237
 	fmt.Println("sort", sort)
222
-	_, errcode := service.GetInspectionMajorById(inspectionmajor)
238
+	_, errcode := service.GetInspectionMajorById(inspectionmajor, orgid)
223 239
 	if errcode == gorm.ErrRecordNotFound {
224 240
 		configuration := models.XtCheckConfiguration{
225 241
 			InspectionMajor:     inspectionmajor,
@@ -285,8 +301,9 @@ func (this *CommonApiController) UpdateCheck() {
285 301
 	fmt.Println("凭次", frequency)
286 302
 	sort := int64(dataBody["sort"].(float64))
287 303
 	fmt.Println("sort", sort)
288
-
289
-	Inspection, err := service.GetInspectionMajorById(inspectionmajor)
304
+	adminInfo := this.GetAdminUserInfo()
305
+	orgId := adminInfo.CurrentOrgId
306
+	Inspection, err := service.GetInspectionMajorByIdTwo(inspectionmajor, orgId)
290 307
 	if Inspection.ID > 0 && Inspection.ID != id {
291 308
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
292 309
 		return
@@ -320,3 +337,136 @@ func (this *CommonApiController) DeleteCheck() {
320 337
 	this.ServeSuccessJSON(returnData)
321 338
 	return
322 339
 }
340
+
341
+func (this *CommonApiController) GetDialysisModeType() {
342
+	timeLayout := "2006-01-02"
343
+	loc, _ := time.LoadLocation("Local")
344
+	startime := this.GetString("startime")
345
+	endtime := this.GetString("endtime")
346
+	fmt.Println("endtime", endtime)
347
+	startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
348
+	startimes := startTimes.Unix()
349
+	// fmt.Println("startime",startimes)
350
+	endtimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
351
+	endtimeData := endtimes.Unix()
352
+	// fmt.Println("结束日期",endtimeData)
353
+	adminUser := this.GetAdminUserInfo()
354
+	orgid := adminUser.CurrentOrgId
355
+	//统计透析总量
356
+	_, total, _ := service.GetDialysiTotal(startimes, endtimeData, orgid)
357
+
358
+	modeType, err := service.GetDialysisCountMode(startimes, endtimeData, orgid)
359
+	if err != nil {
360
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
361
+		return
362
+	}
363
+	this.ServeSuccessJSON(map[string]interface{}{
364
+		"total":    total,
365
+		"modetype": modeType,
366
+	})
367
+}
368
+
369
+func (this *CommonApiController) GetTotalLapseCount() {
370
+	adminUser := this.GetAdminUserInfo()
371
+	orgid := adminUser.CurrentOrgId
372
+	startime, _ := this.GetInt64("startime")
373
+	fmt.Println("startime--", startime)
374
+	endtime, _ := this.GetInt64("endtime")
375
+	fmt.Println("endtime--", endtime)
376
+
377
+	//统计一个月内转出的病人
378
+	patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
379
+	//统计总共病人
380
+	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
381
+	if err != nil {
382
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
383
+		return
384
+	}
385
+	this.ServeSuccessJSON(map[string]interface{}{
386
+		"patients": patients,
387
+		"total":    total,
388
+		"count":    count,
389
+	})
390
+}
391
+
392
+func (this *CommonApiController) GetTotalSexCount() {
393
+	adminUser := this.GetAdminUserInfo()
394
+	orgid := adminUser.CurrentOrgId
395
+	fmt.Println("orgid", orgid)
396
+	startime, _ := this.GetInt64("startime")
397
+	fmt.Println("开始时间", startime)
398
+	endtime, _ := this.GetInt64("endtime")
399
+	fmt.Println("结束时间", endtime)
400
+	//统计这个月透析病人的总数
401
+	_, total, err := service.GetPatientTotalCountTwo(orgid, startime, endtime)
402
+	//统计改月男病人的总数
403
+	_, totalSex, err := service.GetManPatientTotalCount(orgid, startime, endtime)
404
+
405
+	if err != nil {
406
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
407
+		return
408
+	}
409
+	this.ServeSuccessJSON(map[string]interface{}{
410
+		"total":    total,
411
+		"totalSex": totalSex,
412
+	})
413
+}
414
+
415
+func (this *CommonApiController) GetTotalInfectiouscount() {
416
+	adminUser := this.GetAdminUserInfo()
417
+	orgid := adminUser.CurrentOrgId
418
+	fmt.Println("orgid", orgid)
419
+	startime, _ := this.GetInt64("startime")
420
+	fmt.Println("开始时间", startime)
421
+	endtime, _ := this.GetInt64("endtime")
422
+	fmt.Println("结束时间", endtime)
423
+	//统计本月透析总人数
424
+	_, total, err := service.GetPatientTotalCountTwo(orgid, startime, endtime)
425
+	fmt.Println("err--", err)
426
+	fmt.Println("total", total)
427
+	//统计本月透析人数传染病所占比例
428
+	count, err := service.GetPatientInfectiousCount(orgid, startime, endtime)
429
+	fmt.Println("报错-------------", count)
430
+	if err != nil {
431
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
432
+		return
433
+	}
434
+	this.ServeSuccessJSON(map[string]interface{}{
435
+		"total": total,
436
+		"count": count,
437
+	})
438
+}
439
+
440
+func (this *CommonApiController) GetTotalAgeCount() {
441
+	adminUser := this.GetAdminUserInfo()
442
+	orgid := adminUser.CurrentOrgId
443
+	fmt.Println("orgid", orgid)
444
+	startime, _ := this.GetInt64("startime")
445
+	fmt.Println("开始时间", startime)
446
+	endtime, _ := this.GetInt64("endtime")
447
+	fmt.Println("结束时间", endtime)
448
+	//统计本月透析总人数
449
+	_, total, err := service.GetPatientTotalCountTwo(orgid, startime, endtime)
450
+	fmt.Println("err--", err)
451
+	fmt.Println("total", total)
452
+	agecount, err := service.GetTotalAgeCount(orgid, startime, endtime)
453
+	//two, err := service.GetTotalAgeCountTwo(orgid, startime, endtime)
454
+	if err != nil {
455
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
456
+		return
457
+	}
458
+	this.ServeSuccessJSON(map[string]interface{}{
459
+		"total":    total,
460
+		"ageCount": agecount,
461
+	})
462
+}
463
+
464
+func (this *CommonApiController) GetTotalDialysisCount() {
465
+	adminUser := this.GetAdminUserInfo()
466
+	orgid := adminUser.CurrentOrgId
467
+	fmt.Println("org", orgid)
468
+	startime, _ := this.GetInt64("startime")
469
+	fmt.Println(startime)
470
+	endtime, _ := this.GetInt64("endtime")
471
+	fmt.Println(endtime)
472
+}

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

@@ -21,4 +21,10 @@ func CommonApiControllersRegisterRouters() {
21 21
 	beego.Router("/com/api/getcheckdetail", &CommonApiController{}, "Get:GetCheckdetail")
22 22
 	beego.Router("/com/api/updatecheck", &CommonApiController{}, "Post:UpdateCheck")
23 23
 	beego.Router("/com/api/deletecheck", &CommonApiController{}, "Delete:DeleteCheck")
24
+	beego.Router("/com/api/getdialysismodetype", &CommonApiController{}, "Get:GetDialysisModeType")
25
+	beego.Router("/com/api/gettotallapsecount", &CommonApiController{}, "Get:GetTotalLapseCount")
26
+	beego.Router("/com/api/gettotalsexcount", &CommonApiController{}, "Get:GetTotalSexCount")
27
+	beego.Router("/com/api/gettoalinfectiouscount", &CommonApiController{}, "Get:GetTotalInfectiouscount")
28
+	beego.Router("/com/api/gettotalagecount", &CommonApiController{}, "Get:GetTotalAgeCount")
29
+	beego.Router("/com/api/gettotaldialysiscount", &CommonApiController{}, "Get:GetTotalDialysisCount")
24 30
 }

+ 50 - 0
models/common_models.go View File

@@ -59,3 +59,53 @@ type XtCheckConfiguration struct {
59 59
 func (XtCheckConfiguration) TableName() string {
60 60
 	return "xt_check_configuration"
61 61
 }
62
+
63
+type PatientPrescriptionCountStruct struct {
64
+	ModeId int64 `json:"mode_id"`
65
+	Count  int64 `json:"count"`
66
+}
67
+
68
+type PatientLapsetoCountStruct struct {
69
+	lapseto_type int64 `json:"lapseto_type"`
70
+	Count        int64 `json:"count"`
71
+}
72
+
73
+type SgjDialysisOrder struct {
74
+	ID             int64  `gorm:"column:id" json:"id" form:"id"`
75
+	DialysisDate   int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
76
+	UserOrgId      int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
77
+	PatientId      int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
78
+	PrescriptionId int64  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
79
+	Stage          int64  `gorm:"column:stage" json:"stage" form:"stage"`
80
+	Remark         string `gorm:"column:remark" json:"remark" form:"remark"`
81
+	BedId          int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
82
+	StartNurse     int64  `gorm:"column:start_nurse" json:"start_nurse" form:"start_nurse"`
83
+	FinishNurse    int64  `gorm:"column:finish_nurse" json:"finish_nurse" form:"finish_nurse"`
84
+	Status         int64  `gorm:"column:status" json:"status" form:"status"`
85
+	CreatedTime    int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
86
+	UpdatedTime    int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
87
+	StartTime      int64  `gorm:"column:start_time" json:"start_time" form:"start_time"`
88
+	EndTime        int64  `gorm:"column:end_time" json:"end_time" form:"end_time"`
89
+	PunctureNurse  int64  `gorm:"column:puncture_nurse" json:"puncture_nurse" form:"puncture_nurse"`
90
+	Creator        int64  `gorm:"column:creator" json:"creator" form:"creator"`
91
+	Modifier       int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
92
+	FinishCreator  int64  `gorm:"column:finish_creator" json:"finish_creator" form:"finish_creator"`
93
+	FinishModifier int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
94
+	SchedualType   int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
95
+	Number         int64  `gorm:"column:number" json:"number" form:"number"`
96
+	UserName       int64  `gorm:"column:user_name" json:"user_name" form:"user_name"`
97
+}
98
+
99
+func (SgjDialysisOrder) TableName() string {
100
+	return "xt_dialysis_order"
101
+}
102
+
103
+type PatientContagionsCountStruct struct {
104
+	DiseaseId int64 `json:"disease_id"`
105
+	Count     int64 `json:"count"`
106
+}
107
+
108
+type PatientAgeCountStruct struct {
109
+	Age   int64 `json:"age"`
110
+	Count int64 `json:"count"`
111
+}

+ 99 - 2
service/common_service.go View File

@@ -25,6 +25,24 @@ func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
25 25
 	return reference, err
26 26
 }
27 27
 
28
+func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
29
+	standard := models.XtQualityControlStandard{}
30
+	err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
31
+	if err == gorm.ErrRecordNotFound {
32
+		return nil, err
33
+	}
34
+	if err != nil {
35
+		return nil, err
36
+	}
37
+	return &standard, nil
38
+}
39
+
40
+func GetConfigurationByIdTwo(major int64, moni int64, orgid int64) (standard models.XtQualityControlStandard, err error) {
41
+
42
+	err = XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).First(&standard).Error
43
+	return standard, err
44
+}
45
+
28 46
 func SaveInspection(standard *models.XtQualityControlStandard) error {
29 47
 
30 48
 	err := XTWriteDB().Create(&standard).Error
@@ -87,9 +105,9 @@ func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionRefer
87 105
 	return reference, err
88 106
 }
89 107
 
90
-func GetInspectionMajorById(marjor int64) (*models.XtCheckConfiguration, error) {
108
+func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
91 109
 	configuration := models.XtCheckConfiguration{}
92
-	err := XTReadDB().Model(&configuration).Where("inspection_major = ? and status =1", marjor).Find(&configuration).Error
110
+	err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
93 111
 	if err == gorm.ErrRecordNotFound {
94 112
 		return nil, err
95 113
 	}
@@ -99,6 +117,11 @@ func GetInspectionMajorById(marjor int64) (*models.XtCheckConfiguration, error)
99 117
 	return &configuration, nil
100 118
 }
101 119
 
120
+func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
121
+	err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
122
+	return configuration, err
123
+}
124
+
102 125
 func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
103 126
 	err := XTWriteDB().Create(&configuration).Error
104 127
 	return err
@@ -136,3 +159,77 @@ func DeleteCheck(id int64) error {
136 159
 	err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
137 160
 	return err
138 161
 }
162
+
163
+func GetDialysiTotal(startime int64, endtime int64, orgid int64) (prescription []*models.DialysisPrescription, total int64, err error) {
164
+	err = XTReadDB().Model(&prescription).Where("record_date >= ? and record_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&prescription).Error
165
+	return prescription, total, err
166
+}
167
+
168
+func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
169
+	err = readDb.Table("xt_dialysis_prescription as p").Where("p.record_date>= ? and p.record_date<=? and p.user_org_id=?", starttime, endtime, orgid).Select("p.mode_id,count(p.mode_id) as count").Group("p.mode_id").Scan(&counts).Error
170
+	return counts, err
171
+}
172
+
173
+func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
174
+
175
+	db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
176
+	table := readDb.Table("xt_dialysis_order as s")
177
+	fmt.Println(table)
178
+	err = db.Select("x.patient_id,x.lapseto_type").Joins("left join xt_dialysis_order as s on s.patient_id = x.patient_id").Where("x.lapseto_time >=? and x.lapseto_time <= ? and x.lapseto_type = 2 and s.user_org_id = ?", starttime, endtime, orgid).Group("x.patient_id").Count(&total).Scan(&counts).Error
179
+	return counts, total, err
180
+}
181
+
182
+func GetPatientTotalCount(orgID int64) (total int64) {
183
+	readDb.Model(&models.XtPatients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
184
+	return
185
+}
186
+
187
+func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
188
+
189
+	err = XTReadDB().Model(&dialysisorder).Group("patient_id").Where("user_org_id = ? and dialysis_date >= ? and dialysis_date <=? and status =1", orgid, starttime, endtime).Count(&total).Find(&dialysisorder).Error
190
+	return dialysisorder, total, err
191
+}
192
+
193
+func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
194
+
195
+	db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
196
+	table := XTReadDB().Table("xt_patients as x")
197
+	fmt.Println("table", table)
198
+	err = db.Select("s.dialysis_date,s.prescription_id").Joins("left join xt_patients as x on x.id = s.patient_id").Where("s.dialysis_date>=? and s.dialysis_date<=? and s.user_org_id = ? and s.status = 1 and x.gender = 1", starttime, endtime, orgid).Group("s.patient_id").Count(&total).Scan(&dialysisorder).Error
199
+	return dialysisorder, total, err
200
+
201
+}
202
+
203
+func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
204
+	err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_dialysis_order as o on o.patient_id = x.patient_id").Joins("join xt_patients as s on s.id = x.patient_id").Where("o.user_org_id = ? and o.status =1 and o.dialysis_date>=? and o.dialysis_date <=? and x.status =1 and s.is_infectious = 2", orgid, starttime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
205
+	return counts, err
206
+}
207
+
208
+func GetTotalAgeCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
209
+
210
+	readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
211
+	 SELECT
212
+	 CASE
213
+	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=20 THEN '20'
214
+	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>20 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=40 THEN '40'
215
+	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>40 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=60 THEN '60'
216
+	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>60 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=80 THEN '80'
217
+	  WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>80 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + ( FROM_UNIXTIME(birthday, '%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<=150 THEN '150'
218
+	  ELSE '-1'
219
+	 END
220
+	 AS nnd FROM xt_patients as s  left join xt_dialysis_order as o on o.patient_id = s.id where s.user_org_id=? and s.status=1 and o.dialysis_date>= ? and o.dialysis_date<=?
221
+	 )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
222
+	return
223
+
224
+}
225
+
226
+func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
227
+	readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
228
+	 SELECT
229
+	 CASE
230
+	    when (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')>0) and  (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')<20) THEN '20'
231
+	   END
232
+       AS nnd FROM xt_patients as s  left join xt_dialysis_order as o on o.patient_id = s.id where s.user_org_id=? and s.status=1 and o.dialysis_date>= ? and o.dialysis_date<=?
233
+       )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
234
+	return
235
+}