Explorar el Código

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

XMLWAN hace 4 años
padre
commit
fd85775a0c

+ 1 - 0
controllers/new_mobile_api_controllers/index_evaluation_api_controller.go Ver fichero

@@ -47,6 +47,7 @@ func (this *IndexEvaluationApiController) GetLaboratoryIndexProjectRangeValueDat
47 47
 	var range_vaule []string
48 48
 	if range_type == 1 {
49 49
 		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
50
+
50 51
 		if qcs.ID == 0 { //没有配置选项
51 52
 			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.Org.Id) //判断是否为集成过来的数据
52 53
 			if count <= 0 {                                                             //不是,读系统参考值

+ 31 - 18
service/statistics_service/index_evaluation_service.go Ver fichero

@@ -12,7 +12,7 @@ import (
12 12
 func GetOrgFirstPatientInfo(user_org_id int64) (patient *models.Patients, err error) {
13 13
 	db := service.XTReadDB()
14 14
 	var tempPatient models.Patients
15
-	findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).First(&tempPatient).Error
15
+	findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Last(&tempPatient).Error
16 16
 	if findErr == gorm.ErrRecordNotFound {
17 17
 		return nil, nil
18 18
 	}
@@ -487,7 +487,6 @@ func GetDialysisWeightChartData(user_org_id int64, start_time int64, end_time in
487 487
 				weightAdd = append(weightAdd, weights[index].WeightBefore-weights[index+1].WeightAfter)
488 488
 			}
489 489
 		}
490
-		fmt.Println(weightAdd)
491 490
 
492 491
 		var total_one int64
493 492
 		var total_two int64
@@ -668,7 +667,7 @@ func GetDialysisWeightTableData(orgID, patientID int64, page, limit, start, end
668 667
 	if end != 0 {
669 668
 		db = db.Where("assessment_date<=?", end)
670 669
 	}
671
-	db = db.Preload("VMAssessmentAfterDislysis", "status = 1").Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
670
+	db = db.Preload("VMAssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
672 671
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc").Select("dry_weight, weight_before, patient_id, assessment_date").Find(&orders).Error
673 672
 
674 673
 	for _, item := range orders {
@@ -750,7 +749,7 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
750 749
 	db := service.XTReadDB()
751 750
 	var items []*otherItemAmount
752 751
 	var tempErr error
753
-	//var total int64
752
+	var Total int64
754 753
 	switch statistics_type {
755 754
 	case 1:
756 755
 		type bp struct {
@@ -761,8 +760,11 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
761 760
 
762 761
 		if patient_id == 0 {
763 762
 			db.Raw("SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_before_dislysis Where user_org_id = ? AND  created_time >= ? AND created_time <= ?   UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure  FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ?  ", user_org_id, start_time, end_time, user_org_id, start_time, end_time).Scan(&bps)
763
+			//db.Raw("SELECT count(id) FROM xt_assessment_before_dislysis Where user_org_id = ? AND  created_time >= ? AND created_time <= ?   UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure  FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ?  ", user_org_id, start_time, end_time, user_org_id, start_time, end_time).Count(&Total)
764
+
764 765
 		} else {
765 766
 			db.Raw("SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_before_dislysis Where user_org_id = ? AND  created_time >= ? AND created_time <= ? AND patient_id = ?  UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure  FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ?  ", user_org_id, start_time, end_time, patient_id, user_org_id, start_time, end_time, patient_id).Scan(&bps)
767
+			//db.Raw("SELECT  count(id) FROM xt_assessment_before_dislysis Where user_org_id = ? AND  created_time >= ? AND created_time <= ? AND patient_id = ?  UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure  FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ?  ", user_org_id, start_time, end_time, patient_id, user_org_id, start_time, end_time, patient_id).Count(&Total)
766 768
 
767 769
 		}
768 770
 
@@ -780,6 +782,9 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
780 782
 			} else if item.SystolicBloodPressure >= 100 && item.SystolicBloodPressure <= 160 && item.DiastolicBloodPressure >= 99 && item.DiastolicBloodPressure <= 140 {
781 783
 				total_three++
782 784
 			} else {
785
+				fmt.Println(item.SystolicBloodPressure)
786
+				fmt.Println(item.DiastolicBloodPressure)
787
+
783 788
 				total_four++
784 789
 			}
785 790
 		}
@@ -810,6 +815,12 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
810 815
 		items = append(items, newItem2)
811 816
 		items = append(items, newItem3)
812 817
 
818
+		//
819
+		//for _, item := range items {
820
+		//	float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", float64(item.Total)/float64(Total)), 64)
821
+		//	item.Ratio = strconv.FormatInt(int64(float_value*100), 10)
822
+		//}
823
+
813 824
 		break
814 825
 	case 2:
815 826
 		if patient_id == 0 {
@@ -831,6 +842,8 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
831 842
 
832 843
 		}
833 844
 
845
+		//db.Table("xt_assessment_before_dislysis as before").Where("before.user_org_id=? AND before.status = 1  AND before.created_time >= ? and before.created_time <= ? ", user_org_id, patient_id, start_time, end_time).Count(&total)
846
+
834 847
 		var isHasConditionOne bool = false
835 848
 		var isHasConditionTwo bool = false
836 849
 		var isHasConditionThree bool = false
@@ -960,13 +973,13 @@ func GetBloodPressureTableData(orgID, patientID int64, page, limit, start, end i
960 973
 	if end != 0 {
961 974
 		db = db.Where("sch.created_time<=?", end)
962 975
 	}
963
-	db = db.Preload("VMPredialysisEvaluation", "status = 1").
964
-		Preload("VMAssessmentAfterDislysis", "status = 1").
976
+	db = db.Preload("VMPredialysisEvaluation", "status = 1 AND user_org_id = ?", orgID).
977
+		Preload("VMAssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
965 978
 		Preload("VMMinMonitoringRecord", func(db *gorm.DB) *gorm.DB {
966
-			return db.Where("status = 1").Order("systolic_blood_pressure DESC")
979
+			return db.Where("status = 1 AND user_org_id = ?", orgID).Order("systolic_blood_pressure DESC")
967 980
 		}).
968 981
 		Preload("VMMaxMonitoringRecord", func(db *gorm.DB) *gorm.DB {
969
-			return db.Where("status = 1").Order("systolic_blood_pressure ASC")
982
+			return db.Where("status = 1 AND user_org_id = ?", orgID).Order("systolic_blood_pressure ASC")
970 983
 		}).
971 984
 		Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
972 985
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("sch.schedule_date desc").Select(" sch.schedule_date,sch.patient_id,sch.user_org_id").Find(&orders).Error
@@ -1076,14 +1089,14 @@ func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int
1076 1089
 	case 1:
1077 1090
 		for _, item := range datas {
1078 1091
 			var Total int64
1079
-			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 config.name like '%内瘘%' 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1092
+			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   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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1080 1093
 			item.PunctureCount = Total
1081 1094
 		}
1082 1095
 		break
1083 1096
 	case 2:
1084 1097
 		for _, item := range datas {
1085 1098
 			var Total int64
1086
-			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 config.name like '%导管%' 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1099
+			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 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1087 1100
 			item.ChangemedicineCount = Total
1088 1101
 		}
1089 1102
 
@@ -1127,8 +1140,8 @@ func GetNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int
1127 1140
 		var TotalOne int64
1128 1141
 		var TotalTwo int64
1129 1142
 		var TotalThree int64
1130
-		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 config.name like '%内瘘%' 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1131
-		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 config.name like '%导管%' 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
1143
+		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 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
1144
+		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 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.created_time >= ? AND xt_dialysis_order.created_time <= ? ", user_org_id, tempConfig.ID, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
1132 1145
 		db.Table("xt_monitoring_record ").Where("user_org_id = ? AND status = 1 AND monitoring_nurse = ? AND created_time >= ? AND created_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
1133 1146
 		db.Table("xt_treatment_summary").Where("user_org_id = ? AND status = 1 AND creater = ? AND created_time >= ? AND created_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
1134 1147
 		item.PunctureCount = Total
@@ -1299,7 +1312,7 @@ func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time i
1299 1312
 			db := service.XTReadDB()
1300 1313
 			offset := (page - 1) * limit
1301 1314
 			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value < ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1302
-				return db.Where("status = 1")
1315
+				return db.Where("status = 1 AND user_org_id = ?", user_org_id)
1303 1316
 			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1304 1317
 			return datas, total, err
1305 1318
 		} else if indexTwo != -1 {
@@ -1308,7 +1321,7 @@ func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time i
1308 1321
 			db := service.XTReadDB()
1309 1322
 			offset := (page - 1) * limit
1310 1323
 			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value > ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1311
-				return db.Where("status = 1")
1324
+				return db.Where("status = 1 AND user_org_id = ?", user_org_id)
1312 1325
 			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1313 1326
 			return datas, total, err
1314 1327
 		} else if indexThree != -1 {
@@ -1325,14 +1338,14 @@ func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time i
1325 1338
 			db := service.XTReadDB()
1326 1339
 			offset := (page - 1) * limit
1327 1340
 			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value >= ? AND inspect_value <= ?", user_org_id, start_time, end_time, project_id, item_id, float1, float2).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1328
-				return db.Where("status = 1")
1341
+				return db.Where("status = 1 AND user_org_id = ?", user_org_id)
1329 1342
 			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1330 1343
 			return datas, total, err
1331 1344
 		} else {
1332 1345
 			db := service.XTReadDB()
1333 1346
 			offset := (page - 1) * limit
1334 1347
 			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1 ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1335
-				return db.Where("status = 1")
1348
+				return db.Where("status = 1 AND user_org_id = ?", user_org_id)
1336 1349
 			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1337 1350
 			return datas, total, err
1338 1351
 		}
@@ -1343,7 +1356,7 @@ func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time i
1343 1356
 			db := service.XTReadDB()
1344 1357
 			offset := (page - 1) * limit
1345 1358
 			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1346
-				return db.Where("status = 1")
1359
+				return db.Where("status = 1 AND user_org_id = ?", user_org_id)
1347 1360
 			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1348 1361
 			return datas, total, err
1349 1362
 
@@ -1352,7 +1365,7 @@ func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time i
1352 1365
 			db := service.XTReadDB()
1353 1366
 			offset := (page - 1) * limit
1354 1367
 			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value = ?", user_org_id, start_time, end_time, project_id, item_id, range_value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1355
-				return db.Where("status = 1")
1368
+				return db.Where("status = 1 AND user_org_id = ?", user_org_id)
1356 1369
 			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1357 1370
 			return datas, total, err
1358 1371