Browse Source

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

XMLWAN 4 years ago
parent
commit
ea26229729

+ 75 - 15
controllers/new_mobile_api_controllers/index_evaluation_api_controller.go View File

@@ -46,32 +46,29 @@ func (this *IndexEvaluationApiController) GetLaboratoryIndexProjectRangeValueDat
46 46
 	adminUserInfo := this.GetMobileAdminUserInfo()
47 47
 	var range_vaule []string
48 48
 	if range_type == 1 {
49
-		qcs, _ := statistics_service.FindOrgConfigRnageTypeValue(adminUserInfo.Org.Id, project_id, item_id)
49
+		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
50 50
 		if qcs.ID == 0 { //没有配置选项
51 51
 			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.Org.Id) //判断是否为集成过来的数据
52 52
 			if count <= 0 {                                                             //不是,读系统参考值
53 53
 				reference, _ := statistics_service.FindProcjectInspectionReference(0, project_id, item_id)
54
-				range_vaule = append(range_vaule, "小于"+reference.RangeMin)
55
-				range_vaule = append(range_vaule, reference.RangeMin+"~"+reference.RangeMax)
56
-				range_vaule = append(range_vaule, "大于"+reference.RangeMax)
54
+				range_vaule = append(range_vaule, reference.RangeMin)
55
+				range_vaule = append(range_vaule, reference.RangeMax)
57 56
 
58 57
 			} else { //是,读集成过来的参考值
59 58
 				reference, _ := statistics_service.FindProcjectInspectionReference(adminUserInfo.Org.Id, project_id, item_id)
60
-				range_vaule = append(range_vaule, "小于"+reference.RangeMin)
61
-				range_vaule = append(range_vaule, reference.RangeMin+"~"+reference.RangeMax)
62
-				range_vaule = append(range_vaule, "大于"+reference.RangeMax)
59
+				range_vaule = append(range_vaule, reference.RangeMin)
60
+				range_vaule = append(range_vaule, reference.RangeMax)
63 61
 			}
64 62
 
65 63
 		} else { //有配置
66
-			range_vaule = append(range_vaule, "小于"+qcs.MinRange)
67
-			range_vaule = append(range_vaule, qcs.MinRange+"~"+qcs.LargeRange)
68
-			range_vaule = append(range_vaule, "大于"+qcs.LargeRange)
64
+			range_vaule = append(range_vaule, qcs.MinRange)
65
+			range_vaule = append(range_vaule, qcs.LargeRange)
69 66
 
70 67
 		}
71 68
 
72 69
 	} else {
73 70
 
74
-		inspection, _ := statistics_service.FindOrgInspectionReferenceRnageTypeValue(adminUserInfo.Org.Id, project_id, item_id)
71
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
75 72
 		for _, item := range inspection {
76 73
 			range_vaule = append(range_vaule, item.InspectValue)
77 74
 		}
@@ -89,7 +86,6 @@ func (this *IndexEvaluationApiController) GetInspectionChartData() {
89 86
 	project_id, _ := this.GetInt64("project_id")
90 87
 	item_id, _ := this.GetInt64("item_id")
91 88
 	range_type, _ := this.GetInt("range_type")
92
-	range_value := this.GetString("range_value")
93 89
 
94 90
 	timeLayout := "2006-01-02"
95 91
 	loc, _ := time.LoadLocation("Local")
@@ -111,6 +107,38 @@ func (this *IndexEvaluationApiController) GetInspectionChartData() {
111 107
 		theEndtTIme = theTime.Unix()
112 108
 	}
113 109
 
110
+	var range_value string
111
+	if range_type == 1 {
112
+		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
113
+		if qcs.ID == 0 { //没有配置选项
114
+			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.Org.Id) //判断是否为集成过来的数据
115
+			if count <= 0 {                                                             //不是,读系统参考值
116
+				reference, _ := statistics_service.FindProcjectInspectionReference(0, project_id, item_id)
117
+				range_value = reference.RangeMin + "," + reference.RangeMax
118
+
119
+			} else { //是,读集成过来的参考值
120
+				reference, _ := statistics_service.FindProcjectInspectionReference(adminUserInfo.Org.Id, project_id, item_id)
121
+				range_value = reference.RangeMin + "," + reference.RangeMax
122
+
123
+			}
124
+
125
+		} else { //有配置
126
+			range_value = qcs.MinRange + "," + qcs.LargeRange
127
+
128
+		}
129
+
130
+	} else {
131
+
132
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
133
+		for _, item := range inspection {
134
+			if len(range_value) == 0 {
135
+				range_value = item.InspectValue
136
+			} else {
137
+				range_value = range_value + "," + item.InspectValue
138
+			}
139
+		}
140
+	}
141
+
114 142
 	data, _ := statistics_service.GetInspectionChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, range_type, range_value)
115 143
 	this.ServeSuccessJSON(map[string]interface{}{
116 144
 		"data": data,
@@ -126,6 +154,8 @@ func (this *IndexEvaluationApiController) GetInspectionChartTableData() {
126 154
 	limit, _ := this.GetInt64("limit")
127 155
 	project_id, _ := this.GetInt64("project_id")
128 156
 	item_id, _ := this.GetInt64("item_id")
157
+	range_value := this.GetString("range_value")
158
+	range_type, _ := this.GetInt("range_type")
129 159
 
130 160
 	if page == 0 {
131 161
 		page = 1
@@ -152,7 +182,7 @@ func (this *IndexEvaluationApiController) GetInspectionChartTableData() {
152 182
 		}
153 183
 		theEndtTIme = theTime.Unix()
154 184
 	}
155
-	data, total, _ := statistics_service.GetInspectionChartTableData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, patient_id, page, limit)
185
+	data, total, _ := statistics_service.GetInspectionChartTableData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, patient_id, page, limit, range_type, range_value)
156 186
 	this.ServeSuccessJSON(map[string]interface{}{
157 187
 		"data":  data,
158 188
 		"total": total,
@@ -200,7 +230,6 @@ func (this *IndexEvaluationApiController) GetPatientInspectionBarChartData() {
200 230
 	project_id, _ := this.GetInt64("project_id")
201 231
 	item_id, _ := this.GetInt64("item_id")
202 232
 	range_type, _ := this.GetInt("range_type")
203
-	range_value := this.GetString("range_value")
204 233
 	patient_id, _ := this.GetInt64("patient_id")
205 234
 
206 235
 	timeLayout := "2006-01-02"
@@ -223,6 +252,38 @@ func (this *IndexEvaluationApiController) GetPatientInspectionBarChartData() {
223 252
 		theEndtTIme = theTime.Unix()
224 253
 	}
225 254
 
255
+	var range_value string
256
+	if range_type == 1 {
257
+		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
258
+		if qcs.ID == 0 { //没有配置选项
259
+			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.Org.Id) //判断是否为集成过来的数据
260
+			if count <= 0 {                                                             //不是,读系统参考值
261
+				reference, _ := statistics_service.FindProcjectInspectionReference(0, project_id, item_id)
262
+				range_value = reference.RangeMin + "," + reference.RangeMax
263
+
264
+			} else { //是,读集成过来的参考值
265
+				reference, _ := statistics_service.FindProcjectInspectionReference(adminUserInfo.Org.Id, project_id, item_id)
266
+				range_value = reference.RangeMin + "," + reference.RangeMax
267
+
268
+			}
269
+
270
+		} else { //有配置
271
+			range_value = qcs.MinRange + "," + qcs.LargeRange
272
+
273
+		}
274
+
275
+	} else {
276
+
277
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRangeTypeValue(adminUserInfo.Org.Id, project_id, item_id)
278
+		for _, item := range inspection {
279
+			if len(range_value) == 0 {
280
+				range_value = item.InspectValue
281
+			} else {
282
+				range_value = range_value + "," + item.InspectValue
283
+			}
284
+		}
285
+	}
286
+
226 287
 	data, _ := statistics_service.GetPatientInspectionBarChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, range_type, range_value, patient_id)
227 288
 	this.ServeSuccessJSON(map[string]interface{}{
228 289
 		"data": data,
@@ -356,7 +417,6 @@ func (this *IndexEvaluationApiController) GetDialysisProcessIndexTableData() {
356 417
 	}
357 418
 
358 419
 }
359
-
360 420
 func (this *IndexEvaluationApiController) GetDialysisWatchChartData() {
361 421
 	adminUserInfo := this.GetMobileAdminUserInfo()
362 422
 	statistics_type, _ := this.GetInt("statistics_type")

+ 284 - 0
controllers/pc_index_evaluation_api_controller.go View File

@@ -2,6 +2,7 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
+	"XT_New/models"
5 6
 	"XT_New/service/statistics_service"
6 7
 	"XT_New/utils"
7 8
 	"github.com/astaxie/beego"
@@ -10,6 +11,13 @@ import (
10 11
 
11 12
 func PCIndexEvaluationApiControllersRegisterRouters() {
12 13
 
14
+	beego.Router("/api/inspectionindex/init", &PCIndexEvaluationApiController{}, "Get:GetLaboratoryIndexInitData")
15
+	beego.Router("/api/rangevalue/get", &PCIndexEvaluationApiController{}, "Get:GetLaboratoryIndexProjectRangeValueData")
16
+	beego.Router("/api/inspectionindex/chart", &PCIndexEvaluationApiController{}, "Get:GetInspectionChartData")
17
+	beego.Router("/api/inspectionindex/table", &PCIndexEvaluationApiController{}, "Get:GetInspectionChartTableData")
18
+	beego.Router("/api/patientinspectionindex/chart", &PCIndexEvaluationApiController{}, "Get:GetPatientInspectionChartData")
19
+	beego.Router("/api/patientinspectionindex/barchart", &PCIndexEvaluationApiController{}, "Get:GetPatientInspectionBarChartData")
20
+
13 21
 	beego.Router("/api/dialysisprocessindex/chart", &PCIndexEvaluationApiController{}, "Get:GetDialysisProcessIndexChartData")
14 22
 	beego.Router("/api/dialysisprocessindex/table", &PCIndexEvaluationApiController{}, "Get:GetDialysisProcessIndexTableData")
15 23
 
@@ -39,6 +47,282 @@ type PCIndexEvaluationApiController struct {
39 47
 	BaseAuthAPIController
40 48
 }
41 49
 
50
+//化验指标
51
+
52
+//初始化数据
53
+func (this *PCIndexEvaluationApiController) GetLaboratoryIndexInitData() {
54
+	adminUserInfo := this.GetAdminUserInfo()
55
+	var references []*models.InspectionReference
56
+	count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.CurrentOrgId)
57
+	if count <= 0 {
58
+		references, _ = statistics_service.FindOrgInspectionReference(0)
59
+	} else {
60
+		references, _ = statistics_service.FindOrgInspectionReference(adminUserInfo.CurrentOrgId)
61
+	}
62
+
63
+	this.ServeSuccessJSON(map[string]interface{}{
64
+		"references": references,
65
+	})
66
+
67
+}
68
+
69
+//获取取值范围
70
+func (this *PCIndexEvaluationApiController) GetLaboratoryIndexProjectRangeValueData() {
71
+	range_type, _ := this.GetInt64("range_type")
72
+	project_id, _ := this.GetInt64("project_id")
73
+	item_id, _ := this.GetInt64("item_id")
74
+	adminUserInfo := this.GetAdminUserInfo()
75
+	var range_vaule []string
76
+	if range_type == 1 {
77
+		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.CurrentOrgId, project_id, item_id)
78
+		if qcs.ID == 0 { //没有配置选项
79
+			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.CurrentOrgId) //判断是否为集成过来的数据
80
+			if count <= 0 {                                                                   //不是,读系统参考值
81
+				reference, _ := statistics_service.FindProcjectInspectionReference(0, project_id, item_id)
82
+				range_vaule = append(range_vaule, reference.RangeMin)
83
+				range_vaule = append(range_vaule, reference.RangeMax)
84
+
85
+			} else { //是,读集成过来的参考值
86
+				reference, _ := statistics_service.FindProcjectInspectionReference(adminUserInfo.CurrentOrgId, project_id, item_id)
87
+				range_vaule = append(range_vaule, reference.RangeMin)
88
+				range_vaule = append(range_vaule, reference.RangeMax)
89
+			}
90
+
91
+		} else { //有配置
92
+			range_vaule = append(range_vaule, qcs.MinRange)
93
+			range_vaule = append(range_vaule, qcs.LargeRange)
94
+
95
+		}
96
+
97
+	} else {
98
+
99
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRangeTypeValue(adminUserInfo.CurrentOrgId, project_id, item_id)
100
+		for _, item := range inspection {
101
+			range_vaule = append(range_vaule, item.InspectValue)
102
+		}
103
+
104
+	}
105
+	this.ServeSuccessJSON(map[string]interface{}{
106
+		"range_vaule": range_vaule,
107
+	})
108
+
109
+}
110
+func (this *PCIndexEvaluationApiController) GetInspectionChartData() {
111
+	adminUserInfo := this.GetAdminUserInfo()
112
+	start_time := this.GetString("start_time")
113
+	end_time := this.GetString("end_time")
114
+	project_id, _ := this.GetInt64("project_id")
115
+	item_id, _ := this.GetInt64("item_id")
116
+	range_type, _ := this.GetInt("range_type")
117
+
118
+	timeLayout := "2006-01-02"
119
+	loc, _ := time.LoadLocation("Local")
120
+
121
+	var theStartTIme int64
122
+	if len(start_time) > 0 {
123
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
124
+		if err != nil {
125
+			utils.ErrorLog(err.Error())
126
+		}
127
+		theStartTIme = theTime.Unix()
128
+	}
129
+	var theEndtTIme int64
130
+	if len(end_time) > 0 {
131
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
132
+		if err != nil {
133
+			utils.ErrorLog(err.Error())
134
+		}
135
+		theEndtTIme = theTime.Unix()
136
+	}
137
+
138
+	var range_value string
139
+	if range_type == 1 {
140
+		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.CurrentOrgId, project_id, item_id)
141
+		if qcs.ID == 0 { //没有配置选项
142
+			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.CurrentOrgId) //判断是否为集成过来的数据
143
+			if count <= 0 {                                                                   //不是,读系统参考值
144
+				reference, _ := statistics_service.FindProcjectInspectionReference(0, project_id, item_id)
145
+				range_value = reference.RangeMin + "," + reference.RangeMax
146
+
147
+			} else { //是,读集成过来的参考值
148
+				reference, _ := statistics_service.FindProcjectInspectionReference(adminUserInfo.CurrentOrgId, project_id, item_id)
149
+				range_value = reference.RangeMin + "," + reference.RangeMax
150
+
151
+			}
152
+
153
+		} else { //有配置
154
+
155
+			range_value = qcs.MinRange + "," + qcs.LargeRange
156
+
157
+		}
158
+
159
+	} else {
160
+
161
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRangeTypeValue(adminUserInfo.CurrentOrgId, project_id, item_id)
162
+		for _, item := range inspection {
163
+			if len(range_value) == 0 {
164
+				range_value = item.InspectValue
165
+			} else {
166
+				range_value = range_value + "," + item.InspectValue
167
+			}
168
+		}
169
+
170
+	}
171
+
172
+	data, _ := statistics_service.GetInspectionChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, project_id, item_id, range_type, range_value)
173
+	this.ServeSuccessJSON(map[string]interface{}{
174
+		"data": data,
175
+	})
176
+
177
+}
178
+func (this *PCIndexEvaluationApiController) GetInspectionChartTableData() {
179
+	adminUserInfo := this.GetAdminUserInfo()
180
+	start_time := this.GetString("start_time")
181
+	end_time := this.GetString("end_time")
182
+	patient_id, _ := this.GetInt64("patient_id")
183
+	page, _ := this.GetInt64("page")
184
+	limit, _ := this.GetInt64("limit")
185
+	project_id, _ := this.GetInt64("project_id")
186
+	item_id, _ := this.GetInt64("item_id")
187
+	range_value := this.GetString("range_value")
188
+	range_type, _ := this.GetInt("range_type")
189
+
190
+	if page == 0 {
191
+		page = 1
192
+	}
193
+	if limit == 0 {
194
+		limit = 20
195
+	}
196
+	timeLayout := "2006-01-02"
197
+	loc, _ := time.LoadLocation("Local")
198
+
199
+	var theStartTIme int64
200
+	if len(start_time) > 0 {
201
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
202
+		if err != nil {
203
+			utils.ErrorLog(err.Error())
204
+		}
205
+		theStartTIme = theTime.Unix()
206
+	}
207
+	var theEndtTIme int64
208
+	if len(end_time) > 0 {
209
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
210
+		if err != nil {
211
+			utils.ErrorLog(err.Error())
212
+		}
213
+		theEndtTIme = theTime.Unix()
214
+	}
215
+	data, total, _ := statistics_service.GetInspectionChartTableData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, project_id, item_id, patient_id, page, limit, range_type, range_value)
216
+	this.ServeSuccessJSON(map[string]interface{}{
217
+		"data":  data,
218
+		"total": total,
219
+	})
220
+
221
+}
222
+func (this *PCIndexEvaluationApiController) GetPatientInspectionChartData() {
223
+	adminUserInfo := this.GetAdminUserInfo()
224
+	start_time := this.GetString("start_time")
225
+	end_time := this.GetString("end_time")
226
+	project_id, _ := this.GetInt64("project_id")
227
+	item_id, _ := this.GetInt64("item_id")
228
+	patient_id, _ := this.GetInt64("patient_id")
229
+
230
+	timeLayout := "2006-01-02"
231
+	loc, _ := time.LoadLocation("Local")
232
+
233
+	var theStartTIme int64
234
+	if len(start_time) > 0 {
235
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
236
+		if err != nil {
237
+			utils.ErrorLog(err.Error())
238
+		}
239
+		theStartTIme = theTime.Unix()
240
+	}
241
+	var theEndtTIme int64
242
+	if len(end_time) > 0 {
243
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
244
+		if err != nil {
245
+			utils.ErrorLog(err.Error())
246
+		}
247
+		theEndtTIme = theTime.Unix()
248
+	}
249
+
250
+	data, _ := statistics_service.GetPatientInspectionChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, project_id, item_id, patient_id)
251
+	this.ServeSuccessJSON(map[string]interface{}{
252
+		"data": data,
253
+	})
254
+
255
+}
256
+func (this *PCIndexEvaluationApiController) GetPatientInspectionBarChartData() {
257
+	adminUserInfo := this.GetAdminUserInfo()
258
+	start_time := this.GetString("start_time")
259
+	end_time := this.GetString("end_time")
260
+	project_id, _ := this.GetInt64("project_id")
261
+	item_id, _ := this.GetInt64("item_id")
262
+	range_type, _ := this.GetInt("range_type")
263
+	patient_id, _ := this.GetInt64("patient_id")
264
+
265
+	timeLayout := "2006-01-02"
266
+	loc, _ := time.LoadLocation("Local")
267
+
268
+	var theStartTIme int64
269
+	if len(start_time) > 0 {
270
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
271
+		if err != nil {
272
+			utils.ErrorLog(err.Error())
273
+		}
274
+		theStartTIme = theTime.Unix()
275
+	}
276
+	var theEndtTIme int64
277
+	if len(end_time) > 0 {
278
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
279
+		if err != nil {
280
+			utils.ErrorLog(err.Error())
281
+		}
282
+		theEndtTIme = theTime.Unix()
283
+	}
284
+
285
+	var range_value string
286
+	if range_type == 1 {
287
+		qcs, _ := statistics_service.FindOrgConfigRangeTypeValue(adminUserInfo.CurrentOrgId, project_id, item_id)
288
+		if qcs.ID == 0 { //没有配置选项
289
+			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.CurrentOrgId) //判断是否为集成过来的数据
290
+			if count <= 0 {                                                                   //不是,读系统参考值
291
+				reference, _ := statistics_service.FindProcjectInspectionReference(0, project_id, item_id)
292
+				range_value = reference.RangeMin + "," + reference.RangeMax
293
+
294
+			} else { //是,读集成过来的参考值
295
+				reference, _ := statistics_service.FindProcjectInspectionReference(adminUserInfo.CurrentOrgId, project_id, item_id)
296
+				range_value = reference.RangeMin + "," + reference.RangeMax
297
+
298
+			}
299
+
300
+		} else { //有配置
301
+
302
+			range_value = qcs.MinRange + "," + qcs.LargeRange
303
+
304
+		}
305
+
306
+	} else {
307
+
308
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRangeTypeValue(adminUserInfo.CurrentOrgId, project_id, item_id)
309
+		for _, item := range inspection {
310
+			if len(range_value) == 0 {
311
+				range_value = item.InspectValue
312
+			} else {
313
+				range_value = range_value + "," + item.InspectValue
314
+			}
315
+		}
316
+
317
+	}
318
+
319
+	data, _ := statistics_service.GetPatientInspectionBarChartData(adminUserInfo.CurrentOrgId, theStartTIme, theEndtTIme, project_id, item_id, range_type, range_value, patient_id)
320
+	this.ServeSuccessJSON(map[string]interface{}{
321
+		"data": data,
322
+	})
323
+
324
+}
325
+
42 326
 func (this *PCIndexEvaluationApiController) GetAdminUser() {
43 327
 	admins, _ := statistics_service.GetAllAdminUser(this.GetAdminUserInfo().CurrentOrgId)
44 328
 	this.ServeSuccessJSON(map[string]interface{}{

+ 214 - 41
service/statistics_service/index_evaluation_service.go View File

@@ -331,7 +331,7 @@ func GetDialysisWeightChartData(user_org_id int64, start_time int64, end_time in
331 331
 			}
332 332
 
333 333
 			if item.Name == "60~70kg" {
334
-				isHasConditionTwo = true
334
+				isHasConditionThree = true
335 335
 			}
336 336
 
337 337
 			if item.Name == "大于70kg" {
@@ -414,7 +414,7 @@ func GetDialysisWeightChartData(user_org_id int64, start_time int64, end_time in
414 414
 			}
415 415
 
416 416
 			if item.Name == "60~70kg" {
417
-				isHasConditionTwo = true
417
+				isHasConditionThree = true
418 418
 			}
419 419
 
420 420
 			if item.Name == "大于70kg" {
@@ -585,7 +585,7 @@ func GetDialysisWeightChartData(user_org_id int64, start_time int64, end_time in
585 585
 			}
586 586
 
587 587
 			if item.Name == "60~70kg" {
588
-				isHasConditionTwo = true
588
+				isHasConditionThree = true
589 589
 			}
590 590
 
591 591
 			if item.Name == "大于70kg" {
@@ -844,7 +844,7 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
844 844
 			}
845 845
 
846 846
 			if item.Name == "140-160mmHg/90-100mmHg" {
847
-				isHasConditionTwo = true
847
+				isHasConditionThree = true
848 848
 			}
849 849
 		}
850 850
 		if !isHasConditionOne {
@@ -906,7 +906,7 @@ func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int
906 906
 			}
907 907
 
908 908
 			if item.Name == "140-160mmHg/90-100mmHg" {
909
-				isHasConditionTwo = true
909
+				isHasConditionThree = true
910 910
 			}
911 911
 		}
912 912
 		if !isHasConditionOne {
@@ -1168,23 +1168,23 @@ func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
1168 1168
 
1169 1169
 func FindOrgInspectionReference(user_org_id int64) (references []*models.InspectionReference, err error) {
1170 1170
 	db := service.XTReadDB()
1171
-	err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Find(&references).Error
1171
+	err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_max REGEXP '(^[0-9]+.[0-9]+$)|(^[0-9]$)' AND range_min REGEXP '(^[0-9]+.[0-9]+$)|(^[0-9]$)' ", user_org_id).Find(&references).Error
1172 1172
 	return
1173 1173
 }
1174 1174
 
1175 1175
 func FindProcjectInspectionReference(user_org_id int64, project_id int64, item_id int64) (references models.InspectionReference, err error) {
1176 1176
 	db := service.XTReadDB()
1177
-	err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ?", user_org_id, project_id, item_id).First(&references).Error
1177
+	err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND id = ?", user_org_id, project_id, item_id).First(&references).Error
1178 1178
 	return
1179 1179
 }
1180 1180
 
1181
-func FindOrgInspectionReferenceRnageTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
1181
+func FindOrgInspectionReferenceRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
1182 1182
 	db := service.XTReadDB()
1183
-	err = db.Model(&models.Inspection{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ? AND  inspect_type = 2", user_org_id, project_id, item_id).Group("inspect_value").Find(&inspection).Error
1183
+	err = db.Model(&models.Inspection{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ? AND  inspect_type = 2 AND inspect_value <> ''", user_org_id, project_id, item_id).Group("inspect_value").Find(&inspection).Error
1184 1184
 	return
1185 1185
 }
1186 1186
 
1187
-func FindOrgConfigRnageTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs models.QualityControlStandard, err error) {
1187
+func FindOrgConfigRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs QualityControlStandard, err error) {
1188 1188
 	db := service.XTReadDB()
1189 1189
 	err = db.Model(&QualityControlStandard{}).Where("status = 1 AND user_org_id = ? AND inspection_major = ? AND inspection_minor = ?", user_org_id, project_id, item_id).First(&qcs).Error
1190 1190
 	return
@@ -1197,49 +1197,179 @@ func GetInspectionChartData(user_org_id int64, start_time int64, end_time int64,
1197 1197
 	selectContent := "CASE"
1198 1198
 	range_value_arr := strings.Split(range_value, ",")
1199 1199
 
1200
+	fmt.Println(range_value_arr)
1201
+
1200 1202
 	if range_type == 1 {
1201
-		tempErr = db.Table("xt_inspection").Where("user_org_id=? and status=1 and  created_time >= ? and created_time <= ? AND project_id = ? AND item_id = ?", user_org_id, start_time, end_time, project_id, item_id).
1202
-			Select("CASE WHEN inspect_value < ? THEN 小于" + range_value_arr[0] +
1203
-				" WHEN inspect_value >= ? AND  inspect_value <= ? THEN " + range_value_arr[0] + "~" + range_value_arr[1] +
1204
-				" WHEN inspect_value > ? THEN 大于" + range_value_arr[1] +
1203
+		tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and  created_time >= ? and created_time <= ? AND project_id = ? AND item_id = ?", user_org_id, start_time, end_time, project_id, item_id).
1204
+			Select("CASE WHEN inspect_value < " + range_value_arr[0] + "THEN" + "'" + "小于" + range_value_arr[0] + "'" +
1205
+				" WHEN inspect_value >= " + range_value_arr[0] + "AND  inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
1206
+				" WHEN inspect_value > " + range_value_arr[1] + "THEN " + "'" + "大于" + range_value_arr[1] + "'" +
1205 1207
 				" ELSE '未知' END AS name, COUNT(*) AS total",
1206 1208
 			).Group("name").Scan(&items).Error
1209
+
1210
+		var isHasConditionOne bool = false
1211
+		var isHasConditionTwo bool = false
1212
+		var isHasConditionThree bool = false
1213
+
1214
+		for _, item := range items {
1215
+			if item.Name == "大于"+range_value_arr[1] {
1216
+				isHasConditionOne = true
1217
+			}
1218
+			if item.Name == "小于"+range_value_arr[0] {
1219
+				isHasConditionTwo = true
1220
+			}
1221
+			if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
1222
+				isHasConditionThree = true
1223
+			}
1224
+		}
1225
+		if !isHasConditionOne {
1226
+			newItem := &otherItemAmount{
1227
+				Total: 0,
1228
+				Name:  "大于" + range_value_arr[1],
1229
+				Ratio: "0",
1230
+			}
1231
+			items = append(items, newItem)
1232
+		}
1233
+
1234
+		if !isHasConditionTwo {
1235
+			newItem := &otherItemAmount{
1236
+				Total: 0,
1237
+				Name:  "小于" + range_value_arr[0],
1238
+				Ratio: "0",
1239
+			}
1240
+			items = append(items, newItem)
1241
+		}
1242
+		if !isHasConditionThree {
1243
+			newItem := &otherItemAmount{
1244
+				Total: 0,
1245
+				Name:  range_value_arr[0] + "~" + range_value_arr[1],
1246
+				Ratio: "0",
1247
+			}
1248
+			items = append(items, newItem)
1249
+		}
1250
+		return items, tempErr
1251
+
1207 1252
 	} else {
1253
+
1208 1254
 		for _, item := range range_value_arr {
1209
-			selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
1255
+			//selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
1256
+			selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
1257
+
1210 1258
 		}
1211
-		tempErr = db.Table("xt_inspection").Where("user_org_id=? and status=1 and  created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).
1259
+		tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and  created_time >= ? and created_time <= ? AND project_id = ? AND item_id = ?", user_org_id, start_time, end_time, project_id, item_id).
1212 1260
 			Select(selectContent +
1213 1261
 				" ELSE '未知' END AS name, COUNT(*) AS total",
1214 1262
 			).Group("name").Scan(&items).Error
1215
-
1263
+		return items, tempErr
1216 1264
 	}
1217
-	return items, tempErr
1218 1265
 
1219 1266
 }
1220 1267
 
1221
-type Patient struct {
1222
-	ID         int64             `gorm:"column:id" json:"id" form:"id"`
1223
-	Name       string            `gorm:"column:name" json:"name" form:"name"`
1224
-	Inspection models.Inspection `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
1268
+type Inspection struct {
1269
+	ID           int64           `gorm:"column:id" json:"id" form:"id"`
1270
+	PatientId    int64           `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1271
+	OrgId        int64           `gorm:"column:org_id" json:"org_id" form:"org_id"`
1272
+	ProjectId    int64           `gorm:"column:project_id" json:"project_id" form:"project_id"`
1273
+	ItemId       int64           `gorm:"column:item_id" json:"item_id" form:"item_id"`
1274
+	ItemName     string          `gorm:"column:item_name" json:"item_name" form:"item_name"`
1275
+	ProjectName  string          `gorm:"column:project_name" json:"project_name" form:"project_name"`
1276
+	InspectType  int64           `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
1277
+	InspectValue string          `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
1278
+	InspectDate  int64           `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
1279
+	Status       int64           `gorm:"column:status" json:"status" form:"status"`
1280
+	CreatedTime  int64           `gorm:"column:created_time" json:"created_time" form:"created_time"`
1281
+	UpdatedTime  int64           `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1282
+	Patient      models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
1225 1283
 }
1226 1284
 
1227
-func (Patient) TableName() string {
1228
-	return "xt_patients"
1285
+func (Inspection) TableName() string {
1286
+	return "xt_inspection"
1229 1287
 }
1230 1288
 
1231
-func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64, page, limit int64) (datas []*Patient, total int64, err error) {
1232
-	db := service.XTReadDB()
1233
-	offset := (page - 1) * limit
1234
-	err = db.Select("id, name from xt_patients RIGHT JOIN  xt_inspection ON xt_inspection.patient_id = xt_patients.id AND xt_inspection.created_time >= ? AND xt_inspection.created_time >= ? AND xt_inspection.project_id = ? AND xt_inspection.item_id = ?", start_time, end_time, project_id, item_id).Where("user_org_id = ? AND status = 1", user_org_id).Preload("Inspection", func(db *gorm.DB) *gorm.DB {
1235
-		return db.Where("status = 1 AND created_time >= ? AND created_time >= ? AND project_id = ? AND item_id = ?", start_time, end_time, project_id, item_id).Order("created_time DESC")
1236
-	}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1237
-	return datas, total, err
1289
+func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64, page, limit int64, range_type int, range_value string) (datas []*Inspection, total int64, err error) {
1290
+
1291
+	if range_type == 1 {
1292
+
1293
+		index := strings.Index(range_value, "小于")
1294
+		indexTwo := strings.Index(range_value, "大于")
1295
+		indexThree := strings.Index(range_value, "~")
1296
+
1297
+		if index != -1 {
1298
+			value, _ := strconv.ParseFloat(strings.Replace(range_value, "小于", "", 1), 64)
1299
+			db := service.XTReadDB()
1300
+			offset := (page - 1) * limit
1301
+			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value < ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1302
+				return db.Where("status = 1")
1303
+			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1304
+			return datas, total, err
1305
+		} else if indexTwo != -1 {
1306
+			value, _ := strconv.ParseFloat(strings.Replace(range_value, "大于", "", 1), 64)
1307
+
1308
+			db := service.XTReadDB()
1309
+			offset := (page - 1) * limit
1310
+			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value > ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1311
+				return db.Where("status = 1")
1312
+			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1313
+			return datas, total, err
1314
+		} else if indexThree != -1 {
1315
+			range_value_arr := strings.Split(range_value, "~")
1316
+			fmt.Println(range_value_arr)
1317
+
1318
+			float1, err := strconv.ParseFloat(range_value_arr[0], 64)
1319
+			float2, err := strconv.ParseFloat(range_value_arr[1], 64)
1320
+			fmt.Println(err)
1321
+			fmt.Println(float1)
1322
+
1323
+			fmt.Println(float2)
1324
+
1325
+			db := service.XTReadDB()
1326
+			offset := (page - 1) * limit
1327
+			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value >= ? AND inspect_value <= ?", user_org_id, start_time, end_time, project_id, item_id, float1, float2).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1328
+				return db.Where("status = 1")
1329
+			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1330
+			return datas, total, err
1331
+		} else {
1332
+			db := service.XTReadDB()
1333
+			offset := (page - 1) * limit
1334
+			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1 ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1335
+				return db.Where("status = 1")
1336
+			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1337
+			return datas, total, err
1338
+		}
1339
+
1340
+	} else {
1341
+
1342
+		if range_value == "全部" {
1343
+			db := service.XTReadDB()
1344
+			offset := (page - 1) * limit
1345
+			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1346
+				return db.Where("status = 1")
1347
+			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1348
+			return datas, total, err
1349
+
1350
+		} else {
1351
+
1352
+			db := service.XTReadDB()
1353
+			offset := (page - 1) * limit
1354
+			err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND created_time >= ? AND created_time <= ?  AND project_id = ? AND item_id = ? AND status = 1  AND inspect_value = ?", user_org_id, start_time, end_time, project_id, item_id, range_value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
1355
+				return db.Where("status = 1")
1356
+			}).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
1357
+			return datas, total, err
1358
+
1359
+		}
1360
+
1361
+	}
1362
+
1363
+}
1364
+
1365
+type NewIndexDataStruct struct {
1366
+	Date  string `json:"date"`
1367
+	Value string `json:"value"`
1238 1368
 }
1239 1369
 
1240
-func GetPatientInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64) (datas []*ProcessIndexDataStruct, err error) {
1370
+func GetPatientInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64) (datas []*NewIndexDataStruct, err error) {
1241 1371
 	db := service.XTReadDB()
1242
-	err = db.Raw("select from_unixtime(inspect_date, '%Y-%m-%d') as date, inspect_value as value from xt_inspection  Where status = 1 AND user_org_id = ? AND patient_id = ? AND project_id = ? AND item_id = ? created_time <= ? AND  created_time >= ? ", user_org_id, patient_id, project_id, item_id, end_time, start_time).Scan(&datas).Error
1372
+	err = db.Raw("select from_unixtime(inspect_date, '%Y-%m-%d') as date, inspect_value as value from xt_inspection  Where status = 1 AND org_id = ? AND patient_id = ? AND project_id = ? AND item_id = ? AND created_time <= ? AND  created_time >= ? ", user_org_id, patient_id, project_id, item_id, end_time, start_time).Scan(&datas).Error
1243 1373
 	if err != nil {
1244 1374
 		return nil, err
1245 1375
 	}
@@ -1255,22 +1385,65 @@ func GetPatientInspectionBarChartData(user_org_id int64, start_time int64, end_t
1255 1385
 	range_value_arr := strings.Split(range_value, ",")
1256 1386
 
1257 1387
 	if range_type == 1 {
1258
-		tempErr = db.Table("xt_inspection").Where("user_org_id=? and status=1 and  created_time >= ? and created_time <= ? AND project_id = ? AND item_id = ? AND patient_id = ?", user_org_id, start_time, end_time, project_id, item_id, patient_id).
1259
-			Select("CASE WHEN inspect_value < ? THEN 小于" + range_value_arr[0] +
1260
-				" WHEN inspect_value >= ? AND  inspect_value <= ? THEN " + range_value_arr[0] + "~" + range_value_arr[1] +
1261
-				" WHEN inspect_value > ? THEN 大于" + range_value_arr[1] +
1388
+		tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and  created_time >= ? and created_time <= ? AND project_id = ? AND item_id = ? AND patient_id = ?", user_org_id, start_time, end_time, project_id, item_id, patient_id).
1389
+			Select("CASE WHEN inspect_value < " + range_value_arr[0] + "THEN" + "'" + "小于" + range_value_arr[0] + "'" +
1390
+				" WHEN inspect_value >= " + range_value_arr[0] + "AND  inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
1391
+				" WHEN inspect_value > " + range_value_arr[1] + "THEN " + "'" + "大于" + range_value_arr[1] + "'" +
1262 1392
 				" ELSE '未知' END AS name, COUNT(*) AS total",
1263 1393
 			).Group("name").Scan(&items).Error
1394
+
1395
+		var isHasConditionOne bool = false
1396
+		var isHasConditionTwo bool = false
1397
+		var isHasConditionThree bool = false
1398
+
1399
+		for _, item := range items {
1400
+			if item.Name == "大于"+range_value_arr[1] {
1401
+				isHasConditionOne = true
1402
+			}
1403
+			if item.Name == "小于"+range_value_arr[0] {
1404
+				isHasConditionTwo = true
1405
+			}
1406
+			if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
1407
+				isHasConditionThree = true
1408
+			}
1409
+		}
1410
+		if !isHasConditionOne {
1411
+			newItem := &otherItemAmount{
1412
+				Total: 0,
1413
+				Name:  "大于" + range_value_arr[1],
1414
+				Ratio: "0",
1415
+			}
1416
+			items = append(items, newItem)
1417
+		}
1418
+
1419
+		if !isHasConditionTwo {
1420
+			newItem := &otherItemAmount{
1421
+				Total: 0,
1422
+				Name:  "小于" + range_value_arr[0],
1423
+				Ratio: "0",
1424
+			}
1425
+			items = append(items, newItem)
1426
+		}
1427
+		if !isHasConditionThree {
1428
+			newItem := &otherItemAmount{
1429
+				Total: 0,
1430
+				Name:  range_value_arr[0] + "~" + range_value_arr[1],
1431
+				Ratio: "0",
1432
+			}
1433
+			items = append(items, newItem)
1434
+		}
1435
+		return items, tempErr
1436
+
1264 1437
 	} else {
1438
+
1265 1439
 		for _, item := range range_value_arr {
1266
-			selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
1440
+			selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
1267 1441
 		}
1268
-		tempErr = db.Table("xt_inspection").Where("user_org_id=? and status=1 and  created_time >= ? and created_time <= ? AND patient_id = ?", user_org_id, start_time, end_time, patient_id).
1442
+		tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and  created_time >= ? and created_time <= ? AND patient_id  = ?", user_org_id, start_time, end_time, patient_id).
1269 1443
 			Select(selectContent +
1270 1444
 				" ELSE '未知' END AS name, COUNT(*) AS total",
1271 1445
 			).Group("name").Scan(&items).Error
1272
-
1446
+		return items, tempErr
1273 1447
 	}
1274
-	return items, tempErr
1275 1448
 
1276 1449
 }