Browse Source

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

XMLWAN 4 years ago
parent
commit
8b68a89e23

+ 5 - 2
controllers/new_mobile_api_controllers/index_evaluation_api_controller.go View File

@@ -685,6 +685,7 @@ func (this *IndexEvaluationApiController) GetDoctorWorkloadChartData() {
685 685
 	adminUserInfo := this.GetMobileAdminUserInfo()
686 686
 	statistics_type, _ := this.GetInt("statistics_type")
687 687
 	start_time := this.GetString("start_time")
688
+	admin_user_id, _ := this.GetInt64("admin_user_id")
688 689
 	end_time := this.GetString("end_time")
689 690
 	timeLayout := "2006-01-02"
690 691
 	loc, _ := time.LoadLocation("Local")
@@ -706,7 +707,7 @@ func (this *IndexEvaluationApiController) GetDoctorWorkloadChartData() {
706 707
 		theEndtTIme = theTime.Unix()
707 708
 	}
708 709
 
709
-	data, _ := statistics_service.GetDoctorWorkloadChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, statistics_type)
710
+	data, _ := statistics_service.GetDoctorWorkloadChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, statistics_type, admin_user_id)
710 711
 	this.ServeSuccessJSON(map[string]interface{}{
711 712
 		"data": data,
712 713
 	})
@@ -755,6 +756,8 @@ func (this *IndexEvaluationApiController) GetNurseWorkloadChartData() {
755 756
 	adminUserInfo := this.GetMobileAdminUserInfo()
756 757
 	statistics_type, _ := this.GetInt("statistics_type")
757 758
 	start_time := this.GetString("start_time")
759
+	admin_user_id, _ := this.GetInt64("admin_user_id")
760
+
758 761
 	end_time := this.GetString("end_time")
759 762
 	timeLayout := "2006-01-02"
760 763
 	loc, _ := time.LoadLocation("Local")
@@ -776,7 +779,7 @@ func (this *IndexEvaluationApiController) GetNurseWorkloadChartData() {
776 779
 		theEndtTIme = theTime.Unix()
777 780
 	}
778 781
 
779
-	data, _ := statistics_service.GetNurseWorkloadChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, statistics_type)
782
+	data, _ := statistics_service.GetNurseWorkloadChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, statistics_type, admin_user_id)
780 783
 	this.ServeSuccessJSON(map[string]interface{}{
781 784
 		"data": data,
782 785
 	})

+ 6 - 2
controllers/pc_index_evaluation_api_controller.go View File

@@ -719,6 +719,8 @@ func (this *PCIndexEvaluationApiController) GetDoctorWorkloadChartData() {
719 719
 	adminUserInfo := this.GetAdminUserInfo()
720 720
 	statistics_type, _ := this.GetInt("statistics_type")
721 721
 	start_time := this.GetString("start_time")
722
+	admin_user_id, _ := this.GetInt64("admin_user_id")
723
+
722 724
 	end_time := this.GetString("end_time")
723 725
 	timeLayout := "2006-01-02"
724 726
 	loc, _ := time.LoadLocation("Local")
@@ -740,7 +742,7 @@ func (this *PCIndexEvaluationApiController) GetDoctorWorkloadChartData() {
740 742
 		theEndtTIme = theTime.Unix()
741 743
 	}
742 744
 
743
-	data, _ := statistics_service.GetDoctorWorkloadChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, statistics_type)
745
+	data, _ := statistics_service.GetDoctorWorkloadChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, statistics_type, admin_user_id)
744 746
 	this.ServeSuccessJSON(map[string]interface{}{
745 747
 		"data": data,
746 748
 	})
@@ -790,6 +792,8 @@ func (this *PCIndexEvaluationApiController) GetNurseWorkloadChartData() {
790 792
 	statistics_type, _ := this.GetInt("statistics_type")
791 793
 	start_time := this.GetString("start_time")
792 794
 	end_time := this.GetString("end_time")
795
+	admin_user_id, _ := this.GetInt64("admin_user_id")
796
+
793 797
 	timeLayout := "2006-01-02"
794 798
 	loc, _ := time.LoadLocation("Local")
795 799
 
@@ -810,7 +814,7 @@ func (this *PCIndexEvaluationApiController) GetNurseWorkloadChartData() {
810 814
 		theEndtTIme = theTime.Unix()
811 815
 	}
812 816
 
813
-	data, _ := statistics_service.GetNurseWorkloadChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, statistics_type)
817
+	data, _ := statistics_service.GetNurseWorkloadChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, statistics_type, admin_user_id)
814 818
 	this.ServeSuccessJSON(map[string]interface{}{
815 819
 		"data": data,
816 820
 	})

+ 25 - 22
service/statistics_service/index_evaluation_service.go View File

@@ -1159,19 +1159,23 @@ func GetPatientBloodPressureChartData(user_org_id int64, patient_id int64, start
1159 1159
 //透析血压统计
1160 1160
 
1161 1161
 //工作量统计
1162
-func GetDoctorWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (datas []*VMUserAdminRole, err error) {
1162
+func GetDoctorWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
1163 1163
 	userDb := service.UserReadDB()
1164 1164
 	db := service.XTReadDB()
1165
-	userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 2 ", user_org_id).Scan(&datas)
1165
+	if admin_user_id == 0 {
1166
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 2 ", user_org_id).Scan(&datas)
1167
+	} else {
1168
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 2  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1169
+	}
1166 1170
 
1167 1171
 	switch statistics_type {
1168 1172
 	case 1:
1169 1173
 		var Total int64
1170
-		db.Table("xt_dialysis_prescription as p").Where("user_org_id = ? AND status = 1  AND record_date >= ? AND  record_date <= ?", user_org_id, start_time, end_time).Count(&Total)
1174
+		db.Table("xt_dialysis_prescription as p").Joins("join xt_schedule sch On sch.schedule_date = p.record_date AND sch.patient_id = p.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("p.user_org_id = ? AND p.status = 1  AND p.record_date >= ? AND  p.record_date <= ? AND p.creater <> 0 ", user_org_id, start_time, end_time).Count(&Total)
1171 1175
 
1172 1176
 		for _, item := range datas {
1173 1177
 			var total int64
1174
-			db.Table("xt_dialysis_prescription as p").Where("user_org_id = ? AND status = 1 AND prescription_doctor = ? AND record_date >= ? AND  record_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
1178
+			db.Table("xt_dialysis_prescription as p").Joins("join xt_schedule sch On sch.schedule_date = p.record_date AND sch.patient_id = p.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("p.user_org_id = ? AND p.status = 1 AND p.creater = ? AND p.record_date >= ? AND  p.record_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
1175 1179
 			item.PCount = total
1176 1180
 
1177 1181
 			if math.IsNaN(float64(item.PCount) / float64(Total)) {
@@ -1242,7 +1246,7 @@ func GetDoctorWorkloadTableData(user_org_id int64, start_time int64, end_time in
1242 1246
 		var Total int64
1243 1247
 		var TotalOne int64
1244 1248
 		var TotalTwo int64
1245
-		db.Table("xt_dialysis_prescription as p").Where("user_org_id = ? AND status = 1 AND prescription_doctor = ?  AND record_date >= ? AND  record_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1249
+		db.Table("xt_dialysis_prescription as p").Joins("join xt_schedule sch On sch.schedule_date = p.record_date AND sch.patient_id = p.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("p.user_org_id = ? AND p.status = 1 AND p.creater = ?  AND p.record_date >= ? AND  p.record_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1246 1250
 		db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
1247 1251
 		db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
1248 1252
 		item.PCount = Total
@@ -1255,30 +1259,29 @@ func GetDoctorWorkloadTableData(user_org_id int64, start_time int64, end_time in
1255 1259
 	return datas, nil
1256 1260
 
1257 1261
 }
1258
-func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (datas []*VMUserAdminRole, err error) {
1262
+func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
1259 1263
 	userDb := service.UserReadDB()
1260 1264
 	db := service.XTReadDB()
1261
-	userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3 ", user_org_id).Scan(&datas)
1265
+
1266
+	if admin_user_id == 0 {
1267
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3 ", user_org_id).Scan(&datas)
1268
+	} else {
1269
+		userDb.Raw("select admin_user_id, user_name,org_id  from sgj_user_admin_role  Where status = 1 AND org_id = ?  AND user_type = 3  AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
1270
+	}
1262 1271
 
1263 1272
 	var NewTotalOne int64
1264 1273
 	var NewTotalThree int64
1265 1274
 	var NewTotalFour int64
1266 1275
 
1267
-	//var tempConfig models.Dataconfig
1268
-	//db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
1269
-
1270
-	//db.Raw("select count(*) as total from xt_dialysis_order where status = 1 AND dialysis_date >= ? AND dialysis_date <= ? AND user_org_id = ?",start_time,end_time,user_org_id).Count(&NewTotalOne)
1271
-	//db.Raw("select count(*) as total_one from  (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from  xt_assessment_before_dislysis as d  JOIN `xt_data_config` config on  d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('导管',config.name) > 0  Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ?  Group by d.id)  b JOIN `xt_dialysis_order`  on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1  AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, start_time, end_time).Count(&NewTotalTwo)
1272
-
1273
-	db.Table("xt_dialysis_order ").Where("user_org_id = ? AND status = 1  AND dialysis_date >= ? AND dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalOne)
1274
-	db.Table("xt_monitoring_record ").Where("user_org_id = ? AND status = 1  AND operate_time >= ? AND operate_time <= ?", user_org_id, start_time, end_time).Count(&NewTotalThree)
1275
-	db.Table("xt_treatment_summary").Where("user_org_id = ? AND status = 1  AND assessment_date >= ? AND assessment_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalFour)
1276
+	db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1  AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalOne)
1277
+	db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1  AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalThree)
1278
+	db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1  AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalFour)
1276 1279
 
1277 1280
 	switch statistics_type {
1278 1281
 	case 2:
1279 1282
 		for _, item := range datas {
1280 1283
 			var Total int64
1281
-			db.Table("xt_dialysis_order ").Where("user_org_id = ? AND status = 1  AND dialysis_date >= ? AND dialysis_date <= ? AND puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
1284
+			db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1  AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
1282 1285
 			item.PunctureCount = Total
1283 1286
 			if math.IsNaN(float64(item.PunctureCount) / float64(NewTotalOne)) {
1284 1287
 				item.PunctureRatio = "0.0"
@@ -1292,7 +1295,7 @@ func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int
1292 1295
 	case 1:
1293 1296
 		for _, item := range datas {
1294 1297
 			var Total int64
1295
-			db.Table("xt_monitoring_record").Where("user_org_id = ? AND status = 1 AND monitoring_nurse = ?  AND operate_time >= ? AND operate_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1298
+			db.Table("xt_monitoring_record as monitor").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ?  AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1296 1299
 			item.CureCount = Total
1297 1300
 			if math.IsNaN(float64(item.CureCount) / float64(NewTotalThree)) {
1298 1301
 				item.CureRatio = "0.0"
@@ -1307,7 +1310,7 @@ func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int
1307 1310
 	case 3:
1308 1311
 		for _, item := range datas {
1309 1312
 			var Total int64
1310
-			db.Table("xt_treatment_summary ").Where("user_org_id = ? AND status = 1 AND creater = ?  AND assessment_date >= ? AND assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1313
+			db.Table("xt_treatment_summary as summary ").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ?  AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1311 1314
 			item.MissionCount = Total
1312 1315
 			if math.IsNaN(float64(item.MissionCount) / float64(NewTotalFour)) {
1313 1316
 				item.MissionRatio = "0.0"
@@ -1346,9 +1349,9 @@ func GetNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int
1346 1349
 		var TotalThree int64
1347 1350
 		//db.Raw("select count(*) as total from  (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from  xt_assessment_before_dislysis as d  JOIN `xt_data_config` config on  d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('内瘘',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ?  Group by d.id)  b JOIN `xt_dialysis_order`  on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1  AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1348 1351
 		//db.Raw("select count(*) as total_one from  (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from  xt_assessment_before_dislysis as d  JOIN `xt_data_config` config on  d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('导管',config.name) > 0 Where  d.user_org_id = ?  AND d.assessment_date >=? AND d.assessment_date <= ?  Group by d.id)  b JOIN `xt_dialysis_order`  on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1  AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
1349
-		db.Table("xt_monitoring_record ").Where("user_org_id = ? AND status = 1 AND monitoring_nurse = ? AND operate_time >= ? AND operate_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
1350
-		db.Table("xt_dialysis_order ").Where("user_org_id = ? AND status = 1  AND dialysis_date >= ? AND dialysis_date <= ? AND puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
1351
-		db.Table("xt_treatment_summary").Where("user_org_id = ? AND status = 1 AND creater = ? AND assessment_date >= ? AND assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
1352
+		db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
1353
+		db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1  AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
1354
+		db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
1352 1355
 		item.PunctureCount = Total
1353 1356
 		item.CureCount = TotalTwo
1354 1357
 		item.MissionCount = TotalThree