陈少旭 hace 1 año
padre
commit
b6c1105ba6

+ 48 - 0
controllers/his_api_controller.go Ver fichero

@@ -102,6 +102,54 @@ func HisManagerApiRegistRouters() {
102 102
 
103 103
 	beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
104 104
 
105
+	beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
106
+
107
+}
108
+func (c *HisApiController) ChangeOrderDesc() {
109
+	id, _ := c.GetInt64("id")
110
+	desc := c.GetString("desc")
111
+	change_type := c.GetString("change_type")
112
+	order, _ := service.GetHisOrderByID(id)
113
+	if order.ID == 0 {
114
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
115
+		return
116
+	}
117
+	switch change_type {
118
+	case "oth_desc":
119
+		order.OthDesc = desc
120
+		break
121
+	case "cash_pay":
122
+		order.CashPay = desc
123
+
124
+		break
125
+	case "jifen_pay":
126
+		order.JifenPay = desc
127
+
128
+		break
129
+	case "band_card_pay":
130
+		order.BandCardPay = desc
131
+
132
+		break
133
+	case "ali_pay":
134
+		order.AliPay = desc
135
+
136
+		break
137
+	case "wechat_pay":
138
+		order.WechatPay = desc
139
+		break
140
+	}
141
+	err := service.SaveHisOrder(&order)
142
+	if err == nil {
143
+		c.ServeSuccessJSON(map[string]interface{}{
144
+			"msg": "修改成功",
145
+		})
146
+		return
147
+
148
+	} else {
149
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
150
+		return
151
+	}
152
+
105 153
 }
106 154
 func (c *HisApiController) GetMonthHisPatient() {
107 155
 	record_date := c.GetString("record_date")

+ 26 - 0
controllers/his_print_api_controller.go Ver fichero

@@ -20,8 +20,34 @@ func HisPrintApiRegistRouters() {
20 20
 	beego.Router("/api/his/label/create", &HisPrintApiController{}, "get:CreateLablePrint")
21 21
 	beego.Router("/api/his/label/get", &HisPrintApiController{}, "get:GetLablePrint")
22 22
 
23
+	//beego.Router("/api/his/checkprescription/print", &HisPrintApiController{}, "get:GetBatchCheckHisPrescriptionData")
24
+
23 25
 }
24 26
 
27
+//func (c *HisPrintApiController) GetBatchCheckHisPrescriptionData() {
28
+//	record_date := c.GetString("record_date")
29
+//	patient_ids := c.GetString("patient_ids")
30
+//	timeLayout := "2006-01-02"
31
+//	loc, _ := time.LoadLocation("Local")
32
+//	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
33
+//	if err != nil {
34
+//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
35
+//		return
36
+//	}
37
+//	recordDateTime := theTime.Unix()
38
+//	adminInfo := c.GetAdminUserInfo()
39
+//	ids := strings.Split(patient_ids, ",")
40
+//
41
+//	//var newPatients []*models.PrintPatient
42
+//
43
+//	patients, _ := service.GetBatchInspectionProjectHisPrescriptionTwo(ids, recordDateTime, adminInfo.CurrentOrgId)
44
+//
45
+//	c.ServeSuccessJSON(map[string]interface{}{
46
+//		"patients": patients,
47
+//	})
48
+//	break
49
+//}
50
+
25 51
 func (c *HisPrintApiController) GetLablePrint() {
26 52
 	patient_id, _ := c.GetInt64("patient_id")
27 53
 	ids := c.GetString("ids")

+ 181 - 37
controllers/statistics_api_controller.go Ver fichero

@@ -26,7 +26,41 @@ func StatisticsApiRegistRouters() {
26 26
 
27 27
 	//beego.Router("/api/qc/statistiscperson/export", &StatisticsApiController{}, "get:ExportPersonInspectionStatistisc")
28 28
 
29
+	beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
30
+
29 31
 }
32
+
33
+func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
34
+	start_date := c.GetString("start_date")
35
+	end_date := c.GetString("end_date")
36
+	keyword := c.GetString("keyword")
37
+	timeLayout := "2006-01-02"
38
+	loc, _ := time.LoadLocation("Local")
39
+	var startTime int64
40
+	if len(start_date) > 0 {
41
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
42
+		if err != nil {
43
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
44
+			return
45
+		}
46
+		startTime = theTime.Unix()
47
+	}
48
+	var endTime int64
49
+	if len(end_date) > 0 {
50
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
51
+		if err != nil {
52
+			utils.ErrorLog(err.Error())
53
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
54
+			return
55
+		}
56
+		endTime = theTime.Unix()
57
+	}
58
+	list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
59
+	c.ServeSuccessJSON(map[string]interface{}{
60
+		"list": list,
61
+	})
62
+}
63
+
30 64
 func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
31 65
 	start_date := c.GetString("start_date")
32 66
 	end_date := c.GetString("end_date")
@@ -35,6 +69,7 @@ func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
35 69
 	item_type, _ := c.GetInt64("item_type")
36 70
 	//order_type,  _ := c.GetInt64("order_type")
37 71
 	keyword := c.GetString("keyword")
72
+	s_type, _ := c.GetInt64("type")
38 73
 
39 74
 	timeLayout := "2006-01-02"
40 75
 	loc, _ := time.LoadLocation("Local")
@@ -71,25 +106,67 @@ func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
71 106
 
72 107
 		break
73 108
 	case 1:
74
-		list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
75
-		c.ServeSuccessJSON(map[string]interface{}{
76
-			"list":      list,
77
-			"reference": reference,
78
-		})
109
+		if s_type == 2 { //KTV
110
+			list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
111
+			c.ServeSuccessJSON(map[string]interface{}{
112
+				"list": list,
113
+			})
114
+		} else if s_type == 3 { //URR
115
+			list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
116
+			c.ServeSuccessJSON(map[string]interface{}{
117
+				"list": list,
118
+			})
119
+		} else {
120
+
121
+			list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
122
+			c.ServeSuccessJSON(map[string]interface{}{
123
+				"list":      list,
124
+				"reference": reference,
125
+			})
126
+
127
+		}
128
+
79 129
 		break
80 130
 	case 2:
81
-		list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
82
-		c.ServeSuccessJSON(map[string]interface{}{
83
-			"list":      list,
84
-			"reference": reference,
85
-		})
131
+		if s_type == 2 { //KTV
132
+			list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
133
+			c.ServeSuccessJSON(map[string]interface{}{
134
+				"list": list,
135
+			})
136
+		} else if s_type == 3 { //URR
137
+			list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
138
+			c.ServeSuccessJSON(map[string]interface{}{
139
+				"list": list,
140
+			})
141
+		} else {
142
+
143
+			list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
144
+			c.ServeSuccessJSON(map[string]interface{}{
145
+				"list":      list,
146
+				"reference": reference,
147
+			})
148
+		}
149
+
86 150
 		break
87 151
 	case 3:
88
-		list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
89
-		c.ServeSuccessJSON(map[string]interface{}{
90
-			"list":      list,
91
-			"reference": reference,
92
-		})
152
+		if s_type == 2 { //KTV
153
+			list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
154
+			c.ServeSuccessJSON(map[string]interface{}{
155
+				"list": list,
156
+			})
157
+		} else if s_type == 3 { //URR
158
+			list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
159
+			c.ServeSuccessJSON(map[string]interface{}{
160
+				"list": list,
161
+			})
162
+		} else {
163
+			list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
164
+			c.ServeSuccessJSON(map[string]interface{}{
165
+				"list":      list,
166
+				"reference": reference,
167
+			})
168
+		}
169
+
93 170
 		break
94 171
 	}
95 172
 }
@@ -100,6 +177,8 @@ func (c *StatisticsApiController) GetAllInspectionStatistisc() {
100 177
 	project_id, _ := c.GetInt64("project_id")
101 178
 	item_id, _ := c.GetInt64("item_id")
102 179
 
180
+	s_type, _ := c.GetInt64("type")
181
+
103 182
 	timeLayout := "2006-01-02"
104 183
 	loc, _ := time.LoadLocation("Local")
105 184
 	var startTime int64
@@ -132,19 +211,57 @@ func (c *StatisticsApiController) GetAllInspectionStatistisc() {
132 211
 	max, _ := strconv.ParseFloat(reference.RangeMax, 64)
133 212
 	min, _ := strconv.ParseFloat(reference.RangeMin, 64)
134 213
 
135
-	normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
136
-	//获取数值异常的总数
137
-	unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
138
-	//获取没有检查的患者总数
139
-	noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
214
+	if s_type == 2 {
215
+		normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
216
+		//获取数值异常的总数
217
+		//unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
218
+		unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
219
+
220
+		//获取没有检查的患者总数
221
+		noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
222
+
223
+		c.ServeSuccessJSON(map[string]interface{}{
224
+			"patient_count":  patientCount,
225
+			"normal_total":   normalTotal,
226
+			"unusual_total":  unusualTotal,
227
+			"no_check_total": noCheckTotal,
228
+		})
229
+
230
+	} else if s_type == 3 {
231
+
232
+		normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
233
+		//获取数值异常的总数
234
+		//unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
235
+		unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
236
+
237
+		//获取没有检查的患者总数
238
+		noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
239
+
240
+		c.ServeSuccessJSON(map[string]interface{}{
241
+			"patient_count":  patientCount,
242
+			"normal_total":   normalTotal,
243
+			"unusual_total":  unusualTotal,
244
+			"no_check_total": noCheckTotal,
245
+		})
246
+
247
+	} else {
248
+
249
+		normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
250
+		//获取数值异常的总数
251
+		unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
252
+		//获取没有检查的患者总数
253
+		noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
254
+
255
+		c.ServeSuccessJSON(map[string]interface{}{
256
+			"patient_count":  patientCount,
257
+			"normal_total":   normalTotal,
258
+			"unusual_total":  unusualTotal,
259
+			"no_check_total": noCheckTotal,
260
+			"reference":      reference,
261
+		})
262
+
263
+	}
140 264
 
141
-	c.ServeSuccessJSON(map[string]interface{}{
142
-		"patient_count":  patientCount,
143
-		"normal_total":   normalTotal,
144
-		"unusual_total":  unusualTotal,
145
-		"no_check_total": noCheckTotal,
146
-		"reference":      reference,
147
-	})
148 265
 }
149 266
 func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
150 267
 	start_date := c.GetString("start_time")
@@ -152,6 +269,7 @@ func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
152 269
 	project_id, _ := c.GetInt64("project_id")
153 270
 	item_id, _ := c.GetInt64("item_id")
154 271
 	patient_id, _ := c.GetInt64("patient_id")
272
+	s_type, _ := c.GetInt64("type")
155 273
 
156 274
 	timeLayout := "2006-01-02"
157 275
 	loc, _ := time.LoadLocation("Local")
@@ -176,17 +294,43 @@ func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
176 294
 		endTime = theTime.Unix()
177 295
 	}
178 296
 
179
-	patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
180
-	//获取配置
181
-	reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
182
-	//获取数值在正常范围内的总数
183
-	inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
297
+	if s_type == 2 {
298
+		patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
299
+		//获取配置
300
+		reference, _ := service.GetInspectionReferenceThree(1014, 10950)
301
+		//获取数值在正常范围内的总数
302
+		inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
303
+		c.ServeSuccessJSON(map[string]interface{}{
304
+			"patient":     patient,
305
+			"reference":   reference,
306
+			"inspections": inspections,
307
+		})
308
+
309
+	} else if s_type == 3 {
310
+		patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
311
+		//获取配置
312
+		reference, _ := service.GetInspectionReferenceThree(1014, 10951)
313
+		//获取数值在正常范围内的总数
314
+		inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
315
+		c.ServeSuccessJSON(map[string]interface{}{
316
+			"patient":     patient,
317
+			"reference":   reference,
318
+			"inspections": inspections,
319
+		})
320
+
321
+	} else {
322
+		patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
323
+		//获取配置
324
+		reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
325
+		//获取数值在正常范围内的总数
326
+		inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
327
+		c.ServeSuccessJSON(map[string]interface{}{
328
+			"patient":     patient,
329
+			"reference":   reference,
330
+			"inspections": inspections,
331
+		})
332
+	}
184 333
 
185
-	c.ServeSuccessJSON(map[string]interface{}{
186
-		"patient":     patient,
187
-		"reference":   reference,
188
-		"inspections": inspections,
189
-	})
190 334
 }
191 335
 
192 336
 func (c *StatisticsApiController) GetStatistics() {

+ 22 - 0
models/his_print_models.go Ver fichero

@@ -24,6 +24,28 @@ func (PrintPatient) TableName() string {
24 24
 	return "xt_patients"
25 25
 }
26 26
 
27
+type CheckPrintPatient struct {
28
+	ID                     int64                   `gorm:"column:id" json:"id" form:"id"`
29
+	UserOrgId              int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
30
+	Name                   string                  `gorm:"column:name" json:"name" form:"name"`
31
+	Age                    string                  `gorm:"column:age" json:"age" form:"age"`
32
+	Gender                 int64                   `gorm:"column:gender" json:"gender" form:"gender"`
33
+	HomeAddress            string                  `gorm:"column:home_address" json:"home_address" form:"home_address"`
34
+	Phone                  string                  `gorm:"column:phone" json:"phone" form:"phone"`
35
+	Lapseto                int64                   `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
36
+	Status                 int64                   `gorm:"column:status" json:"status" form:"status"`
37
+	ReimbursementWayId     int64                   `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
38
+	Birthday               int64                   `gorm:"column:birthday" json:"birthday" form:"birthday"`
39
+	HisPrintPatient        HisPrintPatient         `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
40
+	HisHospitalCheckRecord HisHospitalCheckRecord  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_record_patient"`
41
+	HisPrescriptionInfoTwo HisPrescriptionInfoTwo  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
42
+	HisPrintPrescription   []*HisPrintPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescriptions"`
43
+}
44
+
45
+func (CheckPrintPatient) TableName() string {
46
+	return "xt_patients"
47
+}
48
+
27 49
 type HisPrintPatient struct {
28 50
 	ID                     int64   `gorm:"column:id" json:"id" form:"id"`
29 51
 	BalanceAccountsType    int64   `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`

+ 35 - 0
models/inspection_models.go Ver fichero

@@ -216,3 +216,38 @@ type XtPatientsTen struct {
216 216
 func (XtPatientsTen) TableName() string {
217 217
 	return "xt_patients"
218 218
 }
219
+
220
+type XtPatientsTenOne struct {
221
+	ID              int64  `gorm:"column:id" json:"id" form:"id"`
222
+	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
223
+	UserId          int64  `gorm:"column:user_id" json:"user_id" form:"user_id"`
224
+	Avatar          string `gorm:"column:avatar" json:"avatar" form:"avatar"`
225
+	PatientType     int64  `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
226
+	DialysisNo      string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
227
+	AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
228
+	Source          int64  `gorm:"column:source" json:"source" form:"source"`
229
+	Lapseto         int64  `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
230
+	PartitionId     int64  `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
231
+	BedId           int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
232
+	Name            string `gorm:"column:name" json:"name" form:"name"`
233
+	Inspection      []Inspection
234
+}
235
+
236
+func (XtPatientsTenOne) TableName() string {
237
+	return "xt_patients"
238
+}
239
+
240
+type InspectionTen struct {
241
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
242
+	PatientId int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
243
+	Name      string `gorm:"-" json:"name" form:"name"`
244
+	Ipth      string `gorm:"-" json:"ipth" form:"ipth"`
245
+	Xuejia    string `gorm:"-" json:"xuejia" form:"xuejia"`
246
+	Xuelin    string `gorm:"-" json:"xuelin" form:"xuelin"`
247
+	Bdb       string `gorm:"-" json:"bdb" form:"bdb"`
248
+	Xhdb      string `gorm:"-" json:"xhdb" form:"xhdb"`
249
+}
250
+
251
+func (InspectionTen) TableName() string {
252
+	return "xt_inspection"
253
+}

+ 14 - 0
service/his_print_service.go Ver fichero

@@ -124,6 +124,20 @@ func GetBatchProjectHisPrescription(ids []string, record_time int64, user_org_id
124 124
 
125 125
 func GetBatchInspectionProjectHisPrescription(ids []string, record_time int64, user_org_id int64) (patients []*models.PrintPatient, err error) {
126 126
 	readDb.Model(&models.PrintPatient{}).Preload("HisPrintPatient", "status = 1 AND record_date = ?", record_time).
127
+		Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
128
+			return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
129
+				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
130
+					return db.Joins("Join xt_his_project p On p.id = his_prescription_project.project_id  AND p.cost_classify = 3").Where("his_prescription_project.status = 1 AND his_prescription_project.type = 2").Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1")
131
+				})
132
+		}).
133
+		Preload("HisPrescriptionInfoTwo", "status = 1 AND record_date = ?", record_time).
134
+		Where("id in (?) AND user_org_id = ?  ", ids, user_org_id).Find(&patients)
135
+	return
136
+
137
+}
138
+
139
+func GetBatchInspectionProjectHisPrescriptionTwo(ids []string, record_time int64, user_org_id int64) (patients []*models.CheckPrintPatient, err error) {
140
+	readDb.Model(&models.CheckPrintPatient{}).Preload("HisPrintPatient", "status = 1 AND record_date = ?", record_time).
127 141
 		Preload("HisPrintPrescription", func(db *gorm.DB) *gorm.DB {
128 142
 			return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND type <> 1 AND p_type = 2", user_org_id, record_time).
129 143
 				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {

+ 228 - 1
service/patientmanage_service.go Ver fichero

@@ -1975,7 +1975,6 @@ func GetUnusualInspectionTotalByID(startime int64, endtime int64, orgid int64, p
1975 1975
 	}
1976 1976
 	return total, err2
1977 1977
 }
1978
-
1979 1978
 func GetPatientNotInspectionTotal(startime int64, endtime int64, orgid int64, projectid int64, item_id int64) (total int64, err error) {
1980 1979
 	err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.reference_project_id = ? and pd.reference_item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
1981 1980
 	return total, err
@@ -2006,6 +2005,69 @@ func GetPatientInspectionByID(startime int64, endtime int64, orgid int64, projec
2006 2005
 	return inspections, err
2007 2006
 }
2008 2007
 
2008
+func GetPatientKTVORURRInspectionByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, patient_id int64) (inspections []*models.Inspection, err error) {
2009
+	db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
2010
+	if startime > 0 {
2011
+		db = db.Where("x.inspect_date >= ?", startime)
2012
+	}
2013
+	if endtime > 0 {
2014
+		db = db.Where("x.inspect_date<=?", endtime)
2015
+	}
2016
+
2017
+	if orgid > 0 {
2018
+		db = db.Where("x.org_id = ?", orgid)
2019
+	}
2020
+	if projectid > 0 {
2021
+		db = db.Where("x.project_id = ?", projectid)
2022
+	}
2023
+	if item_id > 0 {
2024
+		db = db.Where("x.item_id = ?", item_id)
2025
+	}
2026
+	if patient_id > 0 {
2027
+		db = db.Where("x.patient_id = ?", patient_id)
2028
+	}
2029
+	err = db.Find(&inspections).Error
2030
+	return inspections, err
2031
+}
2032
+
2033
+func GetPatientKTVByID(startime int64, endtime int64, orgid int64, patient_id int64) (inspections []*models.Inspection, err error) {
2034
+	db := XTReadDB().Table("xt_assessment_after_dislysis as x").Select("patient_id as patient_id,assessment_date as inspect_date,ktv as inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
2035
+	if startime > 0 {
2036
+		db = db.Where("x.assessment_date >= ?", startime)
2037
+	}
2038
+	if endtime > 0 {
2039
+		db = db.Where("x.assessment_date<=?", endtime)
2040
+	}
2041
+
2042
+	if orgid > 0 {
2043
+		db = db.Where("x.user_org_id = ?", orgid)
2044
+	}
2045
+	if patient_id > 0 {
2046
+		db = db.Where("x.patient_id = ?", patient_id)
2047
+	}
2048
+	err = db.Find(&inspections).Error
2049
+	return inspections, err
2050
+}
2051
+
2052
+func GetPatientURRByID(startime int64, endtime int64, orgid int64, patient_id int64) (inspections []*models.Inspection, err error) {
2053
+	db := XTReadDB().Table("xt_assessment_after_dislysis as x").Select("patient_id as patient_id,assessment_date as inspect_date,urr as inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
2054
+	if startime > 0 {
2055
+		db = db.Where("x.assessment_date >= ?", startime)
2056
+	}
2057
+	if endtime > 0 {
2058
+		db = db.Where("x.assessment_date<=?", endtime)
2059
+	}
2060
+
2061
+	if orgid > 0 {
2062
+		db = db.Where("x.user_org_id = ?", orgid)
2063
+	}
2064
+	if patient_id > 0 {
2065
+		db = db.Where("x.patient_id = ?", patient_id)
2066
+	}
2067
+	err = db.Find(&inspections).Error
2068
+	return inspections, err
2069
+}
2070
+
2009 2071
 func GetNormalInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2010 2072
 	db := XTReadDB().Table("xt_inspection as xti ")
2011 2073
 	if len(keyword) > 0 {
@@ -2033,3 +2095,168 @@ func GetPatientNotInspectionPatientList(startime int64, endtime int64, orgid int
2033 2095
 	err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.reference_project_id = ? and pd.reference_item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
2034 2096
 	return patient, err
2035 2097
 }
2098
+
2099
+func GetUnusualKTVPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2100
+	db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
2101
+	if len(keyword) > 0 {
2102
+		keyword = "%" + keyword + "%"
2103
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1   and name like ?", keyword)
2104
+	} else {
2105
+
2106
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
2107
+	}
2108
+	err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x  WHERE (x.status = 1) AND (x.user_org_id = ?  and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.user_org_id = ?   and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv +'0' < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
2109
+	return xti, err2
2110
+}
2111
+
2112
+func GetUnusualKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2113
+	db := XTReadDB().Table("xt_inspection as xti ")
2114
+	if len(keyword) > 0 {
2115
+		keyword = "%" + keyword + "%"
2116
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1   and name like ?", keyword)
2117
+	} else {
2118
+
2119
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
2120
+	}
2121
+	err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x  WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE  (xti.status = 1 AND xti.org_id = ? and xti.project_id = ? and xti.item_id = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
2122
+	return xti, err2
2123
+}
2124
+
2125
+func GetNormalKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2126
+	db := XTReadDB().Table("xt_inspection as xti ")
2127
+	if len(keyword) > 0 {
2128
+		keyword = "%" + keyword + "%"
2129
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
2130
+	} else {
2131
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
2132
+	}
2133
+	err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x  WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.org_id = ? and xti.project_id = ? and xti.item_id = ?  and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
2134
+	return xti, err2
2135
+}
2136
+
2137
+func GetPatientNotKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, keyword string) (patient []*models.XtPatientsTen, err error) {
2138
+	err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.project_id = ? and pd.item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
2139
+	return patient, err
2140
+}
2141
+
2142
+func GetNormalKTVPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2143
+	db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
2144
+	if len(keyword) > 0 {
2145
+		keyword = "%" + keyword + "%"
2146
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
2147
+	} else {
2148
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
2149
+	}
2150
+	err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x  WHERE (x.status = 1) AND (x.user_org_id = ?  and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.user_org_id = ?    and xti.assessment_date >= ? and xti.assessment_date<= ? and xti.ktv + '0'  >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
2151
+	return xti, err2
2152
+}
2153
+func GetPatientNotKTVPatientList(startime int64, endtime int64, orgid int64) (patient []*models.XtPatientsTen, err error) {
2154
+	err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.ktv <> '' and pd.assessment_date >= ? and pd.assessment_date<=? ", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
2155
+	return patient, err
2156
+}
2157
+
2158
+func GetNormalURRPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2159
+	db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
2160
+	if len(keyword) > 0 {
2161
+		keyword = "%" + keyword + "%"
2162
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
2163
+	} else {
2164
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
2165
+	}
2166
+	err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x  WHERE (x.status = 1) AND (x.user_org_id = ?  and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date<= ? and REPLACE(xti.urr, '%', '') + 0 >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
2167
+	return xti, err2
2168
+}
2169
+func GetUnusualURRPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
2170
+	db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
2171
+	if len(keyword) > 0 {
2172
+		keyword = "%" + keyword + "%"
2173
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1   and name like ?", keyword)
2174
+	} else {
2175
+
2176
+		db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
2177
+	}
2178
+	err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x  WHERE (x.status = 1) AND (x.user_org_id = ?  and x.assessment_date >= ? and x.assessment_date <= ?) group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE  (xti.status = 1 AND xti.user_org_id = ?   and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '') + 0 < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
2179
+	return xti, err2
2180
+}
2181
+func GetPatientNotURRPatientList(startime int64, endtime int64, orgid int64) (patient []*models.XtPatientsTen, err error) {
2182
+	err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and xti.urr <> '' and pd.assessment_date >= ? and pd.assessment_date<=? ", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
2183
+	return patient, err
2184
+}
2185
+
2186
+func GetNormalKTVTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
2187
+	var count []*InspectionCount
2188
+	err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1  WHERE (x.status = 1) AND (x.user_org_id = ?  and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.user_org_id = ?  and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv + '0' >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
2189
+	for _, items := range count {
2190
+		total = total + items.Count
2191
+	}
2192
+	return total, err2
2193
+}
2194
+func GetUnusualKTVTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
2195
+	var count []*InspectionCount
2196
+	err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti ").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1  WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ?  and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.user_org_id = ?  and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv  + '0'< ?)  Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
2197
+	for _, items := range count {
2198
+		total = total + items.Count
2199
+	}
2200
+	return total, err2
2201
+}
2202
+func GetPatientNotKTVTotal(startime int64, endtime int64, orgid int64) (total int64, err error) {
2203
+	err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.user_org_id = ? and pd.assessment_date >= ? and pd.assessment_date<=? and pd.ktv <> ''", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
2204
+	return total, err
2205
+}
2206
+
2207
+func GetNormalURRTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
2208
+	var count []*InspectionCount
2209
+	err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1  WHERE (x.status = 1) AND (x.user_org_id = ?  and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.user_org_id = ?  and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '') + 0 >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
2210
+	for _, items := range count {
2211
+		total = total + items.Count
2212
+	}
2213
+	return total, err2
2214
+}
2215
+func GetUnusualURRTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
2216
+	var count []*InspectionCount
2217
+	err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti ").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid  FROM xt_assessment_after_dislysis as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1  WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.user_org_id = ?  and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '')+ 0 < ?)  Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
2218
+	for _, items := range count {
2219
+		total = total + items.Count
2220
+	}
2221
+	return total, err2
2222
+}
2223
+func GetPatientNotURRTotal(startime int64, endtime int64, orgid int64) (total int64, err error) {
2224
+	err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.user_org_id = ? and pd.assessment_date >= ? and pd.assessment_date<=? and pd.urr <> ''", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
2225
+	return total, err
2226
+}
2227
+
2228
+func GetNormalKTVORURRInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, min_value float64) (total int64, err error) {
2229
+	var count []*InspectionCount
2230
+	err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1  WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE (xti.status = 1) AND (xti.org_id = ? and xti.project_id = ? and xti.item_id = ?  and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
2231
+	for _, items := range count {
2232
+		total = total + items.Count
2233
+	}
2234
+	return total, err2
2235
+}
2236
+func GetUnusualKTVORURRInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, min_value float64) (total int64, err error) {
2237
+	var count []*InspectionCount
2238
+	err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid  FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1  WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ?  and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid  WHERE   (xti.status = 1 AND xti.org_id = ? and xti.project_id = ? and xti.item_id = ?  and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
2239
+	for _, items := range count {
2240
+		total = total + items.Count
2241
+	}
2242
+	return total, err2
2243
+}
2244
+
2245
+func GetPatientNotKTVORURRInspectionTotal(startime int64, endtime int64, orgid int64, projectid int64, item_id int64) (total int64, err error) {
2246
+	err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.project_id = ? and pd.item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
2247
+	return total, err
2248
+}
2249
+
2250
+func GetFiveInspectionPatientList(orgid int64, keyword string) (xti []*models.XtPatientsTenOne, err error) {
2251
+	keyword = "%" + keyword + "%"
2252
+	err = XTReadDB().Model(models.XtPatientsTenOne{}).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and xt_patients.lapseto = 1 and xt.patients.name like ?", orgid, keyword).Find(&xti).Error
2253
+	return
2254
+}
2255
+
2256
+func GetPatientFiveInspectionByID(startime int64, endtime int64, orgid int64, keyword string) (inspections []models.InspectionTen, err error) {
2257
+	keyword = "%" + keyword + "%"
2258
+
2259
+	db := XTReadDB().Table("xt_patients as p").Select("p.id as patient_id, p.name as name, IFNULL(a.inspect_value, '') AS 'ipth',IFNULL(b.inspect_value, '') AS 'xuejia',IFNULL(c.inspect_value, '') AS 'xuelin',IFNULL(d.inspect_value, '') AS 'bdb',IFNULL(e.inspect_value, '') AS 'xhdb'").Joins("LEFT JOIN `xt_inspection` a ON p.id = a.patient_id AND a.org_id = ?  and a.`reference_item_id` = 171 and a.`reference_project_id` = 20  and a.`inspect_date` >= ? and a.`inspect_date` <= ?  LEFT JOIN xt_inspection b ON p.id = b.patient_id AND b.org_id = ?  and b.`reference_item_id` = 48 and b.`reference_project_id` = 4 and b.`inspect_date` >= ? and b.`inspect_date` <= ? LEFT JOIN xt_inspection c ON p.id = c.patient_id AND c.org_id = ?  and c.`reference_item_id` = 169 and c.`reference_project_id` = 4 and c.`inspect_date` >= ? and c.`inspect_date` <= ? LEFT JOIN xt_inspection d ON p.id = d.patient_id AND d.org_id = ?  and d.`reference_item_id` = 35 and d.`reference_project_id` = 2 and d.`inspect_date` >= ? and d.`inspect_date` <= ? LEFT JOIN xt_inspection e ON p.id = e.patient_id AND e.org_id = ?  and e.`reference_item_id` = 17 and e.`reference_project_id` = 1 and e.`inspect_date` >= ? and e.`inspect_date` <= ?", orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime).Where("p.name like ? and  p.user_org_id = ? and p.status = 1 and p.lapseto = 1 ", keyword, orgid).Group("p.id")
2260
+	err = db.Find(&inspections).Error
2261
+	return inspections, err
2262
+}