|
@@ -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 {
|