Browse Source

患者检验检查统计开发

XMLWAN 4 years ago
parent
commit
24c34c5140

+ 126 - 0
controllers/new_mobile_api_controllers/common_api_controller.go View File

@@ -1012,6 +1012,9 @@ func (this *CommonApiController) GetMonthProjectList() {
1012 1012
 
1013 1013
 	febStart := this.GetString("febStart")
1014 1014
 	fmt.Println("二月始", febStart)
1015
+	febStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", febStart)
1016
+	febStartStrStrUnix := febStartStr.Unix()
1017
+	fmt.Println("二月使", febStartStrStrUnix)
1015 1018
 	febEnd := this.GetString("febEnd")
1016 1019
 	fmt.Println("二月末", febEnd)
1017 1020
 	febEndStr := febEnd + " 23:59:59"
@@ -1021,6 +1024,9 @@ func (this *CommonApiController) GetMonthProjectList() {
1021 1024
 
1022 1025
 	marchStart := this.GetString("marchStart")
1023 1026
 	fmt.Println("三月始", marchStart)
1027
+	marchStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", marchStart)
1028
+	marchStartStrUnix := marchStartStr.Unix()
1029
+	fmt.Println("三月使", marchStartStrUnix)
1024 1030
 	marchEnd := this.GetString("marchEnd")
1025 1031
 	fmt.Println("三月末", febEnd)
1026 1032
 	marchEndStr := marchEnd + " 23:59:59"
@@ -1028,4 +1034,124 @@ func (this *CommonApiController) GetMonthProjectList() {
1028 1034
 	marchEndStrUnix := marchEndStrs.Unix()
1029 1035
 	fmt.Println("三月末", marchEndStrUnix)
1030 1036
 
1037
+	aprStart := this.GetString("aprStart")
1038
+	fmt.Println("四月始", aprStart)
1039
+	aprStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", aprStart)
1040
+	aprStartStrUnix := aprStartStr.Unix()
1041
+	fmt.Println("四月使", aprStartStrUnix)
1042
+	aprEnd := this.GetString("aprEnd")
1043
+	fmt.Println("四月末", aprEnd)
1044
+	aprEndStr := aprEnd + " 23:59:59"
1045
+	aprEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", aprEndStr)
1046
+	aprEndStrsUnix := aprEndStrs.Unix()
1047
+	fmt.Println("四月末", aprEndStrsUnix)
1048
+
1049
+	mayStart := this.GetString("mayStart")
1050
+	fmt.Println("五月始", mayStart)
1051
+	mayStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", mayStart)
1052
+	mayStartStrUnix := mayStartStr.Unix()
1053
+	fmt.Println("五月使", mayStartStrUnix)
1054
+	mayEnd := this.GetString("mayEnd")
1055
+	fmt.Println("五月末", mayEnd)
1056
+	mayEndStr := mayEnd + " 23:59:59"
1057
+	mayEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", mayEndStr)
1058
+	mayEndStrsUnix := mayEndStrs.Unix()
1059
+	fmt.Println("五月末", mayEndStrsUnix)
1060
+
1061
+	junStart := this.GetString("junStart")
1062
+	fmt.Println("六月始", mayStart)
1063
+	junStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", junStart)
1064
+	junStartStrUnix := junStartStr.Unix()
1065
+	fmt.Println("六月使", junStartStrUnix)
1066
+	junEnd := this.GetString("junEnd")
1067
+	fmt.Println("六月末", junEnd)
1068
+	junEndStr := junEnd + " 23:59:59"
1069
+	junEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", junEndStr)
1070
+	junEndStrsUnix := junEndStrs.Unix()
1071
+	fmt.Println("六月末", junEndStrsUnix)
1072
+
1073
+	julStart := this.GetString("julStart")
1074
+	fmt.Println("七月始", julStart)
1075
+	julStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", julStart)
1076
+	julStartStrUnix := julStartStr.Unix()
1077
+	fmt.Println("七月使", julStartStrUnix)
1078
+	julEnd := this.GetString("julEnd")
1079
+	fmt.Println("七月末", julEnd)
1080
+	julEndStr := julEnd + " 23:59:59"
1081
+	julEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", julEndStr)
1082
+	julEndStrsUnix := julEndStrs.Unix()
1083
+	fmt.Println("七月末", julEndStrsUnix)
1084
+
1085
+	augStart := this.GetString("augStart")
1086
+	fmt.Println("八月始", augStart)
1087
+	augStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", augStart)
1088
+	augStartStrUnix := augStartStr.Unix()
1089
+	fmt.Println("八月使", augStartStrUnix)
1090
+	augEnd := this.GetString("augEnd")
1091
+	fmt.Println("八月末", augEnd)
1092
+	augEndStr := augEnd + " 23:59:59"
1093
+	augEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", augEndStr)
1094
+	augEndStrsUnix := augEndStrs.Unix()
1095
+	fmt.Println("八月末", augEndStrsUnix)
1096
+
1097
+	sepStart := this.GetString("sepStart")
1098
+	fmt.Println("九月始", sepStart)
1099
+	sepStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", sepStart)
1100
+	sepStartStrUnix := sepStartStr.Unix()
1101
+	fmt.Println("九月使", sepStartStrUnix)
1102
+	sepEnd := this.GetString("sepEnd")
1103
+	fmt.Println("九月末", sepEnd)
1104
+	sepEndStr := sepEnd + " 23:59:59"
1105
+	sepEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", sepEndStr)
1106
+	sepEndStrsUnix := sepEndStrs.Unix()
1107
+	fmt.Println("九月末", sepEndStrsUnix)
1108
+
1109
+	octStart := this.GetString("octStart")
1110
+	fmt.Println("10月始", octStart)
1111
+	octStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", octStart)
1112
+	octStartStrUnix := octStartStr.Unix()
1113
+	fmt.Println("10月使", octStartStrUnix)
1114
+	octEnd := this.GetString("octEnd")
1115
+	fmt.Println("10月末", octEnd)
1116
+	octEndStr := octEnd + " 23:59:59"
1117
+	octEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", octEndStr)
1118
+	octEndStrsUnix := octEndStrs.Unix()
1119
+	fmt.Println("10月末", octEndStrsUnix)
1120
+
1121
+	novStart := this.GetString("novStart")
1122
+	fmt.Println("11月始", novStart)
1123
+	novStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", novStart)
1124
+	novStartStrUnix := novStartStr.Unix()
1125
+	fmt.Println("11月使", novStartStrUnix)
1126
+	novEnd := this.GetString("novEnd")
1127
+	fmt.Println("11月末", novEnd)
1128
+	novEndStr := novEnd + " 23:59:59"
1129
+	novEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", novEndStr)
1130
+	novEndStrsUnix := novEndStrs.Unix()
1131
+	fmt.Println("10月末", novEndStrsUnix)
1132
+
1133
+	decStart := this.GetString("decStart")
1134
+	fmt.Println("12月始", novStart)
1135
+	decStartStr, _ := utils.ParseTimeStringToTime("2006-01-02", decStart)
1136
+	decStartStrUnix := decStartStr.Unix()
1137
+	fmt.Println("12月使", decStartStrUnix)
1138
+	decEnd := this.GetString("decEnd")
1139
+	fmt.Println("12月末", novEnd)
1140
+	decEndStr := decEnd + " 23:59:59"
1141
+	decEndStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", decEndStr)
1142
+	decEndStrsUnix := decEndStrs.Unix()
1143
+	fmt.Println("12月末", decEndStrsUnix)
1144
+	//统计总共
1145
+	monthlist, err := service.GetMonthProjectList(orgid, lapseto, modetype, januaryStartStrUnix, januaryEndStrUnix, febStartStrStrUnix, febEndStrUnix, marchStartStrUnix, marchEndStrUnix, aprStartStrUnix, aprEndStrsUnix, mayStartStrUnix, mayEndStrsUnix, junStartStrUnix, junEndStrsUnix, julStartStrUnix, julEndStrsUnix, augStartStrUnix, augEndStrsUnix, sepStartStrUnix, sepEndStrsUnix, octStartStrUnix, octEndStrsUnix, novStartStrUnix, novEndStrsUnix, decStartStrUnix, decEndStrsUnix)
1146
+	//统计不合格
1147
+	monthNolist, err := service.GetMonthProjectListTwo(orgid, lapseto, modetype, januaryStartStrUnix, januaryEndStrUnix, febStartStrStrUnix, febEndStrUnix, marchStartStrUnix, marchEndStrUnix, aprStartStrUnix, aprEndStrsUnix, mayStartStrUnix, mayEndStrsUnix, junStartStrUnix, junEndStrsUnix, julStartStrUnix, julEndStrsUnix, augStartStrUnix, augEndStrsUnix, sepStartStrUnix, sepEndStrsUnix, octStartStrUnix, octEndStrsUnix, novStartStrUnix, novEndStrsUnix, decStartStrUnix, decEndStrsUnix)
1148
+	if err != nil {
1149
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1150
+		return
1151
+	}
1152
+
1153
+	this.ServeSuccessJSON(map[string]interface{}{
1154
+		"monthlist":   monthlist,
1155
+		"monthNolist": monthNolist,
1156
+	})
1031 1157
 }

+ 441 - 0
service/common_service.go View File

@@ -1080,3 +1080,444 @@ func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime in
1080 1080
 	}
1081 1081
 	return
1082 1082
 }
1083
+
1084
+func GetMonthProjectList(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
1085
+
1086
+	if lapseto == 0 {
1087
+
1088
+		d := XTReadDB().Table("xt_patients as s")
1089
+		fmt.Println("d", d)
1090
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1091
+
1092
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1093
+			"SELECT " +
1094
+			"CASE " +
1095
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '一月'" +
1096
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '二月'" +
1097
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '三月'" +
1098
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '四月'" +
1099
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '五月'" +
1100
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '六月'" +
1101
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '七月'" +
1102
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '八月'" +
1103
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '九月'" +
1104
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十月'" +
1105
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十一月'" +
1106
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十二月'" +
1107
+			" ELSE '其他'" +
1108
+			"END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
1109
+		countParams := make([]interface{}, 0)
1110
+		countParams = append(countParams, januaryStartStrUnix)
1111
+		countParams = append(countParams, januaryEndStrUnix)
1112
+		countParams = append(countParams, febStartStrStrUnix)
1113
+		countParams = append(countParams, febEndStrUnix)
1114
+		countParams = append(countParams, marchStartStrUnix)
1115
+		countParams = append(countParams, marchEndStrUnix)
1116
+		countParams = append(countParams, aprStartStrUnix)
1117
+		countParams = append(countParams, aprEndStrsUnix)
1118
+		countParams = append(countParams, mayStartStrUnix)
1119
+		countParams = append(countParams, mayEndStrsUnix)
1120
+		countParams = append(countParams, junStartStrUnix)
1121
+		countParams = append(countParams, junEndStrsUnix)
1122
+		countParams = append(countParams, julStartStrUnix)
1123
+		countParams = append(countParams, julEndStrsUnix)
1124
+		countParams = append(countParams, augStartStrUnix)
1125
+		countParams = append(countParams, augEndStrsUnix)
1126
+		countParams = append(countParams, sepStartStrUnix)
1127
+		countParams = append(countParams, sepEndStrsUnix)
1128
+		countParams = append(countParams, octStartStrUnix)
1129
+		countParams = append(countParams, octEndStrsUnix)
1130
+		countParams = append(countParams, novStartStrUnix)
1131
+		countParams = append(countParams, novEndStrsUnix)
1132
+		countParams = append(countParams, decStartStrUnix)
1133
+		countParams = append(countParams, decEndStrsUnix)
1134
+		if orgid > 0 {
1135
+			db = db.Where("x.org_id=?", orgid)
1136
+			countSQL += " AND x.org_id=?"
1137
+			countParams = append(countParams, orgid)
1138
+		}
1139
+		if modetype > 0 {
1140
+			db = db.Where("x.item_id = ?", modetype)
1141
+			countSQL += " AND x.item_id=?"
1142
+			countParams = append(countParams, modetype)
1143
+		}
1144
+		if januaryStartStrUnix > 0 {
1145
+			db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1146
+			countSQL += " AND x.inspect_date >=?"
1147
+			countParams = append(countParams, januaryStartStrUnix)
1148
+		}
1149
+		if decEndStrsUnix > 0 {
1150
+			db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1151
+			countSQL += " AND x.inspect_date <=?"
1152
+			countParams = append(countParams, decEndStrsUnix)
1153
+		}
1154
+		countSQL += ")a GROUP BY nnd"
1155
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1156
+	}
1157
+
1158
+	if lapseto == 1 {
1159
+
1160
+		d := XTReadDB().Table("xt_patients as s")
1161
+		fmt.Println("d", d)
1162
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1163
+
1164
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1165
+			"SELECT " +
1166
+			"CASE " +
1167
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '一月'" +
1168
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '二月'" +
1169
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '三月'" +
1170
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '四月'" +
1171
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '五月'" +
1172
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '六月'" +
1173
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '七月'" +
1174
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '八月'" +
1175
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '九月'" +
1176
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十月'" +
1177
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十一月'" +
1178
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十二月'" +
1179
+			" ELSE '其他'" +
1180
+			"END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1)"
1181
+		countParams := make([]interface{}, 0)
1182
+		countParams = append(countParams, januaryStartStrUnix)
1183
+		countParams = append(countParams, januaryEndStrUnix)
1184
+		countParams = append(countParams, febStartStrStrUnix)
1185
+		countParams = append(countParams, febEndStrUnix)
1186
+		countParams = append(countParams, marchStartStrUnix)
1187
+		countParams = append(countParams, marchEndStrUnix)
1188
+		countParams = append(countParams, aprStartStrUnix)
1189
+		countParams = append(countParams, aprEndStrsUnix)
1190
+		countParams = append(countParams, mayStartStrUnix)
1191
+		countParams = append(countParams, mayEndStrsUnix)
1192
+		countParams = append(countParams, junStartStrUnix)
1193
+		countParams = append(countParams, junEndStrsUnix)
1194
+		countParams = append(countParams, julStartStrUnix)
1195
+		countParams = append(countParams, julEndStrsUnix)
1196
+		countParams = append(countParams, augStartStrUnix)
1197
+		countParams = append(countParams, augEndStrsUnix)
1198
+		countParams = append(countParams, sepStartStrUnix)
1199
+		countParams = append(countParams, sepEndStrsUnix)
1200
+		countParams = append(countParams, octStartStrUnix)
1201
+		countParams = append(countParams, octEndStrsUnix)
1202
+		countParams = append(countParams, novStartStrUnix)
1203
+		countParams = append(countParams, novEndStrsUnix)
1204
+		countParams = append(countParams, decStartStrUnix)
1205
+		countParams = append(countParams, decEndStrsUnix)
1206
+		if orgid > 0 {
1207
+			db = db.Where("x.org_id=?", orgid)
1208
+			countSQL += " AND x.org_id=?"
1209
+			countParams = append(countParams, orgid)
1210
+		}
1211
+		if modetype > 0 {
1212
+			db = db.Where("x.item_id = ?", modetype)
1213
+			countSQL += " AND x.item_id=?"
1214
+			countParams = append(countParams, modetype)
1215
+		}
1216
+		if januaryStartStrUnix > 0 {
1217
+			db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1218
+			countSQL += " AND x.inspect_date >=?"
1219
+			countParams = append(countParams, januaryStartStrUnix)
1220
+		}
1221
+		if decEndStrsUnix > 0 {
1222
+			db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1223
+			countSQL += " AND x.inspect_date <=?"
1224
+			countParams = append(countParams, decEndStrsUnix)
1225
+		}
1226
+		countSQL += ")a GROUP BY nnd"
1227
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1228
+	}
1229
+
1230
+	if lapseto == 2 {
1231
+		d := XTReadDB().Table("xt_patients as s")
1232
+		fmt.Println("d", d)
1233
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1234
+
1235
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1236
+			"SELECT " +
1237
+			"CASE " +
1238
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '一月'" +
1239
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '二月'" +
1240
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '三月'" +
1241
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '四月'" +
1242
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '五月'" +
1243
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '六月'" +
1244
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '七月'" +
1245
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '八月'" +
1246
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '九月'" +
1247
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十月'" +
1248
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十一月'" +
1249
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? THEN '十二月'" +
1250
+			" ELSE '其他'" +
1251
+			"END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 2)"
1252
+		countParams := make([]interface{}, 0)
1253
+		countParams = append(countParams, januaryStartStrUnix)
1254
+		countParams = append(countParams, januaryEndStrUnix)
1255
+		countParams = append(countParams, febStartStrStrUnix)
1256
+		countParams = append(countParams, febEndStrUnix)
1257
+		countParams = append(countParams, marchStartStrUnix)
1258
+		countParams = append(countParams, marchEndStrUnix)
1259
+		countParams = append(countParams, aprStartStrUnix)
1260
+		countParams = append(countParams, aprEndStrsUnix)
1261
+		countParams = append(countParams, mayStartStrUnix)
1262
+		countParams = append(countParams, mayEndStrsUnix)
1263
+		countParams = append(countParams, junStartStrUnix)
1264
+		countParams = append(countParams, junEndStrsUnix)
1265
+		countParams = append(countParams, julStartStrUnix)
1266
+		countParams = append(countParams, julEndStrsUnix)
1267
+		countParams = append(countParams, augStartStrUnix)
1268
+		countParams = append(countParams, augEndStrsUnix)
1269
+		countParams = append(countParams, sepStartStrUnix)
1270
+		countParams = append(countParams, sepEndStrsUnix)
1271
+		countParams = append(countParams, octStartStrUnix)
1272
+		countParams = append(countParams, octEndStrsUnix)
1273
+		countParams = append(countParams, novStartStrUnix)
1274
+		countParams = append(countParams, novEndStrsUnix)
1275
+		countParams = append(countParams, decStartStrUnix)
1276
+		countParams = append(countParams, decEndStrsUnix)
1277
+		if orgid > 0 {
1278
+			db = db.Where("x.org_id=?", orgid)
1279
+			countSQL += " AND x.org_id=?"
1280
+			countParams = append(countParams, orgid)
1281
+		}
1282
+		if modetype > 0 {
1283
+			db = db.Where("x.item_id = ?", modetype)
1284
+			countSQL += " AND x.item_id=?"
1285
+			countParams = append(countParams, modetype)
1286
+		}
1287
+		if januaryStartStrUnix > 0 {
1288
+			db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1289
+			countSQL += " AND x.inspect_date >=?"
1290
+			countParams = append(countParams, januaryStartStrUnix)
1291
+		}
1292
+		if decEndStrsUnix > 0 {
1293
+			db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1294
+			countSQL += " AND x.inspect_date <=?"
1295
+			countParams = append(countParams, decEndStrsUnix)
1296
+		}
1297
+		countSQL += ")a GROUP BY nnd"
1298
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1299
+	}
1300
+	return
1301
+}
1302
+
1303
+func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
1304
+
1305
+	if lapseto == 0 {
1306
+		d := XTReadDB().Table("xt_patients as s")
1307
+		fmt.Println("d", d)
1308
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1309
+		table := XTReadDB().Table("xt_inspection_reference as r")
1310
+		fmt.Println(table)
1311
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1312
+			"SELECT " +
1313
+			"CASE " +
1314
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '一月'" +
1315
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '二月'" +
1316
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '三月'" +
1317
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '四月'" +
1318
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '五月'" +
1319
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '六月'" +
1320
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '七月'" +
1321
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '八月'" +
1322
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '九月'" +
1323
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十月'" +
1324
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十一月'" +
1325
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十二月'" +
1326
+			" ELSE '其他'" +
1327
+			"END AS nnd FROM xt_inspection as x left join xt_inspection_reference as  r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1328
+		countParams := make([]interface{}, 0)
1329
+		countParams = append(countParams, januaryStartStrUnix)
1330
+		countParams = append(countParams, januaryEndStrUnix)
1331
+		countParams = append(countParams, febStartStrStrUnix)
1332
+		countParams = append(countParams, febEndStrUnix)
1333
+		countParams = append(countParams, marchStartStrUnix)
1334
+		countParams = append(countParams, marchEndStrUnix)
1335
+		countParams = append(countParams, aprStartStrUnix)
1336
+		countParams = append(countParams, aprEndStrsUnix)
1337
+		countParams = append(countParams, mayStartStrUnix)
1338
+		countParams = append(countParams, mayEndStrsUnix)
1339
+		countParams = append(countParams, junStartStrUnix)
1340
+		countParams = append(countParams, junEndStrsUnix)
1341
+		countParams = append(countParams, julStartStrUnix)
1342
+		countParams = append(countParams, julEndStrsUnix)
1343
+		countParams = append(countParams, augStartStrUnix)
1344
+		countParams = append(countParams, augEndStrsUnix)
1345
+		countParams = append(countParams, sepStartStrUnix)
1346
+		countParams = append(countParams, sepEndStrsUnix)
1347
+		countParams = append(countParams, octStartStrUnix)
1348
+		countParams = append(countParams, octEndStrsUnix)
1349
+		countParams = append(countParams, novStartStrUnix)
1350
+		countParams = append(countParams, novEndStrsUnix)
1351
+		countParams = append(countParams, decStartStrUnix)
1352
+		countParams = append(countParams, decEndStrsUnix)
1353
+		if orgid > 0 {
1354
+			db = db.Where("x.org_id=?", orgid)
1355
+			countSQL += " AND x.org_id=?"
1356
+			countParams = append(countParams, orgid)
1357
+		}
1358
+		if modetype > 0 {
1359
+			db = db.Where("x.item_id = ?", modetype)
1360
+			countSQL += " AND x.item_id=?"
1361
+			countParams = append(countParams, modetype)
1362
+		}
1363
+		if januaryStartStrUnix > 0 {
1364
+			db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1365
+			countSQL += " AND x.inspect_date >=?"
1366
+			countParams = append(countParams, januaryStartStrUnix)
1367
+		}
1368
+		if decEndStrsUnix > 0 {
1369
+			db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1370
+			countSQL += " AND x.inspect_date <=?"
1371
+			countParams = append(countParams, decEndStrsUnix)
1372
+		}
1373
+		countSQL += ")a GROUP BY nnd"
1374
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1375
+	}
1376
+
1377
+	if lapseto == 1 {
1378
+
1379
+		d := XTReadDB().Table("xt_patients as s")
1380
+		fmt.Println("d", d)
1381
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1382
+		table := XTReadDB().Table("xt_inspection_reference as r")
1383
+		fmt.Println(table)
1384
+		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1385
+			"SELECT " +
1386
+			"CASE " +
1387
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '一月'" +
1388
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '二月'" +
1389
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '三月'" +
1390
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '四月'" +
1391
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '五月'" +
1392
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '六月'" +
1393
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '七月'" +
1394
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '八月'" +
1395
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '九月'" +
1396
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十月'" +
1397
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十一月'" +
1398
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十二月'" +
1399
+			" ELSE '其他'" +
1400
+			"END AS nnd FROM xt_inspection as x left join xt_inspection_reference as  r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1401
+		countParams := make([]interface{}, 0)
1402
+		countParams = append(countParams, januaryStartStrUnix)
1403
+		countParams = append(countParams, januaryEndStrUnix)
1404
+		countParams = append(countParams, febStartStrStrUnix)
1405
+		countParams = append(countParams, febEndStrUnix)
1406
+		countParams = append(countParams, marchStartStrUnix)
1407
+		countParams = append(countParams, marchEndStrUnix)
1408
+		countParams = append(countParams, aprStartStrUnix)
1409
+		countParams = append(countParams, aprEndStrsUnix)
1410
+		countParams = append(countParams, mayStartStrUnix)
1411
+		countParams = append(countParams, mayEndStrsUnix)
1412
+		countParams = append(countParams, junStartStrUnix)
1413
+		countParams = append(countParams, junEndStrsUnix)
1414
+		countParams = append(countParams, julStartStrUnix)
1415
+		countParams = append(countParams, julEndStrsUnix)
1416
+		countParams = append(countParams, augStartStrUnix)
1417
+		countParams = append(countParams, augEndStrsUnix)
1418
+		countParams = append(countParams, sepStartStrUnix)
1419
+		countParams = append(countParams, sepEndStrsUnix)
1420
+		countParams = append(countParams, octStartStrUnix)
1421
+		countParams = append(countParams, octEndStrsUnix)
1422
+		countParams = append(countParams, novStartStrUnix)
1423
+		countParams = append(countParams, novEndStrsUnix)
1424
+		countParams = append(countParams, decStartStrUnix)
1425
+		countParams = append(countParams, decEndStrsUnix)
1426
+		if orgid > 0 {
1427
+			db = db.Where("x.org_id=?", orgid)
1428
+			countSQL += " AND x.org_id=?"
1429
+			countParams = append(countParams, orgid)
1430
+		}
1431
+		if modetype > 0 {
1432
+			db = db.Where("x.item_id = ?", modetype)
1433
+			countSQL += " AND x.item_id=?"
1434
+			countParams = append(countParams, modetype)
1435
+		}
1436
+		if januaryStartStrUnix > 0 {
1437
+			db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1438
+			countSQL += " AND x.inspect_date >=?"
1439
+			countParams = append(countParams, januaryStartStrUnix)
1440
+		}
1441
+		if decEndStrsUnix > 0 {
1442
+			db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1443
+			countSQL += " AND x.inspect_date <=?"
1444
+			countParams = append(countParams, decEndStrsUnix)
1445
+		}
1446
+		countSQL += ")a GROUP BY nnd"
1447
+		err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1448
+
1449
+		if lapseto == 2 {
1450
+
1451
+			d := XTReadDB().Table("xt_patients as s")
1452
+			fmt.Println("d", d)
1453
+			db := readDb.Table("xt_inspection as x ").Where("x.status=1")
1454
+			table := XTReadDB().Table("xt_inspection_reference as r")
1455
+			fmt.Println(table)
1456
+			countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1457
+				"SELECT " +
1458
+				"CASE " +
1459
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '一月'" +
1460
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '二月'" +
1461
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '三月'" +
1462
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '四月'" +
1463
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '五月'" +
1464
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '六月'" +
1465
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '七月'" +
1466
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '八月'" +
1467
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '九月'" +
1468
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十月'" +
1469
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十一月'" +
1470
+				" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0  THEN '十二月'" +
1471
+				" ELSE '其他'" +
1472
+				"END AS nnd FROM xt_inspection as x left join xt_inspection_reference as  r on r.id = x.item_id left join xt_patients as s on s.id = x.patient_id  WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
1473
+			countParams := make([]interface{}, 0)
1474
+			countParams = append(countParams, januaryStartStrUnix)
1475
+			countParams = append(countParams, januaryEndStrUnix)
1476
+			countParams = append(countParams, febStartStrStrUnix)
1477
+			countParams = append(countParams, febEndStrUnix)
1478
+			countParams = append(countParams, marchStartStrUnix)
1479
+			countParams = append(countParams, marchEndStrUnix)
1480
+			countParams = append(countParams, aprStartStrUnix)
1481
+			countParams = append(countParams, aprEndStrsUnix)
1482
+			countParams = append(countParams, mayStartStrUnix)
1483
+			countParams = append(countParams, mayEndStrsUnix)
1484
+			countParams = append(countParams, junStartStrUnix)
1485
+			countParams = append(countParams, junEndStrsUnix)
1486
+			countParams = append(countParams, julStartStrUnix)
1487
+			countParams = append(countParams, julEndStrsUnix)
1488
+			countParams = append(countParams, augStartStrUnix)
1489
+			countParams = append(countParams, augEndStrsUnix)
1490
+			countParams = append(countParams, sepStartStrUnix)
1491
+			countParams = append(countParams, sepEndStrsUnix)
1492
+			countParams = append(countParams, octStartStrUnix)
1493
+			countParams = append(countParams, octEndStrsUnix)
1494
+			countParams = append(countParams, novStartStrUnix)
1495
+			countParams = append(countParams, novEndStrsUnix)
1496
+			countParams = append(countParams, decStartStrUnix)
1497
+			countParams = append(countParams, decEndStrsUnix)
1498
+			if orgid > 0 {
1499
+				db = db.Where("x.org_id=?", orgid)
1500
+				countSQL += " AND x.org_id=?"
1501
+				countParams = append(countParams, orgid)
1502
+			}
1503
+			if modetype > 0 {
1504
+				db = db.Where("x.item_id = ?", modetype)
1505
+				countSQL += " AND x.item_id=?"
1506
+				countParams = append(countParams, modetype)
1507
+			}
1508
+			if januaryStartStrUnix > 0 {
1509
+				db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
1510
+				countSQL += " AND x.inspect_date >=?"
1511
+				countParams = append(countParams, januaryStartStrUnix)
1512
+			}
1513
+			if decEndStrsUnix > 0 {
1514
+				db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
1515
+				countSQL += " AND x.inspect_date <=?"
1516
+				countParams = append(countParams, decEndStrsUnix)
1517
+			}
1518
+			countSQL += ")a GROUP BY nnd"
1519
+			err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
1520
+		}
1521
+	}
1522
+	return
1523
+}