Parcourir la source

Merge branch 'xt_statistics_branch'

csx il y a 4 ans
Parent
révision
bd3cdee84d

+ 1 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Voir le fichier

@@ -2248,6 +2248,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
2248 2248
 			prescription_doctor := adminUserInfo.AdminUser.Id
2249 2249
 			prescription.PrescriptionDoctor = prescription_doctor
2250 2250
 		}
2251
+
2251 2252
 		if dialysisPrescription.Creater == 0 { //体重称
2252 2253
 			prescription.Creater = adminUserInfo.AdminUser.Id
2253 2254
 

+ 212 - 0
controllers/new_mobile_api_controllers/index_evaluation_api_controller.go Voir le fichier

@@ -2,6 +2,7 @@ package new_mobile_api_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
 	"time"
@@ -18,6 +19,217 @@ func (this *IndexEvaluationApiController) GetAdminUser() {
18 19
 	})
19 20
 }
20 21
 
22
+//化验指标
23
+
24
+//初始化数据
25
+func (this *IndexEvaluationApiController) GetLaboratoryIndexInitData() {
26
+	adminUserInfo := this.GetMobileAdminUserInfo()
27
+	var references []*models.InspectionReference
28
+	count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.Org.Id)
29
+	if count <= 0 {
30
+		references, _ = statistics_service.FindOrgInspectionReference(0)
31
+	} else {
32
+		references, _ = statistics_service.FindOrgInspectionReference(adminUserInfo.Org.Id)
33
+	}
34
+
35
+	this.ServeSuccessJSON(map[string]interface{}{
36
+		"references": references,
37
+	})
38
+
39
+}
40
+
41
+//获取取值范围
42
+func (this *IndexEvaluationApiController) GetLaboratoryIndexProjectRangeValueData() {
43
+	range_type, _ := this.GetInt64("range_type")
44
+	project_id, _ := this.GetInt64("project_id")
45
+	item_id, _ := this.GetInt64("item_id")
46
+	adminUserInfo := this.GetMobileAdminUserInfo()
47
+	var range_vaule []string
48
+	if range_type == 1 {
49
+		qcs, _ := statistics_service.FindOrgConfigRnageTypeValue(adminUserInfo.Org.Id, project_id, item_id)
50
+		if qcs.ID == 0 { //没有配置选项
51
+			count, _ := statistics_service.FindOrgInspectionCount(adminUserInfo.Org.Id) //判断是否为集成过来的数据
52
+			if count <= 0 {                                                             //不是,读系统参考值
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)
57
+
58
+			} else { //是,读集成过来的参考值
59
+				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)
63
+			}
64
+
65
+		} 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)
69
+
70
+		}
71
+
72
+	} else {
73
+
74
+		inspection, _ := statistics_service.FindOrgInspectionReferenceRnageTypeValue(adminUserInfo.Org.Id, project_id, item_id)
75
+		for _, item := range inspection {
76
+			range_vaule = append(range_vaule, item.InspectValue)
77
+		}
78
+
79
+	}
80
+	this.ServeSuccessJSON(map[string]interface{}{
81
+		"range_vaule": range_vaule,
82
+	})
83
+
84
+}
85
+func (this *IndexEvaluationApiController) GetInspectionChartData() {
86
+	adminUserInfo := this.GetMobileAdminUserInfo()
87
+	start_time := this.GetString("start_time")
88
+	end_time := this.GetString("end_time")
89
+	project_id, _ := this.GetInt64("project_id")
90
+	item_id, _ := this.GetInt64("item_id")
91
+	range_type, _ := this.GetInt("range_type")
92
+	range_value := this.GetString("range_value")
93
+
94
+	timeLayout := "2006-01-02"
95
+	loc, _ := time.LoadLocation("Local")
96
+
97
+	var theStartTIme int64
98
+	if len(start_time) > 0 {
99
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
100
+		if err != nil {
101
+			utils.ErrorLog(err.Error())
102
+		}
103
+		theStartTIme = theTime.Unix()
104
+	}
105
+	var theEndtTIme int64
106
+	if len(end_time) > 0 {
107
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
108
+		if err != nil {
109
+			utils.ErrorLog(err.Error())
110
+		}
111
+		theEndtTIme = theTime.Unix()
112
+	}
113
+
114
+	data, _ := statistics_service.GetInspectionChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, range_type, range_value)
115
+	this.ServeSuccessJSON(map[string]interface{}{
116
+		"data": data,
117
+	})
118
+
119
+}
120
+func (this *IndexEvaluationApiController) GetInspectionChartTableData() {
121
+	adminUserInfo := this.GetMobileAdminUserInfo()
122
+	start_time := this.GetString("start_time")
123
+	end_time := this.GetString("end_time")
124
+	patient_id, _ := this.GetInt64("patient_id")
125
+	page, _ := this.GetInt64("page")
126
+	limit, _ := this.GetInt64("limit")
127
+	project_id, _ := this.GetInt64("project_id")
128
+	item_id, _ := this.GetInt64("item_id")
129
+
130
+	if page == 0 {
131
+		page = 1
132
+	}
133
+	if limit == 0 {
134
+		limit = 20
135
+	}
136
+	timeLayout := "2006-01-02"
137
+	loc, _ := time.LoadLocation("Local")
138
+
139
+	var theStartTIme int64
140
+	if len(start_time) > 0 {
141
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
142
+		if err != nil {
143
+			utils.ErrorLog(err.Error())
144
+		}
145
+		theStartTIme = theTime.Unix()
146
+	}
147
+	var theEndtTIme int64
148
+	if len(end_time) > 0 {
149
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
150
+		if err != nil {
151
+			utils.ErrorLog(err.Error())
152
+		}
153
+		theEndtTIme = theTime.Unix()
154
+	}
155
+	data, total, _ := statistics_service.GetInspectionChartTableData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, patient_id, page, limit)
156
+	this.ServeSuccessJSON(map[string]interface{}{
157
+		"data":  data,
158
+		"total": total,
159
+	})
160
+
161
+}
162
+func (this *IndexEvaluationApiController) GetPatientInspectionChartData() {
163
+	adminUserInfo := this.GetMobileAdminUserInfo()
164
+	start_time := this.GetString("start_time")
165
+	end_time := this.GetString("end_time")
166
+	project_id, _ := this.GetInt64("project_id")
167
+	item_id, _ := this.GetInt64("item_id")
168
+	patient_id, _ := this.GetInt64("patient_id")
169
+
170
+	timeLayout := "2006-01-02"
171
+	loc, _ := time.LoadLocation("Local")
172
+
173
+	var theStartTIme int64
174
+	if len(start_time) > 0 {
175
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
176
+		if err != nil {
177
+			utils.ErrorLog(err.Error())
178
+		}
179
+		theStartTIme = theTime.Unix()
180
+	}
181
+	var theEndtTIme int64
182
+	if len(end_time) > 0 {
183
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
184
+		if err != nil {
185
+			utils.ErrorLog(err.Error())
186
+		}
187
+		theEndtTIme = theTime.Unix()
188
+	}
189
+
190
+	data, _ := statistics_service.GetPatientInspectionChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, patient_id)
191
+	this.ServeSuccessJSON(map[string]interface{}{
192
+		"data": data,
193
+	})
194
+
195
+}
196
+func (this *IndexEvaluationApiController) GetPatientInspectionBarChartData() {
197
+	adminUserInfo := this.GetMobileAdminUserInfo()
198
+	start_time := this.GetString("start_time")
199
+	end_time := this.GetString("end_time")
200
+	project_id, _ := this.GetInt64("project_id")
201
+	item_id, _ := this.GetInt64("item_id")
202
+	range_type, _ := this.GetInt("range_type")
203
+	range_value := this.GetString("range_value")
204
+	patient_id, _ := this.GetInt64("patient_id")
205
+
206
+	timeLayout := "2006-01-02"
207
+	loc, _ := time.LoadLocation("Local")
208
+
209
+	var theStartTIme int64
210
+	if len(start_time) > 0 {
211
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
212
+		if err != nil {
213
+			utils.ErrorLog(err.Error())
214
+		}
215
+		theStartTIme = theTime.Unix()
216
+	}
217
+	var theEndtTIme int64
218
+	if len(end_time) > 0 {
219
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
220
+		if err != nil {
221
+			utils.ErrorLog(err.Error())
222
+		}
223
+		theEndtTIme = theTime.Unix()
224
+	}
225
+
226
+	data, _ := statistics_service.GetPatientInspectionBarChartData(adminUserInfo.Org.Id, theStartTIme, theEndtTIme, project_id, item_id, range_type, range_value, patient_id)
227
+	this.ServeSuccessJSON(map[string]interface{}{
228
+		"data": data,
229
+	})
230
+
231
+}
232
+
21 233
 func (this *IndexEvaluationApiController) GetDialysisProcessIndexChartData() {
22 234
 	adminUserInfo := this.GetMobileAdminUserInfo()
23 235
 	statistics_type, _ := this.GetInt("statistics_type")

+ 8 - 0
controllers/new_mobile_api_controllers/statistics_api_controllers.go Voir le fichier

@@ -4,6 +4,14 @@ import "github.com/astaxie/beego"
4 4
 
5 5
 func StatisticsAPIControllersRegisterRouters() {
6 6
 
7
+	//化验指标
8
+	beego.Router("/m/api/inspectionindex/init", &IndexEvaluationApiController{}, "Get:GetLaboratoryIndexInitData")
9
+	beego.Router("/m/api/rangevalue/get", &IndexEvaluationApiController{}, "Get:GetLaboratoryIndexProjectRangeValueData")
10
+	beego.Router("/m/api/inspectionindex/chart", &IndexEvaluationApiController{}, "Get:GetInspectionChartData")
11
+	beego.Router("/m/api/inspectionindex/table", &IndexEvaluationApiController{}, "Get:GetInspectionChartTableData")
12
+	beego.Router("/m/api/patientinspectionindex/chart", &IndexEvaluationApiController{}, "Get:GetPatientInspectionChartData")
13
+	beego.Router("/m/api/patientinspectionindex/barchart", &IndexEvaluationApiController{}, "Get:GetPatientInspectionBarChartData")
14
+
7 15
 	beego.Router("/m/api/dialysisprocessindex/chart", &IndexEvaluationApiController{}, "Get:GetDialysisProcessIndexChartData")
8 16
 	beego.Router("/m/api/dialysisprocessindex/table", &IndexEvaluationApiController{}, "Get:GetDialysisProcessIndexTableData")
9 17
 

+ 6 - 6
controllers/schedule_api_controller.go Voir le fichier

@@ -761,7 +761,7 @@ func (this *ScheduleApiController) ExportSchedule() {
761 761
 					err_log := models.ExportErrLog{
762 762
 						LogType:    2,
763 763
 						UserOrgId:  this.GetAdminUserInfo().CurrentOrgId,
764
-						ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该病人",
764
+						ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
765 765
 						Status:     1,
766 766
 						CreateTime: time.Now().Unix(),
767 767
 						UpdateTime: time.Now().Unix(),
@@ -1150,7 +1150,7 @@ func (this *ScheduleApiController) ExportSchedule() {
1150 1150
 		errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
1151 1151
 
1152 1152
 		if len(schedules) > 0 {
1153
-			schedule_date := this.GetString("date")
1153
+			schedule_date := time.Now().Format("2006-01-02")
1154 1154
 			date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
1155 1155
 			clear_schedule_date := date.Unix() //根据日期去清除,该日期以及未来的排班数据
1156 1156
 			err := service.UpdateScheduleStatus(clear_schedule_date, this.GetAdminUserInfo().CurrentOrgId)
@@ -1176,7 +1176,7 @@ func (this *ScheduleApiController) ExportSchedule() {
1176 1176
 					err_log := models.ExportErrLog{
1177 1177
 						LogType:   2,
1178 1178
 						UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1179
-						ErrMsg: "当前日期(" + this.GetString("date") + " " + GetWeekString(time.Now().Weekday().String()) +
1179
+						ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
1180 1180
 							")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
1181 1181
 						Status:     1,
1182 1182
 						CreateTime: time.Now().Unix(),
@@ -1210,7 +1210,7 @@ func (this *ScheduleApiController) ExportSchedule() {
1210 1210
 					err_log := models.ExportErrLog{
1211 1211
 						LogType:   2,
1212 1212
 						UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1213
-						ErrMsg: "当前日期(" + this.GetString("date") + " " + GetWeekString(time.Now().Weekday().String()) +
1213
+						ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
1214 1214
 							")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
1215 1215
 						Status:     1,
1216 1216
 						CreateTime: time.Now().Unix(),
@@ -1245,7 +1245,7 @@ func (this *ScheduleApiController) ExportSchedule() {
1245 1245
 				err_log := models.ExportErrLog{
1246 1246
 					LogType:   2,
1247 1247
 					UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1248
-					ErrMsg: "当前日期(" + this.GetString("date") + " " + GetWeekString(time.Now().Weekday().String()) +
1248
+					ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
1249 1249
 						")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
1250 1250
 					Status:     1,
1251 1251
 					CreateTime: time.Now().Unix(),
@@ -1319,7 +1319,7 @@ func (this *ScheduleApiController) ExportScheduleTemplate() {
1319 1319
 						LogType:   3,
1320 1320
 						UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
1321 1321
 						//ErrMsg:     "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
1322
-						ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该病人",
1322
+						ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
1323 1323
 
1324 1324
 						Status:     1,
1325 1325
 						CreateTime: time.Now().Unix(),

+ 117 - 1
service/statistics_service/index_evaluation_service.go Voir le fichier

@@ -6,6 +6,7 @@ import (
6 6
 	"fmt"
7 7
 	"github.com/jinzhu/gorm"
8 8
 	"strconv"
9
+	"strings"
9 10
 )
10 11
 
11 12
 func GetOrgFirstPatientInfo(user_org_id int64) (patient *models.Patients, err error) {
@@ -731,7 +732,7 @@ func GetPatientDialysisWeightChartData(user_org_id int64, patient_id int64, star
731 732
 
732 733
 		break
733 734
 	case 4:
734
-		err = db.Raw("select assessment_date as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND  created_time <= ? AND  created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
735
+		err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND  created_time <= ? AND  created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
735 736
 		break
736 737
 
737 738
 	}
@@ -1158,3 +1159,118 @@ func GetAllAdminUser(user_org_id int64) (datas []*AdminUser, err error) {
1158 1159
 	return datas, nil
1159 1160
 
1160 1161
 }
1162
+
1163
+func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
1164
+	db := service.XTReadDB()
1165
+	err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Count(&count).Error
1166
+	return
1167
+}
1168
+
1169
+func FindOrgInspectionReference(user_org_id int64) (references []*models.InspectionReference, err error) {
1170
+	db := service.XTReadDB()
1171
+	err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Find(&references).Error
1172
+	return
1173
+}
1174
+
1175
+func FindProcjectInspectionReference(user_org_id int64, project_id int64, item_id int64) (references models.InspectionReference, err error) {
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
1178
+	return
1179
+}
1180
+
1181
+func FindOrgInspectionReferenceRnageTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
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
1184
+	return
1185
+}
1186
+
1187
+func FindOrgConfigRnageTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs models.QualityControlStandard, err error) {
1188
+	db := service.XTReadDB()
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
+	return
1191
+}
1192
+
1193
+func GetInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, range_type int, range_value string) (item []*otherItemAmount, err error) {
1194
+	db := service.XTReadDB()
1195
+	var items []*otherItemAmount
1196
+	var tempErr error
1197
+	selectContent := "CASE"
1198
+	range_value_arr := strings.Split(range_value, ",")
1199
+
1200
+	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] +
1205
+				" ELSE '未知' END AS name, COUNT(*) AS total",
1206
+			).Group("name").Scan(&items).Error
1207
+	} else {
1208
+		for _, item := range range_value_arr {
1209
+			selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
1210
+		}
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).
1212
+			Select(selectContent +
1213
+				" ELSE '未知' END AS name, COUNT(*) AS total",
1214
+			).Group("name").Scan(&items).Error
1215
+
1216
+	}
1217
+	return items, tempErr
1218
+
1219
+}
1220
+
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"`
1225
+}
1226
+
1227
+func (Patient) TableName() string {
1228
+	return "xt_patients"
1229
+}
1230
+
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
1238
+}
1239
+
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) {
1241
+	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
1243
+	if err != nil {
1244
+		return nil, err
1245
+	}
1246
+	return datas, nil
1247
+
1248
+}
1249
+
1250
+func GetPatientInspectionBarChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, range_type int, range_value string, patient_id int64) (item []*otherItemAmount, err error) {
1251
+	db := service.XTReadDB()
1252
+	var items []*otherItemAmount
1253
+	var tempErr error
1254
+	selectContent := "CASE"
1255
+	range_value_arr := strings.Split(range_value, ",")
1256
+
1257
+	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] +
1262
+				" ELSE '未知' END AS name, COUNT(*) AS total",
1263
+			).Group("name").Scan(&items).Error
1264
+	} else {
1265
+		for _, item := range range_value_arr {
1266
+			selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
1267
+		}
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).
1269
+			Select(selectContent +
1270
+				" ELSE '未知' END AS name, COUNT(*) AS total",
1271
+			).Group("name").Scan(&items).Error
1272
+
1273
+	}
1274
+	return items, tempErr
1275
+
1276
+}

+ 17 - 0
service/statistics_service/index_models.go Voir le fichier

@@ -147,3 +147,20 @@ type VMDeviceNumber struct {
147 147
 func (VMDeviceNumber) TableName() string {
148 148
 	return "xt_device_number"
149 149
 }
150
+
151
+type QualityControlStandard struct {
152
+	ID              int64  `gorm:"column:id" json:"id" form:"id"`
153
+	InspectionMajor int64  `gorm:"column:inspection_major" json:"inspection_major" form:"inspection_major"`
154
+	InspectionMinor int64  `gorm:"column:inspection_minor" json:"inspection_minor" form:"inspection_minor"`
155
+	MinRange        string `gorm:"column:min_range" json:"min_range" form:"min_range"`
156
+	LargeRange      string `gorm:"column:large_range" json:"large_range" form:"large_range"`
157
+	Sort            int64  `gorm:"column:sort" json:"sort" form:"sort"`
158
+	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
159
+	Status          int64  `gorm:"column:status" json:"status" form:"status"`
160
+	CreatedTime     int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
161
+	UpdatedTime     int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
162
+}
163
+
164
+func (QualityControlStandard) TableName() string {
165
+	return "xt_quality_control_standard"
166
+}