Browse Source

提交代码

陈少旭 1 year ago
parent
commit
86b9f43903
2 changed files with 206 additions and 73 deletions
  1. 6 5
      controllers/his_charge_api_controller.go
  2. 200 68
      service/his_charge_service.go

+ 6 - 5
controllers/his_charge_api_controller.go View File

238
 
238
 
239
 	start_time := c.GetString("start_time")
239
 	start_time := c.GetString("start_time")
240
 	end_time := c.GetString("end_time")
240
 	end_time := c.GetString("end_time")
241
+	time_type := c.GetString("time_type")
241
 	keyword := c.GetString("keyword")
242
 	keyword := c.GetString("keyword")
242
 	item_type, _ := c.GetInt64("type")
243
 	item_type, _ := c.GetInt64("type")
243
 
244
 
259
 
260
 
260
 	switch item_type {
261
 	switch item_type {
261
 	case 0:
262
 	case 0:
262
-		chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
263
-		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
263
+		chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
264
+		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
264
 		chargeDrug = append(chargeDrug, chargeProject...)
265
 		chargeDrug = append(chargeDrug, chargeProject...)
265
 		b, _ := structToBytes(chargeDrug)
266
 		b, _ := structToBytes(chargeDrug)
266
 		//cd, _ := compressData(b)
267
 		//cd, _ := compressData(b)
281
 		c.Ctx.ResponseWriter.Write(compressedData.Bytes())
282
 		c.Ctx.ResponseWriter.Write(compressedData.Bytes())
282
 		break
283
 		break
283
 	case 1:
284
 	case 1:
284
-		chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
285
+		chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
285
 		//chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
286
 		//chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
286
 		//chargeDrug = append(chargeDrug, chargeProject...)
287
 		//chargeDrug = append(chargeDrug, chargeProject...)
287
 		b, _ := structToBytes(chargeDrug)
288
 		b, _ := structToBytes(chargeDrug)
304
 		break
305
 		break
305
 	case 2:
306
 	case 2:
306
 		//chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
307
 		//chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
307
-		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
308
+		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
308
 		//chargeDrug = append(chargeDrug, chargeProject...)
309
 		//chargeDrug = append(chargeDrug, chargeProject...)
309
 		b, _ := structToBytes(chargeProject)
310
 		b, _ := structToBytes(chargeProject)
310
 		//cd, _ := compressData(b)
311
 		//cd, _ := compressData(b)
327
 
328
 
328
 	case 3:
329
 	case 3:
329
 		//chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
330
 		//chargeDrug, err := service.GetNewAllPatientDrugChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
330
-		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type)
331
+		chargeProject, err := service.GetNewAllPatientProjectAndGoodChargeDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, keyword, item_type, time_type)
331
 		//chargeDrug = append(chargeDrug, chargeProject...)
332
 		//chargeDrug = append(chargeDrug, chargeProject...)
332
 		b, _ := structToBytes(chargeProject)
333
 		b, _ := structToBytes(chargeProject)
333
 		//cd, _ := compressData(b)
334
 		//cd, _ := compressData(b)

+ 200 - 68
service/his_charge_service.go View File

10
 	if len(keyword) == 0 {
10
 	if len(keyword) == 0 {
11
 		switch item_type {
11
 		switch item_type {
12
 		case 0:
12
 		case 0:
13
+
13
 			err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1  AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
14
 			err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1  AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
14
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
15
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
15
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
16
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
152
 	return
153
 	return
153
 }
154
 }
154
 
155
 
155
-func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
156
+func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64, time_type string) (patients []*models.NewChargeDetail, err error) {
156
 	if len(keyword) == 0 {
157
 	if len(keyword) == 0 {
157
 		switch item_type {
158
 		switch item_type {
158
 		case 0:
159
 		case 0:
159
-			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
160
-				Joins("JOIN his_order o ON oi.order_number = o.number  and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
161
-				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
162
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
163
-				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
164
-				Where("oi.advice_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
160
+			if time_type == "0" {
161
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
162
+					Joins("JOIN his_order o ON oi.order_number = o.number  and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
163
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
164
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
165
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
166
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
167
+
168
+			} else {
169
+
170
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
171
+					Joins("JOIN his_order o ON oi.order_number = o.number  and o.setl_time BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
172
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
173
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
174
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
175
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ?   and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
176
+
177
+			}
178
+
165
 			break
179
 			break
166
 		case 1:
180
 		case 1:
167
-			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
168
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
169
-				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
170
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
171
-				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
172
-				Where("oi.advice_id > 0 and oi.user_org_id = ? and  o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?    and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
181
+			if time_type == "0" {
182
+
183
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
184
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
185
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
186
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
187
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
188
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and  o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?    and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
189
+
190
+			} else {
191
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
192
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
193
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
194
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
195
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
196
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and  oi.upload_date >= ?  and oi.upload_date <= ?    and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
197
+
198
+			}
199
+
173
 			break
200
 			break
174
 
201
 
175
 		}
202
 		}
178
 		keyword := "%" + keyword + "%"
205
 		keyword := "%" + keyword + "%"
179
 		switch item_type {
206
 		switch item_type {
180
 		case 0:
207
 		case 0:
181
-			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
182
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
183
-				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
184
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
185
-				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
186
-				Where("oi.advice_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
208
+			if time_type == "0" {
209
+
210
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
211
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
212
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
213
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
214
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
215
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
216
+
217
+			} else {
218
+
219
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
220
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
221
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
222
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
223
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
224
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ?  and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
225
+
226
+			}
187
 
227
 
188
 			break
228
 			break
189
 		case 1:
229
 		case 1:
190
-			err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
191
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
192
-				Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
193
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
194
-				Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
195
-				Where("oi.advice_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
230
+			if time_type == "0" {
231
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
232
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
233
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
234
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
235
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
236
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
237
+
238
+			} else {
239
+
240
+				err = readDb.Table("his_order_info as oi").Select("oi.advice_id as advice_id, 0 as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,drug.drug_name as item_name,drug.dose as dose,drug.dose_unit as dose_unit, drug.min_number as min_number,drug.min_unit as min_unit, drug.max_unit as max_unit,drug.id as item_id").
241
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
242
+					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
243
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
244
+					Joins(" JOIN  xt_base_drug drug on  a.drug_id = drug.id").
245
+					Where("oi.advice_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
246
+
247
+			}
196
 
248
 
197
 			break
249
 			break
198
 
250
 
202
 
254
 
203
 	return
255
 	return
204
 }
256
 }
205
-func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.NewChargeDetail, err error) {
257
+func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, keyword string, item_type int64, time_type string) (patients []*models.NewChargeDetail, err error) {
206
 	if len(keyword) == 0 {
258
 	if len(keyword) == 0 {
207
 		switch item_type {
259
 		switch item_type {
208
 		case 0:
260
 		case 0:
209
-			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
210
-				Joins("JOIN his_order o ON oi.order_number = o.number  and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
211
-				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
212
-				Joins(" left join xt_his_project project on  p.project_id = project.id").
213
-				Joins(" left join  xt_good_information good on  p.project_id = good.id").
214
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
215
-				Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
261
+			if time_type == "0" {
262
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
263
+					Joins("JOIN his_order o ON oi.order_number = o.number  and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
264
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
265
+					Joins(" left join xt_his_project project on  p.project_id = project.id").
266
+					Joins(" left join  xt_good_information good on  p.project_id = good.id").
267
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
268
+					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
269
+
270
+			} else {
271
+
272
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
273
+					Joins("JOIN his_order o ON oi.order_number = o.number  and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
274
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
275
+					Joins(" left join xt_his_project project on  p.project_id = project.id").
276
+					Joins(" left join  xt_good_information good on  p.project_id = good.id").
277
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
278
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
279
+
280
+			}
216
 
281
 
217
 			//err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1  AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
282
 			//err = readDb2.Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1  AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
218
 			//	return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
283
 			//	return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
232
 
297
 
233
 			break
298
 			break
234
 		case 2:
299
 		case 2:
235
-			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
236
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1 ", start_time_str, end_time_str).
237
-				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
238
-				Joins("left join xt_his_project project on  p.project_id = project.id").
239
-				Joins("left join  xt_good_information good on  p.project_id = good.id").
240
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
241
-				Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
300
+			if time_type == "0" {
301
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
302
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1 ", start_time_str, end_time_str).
303
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
304
+					Joins("left join xt_his_project project on  p.project_id = project.id").
305
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
306
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
307
+					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
308
+
309
+			} else {
310
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
311
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1 ", start_time_str, end_time_str).
312
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
313
+					Joins("left join xt_his_project project on  p.project_id = project.id").
314
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
315
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
316
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ?  and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
317
+
318
+			}
319
+
242
 			break
320
 			break
243
 		case 3:
321
 		case 3:
244
-			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
245
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1 ", start_time_str, end_time_str).
246
-				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
247
-				Joins("left join xt_his_project project on  p.project_id = project.id").
248
-				Joins("left join  xt_good_information good on  p.project_id = good.id").
249
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
250
-				Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
322
+			if time_type == "0" {
323
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
324
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1 ", start_time_str, end_time_str).
325
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
326
+					Joins("left join xt_his_project project on  p.project_id = project.id").
327
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
328
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
329
+					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
330
+
331
+			} else {
332
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
333
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1 ", start_time_str, end_time_str).
334
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
335
+					Joins("left join xt_his_project project on  p.project_id = project.id").
336
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
337
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
338
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
339
+
340
+			}
341
+
251
 			break
342
 			break
252
 		}
343
 		}
253
 	} else {
344
 	} else {
254
 		keyword := "%" + keyword + "%"
345
 		keyword := "%" + keyword + "%"
255
 		switch item_type {
346
 		switch item_type {
256
 		case 0:
347
 		case 0:
257
-			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
258
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
259
-				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
260
-				Joins("left join xt_his_project project on  p.project_id = project.id").
261
-				Joins("left join  xt_good_information good on  p.project_id = good.id").
262
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
263
-				Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
348
+			if time_type == "0" {
349
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
350
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
351
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
352
+					Joins("left join xt_his_project project on  p.project_id = project.id").
353
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
354
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
355
+					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
356
+
357
+			} else {
358
+
359
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
360
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ? and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
361
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
362
+					Joins("left join xt_his_project project on  p.project_id = project.id").
363
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
364
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
365
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
366
+
367
+			}
264
 
368
 
265
 			break
369
 			break
266
 
370
 
267
 		case 2:
371
 		case 2:
268
-			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
269
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
270
-				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
271
-				Joins("left join xt_his_project project on  p.project_id = project.id").
272
-				Joins("left join  xt_good_information good on  p.project_id = good.id").
273
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
274
-				Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
372
+			if time_type == "0" {
373
+
374
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
375
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
376
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
377
+					Joins("left join xt_his_project project on  p.project_id = project.id").
378
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
379
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
380
+					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
381
+
382
+			} else {
383
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
384
+					Joins("JOIN his_order o ON oi.order_number = o.number   and o.setl_time BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
385
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
386
+					Joins("left join xt_his_project project on  p.project_id = project.id").
387
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
388
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
389
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
390
+
391
+			}
275
 
392
 
276
 			break
393
 			break
277
 		case 3:
394
 		case 3:
278
-			err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
279
-				Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d') BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
280
-				Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
281
-				Joins("left join xt_his_project project on  p.project_id = project.id").
282
-				Joins("left join  xt_good_information good on  p.project_id = good.id").
283
-				Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
284
-				Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
395
+			if time_type == "0" {
396
+
397
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
398
+					Joins("JOIN his_order o ON oi.order_number = o.number   and FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S')  BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
399
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
400
+					Joins("left join xt_his_project project on  p.project_id = project.id").
401
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
402
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
403
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
404
+
405
+			} else {
406
+
407
+				err = readDb.Table("his_order_info as oi").Select("0 as advice_id, oi.project_id as project_id, oi.patient_id as p_id,oi.cnt as cnt,oi.pric as pric,pp.name as p_name,p.type as p_type,  (case p.type  when 2 then project.project_name  when 3 then good.good_name  END) as item_name,(case p.type  when 2 then ''  when 3 then good.specification_name  END) as specification_name, p.project_id as item_id").
408
+					Joins("JOIN his_order o ON oi.order_number = o.number   and  o.setl_time BETWEEN ? AND ?  and o.order_status = 2 and o.status = 1", start_time_str, end_time_str).
409
+					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
410
+					Joins("left join xt_his_project project on  p.project_id = project.id").
411
+					Joins("left join  xt_good_information good on  p.project_id = good.id").
412
+					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
413
+					Where("oi.project_id > 0 and oi.user_org_id = ? and oi.upload_date >= ?  and oi.upload_date <= ? and oi.status = 1 ", org_id, start_time, end_time).Scan(&patients).Error
414
+
415
+			}
416
+
285
 			break
417
 			break
286
 		}
418
 		}
287
 	}
419
 	}