Kaynağa Gözat

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

28169 7 ay önce
ebeveyn
işleme
e5dd609b75

+ 5 - 1
controllers/his_api_controller.go Dosyayı Görüntüle

@@ -1411,6 +1411,10 @@ func (c *HisApiController) GetHisPatientList() {
1411 1411
 	//patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
1412 1412
 	patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
1413 1413
 	patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
1414
+	patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
1415
+
1416
+	//patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
1417
+
1414 1418
 	//获取当前用户的信息
1415 1419
 	adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
1416 1420
 	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
@@ -1419,6 +1423,7 @@ func (c *HisApiController) GetHisPatientList() {
1419 1423
 	c.ServeSuccessJSON(map[string]interface{}{
1420 1424
 		"list":       patients,
1421 1425
 		"list_two":   patients_two,
1426
+		"list_three": patient_three,
1422 1427
 		"info":       adminUserInfo,
1423 1428
 		"doctors":    doctors,
1424 1429
 		"department": department,
@@ -9185,7 +9190,6 @@ func (c *HisApiController) GetUploadInfo() {
9185 9190
 		if dec_way == "true" {
9186 9191
 
9187 9192
 			tmpstring := strconv.FormatInt(order.ID, 10)
9188
-
9189 9193
 			//扣押金
9190 9194
 			errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
9191 9195
 			order.Decimal = decimal

+ 83 - 0
controllers/his_charge_api_controller.go Dosyayı Görüntüle

@@ -20,6 +20,10 @@ type HisChargeApiController struct {
20 20
 func HisChargeApiRegistRouters() {
21 21
 	beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
22 22
 	beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
23
+
24
+	beego.Router("/api/his/prescription/detail", &HisChargeApiController{}, "get:GetPrescriptionStatisticsDetail")
25
+	beego.Router("/api/his/prescription/initdata", &HisChargeApiController{}, "get:GetPrescriptionInitData")
26
+
23 27
 	//beego.InsertFilter("/api/his/chargestatistics/detail", beego.BeforeRouter, GzipFilter)
24 28
 
25 29
 	beego.Router("/api/his/patient", &HisChargeApiController{}, "get:GetAllPatient")
@@ -441,6 +445,85 @@ func (c *HisChargeApiController) GetChargeStatisticsDetail() {
441 445
 
442 446
 }
443 447
 
448
+func (c *HisChargeApiController) GetPrescriptionStatisticsDetail() {
449
+	start_time := c.GetString("start_time")
450
+	end_time := c.GetString("end_time")
451
+	patient_id, _ := c.GetInt64("patient_id")
452
+	item_type, _ := c.GetInt64("type")
453
+
454
+	date1, _ := time.Parse("2006-01-02", start_time)
455
+	date2, _ := time.Parse("2006-01-02", end_time)
456
+
457
+	// 计算日期间隔
458
+	duration := date2.Sub(date1)
459
+
460
+	// 一个月的时间跨度为30天 * 24小时 * 60分钟 * 60秒
461
+	oneMonthDuration := 30 * 24 * time.Hour
462
+
463
+	if duration <= oneMonthDuration {
464
+
465
+	} else {
466
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorTimeCodeParamWrong)
467
+		return
468
+	}
469
+
470
+	adminUser := c.GetAdminUserInfo()
471
+	timeLayout := "2006-01-02"
472
+	loc, _ := time.LoadLocation("Local")
473
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
474
+	if err != nil {
475
+
476
+	}
477
+	startRecordDateTime := startTime.Unix()
478
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
479
+	if err != nil {
480
+
481
+	}
482
+	endRecordDateTime := endTime.Unix()
483
+	chargeDrug, err := service.GetHisPrescriptionDrugDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, patient_id, item_type)
484
+	chargeProject, err := service.GetHisPrescriptionProjectDetails(adminUser.CurrentOrgId, start_time+" 00:00:00", end_time+" 23:59:59", startRecordDateTime, endRecordDateTime, patient_id, item_type)
485
+	chargeDrug = append(chargeDrug, chargeProject...)
486
+	b, _ := structpToBytes(chargeDrug)
487
+	//cd, _ := compressData(b)
488
+	// 使用 Gzip 压缩数据
489
+	var compressedData bytes.Buffer
490
+	writer := gzip.NewWriter(&compressedData)
491
+	_, err = writer.Write(b)
492
+	if err != nil {
493
+		c.Ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
494
+		c.Ctx.WriteString(err.Error())
495
+		return
496
+	}
497
+	writer.Close()
498
+	// 设置响应头,表明数据经过了 Gzip 压缩
499
+	c.Ctx.Output.Header("Content-Encoding", "gzip")
500
+	// 发送压缩后的数据
501
+	c.Ctx.ResponseWriter.Write(compressedData.Bytes())
502
+}
503
+
504
+func (c *HisChargeApiController) GetPrescriptionInitData() {
505
+	var drugType = "药品类型"
506
+	drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
507
+	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, c.GetAdminUserInfo().CurrentOrgId)
508
+	var costClassify = "费用类别"
509
+	costClassifyParent, _ := service.GetDrugDataConfig(0, costClassify)
510
+	costClassifyList, _ := service.GetParentDataConfig(costClassifyParent.ID, c.GetAdminUserInfo().CurrentOrgId)
511
+
512
+	c.ServeSuccessJSON(map[string]interface{}{
513
+		"drugTypeList":     drugTypeList,
514
+		"costClassifyList": costClassifyList,
515
+	})
516
+
517
+}
518
+
519
+func structpToBytes(p []*models.NewPDetail) ([]byte, error) {
520
+	data, err := json.Marshal(p)
521
+	if err != nil {
522
+		return nil, err
523
+	}
524
+	return data, nil
525
+}
526
+
444 527
 func structToBytes(p []*models.NewChargeDetail) ([]byte, error) {
445 528
 	data, err := json.Marshal(p)
446 529
 	if err != nil {

+ 4 - 0
enums/error_code.go Dosyayı Görüntüle

@@ -283,6 +283,8 @@ const ( // ErrorCode
283 283
 	ErrorScheduleCode = 600000009
284 284
 
285 285
 	ErrorAdivceCode = 600000010
286
+
287
+	ErrorTimeCodeParamWrong = 600000012
286 288
 )
287 289
 
288 290
 var ErrCodeMsgs = map[int]string{
@@ -545,6 +547,8 @@ var ErrCodeMsgs = map[int]string{
545 547
 	ErrorCodeInformationExist:             "已经超过归档天数,不予编辑,请提交申请",
546 548
 	ErrorScheduleCode:                     "未更改排班,保存失败!",
547 549
 	ErrorAdivceCode:                       "该患者已开药,请先删除药品或耗材",
550
+
551
+	ErrorTimeCodeParamWrong: "时间跨度不能超过一个月",
548 552
 }
549 553
 
550 554
 type SGJError struct {

+ 19 - 0
models/his_charge_models.go Dosyayı Görüntüle

@@ -466,3 +466,22 @@ type NewHisChargeDoctorAdviceInfo struct {
466 466
 func (NewHisChargeDoctorAdviceInfo) TableName() string {
467 467
 	return "his_doctor_advice_info"
468 468
 }
469
+
470
+type NewPDetail struct {
471
+	PType        string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
472
+	PName        string  `gorm:"column:p_name" json:"p_name" form:"p_name"`
473
+	RecordDate   string  `gorm:"column:record_date" json:"record_date" form:"record_date"`
474
+	ItemCostType int64   `gorm:"column:item_cost_type" json:"item_cost_type" form:"item_cost_type"`
475
+	MedType      int64   `gorm:"column:med_type" json:"med_type" form:"med_type"`
476
+	Cnt          float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
477
+	Pric         float64 `gorm:"column:pric" json:"pric" form:"pric"`
478
+	ItemName     string  `gorm:"column:item_name" json:"item_name" form:"item_name"`
479
+	Spec         string  `gorm:"column:spec" json:"spec" form:"spec"`
480
+	OrderStatus  int64   `gorm:"column:order_status" json:"order_status" form:"order_status"`
481
+	Unit         string  `gorm:"column:unit" json:"unit" form:"unit"`
482
+	SetlTime     string  `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
483
+	PId          string  `gorm:"column:p_id" json:"p_id" form:"p_id"`
484
+	AdviceId     string  `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
485
+	ProjectId    string  `gorm:"column:project_id" json:"project_id" form:"project_id"`
486
+	ItemId       string  `gorm:"column:item_id" json:"item_id" form:"item_id"`
487
+}

+ 79 - 28
service/his_charge_service.go Dosyayı Görüntüle

@@ -180,7 +180,7 @@ func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_
180 180
 		case 1:
181 181
 			if time_type == "0" {
182 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").
183
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 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 185
 					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
186 186
 					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
@@ -188,7 +188,7 @@ func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_
188 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 189
 
190 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").
191
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 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 193
 					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
194 194
 					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id").
@@ -207,7 +207,7 @@ func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_
207 207
 		case 0:
208 208
 			if time_type == "0" {
209 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").
210
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 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 212
 					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
213 213
 					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
@@ -216,7 +216,7 @@ func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_
216 216
 
217 217
 			} else {
218 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").
219
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 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 221
 					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
222 222
 					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
@@ -228,7 +228,7 @@ func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_
228 228
 			break
229 229
 		case 1:
230 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").
231
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 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 233
 					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
234 234
 					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
@@ -237,7 +237,7 @@ func GetNewAllPatientDrugChargeDetails(org_id int64, start_time_str string, end_
237 237
 
238 238
 			} else {
239 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").
240
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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 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 242
 					Joins(" JOIN his_doctor_advice_info a ON oi.advice_id = a.id").
243 243
 					Joins(" JOIN xt_patients pp on oi.patient_id = pp.id and pp.name like ?", keyword).
@@ -342,7 +342,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
342 342
 			break
343 343
 		case 4:
344 344
 			if time_type == "0" {
345
-				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").
345
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
346 346
 					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).
347 347
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
348 348
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -351,7 +351,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
351 351
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 and project.cost_classify = 3", org_id, start_time, end_time).Scan(&patients).Error
352 352
 
353 353
 			} else {
354
-				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").
354
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
355 355
 					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).
356 356
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
357 357
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -364,7 +364,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
364 364
 			break
365 365
 		case 5:
366 366
 			if time_type == "0" {
367
-				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").
367
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
368 368
 					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).
369 369
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
370 370
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -373,7 +373,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
373 373
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1  and project.cost_classify = 2", org_id, start_time, end_time).Scan(&patients).Error
374 374
 
375 375
 			} else {
376
-				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").
376
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
377 377
 					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).
378 378
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
379 379
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -386,7 +386,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
386 386
 			break
387 387
 		case 6:
388 388
 			if time_type == "0" {
389
-				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").
389
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
390 390
 					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).
391 391
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
392 392
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -395,7 +395,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
395 395
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 and project.cost_classify = 6", org_id, start_time, end_time).Scan(&patients).Error
396 396
 
397 397
 			} else {
398
-				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
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
399 399
 					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).
400 400
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
401 401
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -406,7 +406,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
406 406
 			break
407 407
 		case 7:
408 408
 			if time_type == "0" {
409
-				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").
409
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
410 410
 					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).
411 411
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
412 412
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -415,7 +415,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
415 415
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ?  and oi.status = 1 and project.cost_classify = 11", org_id, start_time, end_time).Scan(&patients).Error
416 416
 
417 417
 			} else {
418
-				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").
418
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
419 419
 					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).
420 420
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
421 421
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -431,7 +431,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
431 431
 		switch item_type {
432 432
 		case 0:
433 433
 			if time_type == "0" {
434
-				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").
434
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
435 435
 					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).
436 436
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
437 437
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -441,7 +441,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
441 441
 
442 442
 			} else {
443 443
 
444
-				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").
444
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
445 445
 					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).
446 446
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id ").
447 447
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -456,7 +456,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
456 456
 		case 2:
457 457
 			if time_type == "0" {
458 458
 
459
-				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").
459
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
460 460
 					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).
461 461
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
462 462
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -465,7 +465,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
465 465
 					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
466 466
 
467 467
 			} else {
468
-				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").
468
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
469 469
 					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).
470 470
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
471 471
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -479,7 +479,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
479 479
 		case 3:
480 480
 			if time_type == "0" {
481 481
 
482
-				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").
482
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
483 483
 					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).
484 484
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
485 485
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -489,7 +489,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
489 489
 
490 490
 			} else {
491 491
 
492
-				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").
492
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
493 493
 					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).
494 494
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 3").
495 495
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -501,7 +501,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
501 501
 		case 4:
502 502
 			if time_type == "0" {
503 503
 
504
-				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").
504
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
505 505
 					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).
506 506
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
507 507
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -510,7 +510,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
510 510
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1 and project.cost_classify = 3 ", org_id, start_time, end_time).Scan(&patients).Error
511 511
 
512 512
 			} else {
513
-				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").
513
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
514 514
 					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).
515 515
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
516 516
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -522,7 +522,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
522 522
 		case 5:
523 523
 			if time_type == "0" {
524 524
 
525
-				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").
525
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
526 526
 					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).
527 527
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
528 528
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -531,7 +531,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
531 531
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1  and project.cost_classify = 2", org_id, start_time, end_time).Scan(&patients).Error
532 532
 
533 533
 			} else {
534
-				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").
534
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
535 535
 					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).
536 536
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
537 537
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -543,7 +543,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
543 543
 		case 6:
544 544
 			if time_type == "0" {
545 545
 
546
-				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").
546
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
547 547
 					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).
548 548
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
549 549
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -552,7 +552,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
552 552
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1  and project.cost_classify = 10", org_id, start_time, end_time).Scan(&patients).Error
553 553
 
554 554
 			} else {
555
-				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").
555
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
556 556
 					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).
557 557
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
558 558
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -564,7 +564,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
564 564
 		case 7:
565 565
 			if time_type == "0" {
566 566
 
567
-				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").
567
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
568 568
 					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).
569 569
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
570 570
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -573,7 +573,7 @@ func GetNewAllPatientProjectAndGoodChargeDetails(org_id int64, start_time_str st
573 573
 					Where("oi.project_id > 0 and oi.user_org_id = ? and o.settle_accounts_date >= ?  and o.settle_accounts_date <= ? and oi.status = 1   and project.cost_classify = 11", org_id, start_time, end_time).Scan(&patients).Error
574 574
 
575 575
 			} else {
576
-				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").
576
+				err = readDb.Table("his_order_info as oi").Select("FROM_UNIXTIME(o.settle_accounts_date, '%Y-%m-%d %H:%i:%S') as pdate,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").
577 577
 					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).
578 578
 					Joins(" JOIN his_prescription_project p ON oi.project_id = p.id and p.type = 2").
579 579
 					Joins("left join xt_his_project project on  p.project_id = project.id").
@@ -1066,3 +1066,54 @@ func GetAllLisDataFor10191(org_id int64) (list []models.HisLabelPrintStatusInfo,
1066 1066
 	err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1  and apply_code = ''", org_id).Find(&list).Error
1067 1067
 	return
1068 1068
 }
1069
+
1070
+func GetHisPrescriptionDrugDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, patient_id int64, item_type int64) (patients []*models.NewPDetail, err error) {
1071
+	db := readDb.Table("his_doctor_advice_info as oi").Select("drug.id as item_id,1 as p_type,oi.id as advice_id,0 as project_id,pp.id as p_id,pp.name as p_name,FROM_UNIXTIME(o.`record_date`, '%Y-%m-%d') as record_date, drug.drug_type as item_cost_type,o.med_type as med_type,oi.`prescribing_number` as cnt,oi.`price` as pric,drug.drug_name as item_name,CONCAT(drug.dose, \"\", drug.dose_unit, \"*\", drug.min_number, \"\", drug.min_unit, \"/\", drug.max_unit) as spec,o.order_status as order_status,oi.`prescribing_number_unit` as unit").
1072
+		Joins("JOIN xt_base_drug drug ON oi.drug_id = drug.id ")
1073
+	if patient_id == 0 {
1074
+		db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id")
1075
+
1076
+	} else {
1077
+		db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id and pp.id = ?", patient_id)
1078
+
1079
+	}
1080
+
1081
+	if item_type == 0 {
1082
+		db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and   FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.status = 1", start_time_str, end_time_str)
1083
+	} else {
1084
+		if item_type == 2 {
1085
+			db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and   FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.status = 1 and o.order_status = 2", start_time_str, end_time_str)
1086
+		} else {
1087
+			db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and   FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.status = 1 and o.order_status <> 2", start_time_str, end_time_str)
1088
+		}
1089
+	}
1090
+
1091
+	err = db.Where(" oi.user_org_id = ?  AND o.record_date >= ? AND o.record_date <= ? AND oi.status = 1", org_id, start_time, end_time).Scan(&patients).Error
1092
+
1093
+	return
1094
+}
1095
+
1096
+func GetHisPrescriptionProjectDetails(org_id int64, start_time_str string, end_time_str string, start_time int64, end_time int64, patient_id int64, item_type int64) (patients []*models.NewPDetail, err error) {
1097
+	db := readDb.Table("`his_prescription_project` AS oi").Select("(case oi.type\n\t\t\tWHEN 2 THEN\n\t\t\tproject.id\n\t\t\tWHEN 3 THEN\n\t\t\tgood.id END) AS item_id,oi.type as p_type,oi.id as project_id,0 as advice_id,pp.id as p_id,(case oi.type\n\t\t\tWHEN 2 THEN\n\t\t\tproject.`cost_classify`\n\t\t\tWHEN 3 THEN\n\t\t\t-100 END) AS item_cost_type,\n\t o.med_type as med_type,\n\t oi.count AS cnt,\n \t oi.price AS pric,\n \t pp.name AS p_name, \n \tFROM_UNIXTIME(o.`record_date`,'%Y-%m-%d') as record_date,\n\t\t (case oi.type\n\tWHEN 2 THEN\n\tproject.project_name\n\tWHEN 3 THEN\n\tgood.good_name END) AS item_name,\n\t\t (case oi.type\n\tWHEN 2 THEN\n\t\"\"\n\tWHEN 3 THEN\n\tgood.`specification_name` END) AS spec,\n\toi.`unit`  as unit,o.order_status as order_status")
1098
+	db = db.Joins("LEFT JOIN xt_his_project project\n\tON oi.project_id = project.id").
1099
+		Joins("LEFT JOIN xt_good_information good\n\tON oi.project_id = good.id\n")
1100
+	//Joins("JOIN his_order ord ON o.batch_number = ord.number ")
1101
+	if patient_id > 0 {
1102
+		db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id and pp.id = ?", patient_id)
1103
+	} else {
1104
+		db = db.Joins("JOIN xt_patients pp on oi.patient_id = pp.id")
1105
+	}
1106
+
1107
+	if item_type > 0 {
1108
+		if item_type == 2 {
1109
+			db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and   FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.status = 1 and o.order_status = 2", start_time_str, end_time_str)
1110
+		} else {
1111
+			db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and   FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.status = 1 and o.order_status <> 2", start_time_str, end_time_str)
1112
+		}
1113
+	} else {
1114
+		db = db.Joins("JOIN `his_prescription` o ON oi.`prescription_id` = o.id and   FROM_UNIXTIME(o.record_date, '%Y-%m-%d %H:%i:%S') BETWEEN ? AND ?  and o.status = 1", start_time_str, end_time_str)
1115
+	}
1116
+
1117
+	err = db.Where(" oi.user_org_id = ?  AND o.record_date >= ? AND o.record_date <= ? AND oi.status = 1", org_id, start_time, end_time).Scan(&patients).Error
1118
+	return
1119
+}

+ 30 - 0
service/his_service.go Dosyayı Görüntüle

@@ -210,6 +210,22 @@ func (PatientTwo) TableName() string {
210 210
 	return "xt_patients"
211 211
 }
212 212
 
213
+type PatientThree struct {
214
+	ID              int64                    `gorm:"column:id" json:"id" form:"id"`
215
+	UserOrgId       int64                    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
216
+	Name            string                   `gorm:"column:name" json:"name" form:"name"`
217
+	Status          int64                    `gorm:"column:status" json:"status" form:"status"`
218
+	IdCardNo        string                   `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
219
+	ScheduleType    int64                    `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
220
+	Schedule        Schedule                 `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
221
+	FirstLetter     string                   `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
222
+	HisPrescription []models.HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
223
+}
224
+
225
+func (PatientThree) TableName() string {
226
+	return "xt_patients"
227
+}
228
+
213 229
 type HisPatientTwo struct {
214 230
 	ID                 int64                 `gorm:"column:id" json:"id" form:"id"`
215 231
 	Name               string                `gorm:"column:name" json:"name" form:"name"`
@@ -265,6 +281,15 @@ func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64) (pati
265 281
 	return
266 282
 }
267 283
 
284
+func GetNewHisPatientListTwo(org_id int64, record_date int64, sch_type int64) (patients []*PatientThree, err error) {
285
+	db := readDb.Model(&PatientThree{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
286
+	//if sch_type > 0 {
287
+	db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ?", record_date, org_id)
288
+	//}
289
+	err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? and his_patient_id = 0", org_id, record_date).Group("id").Find(&patients).Error
290
+	return
291
+}
292
+
268 293
 func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
269 294
 	db := readDb.Model(&PatientTwo{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
270 295
 
@@ -3480,3 +3505,8 @@ func GetBasedrugByIdOne(drug_id int64, user_org_id int64) (models.BaseDrugLib, e
3480 3505
 
3481 3506
 	return lib, err
3482 3507
 }
3508
+
3509
+//func UpDateOrderT111(order models.histen) (err error) {
3510
+//	err = writeDb.Save(&order).Error
3511
+//	return
3512
+//}