Browse Source

Merge branch 'xt_statistics_branch' of http://git.shengws.com/csx/XT_New into xt_statistics_branch

csx 4 years ago
parent
commit
dd37ab86d8

+ 35 - 22
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -370,14 +370,17 @@ func (this *CommonApiController) GetTotalLapseCount() {
370 370
 	adminUser := this.GetAdminUserInfo()
371 371
 	orgid := adminUser.CurrentOrgId
372 372
 	startime, _ := this.GetInt64("startime")
373
-	fmt.Println("startime--", startime)
373
+	fmt.Println("startime", startime)
374 374
 	endtime, _ := this.GetInt64("endtime")
375
-	fmt.Println("endtime--", endtime)
375
+	fmt.Println("endtime", endtime)
376 376
 
377 377
 	//统计一个月内转出的病人
378
-	patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
378
+	//patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
379
+	//统计该机构的转出人数
380
+	patients, total, err := service.GetTotalRollOutPatients(orgid)
379 381
 	//统计总共病人
380
-	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
382
+	//	_, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
383
+	count := service.GetPatientTotalCount(orgid)
381 384
 	if err != nil {
382 385
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
383 386
 		return
@@ -397,10 +400,8 @@ func (this *CommonApiController) GetTotalSexCount() {
397 400
 	fmt.Println("开始时间", startime)
398 401
 	endtime, _ := this.GetInt64("endtime")
399 402
 	fmt.Println("结束时间", endtime)
400
-	//统计这个月透析病人的总数
401
-	_, total, err := service.GetPatientTotalCountTwo(orgid, startime, endtime)
402
-	//统计改月男病人的总数
403
-	_, totalSex, err := service.GetManPatientTotalCount(orgid, startime, endtime)
403
+	total := service.GetPatientTotalCount(orgid)
404
+	_, totalSex, err := service.GetManPatientTotal(orgid)
404 405
 
405 406
 	if err != nil {
406 407
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -420,20 +421,20 @@ func (this *CommonApiController) GetTotalInfectiouscount() {
420 421
 	fmt.Println("开始时间", startime)
421 422
 	endtime, _ := this.GetInt64("endtime")
422 423
 	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)
424
+	//统计透析总人数
425
+	total := service.GetPatientTotalCount(orgid)
426
+	//统计透析人数传染病所占比例
427
+	count, err := service.GetPatientInfectiousCount(orgid)
428
+	//统计其他
429
+	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
430 430
 	if err != nil {
431 431
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
432 432
 		return
433 433
 	}
434 434
 	this.ServeSuccessJSON(map[string]interface{}{
435
-		"total": total,
436
-		"count": count,
435
+		"total":      total,
436
+		"count":      count,
437
+		"otherTotal": otherTotal,
437 438
 	})
438 439
 }
439 440
 
@@ -445,11 +446,9 @@ func (this *CommonApiController) GetTotalAgeCount() {
445 446
 	fmt.Println("开始时间", startime)
446 447
 	endtime, _ := this.GetInt64("endtime")
447 448
 	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)
449
+	//统计透析总人数
450
+	total := service.GetPatientTotalCount(orgid)
451
+	agecount, err := service.GetTotalAgeCount(orgid)
453 452
 	//two, err := service.GetTotalAgeCountTwo(orgid, startime, endtime)
454 453
 	if err != nil {
455 454
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -469,4 +468,18 @@ func (this *CommonApiController) GetTotalDialysisCount() {
469 468
 	fmt.Println(startime)
470 469
 	endtime, _ := this.GetInt64("endtime")
471 470
 	fmt.Println(endtime)
471
+	//统计透析总人数
472
+	total := service.GetPatientTotalCount(orgid)
473
+	fmt.Println("total--------------", total)
474
+	//获取该机构下的所有病人数据
475
+	patients, err := service.GetTotalDialysisAgeCount(orgid)
476
+	fmt.Println("patients--------", patients)
477
+	if err != nil {
478
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
479
+		return
480
+	}
481
+	this.ServeSuccessJSON(map[string]interface{}{
482
+		"total":    total,
483
+		"patients": patients,
484
+	})
472 485
 }

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

@@ -0,0 +1,125 @@
1
+package new_mobile_api_controllers
2
+
3
+import (
4
+	"XT_New/controllers/mobile_api_controllers"
5
+	"XT_New/enums"
6
+	"XT_New/service"
7
+	"fmt"
8
+	"time"
9
+)
10
+
11
+type NewCommonApiController struct {
12
+	mobile_api_controllers.MobileBaseAPIAuthController
13
+}
14
+
15
+func (this *NewCommonApiController) GetTotalDialysis() {
16
+	timeLayout := "2006-01-02"
17
+	loc, _ := time.LoadLocation("Local")
18
+	startime := this.GetString("startime")
19
+	fmt.Println("开始时间", startime)
20
+	endtime := this.GetString("endtime")
21
+	fmt.Println("结束时间", endtime)
22
+	startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
23
+	startimes := startTimes.Unix()
24
+	fmt.Println("startime", startimes)
25
+	endtimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
26
+	endtimeData := endtimes.Unix()
27
+	fmt.Println("结束日期", endtimeData)
28
+	adminUser := this.GetMobileAdminUserInfo()
29
+	orgid := adminUser.Org.Id
30
+	fmt.Println("机构ID", orgid)
31
+	//统计透析总量
32
+	_, total, _ := service.GetDialysiTotal(startimes, endtimeData, orgid)
33
+
34
+	modeType, err := service.GetDialysisCountMode(startimes, endtimeData, orgid)
35
+	if err != nil {
36
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
37
+		return
38
+	}
39
+	this.ServeSuccessJSON(map[string]interface{}{
40
+		"total":    total,
41
+		"modetype": modeType,
42
+	})
43
+}
44
+
45
+func (this *NewCommonApiController) GetMobileTotalLapseCount() {
46
+	startime, _ := this.GetInt64("startime")
47
+	fmt.Println("startime", startime)
48
+	endtime, _ := this.GetInt64("endtime")
49
+	fmt.Println("endtime", endtime)
50
+	adminUser := this.GetMobileAdminUserInfo()
51
+	orgid := adminUser.Org.Id
52
+	_, total, err := service.GetTotalRollOutPatients(orgid)
53
+	count := service.GetPatientTotalCount(orgid)
54
+	if err != nil {
55
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
56
+		return
57
+	}
58
+	this.ServeSuccessJSON(map[string]interface{}{
59
+		"total": total,
60
+		"count": count,
61
+	})
62
+}
63
+
64
+func (this *NewCommonApiController) GetMobileTotalSexCount() {
65
+	startime, _ := this.GetInt64("startime")
66
+	fmt.Println("startime", startime)
67
+	endtime, _ := this.GetInt64("endtime")
68
+	fmt.Println("endtime", endtime)
69
+	adminUser := this.GetMobileAdminUserInfo()
70
+	orgid := adminUser.Org.Id
71
+	total := service.GetPatientTotalCount(orgid)
72
+	_, totalSex, err := service.GetManPatientTotal(orgid)
73
+	if err != nil {
74
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
75
+		return
76
+	}
77
+	this.ServeSuccessJSON(map[string]interface{}{
78
+		"total":    total,
79
+		"totalSex": totalSex,
80
+	})
81
+}
82
+
83
+func (this *NewCommonApiController) GetMobileTotalInfectiousCout() {
84
+	startime, _ := this.GetInt64("startime")
85
+	fmt.Println("startime", startime)
86
+	endtime, _ := this.GetInt64("endtime")
87
+	fmt.Println("endtime", endtime)
88
+	adminUser := this.GetMobileAdminUserInfo()
89
+	orgid := adminUser.Org.Id
90
+	//统计透析总人数
91
+	total := service.GetPatientTotalCount(orgid)
92
+	//统计透析人数传染病所占比例
93
+	count, err := service.GetPatientInfectiousCount(orgid)
94
+	//统计其他
95
+	_, otherTotal, err := service.GetPatientOtherInfectious(orgid)
96
+	if err != nil {
97
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
98
+		return
99
+	}
100
+	this.ServeSuccessJSON(map[string]interface{}{
101
+		"total":      total,
102
+		"count":      count,
103
+		"otherTotal": otherTotal,
104
+	})
105
+}
106
+
107
+func (this *NewCommonApiController) GetMobileTotalAgeCount() {
108
+	startime, _ := this.GetInt64("startime")
109
+	fmt.Println("开始时间", startime)
110
+	endtime, _ := this.GetInt64("endtime")
111
+	fmt.Println("结束时间", endtime)
112
+	adminUser := this.GetMobileAdminUserInfo()
113
+	orgid := adminUser.Org.Id
114
+	total := service.GetPatientTotalCount(orgid)
115
+	agecount, err := service.GetTotalAgeCount(orgid)
116
+	//two, err := service.GetTotalAgeCountTwo(orgid, startime, endtime)
117
+	if err != nil {
118
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
119
+		return
120
+	}
121
+	this.ServeSuccessJSON(map[string]interface{}{
122
+		"total":    total,
123
+		"ageCount": agecount,
124
+	})
125
+}

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

@@ -0,0 +1,12 @@
1
+package new_mobile_api_controllers
2
+
3
+import "github.com/astaxie/beego"
4
+
5
+func NewCommonApiControllersRegisterRouters() {
6
+
7
+	beego.Router("/m/api/gettotaldialysis", &NewCommonApiController{}, "Get:GetTotalDialysis")
8
+	beego.Router("/m/api/getmobiletotallapsecount", &NewCommonApiController{}, "Get:GetMobileTotalLapseCount")
9
+	beego.Router("/m/api/getmobiletotalsexcount", &NewCommonApiController{}, "Get:GetMobileTotalSexCount")
10
+	beego.Router("/m/api/getmobiletotalinfectiouscount", &NewCommonApiController{}, "Get:GetMobileTotalInfectiousCout")
11
+	beego.Router("/m/api/getmobiletotalagecount", &NewCommonApiController{}, "Get:GetMobileTotalAgeCount")
12
+}

+ 1 - 0
routers/router.go View File

@@ -57,6 +57,7 @@ func init() {
57 57
 
58 58
 	//admin_api.AdminAPIControllersRegisterRouters()
59 59
 	new_m_api.CommonApiControllersRegisterRouters()
60
+	new_m_api.NewCommonApiControllersRegisterRouters()
60 61
 	controllers.ManageRouters()
61 62
 	//controllers.PatientRouters()
62 63
 }

+ 35 - 5
service/common_service.go View File

@@ -179,6 +179,12 @@ func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*mod
179 179
 	return counts, total, err
180 180
 }
181 181
 
182
+func GetTotalRollOutPatients(orgid int64) (patients []*models.XtPatients, total int64, err error) {
183
+
184
+	err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and lapseto = 2", orgid).Count(&total).Find(&patients).Error
185
+	return patients, total, err
186
+}
187
+
182 188
 func GetPatientTotalCount(orgID int64) (total int64) {
183 189
 	readDb.Model(&models.XtPatients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
184 190
 	return
@@ -200,12 +206,30 @@ func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialy
200 206
 
201 207
 }
202 208
 
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
209
+func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64, err error) {
210
+
211
+	err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and gender = 1", orgid).Count(&total).Find(&patients).Error
212
+	return patients, total, err
213
+}
214
+
215
+//func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
216
+//	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
217
+//	return counts, err
218
+//}
219
+
220
+func GetPatientInfectiousCount(orgid int64) (counts []*models.PatientContagionsCountStruct, err error) {
221
+
222
+	err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and s.is_infectious = 2", orgid).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
205 223
 	return counts, err
206 224
 }
207 225
 
208
-func GetTotalAgeCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
226
+func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
227
+
228
+	err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
229
+	return patients, total, err
230
+}
231
+
232
+func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err error) {
209 233
 
210 234
 	readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
211 235
 	 SELECT
@@ -217,8 +241,8 @@ func GetTotalAgeCount(orgid int64, starttime int64, endtime int64) (counts []*mo
217 241
 	  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 242
 	  ELSE '-1'
219 243
 	 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)
244
+	 AS nnd FROM xt_patients as s  where s.user_org_id=? and s.status=1
245
+	 )a GROUP BY nnd`, orgid).Scan(&counts)
222 246
 	return
223 247
 
224 248
 }
@@ -233,3 +257,9 @@ func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []
233 257
        )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
234 258
 	return
235 259
 }
260
+
261
+func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
262
+
263
+	err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
264
+	return patients, err
265
+}