Kaynağa Gözat

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

csx 4 yıl önce
ebeveyn
işleme
2a35f35536

+ 4 - 4
controllers/base_api_controller.go Dosyayı Görüntüle

@@ -81,7 +81,7 @@ func (this *BaseAuthAPIController) Prepare() {
81 81
 		userAdmin.ModifyTime = 1530786071
82 82
 		var subscibe models.ServeSubscibe
83 83
 		subscibe.ID = 1
84
-		subscibe.OrgId = 9841
84
+		subscibe.OrgId = 7957
85 85
 		subscibe.PeriodStart = 1538035409
86 86
 		subscibe.PeriodEnd = 1569571409
87 87
 		subscibe.State = 1
@@ -91,7 +91,7 @@ func (this *BaseAuthAPIController) Prepare() {
91 91
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
92 92
 		subscibes[4] = &subscibe
93 93
 		var adminUserInfo service.AdminUserInfo
94
-		adminUserInfo.CurrentOrgId = 9841
94
+		adminUserInfo.CurrentOrgId = 7957
95 95
 		adminUserInfo.CurrentAppId = 18
96 96
 		adminUserInfo.AdminUser = &userAdmin
97 97
 		adminUserInfo.Subscibes = subscibes
@@ -326,7 +326,7 @@ func (this *BaseServeAPIController) Prepare() {
326 326
 		userAdmin.ModifyTime = 1530786071
327 327
 		var subscibe models.ServeSubscibe
328 328
 		subscibe.ID = 1
329
-		subscibe.OrgId = 9841
329
+		subscibe.OrgId = 7957
330 330
 		subscibe.PeriodStart = 1538035409
331 331
 		subscibe.PeriodEnd = 1569571409
332 332
 		subscibe.State = 1
@@ -336,7 +336,7 @@ func (this *BaseServeAPIController) Prepare() {
336 336
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
337 337
 		subscibes[4] = &subscibe
338 338
 		var adminUserInfo service.AdminUserInfo
339
-		adminUserInfo.CurrentOrgId = 9841
339
+		adminUserInfo.CurrentOrgId = 7957
340 340
 		adminUserInfo.CurrentAppId = 18
341 341
 		adminUserInfo.AdminUser = &userAdmin
342 342
 		adminUserInfo.Subscibes = subscibes

+ 2 - 2
controllers/mobile_api_controllers/login_api_controller.go Dosyayı Görüntüle

@@ -32,8 +32,8 @@ func (this *LoginAPIController) LoginByPwd() {
32 32
 	}
33 33
 	ip := utils.GetIP(this.Ctx.Request)
34 34
 
35
-	ssoDomain := beego.AppConfig.String("sso_domain")
36
-	//ssoDomain := "http://localhost:8091"
35
+	//ssoDomain := beego.AppConfig.String("sso_domain")
36
+	ssoDomain := "http://localhost:8091"
37 37
 	api := ssoDomain + "/m/login/pwd"
38 38
 	values := make(url.Values)
39 39
 	values.Set("mobile", mobile)

+ 192 - 75
controllers/new_mobile_api_controllers/common_api_controller.go Dosyayı Görüntüle

@@ -21,7 +21,6 @@ func (this *CommonApiController) GetInspectionMajor() {
21 21
 	adminInfo := this.GetAdminUserInfo()
22 22
 	orgid := adminInfo.CurrentOrgId
23 23
 	major, err := service.GetInspectionMajor(orgid)
24
-
25 24
 	if len(major) == 0 {
26 25
 		major, _ := service.GetInspectionMajor(0)
27 26
 		if err != nil {
@@ -106,32 +105,67 @@ func (this *CommonApiController) SaveConfiguration() {
106 105
 	if rangvalue == "0" {
107 106
 		rangvalue = ""
108 107
 	}
109
-	_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
110
-	if errcode == gorm.ErrRecordNotFound {
111
-		standard := models.XtQualityControlStandard{
112
-			InspectionMajor: inspectionmajor,
113
-			InspectionMinor: inspectionMinor,
114
-			MinRange:        minrange,
115
-			LargeRange:      largerange,
116
-			Sort:            sorts,
117
-			UserOrgId:       orgid,
118
-			Status:          1,
119
-			RangeType:       checktype,
120
-			RangeValue:      rangvalue,
121
-			CreatedTime:     time.Now().Unix(),
108
+	// 参与集成的机构根据小项id获取item_id
109
+	itemid, err := service.GetItemid(inspectionMinor)
110
+	//查询小项是否有值
111
+	fmt.Println("小项id", itemid.ItemId)
112
+	major, err := service.GetInspectionMajor(orgid)
113
+	if len(major) == 0 {
114
+		_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
115
+		if errcode == gorm.ErrRecordNotFound {
116
+			standard := models.XtQualityControlStandard{
117
+				InspectionMajor: inspectionmajor,
118
+				InspectionMinor: inspectionMinor,
119
+				MinRange:        minrange,
120
+				LargeRange:      largerange,
121
+				Sort:            sorts,
122
+				UserOrgId:       orgid,
123
+				Status:          1,
124
+				RangeType:       checktype,
125
+				RangeValue:      rangvalue,
126
+				CreatedTime:     time.Now().Unix(),
127
+			}
128
+			fmt.Println(standard)
129
+			err = service.SaveInspection(&standard)
130
+			if err != nil {
131
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
132
+				return
133
+			}
134
+			this.ServeSuccessJSON(map[string]interface{}{
135
+				"standard": standard,
136
+			})
137
+		} else if errcode == nil {
138
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
139
+			return
122 140
 		}
123
-		fmt.Println(standard)
124
-		err = service.SaveInspection(&standard)
125
-		if err != nil {
126
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
141
+	} else {
142
+		_, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
143
+		if errcode == gorm.ErrRecordNotFound {
144
+			standard := models.XtQualityControlStandard{
145
+				InspectionMajor: inspectionmajor,
146
+				InspectionMinor: itemid.ItemId,
147
+				MinRange:        minrange,
148
+				LargeRange:      largerange,
149
+				Sort:            sorts,
150
+				UserOrgId:       orgid,
151
+				Status:          1,
152
+				RangeType:       checktype,
153
+				RangeValue:      rangvalue,
154
+				CreatedTime:     time.Now().Unix(),
155
+			}
156
+			fmt.Println(standard)
157
+			err = service.SaveInspection(&standard)
158
+			if err != nil {
159
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
160
+				return
161
+			}
162
+			this.ServeSuccessJSON(map[string]interface{}{
163
+				"standard": standard,
164
+			})
165
+		} else if errcode == nil {
166
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
127 167
 			return
128 168
 		}
129
-		this.ServeSuccessJSON(map[string]interface{}{
130
-			"standard": standard,
131
-		})
132
-	} else if errcode == nil {
133
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
134
-		return
135 169
 	}
136 170
 
137 171
 }
@@ -141,40 +175,87 @@ func (this *CommonApiController) GetConfigurationlist() {
141 175
 	page, _ := this.GetInt64("page")
142 176
 	adminUser := this.GetAdminUserInfo()
143 177
 	orgid := adminUser.CurrentOrgId
144
-	configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page)
145
-	if err != nil {
146
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
147
-		return
178
+	major, _ := service.GetInspectionMajor(orgid)
179
+	if len(major) == 0 {
180
+		configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page)
181
+		if err != nil {
182
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
183
+			return
184
+		}
185
+		this.ServeSuccessJSON(map[string]interface{}{
186
+			"configurationlist": configurationlist,
187
+			"total":             total,
188
+		})
189
+	} else {
190
+		configurationlist, total, err := service.GetConfigurationListTwo(orgid, limit, page)
191
+		if err != nil {
192
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
193
+			return
194
+		}
195
+		this.ServeSuccessJSON(map[string]interface{}{
196
+			"configurationlist": configurationlist,
197
+			"total":             total,
198
+		})
148 199
 	}
149
-	this.ServeSuccessJSON(map[string]interface{}{
150
-		"configurationlist": configurationlist,
151
-		"total":             total,
152
-	})
200
+
153 201
 }
154 202
 
155 203
 func (this *CommonApiController) GetConfigurationDetail() {
156 204
 	id, _ := this.GetInt64("id")
157 205
 	//fmt.Println("id是", id)
206
+	orgId := this.GetAdminUserInfo().CurrentOrgId
158 207
 	detail, err := service.GetConfigurationDetail(id)
159
-	if err != nil {
160
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
161
-		return
208
+	major, err := service.GetInspectionMajor(orgId)
209
+	var vid = 0
210
+	if len(major) == 0 {
211
+		if err != nil {
212
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
213
+			return
214
+		}
215
+		this.ServeSuccessJSON(map[string]interface{}{
216
+			"configurationdetail": detail,
217
+			"vid":                 vid,
218
+		})
219
+	} else {
220
+		itemId, err := service.GetIdByItemId(detail.InspectionMinor, orgId)
221
+		if err != nil {
222
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
223
+			return
224
+		}
225
+		this.ServeSuccessJSON(map[string]interface{}{
226
+			"configurationdetail": detail,
227
+			"vid":                 itemId.ID,
228
+		})
162 229
 	}
163
-	this.ServeSuccessJSON(map[string]interface{}{
164
-		"configurationdetail": detail,
165
-	})
230
+
166 231
 }
167 232
 
168 233
 func (this *CommonApiController) GetAllInspectionminor() {
169 234
 
170
-	minor, err := service.GetAllInspectionMinor(0)
171
-	if err != nil {
172
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
173
-		return
235
+	info := this.GetAdminUserInfo()
236
+	orgid := info.CurrentOrgId
237
+	major, _ := service.GetInspectionMajor(orgid)
238
+
239
+	if len(major) == 0 {
240
+		minor, err := service.GetAllInspectionMinor(0)
241
+		if err != nil {
242
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
243
+			return
244
+		}
245
+		this.ServeSuccessJSON(map[string]interface{}{
246
+			"minor": minor,
247
+		})
248
+	} else {
249
+		minor, err := service.GetAllInspectionMinor(orgid)
250
+		if err != nil {
251
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
252
+			return
253
+		}
254
+		this.ServeSuccessJSON(map[string]interface{}{
255
+			"minor": minor,
256
+		})
174 257
 	}
175
-	this.ServeSuccessJSON(map[string]interface{}{
176
-		"minor": minor,
177
-	})
258
+
178 259
 }
179 260
 
180 261
 func (this *CommonApiController) UpdateConfiguration() {
@@ -207,27 +288,54 @@ func (this *CommonApiController) UpdateConfiguration() {
207 288
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
208 289
 		return
209 290
 	}
210
-	standard := models.XtQualityControlStandard{
211
-		InspectionMajor: inspectionmajor,
212
-		InspectionMinor: inspectionMinor,
213
-		MinRange:        minrange,
214
-		LargeRange:      largerange,
215
-		Sort:            sort,
216
-		RangeValue:      rangvalue,
217
-		RangeType:       rangtype,
218
-		Status:          1,
219
-		UserOrgId:       orgId,
220
-		CreatedTime:     time.Now().Unix(),
221
-		UpdatedTime:     time.Now().Unix(),
222
-	}
223
-	err = service.UpdarteConfiguration(&standard, id)
224
-	if err != nil {
225
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
226
-		return
291
+
292
+	major, err := service.GetInspectionMajor(orgId)
293
+	if len(major) == 0 {
294
+		standard := models.XtQualityControlStandard{
295
+			InspectionMajor: inspectionmajor,
296
+			InspectionMinor: inspectionMinor,
297
+			MinRange:        minrange,
298
+			LargeRange:      largerange,
299
+			Sort:            sort,
300
+			RangeValue:      rangvalue,
301
+			RangeType:       rangtype,
302
+			Status:          1,
303
+			UserOrgId:       orgId,
304
+			CreatedTime:     time.Now().Unix(),
305
+			UpdatedTime:     time.Now().Unix(),
306
+		}
307
+		err = service.UpdarteConfiguration(&standard, id)
308
+		if err != nil {
309
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
310
+			return
311
+		}
312
+		this.ServeSuccessJSON(map[string]interface{}{
313
+			"standard": standard,
314
+		})
315
+	} else {
316
+		itemid, _ := service.GetItemid(inspectionMinor)
317
+		standard := models.XtQualityControlStandard{
318
+			InspectionMajor: inspectionmajor,
319
+			InspectionMinor: itemid.ItemId,
320
+			MinRange:        minrange,
321
+			LargeRange:      largerange,
322
+			Sort:            sort,
323
+			RangeValue:      rangvalue,
324
+			RangeType:       rangtype,
325
+			Status:          1,
326
+			UserOrgId:       orgId,
327
+			CreatedTime:     time.Now().Unix(),
328
+			UpdatedTime:     time.Now().Unix(),
329
+		}
330
+		err = service.UpdarteConfiguration(&standard, id)
331
+		if err != nil {
332
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
333
+			return
334
+		}
335
+		this.ServeSuccessJSON(map[string]interface{}{
336
+			"standard": standard,
337
+		})
227 338
 	}
228
-	this.ServeSuccessJSON(map[string]interface{}{
229
-		"standard": standard,
230
-	})
231 339
 
232 340
 }
233 341
 
@@ -1283,9 +1391,9 @@ func (this *CommonApiController) GetPatientscontrol() {
1283 1391
 	limit, _ := this.GetInt64("limit")
1284 1392
 	fmt.Println("limit", limit)
1285 1393
 	patients, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
1286
-	//统计非传染病类型
1394
+
1287 1395
 	control, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1288
-	//统计传染病类型
1396
+
1289 1397
 	infectiousControl, err := service.GetInfectiousControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1290 1398
 
1291 1399
 	if err != nil {
@@ -1318,20 +1426,29 @@ func (this *CommonApiController) GetCartogramList() {
1318 1426
 	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
1319 1427
 	endtimeStrsUnix := endtimeStrs.Unix()
1320 1428
 	fmt.Println("结束时间搓", endtimeStrsUnix)
1321
-	limit, _ := this.GetInt64("limit")
1322
-	page, _ := this.GetInt64("page")
1323
-	cartogramlist, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1324
-	infectiouscontrol, err := service.GetInfectiousPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1325
-	_, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
1429
+	//limit, _ := this.GetInt64("limit")
1430
+	//page, _ := this.GetInt64("page")
1431
+
1432
+	//统计总共
1433
+	_, total, err := service.GetTotalPatientsControl(orgid, startimeStrUnix, endtimeStrsUnix)
1434
+	fmt.Println("total=================", total)
1435
+	//统计rangetype= 1
1436
+	_, standtotal, err := service.GetStandControl(orgid, startimeStrUnix, endtimeStrsUnix)
1437
+	fmt.Println(standtotal)
1438
+	_, standtotalOne, err := service.GetStandControlOne(orgid, startimeStrUnix, endtimeStrsUnix)
1439
+	fmt.Println(standtotalOne)
1440
+	//cartogramlist, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1441
+	//infectiouscontrol, err := service.GetInfectiousPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
1442
+	//_, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
1326 1443
 	if err != nil {
1327 1444
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1328 1445
 		return
1329 1446
 	}
1330 1447
 
1331 1448
 	this.ServeSuccessJSON(map[string]interface{}{
1332
-		"cartogramlist":     cartogramlist,
1333
-		"total":             total,
1334
-		"infectiouscontrol": infectiouscontrol,
1449
+		"total":         total,
1450
+		"standtotal":    standtotal,
1451
+		"standtotalOne": standtotalOne,
1335 1452
 	})
1336 1453
 }
1337 1454
 

+ 16 - 8
controllers/new_mobile_api_controllers/new_common_api_controller.go Dosyayı Görüntüle

@@ -859,20 +859,28 @@ func (this *NewCommonApiController) GetMobileCartogramlist() {
859 859
 	endtimeStrs, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", endtimeStr)
860 860
 	endtimeStrsUnix := endtimeStrs.Unix()
861 861
 	fmt.Println("结束时间搓", endtimeStrsUnix)
862
-	limit, _ := this.GetInt64("limit")
863
-	page, _ := this.GetInt64("page")
864
-	cartogramlist, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
865
-	_, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
866
-	infectiouscontrol, err := service.GetInfectiousPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
862
+	//统计总共
863
+	_, total, err := service.GetTotalPatientsControl(orgid, startimeStrUnix, endtimeStrsUnix)
864
+	fmt.Println("total=================", total)
865
+	//统计rangetype= 1
866
+	_, standtotal, err := service.GetStandControl(orgid, startimeStrUnix, endtimeStrsUnix)
867
+	fmt.Println(standtotal)
868
+	_, standtotalOne, err := service.GetStandControlOne(orgid, startimeStrUnix, endtimeStrsUnix)
869
+	fmt.Println(standtotalOne)
870
+	//limit, _ := this.GetInt64("limit")
871
+	//page, _ := this.GetInt64("page")
872
+	//cartogramlist, err := service.GetLastPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
873
+	//_, total, err := service.GetPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix, page, limit)
874
+	//infectiouscontrol, err := service.GetInfectiousPatientsControl(orgid, lapstor, startimeStrUnix, endtimeStrsUnix)
867 875
 	if err != nil {
868 876
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
869 877
 		return
870 878
 	}
871 879
 
872 880
 	this.ServeSuccessJSON(map[string]interface{}{
873
-		"cartogramlist":     cartogramlist,
874
-		"total":             total,
875
-		"infectiouscontrol": infectiouscontrol,
881
+		"total":         total,
882
+		"standtotal":    standtotal,
883
+		"standtotalOne": standtotalOne,
876 884
 	})
877 885
 }
878 886
 

+ 191 - 84
service/common_service.go Dosyayı Görüntüle

@@ -26,6 +26,12 @@ func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
26 26
 	return reference, err
27 27
 }
28 28
 
29
+func GetItemid(id int64) (models.XtInspectionReference, error) {
30
+	reference := models.XtInspectionReference{}
31
+	err = XTReadDB().Model(&reference).Where("id = ? and status = 1", id).Find(&reference).Error
32
+	return reference, err
33
+}
34
+
29 35
 func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
30 36
 	standard := models.XtQualityControlStandard{}
31 37
 	err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
@@ -64,12 +70,31 @@ func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*mod
64 70
 	return standard, total, err
65 71
 }
66 72
 
73
+func GetConfigurationListTwo(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
74
+	db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
75
+	if orgid > 0 {
76
+		db = db.Where("x.user_org_id = ?", orgid)
77
+	}
78
+	table := XTReadDB().Table("xt_inspection_reference as s")
79
+	fmt.Println(table)
80
+	offset := (page - 1) * limit
81
+	err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name").Count(&total).
82
+		Joins("left join xt_inspection_reference as s on s.item_id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
83
+	return standard, total, err
84
+}
85
+
67 86
 func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
68 87
 	standard := models.XtQualityControlStandard{}
69 88
 	err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
70 89
 	return standard, err
71 90
 }
72 91
 
92
+func GetIdByItemId(itemid int64, orgid int64) (models.XtInspectionReference, error) {
93
+	reference := models.XtInspectionReference{}
94
+	err := XTReadDB().Model(&reference).Where("item_id = ? and org_id = ?", itemid, orgid).Find(&reference).Error
95
+	return reference, err
96
+}
97
+
73 98
 func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
74 99
 
75 100
 	err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
@@ -1854,26 +1879,26 @@ func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryS
1854 1879
 	if lapseto == 0 {
1855 1880
 		d := XTReadDB().Table("xt_patients as s")
1856 1881
 		fmt.Println("d", d)
1857
-		db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
1882
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
1858 1883
 		table := XTReadDB().Table("xt_quality_control_standard as r")
1859 1884
 		fmt.Println(table)
1860 1885
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1861 1886
 			"SELECT " +
1862 1887
 			"CASE " +
1863
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '一月'" +
1864
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '二月'" +
1865
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '三月'" +
1866
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '四月'" +
1867
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '五月'" +
1868
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '六月'" +
1869
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '七月'" +
1870
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '八月'" +
1871
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '九月'" +
1872
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十月'" +
1873
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十一月'" +
1874
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十二月'" +
1888
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '一月'" +
1889
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '二月'" +
1890
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '三月'" +
1891
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '四月'" +
1892
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '五月'" +
1893
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '六月'" +
1894
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '七月'" +
1895
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '八月'" +
1896
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '九月'" +
1897
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '十月'" +
1898
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '十一月'" +
1899
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '十二月'" +
1875 1900
 			" ELSE '其他'" +
1876
-			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 <> r.range_value)"
1901
+			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
1877 1902
 		countParams := make([]interface{}, 0)
1878 1903
 		countParams = append(countParams, januaryStartStrUnix)
1879 1904
 		countParams = append(countParams, januaryEndStrUnix)
@@ -1904,6 +1929,11 @@ func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryS
1904 1929
 			countSQL += " AND x.org_id=?"
1905 1930
 			countParams = append(countParams, orgid)
1906 1931
 		}
1932
+		if orgid > 0 {
1933
+			db = db.Where("r.user_org_id=?", orgid)
1934
+			countSQL += " AND r.user_org_id=?"
1935
+			countParams = append(countParams, orgid)
1936
+		}
1907 1937
 		if modetype > 0 {
1908 1938
 			db = db.Where("x.item_id = ?", modetype)
1909 1939
 			countSQL += " AND x.item_id=?"
@@ -1927,26 +1957,26 @@ func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryS
1927 1957
 
1928 1958
 		d := XTReadDB().Table("xt_patients as s")
1929 1959
 		fmt.Println("d", d)
1930
-		db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
1960
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
1931 1961
 		table := XTReadDB().Table("xt_quality_control_standard as r")
1932 1962
 		fmt.Println(table)
1933 1963
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
1934 1964
 			"SELECT " +
1935 1965
 			"CASE " +
1936
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '一月'" +
1937
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '二月'" +
1938
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '三月'" +
1939
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '四月'" +
1940
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '五月'" +
1941
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '六月'" +
1942
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '七月'" +
1943
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '八月'" +
1944
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '九月'" +
1945
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十月'" +
1946
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十一月'" +
1947
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十二月'" +
1966
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '一月'" +
1967
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '二月'" +
1968
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '三月'" +
1969
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '四月'" +
1970
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '五月'" +
1971
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '六月'" +
1972
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '七月'" +
1973
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '八月'" +
1974
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '九月'" +
1975
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '十月'" +
1976
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '十一月'" +
1977
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '十二月'" +
1948 1978
 			" ELSE '其他'" +
1949
-			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 <> r.range_value)"
1979
+			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
1950 1980
 		countParams := make([]interface{}, 0)
1951 1981
 		countParams = append(countParams, januaryStartStrUnix)
1952 1982
 		countParams = append(countParams, januaryEndStrUnix)
@@ -1977,6 +2007,11 @@ func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryS
1977 2007
 			countSQL += " AND x.org_id=?"
1978 2008
 			countParams = append(countParams, orgid)
1979 2009
 		}
2010
+		if orgid > 0 {
2011
+			db = db.Where("r.user_org_id=?", orgid)
2012
+			countSQL += " AND r.user_org_id=?"
2013
+			countParams = append(countParams, orgid)
2014
+		}
1980 2015
 		if modetype > 0 {
1981 2016
 			db = db.Where("x.item_id = ?", modetype)
1982 2017
 			countSQL += " AND x.item_id=?"
@@ -1999,26 +2034,26 @@ func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryS
1999 2034
 	if lapseto == 2 {
2000 2035
 		d := XTReadDB().Table("xt_patients as s")
2001 2036
 		fmt.Println("d", d)
2002
-		db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
2037
+		db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
2003 2038
 		table := XTReadDB().Table("xt_quality_control_standard as r")
2004 2039
 		fmt.Println(table)
2005 2040
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
2006 2041
 			"SELECT " +
2007 2042
 			"CASE " +
2008
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '一月'" +
2009
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '二月'" +
2010
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '三月'" +
2011
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '四月'" +
2012
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '五月'" +
2013
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '六月'" +
2014
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '七月'" +
2015
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '八月'" +
2016
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '九月'" +
2017
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十月'" +
2018
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十一月'" +
2019
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十二月'" +
2043
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '一月'" +
2044
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '二月'" +
2045
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '三月'" +
2046
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '四月'" +
2047
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '五月'" +
2048
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '六月'" +
2049
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '七月'" +
2050
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '八月'" +
2051
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '九月'" +
2052
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '十月'" +
2053
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0  THEN '十一月'" +
2054
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0   THEN '十二月'" +
2020 2055
 			" ELSE '其他'" +
2021
-			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 <> r.range_value)"
2056
+			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
2022 2057
 		countParams := make([]interface{}, 0)
2023 2058
 		countParams = append(countParams, januaryStartStrUnix)
2024 2059
 		countParams = append(countParams, januaryEndStrUnix)
@@ -2049,6 +2084,11 @@ func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryS
2049 2084
 			countSQL += " AND x.org_id=?"
2050 2085
 			countParams = append(countParams, orgid)
2051 2086
 		}
2087
+		if orgid > 0 {
2088
+			db = db.Where("r.user_org_id=?", orgid)
2089
+			countSQL += " AND r.user_org_id=?"
2090
+			countParams = append(countParams, orgid)
2091
+		}
2052 2092
 		if modetype > 0 {
2053 2093
 			db = db.Where("x.item_id = ?", modetype)
2054 2094
 			countSQL += " AND x.item_id=?"
@@ -2080,20 +2120,20 @@ func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januar
2080 2120
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
2081 2121
 			"SELECT " +
2082 2122
 			"CASE " +
2083
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '一月'" +
2084
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '二月'" +
2085
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '三月'" +
2086
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '四月'" +
2087
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '五月'" +
2088
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '六月'" +
2089
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '七月'" +
2090
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '八月'" +
2091
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '九月'" +
2092
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十月'" +
2093
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十一月'" +
2094
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十二月'" +
2123
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '一月'" +
2124
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '二月'" +
2125
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '三月'" +
2126
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '四月'" +
2127
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '五月'" +
2128
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '六月'" +
2129
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '七月'" +
2130
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '八月'" +
2131
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '九月'" +
2132
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十月'" +
2133
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十一月'" +
2134
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十二月'" +
2095 2135
 			" ELSE '其他'" +
2096
-			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 <> r.range_value)"
2136
+			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 = r.range_value)"
2097 2137
 		countParams := make([]interface{}, 0)
2098 2138
 		countParams = append(countParams, januaryStartStrUnix)
2099 2139
 		countParams = append(countParams, januaryEndStrUnix)
@@ -2124,6 +2164,11 @@ func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januar
2124 2164
 			countSQL += " AND x.org_id=?"
2125 2165
 			countParams = append(countParams, orgid)
2126 2166
 		}
2167
+		if orgid > 0 {
2168
+			db = db.Where("r.user_org_id=?", orgid)
2169
+			countSQL += " AND r.user_org_id=?"
2170
+			countParams = append(countParams, orgid)
2171
+		}
2127 2172
 		if modetype > 0 {
2128 2173
 			db = db.Where("x.item_id = ?", modetype)
2129 2174
 			countSQL += " AND x.item_id=?"
@@ -2153,20 +2198,20 @@ func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januar
2153 2198
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
2154 2199
 			"SELECT " +
2155 2200
 			"CASE " +
2156
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '一月'" +
2157
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '二月'" +
2158
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '三月'" +
2159
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '四月'" +
2160
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '五月'" +
2161
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '六月'" +
2162
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '七月'" +
2163
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '八月'" +
2164
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '九月'" +
2165
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十月'" +
2166
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十一月'" +
2167
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十二月'" +
2201
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '一月'" +
2202
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '二月'" +
2203
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '三月'" +
2204
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '四月'" +
2205
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '五月'" +
2206
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '六月'" +
2207
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '七月'" +
2208
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '八月'" +
2209
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '九月'" +
2210
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十月'" +
2211
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十一月'" +
2212
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十二月'" +
2168 2213
 			" ELSE '其他'" +
2169
-			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 <> r.range_value)"
2214
+			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 = r.range_value)"
2170 2215
 		countParams := make([]interface{}, 0)
2171 2216
 		countParams = append(countParams, januaryStartStrUnix)
2172 2217
 		countParams = append(countParams, januaryEndStrUnix)
@@ -2197,6 +2242,11 @@ func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januar
2197 2242
 			countSQL += " AND x.org_id=?"
2198 2243
 			countParams = append(countParams, orgid)
2199 2244
 		}
2245
+		if orgid > 0 {
2246
+			db = db.Where("r.user_org_id=?", orgid)
2247
+			countSQL += " AND r.user_org_id=?"
2248
+			countParams = append(countParams, orgid)
2249
+		}
2200 2250
 		if modetype > 0 {
2201 2251
 			db = db.Where("x.item_id = ?", modetype)
2202 2252
 			countSQL += " AND x.item_id=?"
@@ -2225,20 +2275,20 @@ func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januar
2225 2275
 		countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
2226 2276
 			"SELECT " +
2227 2277
 			"CASE " +
2228
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '一月'" +
2229
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '二月'" +
2230
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '三月'" +
2231
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '四月'" +
2232
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '五月'" +
2233
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '六月'" +
2234
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '七月'" +
2235
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '八月'" +
2236
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '九月'" +
2237
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十月'" +
2238
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十一月'" +
2239
-			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value <> r.range_value  THEN '十二月'" +
2278
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '一月'" +
2279
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '二月'" +
2280
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '三月'" +
2281
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '四月'" +
2282
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '五月'" +
2283
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '六月'" +
2284
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '七月'" +
2285
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '八月'" +
2286
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '九月'" +
2287
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十月'" +
2288
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十一月'" +
2289
+			" WHEN x.inspect_date>=? AND  x.inspect_date<=? and x.inspect_value = r.range_value  THEN '十二月'" +
2240 2290
 			" ELSE '其他'" +
2241
-			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 <> r.range_value)"
2291
+			"END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = 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 = r.range_value)"
2242 2292
 		countParams := make([]interface{}, 0)
2243 2293
 		countParams = append(countParams, januaryStartStrUnix)
2244 2294
 		countParams = append(countParams, januaryEndStrUnix)
@@ -2269,6 +2319,11 @@ func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januar
2269 2319
 			countSQL += " AND x.org_id=?"
2270 2320
 			countParams = append(countParams, orgid)
2271 2321
 		}
2322
+		if orgid > 0 {
2323
+			db = db.Where("r.user_org_id=?", orgid)
2324
+			countSQL += " AND r.user_org_id=?"
2325
+			countParams = append(countParams, orgid)
2326
+		}
2272 2327
 		if modetype > 0 {
2273 2328
 			db = db.Where("x.item_id = ?", modetype)
2274 2329
 			countSQL += " AND x.item_id=?"
@@ -2355,6 +2410,58 @@ func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime
2355 2410
 	return inspection, err
2356 2411
 }
2357 2412
 
2413
+func GetTotalPatientsControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
2414
+	db := readDb.Table("xt_inspection as x").Where("x.status = 1")
2415
+	table := readDb.Table("xt_quality_control_standard as s")
2416
+	fmt.Println(table)
2417
+	if orgid > 0 {
2418
+		db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
2419
+	}
2420
+	if startime > 0 {
2421
+		db = db.Where("x.inspect_date >=?", startime)
2422
+	}
2423
+	if endtime > 0 {
2424
+		db = db.Where("x.inspect_date <=?", endtime)
2425
+	}
2426
+	err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("s.status = 1").Count(&total).Scan(&inspection).Error
2427
+	return inspection, total, err
2428
+}
2429
+func GetStandControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
2430
+	db := readDb.Table("xt_inspection as x").Where("x.status = 1")
2431
+	table := readDb.Table("xt_quality_control_standard as s")
2432
+	fmt.Println(table)
2433
+	if orgid > 0 {
2434
+		db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1 ", orgid)
2435
+	}
2436
+	if startime > 0 {
2437
+		db = db.Where("x.inspect_date >=?", startime)
2438
+	}
2439
+	if endtime > 0 {
2440
+		db = db.Where("x.inspect_date <=?", endtime)
2441
+	}
2442
+	db = db.Where("s.status = 1")
2443
+	err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value+0 >= s.min_range + 0 and x.inspect_value+0 <= s.large_range + 0 ").Count(&total).Scan(&inspection).Error
2444
+	return inspection, total, err
2445
+}
2446
+
2447
+func GetStandControlOne(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
2448
+	db := readDb.Table("xt_inspection as x").Where("x.status = 1")
2449
+	table := readDb.Table("xt_quality_control_standard as s")
2450
+	fmt.Println(table)
2451
+	if orgid > 0 {
2452
+		db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2 ", orgid)
2453
+	}
2454
+	if startime > 0 {
2455
+		db = db.Where("x.inspect_date >=?", startime)
2456
+	}
2457
+	if endtime > 0 {
2458
+		db = db.Where("x.inspect_date <=?", endtime)
2459
+	}
2460
+	db = db.Where("s.status = 1")
2461
+	err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value = s.range_value").Count(&total).Scan(&inspection).Error
2462
+	return inspection, total, err
2463
+}
2464
+
2358 2465
 func GetInfectiousPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
2359 2466
 	db := readDb.Table("xt_inspection as x").Where("x.status =1")
2360 2467
 	table := readDb.Table("xt_patients as s")
@@ -2492,7 +2599,7 @@ func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime
2492 2599
 	if inspectdate > 0 {
2493 2600
 		db = db.Where("x.inspect_date = ?", inspectdate)
2494 2601
 	}
2495
-	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
2602
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
2496 2603
 
2497 2604
 	return inspection, err
2498 2605
 }
@@ -2507,7 +2614,7 @@ func GetPatientComplianceDetail(orgid int64, patientid int64, startime int64, en
2507 2614
 	fmt.Println("d2", d2)
2508 2615
 
2509 2616
 	if orgid > 0 {
2510
-		db = db.Where("x.org_id = ?", orgid)
2617
+		db = db.Where("x.org_id = ? and (x.inspect_value <> '' or x.inspect_value+0 <> 0)", orgid)
2511 2618
 	}
2512 2619
 	if patientid > 0 {
2513 2620
 		db = db.Where("x.patient_id = ?", patientid)
@@ -2522,7 +2629,7 @@ func GetPatientComplianceDetail(orgid int64, patientid int64, startime int64, en
2522 2629
 		db = db.Where("x.item_id = ?", itemid)
2523 2630
 	}
2524 2631
 
2525
-	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
2632
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
2526 2633
 
2527 2634
 	return inspection, err
2528 2635
 }