Browse Source

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

XMLWAN 3 years ago
parent
commit
9cec9a3fca
51 changed files with 3129 additions and 1276 deletions
  1. 14 1
      conf/app.conf
  2. 59 2
      controllers/base_api_controller.go
  3. 5 1
      controllers/dialysis_api_controller.go
  4. 22 1
      controllers/doctors_api_controller.go
  5. 329 139
      controllers/drug_stock_api_contorller.go
  6. 77 1
      controllers/gobal_config_api_controller.go
  7. 26 7
      controllers/his_api_controller.go
  8. 214 0
      controllers/his_charge_api_controller.go
  9. 2 2
      controllers/his_config_api_controller.go
  10. 1 1
      controllers/his_hospital_api_controller.go
  11. 9 2
      controllers/his_project_api_controller.go
  12. 5 8
      controllers/manage_api_controller.go
  13. 5 1
      controllers/manager_center_api_controller.go
  14. 66 53
      controllers/mobile_api_controllers/dialysis_api_controller.go
  15. 20 0
      controllers/mobile_api_controllers/doctor_advice_api_controller.go
  16. 120 57
      controllers/mobile_api_controllers/patient_api_controller.go
  17. 2 2
      controllers/new_mobile_api_controllers/mobile_his_api_controller.go
  18. 335 10
      controllers/new_mobile_api_controllers/staff_schedule_api_controller.go
  19. 5 0
      controllers/new_mobile_api_controllers/staff_schedule_api_router.go
  20. 64 70
      controllers/patient_api_controller.go
  21. 30 31
      controllers/public_api_controller.go
  22. 28 5
      controllers/self_drug_api_congtroller.go
  23. 471 98
      controllers/stock_in_api_controller.go
  24. 2 0
      models/common_models.go
  25. 76 21
      models/device_models.go
  26. 58 2
      models/dialysis.go
  27. 4 3
      models/drug.go
  28. 2 0
      models/drug_stock.go
  29. 2 0
      models/good_models.go
  30. 40 0
      models/his_charge_models.go
  31. 51 1
      models/his_models.go
  32. 1 1
      models/patient_models.go
  33. 97 12
      models/schedule_models.go
  34. 62 0
      models/self_drug_models.go
  35. 64 23
      models/stock_models.go
  36. 1 0
      models/stock_query_models.go
  37. 13 4
      service/app_version.go
  38. 44 1
      service/dialysis_service.go
  39. 102 2
      service/doctor_schedule_service.go
  40. 99 36
      service/his_charge_service.go
  41. 4 4
      service/his_hospital_service.go
  42. 12 6
      service/his_service.go
  43. 38 15
      service/manage_service.go
  44. 325 72
      service/mobile_dialysis_service.go
  45. 1 1
      service/patient_schedule_template_service.go
  46. 65 551
      service/patient_service.go
  47. 16 16
      service/schedule_service.go
  48. 30 6
      service/self_drug_service.go
  49. 1 0
      service/stock_service.go
  50. 3 7
      service/user_service.go
  51. 7 0
      service/warhouse_service.go

+ 14 - 1
conf/app.conf View File

@@ -7,7 +7,7 @@ copyrequestbody = true
7 7
 sessionon = true
8 8
 #sessiongcmaxlifetime = 64800
9 9
 
10
-tokencookiemaxlifetime = 7200
10
+tokencookiemaxlifetime = 604800
11 11
 enablexsrf = false
12 12
 xsrfkey = 61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o
13 13
 xsrfexpire = 3600
@@ -220,6 +220,19 @@ writesgjpatientmysqlname = sgj_patient
220 220
 
221 221
 
222 222
 redishost = kuyi6666.redis.rds.aliyuncs.com
223
+readmysqlhost2 = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
224
+readmysqlport2 = 3306
225
+readmysqluser2 = root
226
+readmysqlpass2 = 1Q2W3e4r!@#$
227
+readmysqlname2 = sgj_xt
228
+
229
+
230
+
231
+
232
+
233
+#redishost = 120.77.235.13
234
+#redishost = 112.74.16.180
235
+redishost = localhost
223 236
 redisport = 6379
224 237
 redispasswrod = TZtBW098WId3i27clkpj3q8dnUaVFP
225 238
 redisdb = 7

+ 59 - 2
controllers/base_api_controller.go View File

@@ -2,7 +2,6 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
-	"XT_New/models"
6 5
 	"XT_New/service"
7 6
 	_ "fmt"
8 7
 	"strconv"
@@ -73,7 +72,36 @@ func (this *BaseAuthAPIController) Prepare() {
73 72
 		var userAdmin models.AdminUser
74 73
 		userAdmin.Id = 1448
75 74
 		userAdmin.Mobile = "13416402574"
76
-
75
+		//var userAdmin models.AdminUser
76
+		//userAdmin.Id = 1448
77
+		//userAdmin.Mobile = "13318599895"
78
+		//
79
+		//userAdmin.Id = 597
80
+		//userAdmin.Mobile = "19874122664"
81
+		//userAdmin.IsSuperAdmin = false
82
+		//userAdmin.Status = 1
83
+		//userAdmin.CreateTime = 1530786071
84
+		//userAdmin.ModifyTime = 1530786071
85
+		//var subscibe models.ServeSubscibe
86
+		//subscibe.ID = 1
87
+		//subscibe.OrgId = 3877
88
+		//subscibe.PeriodStart = 1538035409
89
+		//subscibe.PeriodEnd = 1569571409
90
+		//subscibe.State = 1
91
+		//subscibe.Status = 1
92
+		//subscibe.CreatedTime = 1538035409
93
+		//subscibe.UpdatedTime = 1538035409
94
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
95
+		//subscibes[4] = &subscibe
96
+		//var adminUserInfo service.AdminUserInfo
97
+		//adminUserInfo.CurrentOrgId = 3877
98
+		//adminUserInfo.CurrentAppId = 4
99
+		//adminUserInfo.AdminUser = &userAdmin
100
+		//adminUserInfo.Subscibes = subscibes
101
+		//this.SetSession("admin_user_info", &adminUserInfo)
102
+
103
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
104
+		this.StopRun()
77 105
 		userAdmin.Id = 597
78 106
 		userAdmin.Mobile = "13416402574"
79 107
 		userAdmin.IsSuperAdmin = false
@@ -345,6 +373,35 @@ func (this *BaseServeAPIController) Prepare() {
345 373
 		this.SetSession("admin_user_info", &adminUserInfo)
346 374
 		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
347 375
 		//this.StopRun()
376
+		//var userAdmin models.AdminUser
377
+		//userAdmin.Id = 1448
378
+		//userAdmin.Mobile = "13318599895"
379
+		//
380
+		//userAdmin.Id = 597
381
+		//userAdmin.Mobile = "19874122664"
382
+		//userAdmin.IsSuperAdmin = false
383
+		//userAdmin.Status = 1
384
+		//userAdmin.CreateTime = 1530786071
385
+		//userAdmin.ModifyTime = 1530786071
386
+		//var subscibe models.ServeSubscibe
387
+		//subscibe.ID = 1
388
+		//subscibe.OrgId = 3877
389
+		//subscibe.PeriodStart = 1538035409
390
+		//subscibe.PeriodEnd = 1569571409
391
+		//subscibe.State = 1
392
+		//subscibe.Status = 1
393
+		//subscibe.CreatedTime = 1538035409
394
+		//subscibe.UpdatedTime = 1538035409
395
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
396
+		//subscibes[4] = &subscibe
397
+		//var adminUserInfo service.AdminUserInfo
398
+		//adminUserInfo.CurrentOrgId = 3877
399
+		//adminUserInfo.CurrentAppId = 4
400
+		//adminUserInfo.AdminUser = &userAdmin
401
+		//adminUserInfo.Subscibes = subscibes
402
+		//this.SetSession("admin_user_info", &adminUserInfo)
403
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
404
+		this.StopRun()
348 405
 	}
349 406
 
350 407
 	//if adminUserInfo.AppRole != nil {

+ 5 - 1
controllers/dialysis_api_controller.go View File

@@ -1376,6 +1376,8 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
1376 1376
 	remark := c.GetString("remark")
1377 1377
 	puncture_method := c.GetString("puncture_method")
1378 1378
 
1379
+	dialysis_count := c.GetString("dialysis_count")
1380
+	//dialysis_count, _ := c.GetInt64("dialysis_count", 0)
1379 1381
 	dialysis_count := c.GetString("dialysis_count")
1380 1382
 	emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
1381 1383
 	emergency_treatment_other := c.GetString("emergency_treatment_other")
@@ -1393,13 +1395,15 @@ func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
1393 1395
 
1394 1396
 	is_infect, _ := c.GetInt64("is_infect", 0)
1395 1397
 	exposed, _ := c.GetFloat("exposed", 0)
1396
-	//skin, _ := c.GetInt64("skin", 0)
1397 1398
 	skin := c.GetString("skin")
1398 1399
 	skin_other := c.GetString("skin_other")
1399 1400
 	infect_other := c.GetString("infect_other")
1400 1401
 	ductus_arantii_other := c.GetString("ductus_arantii_other")
1401 1402
 	machine_type := c.GetString("machine_type")
1402 1403
 	puncture_needle := c.GetString("puncture_needle")
1404
+	//humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
1405
+
1406
+	humor_excessive_symptom := c.GetString("humor_excessive_symptom")
1403 1407
 	humor_excessive_symptom := c.GetString("humor_excessive_symptom")
1404 1408
 	phinholing := c.GetString("pinholing")
1405 1409
 

+ 22 - 1
controllers/doctors_api_controller.go View File

@@ -62,6 +62,7 @@ func (c *DoctorsApiController) ScheduleAdvices() {
62 62
 	delivery_way := c.GetString("delivery_way")
63 63
 	schedule_type, _ := c.GetInt64("schedule_type")
64 64
 	partition_type, _ := c.GetInt64("partition_type")
65
+	patient_id, _ := c.GetInt64("patient_id")
65 66
 	if adviceType != 1 && adviceType != 3 && adviceType != 2 {
66 67
 		adviceType = 0
67 68
 	}
@@ -80,11 +81,17 @@ func (c *DoctorsApiController) ScheduleAdvices() {
80 81
 	adminUserInfo := c.GetAdminUserInfo()
81 82
 	orgID := adminUserInfo.CurrentOrgId
82 83
 
84
+	scheduals, err := service.MobileGetScheduleDoctorAdvicesOne(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id, delivery_way, schedule_type, partition_type, patient_id)
85
+	hisAdvices, _ := service.GetHisDoctorAdvicesOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id)
86
+
87
+	project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id)
83 88
 	scheduals, err := service.MobileGetScheduleDoctorAdvicesOne(orgID, date.Unix(), adviceType, patientType, adminUserInfo.AdminUser.Id, delivery_way, schedule_type, partition_type)
84 89
 
85 90
 	hisAdvices, _ := service.GetHisDoctorAdvicesOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type)
86 91
 
87
-	project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type)
92
+	for _, item := range project {
93
+		index := 0
94
+		for _, subItem := range item.HisPrescriptionTeamProject {
88 95
 
89 96
 	//获取所有的患者
90 97
 	patients, _ := service.GetAllPatientListByListTwo(orgID)
@@ -127,6 +134,20 @@ func (c *DoctorsApiController) ScheduleAdvices() {
127 134
 				break
128 135
 			}
129 136
 		}
137
+	}
138
+			if subItem.HisProject.CostClassify != 3 {
139
+				subItem.IsCheckTeam = 2
140
+				item.HisPrescriptionProject = append(item.HisPrescriptionProject, subItem)
141
+			}
142
+
143
+			if subItem.HisProject.CostClassify == 3 {
144
+				subItem.IsCheckTeam = 1
145
+				index = index + 1
146
+				if index == 1 {
147
+					item.HisPrescriptionProject = append(item.HisPrescriptionProject, subItem)
148
+				}
149
+			}
150
+		}
130 151
 	}
131 152
 	config, _ := service.GetHisDoctorConfig(orgID)
132 153
 	project_config, _ := service.GetHisProjectConfig(orgID)

+ 329 - 139
controllers/drug_stock_api_contorller.go View File

@@ -8,6 +8,7 @@ import (
8 8
 	"encoding/json"
9 9
 	"fmt"
10 10
 	"github.com/astaxie/beego"
11
+	"github.com/jinzhu/gorm"
11 12
 	"reflect"
12 13
 	"strconv"
13 14
 	"strings"
@@ -567,6 +568,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
567 568
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
568 569
 
569 570
 				} else {
571
+
570 572
 					warehouseInfo := &models.DrugWarehouseInfo{
571 573
 						ID:               id,
572 574
 						WarehousingOrder: warehouse.WarehousingOrder,
@@ -626,10 +628,38 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
626 628
 
627 629
 		errs = service.CreateDrugWarehousingInfo(warehousingInfo)
628 630
 		if errs == nil {
629
-			service.CreateDrugFlow(drugFlow)
630 631
 			//更改库存
631 632
 			service.UpdateDrugInfo(warehousingInfo)
633
+			for _, it := range warehousingInfo {
634
+				info, _ := service.GetLastDrugWarehouseInfSix(it.DrugId)
635
+				flows := models.DrugFlow{
636
+					WarehousingOrder: info.WarehousingOrder,
637
+					WarehousingId:    info.WarehousingId,
638
+					DrugId:           info.DrugId,
639
+					Number:           info.Number,
640
+					ProductDate:      info.ProductDate,
641
+					ExpireDate:       info.ExpiryDate,
642
+					Count:            info.WarehousingCount,
643
+					Price:            info.Price,
644
+					Status:           1,
645
+					Ctime:            ctime,
646
+					UserOrgId:        adminUserInfo.CurrentOrgId,
647
+					Manufacturer:     info.Manufacturer,
648
+					Dealer:           info.Dealer,
649
+					BatchNumber:      info.BatchNumber,
650
+					MaxUnit:          info.MaxUnit,
651
+					MinUnit:          "",
652
+					ConsumableType:   1,
653
+					IsEdit:           1,
654
+					Creator:          adminUserInfo.AdminUser.Id,
655
+					IsSys:            0,
656
+				}
657
+				_, existerrcodes := service.GetDrugFlowIsExist(info.ID, info.DrugId)
632 658
 
659
+				if existerrcodes == gorm.ErrRecordNotFound {
660
+					service.CreateDrugFlowOne(flows)
661
+				}
662
+			}
633 663
 		}
634 664
 
635 665
 	}
@@ -638,53 +668,107 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
638 668
 		var total int64
639 669
 		var minNumber float64
640 670
 		var allTotal int64
671
+		var chaTotal int64
641 672
 		for _, item := range upDateWarehousingInfo {
642 673
 			//查询修改的记录
643 674
 			orderInfo, _ := service.GetDrugWarehouseOrderOne(id, item.DrugId)
644 675
 
676
+			fmt.Println("hh23323232323232332233232", orderInfo)
677
+
645 678
 			info, _ := service.FindeDrugInfo(item.DrugId)
646 679
 
680
+			//历史入库总数
647 681
 			total = orderInfo.StockMaxNumber * info.MinNumber
648 682
 
649
-			allTotal = item.WarehousingCount*info.MinNumber - total
683
+			//当前入库总数
684
+			allTotal = item.WarehousingCount * info.MinNumber
650 685
 
651
-			str := strconv.FormatInt(allTotal, 10)
652
-			minFloat, _ := strconv.ParseFloat(str, 64)
686
+			//如果历史的入库总数 大于当前入库总数 则需要扣减
687
+			if total > allTotal {
688
+				chaTotal = total - allTotal
689
+				str := strconv.FormatInt(chaTotal, 10)
690
+				minFloat, _ := strconv.ParseFloat(str, 64)
653 691
 
654
-			minNumber = info.Total + minFloat
692
+				minNumber = info.Total - minFloat
655 693
 
656
-			lib := models.BaseDrugLib{
657
-				Total: minNumber,
694
+				lib := models.BaseDrugLib{
695
+					Total: minNumber,
696
+				}
697
+				service.UpdateBaseDrug(&lib, item.DrugId)
658 698
 			}
659
-			service.UpdateBaseDrug(&lib, item.DrugId)
699
+			//如果历史的入库总数 小于当前入库总数 则需增加库存
700
+			if total < allTotal {
701
+				chaTotal = allTotal - total
702
+				str := strconv.FormatInt(chaTotal, 10)
703
+				minFloat, _ := strconv.ParseFloat(str, 64)
704
+
705
+				minNumber = info.Total + minFloat
706
+
707
+				lib := models.BaseDrugLib{
708
+					Total: minNumber,
709
+				}
710
+				service.UpdateBaseDrug(&lib, item.DrugId)
711
+			}
712
+
660 713
 			warehouseInfo, _ := service.FindeLastWarehouseInfo(item.ID)
661 714
 			fmt.Println("hhhhh23hh32h232332323223", warehouseInfo)
662 715
 			var total int64
716
+
663 717
 			//比较大小(加)
718
+			// 如果当前的入库数量 大于 历史入库数量
664 719
 			if item.WarehousingCount > warehouseInfo.WarehousingCount {
665 720
 				total = item.WarehousingCount - warehouseInfo.WarehousingCount
721
+				item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
722
+
723
+				errs = service.UpDateDrugWarehousingInfo(item)
724
+				if len(drugFlow) > 0 {
725
+					for _, it := range drugFlow {
726
+						fmt.Println(it)
727
+						flow := models.DrugFlow{
728
+							Count: item.StockMaxNumber,
729
+						}
730
+						parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, warehouseInfo.WarehousingId)
731
+						fmt.Println(parseDateErr)
732
+
733
+					}
734
+				}
735
+				break
666 736
 			}
667
-			item.StockMaxNumber = warehouseInfo.StockMaxNumber + total
737
+
738
+			// 如果当前的入库数量 小于 历史入库数量
668 739
 			if item.WarehousingCount < warehouseInfo.WarehousingCount {
669 740
 				total = warehouseInfo.WarehousingCount - item.WarehousingCount
741
+				item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
742
+
743
+				errs = service.UpDateDrugWarehousingInfo(item)
744
+				if len(drugFlow) > 0 {
745
+					for _, it := range drugFlow {
746
+						fmt.Println(it)
747
+						flow := models.DrugFlow{
748
+							Count: item.StockMaxNumber,
749
+						}
750
+						parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, warehouseInfo.WarehousingId)
751
+						fmt.Println(parseDateErr)
752
+					}
753
+				}
754
+				break
670 755
 			}
671
-			item.StockMaxNumber = warehouseInfo.StockMaxNumber - total
672
-			if item.WarehousingCount == warehouseInfo.StockMaxNumber {
673
-
674
-				item.StockMaxNumber = item.WarehousingCount
675
-			}
676
-			errs = service.UpDateDrugWarehousingInfo(item)
677
-
678
-		}
679
-	}
680 756
 
681
-	if len(drugFlow) > 0 {
682
-		for _, item := range drugFlow {
683
-			flow := models.DrugFlow{
684
-				Count: item.Count,
757
+			if item.WarehousingCount == warehouseInfo.WarehousingCount {
758
+				item.OrgId = item.OrgId
759
+				warehouseinfo := &models.DrugWarehouseInfo{
760
+					Number:       item.Number,
761
+					ProductDate:  item.ProductDate,
762
+					ExpiryDate:   item.ExpiryDate,
763
+					Price:        item.Price,
764
+					TotalPrice:   item.TotalPrice,
765
+					Dealer:       item.Dealer,
766
+					Manufacturer: item.Manufacturer,
767
+					Remark:       item.Remark,
768
+					BatchNumber:  item.BatchNumber,
769
+				}
770
+				errs = service.UpDateDrugWarehousingInfoTwo(item.ID, warehouseinfo)
685 771
 			}
686
-			parseDateErr := service.UpdateDrugFlow(flow, item.DrugId, item.WarehousingId)
687
-			fmt.Println(parseDateErr)
688 772
 		}
689 773
 	}
690 774
 
@@ -1153,7 +1237,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1153 1237
 
1154 1238
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1155 1239
 
1156
-	var drugFlow []*models.DrugFlow
1240
+	//var drugFlow []*models.DrugFlow
1157 1241
 
1158 1242
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1159 1243
 		thisStockIn, _ := dataBody["stockOut"].([]interface{})
@@ -1226,7 +1310,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1226 1310
 					}
1227 1311
 
1228 1312
 				}
1229
-				fmt.Println("孟子", warehouseOut.ID)
1313
+
1230 1314
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1231 1315
 
1232 1316
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1253,52 +1337,46 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1253 1337
 					WarehouseInfoId:         warehouse_info_id,
1254 1338
 				}
1255 1339
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1256
-				fmt.Println("hhhhhhhhhhhhhhhh", warehouseOut.ID)
1257 1340
 
1258
-				drugflow := &models.DrugFlow{
1259
-					WarehouseOutId:          warehouseOut.ID,
1260
-					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1261
-					DrugId:                  drug_id,
1262
-					Number:                  number,
1263
-					ProductDate:             productDates,
1264
-					ExpireDate:              expiryDates,
1265
-					Count:                   count,
1266
-					Price:                   price,
1267
-					Status:                  1,
1268
-					Ctime:                   ctime,
1269
-					UserOrgId:               adminUserInfo.CurrentOrgId,
1270
-					Manufacturer:            manufacturer,
1271
-					Dealer:                  dealer,
1272
-					BatchNumber:             batch_number,
1273
-					MaxUnit:                 max_unit,
1274
-					ConsumableType:          2,
1275
-					IsEdit:                  1,
1276
-					Creator:                 adminUserInfo.AdminUser.Id,
1277
-					IsSys:                   0,
1278
-				}
1279
-				drugFlow = append(drugFlow, drugflow)
1341
+				//drugflow := &models.DrugFlow{
1342
+				//	WarehouseOutId:          warehouseOut.ID,
1343
+				//	WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1344
+				//	DrugId:                  drug_id,
1345
+				//	Number:                  number,
1346
+				//	ProductDate:             productDates,
1347
+				//	ExpireDate:              expiryDates,
1348
+				//	Count:                   count,
1349
+				//	Price:                   price,
1350
+				//	Status:                  1,
1351
+				//	Ctime:                   ctime,
1352
+				//	UserOrgId:               adminUserInfo.CurrentOrgId,
1353
+				//	Manufacturer:            manufacturer,
1354
+				//	Dealer:                  dealer,
1355
+				//	BatchNumber:             batch_number,
1356
+				//	MaxUnit:                 max_unit,
1357
+				//	ConsumableType:          2,
1358
+				//	IsEdit:                  1,
1359
+				//	Creator:                 adminUserInfo.AdminUser.Id,
1360
+				//	IsSys:                   0,
1361
+				//}
1362
+				//drugFlow = append(drugFlow, drugflow)
1280 1363
 			}
1281 1364
 		}
1282 1365
 	}
1283
-	var total_count int64
1284
-	var prescribing_number_total int64
1366
+
1367
+	var total_count int64              //总库存
1368
+	var prescribing_number_total int64 //出库数据
1285 1369
 	//调用出库逻辑
1286 1370
 	for _, item := range warehousingOutInfo {
1287 1371
 		//获取药品库存
1288
-		info, _ := service.GetDrugTotalCountOne(item.DrugId, item.OrgId, item.WarehouseInfoId)
1372
+		info, _ := service.GetDrugTotalCountTwo(item.DrugId)
1373
+
1374
+		for _, it := range info {
1375
+			total_count += it.StockMaxNumber*it.MinNumber + it.StockMinNumber
1376
+		}
1289 1377
 		//查询改药品信息
1290 1378
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1291
-		total_count = info.StockMaxNumber*medical.MinNumber + info.StockMinNumber
1292
-		//for _, it := range info{
1293
-		//  if medical.MaxUnit == it.MaxUnit{
1294
-		//    it.Count = it.StockMaxNumber * medical.MinNumber
1295
-		//  }
1296
-		//  if medical.MinUnit == it.MinUnit{
1297
-		//    it.Count = it.StockMinNumber
1298
-		//  }
1299
-		//  total_count += it.Count
1300
-		//}
1301
-		fmt.Println("总库存23232323232232332232332223", total_count)
1379
+
1302 1380
 		//判断单位是否相等
1303 1381
 		if medical.MaxUnit == item.CountUnit {
1304 1382
 			//转化为最小单位
@@ -1308,8 +1386,10 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1308 1386
 			prescribing_number_total = item.Count
1309 1387
 		}
1310 1388
 
1389
+		fmt.Println("药品ID", item.DrugId)
1311 1390
 		fmt.Println("数量一", prescribing_number_total)
1312 1391
 		fmt.Println("数量二", total_count)
1392
+
1313 1393
 		//判断单位
1314 1394
 		if total_count == 0 {
1315 1395
 			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
@@ -1339,11 +1419,11 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1339 1419
 			return
1340 1420
 		} else {
1341 1421
 			service.AddSigleDrugWarehouseOut(&warehouseOut)
1342
-			list, _ := service.GetLastWarehouseOut(adminUserInfo.CurrentOrgId)
1343
-			for _, item := range drugFlow {
1344
-				item.WarehouseOutId = list.ID
1345
-			}
1346
-			service.CreateDrugFlow(drugFlow)
1422
+			//list, _ := service.GetLastWarehouseOut(adminUserInfo.CurrentOrgId)
1423
+			//for _, item := range drugFlow {
1424
+			//	item.WarehouseOutId = list.ID
1425
+			//}
1426
+			//service.CreateDrugFlow(drugFlow)
1347 1427
 			// 出库流程
1348 1428
 			// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1349 1429
 			drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1351,6 +1431,8 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1351 1431
 				prescribingNumber := item.Count
1352 1432
 				service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1353 1433
 			}
1434
+			prescribing_number_total = 0
1435
+			total_count = 0
1354 1436
 		}
1355 1437
 
1356 1438
 	}
@@ -1364,7 +1446,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1364 1446
 		"min_unit":   "",
1365 1447
 		"max_unit":   "",
1366 1448
 	})
1367
-
1449
+	return
1368 1450
 }
1369 1451
 func (c *StockDrugApiController) GetDrugWarehouseOutList() {
1370 1452
 	page, _ := c.GetInt64("page", -1)
@@ -1503,9 +1585,10 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1503 1585
 	warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
1504 1586
 
1505 1587
 	tempWarehouseOut := models.DrugWarehouseOut{
1506
-		ID:               warehouseOut.ID,
1507
-		Mtime:            mtime,
1508
-		WarehouseOutTime: warehouseOutDate.Unix(),
1588
+		ID:                      warehouseOut.ID,
1589
+		Mtime:                   mtime,
1590
+		WarehouseOutTime:        warehouseOutDate.Unix(),
1591
+		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1509 1592
 	}
1510 1593
 
1511 1594
 	service.EditDrugWarehouseOut(tempWarehouseOut)
@@ -1787,8 +1870,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1787 1870
 				})
1788 1871
 				return
1789 1872
 			} else {
1790
-				errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1791
-				service.CreateDrugFlow(drugFlow)
1873
+				//errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1874
+				//service.CreateDrugFlow(drugFlow)
1792 1875
 				// 出库流程
1793 1876
 				// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1794 1877
 				drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
@@ -1836,14 +1919,12 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1836 1919
 			}
1837 1920
 
1838 1921
 			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1839
-			fmt.Println("总库存223232", all_number)
1840
-			fmt.Println("当前库存00000000000000000000000000000000000000000", max_number)
1922
+
1841 1923
 			////比较当前出库数量 和 最后一次出库数量,正常出库
1842 1924
 			if max_number <= min_number {
1843 1925
 				errs = service.UpDateDrugWarehouseOutInfo(item)
1844 1926
 				cha_number = min_number - max_number
1845
-				fmt.Println("差库存", cha_number)
1846
-				fmt.Println("最后一次库存0000000000000000000000000000000000000000", min_number)
1927
+
1847 1928
 				if item.CountUnit == medical.MaxUnit {
1848 1929
 					maxNumber = cha_number / medical.MinNumber
1849 1930
 					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
@@ -1900,23 +1981,20 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1900 1981
 				}
1901 1982
 
1902 1983
 			}
1903
-
1904
-			fmt.Println("当前出库", max_number)
1905
-			fmt.Println("最后一次232233", min_number)
1906 1984
 			//退库操作
1907 1985
 			if max_number > min_number {
1908 1986
 
1909 1987
 				cha_number = min_number - max_number
1910 1988
 				//如果总库存大于差,正常出库
1911
-				if all_number >= cha_number {
1989
+				if all_number > cha_number {
1912 1990
 
1913 1991
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1914
-					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1992
+
1915 1993
 					if item.CountUnit == medical.MaxUnit {
1916 1994
 						maxNumber = cha_number / medical.MinNumber
1917
-						fmt.Println("maxNumber232323232323232232", maxNumber)
1995
+
1918 1996
 						parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1919
-						fmt.Println("parseDateErr9999999999999999999999", parseDateErr)
1997
+						fmt.Println("parseDateErr", parseDateErr)
1920 1998
 						if parseDateErr != nil {
1921 1999
 							utils.ErrorLog(errs.Error())
1922 2000
 							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
@@ -1969,7 +2047,36 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1969 2047
 						})
1970 2048
 					}
1971 2049
 				}
2050
+				if all_number == cha_number {
2051
+					warehouseInfo := models.XtDrugWarehouseInfo{
2052
+						Number:       item.Number,
2053
+						ProductDate:  item.ProductDate,
2054
+						ExpiryDate:   item.ExpiryDate,
2055
+						Price:        item.Price,
2056
+						TotalPrice:   item.TotalPrice,
2057
+						Dealer:       item.Dealer,
2058
+						Manufacturer: item.Manufacturer,
2059
+						Remark:       item.Remark,
2060
+						BatchNumber:  item.BatchNumber,
2061
+						MaxUnit:      item.CountUnit,
2062
+					}
2063
+					parseDateErr := service.UpdateDrugWarehouseingInfoSix(item.ID, warehouseInfo)
2064
+					if parseDateErr != nil {
2065
+						utils.ErrorLog(errs.Error())
2066
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
2067
+						return
2068
+					}
1972 2069
 
2070
+					c.ServeSuccessJSON(map[string]interface{}{
2071
+						"msg":        "2",
2072
+						"drug_name":  "",
2073
+						"dose":       "",
2074
+						"dose_unit":  "",
2075
+						"min_number": "",
2076
+						"min_unit":   "",
2077
+						"max_unit":   "",
2078
+					})
2079
+				}
1973 2080
 				if all_number < cha_number {
1974 2081
 					goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1975 2082
 					c.ServeSuccessJSON(map[string]interface{}{
@@ -2018,8 +2125,6 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2018 2125
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2019 2126
 		return
2020 2127
 	}
2021
-	fmt.Println("cancelStockDate232323223233223", cancelStockDate.Unix())
2022
-
2023 2128
 	adminUserInfo := c.GetAdminUserInfo()
2024 2129
 	operation_time := time.Now().Unix()
2025 2130
 	creater := adminUserInfo.AdminUser.Id
@@ -2044,7 +2149,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2044 2149
 		Type:         types,
2045 2150
 	}
2046 2151
 	service.AddSigleDrugCancelStock(&cancelStock)
2047
-	fmt.Println("hh232323232323232323232323232322332", parseDateErr)
2152
+
2048 2153
 	dataBody := make(map[string]interface{}, 0)
2049 2154
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
2050 2155
 	if err != nil {
@@ -2151,10 +2256,10 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2151 2256
 						dealer_id = item.ID
2152 2257
 					}
2153 2258
 				}
2154
-				fmt.Println("99999999999999999999", batch_number_id)
2259
+				cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
2155 2260
 				cancelStockInfo := &models.DrugCancelStockInfo{
2156
-					OrderNumber:      cancelStock.OrderNumber,
2157
-					CancelStockId:    cancelStock.ID,
2261
+					OrderNumber:      cancelInfo.OrderNumber,
2262
+					CancelStockId:    cancelInfo.ID,
2158 2263
 					DrugId:           drug_id,
2159 2264
 					Count:            count,
2160 2265
 					Status:           1,
@@ -2216,6 +2321,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2216 2321
 	}
2217 2322
 	//扣减库存逻辑
2218 2323
 	for _, item := range cancelStockInfos {
2324
+
2219 2325
 		var total_number int64
2220 2326
 		var out_number int64
2221 2327
 		var can_number int64
@@ -2227,78 +2333,117 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2227 2333
 		if item.MaxUnit == medical.MinUnit {
2228 2334
 			total_number = item.Count
2229 2335
 		}
2230
-		fmt.Println("当前库存", total_number)
2231 2336
 		//查询当前药品退库的批次号的总入库数
2232 2337
 		infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2233
-		fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit, infoWareInfo.StockMaxNumber, infoWareInfo.StockMinNumber)
2234 2338
 		var total_count int64
2235
-		total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2339
+		total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2236 2340
 		fmt.Println("当前批次总库存", total_count)
2237 2341
 
2238 2342
 		//查询该批次的出库数量
2239 2343
 		outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2240
-		//查询该批次总的退库数量
2241 2344
 
2345
+		//查询该批次总的退库数量
2242 2346
 		canInfo, _ := service.GetCancelDrugStockOutInfo(item.BatchNumberId, item.DrugId)
2243
-		for _, item := range canInfo {
2244
-			if item.MaxUnit == medical.MaxUnit {
2245
-				item.Count = item.Count * medical.MinNumber
2347
+
2348
+		for _, it := range canInfo {
2349
+			if it.MaxUnit == medical.MaxUnit {
2350
+				it.Count = it.Count * medical.MinNumber
2246 2351
 			}
2247
-			if item.MaxUnit == medical.MinUnit {
2248
-				item.Count = item.Count
2352
+			if it.MaxUnit == medical.MinUnit {
2353
+				it.Count = it.Count
2249 2354
 			}
2250 2355
 		}
2251
-		for _, item := range canInfo {
2252
-			can_number += item.Count
2356
+
2357
+		for _, it := range canInfo {
2358
+			can_number += it.Count
2253 2359
 		}
2254 2360
 
2255
-		for _, item := range outInfo {
2256
-			if item.CountUnit == medical.MaxUnit {
2257
-				item.Count = item.Count * medical.MinNumber
2361
+		for _, it := range outInfo {
2362
+			if it.CountUnit == medical.MaxUnit {
2363
+				it.Count = it.Count * medical.MinNumber
2258 2364
 			}
2259
-			if item.CountUnit == medical.MinUnit {
2260
-				item.Count = item.Count
2365
+			if it.CountUnit == medical.MinUnit {
2366
+				it.Count = it.Count
2261 2367
 			}
2262 2368
 		}
2263
-		for _, item := range outInfo {
2264
-			out_number += item.Count
2369
+		for _, it := range outInfo {
2370
+			out_number += it.Count
2265 2371
 		}
2266
-		fmt.Println("出库数量23232232323222332", out_number)
2372
+
2267 2373
 		if out_number == 0 {
2374
+			service.UpdateDrugCancel(item.CancelStockId)
2268 2375
 			c.ServeSuccessJSON(map[string]interface{}{
2269 2376
 				"msg": "2",
2270 2377
 			})
2271 2378
 			return
2272 2379
 		}
2380
+
2381
+		fmt.Println("时间任命323332233232", total_number, total_count)
2382
+
2273 2383
 		//判断退库数量是否大于总入库数量
2274
-		if total_number > out_number {
2384
+		if total_number > total_count {
2275 2385
 			service.UpdateDrugCancel(item.CancelStockId)
2276 2386
 			c.ServeSuccessJSON(map[string]interface{}{
2277
-				"msg": "4",
2387
+				"msg": "2",
2278 2388
 			})
2279 2389
 			return
2280 2390
 		}
2281 2391
 
2282 2392
 		//判断总退库数量是否大于出库数量
2283
-		fmt.Println("hhhhhhhhhhh", can_number+total_number)
2393
+		fmt.Println("该批次总退库数量", can_number+total_number)
2394
+		fmt.Println("总出库数量", out_number)
2395
+		fmt.Println("当前退库数量", total_number)
2284 2396
 		if can_number+total_number > out_number {
2397
+			//清空退库单
2285 2398
 			service.UpdateDrugCancel(item.CancelStockId)
2286 2399
 			c.ServeSuccessJSON(map[string]interface{}{
2287 2400
 				"msg": "2",
2288 2401
 			})
2289 2402
 			return
2290 2403
 		}
2291
-
2404
+		fmt.Println("当前退库数量", total_number)
2405
+		fmt.Println("总出口数量", out_number)
2292 2406
 		//正常退库
2293 2407
 		if total_number <= out_number {
2294 2408
 			//创建退库详情
2295
-			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2409
+			errs := service.CreateCancelStockInfoTwo(item)
2296 2410
 			//创建库存明细
2297
-			errs = service.CreateDrugFlow(drugFlow)
2411
+			flows := models.DrugFlow{
2412
+				WarehousingId:           0,
2413
+				DrugId:                  item.DrugId,
2414
+				Number:                  "",
2415
+				BatchNumber:             item.BatchNumber,
2416
+				Count:                   item.Count,
2417
+				UserOrgId:               adminUserInfo.CurrentOrgId,
2418
+				PatientId:               0,
2419
+				SystemTime:              ctime,
2420
+				ConsumableType:          4,
2421
+				IsSys:                   0,
2422
+				WarehousingOrder:        infoWareInfo.WarehousingOrder,
2423
+				WarehouseOutId:          0,
2424
+				WarehouseOutOrderNumber: "",
2425
+				IsEdit:                  0,
2426
+				CancelStockId:           cancelStock.ID,
2427
+				CancelOrderNumber:       cancelStock.OrderNumber,
2428
+				Manufacturer:            manufacturer_id,
2429
+				Dealer:                  dealer_id,
2430
+				Creator:                 adminUserInfo.AdminUser.Id,
2431
+				UpdateCreator:           0,
2432
+				Status:                  1,
2433
+				Ctime:                   time.Now().Unix(),
2434
+				Mtime:                   0,
2435
+				Price:                   item.Price,
2436
+				WarehousingDetailId:     0,
2437
+				WarehouseOutDetailId:    0,
2438
+				CancelOutDetailId:       0,
2439
+				ExpireDate:              item.ExpiryDate,
2440
+				ProductDate:             item.ProductDate,
2441
+				MaxUnit:                 item.MaxUnit,
2442
+				MinUnit:                 "",
2443
+			}
2444
+			errs = service.CreateDrugFlowOne(flows)
2298 2445
 
2299 2446
 			var total int64
2300
-			////退库到当前批次,获取当前退库批次的库存
2301
-			//info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2302 2447
 
2303 2448
 			if medical.MaxUnit == item.MaxUnit {
2304 2449
 				total = item.Count
@@ -2318,7 +2463,6 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2318 2463
 				})
2319 2464
 			}
2320 2465
 			if medical.MinUnit == item.MaxUnit {
2321
-				fmt.Println("hhhhhh2323323232322332232332999999999进来", item.Count)
2322 2466
 				total = item.Count
2323 2467
 				warehouseInfo := models.XtDrugWarehouseInfo{
2324 2468
 					StockMinNumber: total,
@@ -2335,16 +2479,8 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
2335 2479
 					"msg": "1",
2336 2480
 				})
2337 2481
 			}
2338
-			if errs != nil {
2339
-				utils.ErrorLog(errs.Error())
2340
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2341
-				return
2342
-			}
2343
-
2344
-			c.ServeSuccessJSON(map[string]interface{}{
2345
-				"msg": "1",
2346
-			})
2347 2482
 		}
2483
+
2348 2484
 	}
2349 2485
 }
2350 2486
 func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
@@ -2664,8 +2800,6 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2664 2800
 			}
2665 2801
 		}
2666 2802
 	}
2667
-	fmt.Println("cancelStockInfos232323223323223322323223", cancelStockInfos)
2668
-	fmt.Println("cancelStockInfos232323223323223322323223", upDateCancelStockInfos)
2669 2803
 
2670 2804
 	var errs error
2671 2805
 	if len(cancelStockInfos) > 0 {
@@ -2741,7 +2875,13 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2741 2875
 				//创建退库详情
2742 2876
 				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2743 2877
 				//创建库存明细
2744
-				errs = service.CreateDrugFlow(drugFlow)
2878
+				//查询这个药品这个订单是否已存在流水
2879
+				for _, items := range drugFlow {
2880
+					_, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
2881
+					if errsId == gorm.ErrRecordNotFound {
2882
+						errs = service.CreateDrugFlowTwo(items)
2883
+					}
2884
+				}
2745 2885
 
2746 2886
 				//获取该批次最后一条退库详情
2747 2887
 				lastCancel, _ := service.GetLastCancelStockInfo(id)
@@ -2753,7 +2893,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2753 2893
 				if lastCancel.MaxUnit == medical.MinUnit {
2754 2894
 					cancel_number = lastCancel.Count
2755 2895
 				}
2756
-				fmt.Println("999999232323232232232323232323", lastCancel)
2896
+				fmt.Println("999999232323232232232323232323", item.Count, cancel_number)
2757 2897
 				var total int64
2758 2898
 
2759 2899
 				if medical.MaxUnit == item.MaxUnit {
@@ -2803,21 +2943,31 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2803 2943
 		}
2804 2944
 	}
2805 2945
 	if len(drugFlow) > 0 {
2806
-		parseDateErr := service.CreateDrugFlow(drugFlow)
2807
-		fmt.Println(parseDateErr)
2946
+		for _, items := range drugFlow {
2947
+			_, errsId := service.GetCancelStockId(items.CancelStockId, items.DrugId)
2948
+			if errsId == gorm.ErrRecordNotFound {
2949
+				errs = service.CreateDrugFlowTwo(items)
2950
+			}
2951
+		}
2808 2952
 	}
2809 2953
 
2810 2954
 	if len(upDateCancelStockInfos) > 0 {
2811 2955
 		var total int64
2812 2956
 		var out_count int64
2957
+		var cancel_count int64
2958
+		var now_count int64
2959
+		var all_count int64
2813 2960
 		for _, item := range upDateCancelStockInfos {
2961
+			//查询最后一条退库记录
2962
+			info, _ := service.GetLastCancelStockInfoOne(id, item.DrugId)
2814 2963
 			errs = service.UpDateDrugCancelStockInfo(item)
2815
-			//查询该批次最后一条退库记录
2816
-			info, _ := service.GetLastCancelStockInfo(id)
2964
+			fmt.Println("hh23232oooooooo2o3o2o32o23oo23o23o23", info)
2817 2965
 			//查询该药品的信息
2818 2966
 			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2819 2967
 			//统计该批次的总出库数
2820 2968
 			outInfo, _ := service.GetDrugWarehouseOutInfo(item.BatchNumberId, item.DrugId)
2969
+			//查询该批次的总退库数量
2970
+			cancelInfo, _ := service.GetTotalDrugCancelInfo(item.BatchNumberId, item.DrugId, item.ID)
2821 2971
 			for _, item := range outInfo {
2822 2972
 				if item.CountUnit == medical.MaxUnit {
2823 2973
 					item.Count = item.Count * medical.MinNumber
@@ -2831,21 +2981,61 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2831 2981
 				out_count += item.Count
2832 2982
 			}
2833 2983
 
2984
+			for _, item := range cancelInfo {
2985
+				if item.MaxUnit == medical.MaxUnit {
2986
+					item.Count = item.Count * medical.MinNumber
2987
+				}
2988
+				if item.MaxUnit == medical.MinUnit {
2989
+					item.Count = item.Count
2990
+				}
2991
+			}
2992
+
2993
+			for _, item := range cancelInfo {
2994
+				cancel_count += item.Count
2995
+			}
2996
+
2834 2997
 			fmt.Println("out_count232233332232323223", out_count)
2835 2998
 
2836 2999
 			if item.MaxUnit == medical.MaxUnit {
2837
-				item.Count = item.Count * medical.MinNumber
3000
+				now_count = item.Count * medical.MinNumber
3001
+			}
3002
+			if item.MaxUnit == medical.MinUnit {
3003
+				now_count = item.Count
3004
+			}
3005
+			fmt.Println("hhhhhh2323322323", now_count+cancel_count)
3006
+			//总退库批次
3007
+			all_count = now_count + cancel_count
3008
+
3009
+			//该批次的总出库数小与退库数报错返回
3010
+			if all_count > out_count {
3011
+				c.ServeSuccessJSON(map[string]interface{}{
3012
+					"msg": "4",
3013
+				})
3014
+				return
3015
+			}
3016
+
3017
+			if item.MaxUnit == medical.MaxUnit {
2838 3018
 				//更新库存
2839 3019
 				total = item.Count - info.Count
2840
-				fmt.Println("total232323232323232232323", total)
2841
-				service.UpdatedDrugInfo(item.BatchNumberId, total)
3020
+				parseDateErr := service.UpdatedDrugInfo(item.BatchNumberId, total)
3021
+				fmt.Println("parseDateErr", parseDateErr)
3022
+
3023
+				flow := models.DrugFlow{
3024
+					Count: item.Count,
3025
+				}
3026
+				service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
2842 3027
 				break
3028
+
2843 3029
 			}
2844 3030
 
2845 3031
 			if item.MaxUnit == medical.MinUnit {
2846 3032
 				item.Count = item.Count
2847 3033
 				total = item.Count - info.Count
2848 3034
 				service.UpdatedDrugInfoOne(item.BatchNumberId, total)
3035
+				flow := models.DrugFlow{
3036
+					Count: item.Count,
3037
+				}
3038
+				service.UpdatedDrugFlow(info.CancelStockId, item.DrugId, flow)
2849 3039
 				break
2850 3040
 			}
2851 3041
 		}

+ 77 - 1
controllers/gobal_config_api_controller.go View File

@@ -67,6 +67,12 @@ func GobalConfigRegistRouters() {
67 67
 	beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
68 68
 	beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
69 69
 
70
+	beego.Router("/api/hisstockpriceconfig/get", &GobalConfigApiController{}, "get:GetHisStockPriceConfig")
71
+	beego.Router("/api/hisstockpriceconfig/isopen", &GobalConfigApiController{}, "post:PostHisStockPriceConfig")
72
+
73
+	beego.Router("/api/xtconfig/get", &GobalConfigApiController{}, "get:GetXTHisConfig")
74
+	beego.Router("/api/xtconfig/isopen", &GobalConfigApiController{}, "post:PostXTHisConfig")
75
+
70 76
 	beego.Router("/api/xtconfigproject/isopen", &GobalConfigApiController{}, "post:PostXTHisProjectConfig")
71 77
 
72 78
 	beego.Router("/api/isopen/init", &GobalConfigApiController{}, "get:GetAllIsOpenConfig")
@@ -1040,6 +1046,10 @@ func (c *GobalConfigApiController) GetPrintInfo() {
1040 1046
 	dataBody := make(map[string]interface{}, 0)
1041 1047
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1042 1048
 	idsInters := dataBody["ids"].([]interface{})
1049
+	advice_type, _ := c.GetInt64("advice_type")
1050
+	stop_type, _ := c.GetInt64("stop_type")
1051
+	fmt.Println("advcie_type23323232322332", advice_type)
1052
+	fmt.Println("stop_type33332323223232323", stop_type)
1043 1053
 	if len(idsInters) == 0 {
1044 1054
 		if err != nil {
1045 1055
 			c.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除会员失败:(没有选择会员)")
@@ -1405,6 +1415,60 @@ func (c *GobalConfigApiController) PostXTHisConfig() {
1405 1415
 	return
1406 1416
 }
1407 1417
 
1418
+func (c *GobalConfigApiController) PostHisStockPriceConfig() {
1419
+	is_open, _ := c.GetBool("is_open", false)
1420
+	adminUserInfo := c.GetAdminUserInfo()
1421
+	org_id := adminUserInfo.CurrentOrgId
1422
+	isOpen := 0
1423
+
1424
+	if is_open {
1425
+		isOpen = 1
1426
+	} else {
1427
+		isOpen = 2
1428
+	}
1429
+
1430
+	config := models.HisStockPriceConfig{
1431
+		UserOrgId: org_id,
1432
+		IsOpen:    int64(isOpen),
1433
+		Status:    1,
1434
+		Ctime:     time.Now().Unix(),
1435
+		Mtime:     time.Now().Unix(),
1436
+	}
1437
+
1438
+	errs, configs := service.FindHisStockPriceRecordByOrgId(org_id)
1439
+
1440
+	if errs == gorm.ErrRecordNotFound {
1441
+		err := service.CreateHisStockPriceRecord(&config)
1442
+		if err != nil {
1443
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1444
+			return
1445
+		}
1446
+
1447
+	} else if errs == nil {
1448
+		modifyConfig := models.HisStockPriceConfig{
1449
+			ID:        configs.ID,
1450
+			UserOrgId: org_id,
1451
+			Status:    1,
1452
+			Ctime:     time.Now().Unix(),
1453
+			Mtime:     time.Now().Unix(),
1454
+			IsOpen:    int64(isOpen),
1455
+		}
1456
+
1457
+		err := service.UpdateHisStockPriceRecord(&modifyConfig)
1458
+		if err != nil {
1459
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1460
+			return
1461
+		}
1462
+
1463
+	}
1464
+
1465
+	c.ServeSuccessJSON(map[string]interface{}{
1466
+		"is_open": is_open,
1467
+	})
1468
+
1469
+	return
1470
+}
1471
+
1408 1472
 func (c *GobalConfigApiController) PostXTHisProjectConfig() {
1409 1473
 	is_open, _ := c.GetBool("is_open", false)
1410 1474
 	adminUserInfo := c.GetAdminUserInfo()
@@ -1474,6 +1538,15 @@ func (c *GobalConfigApiController) GetXTHisConfig() {
1474 1538
 	})
1475 1539
 }
1476 1540
 
1541
+func (c *GobalConfigApiController) GetHisStockPriceConfig() {
1542
+	adminUserInfo := c.GetAdminUserInfo()
1543
+	_, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
1544
+
1545
+	c.ServeSuccessJSON(map[string]interface{}{
1546
+		"config": config,
1547
+	})
1548
+}
1549
+
1477 1550
 func (c *GobalConfigApiController) GetAllIsOpenConfig() {
1478 1551
 	adminUserInfo := c.GetAdminUserInfo()
1479 1552
 	_, config := service.FindXTHisRecordByOrgId(adminUserInfo.CurrentOrgId)
@@ -1908,7 +1981,7 @@ func (c *GobalConfigApiController) GetDrugStockFllow() {
1908 1981
 	}
1909 1982
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1910 1983
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
1911
-
1984
+	medical, _ := service.GetBaseDrugMedical(drug_id)
1912 1985
 	//查询入库数据
1913 1986
 	if stock_type == 3 || stock_type == 0 {
1914 1987
 		list, total, err := service.GetDrugStockFlow(drug_id, startTime, endTime, page, limit, orgId)
@@ -1920,6 +1993,7 @@ func (c *GobalConfigApiController) GetDrugStockFllow() {
1920 1993
 			"list":             list,
1921 1994
 			"total":            total,
1922 1995
 			"manufacturerList": manufacturerList,
1996
+			"drug":             medical,
1923 1997
 		})
1924 1998
 	}
1925 1999
 
@@ -2196,11 +2270,13 @@ func (c *GobalConfigApiController) GetDrugFlow() {
2196 2270
 	list, total, _ := service.GetDrugFlow(drug_id, orgId, limit, page, startTime, endTime, stock_type)
2197 2271
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2198 2272
 	dealerList, _ := service.GetAllDealerList(orgId)
2273
+	medical, _ := service.GetBaseDrugMedical(drug_id)
2199 2274
 	c.ServeSuccessJSON(map[string]interface{}{
2200 2275
 		"list":             list,
2201 2276
 		"total":            total,
2202 2277
 		"manufacturerList": manufacturerList,
2203 2278
 		"dealerList":       dealerList,
2279
+		"drug":             medical,
2204 2280
 	})
2205 2281
 }
2206 2282
 

+ 26 - 7
controllers/his_api_controller.go View File

@@ -529,7 +529,7 @@ func (c *HisApiController) GetHisPatientInfo() {
529 529
 	//prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
530 530
 	//monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
531 531
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
532
-	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
532
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
533 533
 	lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
534 534
 
535 535
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
@@ -582,6 +582,24 @@ func (c *HisApiController) GetHisPrescriptionConfig() {
582 582
 		}
583 583
 	}
584 584
 
585
+
586
+	manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
587
+
588
+	_, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
589
+	if config.ID > 0 && config.IsOpen == 1 {
590
+		for _, item := range drugs {
591
+			var index = 0
592
+			for _, subItem := range item.OtherDrugWarehouseInfo {
593
+				if index == 0 {
594
+					if subItem.StockMaxNumber*item.MinNumber+subItem.StockMinNumber > 0 {
595
+						index = index + 1
596
+						item.MinPrice = subItem.Price
597
+					}
598
+				}
599
+			}
600
+		}
601
+	}
602
+
585 603
 	drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
586 604
 	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
587 605
 	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
@@ -606,6 +624,7 @@ func (c *HisApiController) GetHisPrescriptionConfig() {
606 624
 		"sick":             sick,
607 625
 		"additions":        additions,
608 626
 		"diagnose":         diagnose,
627
+		"manufacturers":    manufacturers,
609 628
 	})
610 629
 }
611 630
 func (c *HisApiController) CreateHisPrescription() {
@@ -1158,7 +1177,7 @@ func (c *HisApiController) EditHisPrescription() {
1158 1177
 
1159 1178
 	role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
1160 1179
 
1161
-	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type)
1180
+	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
1162 1181
 	var hpInfo models.HisPrescriptionInfo
1163 1182
 	if info.ID == 0 {
1164 1183
 		var randNum int
@@ -2602,8 +2621,8 @@ func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescri
2602 2621
 
2603 2622
 	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
2604 2623
 		total, _ := json["total"].(string)
2605
-		totals, _ := strconv.ParseInt(total, 10, 64)
2606
-		project.Count = totals
2624
+		//totals, _ := strconv.ParseInt(total, 10, 64)
2625
+		project.Count = total
2607 2626
 	}
2608 2627
 
2609 2628
 	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
@@ -3846,7 +3865,7 @@ func (c *HisApiController) GetHisChargePatientInfo() {
3846 3865
 	//}
3847 3866
 
3848 3867
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
3849
-	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
3868
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
3850 3869
 
3851 3870
 	lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
3852 3871
 
@@ -5440,7 +5459,7 @@ func (c *HisApiController) GetHisMonthChargePatientInfo() {
5440 5459
 	}
5441 5460
 
5442 5461
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
5443
-	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
5462
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
5444 5463
 
5445 5464
 	lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
5446 5465
 
@@ -5497,7 +5516,7 @@ func (c *HisApiController) GetHisMonthPatientInfo() {
5497 5516
 
5498 5517
 	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
5499 5518
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
5500
-	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
5519
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
5501 5520
 	lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
5502 5521
 
5503 5522
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)

+ 214 - 0
controllers/his_charge_api_controller.go View File

@@ -2,7 +2,9 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
+	"XT_New/models"
5 6
 	"XT_New/service"
7
+	"XT_New/utils"
6 8
 	"github.com/astaxie/beego"
7 9
 	"time"
8 10
 )
@@ -15,6 +17,171 @@ func HisChargeApiRegistRouters() {
15 17
 	beego.Router("/api/his/chargestatistics/detail", &HisChargeApiController{}, "get:GetChargeStatisticsDetail")
16 18
 	beego.Router("/api/his/chargestatistics/settle", &HisChargeApiController{}, "get:GetChargeStatisticsSettle")
17 19
 
20
+	beego.Router("/api/his/inspectionlist/get", &HisChargeApiController{}, "get:GetHisInspectionList")
21
+	beego.Router("/api/his/inspectioninfo/get", &HisChargeApiController{}, "get:GetHisInspectionInfo")
22
+
23
+	//发票
24
+	beego.Router("/api/fapiao/create", &HisChargeApiController{}, "post:CreateFaPiaoRecord")
25
+	beego.Router("/api/fapiao/modify", &HisChargeApiController{}, "post:ModifyFaPiaoRecord")
26
+	beego.Router("/api/fapiao/list", &HisChargeApiController{}, "get:GetFaPiaoRecordList")
27
+	beego.Router("/api/fapiao/delete", &HisChargeApiController{}, "post:DeleteFaPiaoRecord")
28
+	beego.Router("/api/fapiao", &HisChargeApiController{}, "get:GetFaPiaoRecord")
29
+	beego.Router("/api/fapiao/is_use", &HisChargeApiController{}, "post:UpdateFaPiaoRecordIsUse")
30
+
31
+}
32
+
33
+func (c *HisChargeApiController) UpdateFaPiaoRecordIsUse() {
34
+	id, _ := c.GetInt64("id", 0)
35
+	is_use, _ := c.GetInt64("is_use")
36
+	if id <= 0 {
37
+		utils.ErrorLog("id == 0")
38
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
39
+		return
40
+	}
41
+
42
+	record, _ := service.FindFapiaoById(id)
43
+	adminUserInfo := c.GetAdminUserInfo()
44
+	service.UpdateFapiaoIsUse(adminUserInfo.CurrentOrgId)
45
+	records := models.HisFapiaoRecord{
46
+		ID:           id,
47
+		FapiaoCode:   record.FapiaoCode,
48
+		FapiaoNumber: record.FapiaoNumber,
49
+		Ctime:        time.Now().Unix(),
50
+		Mtime:        time.Now().Unix(),
51
+		UserOrgId:    adminUserInfo.CurrentOrgId,
52
+		Status:       1,
53
+		IsUse:        is_use,
54
+	}
55
+	err := service.ModifyFapiao(&records)
56
+	if err == nil {
57
+		c.ServeSuccessJSON(map[string]interface{}{
58
+			"fapiao_record": records,
59
+		})
60
+	} else {
61
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
62
+	}
63
+}
64
+func (c *HisChargeApiController) CreateFaPiaoRecord() {
65
+	fapiao_code := c.GetString("fapiao_code")
66
+	fapiao_number := c.GetString("fapiao_number")
67
+	if len(fapiao_code) <= 0 {
68
+		utils.ErrorLog("len(fapiao_code) == 0")
69
+
70
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
71
+		return
72
+	}
73
+
74
+	if len(fapiao_number) <= 0 {
75
+		utils.ErrorLog("len(fapiao_number) == 0")
76
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
77
+		return
78
+	}
79
+
80
+	adminUserInfo := c.GetAdminUserInfo()
81
+
82
+	record := models.HisFapiaoRecord{
83
+		FapiaoCode:   fapiao_code,
84
+		FapiaoNumber: fapiao_number,
85
+		Ctime:        time.Now().Unix(),
86
+		Mtime:        time.Now().Unix(),
87
+		UserOrgId:    adminUserInfo.CurrentOrgId,
88
+		Status:       1,
89
+		IsUse:        0,
90
+	}
91
+
92
+	err, records := service.AddSigleFapiaoRecord(&record)
93
+	if err == nil {
94
+		c.ServeSuccessJSON(map[string]interface{}{
95
+			"fapiao_record": records,
96
+		})
97
+
98
+	} else {
99
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
100
+
101
+	}
102
+
103
+}
104
+func (c *HisChargeApiController) ModifyFaPiaoRecord() {
105
+	id, _ := c.GetInt64("id", 0)
106
+	fapiao_code := c.GetString("fapiao_code")
107
+	fapiao_number := c.GetString("fapiao_number")
108
+
109
+	if id <= 0 {
110
+		utils.ErrorLog("id == 0")
111
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
112
+		return
113
+	}
114
+
115
+	if len(fapiao_code) <= 0 {
116
+		utils.ErrorLog("len(fapiao_code) == 0")
117
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
118
+		return
119
+	}
120
+
121
+	if len(fapiao_number) <= 0 {
122
+		utils.ErrorLog("len(fapiao_number) == 0")
123
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
124
+		return
125
+	}
126
+
127
+	record, _ := service.FindFapiaoById(id)
128
+	adminUserInfo := c.GetAdminUserInfo()
129
+	records := models.HisFapiaoRecord{
130
+		ID:           id,
131
+		FapiaoCode:   fapiao_code,
132
+		FapiaoNumber: fapiao_number,
133
+		Ctime:        time.Now().Unix(),
134
+		Mtime:        time.Now().Unix(),
135
+		UserOrgId:    adminUserInfo.CurrentOrgId,
136
+		Status:       1,
137
+		IsUse:        record.IsUse,
138
+	}
139
+
140
+	err := service.ModifyFapiao(&records)
141
+
142
+	if err == nil {
143
+		c.ServeSuccessJSON(map[string]interface{}{
144
+			"fapiao_record": records,
145
+		})
146
+	} else {
147
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
148
+	}
149
+}
150
+func (c *HisChargeApiController) GetFaPiaoRecordList() {
151
+	page, _ := c.GetInt64("page", 1)
152
+	limit, _ := c.GetInt64("limit", 7)
153
+	adminUserInfo := c.GetAdminUserInfo()
154
+	fapiaoRecord, total, err := service.FindAllFapiaoList(adminUserInfo.CurrentOrgId, page, limit)
155
+	if err == nil {
156
+		c.ServeSuccessJSON(map[string]interface{}{
157
+			"fapiao_record": fapiaoRecord,
158
+			"total":         total,
159
+		})
160
+	} else {
161
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
162
+	}
163
+}
164
+func (c *HisChargeApiController) DeleteFaPiaoRecord() {
165
+	id, _ := c.GetInt64("id", 0)
166
+	err := service.DeleteFapiaoById(id)
167
+	if err == nil {
168
+		c.ServeSuccessJSON(map[string]interface{}{
169
+			"msg": "删除成功",
170
+		})
171
+	} else {
172
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
173
+	}
174
+}
175
+func (c *HisChargeApiController) GetFaPiaoRecord() {
176
+	id, _ := c.GetInt64("id", 0)
177
+	fapiaoRecord, err := service.FindFapiaoById(id)
178
+	if err == nil {
179
+		c.ServeSuccessJSON(map[string]interface{}{
180
+			"fapiao_record": fapiaoRecord,
181
+		})
182
+	} else {
183
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
184
+	}
18 185
 }
19 186
 
20 187
 func (c *HisChargeApiController) GetChargeStatisticsDetail() {
@@ -87,3 +254,50 @@ func (c *HisChargeApiController) GetChargeStatisticsSettle() {
87 254
 	}
88 255
 
89 256
 }
257
+
258
+func (c *HisChargeApiController) GetHisInspectionList() {
259
+	record_date := c.GetString("record_date")
260
+	keyword := c.GetString("keyword")
261
+	is_print, _ := c.GetInt64("is_print")
262
+	page, _ := c.GetInt64("page")
263
+	limit, _ := c.GetInt64("limit")
264
+
265
+	adminUser := c.GetAdminUserInfo()
266
+
267
+	timeLayout := "2006-01-02"
268
+	loc, _ := time.LoadLocation("Local")
269
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
270
+	if err != nil {
271
+
272
+	}
273
+	record_time := startTime.Unix()
274
+	labels, total, err := service.GetLabelPrintList(page, limit, adminUser.CurrentOrgId, record_time, is_print, keyword)
275
+	if err == nil {
276
+
277
+		c.ServeSuccessJSON(map[string]interface{}{
278
+			"labels": labels,
279
+			"total":  total,
280
+		})
281
+		return
282
+
283
+	} else {
284
+
285
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
286
+		return
287
+
288
+	}
289
+
290
+}
291
+func (c *HisChargeApiController) GetHisInspectionInfo() {
292
+	id, _ := c.GetInt64("id")
293
+	label, err := service.GetLabelPrintInfo(id)
294
+	if err == nil {
295
+		c.ServeSuccessJSON(map[string]interface{}{
296
+			"label": label,
297
+		})
298
+		return
299
+	} else {
300
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
301
+		return
302
+	}
303
+}

+ 2 - 2
controllers/his_config_api_controller.go View File

@@ -413,8 +413,8 @@ func (c *HisConfigApiController) setProjectTemplateWithJSON(project *models.HisP
413 413
 
414 414
 	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
415 415
 		total, _ := json["total"].(string)
416
-		totals, _ := strconv.ParseInt(total, 10, 64)
417
-		project.Count = totals
416
+		//totals, _ := strconv.ParseInt(total, 10, 64)
417
+		project.Count = total
418 418
 	}
419 419
 
420 420
 	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {

+ 1 - 1
controllers/his_hospital_api_controller.go View File

@@ -198,7 +198,7 @@ func (c *HisHospitalApiController) GetHisHospitalChargePatientInfo() {
198 198
 		monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
199 199
 	}
200 200
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
201
-	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
201
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
202 202
 	order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
203 203
 	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
204 204
 	//获取所有科室信息

+ 9 - 2
controllers/his_project_api_controller.go View File

@@ -825,12 +825,19 @@ func (this *HisProjectApiController) DeleteProject() {
825 825
 }
826 826
 
827 827
 func (this *HisProjectApiController) GetHisProject() {
828
-
829 828
 	adminUserInfo := this.GetAdminUserInfo()
830 829
 	orgId := adminUserInfo.CurrentOrgId
831 830
 	project, err := service.GetHisProject(orgId)
832 831
 	good_info, err := service.GetGoodInfoMation(orgId)
833
-
832
+	_, config := service.FindHisStockPriceRecordByOrgId(orgId)
833
+	if config.ID > 0 && config.IsOpen == 1 {
834
+		//处理耗材不同批号价格问题
835
+		for _, item := range good_info {
836
+			if len(item.GoodSotckInfo) > 0 {
837
+				item.PackingPrice = item.GoodSotckInfo[0].Price
838
+			}
839
+		}
840
+	}
834 841
 	if err != nil {
835 842
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
836 843
 		return

+ 5 - 8
controllers/manage_api_controller.go View File

@@ -2300,15 +2300,12 @@ func (this *MachineApiController) EditUser() {
2300 2300
 	id, _ := this.GetInt64("id")
2301 2301
 	fmt.Println("id", id)
2302 2302
 	patientid, _ := this.GetInt64("patientid")
2303
-	device, err := service.GetUserInformation(id)
2303
+	device, _ := service.GetUserInformation(id)
2304 2304
 	//获取初次使用记录
2305
-	macher, err := service.GetUserTotalByMacher(device.EquimentId)
2306
-	count, err := service.GetUserTotalCount(orgId, device.BedNumber)
2307
-	patients, err := service.GetPatientInfoMation(patientid)
2308
-	if err != nil {
2309
-		this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "查询失败:("+err.Error()+")")
2310
-		return
2311
-	}
2305
+	macher, _ := service.GetUserTotalByMacher(device.EquimentId)
2306
+	count, _ := service.GetUserTotalCount(orgId, device.BedNumber)
2307
+	patients, _ := service.GetPatientInfoMation(patientid)
2308
+
2312 2309
 	this.ServeSuccessJSON(map[string]interface{}{
2313 2310
 		"device":   device,
2314 2311
 		"patients": patients,

+ 5 - 1
controllers/manager_center_api_controller.go View File

@@ -303,7 +303,6 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
303 303
 	hosp_appr_flag, _ := c.GetInt64("hosp_appr_flag")
304 304
 	lmt_used_flag, _ := c.GetInt64("lmt_used_flag")
305 305
 	prescribing_number_unit := c.GetString("prescribing_number_unit")
306
-
307 306
 	adminInfo := c.GetAdminUserInfo()
308 307
 	drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
309 308
 	drugLib := &models.BaseDrugLib{
@@ -1440,6 +1439,8 @@ func (c *ManagerCenterApiController) GetAllManufacturer() {
1440 1439
 func (c *ManagerCenterApiController) CreateGoodInfo() {
1441 1440
 	good_id, _ := c.GetInt64("good_id", 0)
1442 1441
 	specification_name := c.GetString("specification_name")
1442
+	register_number := c.GetString("register_number")
1443
+
1443 1444
 	good_unit, _ := c.GetInt64("good_unit", -1)
1444 1445
 	buy_price, _ := c.GetFloat("buy_price", 0)
1445 1446
 	sell_price, _ := c.GetFloat("sell_price", 0)
@@ -1540,6 +1541,7 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1540 1541
 		PackingPrice:                packing_price,
1541 1542
 		DefaultCountUnit:            default_count_unit,
1542 1543
 		MinUnit:                     min_unit,
1544
+		RegisterNumber:              register_number,
1543 1545
 	}
1544 1546
 	err, goodInfos := service.AddSigleGoodInfo(&goodInfo)
1545 1547
 	if err == nil {
@@ -1601,6 +1603,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1601 1603
 	default_count_unit := c.GetString("default_count_unit")
1602 1604
 	min_unit := c.GetString("min_unit")
1603 1605
 	total, _ := c.GetFloat("total")
1606
+	register_number := c.GetString("register_number")
1604 1607
 
1605 1608
 	adminUserInfo := c.GetAdminUserInfo()
1606 1609
 
@@ -1652,6 +1655,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1652 1655
 		DefaultCountUnit:            default_count_unit,
1653 1656
 		MinUnit:                     min_unit,
1654 1657
 		Total:                       total,
1658
+		RegisterNumber:              register_number,
1655 1659
 	}
1656 1660
 
1657 1661
 	totals := service.FindGoodInfoByNameOne(specification_name, adminUserInfo.CurrentOrgId, good_id, id, good_name)

+ 66 - 53
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -502,6 +502,36 @@ func (this *DialysisAPIController) DialysisRecord() {
502 502
 		}
503 503
 	}
504 504
 	_, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
505
+
506
+	_, is_project_open_config := service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
507
+
508
+	projects, _ := service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
509
+	temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
510
+
511
+	var team_projects []*models.HisPrescriptionProject
512
+	var index int64 = 0
513
+	for _, item := range temp_team_projects {
514
+		//组套里面非检验项目的
515
+		if item.HisProject.CostClassify != 3 {
516
+			projects = append(projects, item)
517
+		}
518
+		//组套里面检验项目的
519
+		if item.HisProject.CostClassify == 3 {
520
+			index = index + 1
521
+			if index == 1 {
522
+				team_projects = append(team_projects, item)
523
+			}
524
+		}
525
+	}
526
+
527
+	stockType, _ := service.GetStockType(adminInfo.Org.Id)
528
+
529
+	prepare, _ := service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
530
+
531
+	//获取最后一次血管通路
532
+	lastAssessment, parseDateErr := service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
533
+
534
+	prescribeOne, parseDateErr := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
505 535
 	var his_advices []*models.HisDoctorAdviceInfo
506 536
 	if is_open_config.IsOpen == 1 {
507 537
 		// 先走redis,没有走数据库
@@ -537,6 +567,7 @@ func (this *DialysisAPIController) DialysisRecord() {
537 567
 		"prescribeOne":                   prescribeOne,
538 568
 		"is_project_open_config":         is_project_open_config,
539 569
 		"project":                        projects,
570
+		"team_projects":                  team_projects,
540 571
 	}
541 572
 	this.ServeSuccessJSON(returnData)
542 573
 }
@@ -1145,7 +1176,9 @@ func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
1145 1176
 		keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_after_dislysis_list_all"
1146 1177
 		redis.Set(keyOne, "", time.Second)
1147 1178
 		err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
1179
+
1148 1180
 		if err == nil {
1181
+			fmt.Println("hhhhhhhhhhh0000000000", err)
1149 1182
 			c.ServeSuccessJSON(map[string]interface{}{
1150 1183
 				"assessmentAfterDislysis": assessmentAfterDislysis,
1151 1184
 			})
@@ -1695,6 +1728,7 @@ func (c *DialysisAPIController) Finish() {
1695 1728
 
1696 1729
 	}
1697 1730
 	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 {
1731
+	if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 {
1698 1732
 		evaluation, _ := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, recordDate.Unix())
1699 1733
 		if evaluation.SystolicBloodPressure == 0 {
1700 1734
 			evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
@@ -3188,11 +3222,10 @@ func (c *DialysisAPIController) GetLongAdvice() {
3188 3222
 		}
3189 3223
 		if err == nil {
3190 3224
 			c.ServeSuccessJSON(map[string]interface{}{
3191
-				"status":          "2",
3192
-				"advices":         advices,
3193
-				"advices_two":     RemoveRepeatedElement(advice_three),
3194
-				"is_open_remind":  config.IsOpenRemind,
3195
-				"his_config_open": hisConfig.IsOpen,
3225
+				"status":         "2",
3226
+				"advices":        advices,
3227
+				"advices_two":    RemoveRepeatedElement(advice_three),
3228
+				"is_open_remind": config.IsOpenRemind,
3196 3229
 			})
3197 3230
 		}
3198 3231
 	}
@@ -3834,7 +3867,7 @@ func (c *DialysisAPIController) CreateConsumables() {
3834 3867
 			}
3835 3868
 		}
3836 3869
 
3837
-		fmt.Println("dialysisBefor9999999999999999999", dialysisBefor, active)
3870
+		//fmt.Println("dialysisBefor9999999999999999999", dialysisBefor, active)
3838 3871
 
3839 3872
 		//新增
3840 3873
 		if active == 1 && len(goods) > 0 {
@@ -3995,34 +4028,6 @@ func (c *DialysisAPIController) CreateConsumables() {
3995 4028
 				}
3996 4029
 			}
3997 4030
 
3998
-			//出库
3999
-			//err = service.ConsumablesDeliveryTotal(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
4000
-			//fmt.Println("err", err)
4001
-			////查询今日出库数据
4002
-			//list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
4003
-			//
4004
-			//if len(list) == 0 {
4005
-			//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
4006
-			//	return
4007
-			//}
4008
-			//
4009
-			//for _, item := range list {
4010
-			//	prepare := models.DialysisBeforePrepare{
4011
-			//		UserOrgId:  item.OrgId,
4012
-			//		PatientId:  patient_id,
4013
-			//		RecordDate: item.RecordTime,
4014
-			//		GoodId:     item.GoodId,
4015
-			//		GoodTypeId: item.GoodTypeId,
4016
-			//		Count:      item.Count,
4017
-			//		Ctime:      time.Now().Unix(),
4018
-			//		Creater:    adminUser.AdminUser.Id,
4019
-			//		Status:     1,
4020
-			//	}
4021
-			//	//删除准备表数据
4022
-			//	service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
4023
-			//	service.CreateDialysisBeforePrepareOne(&prepare)
4024
-			//}
4025
-
4026 4031
 		}
4027 4032
 	}
4028 4033
 
@@ -4268,7 +4273,6 @@ func (c *DialysisAPIController) EditConsumables() {
4268 4273
 				}
4269 4274
 
4270 4275
 				for _, item := range beforePrepares {
4271
-					fmt.Println("23232323232323为什么99999999999999999999999999999999", item.GoodId)
4272 4276
 
4273 4277
 					//1.查看该患者该耗材型号最后一次出库数量
4274 4278
 					goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
@@ -4283,6 +4287,7 @@ func (c *DialysisAPIController) EditConsumables() {
4283 4287
 						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
4284 4288
 						break
4285 4289
 					}
4290
+
4286 4291
 					var last_total int64
4287 4292
 
4288 4293
 					//如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
@@ -4293,6 +4298,7 @@ func (c *DialysisAPIController) EditConsumables() {
4293 4298
 
4294 4299
 						//查询该批次剩余库存
4295 4300
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
4301
+						fmt.Println("剩余库存333333333333333", lastInfo)
4296 4302
 						if lastInfo.StockCount == 0 {
4297 4303
 							//查询该耗材的总库存
4298 4304
 							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
@@ -4307,17 +4313,22 @@ func (c *DialysisAPIController) EditConsumables() {
4307 4313
 							}
4308 4314
 
4309 4315
 						}
4316
+
4310 4317
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
4311 4318
 						fmt.Println("剩余库存", lastInfo.StockCount)
4312 4319
 						fmt.Println("差", last_total)
4313
-						if lastInfo.StockCount >= last_total {
4314
-							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
4315
-							break
4316
-						}
4317
-
4318
-						//如果库存不够,则出库到下一个批次
4319
-						if lastInfo.StockCount < last_total {
4320
-
4320
+						//查询该耗材的总库存
4321
+						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
4322
+						// 如果库存差大于剩余库存则提示库存不足
4323
+						if last_total > wareinfo.StockCount {
4324
+							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
4325
+							c.ServeSuccessJSON(map[string]interface{}{
4326
+								"message":            "1",
4327
+								"good_name":          goodObj.GoodName,
4328
+								"specification_name": goodObj.SpecificationName,
4329
+							})
4330
+							return
4331
+						} else {
4321 4332
 							err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
4322 4333
 							break
4323 4334
 						}
@@ -4955,7 +4966,6 @@ func (c *DialysisAPIController) UpdateStockGoods() {
4955 4966
 //当前数据比上一次出库数据少
4956 4967
 func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
4957 4968
 
4958
-	fmt.Println("w我的中国馆公共区发电房阿道夫安抚安抚安抚安抚安抚安抚阿道夫阿道夫阿凡达阿道夫a", count)
4959 4969
 	//查询该患者当天已经出库的耗材信息
4960 4970
 	goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
4961 4971
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
@@ -4994,7 +5004,6 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
4994 5004
 
4995 5005
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
4996 5006
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
4997
-	fmt.Println("goodsy999999999999", goods_yc)
4998 5007
 
4999 5008
 	//退库
5000 5009
 	if len(goods_yc) > 0 {
@@ -5010,10 +5019,8 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
5010 5019
 //耗材出库删除
5011 5020
 func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
5012 5021
 
5013
-	fmt.Println("count2323223884584854854854u5454785487547845785478758487545475475487,count", count)
5014 5022
 	// 先根据相关信息查询当天该耗材的出库信息
5015 5023
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
5016
-	fmt.Println("errr232323232323232323232323232", err)
5017 5024
 
5018 5025
 	if err != nil {
5019 5026
 		return err
@@ -5115,7 +5122,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
5115 5122
 				PatientId:               patient_id,
5116 5123
 			}
5117 5124
 
5118
-			service.UpdatedStockFlow(stockFlow)
5125
+			service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
5119 5126
 		}
5120 5127
 
5121 5128
 		if errOne != nil {
@@ -5182,7 +5189,8 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
5182 5189
 				PatientId:               patient_id,
5183 5190
 				ReturnCount:             delete_count,
5184 5191
 			}
5185
-			service.UpdatedStockFlow(stockFlow)
5192
+			//service.UpdatedStockFlow(stockFlow)
5193
+			service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
5186 5194
 		}
5187 5195
 
5188 5196
 	}
@@ -5216,7 +5224,8 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
5216 5224
 	// 删除出库完成后,要增加对应批次的库存数量
5217 5225
 	fmt.Println("deletecount2323232323232323232323232323", delete_count)
5218 5226
 	errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count)
5219
-
5227
+	errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
5228
+	fmt.Println("erron2332323232323232232323", errOne)
5220 5229
 	if errThree != nil {
5221 5230
 		return errThree
5222 5231
 	}
@@ -5268,6 +5277,7 @@ func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int6
5268 5277
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
5269 5278
 	fmt.Println("goods222222222222", goods)
5270 5279
 	fmt.Println("goodsy999999999999", goods_yc)
5280
+
5271 5281
 	if len(goods) > 0 {
5272 5282
 		out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
5273 5283
 		if err == gorm.ErrRecordNotFound {
@@ -5368,14 +5378,17 @@ func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *mod
5368 5378
 		stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
5369 5379
 		warehouseOutInfo.Price = stockInInfo.Price
5370 5380
 		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5381
+
5371 5382
 		if errOne != nil {
5372 5383
 			return errOne
5373 5384
 		}
5374 5385
 
5375
-		//更改自动出库的表格
5376
-
5377 5386
 		// 删除出库完成后,要增加对应批次的库存数量
5378
-		fmt.Println("deletecount2323232323232323232323232323", delete_count)
5387
+		fmt.Println("时间人秘股呢换药2232323223323223322323232323232323232323232323", delete_count)
5388
+
5389
+		// 删除出库完成后,要改变流水库存
5390
+		errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
5391
+		fmt.Println("erron2332323232323232232323", errOne)
5379 5392
 		errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
5380 5393
 
5381 5394
 		if errThree != nil {

+ 20 - 0
controllers/mobile_api_controllers/doctor_advice_api_controller.go View File

@@ -75,6 +75,26 @@ func (this *DoctorAdviceAPIController) ScheduleAdvices() {
75 75
 	if project_config.IsOpen == 1 || project_config.IsOpen == 2 {
76 76
 		//获取his医嘱数据
77 77
 		project, _ := service.GetMobileHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, adminInfo.AdminUser.Id)
78
+		//team_project, _ := service.GetMobileHisPrescriptionTeamProject(orgID, date.Unix(), delivery_way, patientType, adminInfo.AdminUser.Id)
79
+		for _, item := range project {
80
+			index := 0
81
+			for _, subItem := range item.HisPrescriptionTeamProject {
82
+
83
+				if subItem.HisProject.CostClassify != 3 {
84
+					subItem.IsCheckTeam = 2
85
+					item.HisPrescriptionProject = append(item.HisPrescriptionProject, subItem)
86
+				}
87
+
88
+				if subItem.HisProject.CostClassify == 3 {
89
+					subItem.IsCheckTeam = 1
90
+					index = index + 1
91
+					if index == 1 {
92
+						item.HisPrescriptionProject = append(item.HisPrescriptionProject, subItem)
93
+					}
94
+				}
95
+			}
96
+		}
97
+
78 98
 
79 99
 		//获取所有的患者
80 100
 		patients, _ := service.GetAllPatientListByListTwo(orgID)

+ 120 - 57
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -679,7 +679,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
679 679
 
680 680
 		//自备药信息
681 681
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
682
-		fmt.Println("2323232323232323232开关", drugStockConfig.IsOpen)
682
+
683 683
 		if drugStockConfig.IsOpen == 1 {
684 684
 			if groupno > 0 {
685 685
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
@@ -695,9 +695,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
695 695
 					var prescribing_number_total int64
696 696
 					for _, item := range advices {
697 697
 						if item.Way == 1 {
698
-							//查询该药品是否有库存
698
+							//查询该药品的剩余库存
699 699
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
700
-							fmt.Println("list23232323232232323232323232", list)
700
+
701 701
 							//查询改药品信息
702 702
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
703 703
 							//判断单位是否相等
@@ -715,8 +715,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
715 715
 								prescribing_number_total = count
716 716
 							}
717 717
 
718
-							fmt.Println("数量", prescribing_number_total)
719
-							fmt.Println("数量二", total)
718
+							fmt.Println("开医嘱数量", prescribing_number_total)
719
+							fmt.Println("剩余库存", total)
720 720
 
721 721
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
722 722
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -757,26 +757,29 @@ func (c *PatientApiController) ExecDoctorAdvice() {
757 757
 						isHasWay = true
758 758
 					}
759 759
 				}
760
-				fmt.Println("hh2h32323232323232323", isHasWay)
760
+
761 761
 				if isHasWay {
762 762
 					var total int64
763 763
 					var prescribing_number_total int64
764 764
 					for _, item := range advices {
765
-						fmt.Println("hhh23h2h3h232323", item.Way)
765
+
766 766
 						if item.Way == 1 {
767
-							//查询该药品是否有库存
767
+							//查询该药品的剩余库存
768 768
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
769 769
 
770 770
 							//查询改药品信息
771 771
 							medical, _ := service.GetBaseDrugMedical(item.DrugId)
772
+
772 773
 							//判断单位是否相等
773 774
 							if medical.MaxUnit == item.PrescribingNumberUnit {
774 775
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
775 776
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
776 777
 								//转化为最小单位
777
-								total = list.Count * medical.MinNumber
778
+								total = list.Count*medical.MinNumber + list.StockMinNumber
779
+								fmt.Println("美国疫情2332323233232323232332323232233232323232", total)
778 780
 								prescribing_number_total = count * medical.MinNumber
779 781
 							}
782
+
780 783
 							if medical.MinUnit == item.PrescribingNumberUnit {
781 784
 								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
782 785
 								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
@@ -784,8 +787,8 @@ func (c *PatientApiController) ExecDoctorAdvice() {
784 787
 								prescribing_number_total = count
785 788
 							}
786 789
 
787
-							fmt.Println("数量", prescribing_number_total)
788
-							fmt.Println("数量二", total)
790
+							fmt.Println("开医嘱数量", prescribing_number_total)
791
+							fmt.Println("剩余库存", total)
789 792
 
790 793
 							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
791 794
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -803,6 +806,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
803 806
 								})
804 807
 								return
805 808
 							}
809
+
806 810
 							if prescribing_number_total <= total {
807 811
 								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
808 812
 								c.ServeSuccessJSON(map[string]interface{}{
@@ -982,26 +986,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
982 986
 				for _, item := range advices {
983 987
 
984 988
 					advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
985
-					//查询该药品是否有库存
986
-					//  list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
987
-					//  prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
988
-					//  count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
989
-					//  if list.Count == 0 {
990
-					//    c.ServeSuccessJSON(map[string]interface{}{
991
-					//      "msg":    "1",
992
-					//      "advice": advice,
993
-					//      "ids":    ids,
994
-					//    })
995
-					//    return
996
-					//  }
997
-					//  if count > list.Count {
998
-					//    c.ServeSuccessJSON(map[string]interface{}{
999
-					//      "msg":    "2",
1000
-					//      "advice": advice,
1001
-					//      "ids":    ids,
1002
-					//    })
1003
-					//    return
1004
-					//}
989
+
1005 990
 					var total int64
1006 991
 					var prescribing_number_total int64
1007 992
 					//查询该药品是否有库存
@@ -1014,9 +999,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1014 999
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1015 1000
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1016 1001
 						//转化为最小单位
1017
-						total = list.Count * medical.MinNumber
1002
+						total = list.Count*medical.MinNumber + list.StockMinNumber
1018 1003
 						prescribing_number_total = count * medical.MinNumber
1019 1004
 					}
1005
+					fmt.Println("医嘱开的数量", total)
1020 1006
 					if medical.MinUnit == advice.PrescribingNumberUnit {
1021 1007
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1022 1008
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
@@ -1071,6 +1057,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1071 1057
 
1072 1058
 func (c *PatientApiController) ModifyExecDoctorAdvice() {
1073 1059
 	execution_time := c.GetString("execution_time")
1060
+	fmt.Println("execution_time", execution_time)
1074 1061
 	groupno, _ := c.GetInt64("groupno", -1)
1075 1062
 
1076 1063
 	var ids []string
@@ -1156,8 +1143,15 @@ func (c *PatientApiController) ModifyExecDoctorAdvice() {
1156 1143
 			ExecutionTime: theTime.Unix(),
1157 1144
 			UpdatedTime:   time.Now().Unix(),
1158 1145
 		}
1146
+		fmt.Println("ids2323232232323", ids)
1159 1147
 		service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
1160 1148
 
1149
+		project := models.HisPrescriptionProject{
1150
+			ExecutionTime: theTime.Unix(),
1151
+			Mtime:         time.Now().Unix(),
1152
+		}
1153
+		service.ModifyHisPrescriptionProject(&project, ids)
1154
+
1161 1155
 	}
1162 1156
 	if err != nil {
1163 1157
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
@@ -2053,10 +2047,7 @@ func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, dat
2053 2047
 		blood_access_part_id := dataBody["blood_access_part_id"].(string)
2054 2048
 		evaluation.BloodAccessPartId = blood_access_part_id
2055 2049
 	}
2056
-	//if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
2057
-	//	blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
2058
-	//	evaluation.BloodAccessPartId = blood_access_part_id
2059
-	//}
2050
+
2060 2051
 	if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
2061 2052
 		blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
2062 2053
 		evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
@@ -2075,9 +2066,6 @@ func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, dat
2075 2066
 		is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
2076 2067
 		evaluation.IsHemorrhage = is_hemorrhage
2077 2068
 
2078
-		//if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
2079
-		//	is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
2080
-		//	fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
2081 2069
 		if is_hemorrhage != 1 && is_hemorrhage != 2 {
2082 2070
 			is_hemorrhage = 0
2083 2071
 		}
@@ -2193,6 +2181,8 @@ func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, dat
2193 2181
 
2194 2182
 		humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
2195 2183
 
2184
+	if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
2185
+		humor_excessive_symptom := dataBody["humor_excessive_symptom"].(string)
2196 2186
 		evaluation.HumorExcessiveSymptom = humor_excessive_symptom
2197 2187
 	}
2198 2188
 
@@ -2902,6 +2892,7 @@ func (c *PatientApiController) GetPrintDialysisOrder() {
2902 2892
 	projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
2903 2893
 	if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
2904 2894
 		for _, item := range projects {
2895
+			cnt, _ := strconv.ParseFloat(item.Count, 64)
2905 2896
 			var advice models.HisDoctorAdviceInfo
2906 2897
 			advice.ID = item.ID
2907 2898
 			advice.Checker = item.Checker
@@ -2910,6 +2901,7 @@ func (c *PatientApiController) GetPrintDialysisOrder() {
2910 2901
 			advice.ExecutionState = item.ExecutionState
2911 2902
 			advice.ExecutionStaff = item.ExecutionStaff
2912 2903
 			//advice.PrescribingNumber = float64(item.Count)
2904
+			advice.PrescribingNumber = cnt
2913 2905
 			advice.PrescribingNumberUnit = item.Unit
2914 2906
 			advice.AdviceDoctor = item.Doctor
2915 2907
 			if item.Type == 3 {
@@ -3578,6 +3570,8 @@ func (this *PatientApiController) GetSearchPatient() {
3578 3570
 func (c *PatientApiController) ExecProject() {
3579 3571
 	execution_time := c.GetString("execution_time")
3580 3572
 	project_id, _ := c.GetInt64("project_id")
3573
+	team_id, _ := c.GetInt64("team_id")
3574
+	is_check_team, _ := c.GetInt64("is_check_team")
3581 3575
 
3582 3576
 	if len(execution_time) <= 0 {
3583 3577
 		utils.ErrorLog("execution_time")
@@ -3593,6 +3587,7 @@ func (c *PatientApiController) ExecProject() {
3593 3587
 		return
3594 3588
 	}
3595 3589
 	adminInfo := c.GetMobileAdminUserInfo()
3590
+
3596 3591
 	project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
3597 3592
 	if project.ExecutionState == 1 {
3598 3593
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
@@ -3602,29 +3597,63 @@ func (c *PatientApiController) ExecProject() {
3602 3597
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
3603 3598
 		return
3604 3599
 	}
3605
-
3606 3600
 	project.ExecutionState = 1
3607 3601
 	project.ExecutionStaff = adminInfo.AdminUser.Id
3608 3602
 	project.ExecutionTime = theTime.Unix()
3609
-	err := service.SaveHisProject(&project)
3610
-	if err == nil {
3611
-		c.ServeSuccessJSON(map[string]interface{}{
3612
-			"project": project,
3613
-		})
3603
+	if team_id == 0 {
3604
+
3605
+		err := service.SaveHisProject(&project)
3606
+		if err == nil {
3607
+			c.ServeSuccessJSON(map[string]interface{}{
3608
+				"project": project,
3609
+			})
3610
+		} else {
3611
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3612
+			return
3613
+
3614
+		}
3614 3615
 	} else {
3615
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3616
-		return
3616
+		if is_check_team == 2 { //虽然是组套数据,但不是检验项目
3617 3617
 
3618
-	}
3618
+			err := service.SaveHisProject(&project)
3619
+			if err == nil {
3620
+				c.ServeSuccessJSON(map[string]interface{}{
3621
+					"project": project,
3622
+				})
3623
+			} else {
3624
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3625
+				return
3619 3626
 
3627
+			}
3628
+		} else {
3629
+			ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
3630
+			var ids []int64
3631
+			for _, items := range ps {
3632
+				ids = append(ids, items.ID)
3633
+			}
3634
+			err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
3635
+			if err == nil {
3636
+				c.ServeSuccessJSON(map[string]interface{}{
3637
+					"project": project,
3638
+				})
3639
+			} else {
3640
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3641
+				return
3642
+
3643
+			}
3644
+		}
3645
+
3646
+	}
3620 3647
 }
3621 3648
 
3622 3649
 func (c *PatientApiController) CheckProject() {
3623 3650
 
3624 3651
 	adminInfo := c.GetMobileAdminUserInfo()
3625 3652
 	project_id, _ := c.GetInt64("project_id")
3626
-	project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
3653
+	team_id, _ := c.GetInt64("team_id")
3654
+	is_check_team, _ := c.GetInt64("is_check_team")
3627 3655
 
3656
+	project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
3628 3657
 	if project.CheckState == 1 {
3629 3658
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
3630 3659
 		return
@@ -3637,18 +3666,52 @@ func (c *PatientApiController) CheckProject() {
3637 3666
 	project.Checker = adminInfo.AdminUser.Id
3638 3667
 	project.CheckTime = time.Now().Unix()
3639 3668
 	project.CheckState = 1
3669
+	if team_id == 0 {
3670
+		err := service.SaveHisProject(&project)
3671
+		if err == nil {
3672
+			c.ServeSuccessJSON(map[string]interface{}{
3673
+				"msg":     "ok",
3674
+				"project": project,
3675
+			})
3640 3676
 
3641
-	err := service.SaveHisProject(&project)
3677
+		} else {
3678
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3679
+			return
3642 3680
 
3643
-	if err == nil {
3644
-		c.ServeSuccessJSON(map[string]interface{}{
3645
-			"msg":     "ok",
3646
-			"project": project,
3647
-		})
3681
+		}
3648 3682
 
3649 3683
 	} else {
3650
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3651
-		return
3684
+		if is_check_team == 2 { //虽然是组套数据,但不是检验项目
3685
+			err := service.SaveHisProject(&project)
3686
+			if err == nil {
3687
+				c.ServeSuccessJSON(map[string]interface{}{
3688
+					"msg":     "ok",
3689
+					"project": project,
3690
+				})
3691
+
3692
+			} else {
3693
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3694
+				return
3695
+
3696
+			}
3697
+
3698
+		} else {
3699
+			ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
3700
+			var ids []int64
3701
+			for _, items := range ps {
3702
+				ids = append(ids, items.ID)
3703
+			}
3704
+			err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
3705
+			if err == nil {
3706
+				c.ServeSuccessJSON(map[string]interface{}{
3707
+					"project": project,
3708
+				})
3709
+			} else {
3710
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
3711
+				return
3712
+
3713
+			}
3714
+		}
3652 3715
 
3653 3716
 	}
3654 3717
 

+ 2 - 2
controllers/new_mobile_api_controllers/mobile_his_api_controller.go View File

@@ -100,7 +100,7 @@ func (c *MobileHisApiController) GetHisPatientInfo() {
100 100
 	prescriptions, _ := service.GetHisPrescription(admin.Org.Id, patient_id, recordDateTime, 2)
101 101
 	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.Org.Id, patient_id, startRecordDateTime, endRecordDateTime, 2)
102 102
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.Org.Id, patient_id, recordDateTime)
103
-	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.Org.Id, patient_id, recordDateTime, 2)
103
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfoTwo(admin.Org.Id, patient_id, recordDateTime, 2)
104 104
 	order, _ := service.GetHisOrder(admin.Org.Id, number, patient_id)
105 105
 	all_prescriptions, _ := service.GetCallHisPrescriptions(startRecordDateTime, endRecordDateTime, admin.Org.Id, patient_id, 2)
106 106
 	adminUserInfo, _ := service.GetAdminUserInfoByID(admin.Org.Id, admin.AdminUser.Id)
@@ -527,7 +527,7 @@ func (c *MobileHisApiController) CreateHisPrescription() {
527 527
 
528 528
 	}
529 529
 
530
-	info, _ := service.FindPatientPrescriptionInfo(adminInfo.Org.Id, patient_id, recordDateTime, 2)
530
+	info, _ := service.FindPatientPrescriptionInfoTwo(adminInfo.Org.Id, patient_id, recordDateTime, 2)
531 531
 	var hpInfo models.HisPrescriptionInfo
532 532
 	if info.ID == 0 {
533 533
 		var randNum int

+ 335 - 10
controllers/new_mobile_api_controllers/staff_schedule_api_controller.go View File

@@ -5,7 +5,12 @@ import (
5 5
 	"XT_New/enums"
6 6
 	"XT_New/models"
7 7
 	"XT_New/service"
8
+	"XT_New/utils"
9
+	"encoding/json"
8 10
 	"fmt"
11
+	"github.com/jinzhu/gorm"
12
+	"reflect"
13
+	"strconv"
9 14
 	"strings"
10 15
 	"time"
11 16
 )
@@ -268,22 +273,37 @@ func (this *StaffScheduleApiController) GetPatientScheduleList() {
268 273
 		}
269 274
 		startTime = theTime.Unix()
270 275
 	}
271
-	fmt.Println("时间搓", startTime)
272 276
 	zoneid, _ := this.GetInt64("zoneid")
273 277
 	fmt.Println(zoneid)
274 278
 	classtype, _ := this.GetInt64("classtype")
275
-	fmt.Println("classtype", classtype)
276 279
 
277
-	//获取当天排班的病人情况
278
-	schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
280
+	is_open, _ := this.GetInt64("is_open")
279 281
 
280
-	if err != nil {
281
-		this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
282
-		return
282
+	if is_open == 0 {
283
+		//获取当天排班的病人情况
284
+		schedule, err := service.GetPatientSchedule(startTime, zoneid, classtype, orgid)
285
+
286
+		if err != nil {
287
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
288
+			return
289
+		}
290
+		this.ServeSuccessJSON(map[string]interface{}{
291
+			"schedule": schedule,
292
+		})
293
+	}
294
+	if is_open == 1 {
295
+		//获取空床位的排班数据
296
+		list, err := service.GetPatientScheduleByBed(startTime, zoneid, orgid, classtype)
297
+		stockType, _ := service.GetStockType(orgid)
298
+		if err != nil {
299
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
300
+			return
301
+		}
302
+		this.ServeSuccessJSON(map[string]interface{}{
303
+			"schedule":  list,
304
+			"stockType": stockType,
305
+		})
283 306
 	}
284
-	this.ServeSuccessJSON(map[string]interface{}{
285
-		"schedule": schedule,
286
-	})
287 307
 }
288 308
 
289 309
 func (this *StaffScheduleApiController) DeleteSchedule() {
@@ -352,3 +372,308 @@ func (this *StaffScheduleApiController) UpdatePatientScheduleById() {
352 372
 		"msg": "切换成功",
353 373
 	})
354 374
 }
375
+func (this *StaffScheduleApiController) UpdateDialysisPrescription() {
376
+	patient_id, _ := this.GetInt64("patient_id")
377
+	start_time, _ := this.GetInt64("start_time")
378
+	mode_id, _ := this.GetInt64("mode_id")
379
+	dialyzer_perfusion_apparatus := this.GetString("dialyzer_perfusion_apparatus")
380
+	dialysis_irrigation := this.GetString("dialysis_irrigation")
381
+	//更改透析模式
382
+	_, errcode := service.GetDialyisSolution(patient_id, start_time)
383
+	if errcode == gorm.ErrRecordNotFound {
384
+		orgId := this.GetMobileAdminUserInfo().Org.Id
385
+		prescription := models.DialysisPrescription{
386
+			DialysisDialyszers: dialyzer_perfusion_apparatus,
387
+			DialysisIrrigation: dialysis_irrigation,
388
+			PatientId:          patient_id,
389
+			UserOrgId:          orgId,
390
+			Status:             1,
391
+			RecordDate:         start_time,
392
+			CreatedTime:        time.Now().Unix(),
393
+			ModeId:             mode_id,
394
+		}
395
+		err := service.CreateDialysisPrescription(&prescription)
396
+
397
+		if err != nil {
398
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
399
+			return
400
+		}
401
+		this.ServeSuccessJSON(map[string]interface{}{
402
+			"msg": "保存成功",
403
+		})
404
+	} else if errcode == nil {
405
+		prescription := models.DialysisPrescription{
406
+			DialysisDialyszers: dialyzer_perfusion_apparatus,
407
+			DialysisIrrigation: dialysis_irrigation,
408
+			ModeId:             mode_id,
409
+		}
410
+		err := service.UpdateDialysisPrescriptionOne(prescription, patient_id, start_time, mode_id)
411
+		if err != nil {
412
+			this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
413
+			return
414
+		}
415
+		this.ServeSuccessJSON(map[string]interface{}{
416
+			"msg": "保存成功",
417
+		})
418
+	}
419
+}
420
+
421
+func (this *StaffScheduleApiController) UpdateBloodScheduleMode() {
422
+	id, _ := this.GetInt64("id")
423
+	mode_id, _ := this.GetInt64("mode_id")
424
+	schedule := models.XtSchedule{
425
+		ModeId: mode_id,
426
+	}
427
+	service.UpdatedScheduleMode(schedule, id)
428
+	this.ServeSuccessJSON(map[string]interface{}{
429
+		"msg": "保存成功",
430
+	})
431
+}
432
+
433
+func (this *StaffScheduleApiController) UpdateBloodSchedule() {
434
+
435
+	patient_id, _ := this.GetInt64("patient_id")
436
+	fmt.Println(patient_id)
437
+	mode_id, _ := this.GetInt64("mode_id")
438
+	schedule_type, _ := this.GetInt64("schedule_type")
439
+	start_time, _ := this.GetInt64("start_time")
440
+	bed_id, _ := this.GetInt64("bed_id")
441
+	//更改排班
442
+	schedule := models.XtSchedule{
443
+		ScheduleType: schedule_type,
444
+		ModeId:       mode_id,
445
+	}
446
+
447
+	//查询该床位该班次是否存在排班
448
+	_, errschedulecode := service.GetPatientScheduleIsExist(start_time, schedule_type, bed_id)
449
+	if errschedulecode == gorm.ErrRecordNotFound {
450
+		service.UpdatedSchedule(schedule, patient_id, start_time, schedule_type, bed_id)
451
+		this.ServeSuccessJSON(map[string]interface{}{
452
+			"msgerr": "保存成功",
453
+		})
454
+	} else if errschedulecode == nil {
455
+		this.ServeSuccessJSON(map[string]interface{}{
456
+			"msg":    "1",
457
+			"msgerr": "排班已存在",
458
+		})
459
+	}
460
+
461
+}
462
+
463
+func (this *StaffScheduleApiController) GetSchedulePatient() {
464
+
465
+	schedule, _ := this.GetInt64("schedule", 0) //1已2未
466
+	contagion, _ := this.GetInt64("contagion", 0)
467
+	keywords := this.GetString("keywords", "")
468
+	adminInfo := this.GetMobileAdminUserInfo()
469
+	thisTime := time.Now()
470
+	weekDay := int(thisTime.Weekday())
471
+	if weekDay == 0 {
472
+		weekDay = 7
473
+	}
474
+	thisWeekEnd := 7 - weekDay
475
+	weekStartPoint := thisWeekEnd - 6
476
+	weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
477
+	weekEndPoint := thisWeekEnd + 7
478
+	weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
479
+	fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
480
+
481
+	weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
482
+	weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
483
+	fmt.Println(weekStartTime, weekEndTime)
484
+
485
+	timeLayout := "2006-01-02 15:04:05"
486
+	loc, _ := time.LoadLocation("Local")
487
+	theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
488
+	theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
489
+	weekStart := theStarTime.Unix()
490
+	weekEnd := theEndTime.Unix()
491
+
492
+	patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.Org.Id, keywords, weekStart, weekEnd, schedule, contagion)
493
+
494
+	this.ServeSuccessJSON(map[string]interface{}{
495
+		"patients": patients,
496
+	})
497
+	return
498
+}
499
+
500
+func (c *StaffScheduleApiController) CreateMobileSchedulePatient() {
501
+
502
+	patientID, _ := c.GetInt64("patient_id", 0)
503
+	if patientID <= 0 {
504
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
505
+		return
506
+	}
507
+
508
+	adminUserInfo := c.GetMobileAdminUserInfo()
509
+	patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patientID)
510
+	if patientInfo.ID == 0 {
511
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
512
+		return
513
+	}
514
+
515
+	var schedule models.Schedule
516
+	dataBody := make(map[string]interface{}, 0)
517
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
518
+	if err != nil {
519
+		utils.ErrorLog(err.Error())
520
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
521
+		return
522
+	}
523
+
524
+	if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
525
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
526
+		return
527
+	}
528
+	scheduleDate, _ := dataBody["schedule_date"].(string)
529
+	if len(scheduleDate) == 0 {
530
+		utils.ErrorLog("len(schedule_date) == 0")
531
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
532
+		return
533
+	}
534
+	timeLayout := "2006-01-02"
535
+	loc, _ := time.LoadLocation("Local")
536
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
537
+	if err != nil {
538
+		utils.ErrorLog(err.Error())
539
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
540
+		return
541
+	}
542
+	schedule.ScheduleDate = theTime.Unix()
543
+
544
+	timeNow := time.Now().Format("2006-01-02")
545
+	if timeNow > scheduleDate {
546
+		utils.ErrorLog(timeNow)
547
+		utils.ErrorLog(scheduleDate)
548
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
549
+		return
550
+	}
551
+
552
+	if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
553
+		utils.ErrorLog("schedule_type")
554
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
555
+		return
556
+	}
557
+	scheduleType := int64(dataBody["schedule_type"].(float64))
558
+	if scheduleType < 1 || scheduleType > 3 {
559
+		utils.ErrorLog("scheduleType < 3")
560
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
561
+		return
562
+	}
563
+	schedule.ScheduleType = scheduleType
564
+
565
+	if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
566
+		utils.ErrorLog("bed_id")
567
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
568
+		return
569
+	}
570
+	bedId := int64(dataBody["bed_id"].(float64))
571
+	if bedId < 1 {
572
+		utils.ErrorLog("bedId < 1")
573
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
574
+		return
575
+	}
576
+	schedule.BedId = bedId
577
+
578
+	if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
579
+		utils.ErrorLog("partition_id")
580
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
581
+		return
582
+	}
583
+	partitionId := int64(dataBody["partition_id"].(float64))
584
+	if partitionId < 1 {
585
+		utils.ErrorLog("partitionId < 1")
586
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
587
+		return
588
+	}
589
+	schedule.PartitionId = partitionId
590
+
591
+	if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
592
+		utils.ErrorLog("schedule_week")
593
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
594
+		return
595
+	}
596
+	scheduleWeek := int64(dataBody["schedule_week"].(float64))
597
+	if scheduleWeek < 1 || scheduleWeek > 7 {
598
+		utils.ErrorLog("scheduleWeek < 1")
599
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
600
+		return
601
+	}
602
+	schedule.ScheduleWeek = scheduleWeek
603
+
604
+	if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
605
+		utils.ErrorLog("mode_id")
606
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
607
+		return
608
+	}
609
+	modeId := int64(dataBody["mode_id"].(float64))
610
+	if modeId < 1 && modeId > 14 {
611
+		utils.ErrorLog("modeId < 1")
612
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
613
+		return
614
+	}
615
+	schedule.ModeId = modeId
616
+
617
+	schedule.PatientId = patientID
618
+	schedule.CreatedTime = time.Now().Unix()
619
+	schedule.UpdatedTime = time.Now().Unix()
620
+	schedule.Status = 1
621
+	schedule.UserOrgId = adminUserInfo.Org.Id
622
+
623
+	bed, _ := service.GetDeviceNumberByID(adminUserInfo.Org.Id, schedule.BedId)
624
+	if bed == nil {
625
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
626
+		return
627
+	}
628
+	if bed.ZoneID != schedule.PartitionId {
629
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
630
+		return
631
+	}
632
+
633
+	scheduleDateStart := scheduleDate + " 00:00:00"
634
+	scheduleDateEnd := scheduleDate + " 23:59:59"
635
+	timeLayout = "2006-01-02 15:04:05"
636
+	theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
637
+	theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
638
+	startTime := theStartTime.Unix()
639
+	endTime := theEndTime.Unix()
640
+
641
+	//一天只有排班一次
642
+	daySchedule, err := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, patientID)
643
+	if daySchedule.ID > 0 {
644
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
645
+		return
646
+	}
647
+
648
+	//同天同位置只能排一个
649
+	pointSchedule, err := service.GetPointSchedule(adminUserInfo.Org.Id, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
650
+	if err != nil {
651
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
652
+		return
653
+	}
654
+	if pointSchedule.ID > 0 {
655
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
656
+		return
657
+	}
658
+
659
+	redis := service.RedisClient()
660
+	defer redis.Close()
661
+	err = service.CreateSchedule(&schedule)
662
+
663
+	key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
664
+	redis.Set(key, "", time.Second)
665
+
666
+	fmt.Println(err)
667
+	if err != nil {
668
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
669
+		return
670
+	}
671
+	schedule.Patient = patientInfo.Name
672
+
673
+	c.ServeSuccessJSON(map[string]interface{}{
674
+		"msg":      "ok",
675
+		"schedule": schedule,
676
+	})
677
+	return
678
+
679
+}

+ 5 - 0
controllers/new_mobile_api_controllers/staff_schedule_api_router.go View File

@@ -20,4 +20,9 @@ func StaffScheduleApiControllersRegisterRouters() {
20 20
 	beego.Router("/m/api/deleteSchedule", &StaffScheduleApiController{}, "Get:DeleteSchedule")
21 21
 	beego.Router("/m/api/ssearchpatient", &StaffScheduleApiController{}, "Get:SearchPatient")
22 22
 	beego.Router("/m/api/updatepatientschedule", &StaffScheduleApiController{}, "Get:UpdatePatientScheduleById")
23
+	beego.Router("/m/api/updateschedulemode", &StaffScheduleApiController{}, "Get:UpdateBloodScheduleMode")
24
+	beego.Router("/m/api/updatedialysisprescription", &StaffScheduleApiController{}, "Get:UpdateDialysisPrescription")
25
+	beego.Router("/m/api/updateschedule", &StaffScheduleApiController{}, "Get:UpdateBloodSchedule")
26
+	beego.Router("m/api/schedule/patients", &StaffScheduleApiController{}, "Get:GetSchedulePatient")
27
+	beego.Router("/m/api/schedule/create", &StaffScheduleApiController{}, "Post:CreateMobileSchedulePatient")
23 28
 }

+ 64 - 70
controllers/patient_api_controller.go View File

@@ -1689,7 +1689,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1689 1689
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1690 1690
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1691 1691
 					//转化为最小单位
1692
-					total = list.Count * medical.MinNumber
1692
+					total = list.Count*medical.MinNumber + list.StockMinNumber
1693 1693
 					prescribing_number_total = count * medical.MinNumber
1694 1694
 				}
1695 1695
 				if medical.MinUnit == item.PrescribingNumberUnit {
@@ -1726,27 +1726,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1726 1726
 					return
1727 1727
 				}
1728 1728
 
1729
-				////查询该药品是否有库存
1730
-				//list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1731
-				//prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1732
-				//count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1733
-				//if list.Count == 0 {
1734
-				//	c.ServeSuccessJSON(map[string]interface{}{
1735
-				//		"msg":    "1",
1736
-				//		"advice": advice,
1737
-				//	})
1738
-				//	return
1739
-				//}
1740
-				//if count > list.Count {
1741
-				//	c.ServeSuccessJSON(map[string]interface{}{
1742
-				//		"msg":    "2",
1743
-				//		"advice": advice,
1744
-				//	})
1745
-				//	return
1746
-				//}
1747
-				////调用药品出库接口
1748
-				//service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1749
-
1750 1729
 			}
1751 1730
 		}
1752 1731
 
@@ -1830,7 +1809,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1830 1809
 		}
1831 1810
 
1832 1811
 		executionStaff := adminUserInfo.AdminUser.Id
1833
-		// checker := adminUserInfo.AdminUser.Id
1834 1812
 
1835 1813
 		timeLayout := "2006-01-02 15:04:05"
1836 1814
 		loc, _ := time.LoadLocation("Local")
@@ -1890,7 +1868,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1890 1868
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1891 1869
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1892 1870
 					//转化为最小单位
1893
-					total = list.Count * medical.MinNumber
1871
+					total = list.Count*medical.MinNumber + list.StockMinNumber
1894 1872
 					prescribing_number_total = count * medical.MinNumber
1895 1873
 				}
1896 1874
 				fmt.Println("单位1", medical.MinUnit)
@@ -1900,9 +1878,9 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1900 1878
 					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1901 1879
 					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1902 1880
 					total = list.Count*medical.MinNumber + list.StockMinNumber
1903
-					fmt.Println("23232322323322323233223", total)
1881
+
1904 1882
 					prescribing_number_total = count
1905
-					fmt.Println("7777777777777777", prescribing_number_total)
1883
+
1906 1884
 				}
1907 1885
 
1908 1886
 				fmt.Println("数量一", prescribing_number_total)
@@ -1932,26 +1910,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1932 1910
 					return
1933 1911
 				}
1934 1912
 			}
1935
-			//	//查询该药品是否有库存
1936
-			//	list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1937
-			//	prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1938
-			//	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1939
-			//	if list.Count == 0 {
1940
-			//		c.ServeSuccessJSON(map[string]interface{}{
1941
-			//			"msg":    "1",
1942
-			//			"advice": advice,
1943
-			//		})
1944
-			//		return
1945
-			//	}
1946
-			//	if count > list.Count {
1947
-			//		c.ServeSuccessJSON(map[string]interface{}{
1948
-			//			"msg":    "2",
1949
-			//			"advice": advice,
1950
-			//		})
1951
-			//		return
1952
-			//	}
1953
-			//	service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1954
-			//}
1913
+
1955 1914
 		}
1956 1915
 		c.ServeSuccessJSON(map[string]interface{}{
1957 1916
 			"msg":    "1",
@@ -2508,36 +2467,71 @@ func (c *PatientApiController) GetDoctorAdvices() {
2508 2467
 		theEndtTIme = theTime.Unix()
2509 2468
 	}
2510 2469
 
2511
-	advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
2512
-	advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
2470
+	hisconfig, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
2513 2471
 
2514
-	if len(advices) > 0 {
2515
-		for _, item := range advices {
2516
-			if item.AdviceDoctor > 0 {
2517
-				operatorIDs = append(operatorIDs, item.AdviceDoctor)
2518
-			}
2519
-			if item.ExecutionStaff > 0 {
2520
-				operatorIDs = append(operatorIDs, item.ExecutionStaff)
2521
-			}
2522
-			if item.Checker > 0 {
2523
-				operatorIDs = append(operatorIDs, item.Checker)
2472
+	if hisconfig.IsOpen == 1 {
2473
+		advices, total, _ := service.GetDoctorAdviceListThree(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
2474
+		advicestwo, _, _ := service.GetDoctorAdviceListFour(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
2475
+
2476
+		if len(advices) > 0 {
2477
+			for _, item := range advices {
2478
+				if item.AdviceDoctor > 0 {
2479
+					operatorIDs = append(operatorIDs, item.AdviceDoctor)
2480
+				}
2481
+				if item.ExecutionStaff > 0 {
2482
+					operatorIDs = append(operatorIDs, item.ExecutionStaff)
2483
+				}
2484
+				if item.Checker > 0 {
2485
+					operatorIDs = append(operatorIDs, item.Checker)
2486
+				}
2487
+				if item.StopDoctor > 0 {
2488
+					operatorIDs = append(operatorIDs, item.StopDoctor)
2489
+				}
2524 2490
 			}
2525
-			if item.StopDoctor > 0 {
2526
-				operatorIDs = append(operatorIDs, item.StopDoctor)
2491
+		}
2492
+
2493
+		//相关操作对应的操作人
2494
+		operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
2495
+
2496
+		c.ServeSuccessJSON(map[string]interface{}{
2497
+			"advices":   advices,
2498
+			"operators": operators,
2499
+			"total":     total,
2500
+			"advicetwo": advicestwo,
2501
+		})
2502
+		return
2503
+	} else {
2504
+		advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
2505
+		advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
2506
+
2507
+		if len(advices) > 0 {
2508
+			for _, item := range advices {
2509
+				if item.AdviceDoctor > 0 {
2510
+					operatorIDs = append(operatorIDs, item.AdviceDoctor)
2511
+				}
2512
+				if item.ExecutionStaff > 0 {
2513
+					operatorIDs = append(operatorIDs, item.ExecutionStaff)
2514
+				}
2515
+				if item.Checker > 0 {
2516
+					operatorIDs = append(operatorIDs, item.Checker)
2517
+				}
2518
+				if item.StopDoctor > 0 {
2519
+					operatorIDs = append(operatorIDs, item.StopDoctor)
2520
+				}
2527 2521
 			}
2528 2522
 		}
2529
-	}
2530 2523
 
2531
-	//相关操作对应的操作人
2532
-	operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
2524
+		//相关操作对应的操作人
2525
+		operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
2533 2526
 
2534
-	c.ServeSuccessJSON(map[string]interface{}{
2535
-		"advices":   advices,
2536
-		"operators": operators,
2537
-		"total":     total,
2538
-		"advicetwo": advicestwo,
2539
-	})
2540
-	return
2527
+		c.ServeSuccessJSON(map[string]interface{}{
2528
+			"advices":   advices,
2529
+			"operators": operators,
2530
+			"total":     total,
2531
+			"advicetwo": advicestwo,
2532
+		})
2533
+		return
2534
+	}
2541 2535
 
2542 2536
 }
2543 2537
 

+ 30 - 31
controllers/public_api_controller.go View File

@@ -69,7 +69,7 @@ func PublicApiRegistRouters() {
69 69
 
70 70
 	beego.Router("/handle10215", &PublicApiController{}, "get:Handle10215")
71 71
 
72
-	//beego.Router("/handelOrder", &PublicApiController{}, "get:HandleOrder")
72
+	beego.Router("/handelOrder", &PublicApiController{}, "get:HandleOrder")
73 73
 
74 74
 }
75 75
 
@@ -1700,35 +1700,34 @@ func (c *PublicApiController) HandleHIS() {
1700 1700
 
1701 1701
 }
1702 1702
 
1703
-//func (c *PublicApiController)HandleOrder(){
1704
-//	//orders, _ := service.GetAllHisOrder()
1705
-//
1706
-//
1707
-//	order, _ := service.GetLastHisOrder()
1708
-//
1709
-//	fpNumber, _ := strconv.Atoi(order.FaPiaoNumber)
1710
-//
1711
-//
1712
-//	//fmt.Println(fpNumber)
1713
-//
1714
-//	//for index, item := range orders {
1715
-//	//	item.FaPiaoCode ="144072080589"
1716
-//	//	var zero string
1717
-//	//	if 1520 + int64(index) >= 1000{
1718
-//	//		zero = "0000" + strconv.FormatInt(1520 + int64(index),10)
1719
-//	//	}else if 1520 + int64(index) >= 10000{
1720
-//	//		zero = "000" + strconv.FormatInt(1520 + int64(index),10)
1721
-//	//	} else if 1520 + int64(index) >= 100000{
1722
-//	//		zero = "00" +strconv.FormatInt(1520 + int64(index),10)
1723
-//	//	} else if 1520 + int64(index) >= 1000000{
1724
-//	//		zero = "0" +strconv.FormatInt(1520 + int64(index),10)
1725
-//	//	}else {
1726
-//	//		zero = strconv.FormatInt(1520 + int64(index),10)
1727
-//	//	}
1728
-//	//	item.FaPiaoNumber = zero
1729
-//	//	service.SaveOrder(item)
1730
-//	//}
1731
-//}
1703
+func (c *PublicApiController) HandleOrder() {
1704
+	orders, _ := service.GetAllHisOrder(10138)
1705
+	record, _ := service.FindFapiaoByIsUse(10138)
1706
+	last_order, _ := service.GetAllHisOrderTwo(10138)
1707
+	if record.ID > 0 {
1708
+		for index, item := range orders {
1709
+			item.FaPiaoCode = record.FapiaoCode
1710
+			var zero string
1711
+			max_number, _ := strconv.ParseInt(last_order.FaPiaoNumber, 10, 64)
1712
+			number, _ := strconv.ParseInt(record.FapiaoNumber, 10, 64)
1713
+			number = number + max_number
1714
+			if number+int64(index) >= 1000 {
1715
+				zero = "0000" + strconv.FormatInt(number+int64(index), 10)
1716
+			} else if number+int64(index) >= 10000 {
1717
+				zero = "000" + strconv.FormatInt(number+int64(index), 10)
1718
+			} else if number+int64(index) >= 100000 {
1719
+				zero = "00" + strconv.FormatInt(number+int64(index), 10)
1720
+			} else if number+int64(index) >= 1000000 {
1721
+				zero = "0" + strconv.FormatInt(number+int64(index), 10)
1722
+			} else {
1723
+				zero = strconv.FormatInt(number+int64(index), 10)
1724
+			}
1725
+			item.FaPiaoNumber = zero
1726
+			item.FaPiaoBatchnumberId = record.ID
1727
+			service.SaveOrder(item)
1728
+		}
1729
+	}
1730
+}
1732 1731
 
1733 1732
 func Mkdir(dir string) {
1734 1733
 	// 创建文件夹
@@ -1896,7 +1895,7 @@ func (c *PublicApiController) Handle10215() {
1896 1895
 							Mtime:              time.Now().Unix(),
1897 1896
 							PatientId:          ssubItem.PatientId,
1898 1897
 							RecordDate:         ssubItem.AdviceDate,
1899
-							Count:              1,
1898
+							Count:              "1",
1900 1899
 							FeedetlSn:          "",
1901 1900
 							MedListCodg:        "",
1902 1901
 							SingleDose:         "1",

+ 28 - 5
controllers/self_drug_api_congtroller.go View File

@@ -83,6 +83,8 @@ func SelfDrugRouters() {
83 83
 	beego.Router("/api/drug/saveinentorylist", &SelfDrugApiController{}, "Post:SaveInventoryList")
84 84
 
85 85
 	beego.Router("/api/drug/getdamagebydrugid", &SelfDrugApiController{}, "Get:GetDamageByDrugId")
86
+
87
+	beego.Router("/api/drug/getinventorymodelist", &SelfDrugApiController{}, "Get:GetInventoryModeList")
86 88
 }
87 89
 
88 90
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -1453,6 +1455,7 @@ func (this *SelfDrugApiController) GetDrugDamageList() {
1453 1455
 
1454 1456
 	limit, _ := this.GetInt64("limit")
1455 1457
 	page, _ := this.GetInt64("page")
1458
+
1456 1459
 	list, total, err := service.GetDrugDamageList(startTime, endTime, orgId, keyword, limit, page)
1457 1460
 
1458 1461
 	damagelist, _ := service.GetDrugDamageByOrgId(orgId)
@@ -2403,7 +2406,7 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2403 2406
 	fmt.Println(err)
2404 2407
 
2405 2408
 	tableData, _ := dataBody["tableData"].([]interface{})
2406
-	fmt.Println("999939433443", tableData)
2409
+
2407 2410
 	if len(tableData) > 0 {
2408 2411
 		for _, item := range tableData {
2409 2412
 			items := item.(map[string]interface{})
@@ -2488,6 +2491,9 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2488 2491
 				consumable_type = 10
2489 2492
 				consumable_count = new_total - ord_total
2490 2493
 			}
2494
+			fmt.Println("ord_total", ord_total)
2495
+			fmt.Println("new_total23323232323223", new_total)
2496
+			fmt.Println("consumable_count", consumable_count)
2491 2497
 
2492 2498
 			//改变库存
2493 2499
 			info := models.DrugWarehouseInfo{
@@ -2570,12 +2576,12 @@ func (this *SelfDrugApiController) SaveInventoryList() {
2570 2576
 				CancelOutDetailId:       0,
2571 2577
 				ExpireDate:              expiry_date,
2572 2578
 				ProductDate:             0,
2573
-				MaxUnit:                 max_unit,
2579
+				MaxUnit:                 min_unit,
2574 2580
 				MinUnit:                 min_unit,
2575 2581
 			}
2576
-
2577
-			service.CreateDrugFlowOne(flow)
2578
-
2582
+			if ord_total != new_total {
2583
+				service.CreateDrugFlowOne(flow)
2584
+			}
2579 2585
 			if err != nil {
2580 2586
 				this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
2581 2587
 				return
@@ -2603,3 +2609,20 @@ func (this *SelfDrugApiController) GetDamageByDrugId() {
2603 2609
 		"list": list,
2604 2610
 	})
2605 2611
 }
2612
+
2613
+func (this *SelfDrugApiController) GetInventoryModeList() {
2614
+
2615
+	orgId := this.GetAdminUserInfo().CurrentOrgId
2616
+
2617
+	list, err := service.GetInventoryModeList(orgId)
2618
+	manufacturerList, err := service.GetAllManufacturerList(orgId)
2619
+	if err != nil {
2620
+		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
2621
+		return
2622
+	}
2623
+
2624
+	this.ServeSuccessJSON(map[string]interface{}{
2625
+		"list":             list,
2626
+		"manufacturerList": manufacturerList,
2627
+	})
2628
+}

+ 471 - 98
controllers/stock_in_api_controller.go View File

@@ -128,7 +128,10 @@ func StockManagerApiRegistRouters() {
128 128
 	beego.Router("/api/stock/getgoodwarehouselist", &StockManagerApiController{}, "Get:GetGoodWarehouseList")
129 129
 	beego.Router("/api/stock/proofinventory", &StockManagerApiController{}, "Get:ProofInventory")
130 130
 	beego.Router("/api/stock/getwarehousetotal", &StockManagerApiController{}, "Get:GetWarehouseTotal")
131
-
131
+	beego.Router("/api/stock/getgoodinventorywarehouselist", &StockManagerApiController{}, "Get:GetGoodInventoryWarehouseList")
132
+	beego.Router("/api/stock/savestockinentorylist", &StockManagerApiController{}, "Post:SaveStockInventoryList")
133
+	beego.Router("/api/sotck/getdamagedetailbygoodid", &StockManagerApiController{}, "Get:GetDamageDetailByGoodId")
134
+	beego.Router("/api/stock/getinventoryexportlist", &StockManagerApiController{}, "Get:GetInventoryExportList")
132 135
 }
133 136
 
134 137
 func (c *StockManagerApiController) CreateWarehouse() {
@@ -573,32 +576,8 @@ func (c *StockManagerApiController) EditWarehouse() {
573 576
 					}
574 577
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
575 578
 
576
-					flow := &models.VmStockFlow{
577
-						WarehousingOrder:    warehousing.WarehousingOrder,
578
-						WarehousingId:       warehousing.ID,
579
-						GoodId:              good_id,
580
-						Number:              number,
581
-						ProductDate:         productDates,
582
-						ExpireDate:          expiryDates,
583
-						Count:               warehousing_count,
584
-						Price:               price,
585
-						Status:              1,
586
-						Ctime:               ctime,
587
-						UserOrgId:           adminUserInfo.CurrentOrgId,
588
-						Manufacturer:        manufacturer,
589
-						Dealer:              dealer,
590
-						LicenseNumber:       license_number,
591
-						IsEdit:              1,
592
-						Creator:             adminUserInfo.AdminUser.Id,
593
-						SystemTime:          ctime,
594
-						ConsumableType:      1,
595
-						WarehousingDetailId: warehouseInfo.ID,
596
-					}
597
-
598
-					stockFlow = append(stockFlow, flow)
599
-
600 579
 				} else {
601
-					fmt.Println("id23233232323232323232323223", id)
580
+
602 581
 					warehouseInfo := &models.WarehousingInfo{
603 582
 						ID:               id,
604 583
 						WarehousingOrder: warehouse.WarehousingOrder,
@@ -652,27 +631,116 @@ func (c *StockManagerApiController) EditWarehouse() {
652 631
 	var errs error
653 632
 	if len(warehousingInfo) > 0 {
654 633
 		errs = service.CreateWarehousingInfo(warehousingInfo)
655
-		service.CreateStockFlow(stockFlow)
634
+
635
+		for _, its := range warehousingInfo {
636
+			//查询
637
+			info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
638
+			flows := models.VmStockFlow{
639
+				WarehousingOrder:    info.WarehousingOrder,
640
+				WarehousingId:       info.ID,
641
+				GoodId:              info.GoodId,
642
+				Number:              info.Number,
643
+				ProductDate:         info.ProductDate,
644
+				ExpireDate:          info.ExpiryDate,
645
+				Count:               info.WarehousingCount,
646
+				Price:               info.Price,
647
+				Status:              1,
648
+				Ctime:               ctime,
649
+				UserOrgId:           adminUserInfo.CurrentOrgId,
650
+				Manufacturer:        info.Manufacturer,
651
+				Dealer:              info.Dealer,
652
+				LicenseNumber:       info.LicenseNumber,
653
+				IsEdit:              1,
654
+				Creator:             adminUserInfo.AdminUser.Id,
655
+				SystemTime:          ctime,
656
+				ConsumableType:      1,
657
+				WarehousingDetailId: info.ID,
658
+			}
659
+			_, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
660
+
661
+			if errcodescode == gorm.ErrRecordNotFound {
662
+				service.CreateStockFlowOne(flows)
663
+			}
664
+
665
+			//改变库存
666
+			good, _ := service.GetLastInfoMationById(info.GoodId)
667
+			warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
668
+			total, _ := strconv.ParseFloat(warhouseCount, 64)
669
+			goodInfo := models.GoodInfo{
670
+				Total: good.Total + total,
671
+			}
672
+			errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
673
+			fmt.Println(errcodescode)
674
+		}
656 675
 	}
657 676
 
658 677
 	if len(upDateWarehousingInfo) > 0 {
659 678
 
660 679
 		for _, item := range upDateWarehousingInfo {
661
-
662 680
 			var total int64
663
-			var all_total int64
664 681
 			//获取该批次该型号的库存
665 682
 			info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
666
-			fmt.Println("oooooooooo", info.WarehousingCount)
667
-			//判断 该批次的入库数量
668
-			total = item.WarehousingCount - info.WarehousingCount
669
-			fmt.Println("total232323322332232332", total)
670
-			all_total = info.StockCount + total
671 683
 
672
-			item.StockCount = all_total
673
-			fmt.Println("hhhhhhhhhhhhh", item.StockCount)
684
+			//增加库存
685
+			if item.WarehousingCount > info.WarehousingCount {
686
+
687
+				total = item.WarehousingCount - info.WarehousingCount
688
+				goodinfo := models.WarehousingInfo{
689
+					WarehousingCount: item.WarehousingCount,
690
+					StockCount:       info.StockCount + total,
691
+				}
692
+
693
+				service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
694
+				flowStock := models.VmStockFlow{
695
+					Count: item.WarehousingCount,
696
+				}
697
+				service.UpdatedStockFlowByGoodId(item.WarehousingId, item.GoodId, flowStock)
698
+				//改变库存
699
+				good, _ := service.GetLastInfoMationById(info.GoodId)
700
+				warhouseCount := strconv.FormatInt(total, 10)
701
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
702
+				goodInfo := models.GoodInfo{
703
+					Total: good.Total + all_total,
704
+				}
705
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
706
+
707
+			}
708
+
709
+			if item.WarehousingCount < info.WarehousingCount {
710
+
711
+				total = info.WarehousingCount - item.WarehousingCount
712
+				goodinfo := models.WarehousingInfo{
713
+					WarehousingCount: item.WarehousingCount,
714
+					StockCount:       info.StockCount - total,
715
+				}
716
+				service.UpdateWarehouseInfoByGoodId(goodinfo, item.ID)
717
+				//改变库存
718
+				good, _ := service.GetLastInfoMationById(info.GoodId)
719
+				warhouseCount := strconv.FormatInt(total, 10)
720
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
721
+				goodInfo := models.GoodInfo{
722
+					Total: good.Total - all_total,
723
+				}
724
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
725
+
726
+			}
727
+
728
+			if item.WarehousingCount == info.WarehousingCount {
729
+				goodinfo := models.WarehousingInfo{
730
+					WarehousingCount: item.WarehousingCount,
731
+					StockCount:       info.StockCount,
732
+					Price:            item.Price,
733
+					Manufacturer:     item.Manufacturer,
734
+					Number:           item.Number,
735
+					ProductDate:      item.ProductDate,
736
+					ExpiryDate:       item.ExpiryDate,
737
+					LicenseNumber:    item.LicenseNumber,
738
+					Dealer:           item.Dealer,
739
+					Remark:           item.Remark,
740
+				}
741
+				service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
742
+			}
674 743
 
675
-			errs = service.UpDateWarehousingInfo(item)
676 744
 		}
677 745
 	}
678 746
 
@@ -1190,7 +1258,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1190 1258
 
1191 1259
 				var productDate int64
1192 1260
 				if len(product_date) > 0 {
1193
-					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1261
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
1194 1262
 					if err != nil {
1195 1263
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1196 1264
 						return
@@ -1241,14 +1309,13 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1241 1309
 
1242 1310
 	//出库逻辑
1243 1311
 	for _, item := range warehousingOutInfo {
1244
-		//查询库存
1245
-		//warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1246
-		//查询该批次的库存
1247 1312
 
1248
-		warehouseOne, _ := service.FindWarehousingInfoByIdSeven(item.WarehouseInfotId)
1249
-		fmt.Println("数据232323232323232323323232", warehouseOne)
1250
-		fmt.Println("库存查询23322332233232233232322323232323", warehouseOne.StockCount)
1313
+		// 查询该耗材是否有库存
1314
+		warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
1315
+		fmt.Println("hhh2333223223", item.GoodId, item.Count, warehouseOne.StockCount)
1316
+		// 如果出库数量大于该批次剩余库存数量
1251 1317
 		if item.Count > warehouseOne.StockCount {
1318
+
1252 1319
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1253 1320
 			c.ServeSuccessJSON(map[string]interface{}{
1254 1321
 				"msg":                "1",
@@ -1257,31 +1324,30 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1257 1324
 			})
1258 1325
 			return
1259 1326
 
1260
-		} else {
1261
-
1262
-			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1263
-			if errcodes == gorm.ErrRecordNotFound {
1264
-				service.AddSigleWarehouseOut(&warehouseOut)
1265
-			}
1266
-			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1267
-			if parseDateErr != nil {
1268
-				utils.ErrorLog(parseDateErr.Error())
1269
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1270
-				return
1271
-			}
1272
-
1273
-			c.ServeSuccessJSON(map[string]interface{}{
1274
-				"msg":                "2",
1275
-				"good_name":          "",
1276
-				"specification_name": "",
1277
-			})
1278 1327
 		}
1279
-
1280 1328
 	}
1281 1329
 
1282
-	//errs := service.CreateWarehousingOutInfo(warehousingOutInfo)
1283
-	//info, _ := service.FindLastWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1330
+	for _, it := range warehousingOutInfo {
1331
+		//查询是否生成出库单
1332
+		_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1333
+		if errcodes == gorm.ErrRecordNotFound {
1334
+			service.AddSigleWarehouseOut(&warehouseOut)
1335
+		}
1336
+		//出库逻辑
1337
+		parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), it, &warehouseOut, it.Count, creater)
1338
+		if parseDateErr != nil {
1339
+			utils.ErrorLog(parseDateErr.Error())
1340
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1341
+			return
1342
+		}
1284 1343
 
1344
+		c.ServeSuccessJSON(map[string]interface{}{
1345
+			"msg":                "2",
1346
+			"good_name":          "",
1347
+			"specification_name": "",
1348
+		})
1349
+		return
1350
+	}
1285 1351
 }
1286 1352
 func (c *StockManagerApiController) GetWarehouseOutList() {
1287 1353
 	page, _ := c.GetInt64("page", -1)
@@ -1395,7 +1461,6 @@ func (c *StockManagerApiController) GetWarehouseOutInfoList() {
1395 1461
 }
1396 1462
 func (c *StockManagerApiController) EditWarehouseOut() {
1397 1463
 	warehouse_out_time := c.GetString("warehouse_out_time")
1398
-
1399 1464
 	id, _ := c.GetInt64("id", 0)
1400 1465
 	types, _ := c.GetInt64("type", 0)
1401 1466
 
@@ -1509,7 +1574,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1509 1574
 
1510 1575
 				var productDate int64
1511 1576
 				if len(product_date) > 0 {
1512
-					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", expiry_date+" 00:00:00", loc)
1577
+					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
1513 1578
 					if err != nil {
1514 1579
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1515 1580
 						return
@@ -1591,18 +1656,50 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1591 1656
 		}
1592 1657
 	}
1593 1658
 	var errs error
1659
+	//新增出库
1594 1660
 	if len(warehousingOutInfo) > 0 {
1595 1661
 
1596
-		errs = service.CreateWarehousingOutInfo(warehousingOutInfo)
1662
+		warehousingOutDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehouse_out_time)
1663
+		if parseDateErr != nil {
1664
+			c.ErrorLog("日期(%v)解析错误:%v", warehousingOutDate, parseDateErr)
1665
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1666
+			return
1667
+		}
1668
+		creater := adminUserInfo.AdminUser.Id
1669
+
1670
+		for _, item := range warehousingOutInfo {
1671
+			// 查询该耗材是否有库存
1672
+			warehouseOne, _ := service.FindWarehousingInfoTen(item.GoodId)
1673
+			// 如果出库数量大于该批次剩余库存数量
1674
+			if item.Count > warehouseOne.StockCount {
1675
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1676
+				c.ServeSuccessJSON(map[string]interface{}{
1677
+					"msg":                "7",
1678
+					"good_name":          goodObj.GoodName,
1679
+					"specification_name": goodObj.SpecificationName,
1680
+				})
1681
+				return
1682
+
1683
+			} else {
1684
+
1685
+				warehouseOut, _ := service.GetWarehouseById(id)
1686
+
1687
+				//出库逻辑
1688
+				parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count, creater)
1689
+				if parseDateErr != nil {
1690
+					utils.ErrorLog(parseDateErr.Error())
1691
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1692
+					return
1693
+				}
1694
+			}
1695
+		}
1597 1696
 	}
1598 1697
 
1599 1698
 	if len(upDateWarehouseOutInfos) > 0 {
1600 1699
 		for _, item := range upDateWarehouseOutInfos {
1601
-
1700
+			fmt.Println("item2332323232323", item.ProductDate, item.ExpiryDate)
1602 1701
 			//1.查询该耗材该批次的最后一次出库记录
1603
-			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
1604
-			fmt.Println("lastGood", lastGood.Count)
1605
-			fmt.Println("item2323232", item.Count)
1702
+			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId)
1606 1703
 
1607 1704
 			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1608 1705
 			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
@@ -1611,7 +1708,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1611 1708
 
1612 1709
 				//查询该耗材是否还有库存
1613 1710
 				warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId)
1614
-				fmt.Println("hhhhhh23h2323232", warehouseinfo.StockCount)
1711
+
1615 1712
 				//无库存
1616 1713
 				if warehouseinfo.StockCount <= 0 {
1617 1714
 					c.ServeSuccessJSON(map[string]interface{}{
@@ -1627,10 +1724,10 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1627 1724
 					var total_count int64
1628 1725
 					//计算和最后一次出库数据的差
1629 1726
 					total = item.Count - lastGood.Count
1630
-					fmt.Println("total22323232", total)
1727
+
1631 1728
 					//获取该耗材该批次的剩余库存量
1632 1729
 					info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1633
-					fmt.Println("info2232323232323", info)
1730
+
1634 1731
 					//判断该批次的剩余库存 和出库的库存进行比较
1635 1732
 					//如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
1636 1733
 
@@ -1640,12 +1737,20 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1640 1737
 						//清空本批次次库存
1641 1738
 						service.DeleteWarehouseInfo(item.WarehouseInfotId)
1642 1739
 						//调用出库逻辑
1643
-						service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1740
+						parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
1741
+						if parseDateErr != nil {
1742
+							utils.ErrorLog(errs.Error())
1743
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1744
+							return
1745
+						}
1746
+						c.ServeSuccessJSON(map[string]interface{}{
1747
+							"msg": "1",
1748
+						})
1644 1749
 					}
1645 1750
 					//如果出库的库存小于或等于于该批次的剩余库存,那么需要该批次出库
1646 1751
 					if item.Count <= info.StockCount {
1647 1752
 						stock_cout = lastGood.Count + total
1648
-						fmt.Println("232323223232323232323232", stock_cout)
1753
+						fmt.Println(stock_cout)
1649 1754
 						//扣减库存
1650 1755
 						warehouse := models.WarehousingInfo{
1651 1756
 							StockCount: info.StockCount - total,
@@ -1688,8 +1793,13 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1688 1793
 							c.ServeSuccessJSON(map[string]interface{}{
1689 1794
 								"msg": "1",
1690 1795
 							})
1796
+							return
1691 1797
 						} else if errcode == nil {
1692 1798
 							service.UpDateWarehouseOutInfo(item)
1799
+							c.ServeSuccessJSON(map[string]interface{}{
1800
+								"msg": "1",
1801
+							})
1802
+							return
1693 1803
 						}
1694 1804
 
1695 1805
 					}
@@ -1701,31 +1811,30 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1701 1811
 			var stock_total int64
1702 1812
 			//如果退库数量小于最后一次批次的数量(要么要进行退库)
1703 1813
 			if item.Count < lastGood.Count {
1704
-				fmt.Println("hh232323h2h3hh23hh23hh2h3h23")
1814
+
1705 1815
 				//退库数量和最后一次出库数据进行计算
1706 1816
 				last_count = lastGood.Count - item.Count
1707
-				fmt.Println("last_count", last_count)
1817
+
1708 1818
 				//获取该耗材该批次的剩余库存量
1709 1819
 				infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
1710 1820
 
1711 1821
 				//退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
1712 1822
 				all_total = last_count + infoInfo.StockCount
1713
-				fmt.Println("all_total", all_total)
1823
+
1714 1824
 				//如果库存大于总数量,则退回到这个批次
1715
-				fmt.Println("inf232323", infoInfo.WarehousingCount)
1716 1825
 
1717 1826
 				if infoInfo.WarehousingCount > all_total {
1718 1827
 					stock_total = last_count + infoInfo.StockCount
1719
-					fmt.Println("经历323232323232232", last_count, stock_total)
1828
+
1720 1829
 					//退回该批次,计算数量
1721 1830
 					warehousingInfoOne := models.WarehousingInfo{
1722 1831
 						StockCount: stock_total,
1723 1832
 						ID:         item.WarehouseInfotId,
1724 1833
 						OrgId:      item.OrgId,
1725 1834
 					}
1726
-					fmt.Println("********************", warehousingInfoOne, item.WarehouseInfotId)
1835
+
1727 1836
 					parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
1728
-					fmt.Println("parseDateErr2323232322323", parseDateErr)
1837
+					fmt.Println("parseDateErr", parseDateErr)
1729 1838
 					//插入一条新纪录
1730 1839
 					warehouseOutInfoThree := &models.WarehouseOutInfo{
1731 1840
 						WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
@@ -1761,8 +1870,10 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1761 1870
 						c.ServeSuccessJSON(map[string]interface{}{
1762 1871
 							"msg": "1",
1763 1872
 						})
1873
+						return
1764 1874
 					} else if errcode == nil {
1765 1875
 						service.UpDateWarehouseOutInfo(item)
1876
+						return
1766 1877
 					}
1767 1878
 				}
1768 1879
 
@@ -1776,6 +1887,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1776 1887
 			}
1777 1888
 
1778 1889
 			if item.Count == lastGood.Count {
1890
+
1779 1891
 				errs = service.UpDateWarehouseOutInfo(item)
1780 1892
 				if errs != nil {
1781 1893
 					utils.ErrorLog(errs.Error())
@@ -1785,6 +1897,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1785 1897
 				c.ServeSuccessJSON(map[string]interface{}{
1786 1898
 					"msg": "1",
1787 1899
 				})
1900
+				return
1788 1901
 			}
1789 1902
 
1790 1903
 		}
@@ -1981,7 +2094,9 @@ func (c *StockManagerApiController) CreateCancelStock() {
1981 2094
 	for _, item := range cancelStockInfos {
1982 2095
 
1983 2096
 		//统计该批次耗材的出库数量
1984
-		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
2097
+		//info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
2098
+
2099
+		info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId)
1985 2100
 		fmt.Println("2333223323322332233223322323", item.Count, info.Count)
1986 2101
 		if item.Count > info.Count {
1987 2102
 			service.UpdateCancelInfo(item.CancelStockId)
@@ -2007,10 +2122,11 @@ func (c *StockManagerApiController) CreateCancelStock() {
2007 2122
 				service.AddSigleCancelStock(&cancelStock)
2008 2123
 			}
2009 2124
 			listcancel, _ := service.GetLastCancelStockById(adminUserInfo.CurrentOrgId)
2010
-			for _, it := range cancelStockInfos {
2011
-				it.CancelStockId = listcancel.ID
2012
-			}
2013
-			errs := service.CreateCancelStockInfo(cancelStockInfos)
2125
+
2126
+			fmt.Println("2332323232323232323", cancelStockInfos)
2127
+			item.CancelStockId = listcancel.ID
2128
+			errs := service.CreateCancelStockInfoOne(item)
2129
+
2014 2130
 			if len(stockFLow) > 0 {
2015 2131
 				service.CreateStockFlow(stockFLow)
2016 2132
 			}
@@ -2030,7 +2146,11 @@ func (c *StockManagerApiController) CreateCancelStock() {
2030 2146
 			}
2031 2147
 			//更改入库数量
2032 2148
 			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
2033
-			break
2149
+			if err != nil {
2150
+				utils.ErrorLog(err.Error())
2151
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2152
+				return
2153
+			}
2034 2154
 		}
2035 2155
 	}
2036 2156
 
@@ -2378,7 +2498,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2378 2498
 
2379 2499
 		for _, item := range cancelStockInfos {
2380 2500
 			//统计该耗材的出库数量
2381
-			info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId, item.WarehouseInfoId)
2501
+			info, _ := service.GetWarehoureOrderStockOutFlow(item.GoodId, item.OrgId, item.WarehouseInfoId)
2382 2502
 			if item.Count > info.Count {
2383 2503
 				c.ServeSuccessJSON(map[string]interface{}{
2384 2504
 					"msg": "2",
@@ -4356,7 +4476,6 @@ func (this *StockManagerApiController) GetAllStockList() {
4356 4476
 	orgId := adminUserInfo.CurrentOrgId
4357 4477
 
4358 4478
 	list, total, _ := service.GetAllGoodInfoStockList(page, limit, startTime, endTime, types, keywords, orgId)
4359
-	fmt.Println("耗材总计23323232232323232323", total)
4360 4479
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
4361 4480
 	this.ServeSuccessJSON(map[string]interface{}{
4362 4481
 		"list":             list,
@@ -4493,13 +4612,9 @@ func (this *StockManagerApiController) GetOrderDetialByOrderId() {
4493 4612
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4494 4613
 	order, _ := service.GetWarehouseOutOrder(idsArray, orgId)
4495 4614
 	list, _ := service.GetOrderDetialByOrderIdOne(idsArray, orgId)
4496
-	//获取该耗材的最后一条数据
4497
-	info, _ := service.GetLastWarehouseOutInfo(idsArray, orgId)
4498
-	fmt.Println("info323e2342342342432342342432", info)
4499 4615
 	this.ServeSuccessJSON(map[string]interface{}{
4500
-		"order": order,
4501 4616
 		"list":  list,
4502
-		"info":  info,
4617
+		"order": order,
4503 4618
 	})
4504 4619
 }
4505 4620
 
@@ -5236,13 +5351,17 @@ func (this *StockManagerApiController) GetReportStockList() {
5236 5351
 	orgId := this.GetAdminUserInfo().CurrentOrgId
5237 5352
 	keyword := this.GetString("keyword")
5238 5353
 	fmt.Println("startTime", startTime, "endTime", endTime)
5239
-	list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
5354
+	//list, total, _ := service.GetReportStockList(startTime, endTime, orgId, keyword, page, limit)
5355
+
5356
+	list, total, _ := service.GetStockDamagedList(orgId, keyword, page, limit, startTime, endTime)
5357
+	damageList, _ := service.GetStockDamagedCount(orgId)
5240 5358
 	doctorlist, _ := service.GetAllDoctorThree(orgId)
5241 5359
 
5242 5360
 	this.ServeSuccessJSON(map[string]interface{}{
5243 5361
 		"list":       list,
5244 5362
 		"total":      total,
5245 5363
 		"doctorlist": doctorlist,
5364
+		"damageList": damageList,
5246 5365
 	})
5247 5366
 }
5248 5367
 
@@ -6146,3 +6265,257 @@ func (this *StockManagerApiController) GetWarehouseTotal() {
6146 6265
 		"list": list,
6147 6266
 	})
6148 6267
 }
6268
+
6269
+func (this *StockManagerApiController) GetGoodInventoryWarehouseList() {
6270
+
6271
+	id, _ := this.GetInt64("id")
6272
+	list, _ := service.GetGoodInventoryWarehouseList(id)
6273
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6274
+	fmt.Println(orgId)
6275
+	this.ServeSuccessJSON(map[string]interface{}{
6276
+		"list": list,
6277
+	})
6278
+}
6279
+
6280
+func (this *StockManagerApiController) SaveStockInventoryList() {
6281
+
6282
+	dataBody := make(map[string]interface{}, 0)
6283
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
6284
+	fmt.Println(err)
6285
+
6286
+	tableData, _ := dataBody["tableData"].([]interface{})
6287
+
6288
+	if len(tableData) > 0 {
6289
+		for _, item := range tableData {
6290
+			items := item.(map[string]interface{})
6291
+			good_name := items["good_name"].(string)
6292
+			if items["good_name"] == nil || reflect.TypeOf(items["good_name"]).String() != "string" {
6293
+				utils.ErrorLog("good_name")
6294
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6295
+				return
6296
+			}
6297
+
6298
+			specification_name := items["specification_name"].(string)
6299
+			if items["specification_name"] == nil || reflect.TypeOf(items["specification_name"]).String() != "string" {
6300
+				utils.ErrorLog("specification_name")
6301
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6302
+				return
6303
+			}
6304
+
6305
+			warehousing_unit := items["warehousing_unit"].(string)
6306
+			if items["warehousing_unit"] == nil || reflect.TypeOf(items["warehousing_unit"]).String() != "string" {
6307
+				utils.ErrorLog("warehousing_unit")
6308
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6309
+				return
6310
+			}
6311
+
6312
+			stock_count := int64(items["stock_count"].(float64))
6313
+			if items["stock_count"] == nil || reflect.TypeOf(items["stock_count"]).String() != "float64" {
6314
+				utils.ErrorLog("stock_count")
6315
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6316
+				return
6317
+			}
6318
+
6319
+			price := items["price"].(float64)
6320
+			if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "float64" {
6321
+				utils.ErrorLog("price")
6322
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6323
+				return
6324
+			}
6325
+
6326
+			manufacturer_name := items["manufacturer_name"].(string)
6327
+			if items["manufacturer_name"] == nil || reflect.TypeOf(items["manufacturer_name"]).String() != "string" {
6328
+				utils.ErrorLog("manufacturer_name")
6329
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6330
+				return
6331
+			}
6332
+
6333
+			good_id := int64(items["good_id"].(float64))
6334
+			if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
6335
+				utils.ErrorLog("good_id")
6336
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6337
+				return
6338
+			}
6339
+
6340
+			manufacturer := int64(items["manufacturer"].(float64))
6341
+			if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
6342
+				utils.ErrorLog("manufacturer")
6343
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6344
+				return
6345
+			}
6346
+
6347
+			warehousing_order := items["warehousing_order"].(string)
6348
+			if items["warehousing_order"] == nil || reflect.TypeOf(items["warehousing_order"]).String() != "string" {
6349
+				utils.ErrorLog("warehousing_order")
6350
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6351
+				return
6352
+			}
6353
+
6354
+			number := items["number"].(string)
6355
+			if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
6356
+				utils.ErrorLog("number")
6357
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6358
+				return
6359
+			}
6360
+
6361
+			id := int64(items["id"].(float64))
6362
+			if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
6363
+				utils.ErrorLog("id")
6364
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6365
+				return
6366
+			}
6367
+
6368
+			if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "float64" {
6369
+				utils.ErrorLog("expiry_date")
6370
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6371
+				return
6372
+			}
6373
+			expiry_date := int64(items["expiry_date"].(float64))
6374
+
6375
+			if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "float64" {
6376
+				utils.ErrorLog("product_date")
6377
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6378
+				return
6379
+			}
6380
+			product_date := int64(items["product_date"].(float64))
6381
+
6382
+			orgId := this.GetAdminUserInfo().CurrentOrgId
6383
+			adminId := this.GetAdminUserInfo().AdminUser.Id
6384
+
6385
+			stock_type := int64(items["type"].(float64))
6386
+			if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
6387
+				utils.ErrorLog("type")
6388
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6389
+				return
6390
+			}
6391
+
6392
+			last_stock_count := int64(items["last_stock_count"].(float64))
6393
+			if items["last_stock_count"] == nil || reflect.TypeOf(items["last_stock_count"]).String() != "float64" {
6394
+				utils.ErrorLog("last_stock_count")
6395
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6396
+				return
6397
+			}
6398
+			var total_count int64
6399
+			var inventory_type int64
6400
+			fmt.Println("盘点前", stock_count)
6401
+			fmt.Println("盘点后", last_stock_count)
6402
+			if stock_count > last_stock_count {
6403
+				total_count = stock_count - last_stock_count
6404
+				inventory_type = 11
6405
+			}
6406
+			if stock_count < last_stock_count {
6407
+				total_count = last_stock_count - stock_count
6408
+				inventory_type = 10
6409
+			}
6410
+
6411
+			creater := this.GetAdminUserInfo().AdminUser.Id
6412
+			inventory := models.XtStockInventory{
6413
+				GoodName:          good_name,
6414
+				SpecificationName: specification_name,
6415
+				WarehousingUnit:   warehousing_unit,
6416
+				Count:             total_count,
6417
+				BuyPrice:          price,
6418
+				PackingPrice:      price,
6419
+				NewPrice:          0,
6420
+				Manufacturer:      manufacturer_name,
6421
+				Dealer:            "",
6422
+				Remark:            "",
6423
+				GoodId:            good_id,
6424
+				UserOrgId:         orgId,
6425
+				Ctime:             time.Now().Unix(),
6426
+				Mtime:             0,
6427
+				Status:            1,
6428
+				WarehousingOrder:  warehousing_order,
6429
+				LicenseNumber:     number,
6430
+				StartTime:         time.Now().Unix(),
6431
+				Creater:           adminId,
6432
+				Checker:           0,
6433
+				CheckerStatus:     0,
6434
+				CheckerTime:       0,
6435
+				Total:             0,
6436
+				Number:            number,
6437
+				WarehousingInfoId: id,
6438
+				ExpireDate:        expiry_date,
6439
+				ProductDate:       product_date,
6440
+				GoodOriginPlace:   "",
6441
+				Type:              10,
6442
+				InventoryType:     stock_type,
6443
+				LastStockCount:    last_stock_count,
6444
+				StockCount:        stock_count,
6445
+			}
6446
+			service.CreateInentory(inventory)
6447
+
6448
+			stockFlow := models.VmStockFlow{
6449
+				WarehousingId:           0,
6450
+				GoodId:                  good_id,
6451
+				Number:                  number,
6452
+				LicenseNumber:           "",
6453
+				Count:                   total_count,
6454
+				UserOrgId:               orgId,
6455
+				PatientId:               0,
6456
+				SystemTime:              0,
6457
+				ConsumableType:          inventory_type,
6458
+				IsSys:                   0,
6459
+				WarehousingOrder:        "",
6460
+				WarehouseOutId:          0,
6461
+				WarehouseOutOrderNumber: warehousing_order,
6462
+				IsEdit:                  0,
6463
+				CancelStockId:           0,
6464
+				CancelOrderNumber:       "",
6465
+				Manufacturer:            manufacturer,
6466
+				Dealer:                  0,
6467
+				Creator:                 creater,
6468
+				UpdateCreator:           0,
6469
+				Status:                  1,
6470
+				Ctime:                   time.Now().Unix(),
6471
+				Mtime:                   0,
6472
+				Price:                   price,
6473
+				WarehousingDetailId:     0,
6474
+				WarehouseOutDetailId:    0,
6475
+				CancelOutDetailId:       0,
6476
+				ProductDate:             product_date,
6477
+				ExpireDate:              expiry_date,
6478
+				ReturnCount:             0,
6479
+			}
6480
+
6481
+			info := models.WarehousingInfo{
6482
+				StockCount: last_stock_count,
6483
+			}
6484
+			//更改库存
6485
+			service.UpdatedWarehousingInfo(info, id)
6486
+			if stock_count != last_stock_count {
6487
+				service.CreateStockFlowOne(stockFlow)
6488
+			}
6489
+			this.ServeSuccessJSON(map[string]interface{}{
6490
+				"inventory": inventory,
6491
+			})
6492
+		}
6493
+	}
6494
+}
6495
+
6496
+func (this *StockManagerApiController) GetDamageDetailByGoodId() {
6497
+
6498
+	good_id, _ := this.GetInt64("good_id")
6499
+	warehousing_order := this.GetString("warehousing_order")
6500
+	inventory_type, _ := this.GetInt64("type")
6501
+	fmt.Println("inventory_type23232323223322332", inventory_type)
6502
+	list, _ := service.GetDamageDetailByGoodId(good_id, warehousing_order, inventory_type)
6503
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6504
+	damageList, _ := service.GetStockDamagedCountOne(orgId, warehousing_order, inventory_type)
6505
+	this.ServeSuccessJSON(map[string]interface{}{
6506
+		"list":       list,
6507
+		"damageList": damageList,
6508
+	})
6509
+}
6510
+
6511
+func (this *StockManagerApiController) GetInventoryExportList() {
6512
+
6513
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6514
+
6515
+	list, _ := service.GetInventoryExportList(orgId)
6516
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
6517
+	this.ServeSuccessJSON(map[string]interface{}{
6518
+		"list":             list,
6519
+		"manufacturerList": manufacturerList,
6520
+	})
6521
+}

+ 2 - 0
models/common_models.go View File

@@ -294,6 +294,8 @@ type BloodDialysisPrescription struct {
294 294
 	PunctureNeedleCount        float64 `gorm:"column:puncture_needle_count" json:"puncture_needle_count" form:"puncture_needle_count"`
295 295
 	Epo                        string  `gorm:"column:epo" json:"epo" form:"epo"`
296 296
 	EpoCount                   float64 `gorm:"column:epo_count" json:"epo_count" form:"epo_count"`
297
+	DialysisDialyszers         string  `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
298
+	DialysisIrrigation         string  `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
297 299
 }
298 300
 
299 301
 func (BloodDialysisPrescription) TableName() string {

+ 76 - 21
models/device_models.go View File

@@ -140,15 +140,16 @@ func (DeviceGroup) TableName() string {
140 140
 }
141 141
 
142 142
 type DeviceNumber struct {
143
-	ID         int64  `gorm:"column:id" json:"id"`
144
-	OrgID      int64  `gorm:"column:org_id" json:"-"`
145
-	Number     string `gorm:"column:number" json:"number"`
146
-	GroupID    int64  `gorm:"column:group_id" json:"group_id"`
147
-	ZoneID     int64  `gorm:"column:zone_id" json:"zone_id"`
148
-	Status     int8   `json:"-"`
149
-	CreateTime int64  `gorm:"column:ctime" json:"-"`
150
-	ModifyTime int64  `gorm:"column:mtime" json:"-"`
151
-	Sort       int64  `gorm:"column:sort" json:"sort" form:"sort"`
143
+	ID         int64      `gorm:"column:id" json:"id"`
144
+	OrgID      int64      `gorm:"column:org_id" json:"-"`
145
+	Number     string     `gorm:"column:number" json:"number"`
146
+	GroupID    int64      `gorm:"column:group_id" json:"group_id"`
147
+	ZoneID     int64      `gorm:"column:zone_id" json:"zone_id"`
148
+	Status     int8       `json:"-"`
149
+	CreateTime int64      `gorm:"column:ctime" json:"-"`
150
+	ModifyTime int64      `gorm:"column:mtime" json:"-"`
151
+	Sort       int64      `gorm:"column:sort" json:"sort" form:"sort"`
152
+	DeviceZone DeviceZone `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:ZoneID;"`
152 153
 }
153 154
 
154 155
 func (DeviceNumber) TableName() string {
@@ -403,18 +404,19 @@ type Schedules struct {
403 404
 }
404 405
 
405 406
 type XtSchedule struct {
406
-	ID           int64 `gorm:"column:id" json:"id" form:"id"`
407
-	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
408
-	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
409
-	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
410
-	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
411
-	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
412
-	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
413
-	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
414
-	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
415
-	Status       int64 `gorm:"column:status" json:"status" form:"status"`
416
-	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
417
-	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
407
+	ID              int64                   `gorm:"column:id" json:"id" form:"id"`
408
+	UserOrgId       int64                   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
409
+	PartitionId     int64                   `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
410
+	BedId           int64                   `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
411
+	PatientId       int64                   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
412
+	ScheduleDate    int64                   `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
413
+	ScheduleType    int64                   `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
414
+	ScheduleWeek    int64                   `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
415
+	ModeId          int64                   `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
416
+	Status          int64                   `gorm:"column:status" json:"status" form:"status"`
417
+	CreatedTime     int64                   `gorm:"column:created_time" json:"created_time" form:"created_time"`
418
+	UpdatedTime     int64                   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
419
+	LastAfterWeight AssessmentAfterDislysis `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
418 420
 }
419 421
 
420 422
 func (XtSchedule) TableName() string {
@@ -1065,3 +1067,56 @@ type VmXtSchedule struct {
1065 1067
 	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
1066 1068
 	Count        int64
1067 1069
 }
1070
+
1071
+type PatientDeviceNumber struct {
1072
+	ID         int64           `gorm:"column:id" json:"id" form:"id"`
1073
+	OrgId      int64           `gorm:"column:org_id" json:"org_id" form:"org_id"`
1074
+	Number     string          `gorm:"column:number" json:"number" form:"number"`
1075
+	GroupId    int64           `gorm:"column:group_id" json:"group_id" form:"group_id"`
1076
+	ZoneId     int64           `gorm:"column:zone_id" json:"zone_id" form:"zone_id"`
1077
+	Status     int64           `gorm:"column:status" json:"status" form:"status"`
1078
+	Ctime      int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
1079
+	Mtime      int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
1080
+	Sort       int64           `gorm:"column:sort" json:"sort" form:"sort"`
1081
+	DeviceZone DeviceZone      `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:ZoneId;"`
1082
+	Schedule   []*BlodSchedule `json:"schedule" gorm:"foreignkey:BedId;AssociationForeignKey:ID;"`
1083
+}
1084
+
1085
+func (PatientDeviceNumber) TableName() string {
1086
+
1087
+	return "xt_device_number"
1088
+}
1089
+
1090
+type PatientDialysisOrder struct {
1091
+	ID                     int64  `gorm:"column:id" json:"id" form:"id"`
1092
+	DialysisDate           int64  `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
1093
+	UserOrgId              int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1094
+	PatientId              int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1095
+	PrescriptionId         int64  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
1096
+	Stage                  int64  `gorm:"column:stage" json:"stage" form:"stage"`
1097
+	Remark                 string `gorm:"column:remark" json:"remark" form:"remark"`
1098
+	BedId                  int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
1099
+	StartNurse             int64  `gorm:"column:start_nurse" json:"start_nurse" form:"start_nurse"`
1100
+	FinishNurse            int64  `gorm:"column:finish_nurse" json:"finish_nurse" form:"finish_nurse"`
1101
+	Status                 int64  `gorm:"column:status" json:"status" form:"status"`
1102
+	CreatedTime            int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
1103
+	UpdatedTime            int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1104
+	PunctureNurse          int64  `gorm:"column:puncture_nurse" json:"puncture_nurse" form:"puncture_nurse"`
1105
+	Creator                int64  `gorm:"column:creator" json:"creator" form:"creator"`
1106
+	Modifier               int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
1107
+	FinishCreator          int64  `gorm:"column:finish_creator" json:"finish_creator" form:"finish_creator"`
1108
+	FinishModifier         int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
1109
+	SchedualType           int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
1110
+	StartTime              int64  `gorm:"column:start_time" json:"start_time" form:"start_time"`
1111
+	EndTime                int64  `gorm:"column:end_time" json:"end_time" form:"end_time"`
1112
+	WashpipeNurse          int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
1113
+	ChangeNurse            int64  `gorm:"column:change_nurse" json:"change_nurse" form:"change_nurse"`
1114
+	DifficultPunctureNurse int64  `gorm:"column:difficult_puncture_nurse" json:"difficult_puncture_nurse" form:"difficult_puncture_nurse"`
1115
+	NewFistulaNurse        int64  `gorm:"column:new_fistula_nurse" json:"new_fistula_nurse" form:"new_fistula_nurse"`
1116
+	ZoneId                 int64  `gorm:"column:zone_id" json:"zone_id" form:"zone_id"`
1117
+}
1118
+
1119
+func (PatientDialysisOrder) TableName() string {
1120
+
1121
+	return "xt_dialysis_order"
1122
+}

+ 58 - 2
models/dialysis.go View File

@@ -862,8 +862,8 @@ type XtDialysisOrders struct {
862 862
 	FinishCreator  int64  `gorm:"column:finish_creator" json:"finish_creator" form:"finish_creator"`
863 863
 	FinishModifier int64  `gorm:"column:finish_modifier" json:"finish_modifier" form:"finish_modifier"`
864 864
 	SchedualType   int64  `gorm:"column:schedual_type" json:"schedual_type" form:"schedual_type"`
865
-	Number         int64  `gorm:"column:number" json:"number" form:"number"`
866
-	UserName       int64  `gorm:"column:user_name" json:"user_name" form:"user_name"`
865
+	Number         string `gorm:"column:number" json:"number" form:"number"`
866
+	UserName       string `gorm:"column:user_name" json:"user_name" form:"user_name"`
867 867
 	WashpipeNurse  int64  `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
868 868
 	ModeId         int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
869 869
 }
@@ -1093,3 +1093,59 @@ type BloodDoctorAdvice struct {
1093 1093
 	DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
1094 1094
 	Total       int64
1095 1095
 }
1096
+
1097
+type HisDoctorAdvice struct {
1098
+	ID                    int64              `gorm:"column:id" json:"id" form:"id"`
1099
+	GroupNo               int64              `gorm:"column:groupno" json:"groupno" form:"groupno"`
1100
+	UserOrgId             int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1101
+	PatientId             int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1102
+	AdviceType            int64              `gorm:"column:advice_type" json:"advice_type" form:"advice_type"`
1103
+	AdviceDate            int64              `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
1104
+	StartTime             int64              `gorm:"column:start_time" json:"start_time" form:"start_time"`
1105
+	AdviceName            string             `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
1106
+	AdviceDesc            string             `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
1107
+	ReminderDate          int64              `gorm:"column:reminder_date" json:"reminder_date" form:"reminder_date"`
1108
+	SingleDose            float64            `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
1109
+	SingleDoseUnit        string             `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
1110
+	DrugSpec              float64            `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
1111
+	DrugSpecUnit          string             `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
1112
+	PrescribingNumber     float64            `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
1113
+	PrescribingNumberUnit string             `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
1114
+	DeliveryWay           string             `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
1115
+	ExecutionFrequency    string             `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
1116
+	AdviceDoctor          int64              `gorm:"column:advice_doctor" json:"advice_doctor" form:"advice_doctor"`
1117
+	Status                int64              `gorm:"column:status" json:"status" form:"status"`
1118
+	CreatedTime           int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
1119
+	UpdatedTime           int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1120
+	AdviceAffirm          string             `gorm:"column:advice_affirm" json:"advice_affirm" form:"advice_affirm"`
1121
+	Remark                string             `gorm:"column:remark" json:"remark" form:"remark"`
1122
+	StopTime              int64              `gorm:"column:stop_time" json:"stop_time" form:"stop_time"`
1123
+	StopReason            string             `gorm:"column:stop_reason" json:"stop_reason" form:"stop_reason"`
1124
+	StopDoctor            int64              `gorm:"column:stop_doctor" json:"stop_doctor" form:"stop_doctor"`
1125
+	StopState             int64              `gorm:"column:stop_state" json:"stop_state" form:"stop_state"`
1126
+	ParentId              int64              `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
1127
+	ExecutionTime         int64              `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
1128
+	ExecutionStaff        int64              `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
1129
+	ExecutionState        int64              `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
1130
+	Checker               int64              `gorm:"column:checker" json:"checker" form:"checker"`
1131
+	RecordDate            int64              `gorm:"column:record_date" json:"record_date"`
1132
+	DialysisOrderId       int64              `gorm:"column:dialysis_order_id" json:"dialysis_order_id"`
1133
+	CheckTime             int64              `gorm:"column:check_time" json:"check_time" form:"check_time"`
1134
+	CheckState            int64              `gorm:"column:check_state" json:"check_state" form:"check_state"`
1135
+	AdviceId              int64              `gorm:"-"`
1136
+	RemindType            int64              `gorm:"column:remind_type" json:"remind_type"`
1137
+	FrequencyType         int64              `gorm:"column:frequency_type" json:"frequency_type"`
1138
+	DayCount              int64              `gorm:"column:day_count" json:"day_count"`
1139
+	WeekDay               string             `gorm:"column:week_day" json:"week_day"`
1140
+	ChildDoctorAdvice     []*HisDoctorAdvice `gorm:"ForeignKey:ParentId;AssociationForeignKey:ID" json:"child"`
1141
+	TemplateId            string             `gorm:"column:template_id" json:"template_id"`
1142
+	Modifier              int64              `gorm:"column:modifier" json:"modifier" form:"modifier"`
1143
+	IsCheck               int64              `gorm:"-" json:"is_check" form:"is_check"`
1144
+	Way                   int64              `gorm:"column:way" json:"way" form:"way"`
1145
+	DrugId                int64              `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
1146
+	DrugNameId            int64              `gorm:"column:drug_name_id" json:"drug_name_id" form:"drug_name_id"`
1147
+}
1148
+
1149
+func (HisDoctorAdvice) TableName() string {
1150
+	return "his_doctor_advice_info"
1151
+}

+ 4 - 3
models/drug.go View File

@@ -65,9 +65,10 @@ type BaseDrugLib struct {
65 65
 	HospApprFlag                int64   `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
66 66
 	LmtUsedFlag                 int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
67 67
 	//MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
68
-	DrugDay               string  `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
69
-	Total                 float64 `gorm:"column:total" json:"total" form:"total"`
70
-	PrescribingNumberUnit string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
68
+	DrugDay               string                 `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
69
+	Total                 float64                `gorm:"column:total" json:"total" form:"total"`
70
+	PrescribingNumberUnit string                 `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
71
+	DrugWarehouseInfo     []*XtDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug_warehouse_info"`
71 72
 }
72 73
 
73 74
 func (BaseDrugLib) TableName() string {

+ 2 - 0
models/drug_stock.go View File

@@ -283,6 +283,7 @@ type VmDrugWarehouseInfo struct {
283 283
 	CountUnit      string `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
284 284
 	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
285 285
 	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
286
+	MinNumber      int64  `gorm:"column:min_number" json:"min_number" form:"min_number"`
286 287
 }
287 288
 
288 289
 type StDrugWarehouseOutInfo struct {
@@ -324,6 +325,7 @@ type StDrugWarehouseOutInfo struct {
324 325
 	LastPrice               string  `json:"last_price"`
325 326
 	PackingUnit             string  `json:"packing_unit"`
326 327
 	Dosage                  int64   `json:"dosage"`
328
+	ExpireDate              int64   `json:"expire_date"`
327 329
 }
328 330
 
329 331
 type DrugFlow struct {

+ 2 - 0
models/good_models.go View File

@@ -80,6 +80,8 @@ type GoodInfo struct {
80 80
 	StWarehousingInfo           []*StWarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"xt_warehouse_info"`
81 81
 	CancelStockInfo             []*CancelStockInfo   `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"cancel_stock_info"`
82 82
 	RegisterNumber              string               `gorm:"column:register_number" json:"register_number" form:"register_number"`
83
+	GoodSotckInfo               []*GoodSotckInfo     `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"good_stock_in"`
84
+	RegisterNumber              string               `gorm:"column:register_number" json:"register_number" form:"register_number"`
83 85
 }
84 86
 
85 87
 func (GoodInfo) TableName() string {

+ 40 - 0
models/his_charge_models.go View File

@@ -203,3 +203,43 @@ type HisLabelPrintInfo struct {
203 203
 func (HisLabelPrintInfo) TableName() string {
204 204
 	return "his_label_print_info"
205 205
 }
206
+
207
+type HisLabelPrintInfo struct {
208
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
209
+	PatientId   int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
210
+	Number      string `gorm:"column:number" json:"number" form:"number"`
211
+	Ctime       int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
212
+	Mtime       int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
213
+	DoctorId    int64  `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
214
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
215
+	ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
216
+	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
217
+	IsPrint     int64  `gorm:"column:is_print" json:"is_print" form:"is_print"`
218
+	RecordDate  int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
219
+	ItemId      int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
220
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
221
+	PProjectId  int64  `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
222
+
223
+	FeedetlSn   string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
224
+	DoctorName  string `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
225
+	PatientName string `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
226
+}
227
+
228
+func (HisLabelPrintInfo) TableName() string {
229
+	return "his_label_print_info"
230
+}
231
+
232
+type HisFapiaoRecord struct {
233
+	ID           int64  `gorm:"column:id" json:"id" form:"id"`
234
+	FapiaoCode   string `gorm:"column:fapiao_code" json:"fapiao_code" form:"fapiao_code"`
235
+	FapiaoNumber string `gorm:"column:fapiao_number" json:"fapiao_number" form:"fapiao_number"`
236
+	IsUse        int64  `gorm:"column:is_use" json:"is_use" form:"is_use"`
237
+	Status       int64  `gorm:"column:status" json:"status" form:"status"`
238
+	Ctime        int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
239
+	Mtime        int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
240
+	UserOrgId    int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
241
+}
242
+
243
+func (HisFapiaoRecord) TableName() string {
244
+	return "his_fapiao_record"
245
+}

+ 51 - 1
models/his_models.go View File

@@ -236,6 +236,7 @@ type HisDoctorAdviceInfo struct {
236 236
 	Way                   int64                  `gorm:"column:way" json:"way" form:"way"`
237 237
 	HospApprFlag          int64                  `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
238 238
 	LmtUsedFlag           int64                  `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
239
+	HisOrderInfo          HisOrderInfo           `gorm:"ForeignKey:AdviceId;AssociationForeignKey:ID" json:"order_info"`
239 240
 }
240 241
 
241 242
 func (HisDoctorAdviceInfo) TableName() string {
@@ -779,6 +780,11 @@ type HisPrescriptionProject struct {
779 780
 	DayCount      int64  `gorm:"column:day_count" json:"day_count" form:"day_count"`
780 781
 	WeekDay       string `gorm:"column:week_day" json:"week_day" form:"week_day"`
781 782
 	IsCheckTeam   int64  `gorm:"-" json:"is_check_team" form:"is_check_team"`
783
+	FrequencyType int64        `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
784
+	DayCount      int64        `gorm:"column:day_count" json:"day_count" form:"day_count"`
785
+	WeekDay       string       `gorm:"column:week_day" json:"week_day" form:"week_day"`
786
+	IsCheckTeam   int64        `gorm:"-" json:"is_check_team" form:"is_check_team"`
787
+	HisOrderInfo  HisOrderInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"order_info"`
782 788
 }
783 789
 
784 790
 func (HisPrescriptionProject) TableName() string {
@@ -967,6 +973,7 @@ type HisOrder struct {
967 973
 	HisFundSettleListResult HisFundSettleListResult `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"result"`
968 974
 	IsPre                   int64                   `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
969 975
 	Diagnosis               string                  `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
976
+	FaPiaoBatchnumberId     int64                   `gorm:"column:fa_piao_batchnumber_id" json:"fa_piao_batchnumber_id" form:"fa_piao_batchnumber_id"`
970 977
 }
971 978
 
972 979
 func (HisOrder) TableName() string {
@@ -1059,6 +1066,49 @@ func (HisOrderInfoTwo) TableName() string {
1059 1066
 	return "his_order_info"
1060 1067
 }
1061 1068
 
1069
+type HisOrderInfoTwo struct {
1070
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
1071
+	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
1072
+	UploadDate       int64   `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
1073
+	AdviceId         int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
1074
+	DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
1075
+	Cnt              float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
1076
+	Pric             float64 `gorm:"column:pric" json:"pric" form:"pric"`
1077
+	PatientId        int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1078
+	PricUplmtAmt     float64 `gorm:"column:pric_uplmt_amt" json:"pric_uplmt_amt" form:"pric_uplmt_amt"`
1079
+	SelfpayProp      float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
1080
+	FulamtOwnpayAmt  float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
1081
+	OverlmtAmt       float64 `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
1082
+	PreselfpayAmt    float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
1083
+	BasMednFlag      string  `gorm:"column:bas_medn_flag" json:"bas_medn_flag" form:"bas_medn_flag"`
1084
+	MedChrgitmType   string  `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
1085
+	HiNegoDrugFlag   string  `gorm:"column:hi_nego_drug_flag" json:"hi_nego_drug_flag" form:"hi_nego_drug_flag"`
1086
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
1087
+	Memo             string  `gorm:"column:memo" json:"memo" form:"memo"`
1088
+	FeedetlSn        string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
1089
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
1090
+	InscpScpAmt      float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
1091
+	DrtReimFlag      string  `gorm:"column:drt_reim_flag" json:"drt_reim_flag" form:"drt_reim_flag"`
1092
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
1093
+	ListSpItemFlag   string  `gorm:"column:list_sp_item_flag" json:"list_sp_item_flag" form:"list_sp_item_flag"`
1094
+	ChldMedcFlag     string  `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
1095
+	LmtUsedFlag      string  `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
1096
+	ChrgitmLv        string  `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
1097
+	UserOrgId        int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1098
+	HisPatientId     int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
1099
+	OrderId          int64   `gorm:"column:order_id" json:"order_id" form:"order_id"`
1100
+	ProjectId        int64   `gorm:"column:project_id" json:"project_id" form:"project_id"`
1101
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
1102
+	ItemId           int64   `gorm:"column:item_id" json:"item_id" form:"item_id"`
1103
+
1104
+	HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
1105
+	HisDoctorAdviceInfo    HisDoctorAdviceInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
1106
+}
1107
+
1108
+func (HisOrderInfoTwo) TableName() string {
1109
+	return "his_order_info"
1110
+}
1111
+
1062 1112
 type VMHisPatient struct {
1063 1113
 	ID                     int64   `gorm:"column:id" json:"id" form:"id"`
1064 1114
 	BalanceAccountsType    int64   `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
@@ -1429,7 +1479,7 @@ type HisPrescriptionProjectTemplate struct {
1429 1479
 	PatientId          int64        `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1430 1480
 	HisPatientId       int64        `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
1431 1481
 	RecordDate         int64        `gorm:"column:record_date" json:"record_date" form:"record_date"`
1432
-	Count              int64        `gorm:"column:count" json:"count" form:"count"`
1482
+	Count              string       `gorm:"column:count" json:"count" form:"count"`
1433 1483
 	FeedetlSn          string       `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
1434 1484
 	MedListCodg        string       `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
1435 1485
 	SingleDose         string       `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`

+ 1 - 1
models/patient_models.go View File

@@ -1320,7 +1320,7 @@ type XtAssessmentBeforeDislysis struct {
1320 1320
 	DuctusArantii                  string  `gorm:"column:ductus_arantii" json:"ductus_arantii" form:"ductus_arantii"`
1321 1321
 	EmergencyTreatment             int64   `gorm:"column:emergency_treatment" json:"emergency_treatment" form:"emergency_treatment"`
1322 1322
 	EmergencyTreatmentOther        string  `gorm:"column:emergency_treatment_other" json:"emergency_treatment_other" form:"emergency_treatment_other"`
1323
-	DialysisCount                  int64   `gorm:"column:dialysis_count" json:"dialysis_count" form:"dialysis_count"`
1323
+	DialysisCount                  string  `gorm:"column:dialysis_count" json:"dialysis_count" form:"dialysis_count"`
1324 1324
 	AssessmentDoctor               int64   `gorm:"column:assessment_doctor" json:"assessment_doctor" form:"assessment_doctor"`
1325 1325
 	AssessmentTime                 int64   `gorm:"column:assessment_time" json:"assessment_time" form:"assessment_time"`
1326 1326
 	MachineType                    string  `gorm:"column:machine_type" json:"machine_type" form:"machine_type"`

+ 97 - 12
models/schedule_models.go View File

@@ -44,12 +44,12 @@ type Schedule struct {
44 44
 	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
45 45
 	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
46 46
 
47
-	Patient       string        `gorm:"-" json:"patient" form:"patient"`
48
-	DeviceZone    DeviceZone    `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
49
-	DeviceNumber  DeviceNumber  `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
50
-	TreatmentMode TreatmentMode `json:"mode" gorm:"foreignkey:ModeId"`
51
-	DialysisOrder DialysisOrder `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
52
-
47
+	Patient                   string               `gorm:"-" json:"patient" form:"patient"`
48
+	DeviceZone                DeviceZone           `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
49
+	DeviceNumber              DeviceNumber         `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
50
+	TreatmentMode             TreatmentMode        `json:"mode" gorm:"foreignkey:ModeId"`
51
+	DialysisOrder             DialysisOrder        `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
52
+	DialysisPrescription      DialysisPrescription `json:"dialysis_prescription" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId;"`
53 53
 	PatientInfectiousDiseases []InfectiousDiseases `json:"patient_contagions" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
54 54
 }
55 55
 
@@ -190,16 +190,101 @@ type VmSchedulesRemind struct {
190 190
 
191 191
 	DeviceZone                 DeviceZone                 `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
192 192
 	DeviceNumber               DeviceNumber               `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
193
-	DialysisOrder              DialysisOrder              `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
193
+	DialysisOrder              DialysisOrder              `json:"order" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
194 194
 	XtPatients                 XtPatients                 `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientId;"`
195
+	DoctorAdvice               []*DoctorAdvice            `json:"doctoradvice" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
196
+	DialysisPrescription       DialysisPrescription       `json:"prescription" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
197
+	HisDoctorAdviceInfo        []*HisDoctorAdviceInfo     `json:"hisdoctoradviceinfo" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
198
+	DialysisSolution           DialysisSolution           `json:"dialysissolution" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId;"`
199
+	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `json:"assessmentbefor" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
200
+	LastAfterWeight            AssessmentAfterDislysis    `gorm:"ForeignKey:PatientID;AssociationForeignKey:PatientID" json:"lastafterweight"`
201
+}
202
+
203
+func (VmSchedulesRemind) TableName() string {
204
+	return "xt_schedule"
205
+}
206
+
207
+type WeekScheduleSix struct {
208
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
209
+	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
210
+	PartitionId  int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
211
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
212
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
213
+	ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
214
+	ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
215
+	ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
216
+	ModeId       int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
217
+	Status       int64 `gorm:"column:status" json:"status" form:"status"`
218
+	CreatedTime  int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
219
+	UpdatedTime  int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
220
+	IsExport     int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
221
+
222
+	Patient                    string                     `gorm:"-" json:"patient" form:"patient"`
223
+	DeviceZone                 DeviceZone                 `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
224
+	DeviceNumber               DeviceNumber               `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
225
+	DialysisPrescription       DialysisSolution           `json:"prescription" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId"`
195 226
 	DoctorAdvice               []*DoctorAdvice            `json:"doctoradvice" gorm:"foreignkey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
196
-	DialysisPrescription       DialysisPrescription       `json:"prescription" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
197 227
 	HisDoctorAdviceInfo        []*HisDoctorAdviceInfo     `json:"hisdoctoradviceinfo" gorm:"foreignkey:AdviceDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
198
-	DialysisSolution           DialysisSolution           `json:"dialysissolution" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
199
-	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `json:"assessmentbefor" gorm:"foreignkey:AssessmentDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
200
-	Solution                   []*DialysisSolution        `json:"solution" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
228
+	DialysisSolution           DialysisSolution           `json:"dialysissolution" gorm:"foreignkey:PatientId,ModeId;AssociationForeignKey:PatientId,ModeId"`
229
+	XtAssessmentBeforeDislysis XtAssessmentBeforeDislysis `json:"assessmentbefor" gorm:"foreignkey:PatientId,AssessmentDate;AssociationForeignKey:PatientId,ScheduleDate"`
201 230
 }
202 231
 
203
-func (VmSchedulesRemind) TableName() string {
232
+func (WeekScheduleSix) TableName() string {
233
+	return "xt_schedule"
234
+}
235
+
236
+type BlodSchedule struct {
237
+	ID                        int64                     `gorm:"column:id" json:"id" form:"id"`
238
+	UserOrgId                 int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
239
+	PartitionId               int64                     `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
240
+	BedId                     int64                     `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
241
+	PatientId                 int64                     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
242
+	ScheduleDate              int64                     `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
243
+	ScheduleType              int64                     `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
244
+	ScheduleWeek              int64                     `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
245
+	ModeId                    int64                     `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
246
+	Status                    int64                     `gorm:"column:status" json:"status" form:"status"`
247
+	VmBloodPatients           VmBloodPatients           `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientId;"`
248
+	BloodDialysisOrder        BloodPatientDialysisOrder `json:"order" gorm:"foreignkey:DialysisDate,PatientId;AssociationForeignKey:ScheduleDate,PatientId;"`
249
+	BloodDialysisPrescription BloodDialysisPrescription `json:"prescription" gorm:"foreignkey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId;"`
250
+}
251
+
252
+func (BlodSchedule) TableName() string {
204 253
 	return "xt_schedule"
205 254
 }
255
+
256
+type BloodPatientDialysisOrder struct {
257
+	ID           int64 `gorm:"column:id" json:"id" form:"id"`
258
+	DialysisDate int64 `gorm:"column:dialysis_date" json:"dialysis_date" form:"dialysis_date"`
259
+	PatientId    int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
260
+	Stage        int64 `gorm:"column:stage" json:"stage" form:"stage"`
261
+	BedId        int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
262
+}
263
+
264
+func (BloodPatientDialysisOrder) TableName() string {
265
+	return "xt_dialysis_order"
266
+}
267
+
268
+type BloodPatientDialysisPrescription struct {
269
+	ID                         int64  `gorm:"column:id" json:"id" form:"id"`
270
+	PatientId                  int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
271
+	MachineType                string `gorm:"column:machine_type" json:"machine_type" form:"machine_type"`
272
+	ModeId                     int64  `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
273
+	DialysisDialyszers         string `gorm:"column:dialysis_dialyszers" json:"dialysis_dialyszers" form:"dialysis_dialyszers"`
274
+	DialysisIrrigation         string `gorm:"column:dialysis_irrigation" json:"dialysis_irrigation" form:"dialysis_irrigation"`
275
+	DialyzerPerfusionApparatus string `gorm:"column:dialyzer_perfusion_apparatus" json:"dialyzer_perfusion_apparatus" form:"dialyzer_perfusion_apparatus"`
276
+}
277
+
278
+func (BloodPatientDialysisPrescription) TableName() string {
279
+	return "xt_dialysis_prescription"
280
+}
281
+
282
+type VmBloodPatients struct {
283
+	ID    int64  `gorm:"column:id" json:"id" form:"id"`
284
+	BedId int64  `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
285
+	Name  string `gorm:"column:name" json:"name" form:"name"`
286
+}
287
+
288
+func (VmBloodPatients) TableName() string {
289
+	return "xt_patients"
290
+}

+ 62 - 0
models/self_drug_models.go View File

@@ -670,6 +670,7 @@ type VmDrugWarehouseOutInfo struct {
670 670
 	MinPrice                float64 `json:"min_price"`
671 671
 	DrugName                string  `json:"drug_name"`
672 672
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
673
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
673 674
 }
674 675
 
675 676
 type XtDrugAdjustPrice struct {
@@ -767,6 +768,49 @@ func (XtDrugDamage) TableName() string {
767 768
 	return "xt_drug_damage"
768 769
 }
769 770
 
771
+type VmXtDrugInventory struct {
772
+	ID                 int64      `gorm:"column:id" json:"id" form:"id"`
773
+	DrugName           string     `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
774
+	SpecificationName  string     `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
775
+	WarehousingUnit    string     `gorm:"column:warehousing_unit" json:"warehousing_unit" form:"warehousing_unit"`
776
+	Count              int64      `gorm:"column:count" json:"count" form:"count"`
777
+	LastPrice          float64    `gorm:"column:last_price" json:"last_price" form:"last_price"`
778
+	RetailPrice        float64    `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
779
+	NewPrice           float64    `gorm:"column:new_price" json:"new_price" form:"new_price"`
780
+	Manufacturer       string     `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
781
+	Dealer             string     `gorm:"column:dealer" json:"dealer" form:"dealer"`
782
+	Remark             string     `gorm:"column:remark" json:"remark" form:"remark"`
783
+	DrugId             int64      `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
784
+	UserOrgId          int64      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
785
+	Ctime              int64      `gorm:"column:ctime" json:"ctime" form:"ctime"`
786
+	Mtime              int64      `gorm:"column:mtime" json:"mtime" form:"mtime"`
787
+	Status             int64      `gorm:"column:status" json:"status" form:"status"`
788
+	WarehousingOrder   string     `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
789
+	LicenseNumber      string     `gorm:"column:license_number" json:"license_number" form:"license_number"`
790
+	StartTime          int64      `gorm:"column:start_time" json:"start_time" form:"start_time"`
791
+	Creater            int64      `gorm:"column:creater" json:"creater" form:"creater"`
792
+	Checker            int64      `gorm:"column:checker" json:"checker" form:"checker"`
793
+	CheckerStatus      int64      `gorm:"column:checker_status" json:"checker_status" form:"checker_status"`
794
+	CheckerTime        int64      `gorm:"column:checker_time" json:"checker_time" form:"checker_time"`
795
+	ExpiryDate         int64      `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
796
+	ProductDate        int64      `gorm:"column:product_date" json:"product_date" form:"product_date"`
797
+	Number             string     `gorm:"column:number" json:"number" form:"number"`
798
+	BatchNumber        string     `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
799
+	Total              string     `gorm:"column:total" json:"total" form:"total"`
800
+	DrugOriginPlace    string     `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
801
+	WarehouseInfoId    int64      `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
802
+	ProofCount         int64      `gorm:"column:proof_count" json:"proof_count" form:"proof_count"`
803
+	StockMaxNumber     int64      `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
804
+	StockMinNumber     int64      `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
805
+	MinCount           int64      `gorm:"column:min_count" json:"min_count" form:"min_count"`
806
+	MinUnit            string     `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
807
+	LastStockMaxNumber int64      `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
808
+	LastStockMinNumber int64      `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
809
+	InventoryType      int64      `gorm:"column:inventory_type" json:"inventory_type" form:"inventory_type"`
810
+	Type               int64      `gorm:"column:type" json:"type" form:"type"`
811
+	XtBaseDrug         XtBaseDrug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
812
+}
813
+
770 814
 type XtDrugInventory struct {
771 815
 	ID                 int64   `gorm:"column:id" json:"id" form:"id"`
772 816
 	DrugName           string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
@@ -892,3 +936,21 @@ type SgjDrugWarehouseOutInfo struct {
892 936
 func (SgjDrugWarehouseOutInfo) TableName() string {
893 937
 	return "xt_drug_warehouse_out_info"
894 938
 }
939
+
940
+type PatientDrugWarehouseInfo struct {
941
+	DrugId         int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
942
+	Number         string  `gorm:"column:number" json:"number" form:"number"`
943
+	ProductDate    int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
944
+	ExpiryDate     int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
945
+	StockMaxNumber int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
946
+	StockMinNumber int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
947
+	BatchNumber    string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
948
+	DrugName       string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
949
+	MaxUnit        string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
950
+	MinUnit        string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
951
+	MinNumber      int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
952
+	Dose           float64 `gorm:"column:dose" json:"dose" form:"dose"`
953
+	DoseUnit       string  `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
954
+	Manufacturer   int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
955
+	Dealer         int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
956
+}

+ 64 - 23
models/stock_models.go View File

@@ -317,6 +317,7 @@ type WarehousingGoodInfo struct {
317 317
 	Dealers           Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
318 318
 	BuyPrice          float64      `gorm:"column:buy_price" json:"buy_price"`
319 319
 	Total             float64      `gorm:"column:total" json:"total" form:"total"`
320
+	RegisterNumber    string       `gorm:"column:register_number" json:"register_number" form:"register_number"`
320 321
 }
321 322
 
322 323
 func (WarehousingGoodInfo) TableName() string {
@@ -550,29 +551,30 @@ func (VmStockFlow) TableName() string {
550 551
 }
551 552
 
552 553
 type CancelStockInfo struct {
553
-	ID              int64       `gorm:"column:id" json:"id"`
554
-	GoodId          int64       `gorm:"column:good_id" json:"good_id"`
555
-	CancelStockId   int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id"`
556
-	GoodTypeId      int64       `gorm:"column:good_type_id" json:"good_type_id"`
557
-	Count           int64       `gorm:"column:count" json:"count"`
558
-	Price           float64     `gorm:"column:price" json:"price"`
559
-	Total           float64     `gorm:"column:total" json:"total"`
560
-	ProductDate     int64       `gorm:"column:product_date" json:"product_date"`
561
-	ExpiryDate      int64       `gorm:"column:expiry_date" json:"expiry_date"`
562
-	Ctime           int64       `gorm:"column:ctime" json:"ctime"`
563
-	Mtime           int64       `gorm:"column:mtime" json:"mtime"`
564
-	Status          int64       `gorm:"column:status" json:"status"`
565
-	OrgId           int64       `gorm:"column:org_id" json:"org_id"`
566
-	OrderNumber     string      `gorm:"column:order_number" json:"order_number"`
567
-	Type            int64       `gorm:"column:type" json:"type"`
568
-	CancelStock     CancelStock `ForeignKey:CancelStockId json:"CancelStock"`
569
-	Dealer          string      `gorm:"column:dealer" json:"dealer"`
570
-	Manufacturer    string      `gorm:"column:manufacturer" json:"manufacturer"`
571
-	Number          string      `gorm:"column:number" json:"number" form:"number"`
572
-	RegisterAccount string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
573
-	Remark          string      `gorm:"column:remark" json:"remark" form:"remark"`
574
-	WarehouseInfoId int64       `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
575
-	GoodInfo        GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
554
+	ID              int64              `gorm:"column:id" json:"id"`
555
+	GoodId          int64              `gorm:"column:good_id" json:"good_id"`
556
+	CancelStockId   int64              `gorm:"column:cancel_stock_id" json:"cancel_stock_id"`
557
+	GoodTypeId      int64              `gorm:"column:good_type_id" json:"good_type_id"`
558
+	Count           int64              `gorm:"column:count" json:"count"`
559
+	Price           float64            `gorm:"column:price" json:"price"`
560
+	Total           float64            `gorm:"column:total" json:"total"`
561
+	ProductDate     int64              `gorm:"column:product_date" json:"product_date"`
562
+	ExpiryDate      int64              `gorm:"column:expiry_date" json:"expiry_date"`
563
+	Ctime           int64              `gorm:"column:ctime" json:"ctime"`
564
+	Mtime           int64              `gorm:"column:mtime" json:"mtime"`
565
+	Status          int64              `gorm:"column:status" json:"status"`
566
+	OrgId           int64              `gorm:"column:org_id" json:"org_id"`
567
+	OrderNumber     string             `gorm:"column:order_number" json:"order_number"`
568
+	Type            int64              `gorm:"column:type" json:"type"`
569
+	CancelStock     CancelStock        `ForeignKey:CancelStockId json:"CancelStock"`
570
+	Dealer          string             `gorm:"column:dealer" json:"dealer"`
571
+	Manufacturer    string             `gorm:"column:manufacturer" json:"manufacturer"`
572
+	Number          string             `gorm:"column:number" json:"number" form:"number"`
573
+	RegisterAccount string             `gorm:"column:register_account" json:"register_account" form:"register_account"`
574
+	Remark          string             `gorm:"column:remark" json:"remark" form:"remark"`
575
+	WarehouseInfoId int64              `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
576
+	GoodInfo        GoodInfo           `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
577
+	WarehousingInfo []*WarehousingInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"xt_warehouse_info"`
576 578
 }
577 579
 
578 580
 func (CancelStockInfo) TableName() string {
@@ -986,6 +988,10 @@ type XtStockInventory struct {
986 988
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
987 989
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
988 990
 	GoodOriginPlace   string  `gorm:"column:good_origin_place" json:"good_origin_place" form:"good_origin_place"`
991
+	Type              int64   `gorm:"column:type" json:"type" form:"type"`
992
+	InventoryType     int64   `gorm:"column:inventory_type" json:"inventory_type" form:"inventory_type"`
993
+	LastStockCount    int64   `gorm:"column:last_stock_count" json:"last_stock_count" form:"last_stock_count"`
994
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
989 995
 }
990 996
 
991 997
 func (XtStockInventory) TableName() string {
@@ -1022,6 +1028,10 @@ type VmStockInventory struct {
1022 1028
 	Number            string  `gorm:"column:number" json:"number" form:"number"`
1023 1029
 	ExpireDate        int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
1024 1030
 	ProductDate       int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
1031
+	Type              int64   `gorm:"column:type" json:"type" form:"type"`
1032
+	InventoryType     int64   `gorm:"column:inventory_type" json:"inventory_type" form:"inventory_type"`
1033
+	LastStockCount    int64   `gorm:"column:last_stock_count" json:"last_stock_count" form:"last_stock_count"`
1034
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1025 1035
 }
1026 1036
 
1027 1037
 type XtStockCorrectRecord struct {
@@ -1105,6 +1115,37 @@ type SgjCancelStockInfo struct {
1105 1115
 	PackingPrice      float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
1106 1116
 }
1107 1117
 
1118
+type GoodSotckInfo struct {
1119
+	GoodId            int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
1120
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1121
+	GoodName          string  `gorm:"column:good_name" json:"good_name"`
1122
+	SpecificationName string  `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1123
+	Price             float64 `gorm:"column:price" json:"price" form:"price"`
1124
+}
1125
+
1126
+func (GoodSotckInfo) TableName() string {
1127
+	return "xt_warehouse_info"
1128
+}
1129
+
1130
+type PatientWarehouseInfo struct {
1131
+	ID                int64  `gorm:"column:id" json:"id" form:"id"`
1132
+	GoodId            int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`
1133
+	Number            string `gorm:"column:number" json:"number" form:"number"`
1134
+	ProductDate       int64  `gorm:"column:product_date" json:"product_date" form:"product_date"`
1135
+	ExpiryDate        int64  `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
1136
+	WarehousingUnit   string `gorm:"column:warehousing_unit" json:"warehousing_unit" form:"warehousing_unit"`
1137
+	Dealer            int64  `gorm:"column:dealer" json:"dealer" form:"dealer"`
1138
+	Manufacturer      int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
1139
+	GoodName          string `gorm:"column:good_name" json:"good_name"`
1140
+	SpecificationName string `gorm:"column:specification_name" json:"specification_name" form:"specification_name"`
1141
+	PackingUnit       string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
1142
+	Remark            string `gorm:"column:remark" json:"remark" form:"remark"`
1143
+}
1144
+
1145
+func (PatientWarehouseInfo) TableName() string {
1146
+	return "xt_warehouse_info"
1147
+}
1148
+
1108 1149
 type PatientWarehouseInfo struct {
1109 1150
 	ID                int64  `gorm:"column:id" json:"id" form:"id"`
1110 1151
 	GoodId            int64  `gorm:"column:good_id" json:"good_id" form:"good_id"`

+ 1 - 0
models/stock_query_models.go View File

@@ -14,6 +14,7 @@ type StockInfo struct {
14 14
 	QueryWarehouseOutInfo []QueryWarehouseOutInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehouseout_info"`
15 15
 	QueryCancelStockInfo  []QueryCancelStockInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_cancel_stock_info"`
16 16
 	GoodsType             GoodsType               `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
17
+	RegisterNumber        string                  `gorm:"column:register_number" json:"register_number" form:"register_number"`
17 18
 }
18 19
 
19 20
 func (StockInfo) TableName() string {

+ 13 - 4
service/app_version.go View File

@@ -257,13 +257,18 @@ func UpDateHis2(his *models.HisPrescriptionProject) {
257 257
 	writeDb.Save(&his)
258 258
 }
259 259
 
260
-func GetAllHisOrder() (his []*models.HisOrder, err error) {
261
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2 AND settle_accounts_date < 1623168000").Find(&his).Error
260
+func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
261
+	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code == '' AND fa_piao_number == '' ", org_id).Find(&his).Error
262
+	return
263
+}
264
+
265
+func GetAllHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
266
+	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> '' ", org_id).Last(&his).Error
262 267
 	return
263 268
 }
264 269
 
265 270
 func GetLastHisOrder() (his models.HisOrder, err error) {
266
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 4 AND status = 1 AND order_status = 2").Last(&his).Error
271
+	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2").Last(&his).Error
267 272
 	return
268 273
 }
269 274
 
@@ -378,7 +383,7 @@ type HisPrescriptionProjectTemplate struct {
378 383
 	PatientId          int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
379 384
 	HisPatientId       int64   `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
380 385
 	RecordDate         int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
381
-	Count              int64   `gorm:"column:count" json:"count" form:"count"`
386
+	Count              string  `gorm:"column:count" json:"count" form:"count"`
382 387
 	FeedetlSn          string  `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
383 388
 	MedListCodg        string  `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
384 389
 	SingleDose         string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
@@ -437,3 +442,7 @@ func UpdateStatus(project_id int64, p_id int64) {
437 442
 	writeDb.Model(&HisPrescriptionProjectTemplate{}).Where("id = ?", project_id).Updates(map[string]interface{}{"status": 0})
438 443
 	writeDb.Model(&HisPrescriptionInfoTemplateTwo{}).Where("id = ?", p_id).Updates(map[string]interface{}{"status": 0})
439 444
 }
445
+
446
+func SaveOrder(order *models.HisOrder) {
447
+	writeDb.Save(&order)
448
+}

+ 44 - 1
service/dialysis_service.go View File

@@ -1330,7 +1330,7 @@ func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) {
1330 1330
 
1331 1331
 func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) {
1332 1332
 
1333
-	err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND  find_in_set('停用',good_status) = 0", orgid).Find(&goodinfo).Error
1333
+	err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND  find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "stock_count > 0 and status = 1").Find(&goodinfo).Error
1334 1334
 	return goodinfo, err
1335 1335
 }
1336 1336
 
@@ -1370,6 +1370,17 @@ func ModifyExceDoctorAdviceById(m *models.HisDoctorAdviceInfo, ids []string) (er
1370 1370
 	return err
1371 1371
 }
1372 1372
 
1373
+func ModifyHisPrescriptionProject(m *models.HisPrescriptionProject, ids []string) (err error) {
1374
+	ut := writeDb.Begin()
1375
+	err = ut.Model(&models.HisPrescriptionProject{}).Where("status = 1   AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error
1376
+	if err != nil {
1377
+		ut.Rollback()
1378
+		return
1379
+	}
1380
+	ut.Commit()
1381
+	return err
1382
+}
1383
+
1373 1384
 func FindHisProjectById(orgID int64, id int64) (advice models.HisPrescriptionProject, err error) {
1374 1385
 	err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error
1375 1386
 	return
@@ -1580,3 +1591,35 @@ func GetAllPcTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatment
1580 1591
 		}
1581 1592
 	}
1582 1593
 }
1594
+
1595
+func UpdateTeamProjectExceStatus(ids []int64, admin_user_id int64, execution_time int64) (err error) {
1596
+	ut := writeDb.Begin()
1597
+	db := ut.Model(&models.HisPrescriptionProject{})
1598
+	err = db.Where("status = 1   AND id IN (?)", ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_state": 1, "execution_staff": admin_user_id}).Error
1599
+	if err != nil {
1600
+		ut.Rollback()
1601
+		return
1602
+	}
1603
+
1604
+	ut.Commit()
1605
+	return err
1606
+
1607
+}
1608
+
1609
+func UpdateTeamProjectCheckStatus(ids []int64, patient_id int64, record_date int64, user_org_id int64, admin_user_id int64, check_time int64) (err error) {
1610
+	ut := writeDb.Begin()
1611
+	err = ut.Model(&models.HisPrescriptionProject{}).Where("status = 1   AND id IN (?) AND patient_id = ? AND user_org_id = ? AND record_date = ?", ids, patient_id, user_org_id, record_date).Updates(map[string]interface{}{"check_time": check_time, "check_state": 1, "checker": admin_user_id}).Error
1612
+	if err != nil {
1613
+		ut.Rollback()
1614
+		return
1615
+	}
1616
+
1617
+	ut.Commit()
1618
+	return err
1619
+
1620
+}
1621
+
1622
+func GetCheckTeamProject(team_id int64, patient_id int64, record_date int64, user_org_id int64) (ps []*models.HisPrescriptionProject, err error) {
1623
+	err = readDb.Model(&models.HisPrescriptionProject{}).Joins("JOIN xt_his_project as p On p.id = his_prescription_project.project_id AND p.cost_classify = 3").Where("his_prescription_project.team_id IN (?) AND his_prescription_project.patient_id = ? AND his_prescription_project.user_org_id = ? AND his_prescription_project.record_date = ? AND his_prescription_project.status = 1", team_id, patient_id, user_org_id, record_date).Find(&ps).Error
1624
+	return
1625
+}

+ 102 - 2
service/doctor_schedule_service.go View File

@@ -598,6 +598,44 @@ func GetPatientSchedule(startime int64, zoneid int64, classtype int64, orgid int
598 598
 	return schedule, err
599 599
 }
600 600
 
601
+func GetPatientScheduleByBed(schedule_date int64, zoneid int64, orgid int64, class_type int64) (list []*models.PatientDeviceNumber, err error) {
602
+
603
+	db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
604
+	if zoneid > 0 {
605
+		db = db.Where("x.zone_id = ?", zoneid)
606
+	}
607
+	if orgid > 0 {
608
+		db = db.Where("x.org_id = ?", orgid)
609
+	}
610
+	if class_type > 0 {
611
+		err = db.Select("x.id,x.number,x.sort,x.group_id,x.zone_id,x.sort").Preload("DeviceZone", "status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
612
+			return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ? and schedule_type = ?", orgid, schedule_date, class_type).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1 and dialysis_date = ?", schedule_date).Preload("BloodDialysisPrescription", "status = 1 and record_date = ?", schedule_date)
613
+		}).Find(&list).Error
614
+	} else {
615
+		err = db.Select("x.id,x.number,x.sort,x.group_id,x.zone_id,x.sort").Preload("DeviceZone", "status = 1").Preload("Schedule", func(db *gorm.DB) *gorm.DB {
616
+			return XTReadDB().Model(&models.BlodSchedule{}).Where("status = 1 AND user_org_id = ? and schedule_date = ?", orgid, schedule_date).Preload("VmBloodPatients", "status = 1 and user_org_id = ?", orgid).Preload("BloodDialysisOrder", "status = 1 and dialysis_date = ?", schedule_date).Preload("BloodDialysisPrescription", "status = 1 and record_date = ?", schedule_date)
617
+		}).Find(&list).Error
618
+	}
619
+
620
+	return list, err
621
+}
622
+
623
+func GetPatientDialysisOrderDate(shcedule_date int64, class_type int64, orgid int64) (schedule []*models.Schedule, err error) {
624
+
625
+	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
626
+	if shcedule_date > 0 {
627
+		db = db.Where("x.schedule_date = ?", shcedule_date)
628
+	}
629
+	if class_type > 0 {
630
+		db = db.Where("x.schedule_type = ?", class_type)
631
+	}
632
+	if orgid > 0 {
633
+		db = db.Where("x.user_org_id = ?", orgid)
634
+	}
635
+	err = db.Select("x.id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id").Preload("DialysisOrder", "status = 1").Preload("DialysisPrescription", "status = 1").Find(&schedule).Error
636
+	return schedule, err
637
+}
638
+
601 639
 func DeleteSchedule(id int64) error {
602 640
 
603 641
 	schedule := models.XtSchedule{}
@@ -610,8 +648,9 @@ func GetSearchPatient(keywords string, orgid int64, startime int64) (schedule []
610 648
 
611 649
 	likeKey := "%" + keywords + "%"
612 650
 	db := XTReadDB().Table("xt_schedule as s")
613
-	err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", "status= 1").
614
-		Preload("DialysisOrder", "status =1").
651
+	err = db.Preload("DeviceZone", " status= 1").Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
652
+		return db.Where("status =1").Preload("DeviceZone", "status = 1")
653
+	}).Preload("DialysisOrder", "status =1").Preload("DialysisPrescription", "status =1").
615 654
 		Joins("JOIN xt_patients as p ON p.id = s.patient_id And(p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).Where("s.user_org_id = ? and s.schedule_date = ? and s.status =1", orgid, startime).
616 655
 		Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id,p.name as patient").Find(&schedule).Error
617 656
 	return schedule, err
@@ -635,3 +674,64 @@ func UpdateStaffScheduleOne(nextid int64, schedule models.WeekSchedule) error {
635 674
 	err := XTWriteDB().Model(&schedule).Where("id = ?", nextid).Updates(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId}).Error
636 675
 	return err
637 676
 }
677
+
678
+func UpdatedScheduleMode(schedule models.XtSchedule, id int64) error {
679
+
680
+	xtSchedule := models.XtSchedule{}
681
+	err := XTWriteDB().Model(&xtSchedule).Where("id = ? and status =1 ", id).Updates(map[string]interface{}{"mode_id": schedule.ModeId}).Error
682
+	return err
683
+}
684
+
685
+func UpdatedSchedule(schedule models.XtSchedule, patient_id int64, schedule_date int64, schedule_type int64, bed_id int64) error {
686
+
687
+	xtSchedule := models.XtSchedule{}
688
+	err := XTWriteDB().Model(&xtSchedule).Where("patient_id = ? and status =1 and schedule_date = ?  and bed_id = ?", patient_id, schedule_date, bed_id).Updates(map[string]interface{}{"schedule_type": schedule.ScheduleType, "mode_id": schedule.ModeId}).Error
689
+	return err
690
+}
691
+
692
+func GetDialyisSolution(patientid int64, recorddate int64) (*models.DialysisPrescription, error) {
693
+
694
+	prescription := models.DialysisPrescription{}
695
+
696
+	err := XTReadDB().Where("patient_id = ? and record_date = ? and status = 1", patientid, recorddate).Find(&prescription).Error
697
+	if err != nil {
698
+		if err == gorm.ErrRecordNotFound {
699
+			return nil, err
700
+		} else {
701
+			return nil, err
702
+		}
703
+	}
704
+	return &prescription, nil
705
+}
706
+
707
+func GetPatientScheduleIsExist(startime int64, schedule_type int64, bed_id int64) (*models.Schedule, error) {
708
+
709
+	schedule := models.Schedule{}
710
+	err := XTReadDB().Model(&schedule).Where("schedule_date = ? and schedule_type = ? and bed_id = ? and status = 1", startime, schedule_type, bed_id).Find(&schedule).Error
711
+	if err == gorm.ErrRecordNotFound {
712
+		return nil, err
713
+	}
714
+	if err != nil {
715
+		return nil, err
716
+	}
717
+	return &schedule, nil
718
+}
719
+
720
+func CreateDialysisPrescription(prescription *models.DialysisPrescription) error {
721
+
722
+	err := XTReadDB().Create(&prescription).Error
723
+
724
+	return err
725
+}
726
+
727
+func CreateDialysisSolution(solution models.DialysisSolution) error {
728
+
729
+	err := XTReadDB().Create(&solution).Error
730
+	return err
731
+}
732
+
733
+func UpdateDialysisPrescriptionOne(prescription models.DialysisPrescription, patientid int64, recordate int64, mode_id int64) error {
734
+
735
+	err := XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and status = 1", patientid, recordate).Updates(map[string]interface{}{"dialysis_dialyszers": prescription.DialysisDialyszers, "mode_id": mode_id, "dialysis_irrigation": prescription.DialysisIrrigation}).Error
736
+	return err
737
+}

+ 99 - 36
service/his_charge_service.go View File

@@ -3,13 +3,14 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"github.com/jinzhu/gorm"
6
+	"time"
6 7
 )
7 8
 
8 9
 func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64, keyword string, item_type int64) (patients []*models.ChargePatient, err error) {
9 10
 	if len(keyword) == 0 {
10 11
 		switch item_type {
11 12
 		case 0:
12
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
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 {
13 14
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
14 15
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
15 16
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").
@@ -22,12 +23,12 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
22 23
 								return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
23 24
 							}).Where("status = 1 ")
24 25
 						})
25
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
26
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
26 27
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
27 28
 
28 29
 			break
29 30
 		case 1:
30
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
31
+			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 {
31 32
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
32 33
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
33 34
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id > 0 AND project_id = 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -39,12 +40,12 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
39 40
 								return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
40 41
 							}).Where("status = 1 ")
41 42
 						})
42
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
43
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
43 44
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
44 45
 
45 46
 			break
46 47
 		case 2:
47
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
48
+			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 {
48 49
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
49 50
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
50 51
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -54,12 +55,12 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
54 55
 								return db.Select("id,project_name,unit").Where("status = 1 ")
55 56
 							}).Where("status = 1 ")
56 57
 						})
57
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
58
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
58 59
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
59 60
 
60 61
 			break
61 62
 		case 3:
62
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
63
+			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 {
63 64
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
64 65
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
65 66
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -69,7 +70,7 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
69 70
 								return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
70 71
 							}).Where("status = 1 ")
71 72
 						})
72
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
73
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
73 74
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
74 75
 
75 76
 			break
@@ -80,7 +81,7 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
80 81
 		keyword := "%" + keyword + "%"
81 82
 		switch item_type {
82 83
 		case 0:
83
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
84
+			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 {
84 85
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
85 86
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
86 87
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -92,12 +93,12 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
92 93
 								return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
93 94
 							}).Where("status = 1 ")
94 95
 						})
95
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
96
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
96 97
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
97 98
 
98 99
 			break
99 100
 		case 1:
100
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
101
+			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 {
101 102
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
102 103
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
103 104
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id > 0 AND project_id = 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -109,12 +110,12 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
109 110
 								return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
110 111
 							}).Where("status = 1 ")
111 112
 						})
112
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
113
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
113 114
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
114 115
 
115 116
 			break
116 117
 		case 2:
117
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
118
+			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 {
118 119
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
119 120
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
120 121
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -124,12 +125,12 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
124 125
 								return db.Select("id,project_name,unit").Where("status = 1 ")
125 126
 							}).Where("status = 1 ")
126 127
 						})
127
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
128
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
128 129
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
129 130
 
130 131
 			break
131 132
 		case 3:
132
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
133
+			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 {
133 134
 				return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
134 135
 					Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
135 136
 						return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("advice_id = 0 AND project_id > 0").Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -139,7 +140,7 @@ func GetAllPatientChargeDetails(org_id int64, start_time int64, end_time int64,
139 140
 								return db.Select("id,good_name,good_unit,specification_name").Where("status = 1 ")
140 141
 							}).Where("status = 1 ")
141 142
 						})
142
-					}).Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
143
+					}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
143 144
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
144 145
 
145 146
 			break
@@ -155,32 +156,32 @@ func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, k
155 156
 	if len(keyword) == 0 {
156 157
 		switch item_type {
157 158
 		case 0:
158
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
159
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
159
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
160
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
160 161
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
161 162
 
162 163
 			break
163 164
 		case 1:
164
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
165
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id)
165
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
166
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id)
166 167
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
167 168
 
168 169
 			break
169 170
 		case 2:
170
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
171
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id)
171
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
172
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id)
172 173
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
173 174
 
174 175
 			break
175 176
 		case 3:
176
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
177
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id)
177
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
178
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id)
178 179
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
179 180
 
180 181
 			break
181 182
 		case 4:
182
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
183
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id)
183
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
184
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id)
184 185
 			}).Where("p.status = 1  AND p.user_org_id = ?", org_id).Group("id").Find(&patients).Error
185 186
 
186 187
 			break
@@ -191,32 +192,32 @@ func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, k
191 192
 		keyword = "%" + keyword + "%"
192 193
 		switch item_type {
193 194
 		case 0:
194
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
195
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
195
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
196
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
196 197
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
197 198
 
198 199
 			break
199 200
 		case 1:
200
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
201
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id)
201
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
202
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 1 ", start_time, end_time, org_id)
202 203
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
203 204
 
204 205
 			break
205 206
 		case 2:
206
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
207
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id)
207
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
208
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND is_medicine_insurance = 0", start_time, end_time, org_id)
208 209
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
209 210
 
210 211
 			break
211 212
 		case 3:
212
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
213
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id)
213
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
214
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 14", start_time, end_time, org_id)
214 215
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
215 216
 
216 217
 			break
217 218
 		case 4:
218
-			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.settle_accounts_date >= ? AND orders.settle_accounts_date <= ? AND orders.user_org_id = ? AND orders.order_status = 2", start_time, end_time, org_id).Preload("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
219
-				return db.Where("status = 1  AND settle_accounts_date >= ? AND settle_accounts_date <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id)
219
+			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("HisChargeSettleOrder", func(db *gorm.DB) *gorm.DB {
220
+				return db.Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2 AND med_type = 11", start_time, end_time, org_id)
220 221
 			}).Where("p.status = 1  AND p.user_org_id = ? AND p.name LIKE ?", org_id, keyword).Group("id").Find(&patients).Error
221 222
 
222 223
 			break
@@ -226,3 +227,65 @@ func GetAllPatientChargeSettle(org_id int64, start_time int64, end_time int64, k
226 227
 
227 228
 	return
228 229
 }
230
+
231
+func GetLabelPrintList(page int64, limit int64, user_org_id int64, record_time int64, is_print int64, keywors string) (labels []*models.HisLabelPrintInfo, total int64, err error) {
232
+	offset := (page - 1) * limit
233
+	db := readDb.Model(&models.HisLabelPrintInfo{})
234
+	if is_print > 0 {
235
+		db = db.Where("is_print = ?", is_print)
236
+	}
237
+	if len(keywors) > 0 {
238
+		keywors = "%" + keywors + "%"
239
+		db = db.Where("patient_name Like ?", keywors)
240
+
241
+	}
242
+	err = db.Where("user_org_id = ? AND record_date = ? AND status = 1 ", user_org_id, record_time).Count(&total).Offset(offset).Limit(limit).Find(&labels).Error
243
+	return
244
+}
245
+
246
+func GetLabelPrintInfo(id int64) (labels models.HisLabelPrintInfo, err error) {
247
+	db := readDb.Model(&models.HisLabelPrintInfo{})
248
+	err = db.Where("id = ?", id).First(&labels).Error
249
+	return
250
+}
251
+
252
+func AddSigleFapiaoRecord(dealer *models.HisFapiaoRecord) (err error, record *models.HisFapiaoRecord) {
253
+	err = writeDb.Create(&dealer).Error
254
+	return err, dealer
255
+}
256
+
257
+func ModifyFapiao(mesick *models.HisFapiaoRecord) error {
258
+	err := writeDb.Save(&mesick).Error
259
+
260
+	return err
261
+}
262
+
263
+func UpdateFapiaoIsUse(org_id int64) {
264
+	writeDb.Model(&models.HisFapiaoRecord{}).Where("user_org_id = ?", org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "is_use": 0})
265
+
266
+}
267
+
268
+func FindAllFapiaoList(orgId int64, page int64, limit int64) (list []*models.HisFapiaoRecord, total int64, err error) {
269
+	offset := (page - 1) * limit
270
+	db := readDb.Model(&models.HisFapiaoRecord{})
271
+	db = db.Where("user_org_id = ? AND status = 1", orgId)
272
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
273
+	return
274
+}
275
+
276
+func DeleteFapiaoById(id int64) error {
277
+	err := writeDb.Model(&models.HisFapiaoRecord{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
278
+	return err
279
+}
280
+
281
+func FindFapiaoById(id int64) (*models.HisFapiaoRecord, error) {
282
+	dealer := &models.HisFapiaoRecord{}
283
+	err := readDb.Model(&models.HisFapiaoRecord{}).Where("id = ? AND status = 1", id).First(&dealer).Error
284
+	return dealer, err
285
+}
286
+
287
+func FindFapiaoByIsUse(org_id int64) (models.HisFapiaoRecord, error) {
288
+	record := models.HisFapiaoRecord{}
289
+	err := readDb.Model(&models.HisFapiaoRecord{}).Where("user_org_id = ? AND status = 1 AND is_use = 1", org_id).First(&record).Error
290
+	return record, err
291
+}

+ 4 - 4
service/his_hospital_service.go View File

@@ -131,10 +131,10 @@ func GetUnChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_
131 131
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
132 132
 		}).
133 133
 		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
134
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
134
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
135 135
 		}).
136 136
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
137
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
137
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
138 138
 		}).
139 139
 		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3", org_id, record_date, patient_id).
140 140
 		Find(&prescription).Error
@@ -147,10 +147,10 @@ func GetChargeHisHospitalPrescriptionFive(org_id int64, patient_id int64, his_pa
147 147
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
148 148
 		}).
149 149
 		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
150
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
150
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
151 151
 		}).
152 152
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
153
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
153
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
154 154
 		}).
155 155
 		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 ", org_id, record_date, patient_id).
156 156
 		Find(&prescription).Error

+ 12 - 6
service/his_service.go View File

@@ -475,10 +475,10 @@ func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_
475 475
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
476 476
 		}).
477 477
 		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
478
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
478
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
479 479
 		}).
480 480
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
481
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
481
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
482 482
 		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
483 483
 		return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3  AND order_status <> 2  ", org_id)
484 484
 	}).
@@ -810,8 +810,14 @@ func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
810 810
 	return
811 811
 }
812 812
 
813
-func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
814
-	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
813
+func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
814
+	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
815
+	return
816
+
817
+}
818
+
819
+func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
820
+	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?  ", org_id, record_date, patient_id).First(&info).Error
815 821
 	return
816 822
 
817 823
 }
@@ -2086,10 +2092,10 @@ func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number
2086 2092
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
2087 2093
 		}).
2088 2094
 		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
2089
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
2095
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
2090 2096
 		}).
2091 2097
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
2092
-			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
2098
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
2093 2099
 		}).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
2094 2100
 		return db.Where("status = 1 AND user_org_id = ?", org_id)
2095 2101
 	}).

+ 38 - 15
service/manage_service.go View File

@@ -799,25 +799,48 @@ func GetAllEquitName(orgid int64) (equiment []*models.DeviceEquimentname, err er
799 799
 
800 800
 func GetUserForm(id int64, orgId int64, limit int64, page int64) (infor []*models.DeviceInformations, total int64, err error) {
801 801
 
802
-	db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
803
-	table := XTReadDB().Table("xt_patients as p")
804
-	fmt.Println("table", table)
805
-	dbs := UserReadDB().Table("sgj_user_admin_role as r")
806
-	fmt.Println("dbs", dbs)
807
-	offset := (page - 1) * limit
802
+	if orgId == 10060 {
803
+		db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
804
+		table := XTReadDB().Table("xt_patients as p")
805
+		fmt.Println("table", table)
806
+		dbs := UserReadDB().Table("sgj_user_admin_role as r")
807
+		fmt.Println("dbs", dbs)
808
+		offset := (page - 1) * limit
809
+
810
+		if id > 0 {
811
+			db = db.Where("x.equiment_id = ?", id)
812
+		}
808 813
 
809
-	if id > 0 {
810
-		db = db.Where("x.equiment_id = ?", id)
811
-	}
814
+		if orgId > 0 {
815
+			db = db.Where("x.user_org_id = ?", orgId)
816
+		}
817
+		err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Order("x.date asc").Scan(&infor).Error
818
+		if err != nil {
819
+			return
820
+		}
821
+		return
822
+	} else {
823
+		db := UserReadDB().Table("xt_device_information as x").Where("x.status = 1")
824
+		table := XTReadDB().Table("xt_patients as p")
825
+		fmt.Println("table", table)
826
+		dbs := UserReadDB().Table("sgj_user_admin_role as r")
827
+		fmt.Println("dbs", dbs)
828
+		offset := (page - 1) * limit
829
+
830
+		if id > 0 {
831
+			db = db.Where("x.equiment_id = ?", id)
832
+		}
812 833
 
813
-	if orgId > 0 {
814
-		db = db.Where("x.user_org_id = ?", orgId)
815
-	}
816
-	err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Order("x.date desc").Scan(&infor).Error
817
-	if err != nil {
834
+		if orgId > 0 {
835
+			db = db.Where("x.user_org_id = ?", orgId)
836
+		}
837
+		err = db.Group("x.id").Select("x.id,x.date,x.class,x.zone,x.bed_number,x.patient_id,x.contagion,x.dialysis_mode,x.start_time,x.end_time,x.dialysis_hour,x.hyperfiltratio,x.weight_loss,x.warning_value,x.user_total,x.move,x.failure_stage,x.fault_description,x.code_information,x.disinfect_type,x.disinfectant_type,x.disinfection,x.machine_run,x.fluid_path,x.disinfectant,x.disinfection_status,x.disinfection_residue,x.long_time,x.disinfec_startime,x.disinfec_endtime,x.dialysis_checked,x.dialysis_name,x.norms,x.dialysis_concentration,x.germ_checked,x.germ_name,x.germ_number,x.clean,x.sign_name,x.equiment_id,x.bed,p.name,r.user_name").Count(&total).Joins("Left Join sgj_xt.xt_patients as p on p.id = x.patient_id").Joins("Left Join sgj_user_admin_role as r on r.admin_user_id = x.sign_name").Offset(offset).Limit(limit).Order("x.date desc").Scan(&infor).Error
838
+		if err != nil {
839
+			return
840
+		}
818 841
 		return
819 842
 	}
820
-	return
843
+
821 844
 }
822 845
 
823 846
 func GetBedNumber(id int64, orgid int64) (models.DeviceAddmacher, error) {

+ 325 - 72
service/mobile_dialysis_service.go View File

@@ -1666,6 +1666,52 @@ func GetMobileHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay
1666 1666
 		db = db.Where("schedule_date =?", scheduleDate)
1667 1667
 	}
1668 1668
 	err = db.Find(&vms).Error
1669
+	if patientType == 0 {
1670
+		db := readDb.
1671
+			Table("xt_schedule").
1672
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1673
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1674
+				return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1675
+			}).
1676
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1677
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1678
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1679
+			Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
1680
+				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
1681
+			}).
1682
+			Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
1683
+				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
1684
+			}).
1685
+			Where("status = 1 AND user_org_id = ?", orgID)
1686
+		if scheduleDate != 0 {
1687
+			db = db.Where("schedule_date = ?", scheduleDate)
1688
+		}
1689
+		err = db.Find(&vms).Error
1690
+	}
1691
+
1692
+	if patientType > 0 {
1693
+		db := readDb.
1694
+			Table("xt_schedule").
1695
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
1696
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
1697
+				return db.Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
1698
+			}).
1699
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
1700
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
1701
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
1702
+			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
1703
+			Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
1704
+				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
1705
+			}).
1706
+			Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
1707
+				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
1708
+			}).
1709
+			Where("status = 1 AND user_org_id = ?", orgID)
1710
+		if scheduleDate != 0 {
1711
+			db = db.Where("schedule_date = ?", scheduleDate)
1712
+		}
1713
+		err = db.Find(&vms).Error
1714
+	}
1669 1715
 
1670 1716
 	return vms, err
1671 1717
 }
@@ -2575,7 +2621,7 @@ func MobileGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64
2575 2621
 			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ?  AND count > 0 ", orgID, scheduleDate)
2576 2622
 		}).
2577 2623
 		Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
2578
-			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
2624
+			return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?  ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0)  ", orgID).Where("status = 1 AND org_id = ? AND count > 0 AND record_time >= ? AND record_time <= ?  ", orgID, scheduleDate, end_time).Group("patient_id,good_id")
2579 2625
 		}).Where("sch.status = 1 AND sch.user_org_id = ?", orgID)
2580 2626
 	if scheduleDate != 0 {
2581 2627
 		db = db.Where("schedule_date = ?", scheduleDate)
@@ -2804,20 +2850,21 @@ func (HisMScheduleDoctorAdviceVMOne) TableName() string {
2804 2850
 }
2805 2851
 
2806 2852
 type HisMScheduleProjectVM struct {
2807
-	ID                     int64                            `gorm:"column:id" json:"id"`
2808
-	UserOrgId              int64                            `gorm:"column:user_org_id" json:"user_org_id"`
2809
-	PartitionId            int64                            `gorm:"column:partition_id" json:"partition_id"`
2810
-	BedId                  int64                            `gorm:"column:bed_id" json:"bed_id"`
2811
-	PatientId              int64                            `gorm:"column:patient_id" json:"patient_id"`
2812
-	ScheduleDate           int64                            `gorm:"column:schedule_date" json:"schedule_date"`
2813
-	ScheduleType           int64                            `gorm:"column:schedule_type" json:"schedule_type"`
2814
-	ModeId                 int64                            `gorm:"column:mode_id" json:"mode_id"`
2815
-	Status                 int64                            `gorm:"column:status" json:"status"`
2816
-	DialysisOrder          *MDialysisOrderVM                `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
2817
-	SchedualPatient        *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
2818
-	DeviceNumber           *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
2819
-	Prescription           *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
2820
-	HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
2853
+	ID                         int64                            `gorm:"column:id" json:"id"`
2854
+	UserOrgId                  int64                            `gorm:"column:user_org_id" json:"user_org_id"`
2855
+	PartitionId                int64                            `gorm:"column:partition_id" json:"partition_id"`
2856
+	BedId                      int64                            `gorm:"column:bed_id" json:"bed_id"`
2857
+	PatientId                  int64                            `gorm:"column:patient_id" json:"patient_id"`
2858
+	ScheduleDate               int64                            `gorm:"column:schedule_date" json:"schedule_date"`
2859
+	ScheduleType               int64                            `gorm:"column:schedule_type" json:"schedule_type"`
2860
+	ModeId                     int64                            `gorm:"column:mode_id" json:"mode_id"`
2861
+	Status                     int64                            `gorm:"column:status" json:"status"`
2862
+	DialysisOrder              *MDialysisOrderVM                `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
2863
+	SchedualPatient            *MSchedualPatientVM              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
2864
+	DeviceNumber               *MDeviceNumberVM                 `gorm:"ForeignKey:BedId" json:"device_number"`
2865
+	Prescription               *models.DialysisPrescriptionList `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
2866
+	HisPrescriptionProject     []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"project"`
2867
+	HisPrescriptionTeamProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"team_project"`
2821 2868
 }
2822 2869
 
2823 2870
 func (HisMScheduleProjectVM) TableName() string {
@@ -2884,76 +2931,157 @@ func GetHisDoctorAdviceCount(startime int64, endtime int64, deliveway string, or
2884 2931
 	return advice, err
2885 2932
 }
2886 2933
 
2887
-func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64) ([]*MScheduleDoctorAdviceVM, error) {
2934
+func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64) ([]*MScheduleDoctorAdviceVM, error) {
2888 2935
 	var vms []*MScheduleDoctorAdviceVM
2889 2936
 	adviceWhere := ""
2890 2937
 	adviceCondition := []interface{}{}
2891 2938
 	if adviceType == 0 {
2892 2939
 		if patientType == 0 {
2893
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
2894
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2940
+			if patient_id > 0 {
2941
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1) and patient_id = ?"
2942
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
2943
+			} else {
2944
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND (advice_type = 3 OR advice_type = 1)"
2945
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2946
+			}
2895 2947
 
2896 2948
 		} else if patientType == 1 {
2897
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
2898
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
2949
+			if patient_id > 0 {
2950
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1) and patient_id = ?"
2951
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
2952
+			} else {
2953
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_doctor = ? AND(advice_type = 3 OR advice_type = 1)"
2954
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
2955
+			}
2899 2956
 
2900 2957
 		} else if patientType == 2 {
2901
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
2902
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2958
+			if patient_id > 0 {
2959
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1 and patient_id = ?)"
2960
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
2961
+			} else {
2962
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND execution_staff = 0 AND(advice_type = 3 OR advice_type = 1)"
2963
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2964
+			}
2965
+
2903 2966
 		}
2904 2967
 
2905 2968
 	} else if adviceType == 1 {
2906 2969
 		if patientType == 0 {
2907
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
2908
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2970
+			if patient_id > 0 {
2971
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? and patient_id = ? "
2972
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
2973
+			} else {
2974
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ?  "
2975
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2976
+			}
2909 2977
 
2910 2978
 		} else if patientType == 1 {
2911
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
2912
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
2979
+			if patient_id > 0 {
2980
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? and patient_id = ?"
2981
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
2982
+			} else {
2983
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND advice_doctor = ? "
2984
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
2985
+			}
2913 2986
 
2914 2987
 		} else if patientType == 2 {
2915
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
2916
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2988
+			if patient_id > 0 {
2989
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0 and patient_id = ?"
2990
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
2991
+			} else {
2992
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 1 AND record_date = ? AND execution_staff = 0"
2993
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
2994
+			}
2917 2995
 
2918 2996
 		}
2919 2997
 
2920 2998
 	} else if adviceType == 3 {
2921 2999
 		if patientType == 0 {
2922
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
2923
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3000
+			if patient_id > 0 {
3001
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ? and patient_id = ?  "
3002
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3003
+			} else {
3004
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 3 AND record_date = ?  "
3005
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3006
+			}
2924 3007
 
2925 3008
 		} else if patientType == 1 {
2926
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
2927
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3009
+			if patient_id > 0 {
3010
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? and patient_id = ?"
3011
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3012
+			} else {
3013
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3 AND advice_doctor = ? "
3014
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3015
+			}
3016
+
2928 3017
 		} else if patientType == 2 {
2929
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
2930
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3018
+			if patient_id > 0 {
3019
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0 and patient_id = ?"
3020
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3021
+			} else {
3022
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 3  AND execution_staff = 0"
3023
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3024
+			}
3025
+
2931 3026
 		}
2932 3027
 
2933 3028
 	} else if adviceType == 2 && len(deliverWay) > 0 {
2934 3029
 		if patientType == 0 {
2935
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
2936
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3030
+			if patient_id > 0 {
3031
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ? and patient_id = ?"
3032
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay, patient_id)
3033
+			} else {
3034
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and delivery_way = ?"
3035
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3036
+			}
2937 3037
 
2938 3038
 		} else if patientType == 1 {
2939
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
2940
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
3039
+			if patient_id > 0 {
3040
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? and patient_id = ?"
3041
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay, patient_id)
3042
+			} else {
3043
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?  and delivery_way = ? "
3044
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, deliverWay)
3045
+			}
3046
+
2941 3047
 		} else if patientType == 2 {
2942
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
2943
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3048
+			if patient_id > 0 {
3049
+
3050
+			} else {
3051
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and delivery_way = ?"
3052
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, deliverWay)
3053
+			}
3054
+
2944 3055
 		}
2945 3056
 
2946 3057
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
2947 3058
 		if patientType == 0 {
2948
-			adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
2949
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3059
+			if patient_id > 0 {
3060
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and patient_id = ?"
3061
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3062
+			} else {
3063
+				adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
3064
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3065
+			}
2950 3066
 
2951 3067
 		} else if patientType == 1 {
2952
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
2953
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3068
+			if patient_id > 0 {
3069
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ? and patient_id = ?"
3070
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId, patient_id)
3071
+			} else {
3072
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2 AND advice_doctor = ?"
3073
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, adminUserId)
3074
+			}
3075
+
2954 3076
 		} else if patientType == 2 {
2955
-			adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
2956
-			adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3077
+			if patient_id > 0 {
3078
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0 and patient_id = ?"
3079
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, patient_id)
3080
+			} else {
3081
+				adviceWhere = "status = 1 AND user_org_id = ? AND record_date = ? AND advice_type = 2  AND execution_staff = 0"
3082
+				adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
3083
+			}
3084
+
2957 3085
 		}
2958 3086
 
2959 3087
 	}
@@ -2983,7 +3111,7 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
2983 3111
 	return vms, err
2984 3112
 }
2985 3113
 
2986
-func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64) ([]*HisMScheduleDoctorAdviceVM, error) {
3114
+func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string, scheduleType int64, partitionType int64, patient_id int64) ([]*HisMScheduleDoctorAdviceVM, error) {
2987 3115
 
2988 3116
 	var vms []*HisMScheduleDoctorAdviceVM
2989 3117
 	if len(deliverWay) > 0 {
@@ -2994,19 +3122,36 @@ func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string,
2994 3122
 		if partitionType > 0 {
2995 3123
 			db = db.Where("partition_id = ?", partitionType)
2996 3124
 		}
2997
-		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
2998
-			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
2999
-			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3000
-			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3001
-			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
3002
-			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3003
-				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3004
-			}).
3005
-			Where("status = 1 AND user_org_id = ?", orgID)
3006
-		if scheduleDate != 0 {
3007
-			db = db.Where("schedule_date = ?", scheduleDate)
3125
+		if patient_id > 0 {
3126
+			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id =?", orgID, patient_id).
3127
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3128
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3129
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3130
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ? and patient_id = ?", orgID, scheduleDate, deliverWay, patient_id).
3131
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3132
+					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3133
+				}).
3134
+				Where("status = 1 AND user_org_id = ?", orgID)
3135
+			if scheduleDate != 0 {
3136
+				db = db.Where("schedule_date = ?", scheduleDate)
3137
+			}
3138
+			err = db.Find(&vms).Error
3139
+		} else {
3140
+			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3141
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3142
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3143
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3144
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and delivery_way = ?", orgID, scheduleDate, deliverWay).
3145
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3146
+					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3147
+				}).
3148
+				Where("status = 1 AND user_org_id = ?", orgID)
3149
+			if scheduleDate != 0 {
3150
+				db = db.Where("schedule_date = ?", scheduleDate)
3151
+			}
3152
+			err = db.Find(&vms).Error
3008 3153
 		}
3009
-		err = db.Find(&vms).Error
3154
+
3010 3155
 	} else {
3011 3156
 		db := readDb.Table("xt_schedule")
3012 3157
 		if scheduleType > 0 {
@@ -3015,19 +3160,36 @@ func GetHisDoctorAdvicesOne(orgID int64, scheduleDate int64, deliverWay string,
3015 3160
 		if partitionType > 0 {
3016 3161
 			db = db.Where("partition_id = ?", partitionType)
3017 3162
 		}
3018
-		db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3019
-			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3020
-			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3021
-			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3022
-			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
3023
-			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3024
-				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3025
-			}).
3026
-			Where("status = 1 AND user_org_id = ?", orgID)
3027
-		if scheduleDate != 0 {
3028
-			db = db.Where("schedule_date = ?", scheduleDate)
3163
+		if patient_id > 0 {
3164
+			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id = ?", orgID, patient_id).
3165
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3166
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3167
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3168
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3169
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3170
+					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3171
+				}).
3172
+				Where("status = 1 AND user_org_id = ?", orgID)
3173
+			if scheduleDate != 0 {
3174
+				db = db.Where("schedule_date = ?", scheduleDate)
3175
+			}
3176
+			err = db.Find(&vms).Error
3177
+		} else {
3178
+			db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3179
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3180
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3181
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3182
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ?", orgID, scheduleDate).
3183
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3184
+					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3185
+				}).
3186
+				Where("status = 1 AND user_org_id = ?", orgID)
3187
+			if scheduleDate != 0 {
3188
+				db = db.Where("schedule_date = ?", scheduleDate)
3189
+			}
3190
+			err = db.Find(&vms).Error
3029 3191
 		}
3030
-		err = db.Find(&vms).Error
3192
+
3031 3193
 	}
3032 3194
 
3033 3195
 	return vms, err
@@ -3157,8 +3319,99 @@ func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64
3157 3319
 	return
3158 3320
 }
3159 3321
 
3160
-func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64) ([]*HisMScheduleProjectVM, error) {
3322
+func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64) ([]*HisMScheduleProjectVM, error) {
3161 3323
 	var vms []*HisMScheduleProjectVM
3324
+
3325
+	if patientType == 0 {
3326
+
3327
+		if patient_id > 0 {
3328
+			db := readDb.
3329
+				Table("xt_schedule").
3330
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3331
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3332
+					return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3333
+				}).
3334
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3335
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3336
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3337
+				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3338
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3339
+				}).
3340
+				Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3341
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3342
+				}).Where("status = 1 AND user_org_id = ?", orgID)
3343
+			if scheduleDate != 0 {
3344
+				db = db.Where("schedule_date = ?", scheduleDate)
3345
+			}
3346
+			err = db.Find(&vms).Error
3347
+		} else {
3348
+			if patient_id > 0 {
3349
+				db := readDb.
3350
+					Table("xt_schedule").
3351
+					Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3352
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3353
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3354
+					}).
3355
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3356
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3357
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3358
+					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3359
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3360
+					}).
3361
+					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3362
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3363
+					}).Where("status = 1 AND user_org_id = ?", orgID)
3364
+				if scheduleDate != 0 {
3365
+					db = db.Where("schedule_date = ?", scheduleDate)
3366
+				}
3367
+				err = db.Find(&vms).Error
3368
+			} else {
3369
+				db := readDb.
3370
+					Table("xt_schedule").
3371
+					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3372
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3373
+						return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3374
+					}).
3375
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3376
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3377
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3378
+					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3379
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3380
+					}).
3381
+					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3382
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3383
+					}).Where("status = 1 AND user_org_id = ?", orgID)
3384
+				if scheduleDate != 0 {
3385
+					db = db.Where("schedule_date = ?", scheduleDate)
3386
+				}
3387
+				err = db.Find(&vms).Error
3388
+			}
3389
+		}
3390
+
3391
+	}
3392
+
3393
+	if patientType > 0 {
3394
+		db := readDb.
3395
+			Table("xt_schedule").
3396
+			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3397
+			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3398
+				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3399
+			}).
3400
+			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3401
+			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3402
+			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3403
+			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
3404
+			Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3405
+				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3406
+			}).
3407
+			Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3408
+				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3409
+			}).Where("status = 1 AND user_org_id = ?", orgID)
3410
+		if scheduleDate != 0 {
3411
+			db = db.Where("schedule_date = ?", scheduleDate)
3412
+		}
3413
+		err = db.Find(&vms).Error
3414
+	}
3162 3415
 	//if patientType == 0 {
3163 3416
 	//	db := readDb.
3164 3417
 	//		Table("xt_schedule").

+ 1 - 1
service/patient_schedule_template_service.go View File

@@ -422,7 +422,7 @@ func SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode *m
422 422
 	nextMonday, _ := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
423 423
 	nextSecWeek := now.AddDate(0, 0, 14)
424 424
 	_, nextSecSunday := utils.GetMondayAndSundayOfWeekDate(&nextSecWeek)
425
-	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "mtime": now.Unix()}).Error
425
+	disableErr := tx.Model(&models.Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date >= ? AND schedule_date <= ?", templateMode.OrgID, nextMonday.Unix(), nextSecSunday.Unix()).Updates(map[string]interface{}{"status": 0, "updated_time": now.Unix()}).Error
426 426
 	if disableErr != nil {
427 427
 		tx.Rollback()
428 428
 		return disableErr

+ 65 - 551
service/patient_service.go View File

@@ -67,7 +67,7 @@ func GetPatientList(orgID int64, keywords string, page, limit, schedulType, bind
67 67
 
68 68
 	offset := (page - 1) * limit
69 69
 
70
-	err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
70
+	err = db.Order("p.id desc").Select(" p.id, p.user_org_id, p.user_id, p.patient_type, p.dialysis_no, p.admission_number, p.source, p.lapseto, p.partition_id, p.bed_id, p.name, p.alias, p.gender, p.marital_status, p.id_card_no, p.birthday, p.reimbursement_way_id, p.health_care_type, p.health_care_no, p.health_care_due_date, p.height, p.blood_type, p.rh, p.health_care_due_alert_date, p.education_level, p.profession, p.phone, p.home_telephone, p.relative_phone, p.relative_relations, p.home_address, p.work_unit, p.unit_address, p.children, p.receiving_date, p.is_hospital_first_dialysis, p.first_dialysis_date, p.first_dialysis_hospital, p.induction_period, p.initial_dialysis, p.total_dialysis, p.attending_doctor_id, p.head_nurse_id, p.evaluate, p.diagnose, p.remark, p.registrars_id, p.registrars, p.qr_code, p.binding_state, p.status, p.created_time, p.updated_time,p.user_sys_before_count,p.out_reason,p.death_time,p.is_infectious").Group("p.id").Count(&total).Offset(offset).Limit(limit).Find(&patients).Error
71 71
 	return
72 72
 }
73 73
 
@@ -1179,7 +1179,7 @@ func GetDoctorAdviceListOne(orgID, patientID, advice_type, stop, start, end int6
1179 1179
 		db = db.Where("x.start_time>=?", start)
1180 1180
 	}
1181 1181
 	if end != 0 {
1182
-		db = db.Where("start_time<=?", end)
1182
+		db = db.Where("x.start_time<=?", end)
1183 1183
 	}
1184 1184
 	if len(keywords) > 0 {
1185 1185
 		likeKey := "%" + keywords + "%"
@@ -1222,7 +1222,7 @@ func GetDoctorAdviceListTwo(orgID int64, patientID int64, advice_type int64, sto
1222 1222
 		db = db.Where("x.start_time>=?", start)
1223 1223
 	}
1224 1224
 	if end != 0 {
1225
-		db = db.Where("start_time<=?", end)
1225
+		db = db.Where("x.start_time<=?", end)
1226 1226
 	}
1227 1227
 	if len(keywords) > 0 {
1228 1228
 		likeKey := "%" + keywords + "%"
@@ -1338,7 +1338,7 @@ func GetPatientDialysisRecord(orgID, patientID int64, page, limit, start, end, m
1338 1338
 		}).
1339 1339
 		Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
1340 1340
 		Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
1341
-		Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
1341
+		Where("do.patient_id=? and do.user_org_id=?  and do.status=1", patientID, orgID).Group("s.schedule_date")
1342 1342
 
1343 1343
 	if start != 0 {
1344 1344
 		db = db.Where("do.dialysis_date>=?", start)
@@ -1461,6 +1461,7 @@ func MobileGetMonitorsWithPatient(orgID int64, keyword string, page int) ([]*mod
1461 1461
 
1462 1462
 func GetPatientByKeyWord(orgID int64, keywords string) (patient []*models.Patients, err error) {
1463 1463
 	db := readDb.Model(&models.Patients{}).Where("user_org_id=? and status=1", orgID)
1464
+	fmt.Println("keywords22222223322332322332322323323", keywords)
1464 1465
 	if len(keywords) > 0 {
1465 1466
 		likekey := "%" + keywords + "%"
1466 1467
 		err = db.Where("name LIKE ? OR dialysis_no LIKE ? ", likekey, likekey).Find(&patient).Error
@@ -1538,7 +1539,7 @@ func UpdateDoctorAdviceAndSubAdvice(m *models.DoctorAdvice) (err error) {
1538 1539
 		ut.Rollback()
1539 1540
 		return
1540 1541
 	}
1541
-	err = ut.Model(&models.DoctorAdvice{}).Where("status = 1   AND parent_id IN (?)", m.ID).Updates(map[string]interface{}{"start_time": m.StartTime, "groupno": m.GroupNo, "mtime": time.Now().Unix()}).Error
1542
+	err = ut.Model(&models.DoctorAdvice{}).Where("status = 1   AND parent_id IN (?)", m.ID).Updates(map[string]interface{}{"start_time": m.StartTime, "groupno": m.GroupNo, "updated_time": time.Now().Unix()}).Error
1542 1543
 	if err != nil {
1543 1544
 		ut.Rollback()
1544 1545
 		return
@@ -1872,575 +1873,88 @@ func UpdateScheduleItemByPatientId(id int64) error {
1872 1873
 	return err
1873 1874
 }
1874 1875
 
1875
-func GetAllDeviceNumberByList(orgID int64) (number []*models.DeviceNumber, err error) {
1876
-	redis := RedisClient()
1877
-	defer redis.Close()
1878
-	key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
1879
-	number_info_str, _ := redis.Get(key).Result()
1880
-	if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1881
-		err = readDb.Model(&models.DeviceNumber{}).Where("org_id=? and status=1", orgID).Find(&number).Error
1882
-		if err != nil {
1883
-			if err == gorm.ErrRecordNotFound {
1884
-				return nil, nil
1885
-			} else {
1886
-				return nil, err
1887
-			}
1888
-		} else {
1889
-			if len(number) > 0 {
1890
-				//缓存数据
1891
-				device_number_json, err := json.Marshal(&number)
1892
-				if err == nil {
1893
-					redis.Set(key, device_number_json, time.Second*60*60*18)
1894
-				}
1895
-			}
1896
-			return number, nil
1897
-		}
1898
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1899
-		json.Unmarshal([]byte(number_info_str), &number)
1900
-		return number, nil
1901
-	}
1902
-}
1903
-
1904
-func GetAllZoneByList(orgID int64) (zone []*models.DeviceZone, err error) {
1876
+func GetDoctorAdviceListThree(orgID, patientID, advice_type, stop, start, end int64, keywords string, page int64, limit int64) (advices []*models.HisDoctorAdvice, total int64, err error) {
1905 1877
 
1906
-	redis := RedisClient()
1907
-	defer redis.Close()
1908
-	key := strconv.FormatInt(orgID, 10) + ":" + ":device_zone_all"
1909
-	zone_info_str, _ := redis.Get(key).Result()
1910
-	if len(zone_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1911
-		err = readDb.Model(&models.DeviceZone{}).Where("org_id=? and status=1", orgID).Find(&zone).Error
1912
-		if err != nil {
1913
-			if err == gorm.ErrRecordNotFound {
1914
-				return nil, nil
1915
-			} else {
1916
-				return nil, err
1917
-			}
1918
-		} else {
1919
-			if len(zone) > 0 {
1920
-				//缓存数据
1921
-				zone_number_json, err := json.Marshal(&zone)
1922
-				if err == nil {
1923
-					redis.Set(key, zone_number_json, time.Second*60*60*18)
1924
-				}
1925
-			}
1926
-			return zone, nil
1927
-		}
1928
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1929
-		json.Unmarshal([]byte(zone_info_str), &zone)
1930
-		return zone, nil
1878
+	db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
1879
+	table := UserReadDB().Table("sgj_user_admin_role as r")
1880
+	fmt.Print("table", table)
1881
+	if orgID > 0 {
1882
+		db = db.Where("x.user_org_id=?", orgID)
1931 1883
 	}
1932
-}
1933
-
1934
-func GetAllPrescriptionByList(orgID int64, scheduleDate int64) (prescriptions []*models.VMDialysisPrescription, err error) {
1935
-
1936
-	redis := RedisClient()
1937
-	defer redis.Close()
1938
-	key := strconv.FormatInt(orgID, 10) + ":" + ":prescriptions_list_all"
1939
-	prescriptions_list_all, _ := redis.Get(key).Result()
1940
-
1941
-	if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1942
-		err = readDb.Model(&models.VMDialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
1943
-		if err != nil {
1944
-			if err == gorm.ErrRecordNotFound {
1945
-				return nil, nil
1946
-			} else {
1947
-				return nil, err
1948
-			}
1949
-		} else {
1950
-			if len(prescriptions) > 0 {
1951
-				//缓存数据
1952
-				prescriptions_list_all, err := json.Marshal(&prescriptions)
1953
-				if err == nil {
1954
-					redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
1955
-				}
1956
-			}
1957
-			return prescriptions, nil
1958
-		}
1959
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1960
-		json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
1961
-		return prescriptions, nil
1884
+	if patientID > 0 {
1885
+		db = db.Where("x.patient_id = ?", patientID)
1962 1886
 	}
1963
-}
1964
-
1965
-func GetAllAssessmentBeforesByListOne(orgID int64, scheduleDate int64) (assessmentBefores []*models.VMPredialysisEvaluation, err error) {
1966
-	redis := RedisClient()
1967
-	defer redis.Close()
1968
-	key := strconv.FormatInt(orgID, 10) + ":" + ":assessment_befores_list_all"
1969
-	assessment_befores_list_all, _ := redis.Get(key).Result()
1970
-
1971
-	if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1972
-		err = readDb.Model(&models.VMPredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
1973
-		if err != nil {
1974
-			if err == gorm.ErrRecordNotFound {
1975
-				return nil, nil
1976
-			} else {
1977
-				return nil, err
1978
-			}
1979
-		} else {
1980
-			if len(assessmentBefores) > 0 {
1981
-				//缓存数据
1982
-				assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
1983
-				if err == nil {
1984
-					redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
1985
-				}
1986
-			}
1987
-			return assessmentBefores, nil
1988
-		}
1989
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
1990
-		json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
1991
-		return assessmentBefores, nil
1887
+	if advice_type == 1 && advice_type > 0 {
1888
+		db = db.Where("x.advice_type = ?", advice_type)
1992 1889
 	}
1993
-}
1994
-
1995
-func GetAllDialysisOrdersByListOne(orgID int64, scheduleDate int64) (dialysisOrders []*models.VMMonitorDialysisOrder, err error) {
1996
-	redis := RedisClient()
1997
-	defer redis.Close()
1998
-	key := strconv.FormatInt(orgID, 10) + ":" + ":dialysis_orders_list_all"
1999
-	dialysis_orders_list_all, _ := redis.Get(key).Result()
2000
-
2001
-	if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2002
-		err = readDb.Model(&models.VMMonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
2003
-		if err != nil {
2004
-			if err == gorm.ErrRecordNotFound {
2005
-				return nil, nil
2006
-			} else {
2007
-				return nil, err
2008
-			}
2009
-		} else {
2010
-			if len(dialysisOrders) > 0 {
2011
-				//缓存数据
2012
-				dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
2013
-				if err == nil {
2014
-					redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
2015
-				}
2016
-			}
2017
-			return dialysisOrders, nil
2018
-		}
2019
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2020
-		json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
2021
-		return dialysisOrders, nil
1890
+	if advice_type == 3 && advice_type > 0 {
1891
+		db = db.Where("x.advice_type = 2 or x.advice_type = 3")
2022 1892
 	}
2023
-}
2024
-
2025
-func GetAllAssessmentAfterDislysisByListOne(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.VMAssessmentAfterDislysis, err error) {
2026
-	redis := RedisClient()
2027
-	defer redis.Close()
2028
-	key := strconv.FormatInt(orgID, 10) + ":" + ":assessment_after_dislysis_list_all"
2029
-	assessment_after_dislysis__all, _ := redis.Get(key).Result()
2030
-
2031
-	if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2032
-		err = readDb.Model(&models.VMAssessmentAfterDislysis{}).Where("status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
2033
-		if err != nil {
2034
-			if err == gorm.ErrRecordNotFound {
2035
-				return nil, nil
2036
-			} else {
2037
-				return nil, err
2038
-			}
2039
-		} else {
2040
-			if len(assessmentAfterDislysis) > 0 {
2041
-				//缓存数据
2042
-				assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
2043
-				if err == nil {
2044
-					redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
2045
-				}
2046
-			}
2047
-			return assessmentAfterDislysis, nil
2048
-		}
2049
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2050
-		json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
2051
-		return assessmentAfterDislysis, nil
1893
+	if advice_type == 4 && advice_type > 0 {
1894
+		db = db.Where("x.advice_type = 4")
2052 1895
 	}
2053
-}
2054
-
2055
-func GetAllMonitorList(orgID int64, scheduleDate int64) (monitor []*models.VMMonitoringRecord, err error) {
2056
-
2057
-	redis := RedisClient()
2058
-	defer redis.Close()
2059
-	key := strconv.FormatInt(orgID, 10) + ":" + ":monitor_record_list_all"
2060
-	monitor_record_list_all, _ := redis.Get(key).Result()
2061
-	fmt.Println("monitor_recorde_list", len(monitor_record_list_all))
2062
-	if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2063
-		err = readDb.Model(&models.VMMonitoringRecord{}).Where("status = 1  AND user_org_id = ? AND  monitoring_date= ?", orgID, scheduleDate).Find(&monitor).Error
2064
-		if err != nil {
2065
-			if err == gorm.ErrRecordNotFound {
2066
-				return nil, nil
2067
-			} else {
2068
-				return nil, err
2069
-			}
2070
-		} else {
2071
-			if len(monitor) > 0 {
2072
-				//缓存数据
2073
-				assessment_after_dislysis__all, err := json.Marshal(&monitor)
2074
-				if err == nil {
2075
-					redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
2076
-				}
2077
-			}
2078
-			return monitor, nil
2079
-		}
2080
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2081
-		json.Unmarshal([]byte(monitor_record_list_all), &monitor)
2082
-		return monitor, nil
1896
+	if stop == 1 {
1897
+		db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
1898
+	} else if stop == 2 {
1899
+		db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
2083 1900
 	}
2084
-}
2085 1901
 
2086
-func GetAllPatientListByListOne(orgID int64) (patients []*models.VMMonitorPatients, err error) {
2087
-	redis := RedisClient()
2088
-	defer redis.Close()
2089
-	key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
2090
-	patient_info_str, _ := redis.Get(key).Result()
2091
-
2092
-	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2093
-		err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
2094
-		if err != nil {
2095
-			if err == gorm.ErrRecordNotFound {
2096
-				return nil, nil
2097
-			} else {
2098
-				return nil, err
2099
-			}
2100
-		} else {
2101
-			if len(patients) > 0 {
2102
-				//缓存数据
2103
-				patient_info_json, err := json.Marshal(&patients)
2104
-				if err == nil {
2105
-					redis.Set(key, patient_info_json, time.Second*60*60*18)
2106
-				}
2107
-			}
2108
-			return patients, nil
2109
-		}
2110
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2111
-		json.Unmarshal([]byte(patient_info_str), &patients)
2112
-		return patients, nil
1902
+	if start != 0 {
1903
+		db = db.Where("x.start_time>=?", start)
2113 1904
 	}
2114
-}
2115
-
2116
-func GetAllTreatModeByList(orgID int64) (treatement []*models.TreatmentMode, err error) {
2117
-	redis := RedisClient()
2118
-	defer redis.Close()
2119
-	key := strconv.FormatInt(orgID, 10) + ":" + ":treatement_mode_all"
2120
-	treatment_info_str, _ := redis.Get(key).Result()
2121
-
2122
-	if len(treatment_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2123
-		err = readDb.Model(&models.TreatmentMode{}).Where("status=1").Find(&treatement).Error
2124
-		if err != nil {
2125
-			if err == gorm.ErrRecordNotFound {
2126
-				return nil, nil
2127
-			} else {
2128
-				return nil, err
2129
-			}
2130
-		} else {
2131
-			if len(treatement) > 0 {
2132
-				//缓存数据
2133
-				patient_info_json, err := json.Marshal(&treatement)
2134
-				if err == nil {
2135
-					redis.Set(key, patient_info_json, time.Second*60*60*18)
2136
-				}
2137
-			}
2138
-			return treatement, nil
2139
-		}
2140
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2141
-		json.Unmarshal([]byte(treatment_info_str), &treatement)
2142
-		return treatement, nil
1905
+	if end != 0 {
1906
+		db = db.Where("x.start_time<=?", end)
2143 1907
 	}
1908
+	if len(keywords) > 0 {
1909
+		likeKey := "%" + keywords + "%"
1910
+		db = db.Where("x.advice_name LIKE ?", likeKey)
1911
+	}
1912
+	offset := (page - 1) * limit
1913
+	err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&advices).Error
1914
+	fmt.Print("err", err)
1915
+	return
2144 1916
 }
2145 1917
 
2146
-func GetAllPatientListByListTwo(orgID int64) (patients []*MSchedualPatientVM, err error) {
2147
-	redis := RedisClient()
2148
-	defer redis.Close()
2149
-	key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
2150
-	patient_info_str, _ := redis.Get(key).Result()
1918
+func GetDoctorAdviceListFour(orgID int64, patientID int64, advice_type int64, stop int64, start int64, end int64, keywords string, limit int64, page int64) (advices []*models.HisDoctorAdvice, total int64, err error) {
2151 1919
 
2152
-	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2153
-		err = readDb.Model(&MSchedualPatientVM{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
2154
-		if err != nil {
2155
-			if err == gorm.ErrRecordNotFound {
2156
-				return nil, nil
2157
-			} else {
2158
-				return nil, err
2159
-			}
2160
-		} else {
2161
-			if len(patients) > 0 {
2162
-				//缓存数据
2163
-				patient_info_json, err := json.Marshal(&patients)
2164
-				if err == nil {
2165
-					redis.Set(key, patient_info_json, time.Second*60*60*18)
2166
-				}
2167
-			}
2168
-			return patients, nil
2169
-		}
2170
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2171
-		json.Unmarshal([]byte(patient_info_str), &patients)
2172
-		return patients, nil
1920
+	db := readDb.Table("his_doctor_advice_info as x").Where("x.status = 1")
1921
+	table := UserReadDB().Table("sgj_user_admin_role as r")
1922
+	fmt.Println(table)
1923
+	if orgID > 0 {
1924
+		db = db.Where("x.user_org_id=?", orgID)
2173 1925
 	}
2174
-}
2175
-
2176
-func GetAllDeviceNumberByListOne(orgID int64) (number []*MDeviceNumberVM, err error) {
2177
-	redis := RedisClient()
2178
-	defer redis.Close()
2179
-	key := strconv.FormatInt(orgID, 10) + ":" + ":device_number_all"
2180
-	number_info_str, _ := redis.Get(key).Result()
2181
-	if len(number_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2182
-		err = readDb.Model(&MDeviceNumberVM{}).Where("org_id=? and status=1", orgID).Find(&number).Error
2183
-		if err != nil {
2184
-			if err == gorm.ErrRecordNotFound {
2185
-				return nil, nil
2186
-			} else {
2187
-				return nil, err
2188
-			}
2189
-		} else {
2190
-			if len(number) > 0 {
2191
-				//缓存数据
2192
-				device_number_json, err := json.Marshal(&number)
2193
-				if err == nil {
2194
-					redis.Set(key, device_number_json, time.Second*60*60*18)
2195
-				}
2196
-			}
2197
-			return number, nil
2198
-		}
2199
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2200
-		json.Unmarshal([]byte(number_info_str), &number)
2201
-		return number, nil
1926
+	if patientID > 0 {
1927
+		db = db.Where("x.patient_id = ?", patientID)
2202 1928
 	}
2203
-}
2204
-
2205
-func GetAllPrescriptionByListOne(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescriptionList, err error) {
2206
-
2207
-	redis := RedisClient()
2208
-	defer redis.Close()
2209
-	key := strconv.FormatInt(orgID, 10) + ":" + ":prescriptions_list_all"
2210
-	prescriptions_list_all, _ := redis.Get(key).Result()
2211
-
2212
-	if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2213
-		err = readDb.Model(&models.DialysisPrescriptionList{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
2214
-		if err != nil {
2215
-			if err == gorm.ErrRecordNotFound {
2216
-				return nil, nil
2217
-			} else {
2218
-				return nil, err
2219
-			}
2220
-		} else {
2221
-			if len(prescriptions) > 0 {
2222
-				//缓存数据
2223
-				prescriptions_list_all, err := json.Marshal(&prescriptions)
2224
-				if err == nil {
2225
-					redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
2226
-				}
2227
-			}
2228
-			return prescriptions, nil
2229
-		}
2230
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2231
-		json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
2232
-		return prescriptions, nil
1929
+	if advice_type == 1 {
1930
+		db = db.Where("x.advice_type = ?", advice_type)
2233 1931
 	}
2234
-}
2235
-
2236
-func GetAllDialysisOrdersByListTwo(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVM, err error) {
2237
-	redis := RedisClient()
2238
-	defer redis.Close()
2239
-	key := strconv.FormatInt(orgID, 10) + ":" + ":dialysis_orders_list_all"
2240
-	dialysis_orders_list_all, _ := redis.Get(key).Result()
2241
-
2242
-	if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2243
-		err = readDb.Model(&MDialysisOrderVM{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
2244
-		if err != nil {
2245
-			if err == gorm.ErrRecordNotFound {
2246
-				return nil, nil
2247
-			} else {
2248
-				return nil, err
2249
-			}
2250
-		} else {
2251
-			if len(dialysisOrders) > 0 {
2252
-				//缓存数据
2253
-				dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
2254
-				if err == nil {
2255
-					redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
2256
-				}
2257
-			}
2258
-			return dialysisOrders, nil
2259
-		}
2260
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2261
-		json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
2262
-		return dialysisOrders, nil
1932
+	if advice_type == 3 && advice_type > 0 {
1933
+		db = db.Where("x.advice_type = 2 or x.advice_type = 3")
2263 1934
 	}
2264
-}
2265
-
2266
-func GetAllPatientListByListThree(orgID int64) (patients []*models.MonitorPatients, err error) {
2267
-	redis := RedisClient()
2268
-	defer redis.Close()
2269
-	key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all"
2270
-	patient_info_str, _ := redis.Get(key).Result()
2271
-
2272
-	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2273
-		err = readDb.Model(&models.MonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
2274
-		if err != nil {
2275
-			if err == gorm.ErrRecordNotFound {
2276
-				return nil, nil
2277
-			} else {
2278
-				return nil, err
2279
-			}
2280
-		} else {
2281
-			if len(patients) > 0 {
2282
-				//缓存数据
2283
-				patient_info_json, err := json.Marshal(&patients)
2284
-				if err == nil {
2285
-					redis.Set(key, patient_info_json, time.Second*60*60*18)
2286
-				}
2287
-			}
2288
-			return patients, nil
2289
-		}
2290
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2291
-		json.Unmarshal([]byte(patient_info_str), &patients)
2292
-		return patients, nil
1935
+	if advice_type == 4 && advice_type > 0 {
1936
+		db = db.Where("x.advice_type = 4")
2293 1937
 	}
2294
-}
2295 1938
 
2296
-func GetAllPrescriptionByListTwo(orgID int64, scheduleDate int64) (prescriptions []*models.DialysisPrescription, err error) {
2297
-
2298
-	redis := RedisClient()
2299
-	defer redis.Close()
2300
-	key := strconv.FormatInt(orgID, 10) + ":" + ":prescriptions_list_all"
2301
-	prescriptions_list_all, _ := redis.Get(key).Result()
2302
-
2303
-	if len(prescriptions_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2304
-		err = readDb.Model(&models.DialysisPrescription{}).Where("status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).Find(&prescriptions).Error
2305
-		if err != nil {
2306
-			if err == gorm.ErrRecordNotFound {
2307
-				return nil, nil
2308
-			} else {
2309
-				return nil, err
2310
-			}
2311
-		} else {
2312
-			if len(prescriptions) > 0 {
2313
-				//缓存数据
2314
-				prescriptions_list_all, err := json.Marshal(&prescriptions)
2315
-				if err == nil {
2316
-					redis.Set(key, prescriptions_list_all, time.Second*60*60*18)
2317
-				}
2318
-			}
2319
-			return prescriptions, nil
2320
-		}
2321
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2322
-		json.Unmarshal([]byte(prescriptions_list_all), &prescriptions)
2323
-		return prescriptions, nil
1939
+	if stop == 1 {
1940
+		db = db.Where("(x.stop_state=? or x.execution_state=?)", stop, stop)
1941
+	} else if stop == 2 {
1942
+		db = db.Where("x.stop_state=? and x.execution_state=?", stop, stop)
2324 1943
 	}
2325
-}
2326
-
2327
-func GetAllAssessmentBeforesByListThree(orgID int64, scheduleDate int64) (assessmentBefores []*models.PredialysisEvaluation, err error) {
2328
-	redis := RedisClient()
2329
-	defer redis.Close()
2330
-	key := strconv.FormatInt(orgID, 10) + ":" + ":assessment_befores_list_all"
2331
-	assessment_befores_list_all, _ := redis.Get(key).Result()
2332 1944
 
2333
-	if len(assessment_befores_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2334
-		err = readDb.Model(&models.PredialysisEvaluation{}).Where("status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate).Find(&assessmentBefores).Error
2335
-		if err != nil {
2336
-			if err == gorm.ErrRecordNotFound {
2337
-				return nil, nil
2338
-			} else {
2339
-				return nil, err
2340
-			}
2341
-		} else {
2342
-			if len(assessmentBefores) > 0 {
2343
-				//缓存数据
2344
-				assessment_befores_list_all, err := json.Marshal(&assessmentBefores)
2345
-				if err == nil {
2346
-					redis.Set(key, assessment_befores_list_all, time.Second*60*60*18)
2347
-				}
2348
-			}
2349
-			return assessmentBefores, nil
2350
-		}
2351
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2352
-		json.Unmarshal([]byte(assessment_befores_list_all), &assessmentBefores)
2353
-		return assessmentBefores, nil
1945
+	if start != 0 {
1946
+		db = db.Where("x.start_time>=?", start)
2354 1947
 	}
2355
-}
2356
-
2357
-func GetAllDialysisOrdersByListThree(orgID int64, scheduleDate int64) (dialysisOrders []*models.MonitorDialysisOrder, err error) {
2358
-	redis := RedisClient()
2359
-	defer redis.Close()
2360
-	key := strconv.FormatInt(orgID, 10) + ":" + ":dialysis_orders_list_all"
2361
-	dialysis_orders_list_all, _ := redis.Get(key).Result()
2362
-
2363
-	if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2364
-		err = readDb.Model(&models.MonitorDialysisOrder{}).Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error
2365
-		if err != nil {
2366
-			if err == gorm.ErrRecordNotFound {
2367
-				return nil, nil
2368
-			} else {
2369
-				return nil, err
2370
-			}
2371
-		} else {
2372
-			if len(dialysisOrders) > 0 {
2373
-				//缓存数据
2374
-				dialysis_orders_list_all, err := json.Marshal(&dialysisOrders)
2375
-				if err == nil {
2376
-					redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18)
2377
-				}
2378
-			}
2379
-			return dialysisOrders, nil
2380
-		}
2381
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2382
-		json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders)
2383
-		return dialysisOrders, nil
1948
+	if end != 0 {
1949
+		db = db.Where("x.start_time<=?", end)
2384 1950
 	}
2385
-}
2386
-
2387
-func GetAllAssessmentAfterDislysisByListThree(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*models.AssessmentAfterDislysis, err error) {
2388
-	redis := RedisClient()
2389
-	defer redis.Close()
2390
-	key := strconv.FormatInt(orgID, 10) + ":" + ":assessment_after_dislysis_list_all"
2391
-	assessment_after_dislysis__all, _ := redis.Get(key).Result()
2392
-
2393
-	if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2394
-		err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("status = 1  AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error
2395
-		if err != nil {
2396
-			if err == gorm.ErrRecordNotFound {
2397
-				return nil, nil
2398
-			} else {
2399
-				return nil, err
2400
-			}
2401
-		} else {
2402
-			if len(assessmentAfterDislysis) > 0 {
2403
-				//缓存数据
2404
-				assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis)
2405
-				if err == nil {
2406
-					redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
2407
-				}
2408
-			}
2409
-			return assessmentAfterDislysis, nil
2410
-		}
2411
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2412
-		json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis)
2413
-		return assessmentAfterDislysis, nil
1951
+	if len(keywords) > 0 {
1952
+		likeKey := "%" + keywords + "%"
1953
+		db = db.Where("x.advice_name LIKE ?", likeKey)
2414 1954
 	}
2415
-}
2416
-
2417
-func GetAllMonitorListThree(orgID int64, scheduleDate int64) (monitor []*models.MonitoringRecord, err error) {
2418
-
2419
-	redis := RedisClient()
2420
-	defer redis.Close()
2421
-	key := strconv.FormatInt(orgID, 10) + ":" + ":monitor_record_list_all"
2422
-	monitor_record_list_all, _ := redis.Get(key).Result()
1955
+	offset := (page - 1) * limit
1956
+	err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Scan(&advices).Error
1957
+	fmt.Print("错误是什么", err)
1958
+	return
2423 1959
 
2424
-	if len(monitor_record_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2425
-		err = readDb.Model(&models.MonitoringRecord{}).Where("status = 1  AND user_org_id = ? AND  monitoring_date= ?", orgID, scheduleDate).Find(&monitor).Error
2426
-		if err != nil {
2427
-			if err == gorm.ErrRecordNotFound {
2428
-				return nil, nil
2429
-			} else {
2430
-				return nil, err
2431
-			}
2432
-		} else {
2433
-			if len(monitor) > 0 {
2434
-				//缓存数据
2435
-				assessment_after_dislysis__all, err := json.Marshal(&monitor)
2436
-				if err == nil {
2437
-					redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18)
2438
-				}
2439
-			}
2440
-			return monitor, nil
2441
-		}
2442
-	} else { //缓存数据了数据,将redis缓存的json字符串转为map
2443
-		json.Unmarshal([]byte(monitor_record_list_all), &monitor)
2444
-		return monitor, nil
2445
-	}
2446 1960
 }

+ 16 - 16
service/schedule_service.go View File

@@ -591,7 +591,7 @@ func GetWeekDayScheduleById(orgid int64, scheduleDate int64, scheduleType int64,
591 591
 
592 592
 func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
593 593
 
594
-	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
594
+	db := readDb2.Table("xt_schedule as x").Where("x.status = 1")
595 595
 	if orgid > 0 {
596 596
 		db = db.Where("x.user_org_id = ?", orgid)
597 597
 	}
@@ -605,12 +605,12 @@ func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType in
605 605
 		db = db.Where("x.partition_id in (?)", zone)
606 606
 	}
607 607
 
608
-	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1").Preload("XtAssessmentBeforeDislysis", "status = 1").Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
609
-		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
610
-	}).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
608
+	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1 and dialysis_date = ?", scheduleDate).Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =?", scheduleDate).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
609
+		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
610
+	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date =?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
611 611
 		return db.Where("status =1").Order("id asc")
612
-	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
613
-		return db.Where("status =1").Group("patient_id,mode_id").Order("id desc")
612
+	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
613
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
614 614
 	}).Find(&list).Error
615 615
 
616 616
 	return list, err
@@ -618,7 +618,7 @@ func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType in
618 618
 
619 619
 func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int64, startDate int64, zone []string) (list []*models.VmSchedulesRemind, err error) {
620 620
 
621
-	db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
621
+	db := readDb2.Table("xt_schedule as x").Where("x.status = 1")
622 622
 	if orgid > 0 {
623 623
 		db = db.Where("x.user_org_id = ?", orgid)
624 624
 	}
@@ -632,12 +632,12 @@ func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int
632 632
 		db = db.Where("x.partition_id in (?)", zone)
633 633
 	}
634 634
 
635
-	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1").Preload("XtAssessmentBeforeDislysis", "status = 1").Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
636
-		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
637
-	}).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
635
+	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1 and dialysis_date =?", scheduleDate).Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =?", scheduleDate).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
636
+		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
637
+	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date = ?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
638 638
 		return db.Where("status =1").Order("id asc")
639
-	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
640
-		return db.Where("status =1").Group("patient_id,mode_id").Order("id desc")
639
+	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
640
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
641 641
 	}).Find(&list).Error
642 642
 
643 643
 	return list, err
@@ -795,7 +795,7 @@ func UpdateNewScheduleTemplateStatus(id int64, org_id int64) (err error) {
795 795
 	return
796 796
 }
797 797
 
798
-func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string) (schedules []*models.WeekSchedule, err error) {
798
+func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string) (schedules []*models.WeekScheduleSix, err error) {
799 799
 
800 800
 	db := readDb.Table("xt_schedule as s ").Where("s.status =1")
801 801
 	if orgID > 0 {
@@ -824,8 +824,6 @@ func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endt
824 824
 			return db.Where("status = 1").Order("id asc")
825 825
 		}).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
826 826
 		return db.Where("status = 1").Order("id asc")
827
-	}).Preload("Solution", func(db *gorm.DB) *gorm.DB {
828
-		return db.Where("status = 1").Group("patient_id,mode_id").Order("id desc")
829 827
 	}).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
830 828
 		return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
831 829
 	}).Preload("HisDoctorAdviceInfo", "status = 1").Joins("JOIN xt_patients as p ON p.id = s.patient_id").
@@ -993,6 +991,8 @@ func GetDataPrint(orgid int64) (models.XtDataPrint, error) {
993 991
 
994 992
 func GetNextWeekPanels(startime int64, endtime int64, orgid int64) (schedule []*models.XtSchedule, err error) {
995 993
 
996
-	err = XTReadDB().Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Find(&schedule).Error
994
+	err = readDb2.Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
995
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, endtime)
996
+	}).Find(&schedule).Error
997 997
 	return schedule, err
998 998
 }

+ 30 - 6
service/self_drug_service.go View File

@@ -879,12 +879,15 @@ func CreateDrugDamage(damage models.XtDrugDamage) error {
879 879
 func GetDrugDamageList(startime int64, endtime int64, orgId int64, keyword string, limit int64, page int64) (adjust []*models.VmDrugInventory, total int64, err error) {
880 880
 	likeKey := "%" + keyword + "%"
881 881
 	offset := (page - 1) * limit
882
-	db := XTReadDB().Table("xt_drug_inventory as x").Where("x.status = 1 and inventory_type = 11")
882
+	db := XTReadDB().Table("xt_drug_inventory as x").Where("x.status = 1 and type = 4")
883 883
 	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
884 884
 	tab := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1")
885 885
 	fmt.Println(table, tab)
886
+	//if len(keyword) > 0 {
887
+	//	db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
888
+	//}
886 889
 	if len(keyword) > 0 {
887
-		db = db.Where("x.warehousing_order = ? or r.user_name like ?", keyword, likeKey)
890
+		db = db.Where("x.drug_name like ?", likeKey)
888 891
 	}
889 892
 	if orgId > 0 {
890 893
 		db = db.Where("x.user_org_id = ?", orgId)
@@ -900,7 +903,7 @@ func GetDrugDamageList(startime int64, endtime int64, orgId int64, keyword strin
900 903
 }
901 904
 
902 905
 func GetDrugDamageByOrgId(orgid int64) (list []*models.XtDrugInventory, err error) {
903
-	err = XTReadDB().Model(&list).Where("user_org_id = ? and inventory_type = 11 and status = 1", orgid).Find(&list).Error
906
+	err = XTReadDB().Model(&list).Where("user_org_id = ? and type = 4 and status = 1", orgid).Find(&list).Error
904 907
 	return list, err
905 908
 }
906 909
 
@@ -1034,6 +1037,12 @@ func GetLastDrugWarehouseOut(orgid int64) (models.DrugWarehouseOut, error) {
1034 1037
 	return info, err
1035 1038
 }
1036 1039
 
1040
+func GetLastDrugWarehouseInfSix(drugid int64) (models.XtDrugWarehouseInfo, error) {
1041
+
1042
+	info := models.XtDrugWarehouseInfo{}
1043
+	err := XTReadDB().Model(&info).Where("drug_id=? and status = 1", drugid).Last(&info).Error
1044
+	return info, err
1045
+}
1037 1046
 //func GetLastDrugWarehouseInfo(drugid int64) (models.XtDrugWarehouseInfo, error) {
1038 1047
 //
1039 1048
 //	info := models.XtDrugWarehouseInfo{}
@@ -1121,9 +1130,9 @@ func CreateDrugWarehouseOutInfo(info models.DrugWarehouseOutInfo) error {
1121 1130
 	return err
1122 1131
 }
1123 1132
 
1124
-func GetDamageByDrugId(drugid int64, warhousingorder string, drugtype int64) (drug []*models.XtDrugInventory, err error) {
1133
+func GetDamageByDrugId(drugid int64, warhousingorder string, drugtype int64) (drug []*models.VmXtDrugInventory, err error) {
1125 1134
 
1126
-	db := XTReadDB().Table("xt_drug_inventory").Where("status = 1 and inventory_type = 11 ")
1135
+	db := XTReadDB().Table("xt_drug_inventory").Where("status = 1")
1127 1136
 
1128 1137
 	if drugid > 0 {
1129 1138
 		db = db.Where("drug_id = ?", drugid)
@@ -1134,7 +1143,22 @@ func GetDamageByDrugId(drugid int64, warhousingorder string, drugtype int64) (dr
1134 1143
 	if drugtype > 0 {
1135 1144
 		db = db.Where("type = ?", drugtype)
1136 1145
 	}
1146
+	if drugtype == 0 {
1147
+		db = db.Where("type = 4")
1148
+	}
1137 1149
 
1138
-	err = db.Find(&drug).Error
1150
+	err = db.Preload("XtBaseDrug", "status = 1").Find(&drug).Error
1139 1151
 	return drug, err
1140 1152
 }
1153
+
1154
+func GetInventoryModeList(orgid int64) (info []*models.PatientDrugWarehouseInfo, err error) {
1155
+
1156
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
1157
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
1158
+	fmt.Println(table)
1159
+	if orgid > 0 {
1160
+		db = db.Where("x.org_id = ?", orgid)
1161
+	}
1162
+	err = db.Select("x.drug_id,x.number,x.product_date,x.expiry_date,x.stock_max_number,x.stock_min_number,x.batch_number,t.drug_name,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,x.manufacturer,x.dealer").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id,x.batch_number").Scan(&info).Error
1163
+	return info, err
1164
+}

+ 1 - 0
service/stock_service.go View File

@@ -4023,6 +4023,7 @@ func GetExportOutOrderDrugListOne(warehouse_out_id []string) (out []*models.StDr
4023 4023
 }
4024 4024
 
4025 4025
 func GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64, orgid_id int64) (models.WarehouseOutInfo, error) {
4026
+func GetLastGoodInformationByGoodId(goodid int64, warehouse_info_id int64) (models.WarehouseOutInfo, error) {
4026 4027
 
4027 4028
 	info := models.WarehouseOutInfo{}
4028 4029
 	err := XTReadDB().Where("good_id = ? and warehouse_info_id= ? and status =1", goodid, warehouse_info_id).Last(&info).Error

+ 3 - 7
service/user_service.go View File

@@ -48,16 +48,14 @@ func GetAllDoctorAndNurse(orgId, appid int64) (doctors []AdminUserList, nurses [
48 48
 }
49 49
 
50 50
 func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
51
-	//fmt.Println("orgid", orgId)
52
-	//fmt.Println("appid", appid)
51
+
53 52
 	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
54 53
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
55 54
 	return
56 55
 }
57 56
 
58 57
 func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
59
-	//fmt.Println("orgid", orgId)
60
-	//fmt.Println("appid", appid)
58
+
61 59
 	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=?  and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
62 60
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
63 61
 	return
@@ -140,9 +138,7 @@ func GetLastData(orgid int64) (models.SgjPatientDryweight, error) {
140 138
 }
141 139
 
142 140
 func UpdateDialysisPrescription(patientid int64, orgid int64, dryweight float64, prescription models.PredialysisEvaluation) error {
143
-	fmt.Println("patientid", patientid)
144
-	fmt.Println("orgid", orgid)
145
-	fmt.Println("dryweight", dryweight)
141
+
146 142
 	err := XTWriteDB().Model(&prescription).Where("patient_id = ? AND user_org_id = ?", patientid, orgid).Update(map[string]interface{}{"dry_weight": dryweight, "mtime": time.Now().Unix()}).Last(&prescription).Error
147 143
 	fmt.Println("错误是设么", err)
148 144
 	return err

+ 7 - 0
service/warhouse_service.go View File

@@ -1696,6 +1696,8 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1696 1696
 
1697 1697
 		maxNumber = goods.Count
1698 1698
 
1699
+		fmt.Println("数据1111111111111", warehouse.StockCount)
1700
+		fmt.Println("s数据233232323232323232233232", maxNumber)
1699 1701
 		if warehouse.StockCount < maxNumber {
1700 1702
 			return errors.New("库存数量不足")
1701 1703
 		}
@@ -1703,6 +1705,11 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1703 1705
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1704 1706
 		warehouse.Mtime = time.Now().Unix()
1705 1707
 
1708
+		//扣减库存
1709
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
1710
+		fmt.Println("几年里2323323232323232323232")
1711
+		if errThree != nil {
1712
+			return errThree
1706 1713
 		if warehouse.StockCount <= 0 {
1707 1714
 			return errors.New("库存数量不足")
1708 1715
 		} else {