Browse Source

提交代码

陈少旭 9 months ago
parent
commit
8e3202b95d

+ 8 - 12
controllers/statistics_api_controller.go View File

@@ -1447,10 +1447,6 @@ func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
1447 1447
 		// 打印其他列的值
1448 1448
 		for columnName, columnValue := range result {
1449 1449
 
1450
-			fmt.Println("000000")
1451
-			fmt.Println(columnName)
1452
-			fmt.Println("000000")
1453
-
1454 1450
 			// 跳过患者ID列
1455 1451
 
1456 1452
 			if columnName == "姓名" {
@@ -1474,14 +1470,14 @@ func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
1474 1470
 			strValue := string(byteValue)
1475 1471
 
1476 1472
 			// 尝试将字符串转换为浮点数
1477
-			floatValue, err := strconv.ParseFloat(strValue, 64)
1478
-			if err != nil {
1479
-				// 如果转换失败,输出错误信息
1480
-				fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
1481
-			} else {
1482
-				// 如果转换成功,输出列名和浮点数值
1483
-				fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
1484
-			}
1473
+			floatValue, _ := strconv.ParseFloat(strValue, 64)
1474
+			//if err != nil {
1475
+			//	// 如果转换失败,输出错误信息
1476
+			//	fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
1477
+			//} else {
1478
+			//	// 如果转换成功,输出列名和浮点数值
1479
+			//	fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
1480
+			//}
1485 1481
 			ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
1486 1482
 			if floatValue == 0 {
1487 1483
 				ynamicField[columnName] = ""

+ 4 - 2
service/patientmanage_service.go View File

@@ -2254,10 +2254,12 @@ func GetFiveInspectionPatientList(orgid int64, keyword string) (xti []*models.Xt
2254 2254
 	return
2255 2255
 }
2256 2256
 
2257
-func GetPatientFiveInspectionByID(startime int64, endtime int64, orgid int64, keyword string) (inspections []models.InspectionTen, err error) {
2257
+func GetPatientFiveInspectionByID(startime int64, endtime int64, orgid int64, keyword string) (inspections []models.InspectionTenOne, err error) {
2258 2258
 	keyword = "%" + keyword + "%"
2259 2259
 
2260
-	db := XTReadDB().Table("xt_patients as p").Select("p.id as patient_id, p.name as name, IFNULL(a.inspect_value, '') AS 'ipth',IFNULL(b.inspect_value, '') AS 'xuejia',IFNULL(c.inspect_value, '') AS 'xuelin',IFNULL(d.inspect_value, '') AS 'bdb',IFNULL(e.inspect_value, '') AS 'xhdb'").Joins("LEFT JOIN `xt_inspection` a ON p.id = a.patient_id AND a.org_id = ?  and a.`reference_item_id` = 171 and a.`reference_project_id` = 20  and a.`inspect_date` >= ? and a.`inspect_date` <= ?  LEFT JOIN xt_inspection b ON p.id = b.patient_id AND b.org_id = ?  and b.`reference_item_id` = 48 and b.`reference_project_id` = 4 and b.`inspect_date` >= ? and b.`inspect_date` <= ? LEFT JOIN xt_inspection c ON p.id = c.patient_id AND c.org_id = ?  and c.`reference_item_id` = 169 and c.`reference_project_id` = 4 and c.`inspect_date` >= ? and c.`inspect_date` <= ? LEFT JOIN xt_inspection d ON p.id = d.patient_id AND d.org_id = ?  and d.`reference_item_id` = 35 and d.`reference_project_id` = 2 and d.`inspect_date` >= ? and d.`inspect_date` <= ? LEFT JOIN xt_inspection e ON p.id = e.patient_id AND e.org_id = ?  and e.`reference_item_id` = 17 and e.`reference_project_id` = 1 and e.`inspect_date` >= ? and e.`inspect_date` <= ?", orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime).Where("p.name like ? and  p.user_org_id = ? and p.status = 1 and p.lapseto = 1 ", keyword, orgid).Group("p.id")
2260
+	db := XTReadDB().Table("xt_inspection i").Select("p.id AS patient_id,p.name AS patient_name,i.inspect_value,i.item_name,i.project_name,i.item_id").Joins("join xt_patients p ON i.patient_id = p.id").Joins("left join xt_quality_control_standard c ON i.item_id = c.`inspection_minor`").Where("i.org_id = ? and i.inspect_date >= ? and i.inspect_date <= ? and i.item_name <> 'KT/V' and i.item_name <> 'URR(%)'", orgid, startime, endtime)
2261
+
2262
+	//db := XTReadDB().Table("xt_patients as p").Select("p.id as patient_id, p.name as name, IFNULL(a.inspect_value, '') AS 'ipth',IFNULL(b.inspect_value, '') AS 'xuejia',IFNULL(c.inspect_value, '') AS 'xuelin',IFNULL(d.inspect_value, '') AS 'bdb',IFNULL(e.inspect_value, '') AS 'xhdb'").Joins("LEFT JOIN `xt_inspection` a ON p.id = a.patient_id AND a.org_id = ?  and a.`reference_item_id` = 171 and a.`reference_project_id` = 20  and a.`inspect_date` >= ? and a.`inspect_date` <= ?  LEFT JOIN xt_inspection b ON p.id = b.patient_id AND b.org_id = ?  and b.`reference_item_id` = 48 and b.`reference_project_id` = 4 and b.`inspect_date` >= ? and b.`inspect_date` <= ? LEFT JOIN xt_inspection c ON p.id = c.patient_id AND c.org_id = ?  and c.`reference_item_id` = 169 and c.`reference_project_id` = 4 and c.`inspect_date` >= ? and c.`inspect_date` <= ? LEFT JOIN xt_inspection d ON p.id = d.patient_id AND d.org_id = ?  and d.`reference_item_id` = 35 and d.`reference_project_id` = 2 and d.`inspect_date` >= ? and d.`inspect_date` <= ? LEFT JOIN xt_inspection e ON p.id = e.patient_id AND e.org_id = ?  and e.`reference_item_id` = 17 and e.`reference_project_id` = 1 and e.`inspect_date` >= ? and e.`inspect_date` <= ?", orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime).Where("p.name like ? and  p.user_org_id = ? and p.status = 1 and p.lapseto = 1 ", keyword, orgid).Group("p.id")
2261 2263
 	err = db.Find(&inspections).Error
2262 2264
 	return inspections, err
2263 2265
 }

+ 184 - 12
service/statistis_qc_service.go View File

@@ -927,6 +927,68 @@ type DialysisQualityStat struct {
927 927
 	Counts map[string]float64 `json:"counts"`
928 928
 }
929 929
 
930
+//func GetLatestInspectionValues(org_id int64, yearMonth string) ([]map[string]interface{}, error) {
931
+//	standards, err := getQualityControlStandards(org_id)
932
+//	if err != nil {
933
+//		return nil, err
934
+//	}
935
+//
936
+//	var selectFields []string
937
+//	for _, standard := range standards {
938
+//		field := fmt.Sprintf("IFNULL(MAX(CASE WHEN i.item_name = %s THEN i.inspect_value END),'') AS `%s`",
939
+//			"'"+standard.ItemName+"'", standard.ItemName)
940
+//		selectFields = append(selectFields, field)
941
+//	}
942
+//
943
+//	query := fmt.Sprintf(`
944
+//		SELECT
945
+//		    p.name as '姓名',
946
+//			%s
947
+//		FROM xt_inspection i
948
+//		JOIN xt_patients p On p.id = i.patient_id
949
+//		WHERE DATE_FORMAT(FROM_UNIXTIME(i.inspect_date), '%%Y-%%m') = ? and org_id = ?
950
+//
951
+//		GROUP BY i.patient_id
952
+//	`, strings.Join(selectFields, ", "))
953
+//
954
+//	var results []map[string]interface{}
955
+//	rows, err := readDb.Raw(query, yearMonth, org_id).Rows()
956
+//	if err != nil {
957
+//		return nil, err
958
+//	}
959
+//	defer rows.Close()
960
+//
961
+//	columns, err := rows.Columns()
962
+//	if err != nil {
963
+//		return nil, err
964
+//	}
965
+//
966
+//	for rows.Next() {
967
+//		// 创建一个长度为列数的切片,用于存储每一行的值
968
+//		columnValues := make([]interface{}, len(columns))
969
+//		columnPointers := make([]interface{}, len(columns))
970
+//		for i := range columnValues {
971
+//			columnPointers[i] = &columnValues[i]
972
+//		}
973
+//
974
+//		// 扫描当前行的值
975
+//		if err := rows.Scan(columnPointers...); err != nil {
976
+//			return nil, err
977
+//		}
978
+//
979
+//		// 将扫描到的值放入结果 map 中
980
+//		result := make(map[string]interface{})
981
+//		for i, colName := range columns {
982
+//			val := columnPointers[i].(*interface{})
983
+//			result[colName] = *val
984
+//		}
985
+//
986
+//		results = append(results, result)
987
+//	}
988
+//
989
+//	return results, nil
990
+//}
991
+
930 992
 func GetLatestInspectionValues(org_id int64, yearMonth string) ([]map[string]interface{}, error) {
931 993
 	standards, err := getQualityControlStandards(org_id)
932 994
 	if err != nil {
@@ -935,24 +997,48 @@ func GetLatestInspectionValues(org_id int64, yearMonth string) ([]map[string]int
935 997
 
936 998
 	var selectFields []string
937 999
 	for _, standard := range standards {
938
-		field := fmt.Sprintf("IFNULL(MAX(CASE WHEN i.item_name = %s THEN i.inspect_value END),'') AS `%s`",
939
-			"'"+standard.ItemName+"'", standard.ItemName)
1000
+		field := fmt.Sprintf("IFNULL(MAX(CASE WHEN latest_inspections.item_name = '%s' THEN latest_inspections.inspect_value END),'') AS `%s`",
1001
+			standard.ItemName, standard.ItemName)
940 1002
 		selectFields = append(selectFields, field)
941 1003
 	}
942 1004
 
943 1005
 	query := fmt.Sprintf(`
944
-		SELECT
945
-		    p.name as '姓名',
946
-			%s
947
-		FROM xt_inspection i
948
-		JOIN xt_patients p On p.id = i.patient_id
949
-		WHERE DATE_FORMAT(FROM_UNIXTIME(i.inspect_date), '%%Y-%%m') = ? and org_id = ?
950
-		
951
-		GROUP BY i.patient_id
952
-	`, strings.Join(selectFields, ", "))
1006
+			SELECT
1007
+			    p.name as '姓名',
1008
+				%s
1009
+			FROM xt_patients p
1010
+			JOIN (
1011
+				SELECT
1012
+					i1.patient_id,
1013
+					i1.item_name,
1014
+					i1.inspect_value
1015
+				FROM
1016
+					xt_inspection i1
1017
+				JOIN (
1018
+					SELECT
1019
+						patient_id,
1020
+						item_name,
1021
+						MAX(inspect_date) AS latest_inspect_date
1022
+					FROM
1023
+						xt_inspection
1024
+					WHERE
1025
+						DATE_FORMAT(FROM_UNIXTIME(inspect_date), '%%Y-%%m') = ?
1026
+						AND org_id = ?
1027
+					GROUP BY
1028
+						patient_id, item_name
1029
+				) latest
1030
+				ON
1031
+					i1.patient_id = latest.patient_id
1032
+					AND i1.item_name = latest.item_name
1033
+					AND i1.inspect_date = latest.latest_inspect_date
1034
+			) latest_inspections
1035
+			ON p.id = latest_inspections.patient_id 
1036
+			WHERE p.user_org_id = ? and p.lapseto = 1
1037
+			GROUP BY p.id, p.name
1038
+		`, strings.Join(selectFields, ", "))
953 1039
 
954 1040
 	var results []map[string]interface{}
955
-	rows, err := readDb.Raw(query, yearMonth, org_id).Rows()
1041
+	rows, err := readDb.Raw(query, yearMonth, org_id, org_id).Rows() // 注意这里多传一个org_id参数
956 1042
 	if err != nil {
957 1043
 		return nil, err
958 1044
 	}
@@ -989,6 +1075,92 @@ func GetLatestInspectionValues(org_id int64, yearMonth string) ([]map[string]int
989 1075
 	return results, nil
990 1076
 }
991 1077
 
1078
+//func GetLatestInspectionValues(org_id int64, yearMonth string) ([]map[string]interface{}, error) {
1079
+//	standards, err := getQualityControlStandards(org_id)
1080
+//	if err != nil {
1081
+//		return nil, err
1082
+//	}
1083
+//
1084
+//	var selectFields []string
1085
+//	for _, standard := range standards {
1086
+//		field := fmt.Sprintf("IFNULL(MAX(CASE WHEN latest_inspections.item_name = '%s' THEN latest_inspections.inspect_value END),'') AS `%s`",
1087
+//			standard.ItemName, standard.ItemName)
1088
+//		selectFields = append(selectFields, field)
1089
+//	}
1090
+//
1091
+//	query := fmt.Sprintf(`
1092
+//		SELECT
1093
+//		    p.name AS '姓名',
1094
+//			%s
1095
+//		FROM xt_patients p
1096
+//		LEFT JOIN (
1097
+//			SELECT
1098
+//				i1.patient_id,
1099
+//				i1.item_name,
1100
+//				i1.inspect_value
1101
+//			FROM
1102
+//				xt_inspection i1
1103
+//			JOIN (
1104
+//				SELECT
1105
+//					patient_id,
1106
+//					item_name,
1107
+//					MAX(inspect_date) AS latest_inspect_date
1108
+//				FROM
1109
+//					xt_inspection
1110
+//				WHERE
1111
+//					DATE_FORMAT(FROM_UNIXTIME(inspect_date), '%%Y-%%m') = ?
1112
+//					AND org_id = ?
1113
+//				GROUP BY
1114
+//					patient_id, item_name
1115
+//			) latest
1116
+//			ON
1117
+//				i1.patient_id = latest.patient_id
1118
+//				AND i1.item_name = latest.item_name
1119
+//				AND i1.inspect_date = latest.latest_inspect_date
1120
+//		) latest_inspections
1121
+//		ON p.id = latest_inspections.patient_id
1122
+//		WHERE p.user_org_id = ?
1123
+//		GROUP BY p.id, p.name
1124
+//	`, strings.Join(selectFields, ", "))
1125
+//
1126
+//	var results []map[string]interface{}
1127
+//	rows, err := readDb.Raw(query, yearMonth, org_id, org_id).Rows() // 注意这里多传一个org_id参数
1128
+//	if err != nil {
1129
+//		return nil, err
1130
+//	}
1131
+//	defer rows.Close()
1132
+//
1133
+//	columns, err := rows.Columns()
1134
+//	if err != nil {
1135
+//		return nil, err
1136
+//	}
1137
+//
1138
+//	for rows.Next() {
1139
+//		// 创建一个长度为列数的切片,用于存储每一行的值
1140
+//		columnValues := make([]interface{}, len(columns))
1141
+//		columnPointers := make([]interface{}, len(columns))
1142
+//		for i := range columnValues {
1143
+//			columnPointers[i] = &columnValues[i]
1144
+//		}
1145
+//
1146
+//		// 扫描当前行的值
1147
+//		if err := rows.Scan(columnPointers...); err != nil {
1148
+//			return nil, err
1149
+//		}
1150
+//
1151
+//		// 将扫描到的值放入结果 map 中
1152
+//		result := make(map[string]interface{})
1153
+//		for i, colName := range columns {
1154
+//			val := columnPointers[i].(*interface{})
1155
+//			result[colName] = *val
1156
+//		}
1157
+//
1158
+//		results = append(results, result)
1159
+//	}
1160
+//
1161
+//	return results, nil
1162
+//}
1163
+
992 1164
 func createDynamicStruct(fields map[string]interface{}) reflect.Type {
993 1165
 	var structFields []reflect.StructField
994 1166
 	for name, value := range fields {