Преглед изворни кода

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

28169 пре 1 година
родитељ
комит
687ecb6c3f

+ 2 - 2
controllers/his_hospital_api_controller.go Прегледај датотеку

@@ -47,7 +47,7 @@ func HisHospitalManagerApiRegistRouters() {
47 47
 }
48 48
 func (this *HisHospitalApiController) ModifyFaPiaoCode() {
49 49
 	order_id, _ := this.GetInt64("id")
50
-	fapiao_code := this.GetString("fapiao_code")
50
+	fapiao_number := this.GetString("fapiao_number")
51 51
 
52 52
 	order, _ := service.GetHisOrderByID(order_id)
53 53
 	if order.ID == 0 {
@@ -55,7 +55,7 @@ func (this *HisHospitalApiController) ModifyFaPiaoCode() {
55 55
 		return
56 56
 	}
57 57
 
58
-	order.FaPiaoCode = fapiao_code
58
+	order.FaPiaoNumber = fapiao_number
59 59
 	err := service.SaveOrderTwo(&order)
60 60
 	if err != nil {
61 61
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)

+ 248 - 39
controllers/statistics_api_controller.go Прегледај датотеку

@@ -7,6 +7,7 @@ import (
7 7
 	"XT_New/utils"
8 8
 	"fmt"
9 9
 	"github.com/astaxie/beego"
10
+	"sort"
10 11
 	"strconv"
11 12
 	"strings"
12 13
 	"time"
@@ -345,27 +346,23 @@ func (c *StatisticsApiController) GetDialysisTotalDetail() {
345 346
 				//fmt.Println(aa)
346 347
 				var dynamicFields []map[string]interface{}
347 348
 				//var uniqueFields []map[string]interface{}
348
-
349 349
 				for _, result := range list {
350
-					// 打印患者ID
351 350
 					nb := result["日期"].([]byte)
352 351
 					name := string(nb)
353 352
 
354
-					// 创建动态字段的map
355 353
 					dynamicField := make(map[string]interface{})
356
-					// 将日期放在首位
357 354
 					dynamicField["日期"] = name
358 355
 
359
-					// 打印其他列的值,并添加到动态字段中
356
+					numericColumns := make(map[string]interface{})
357
+					nonNumericColumns := make(map[string]interface{})
358
+
359
+					// 分类处理列
360 360
 					for columnName, columnValue := range result {
361
-						if columnName == "日期" {
362
-							continue
363
-						}
364
-						if columnName == "合计" {
361
+						if columnName == "日期" || columnName == "合计" {
365 362
 							continue
366 363
 						}
367 364
 						if columnValue == nil {
368
-							dynamicField[columnName] = ""
365
+							nonNumericColumns[columnName] = ""
369 366
 							continue
370 367
 						}
371 368
 
@@ -376,36 +373,49 @@ func (c *StatisticsApiController) GetDialysisTotalDetail() {
376 373
 						}
377 374
 
378 375
 						strValue := string(byteValue)
379
-
380 376
 						floatValue, err := strconv.ParseFloat(strValue, 64)
381 377
 						if err != nil {
382 378
 							fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
379
+							nonNumericColumns[columnName] = strValue
383 380
 						} else {
384 381
 							if floatValue == 0 {
385
-								dynamicField[columnName] = ""
382
+								nonNumericColumns[columnName] = ""
386 383
 							} else {
387
-								dynamicField[columnName] = floatValue
384
+								numericColumns[columnName] = floatValue
388 385
 							}
389 386
 						}
390 387
 					}
391 388
 
392
-					// 将合计放在末尾
389
+					// 添加数值列
390
+					for columnName, columnValue := range numericColumns {
391
+						dynamicField[columnName] = columnValue
392
+					}
393
+
394
+					// 添加非数值列
395
+					for columnName, columnValue := range nonNumericColumns {
396
+						dynamicField[columnName] = columnValue
397
+					}
398
+
393 399
 					hj := result["合计"].(int64)
394 400
 					dynamicField["合计"] = hj
395 401
 
396 402
 					dynamicFields = append(dynamicFields, dynamicField)
397 403
 				}
398 404
 
399
-				// 将日期放在首位
400 405
 				seen := make(map[interface{}]struct{})
401 406
 				for _, field := range dynamicFields {
402 407
 					value := field["日期"]
403 408
 					if _, ok := seen[value]; !ok {
404 409
 						seen[value] = struct{}{}
405 410
 						uniqueFields = append(uniqueFields, field)
411
+
412
+						//// 对字段进行排序,有值的排在前面
413
+						//sortedField := sortFieldsByValue(field)
414
+						//uniqueFields = append(uniqueFields, sortedField)
406 415
 					}
407 416
 				}
408 417
 			}
418
+
409 419
 			c.ServeSuccessJSON(map[string]interface{}{
410 420
 				"list": uniqueFields,
411 421
 			})
@@ -427,29 +437,25 @@ func (c *StatisticsApiController) GetDialysisTotalDetail() {
427 437
 			var uniqueFields []map[string]interface{}
428 438
 			for _, date := range dailyDates {
429 439
 				list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
430
-				//fmt.Println(aa)
431 440
 				var dynamicFields []map[string]interface{}
432 441
 
433 442
 				for _, result := range list {
434
-					// 打印患者ID
435 443
 					nb := result["日期"].([]byte)
436 444
 					name := string(nb)
437 445
 
438
-					// 创建动态字段的map
439 446
 					dynamicField := make(map[string]interface{})
440
-					// 将日期放在首位
441 447
 					dynamicField["日期"] = name
442 448
 
443
-					// 打印其他列的值,并添加到动态字段中
449
+					numericColumns := make(map[string]interface{})
450
+					nonNumericColumns := make(map[string]interface{})
451
+
452
+					// 分类处理列
444 453
 					for columnName, columnValue := range result {
445
-						if columnName == "日期" {
446
-							continue
447
-						}
448
-						if columnName == "合计" {
454
+						if columnName == "日期" || columnName == "合计" {
449 455
 							continue
450 456
 						}
451 457
 						if columnValue == nil {
452
-							dynamicField[columnName] = ""
458
+							nonNumericColumns[columnName] = ""
453 459
 							continue
454 460
 						}
455 461
 
@@ -460,27 +466,35 @@ func (c *StatisticsApiController) GetDialysisTotalDetail() {
460 466
 						}
461 467
 
462 468
 						strValue := string(byteValue)
463
-
464 469
 						floatValue, err := strconv.ParseFloat(strValue, 64)
465 470
 						if err != nil {
466 471
 							fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
472
+							nonNumericColumns[columnName] = strValue
467 473
 						} else {
468 474
 							if floatValue == 0 {
469
-								dynamicField[columnName] = ""
475
+								nonNumericColumns[columnName] = ""
470 476
 							} else {
471
-								dynamicField[columnName] = floatValue
477
+								numericColumns[columnName] = floatValue
472 478
 							}
473 479
 						}
474 480
 					}
475 481
 
476
-					// 将合计放在末尾
482
+					// 添加数值列
483
+					for columnName, columnValue := range numericColumns {
484
+						dynamicField[columnName] = columnValue
485
+					}
486
+
487
+					// 添加非数值列
488
+					for columnName, columnValue := range nonNumericColumns {
489
+						dynamicField[columnName] = columnValue
490
+					}
491
+
477 492
 					hj := result["合计"].(int64)
478 493
 					dynamicField["合计"] = hj
479 494
 
480 495
 					dynamicFields = append(dynamicFields, dynamicField)
481 496
 				}
482 497
 
483
-				// 将日期放在首位
484 498
 				seen := make(map[interface{}]struct{})
485 499
 				for _, field := range dynamicFields {
486 500
 					value := field["日期"]
@@ -490,6 +504,143 @@ func (c *StatisticsApiController) GetDialysisTotalDetail() {
490 504
 					}
491 505
 				}
492 506
 			}
507
+
508
+			//for _, date := range dailyDates {
509
+			//	list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
510
+			//	//fmt.Println(aa)
511
+			//	var dynamicFields []map[string]interface{}
512
+			//
513
+			//	for _, result := range list {
514
+			//		// 打印患者ID
515
+			//		nb := result["日期"].([]byte)
516
+			//		name := string(nb)
517
+			//
518
+			//		// 创建动态字段的map
519
+			//		dynamicField := make(map[string]interface{})
520
+			//		// 将日期放在首位
521
+			//		dynamicField["日期"] = name
522
+			//
523
+			//		// 临时存储无数值的列
524
+			//		nonNumericColumns := make(map[string]interface{})
525
+			//
526
+			//		// 先处理包含数值的列
527
+			//		for columnName, columnValue := range result {
528
+			//			if columnName == "日期" || columnName == "合计" {
529
+			//				continue
530
+			//			}
531
+			//			if columnValue == nil {
532
+			//				nonNumericColumns[columnName] = ""
533
+			//				continue
534
+			//			}
535
+			//
536
+			//			byteValue, ok := columnValue.([]byte)
537
+			//			if !ok {
538
+			//				fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
539
+			//				continue
540
+			//			}
541
+			//
542
+			//			strValue := string(byteValue)
543
+			//
544
+			//			floatValue, err := strconv.ParseFloat(strValue, 64)
545
+			//			if err != nil {
546
+			//				fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
547
+			//				nonNumericColumns[columnName] = strValue
548
+			//			} else {
549
+			//				if floatValue == 0 {
550
+			//					nonNumericColumns[columnName] = ""
551
+			//				} else {
552
+			//					dynamicField[columnName] = floatValue
553
+			//				}
554
+			//			}
555
+			//		}
556
+			//
557
+			//		// 添加无数值的列
558
+			//		for columnName, columnValue := range nonNumericColumns {
559
+			//			dynamicField[columnName] = columnValue
560
+			//		}
561
+			//
562
+			//		// 将合计放在末尾
563
+			//		hj := result["合计"].(int64)
564
+			//		dynamicField["合计"] = hj
565
+			//
566
+			//		dynamicFields = append(dynamicFields, dynamicField)
567
+			//	}
568
+			//
569
+			//	// 将日期放在首位
570
+			//	seen := make(map[interface{}]struct{})
571
+			//	for _, field := range dynamicFields {
572
+			//		value := field["日期"]
573
+			//		if _, ok := seen[value]; !ok {
574
+			//			seen[value] = struct{}{}
575
+			//			uniqueFields = append(uniqueFields, field)
576
+			//		}
577
+			//	}
578
+			//}
579
+			//for _, date := range dailyDates {
580
+			//	list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
581
+			//	//fmt.Println(aa)
582
+			//	var dynamicFields []map[string]interface{}
583
+			//
584
+			//	for _, result := range list {
585
+			//		// 打印患者ID
586
+			//		nb := result["日期"].([]byte)
587
+			//		name := string(nb)
588
+			//
589
+			//		// 创建动态字段的map
590
+			//		dynamicField := make(map[string]interface{})
591
+			//		// 将日期放在首位
592
+			//		dynamicField["日期"] = name
593
+			//
594
+			//		// 打印其他列的值,并添加到动态字段中
595
+			//		for columnName, columnValue := range result {
596
+			//			if columnName == "日期" {
597
+			//				continue
598
+			//			}
599
+			//			if columnName == "合计" {
600
+			//				continue
601
+			//			}
602
+			//			if columnValue == nil {
603
+			//				dynamicField[columnName] = ""
604
+			//				continue
605
+			//			}
606
+			//
607
+			//			byteValue, ok := columnValue.([]byte)
608
+			//			if !ok {
609
+			//				fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
610
+			//				continue
611
+			//			}
612
+			//
613
+			//			strValue := string(byteValue)
614
+			//
615
+			//			floatValue, err := strconv.ParseFloat(strValue, 64)
616
+			//			if err != nil {
617
+			//				fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
618
+			//			} else {
619
+			//				if floatValue == 0 {
620
+			//					dynamicField[columnName] = ""
621
+			//				} else {
622
+			//					dynamicField[columnName] = floatValue
623
+			//				}
624
+			//			}
625
+			//		}
626
+			//
627
+			//		// 将合计放在末尾
628
+			//		hj := result["合计"].(int64)
629
+			//		dynamicField["合计"] = hj
630
+			//
631
+			//		dynamicFields = append(dynamicFields, dynamicField)
632
+			//	}
633
+			//
634
+			//	// 将日期放在首位
635
+			//	seen := make(map[interface{}]struct{})
636
+			//	for _, field := range dynamicFields {
637
+			//		value := field["日期"]
638
+			//		if _, ok := seen[value]; !ok {
639
+			//			seen[value] = struct{}{}
640
+			//			uniqueFields = append(uniqueFields, field)
641
+			//		}
642
+			//	}
643
+			//}
493 644
 			c.ServeSuccessJSON(map[string]interface{}{
494 645
 				"list": uniqueFields,
495 646
 			})
@@ -1026,8 +1177,17 @@ func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
1026 1177
 	origin, _ := c.GetInt64("origin")
1027 1178
 	page, _ := c.GetInt64("page")
1028 1179
 	limit, _ := c.GetInt64("limit")
1029
-	start_date := strings.Split(date_str, "~")[0]
1030
-	end_date := strings.Split(date_str, "~")[1]
1180
+	time_way, _ := c.GetInt64("time_way")
1181
+	var start_date string
1182
+	var end_date string
1183
+	if time_way == 1 {
1184
+		start_date = date_str
1185
+		end_date = date_str
1186
+	} else {
1187
+		start_date = strings.Split(date_str, "~")[0]
1188
+		end_date = strings.Split(date_str, "~")[1]
1189
+	}
1190
+
1031 1191
 	if origin == 1 {
1032 1192
 		qcp, total, _ := service.GetDialysisPrescriptionInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
1033 1193
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -1173,6 +1333,8 @@ func (c *StatisticsApiController) GetDialyzer() {
1173 1333
 		return
1174 1334
 	}
1175 1335
 	dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
1336
+	DialysisIrrigation, err := service.GetDialysisIrrigationData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
1337
+
1176 1338
 	if err != nil {
1177 1339
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1178 1340
 		return
@@ -1184,11 +1346,23 @@ func (c *StatisticsApiController) GetDialyzer() {
1184 1346
 	}
1185 1347
 	var respDatas []respData
1186 1348
 	for _, item := range dialyzers {
1187
-		var respData respData
1188
-		respData.Name = item.Dialyzer
1189
-		respData.Count = item.Count
1190
-		respData.Percentage = float64(item.Count) / float64(total) * 100
1191
-		respDatas = append(respDatas, respData)
1349
+		if len(item.Dialyzer) > 0 {
1350
+			var respData respData
1351
+			respData.Name = item.Dialyzer
1352
+			respData.Count = item.Count
1353
+			respData.Percentage = float64(item.Count) / float64(total) * 100
1354
+			respDatas = append(respDatas, respData)
1355
+		}
1356
+	}
1357
+	for _, item := range DialysisIrrigation {
1358
+		if len(item.Dialyzer) > 0 {
1359
+
1360
+			var respData respData
1361
+			respData.Name = item.Dialyzer
1362
+			respData.Count = item.Count
1363
+			respData.Percentage = float64(item.Count) / float64(total) * 100
1364
+			respDatas = append(respDatas, respData)
1365
+		}
1192 1366
 	}
1193 1367
 	c.ServeSuccessJSON(map[string]interface{}{
1194 1368
 		"data": respDatas,
@@ -1238,8 +1412,8 @@ func (c *StatisticsApiController) GetDialyzerDetail() {
1238 1412
 }
1239 1413
 func (c *StatisticsApiController) GetDialyzerConfig() {
1240 1414
 	dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
1241
-	//Irrigation, _ := service.GetIrrigationSummary(c.GetAdminUserInfo().CurrentOrgId)
1242
-	//dialyzers = append(dialyzers, Irrigation...)
1415
+	Irrigation, _ := service.GetIrrigationSummary(c.GetAdminUserInfo().CurrentOrgId)
1416
+	dialyzers = append(dialyzers, Irrigation...)
1243 1417
 	c.ServeSuccessJSON(map[string]interface{}{
1244 1418
 		"dialyzers": dialyzers,
1245 1419
 	})
@@ -2011,3 +2185,38 @@ func splitByDay(startDate, endDate time.Time) []time.Time {
2011 2185
 	}
2012 2186
 	return dates
2013 2187
 }
2188
+
2189
+// 排序函数
2190
+func sortFieldsByValue(field map[string]interface{}) map[string]interface{} {
2191
+	// 将键值对分成两个部分,一个有值,一个无值
2192
+	var withValue, withoutValue []string
2193
+
2194
+	for key, value := range field {
2195
+		if key == "日期" || key == "合计" {
2196
+			continue
2197
+		}
2198
+		if value == "" {
2199
+			withoutValue = append(withoutValue, key)
2200
+		} else {
2201
+			withValue = append(withValue, key)
2202
+		}
2203
+	}
2204
+
2205
+	// 对有值和无值部分分别排序
2206
+	sort.Strings(withValue)
2207
+	sort.Strings(withoutValue)
2208
+
2209
+	// 创建一个新的有序map
2210
+	sortedField := make(map[string]interface{})
2211
+	sortedField["日期"] = field["日期"]
2212
+
2213
+	for _, key := range withValue {
2214
+		sortedField[key] = field[key]
2215
+	}
2216
+	for _, key := range withoutValue {
2217
+		sortedField[key] = field[key]
2218
+	}
2219
+
2220
+	sortedField["合计"] = field["合计"]
2221
+	return sortedField
2222
+}

+ 9 - 0
models/dialysis.go Прегледај датотеку

@@ -1706,3 +1706,12 @@ type XtDialysisOrderLost struct {
1706 1706
 func (XtDialysisOrderLost) TableName() string {
1707 1707
 	return "xt_dialysis_order"
1708 1708
 }
1709
+
1710
+type MewTreatmentMode struct {
1711
+	Name   string `gorm:"column:name" json:"name" form:"name"`
1712
+	ModeID int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
1713
+}
1714
+
1715
+func (MewTreatmentMode) TableName() string {
1716
+	return "xt_treatment_mode"
1717
+}

+ 47 - 39
service/statistis_qc_service.go Прегледај датотеку

@@ -50,12 +50,10 @@ type DialysisStat struct {
50 50
 	Total  int            `json:"合计"`
51 51
 }
52 52
 
53
-func GetTreatmentModes() ([]models.TreatmentMode, error) {
54
-	var modes []models.TreatmentMode
55
-	if err := XTReadDB().Model(&models.TreatmentMode{}).Find(&modes).Error; err != nil {
56
-		return nil, err
57
-	}
58
-	return modes, nil
53
+func GetTreatmentModes(org_id int64, start string, end string) (mode []models.MewTreatmentMode) {
54
+	//XTReadDB().Model(&models.HisPrescription{}).Joins("join xt_treatment_mode mode on").Where("user_org_id = ?", org_id).Find(&modes).Error
55
+	XTReadDB().Table("xt_dialysis_prescription p").Joins("join xt_treatment_mode mode on mode.id = p.mode_id").Where("p.user_org_id = ? and  FROM_UNIXTIME(p.record_date) >= ? AND FROM_UNIXTIME(p.record_date) <= ?", org_id, start, end).Select("mode.name as name, p.mode_id as mode_id").Group("p.mode_id").Scan(&mode)
56
+	return
59 57
 }
60 58
 
61 59
 func GetDialysisStats(start int64, end int64, mode int64, org_id int64, time_way int64) ([]map[string]interface{}, error) {
@@ -72,13 +70,13 @@ func GetDialysisStats(start int64, end int64, mode int64, org_id int64, time_way
72 70
 	// 将时间格式化为字符串
73 71
 	endDate := t2.Format(layout) + " 00:00:00"
74 72
 	//var stats []DialysisStat
75
-	var modes []models.TreatmentMode
73
+	var modes []models.MewTreatmentMode
76 74
 	fmt.Println(mode)
77 75
 	if mode == 0 {
78
-		modes, _ = GetTreatmentModes()
76
+		modes = GetTreatmentModes(org_id, startDate, endDate)
79 77
 
80 78
 	} else {
81
-		modes_two, _ := GetTreatmentModes()
79
+		modes_two := GetTreatmentModes(org_id, startDate, endDate)
82 80
 		for _, item := range modes_two {
83 81
 			if item.ModeID == mode {
84 82
 				modes = append(modes, item)
@@ -94,7 +92,7 @@ func GetDialysisStats(start int64, end int64, mode int64, org_id int64, time_way
94 92
 	// 构建动态查询语句
95 93
 	if time_way == 1 {
96 94
 		//selectClauses = []string{fmt.Sprintf("'%s' AS `日期`", strings.Split(startDate, " ")[0])}
97
-		selectClauses = []string{fmt.Sprintf("'%s' AS `日期`", strings.Split(startDate, " ")[0]+"~"+strings.Split(endDate, " ")[0])}
95
+		selectClauses = []string{fmt.Sprintf("'%s' AS `日期`", strings.Split(startDate, " ")[0])}
98 96
 
99 97
 	} else if time_way == 3 {
100 98
 		selectClauses = []string{fmt.Sprintf("'%s' AS `日期`", strings.Split(startDate, " ")[0]+"~"+strings.Split(endDate, " ")[0])}
@@ -218,13 +216,13 @@ func GetScheduleStats(start int64, end int64, mode int64, org_id int64, time_way
218 216
 	// 将时间格式化为字符串
219 217
 	endDate := t2.Format(layout) + " 00:00:00"
220 218
 	//var stats []DialysisStat
221
-	var modes []models.TreatmentMode
219
+	var modes []models.MewTreatmentMode
222 220
 	fmt.Println(mode)
223 221
 	if mode == 0 {
224
-		modes, _ = GetTreatmentModes()
222
+		modes = GetTreatmentModes(org_id, startDate, endDate)
225 223
 
226 224
 	} else {
227
-		modes_two, _ := GetTreatmentModes()
225
+		modes_two := GetTreatmentModes(org_id, startDate, endDate)
228 226
 		for _, item := range modes_two {
229 227
 			if item.ModeID == mode {
230 228
 				modes = append(modes, item)
@@ -543,10 +541,10 @@ func GetAnticoagulantData(start_time int64, end_time int64, org_id int64) (map[s
543 541
 		Count         int
544 542
 	}
545 543
 
546
-	err := XTReadDB().Model(&models.DialysisPrescription{}).
547
-		Select("anticoagulant, COUNT(*) as count").
548
-		Where("status = 1 and record_date >= ? and record_date <= ? and user_org_id = ?", start_time, end_time, org_id).
549
-		Group("anticoagulant").
544
+	err := XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").
545
+		Select("xt_dialysis_prescription.anticoagulant, COUNT(*) as count").
546
+		Where("xt_dialysis_prescription.status = 1 and xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ? and xt_dialysis_prescription.user_org_id = ?", start_time, end_time, org_id).
547
+		Group("xt_dialysis_prescription.anticoagulant").
550 548
 		Scan(&results).Error
551 549
 	if err != nil {
552 550
 		return nil, err
@@ -555,16 +553,17 @@ func GetAnticoagulantData(start_time int64, end_time int64, org_id int64) (map[s
555 553
 	for _, result := range results {
556 554
 		if name, ok := anticoagulantMap[result.Anticoagulant]; ok {
557 555
 			anticoagulantData[name] = result.Count
558
-		} else {
559
-			anticoagulantData[fmt.Sprintf("Unknown (%d)", result.Anticoagulant)] = result.Count
560 556
 		}
557
+		//else {
558
+		//	anticoagulantData[fmt.Sprintf("Unknown (%d)", result.Anticoagulant)] = result.Count
559
+		//}z
561 560
 	}
562 561
 
563 562
 	return anticoagulantData, nil
564 563
 }
565 564
 func GetAnticoagulantTotal(start_time int64, end_time int64, org_id int64) (total int64, err error) {
566
-	err = XTReadDB().Model(&models.DialysisPrescription{}).
567
-		Where("record_date >= ? and record_date <= ? and user_org_id = ? and status = 1", start_time, end_time, org_id).
565
+	err = XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").
566
+		Where("xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ? and xt_dialysis_prescription.user_org_id = ? and xt_dialysis_prescription.status = 1", start_time, end_time, org_id).
568 567
 		Count(&total).Error
569 568
 
570 569
 	return
@@ -601,10 +600,19 @@ type DialyzerResult struct {
601 600
 }
602 601
 
603 602
 func GetDialyzerData(start_time int64, end_time int64, org_id int64) (dr []DialyzerResult, err error) {
604
-	err = XTReadDB().Model(&models.DialysisPrescription{}).
605
-		Select("dialysis_dialyszers as dialyzer, COUNT(*) as count").
606
-		Where("record_date >= ? and record_date <= ? and user_org_id = ? and status = 1", start_time, end_time, org_id).
607
-		Group("dialysis_dialyszers").
603
+	err = XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").
604
+		Select("xt_dialysis_prescription.dialysis_dialyszers as dialyzer, COUNT(*) as count").
605
+		Where("xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ? and xt_dialysis_prescription.user_org_id = ? and xt_dialysis_prescription.status = 1", start_time, end_time, org_id).
606
+		Group("xt_dialysis_prescription.dialysis_dialyszers").
607
+		Scan(&dr).Error
608
+	return
609
+}
610
+
611
+func GetDialysisIrrigationData(start_time int64, end_time int64, org_id int64) (dr []DialyzerResult, err error) {
612
+	err = XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").
613
+		Select("xt_dialysis_prescription.dialysis_irrigation as dialysis_irrigation, COUNT(*) as count").
614
+		Where("xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ? and xt_dialysis_prescription.user_org_id = ? and xt_dialysis_prescription.status = 1", start_time, end_time, org_id).
615
+		Group("xt_dialysis_prescription.dialysis_irrigation").
608 616
 		Scan(&dr).Error
609 617
 	return
610 618
 }
@@ -619,22 +627,22 @@ func GetIrrigationData(start_time int64, end_time int64, org_id int64) (dr []Dia
619 627
 }
620 628
 
621 629
 func GetDialyzerTotal(start_time int64, end_time int64, org_id int64) (total int64, err error) {
622
-	err = XTReadDB().Model(&models.DialysisPrescription{}).
623
-		Where("status = 1 and record_date >= ? and record_date <= ? and user_org_id = ? and dialysis_dialyszers <> ''", start_time, end_time, org_id).
630
+	err = XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").
631
+		Where("xt_dialysis_prescription.status = 1 and xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ? and xt_dialysis_prescription.user_org_id = ?", start_time, end_time, org_id).
624 632
 		Count(&total).Error
625 633
 	return
626 634
 }
627 635
 
628 636
 func GetPrescriptionByAnticoagulant(page int64, limit int64, orgid int64, anticoagulant int64, start_time int64, end_time int64) (solution []*models.DialysisPrescription, total int64, err error) {
629 637
 
630
-	db := XTReadDB().Model(&models.DialysisPrescription{}).Preload("QCPatients", "status = 1 and user_org_id = ?", orgid).Where("status = 1")
638
+	db := XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").Preload("QCPatients", "xt_patients.status = 1 and xt_patients.user_org_id = ?", orgid).Where("xt_dialysis_prescription.status = 1")
631 639
 	if anticoagulant > 0 {
632
-		db = db.Where("anticoagulant = ?", anticoagulant)
640
+		db = db.Where("xt_dialysis_prescription.anticoagulant = ?", anticoagulant)
633 641
 	}
634 642
 	if orgid > 0 {
635
-		db = db.Where("user_org_id = ?", orgid)
643
+		db = db.Where("xt_dialysis_prescription.user_org_id = ?", orgid)
636 644
 	}
637
-	db = db.Where("record_date >= ? and record_date <= ?", start_time, end_time)
645
+	db = db.Where("xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ?", start_time, end_time)
638 646
 
639 647
 	offset := (page - 1) * limit
640 648
 
@@ -644,14 +652,14 @@ func GetPrescriptionByAnticoagulant(page int64, limit int64, orgid int64, antico
644 652
 
645 653
 func GetPrescriptionByDialyzer(page int64, limit int64, orgid int64, dialyzer string, start_time int64, end_time int64) (solution []*models.DialysisPrescription, total int64, err error) {
646 654
 
647
-	db := XTReadDB().Model(&models.DialysisPrescription{}).Preload("QCPatients", "status = 1 and user_org_id = ?", orgid).Where("status = 1")
655
+	db := XTReadDB().Model(&models.DialysisPrescription{}).Joins("join xt_dialysis_order oo on oo.patient_id = xt_dialysis_prescription.patient_id and oo.dialysis_date = xt_dialysis_prescription.record_date and oo.status = 1").Preload("QCPatients", "xt_patients.status = 1 and xt_patients.user_org_id = ?", orgid).Where("xt_dialysis_prescription.status = 1")
648 656
 	if len(dialyzer) > 0 {
649
-		db = db.Where("dialysis_dialyszers = ?", dialyzer)
657
+		db = db.Where("xt_dialysis_prescription.dialysis_dialyszers = ? or xt_dialysis_prescription.dialysis_irrigation = ?", dialyzer, dialyzer)
650 658
 	}
651 659
 	if orgid > 0 {
652
-		db = db.Where("user_org_id = ?", orgid)
660
+		db = db.Where("xt_dialysis_prescription.user_org_id = ?", orgid)
653 661
 	}
654
-	db = db.Where("record_date >= ? and record_date <= ? and status = 1", start_time, end_time)
662
+	db = db.Where("xt_dialysis_prescription.record_date >= ? and xt_dialysis_prescription.record_date <= ? and xt_dialysis_prescription.status = 1", start_time, end_time)
655 663
 
656 664
 	offset := (page - 1) * limit
657 665
 
@@ -680,9 +688,9 @@ func GetDialysisCompletionRate(org_id int64, start_time int64, end_time int64) (
680 688
 	query := `
681 689
         SELECT
682 690
             CASE
683
-                WHEN ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) <= 15 THEN '达'
684
-                WHEN TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) < 0 THEN '未达标'
685
-                ELSE '超时'
691
+                WHEN ABS(TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0))) <= 15 THEN '达到透析处方时间'
692
+                WHEN TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) < -15 THEN '超出处方时间'
693
+                ELSE '未到达处方时间'
686 694
             END AS dialysis_status,
687 695
             COUNT(*) AS count
688 696
         FROM
@@ -808,7 +816,7 @@ func GetDialysisCompletionDetail(org_id int64, start_time int64, end_time int64,
808 816
 	   JOIN
809 817
 	       xt_assessment_after_dislysis a ON o.dialysis_date = a.assessment_date AND o.patient_id = a.patient_id AND a.user_org_id = ?
810 818
 	   WHERE
811
-	       o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) < 0
819
+	       o.stage = 2 AND o.user_org_id = ? AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND TIMESTAMPDIFF(MINUTE, MAKETIME(p.dialysis_duration_hour, p.dialysis_duration_minute, 0), MAKETIME(a.actual_treatment_hour, a.actual_treatment_minute, 0)) < -15
812 820
 	`
813 821
 		readDb.Table("xt_dialysis_order o").
814 822
 			Joins("JOIN xt_patients pp ON o.patient_id = pp.id AND pp.user_org_id = ?", org_id).