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

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

张保健 пре 1 година
родитељ
комит
2dfd653ee5
44 измењених фајлова са 2136 додато и 691 уклоњено
  1. 0 1
      .idea/vcs.xml
  2. 1 1
      conf/app.conf
  3. 1 1
      controllers/data_api_controller.go
  4. 59 9
      controllers/dialysis_api_controller.go
  5. 18 0
      controllers/dialysis_record_api_controller.go
  6. 1 1
      controllers/gobal_config_api_controller.go
  7. 316 204
      controllers/his_api_controller.go
  8. 31 4
      controllers/mobile_api_controllers/dialysis_api_controller.go
  9. 26 0
      controllers/new_mobile_api_controllers/new_dialysis_api_controller.go
  10. 2 0
      controllers/new_mobile_api_controllers/new_mobile_api_router_register.go
  11. 0 3
      controllers/patient_api_controller.go
  12. 36 12
      controllers/print_data_api_controller.go
  13. 283 86
      controllers/schedule_api_controller.go
  14. 140 2
      controllers/schedule_template_api_controller.go
  15. 297 149
      controllers/secondary_order_api_contorller.go
  16. 0 1
      controllers/self_drug_api_congtroller.go
  17. 57 0
      controllers/stock_in_api_controller.go
  18. 1 1
      main.go
  19. 34 0
      models/dialysis.go
  20. 109 0
      models/drug_stock.go
  21. 9 8
      models/new_monitor.go
  22. 2 0
      models/patient_models.go
  23. 1 0
      models/patient_schedule_template_models.go
  24. 24 0
      models/schedule_models.go
  25. 18 17
      models/smart_sch.go
  26. 2 1
      models/stock_models.go
  27. 27 5
      service/device_service.go
  28. 20 8
      service/dialysis_solution_service.go
  29. 8 2
      service/gobal_config_service.go
  30. 4 4
      service/his_service.go
  31. 36 15
      service/manage_center_service.go
  32. 34 0
      service/mobile_dialysis_service.go
  33. 2 2
      service/new_stock_service.go
  34. 165 47
      service/new_warehouse_service.go
  35. 29 0
      service/patient_schedule_template_service.go
  36. 6 1
      service/patient_service.go
  37. 33 0
      service/patientmanage_service.go
  38. 1 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go
  39. 7 1
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go
  40. 56 9
      service/schedule_service.go
  41. 2 2
      service/self_drug_service.go
  42. 88 40
      service/smart_sch.go
  43. 66 3
      service/stock_service.go
  44. 84 51
      service/warhouse_service.go

+ 0 - 1
.idea/vcs.xml Прегледај датотеку

@@ -7,6 +7,5 @@
7 7
   </component>
8 8
   <component name="VcsDirectoryMappings">
9 9
     <mapping directory="$PROJECT_DIR$" vcs="Git" />
10
-    <mapping directory="$PROJECT_DIR$/src/golang.org/x/sync" vcs="Git" />
11 10
   </component>
12 11
 </project>

+ 1 - 1
conf/app.conf Прегледај датотеку

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9531
2
+httpport = 9529
3 3
 runmode =dev
4 4
 #dev/prod
5 5
 

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

@@ -400,7 +400,7 @@ func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
400 400
 	}
401 401
 	dataconfig.Module = module
402 402
 
403
-	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" {
403
+	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" || module == "dialysis_remark" {
404 404
 		if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
405 405
 			utils.ErrorLog("title")
406 406
 			code = enums.ErrorCodeParamWrong

+ 59 - 9
controllers/dialysis_api_controller.go Прегледај датотеку

@@ -107,6 +107,8 @@ func DialysisApiRegistRouters() {
107 107
 	beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
108 108
 
109 109
 	beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
110
+
111
+	beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
110 112
 }
111 113
 
112 114
 func (c *DialysisApiController) GetQueueCall() {
@@ -321,6 +323,7 @@ func (c *DialysisApiController) PostPrescription() {
321 323
 	water_machine := c.GetString("water_machine")
322 324
 	add_amount, _ := c.GetFloat("add_amount")
323 325
 	reduce_amount, _ := c.GetFloat("reduce_amount")
326
+	dialysis_remark := c.GetString("dialysis_remark")
324 327
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
325 328
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
326 329
 
@@ -428,6 +431,7 @@ func (c *DialysisApiController) PostPrescription() {
428 431
 		WaterMachine:               water_machine,
429 432
 		AddAmount:                  add_amount,
430 433
 		ReduceAmount:               reduce_amount,
434
+		DialysisRemark:             dialysis_remark,
431 435
 	}
432 436
 
433 437
 	if appRole.UserType == 2 || appRole.UserType == 1 {
@@ -659,6 +663,7 @@ func (c *DialysisApiController) PostSoulution() {
659 663
 	water_machine := c.GetString("water_machine")
660 664
 	add_amount, _ := c.GetFloat("add_amount")
661 665
 	reduce_amount, _ := c.GetFloat("reduce_amount")
666
+	dialysis_remark := c.GetString("dialysis_remark")
662 667
 	var prescription_doctor int64
663 668
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
664 669
 
@@ -778,6 +783,7 @@ func (c *DialysisApiController) PostSoulution() {
778 783
 		WaterMachine:               water_machine,
779 784
 		AddAmount:                  add_amount,
780 785
 		ReduceAmount:               reduce_amount,
786
+		DialysisRemark:             dialysis_remark,
781 787
 	}
782 788
 
783 789
 	//查询最近透析准备表里是否存在 透析器 灌流器
@@ -948,6 +954,7 @@ func (c *DialysisApiController) PostSoulution() {
948 954
 		OxygenTime:                 oxygen_time,
949 955
 		PreImpulse:                 preImpules,
950 956
 		SolutionStatus:             1,
957
+		DialysisRemark:             dialysis_remark,
951 958
 	}
952 959
 
953 960
 	//针对河间咸得
@@ -2955,13 +2962,22 @@ func (c *DialysisApiController) GetDialysisOrder() {
2955 2962
 
2956 2963
 	check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2957 2964
 
2958
-	if adminUserInfo.CurrentOrgId != 10101 {
2965
+	if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
2959 2966
 		dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2960 2967
 		patientInfo.TotalDialysis = dialysis_count
2961 2968
 	}
2962
-	if adminUserInfo.CurrentOrgId == 10101 {
2963
-		dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2964
-		patientInfo.TotalDialysis = dialysis_count
2969
+	if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
2970
+
2971
+		if xttime <= 1672416000 {
2972
+			dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2973
+			patientInfo.TotalDialysis = dialysis_count
2974
+		}
2975
+
2976
+		if xttime >= 1672502400 {
2977
+			dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
2978
+			patientInfo.TotalDialysis = dialysis_count
2979
+		}
2980
+
2965 2981
 	}
2966 2982
 
2967 2983
 	//相关操作对应的操作人
@@ -4805,7 +4821,8 @@ func (this *DialysisApiController) ExcutionDoctorAdvice() {
4805 4821
 					prescribing_number = parseIntPrescribingNumber
4806 4822
 				}
4807 4823
 				sum_out_count += prescribing_number
4808
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId)
4824
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
4825
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
4809 4826
 				//库存不足
4810 4827
 				if sum_out_count > drugStockOut.FlushCount {
4811 4828
 					this.ServeSuccessJSON(map[string]interface{}{
@@ -4952,7 +4969,8 @@ func (this *DialysisApiController) ExcutionDoctorAdvice() {
4952 4969
 					prescribing_number = parseIntPrescribingNumber
4953 4970
 				}
4954 4971
 				sum_out_count += prescribing_number
4955
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId)
4972
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
4973
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
4956 4974
 				//库存不足
4957 4975
 				if sum_out_count > drugStockOut.FlushCount {
4958 4976
 					this.ServeSuccessJSON(map[string]interface{}{
@@ -5209,8 +5227,8 @@ func (this *DialysisApiController) ExcutionDoctorAdviceById() {
5209 5227
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5210 5228
 			prescribing_number = parseIntPrescribingNumber
5211 5229
 		}
5212
-
5213
-		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId)
5230
+		houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
5231
+		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
5214 5232
 		//库存不足
5215 5233
 		if prescribing_number > drugStockOut.FlushCount {
5216 5234
 			this.ServeSuccessJSON(map[string]interface{}{
@@ -5349,7 +5367,8 @@ func (this *DialysisApiController) ExcutionDoctorAdviceById() {
5349 5367
 		if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5350 5368
 			prescribing_number = parseIntPrescribingNumber
5351 5369
 		}
5352
-		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId)
5370
+		houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
5371
+		drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
5353 5372
 		//库存不足
5354 5373
 		if prescribing_number > drugStockOut.FlushCount {
5355 5374
 			this.ServeSuccessJSON(map[string]interface{}{
@@ -5442,3 +5461,34 @@ func (this *DialysisApiController) ExcutionDoctorAdviceById() {
5442 5461
 	return
5443 5462
 
5444 5463
 }
5464
+
5465
+func (this *DialysisApiController) GetDialysisAdviceToday() {
5466
+
5467
+	orgId := this.GetAdminUserInfo().CurrentOrgId
5468
+
5469
+	schedule_type, _ := this.GetInt64("schedule_type")
5470
+
5471
+	partion_type, _ := this.GetInt64("partion_type")
5472
+
5473
+	start_time := this.GetString("selected_date")
5474
+	timeLayout := "2006-01-02"
5475
+	loc, _ := time.LoadLocation("Local")
5476
+	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
5477
+
5478
+	list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, partion_type, startTime.Unix())
5479
+
5480
+	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
5481
+	_, config := service.FindXTHisRecordByOrgId(orgId)
5482
+	if err == nil {
5483
+		this.ServeSuccessJSON(map[string]interface{}{
5484
+			"list":   list,
5485
+			"drug":   drug,
5486
+			"config": config,
5487
+		})
5488
+		return
5489
+
5490
+	} else {
5491
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
5492
+		return
5493
+	}
5494
+}

+ 18 - 0
controllers/dialysis_record_api_controller.go Прегледај датотеку

@@ -1009,6 +1009,24 @@ func (this *DialysisRecordAPIController) StartDialysis() {
1009 1009
 	createErr := service.MobileCreateDialysisOrder(adminUserInfo.CurrentOrgId, patientID, dialysisRecord)
1010 1010
 	//更新患者表排班备注
1011 1011
 	service.UpdateMobilePatient(adminUserInfo.CurrentOrgId, patientID, schedule_remark)
1012
+
1013
+	////统计该患者总次数
1014
+	//dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
1015
+	//
1016
+	//service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
1017
+
1018
+	if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 3877 && adminUserInfo.CurrentOrgId != 10345 {
1019
+		//统计该患者总次数
1020
+		dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.CurrentOrgId, patientID)
1021
+		service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
1022
+	}
1023
+
1024
+	if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10345 {
1025
+		//统计该患者总次数
1026
+		dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.CurrentOrgId, patientID)
1027
+		service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.CurrentOrgId, dialysisCount.Count)
1028
+	}
1029
+
1012 1030
 	key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
1013 1031
 	redis := service.RedisClient()
1014 1032
 	//清空key 值

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

@@ -2231,7 +2231,7 @@ func (c *GobalConfigApiController) GetSingleOrderDetail() {
2231 2231
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2232 2232
 
2233 2233
 	list, err := service.GetSingleOrderDetail(id, orgId)
2234
-	drugoutlist, _ := service.GetDrugWarehouseOutDetailSeventy(id, orgId)
2234
+	drugoutlist, _ := service.GetDrugWarehouseOutDetailNighty(id, orgId)
2235 2235
 	dealerList, err := service.GetAllDealerList(orgId)
2236 2236
 	manufacturerList, err := service.GetAllManufacturerList(orgId)
2237 2237
 	drugFlowList, _ := service.GetDrugStockFlowDetail(start_time, orgId)

+ 316 - 204
controllers/his_api_controller.go Прегледај датотеку

@@ -988,6 +988,8 @@ func (c *HisApiController) CreateHisPrescription() {
988 988
 	//耗材保存处方出库
989 989
 	goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
990 990
 
991
+	settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
992
+
991 993
 	//已发药和已收费限制逻辑
992 994
 	isMidicine := false
993 995
 	isCharge := false
@@ -1048,7 +1050,7 @@ func (c *HisApiController) CreateHisPrescription() {
1048 1050
 	}
1049 1051
 	//已发药和已收费限制逻辑
1050 1052
 
1051
-	if drugStockConfig.IsOpen == 1 {
1053
+	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1052 1054
 		//校验库存总量
1053 1055
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1054 1056
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
@@ -1564,6 +1566,97 @@ func (c *HisApiController) CreateHisPrescription() {
1564 1566
 		}
1565 1567
 	}
1566 1568
 
1569
+	//校验耗材库存
1570
+	if goodOutConfig.IsOpen == 1 {
1571
+
1572
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1573
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
1574
+
1575
+			if len(prescriptions) > 0 {
1576
+				for _, item := range prescriptions {
1577
+
1578
+					items := item.(map[string]interface{})
1579
+					if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
1580
+						projects := items["project"].([]interface{})
1581
+						if len(projects) > 0 {
1582
+
1583
+							for _, project := range projects {
1584
+								var project_id int64
1585
+								var project_type int64
1586
+								var totals float64
1587
+								var project_name string
1588
+								var parsetotal int64
1589
+								var id int64
1590
+								if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
1591
+									project_id = int64(project.(map[string]interface{})["project_id"].(float64))
1592
+								}
1593
+								if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
1594
+									project_type = int64(project.(map[string]interface{})["type"].(float64))
1595
+								}
1596
+								if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
1597
+									total, _ := project.(map[string]interface{})["total"].(string)
1598
+									totals, _ = strconv.ParseFloat(total, 64)
1599
+								}
1600
+
1601
+								if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
1602
+									project_name = project.(map[string]interface{})["project_name"].(string)
1603
+
1604
+								}
1605
+								if project_type == 3 {
1606
+
1607
+									//查找该耗材的出库记录
1608
+									goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
1609
+
1610
+									if len(goodWarehouseInfo) == 0 {
1611
+										//查询耗材库存
1612
+										list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
1613
+										var stock_count int64
1614
+										for _, it := range list {
1615
+											stock_count += it.StockCount
1616
+										}
1617
+										stock_counts := strconv.FormatInt(stock_count, 10)
1618
+										stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
1619
+										if totals > stock_total_count {
1620
+											c.ServeDynamicFailJsonSend(project_name + "库存不足")
1621
+											return
1622
+										}
1623
+									}
1624
+
1625
+									if len(goodWarehouseInfo) > 0 {
1626
+										//查询该患者耗材的历史数据
1627
+										ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
1628
+										count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
1629
+										//数量发生改变
1630
+										if parsetotal != count {
1631
+											//如果现在的数量大于历史数量,就要看库存是否足够
1632
+											if parsetotal > count {
1633
+
1634
+												//查询耗材所有库存
1635
+												list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
1636
+												var stock_count int64
1637
+												for _, it := range list {
1638
+													stock_count += it.StockCount
1639
+												}
1640
+
1641
+												//库存不足
1642
+												if (parsetotal - count) > stock_count {
1643
+													c.ServeDynamicFailJsonSend(project_name + "库存不足")
1644
+													return
1645
+												}
1646
+											}
1647
+										}
1648
+									}
1649
+
1650
+								}
1651
+
1652
+							}
1653
+						}
1654
+					}
1655
+				}
1656
+			}
1657
+		}
1658
+	}
1659
+
1567 1660
 	//不使用耗材保存处方出库
1568 1661
 	if goodOutConfig.IsOpen != 1 {
1569 1662
 		if stockConfig.IsOpen == 1 {
@@ -2190,15 +2283,22 @@ func (c *HisApiController) CreateHisPrescription() {
2190 2283
 
2191 2284
 			//查询今日耗材出库数量
2192 2285
 			hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
2286
+
2193 2287
 			for _, item := range hisgoodlist {
2194 2288
 				//查询耗材最后一次出库记录
2195 2289
 				wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
2290
+				fmt.Println("hh23h232323o23o23o2o32o23o2o3o2o23o32o23o2o323o23o23o23o23o23o")
2291
+				//查询默认出库仓库库存
2292
+				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2196 2293
 				if len(wareOut) > 0 {
2294
+
2197 2295
 					for _, it := range wareOut {
2198 2296
 						//回退库存
2199 2297
 						service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
2200 2298
 						//删除出库记录
2201 2299
 						service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
2300
+						//出库数量减少
2301
+						service.UpdateSumCount(it.OrgId, storeConfig.StorehouseOutInfo, it.ProjectId, it.Count)
2202 2302
 					}
2203 2303
 				}
2204 2304
 
@@ -2214,8 +2314,7 @@ func (c *HisApiController) CreateHisPrescription() {
2214 2314
 
2215 2315
 				operation_time := time.Now().Unix()
2216 2316
 				creater := c.GetAdminUserInfo().AdminUser.Id
2217
-				//查询默认出库仓库库存
2218
-				storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
2317
+
2219 2318
 				recordDateStr := time.Now().Format("2006-01-02")
2220 2319
 				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
2221 2320
 				nowtime := recordDate.Unix()
@@ -2243,6 +2342,7 @@ func (c *HisApiController) CreateHisPrescription() {
2243 2342
 				goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
2244 2343
 				houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
2245 2344
 				parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
2345
+
2246 2346
 				dialyPrepareOne := models.DialysisBeforePrepare{
2247 2347
 					GoodTypeId:   goodObj.GoodTypeId,
2248 2348
 					GoodId:       item.ProjectId,
@@ -2256,21 +2356,24 @@ func (c *HisApiController) CreateHisPrescription() {
2256 2356
 					StorehouseId: houseConfig.StorehouseOutInfo,
2257 2357
 					ProjectId:    item.ID,
2258 2358
 				}
2359
+				goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
2360
+				if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
2361
+					service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2259 2362
 
2260
-				service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater)
2363
+					//查询剩余库存
2364
+					goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
2365
+					var sum_count int64
2366
+					for _, item := range goodList {
2367
+						sum_count += item.StockCount
2368
+					}
2261 2369
 
2262
-				//查询剩余库存
2263
-				goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId)
2264
-				var sum_count int64
2265
-				for _, item := range goodList {
2266
-					sum_count += item.StockCount
2267
-				}
2370
+					//更新剩余库存
2371
+					service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
2268 2372
 
2269
-				//更新剩余库存
2270
-				service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
2373
+					//耗材
2374
+					service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
2375
+				}
2271 2376
 
2272
-				//耗材
2273
-				service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
2274 2377
 			}
2275 2378
 		}
2276 2379
 	}
@@ -2573,10 +2676,11 @@ func (c *HisApiController) DeletePrescription() {
2573 2676
 	prescription_id, _ := c.GetInt64("id")
2574 2677
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
2575 2678
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
2576
-	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
2679
+	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
2577 2680
 
2578 2681
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
2579 2682
 
2683
+	drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
2580 2684
 	//耗材保存处方出库
2581 2685
 	goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
2582 2686
 	//已收费和已发药限制逻辑
@@ -2833,7 +2937,7 @@ func (c *HisApiController) DeletePrescription() {
2833 2937
 
2834 2938
 							if prescribingNumber >= dialysisInfo.Count {
2835 2939
 								//删除出库表
2836
-								service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
2940
+								service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
2837 2941
 							}
2838 2942
 
2839 2943
 							//更新库存
@@ -2917,7 +3021,6 @@ func (c *HisApiController) DeletePrescription() {
2917 3021
 				}
2918 3022
 			}
2919 3023
 
2920
-			fmt.Println("goodOutConfig.IsOpen23232332233232232323232323", goodOutConfig.IsOpen)
2921 3024
 			//保存耗材出库
2922 3025
 			if goodOutConfig.IsOpen == 1 {
2923 3026
 
@@ -2968,159 +3071,156 @@ func (c *HisApiController) DeletePrescription() {
2968 3071
 					for _, it := range goodList {
2969 3072
 						flush_count += it.StockCount
2970 3073
 					}
2971
-					fmt.Println("nfo.Count342232332323223232323", info.Count)
2972
-					fmt.Println("total_count0999923923932923", total_count)
3074
+					fmt.Println("历史出库数据", info.Count)
3075
+					fmt.Println("出库数量", total_count)
2973 3076
 					if info.ID > 0 {
2974
-						if info.Count >= total_count {
2975
-
2976
-							//回退库存
2977
-							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
2978
-							cancelStockInfo := models.CancelStockInfo{
2979
-								GoodId:          item.ProjectId,
2980
-								CancelStockId:   cancel.ID,
2981
-								GoodTypeId:      good.GoodTypeId,
2982
-								Count:           prescribingNumber,
2983
-								Price:           info.Price,
2984
-								Total:           0,
2985
-								ProductDate:     info.ProductDate,
2986
-								ExpiryDate:      info.ExpiryDate,
2987
-								Ctime:           time.Now().Unix(),
2988
-								Status:          1,
2989
-								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
2990
-								OrderNumber:     cancel.OrderNumber,
2991
-								Type:            0,
2992
-								Dealer:          deaerler.DealerName,
2993
-								Manufacturer:    manufacturer.ManufacturerName,
2994
-								Number:          info.Number,
2995
-								RegisterAccount: "",
2996
-								Remark:          "",
2997
-								WarehouseInfoId: info.WarehouseInfotId,
2998
-								PatientId:       info.PatientId,
2999
-								RecordDate:      info.SysRecordTime,
3000
-								StorehouseId:    houseConfig.StorehouseOutInfo,
3001
-								IsCheck:         1,
3002
-							}
3003
-
3004
-							service.CreateCancelStockInfoOne(&cancelStockInfo)
3005
-
3006
-							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3007
-
3008
-							flow := models.VmStockFlow{
3009
-								WarehousingId:           info.WarehouseInfotId,
3010
-								GoodId:                  item.ProjectId,
3011
-								Number:                  info.Number,
3012
-								LicenseNumber:           info.LicenseNumber,
3013
-								Count:                   prescribingNumber,
3014
-								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3015
-								PatientId:               item.PatientId,
3016
-								SystemTime:              info.SysRecordTime,
3017
-								ConsumableType:          7,
3018
-								IsSys:                   0,
3019
-								WarehousingOrder:        "",
3020
-								WarehouseOutId:          info.WarehouseOutId,
3021
-								WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3022
-								IsEdit:                  0,
3023
-								CancelStockId:           cancel.ID,
3024
-								CancelOrderNumber:       cancel.OrderNumber,
3025
-								Manufacturer:            manufacturer.ID,
3026
-								Dealer:                  0,
3027
-								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3028
-								UpdateCreator:           0,
3029
-								Status:                  1,
3030
-								Ctime:                   time.Now().Unix(),
3031
-								Mtime:                   0,
3032
-								Price:                   info.Price,
3033
-								WarehousingDetailId:     info.WarehouseInfotId,
3034
-								WarehouseOutDetailId:    info.ID,
3035
-								CancelOutDetailId:       cancelInfo.ID,
3036
-								ProductDate:             info.ProductDate,
3037
-								ExpireDate:              info.ExpiryDate,
3038
-								StorehouseId:            houseConfig.StorehouseOutInfo,
3039
-								OverCount:               flush_count,
3040
-							}
3041
-							service.CreateStockFlowOne(flow)
3042
-
3043
-							//退库数量增加
3044
-							service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
3045
-							//出库数量减少
3046
-							service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
3047 3077
 
3078
+						//回退库存
3079
+						service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
3080
+						cancelStockInfo := models.CancelStockInfo{
3081
+							GoodId:          item.ProjectId,
3082
+							CancelStockId:   cancel.ID,
3083
+							GoodTypeId:      good.GoodTypeId,
3084
+							Count:           prescribingNumber,
3085
+							Price:           info.Price,
3086
+							Total:           0,
3087
+							ProductDate:     info.ProductDate,
3088
+							ExpiryDate:      info.ExpiryDate,
3089
+							Ctime:           time.Now().Unix(),
3090
+							Status:          1,
3091
+							OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3092
+							OrderNumber:     cancel.OrderNumber,
3093
+							Type:            0,
3094
+							Dealer:          deaerler.DealerName,
3095
+							Manufacturer:    manufacturer.ManufacturerName,
3096
+							Number:          info.Number,
3097
+							RegisterAccount: "",
3098
+							Remark:          "",
3099
+							WarehouseInfoId: info.WarehouseInfotId,
3100
+							PatientId:       info.PatientId,
3101
+							RecordDate:      info.SysRecordTime,
3102
+							StorehouseId:    houseConfig.StorehouseOutInfo,
3103
+							IsCheck:         1,
3048 3104
 						}
3049 3105
 
3050
-						if info.Count < total_count {
3051
-							//回退库存
3052
-							service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
3053
-							cancelStockInfo := models.CancelStockInfo{
3054
-								GoodId:          item.ProjectId,
3055
-								CancelStockId:   cancel.ID,
3056
-								GoodTypeId:      good.GoodTypeId,
3057
-								Count:           info.Count,
3058
-								Price:           info.Price,
3059
-								Total:           0,
3060
-								ProductDate:     info.ProductDate,
3061
-								ExpiryDate:      info.ExpiryDate,
3062
-								Ctime:           time.Now().Unix(),
3063
-								Status:          1,
3064
-								OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3065
-								OrderNumber:     cancel.OrderNumber,
3066
-								Type:            0,
3067
-								Dealer:          deaerler.DealerName,
3068
-								Manufacturer:    manufacturer.ManufacturerName,
3069
-								Number:          info.Number,
3070
-								RegisterAccount: "",
3071
-								Remark:          "",
3072
-								WarehouseInfoId: info.WarehouseInfotId,
3073
-								PatientId:       info.PatientId,
3074
-								RecordDate:      info.SysRecordTime,
3075
-								StorehouseId:    houseConfig.StorehouseOutInfo,
3076
-								IsCheck:         1,
3077
-							}
3078
-
3079
-							service.CreateCancelStockInfoOne(&cancelStockInfo)
3080
-
3081
-							cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3082
-
3083
-							flow := models.VmStockFlow{
3084
-								WarehousingId:           info.WarehouseInfotId,
3085
-								GoodId:                  item.ProjectId,
3086
-								Number:                  info.Number,
3087
-								LicenseNumber:           info.LicenseNumber,
3088
-								Count:                   info.Count,
3089
-								UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3090
-								PatientId:               item.PatientId,
3091
-								SystemTime:              info.SysRecordTime,
3092
-								ConsumableType:          7,
3093
-								IsSys:                   0,
3094
-								WarehousingOrder:        "",
3095
-								WarehouseOutId:          info.WarehouseOutId,
3096
-								WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3097
-								IsEdit:                  0,
3098
-								CancelStockId:           cancel.ID,
3099
-								CancelOrderNumber:       cancel.OrderNumber,
3100
-								Manufacturer:            manufacturer.ID,
3101
-								Dealer:                  0,
3102
-								Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3103
-								UpdateCreator:           0,
3104
-								Status:                  1,
3105
-								Ctime:                   time.Now().Unix(),
3106
-								Mtime:                   0,
3107
-								Price:                   info.Price,
3108
-								WarehousingDetailId:     info.WarehouseInfotId,
3109
-								WarehouseOutDetailId:    info.ID,
3110
-								CancelOutDetailId:       cancelInfo.ID,
3111
-								ProductDate:             info.ProductDate,
3112
-								ExpireDate:              info.ExpiryDate,
3113
-								StorehouseId:            houseConfig.StorehouseOutInfo,
3114
-								OverCount:               flush_count,
3115
-							}
3116
-							service.CreateStockFlowOne(flow)
3106
+						service.CreateCancelStockInfoOne(&cancelStockInfo)
3117 3107
 
3118
-							//退库数量增加
3119
-							service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3120
-							//出库数量减少
3121
-							service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
3108
+						cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3122 3109
 
3110
+						flow := models.VmStockFlow{
3111
+							WarehousingId:           info.WarehouseInfotId,
3112
+							GoodId:                  item.ProjectId,
3113
+							Number:                  info.Number,
3114
+							LicenseNumber:           info.LicenseNumber,
3115
+							Count:                   prescribingNumber,
3116
+							UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3117
+							PatientId:               item.PatientId,
3118
+							SystemTime:              info.SysRecordTime,
3119
+							ConsumableType:          7,
3120
+							IsSys:                   0,
3121
+							WarehousingOrder:        "",
3122
+							WarehouseOutId:          info.WarehouseOutId,
3123
+							WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3124
+							IsEdit:                  0,
3125
+							CancelStockId:           cancel.ID,
3126
+							CancelOrderNumber:       cancel.OrderNumber,
3127
+							Manufacturer:            manufacturer.ID,
3128
+							Dealer:                  0,
3129
+							Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3130
+							UpdateCreator:           0,
3131
+							Status:                  1,
3132
+							Ctime:                   time.Now().Unix(),
3133
+							Mtime:                   0,
3134
+							Price:                   info.Price,
3135
+							WarehousingDetailId:     info.WarehouseInfotId,
3136
+							WarehouseOutDetailId:    info.ID,
3137
+							CancelOutDetailId:       cancelInfo.ID,
3138
+							ProductDate:             info.ProductDate,
3139
+							ExpireDate:              info.ExpiryDate,
3140
+							StorehouseId:            houseConfig.StorehouseOutInfo,
3141
+							OverCount:               flush_count,
3123 3142
 						}
3143
+						service.CreateStockFlowOne(flow)
3144
+
3145
+						//退库数量增加
3146
+						service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
3147
+						//出库数量减少
3148
+						service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
3149
+
3150
+						//if info.Count < total_count {
3151
+						//	//回退库存
3152
+						//	service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
3153
+						//	cancelStockInfo := models.CancelStockInfo{
3154
+						//		GoodId:          item.ProjectId,
3155
+						//		CancelStockId:   cancel.ID,
3156
+						//		GoodTypeId:      good.GoodTypeId,
3157
+						//		Count:           info.Count,
3158
+						//		Price:           info.Price,
3159
+						//		Total:           0,
3160
+						//		ProductDate:     info.ProductDate,
3161
+						//		ExpiryDate:      info.ExpiryDate,
3162
+						//		Ctime:           time.Now().Unix(),
3163
+						//		Status:          1,
3164
+						//		OrgId:           c.GetAdminUserInfo().CurrentOrgId,
3165
+						//		OrderNumber:     cancel.OrderNumber,
3166
+						//		Type:            0,
3167
+						//		Dealer:          deaerler.DealerName,
3168
+						//		Manufacturer:    manufacturer.ManufacturerName,
3169
+						//		Number:          info.Number,
3170
+						//		RegisterAccount: "",
3171
+						//		Remark:          "",
3172
+						//		WarehouseInfoId: info.WarehouseInfotId,
3173
+						//		PatientId:       info.PatientId,
3174
+						//		RecordDate:      info.SysRecordTime,
3175
+						//		StorehouseId:    houseConfig.StorehouseOutInfo,
3176
+						//		IsCheck:         1,
3177
+						//	}
3178
+						//
3179
+						//	service.CreateCancelStockInfoOne(&cancelStockInfo)
3180
+						//
3181
+						//	cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
3182
+						//
3183
+						//	flow := models.VmStockFlow{
3184
+						//		WarehousingId:           info.WarehouseInfotId,
3185
+						//		GoodId:                  item.ProjectId,
3186
+						//		Number:                  info.Number,
3187
+						//		LicenseNumber:           info.LicenseNumber,
3188
+						//		Count:                   info.Count,
3189
+						//		UserOrgId:               c.GetAdminUserInfo().CurrentOrgId,
3190
+						//		PatientId:               item.PatientId,
3191
+						//		SystemTime:              info.SysRecordTime,
3192
+						//		ConsumableType:          7,
3193
+						//		IsSys:                   0,
3194
+						//		WarehousingOrder:        "",
3195
+						//		WarehouseOutId:          info.WarehouseOutId,
3196
+						//		WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
3197
+						//		IsEdit:                  0,
3198
+						//		CancelStockId:           cancel.ID,
3199
+						//		CancelOrderNumber:       cancel.OrderNumber,
3200
+						//		Manufacturer:            manufacturer.ID,
3201
+						//		Dealer:                  0,
3202
+						//		Creator:                 c.GetAdminUserInfo().CurrentOrgId,
3203
+						//		UpdateCreator:           0,
3204
+						//		Status:                  1,
3205
+						//		Ctime:                   time.Now().Unix(),
3206
+						//		Mtime:                   0,
3207
+						//		Price:                   info.Price,
3208
+						//		WarehousingDetailId:     info.WarehouseInfotId,
3209
+						//		WarehouseOutDetailId:    info.ID,
3210
+						//		CancelOutDetailId:       cancelInfo.ID,
3211
+						//		ProductDate:             info.ProductDate,
3212
+						//		ExpireDate:              info.ExpiryDate,
3213
+						//		StorehouseId:            houseConfig.StorehouseOutInfo,
3214
+						//		OverCount:               flush_count,
3215
+						//	}
3216
+						//	service.CreateStockFlowOne(flow)
3217
+						//
3218
+						//	//退库数量增加
3219
+						//	service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
3220
+						//	//出库数量减少
3221
+						//	service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
3222
+						//
3223
+						//}
3124 3224
 
3125 3225
 						//查询已出库数量
3126 3226
 						dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
@@ -3132,7 +3232,7 @@ func (c *HisApiController) DeletePrescription() {
3132 3232
 
3133 3233
 						if prescribingNumber >= dialysisInfo.Count {
3134 3234
 							//删除出库表
3135
-							service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
3235
+							service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
3136 3236
 						}
3137 3237
 
3138 3238
 						goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
@@ -3178,7 +3278,7 @@ func (c *HisApiController) DeletePrescription() {
3178 3278
 		}
3179 3279
 
3180 3280
 	} else {
3181
-		if drugStockConfig.IsOpen == 1 {
3281
+		if drugOutConfig.IsOpen == 1 {
3182 3282
 			if len(advices) > 0 {
3183 3283
 				for _, item := range advices {
3184 3284
 					creater := c.GetAdminUserInfo().AdminUser.Id
@@ -3199,7 +3299,9 @@ func (c *HisApiController) DeleteDoctorAdvice() {
3199 3299
 	id, _ := c.GetInt64("id")
3200 3300
 	advice, _ := service.GetHisDoctorAdvicesById(id)
3201 3301
 
3202
-	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
3302
+	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
3303
+
3304
+	drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
3203 3305
 
3204 3306
 	//已收费和已发药的限制逻辑
3205 3307
 	isCharge := false
@@ -3281,7 +3383,8 @@ func (c *HisApiController) DeleteDoctorAdvice() {
3281 3383
 				service.DrugAutoAddCancelInfo(&advice, creater)
3282 3384
 			}
3283 3385
 		} else {
3284
-			if drugStockConfig.IsOpen == 1 {
3386
+
3387
+			if drugOutConfig.IsOpen == 1 {
3285 3388
 
3286 3389
 				//查询是否在处方中出库
3287 3390
 				openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
@@ -3570,7 +3673,7 @@ func (c *HisApiController) DeleteProject() {
3570 3673
 
3571 3674
 					if prescribingNumber >= dialysisInfo.Count {
3572 3675
 						//删除出库表
3573
-						service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
3676
+						service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
3574 3677
 					}
3575 3678
 
3576 3679
 					//更新剩余库存
@@ -3897,7 +4000,7 @@ func (c *HisApiController) DeleteProject() {
3897 4000
 
3898 4001
 				if prescribingNumber >= dialysisInfo.Count {
3899 4002
 					//删除出库表
3900
-					service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
4003
+					service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
3901 4004
 				}
3902 4005
 
3903 4006
 				//更新剩余库存
@@ -5843,6 +5946,7 @@ func (c *HisApiController) GetUploadInfo() {
5843 5946
 			}
5844 5947
 
5845 5948
 			for _, info := range prescriptionsOne {
5949
+
5846 5950
 				if info.Type == 1 {
5847 5951
 					hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
5848 5952
 				}
@@ -5866,9 +5970,10 @@ func (c *HisApiController) GetUploadInfo() {
5866 5970
 
5867 5971
 			//判断
5868 5972
 			for _, itemOne := range infos {
5973
+
5869 5974
 				for _, itemTwo := range hisAdvice {
5870 5975
 					if itemOne.DrugId == itemTwo.DrugId {
5871
-						itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
5976
+						itemTwo.Child = append(itemTwo.Child, itemOne)
5872 5977
 					}
5873 5978
 				}
5874 5979
 			}
@@ -5889,10 +5994,13 @@ func (c *HisApiController) GetUploadInfo() {
5889 5994
 					if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5890 5995
 						prescribing_number = parseIntPrescribingNumber
5891 5996
 					}
5997
+
5892 5998
 					sum_out_count += prescribing_number
5893 5999
 				}
5894
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
6000
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
5895 6001
 
6002
+				fmt.Println("sum_out_count233232323232wo", sum_out_count)
6003
+				fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
5896 6004
 				if sum_out_count > drugStockOut.FlushCount {
5897 6005
 					c.ServeSuccessJSON(map[string]interface{}{
5898 6006
 						"msg":  "2",
@@ -5901,11 +6009,11 @@ func (c *HisApiController) GetUploadInfo() {
5901 6009
 					return
5902 6010
 				}
5903 6011
 			}
5904
-
6012
+			fmt.Println("newGoods99999988882os", newGoods)
5905 6013
 			for _, itemOne := range newGoods {
5906 6014
 				for _, item := range newGoodOne {
5907
-					if itemOne.ProjectId == item.ProjectId {
5908
-						item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
6015
+					if itemOne.GoodId == item.GoodId {
6016
+						item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
5909 6017
 					}
5910 6018
 				}
5911 6019
 			}
@@ -5913,11 +6021,10 @@ func (c *HisApiController) GetUploadInfo() {
5913 6021
 			for _, item := range newGoodOne {
5914 6022
 				var sum_out_count_one int64
5915 6023
 				good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
5916
-
5917 6024
 				for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
5918 6025
 					sum_out_count_one += itemOne.Count
5919 6026
 				}
5920
-				list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
6027
+				list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
5921 6028
 				fmt.Println("sum_out_count_one", sum_out_count_one)
5922 6029
 				fmt.Println("list.FlushCount", list.FlushCount)
5923 6030
 				if sum_out_count_one > list.FlushCount {
@@ -6177,22 +6284,23 @@ func (c *HisApiController) GetUploadInfo() {
6177 6284
 
6178 6285
 				for _, item := range infoList {
6179 6286
 					medical, _ := service.GetBaseDrugMedical(item.DrugId)
6180
-					//药品出库
6181
-					service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
6182
-					//查询默认仓库
6183
-					storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
6184
-					//查询默认仓库剩余多少库存
6185
-					var sum_count int64
6186
-					stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
6187
-					for _, its := range stockInfo {
6188
-						if its.MaxUnit == medical.MaxUnit {
6189
-							its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
6287
+					if medical.IsUse == 2 {
6288
+						//药品出库
6289
+						service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
6290
+						//查询默认仓库
6291
+						storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
6292
+						//查询默认仓库剩余多少库存
6293
+						var sum_count int64
6294
+						stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
6295
+						for _, its := range stockInfo {
6296
+							if its.MaxUnit == medical.MaxUnit {
6297
+								its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
6298
+							}
6299
+							sum_count += its.StockMaxNumber + its.StockMinNumber
6190 6300
 						}
6191
-						sum_count += its.StockMaxNumber + its.StockMinNumber
6301
+						service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
6302
+						service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
6192 6303
 					}
6193
-					service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
6194
-					service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
6195
-
6196 6304
 				}
6197 6305
 				orgId := c.GetAdminUserInfo().CurrentOrgId
6198 6306
 
@@ -6250,20 +6358,22 @@ func (c *HisApiController) GetUploadInfo() {
6250 6358
 							Status:       1,
6251 6359
 							StorehouseId: houseConfig.StorehouseOutInfo,
6252 6360
 						}
6361
+						goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
6362
+						//非零用
6363
+						if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
6364
+							service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
6365
+							//查询剩余库存
6366
+							goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
6367
+							var sum_count int64
6368
+							for _, item := range goodList {
6369
+								sum_count += item.StockCount
6370
+							}
6371
+							service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
6253 6372
 
6254
-						//err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
6255
-
6256
-						service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
6257
-						//查询剩余库存
6258
-						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId)
6259
-						var sum_count int64
6260
-						for _, item := range goodList {
6261
-							sum_count += item.StockCount
6373
+							//耗材
6374
+							service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
6262 6375
 						}
6263
-						service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
6264 6376
 
6265
-						//耗材
6266
-						service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
6267 6377
 					}
6268 6378
 				}
6269 6379
 
@@ -6433,7 +6543,8 @@ func (c *HisApiController) GetUploadInfo() {
6433 6543
 							}
6434 6544
 							sum_out_count += prescribing_number
6435 6545
 						}
6436
-						drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
6546
+						houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
6547
+						drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
6437 6548
 
6438 6549
 						if sum_out_count > drugStockOut.FlushCount {
6439 6550
 							c.ServeSuccessJSON(map[string]interface{}{
@@ -6459,7 +6570,7 @@ func (c *HisApiController) GetUploadInfo() {
6459 6570
 						for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
6460 6571
 							sum_out_count_one += itemOne.Count
6461 6572
 						}
6462
-						list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
6573
+						list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
6463 6574
 						fmt.Println("sum_out_count_one", sum_out_count_one)
6464 6575
 						fmt.Println("list.FlushCount", list.FlushCount)
6465 6576
 						if sum_out_count_one > list.FlushCount {
@@ -6534,7 +6645,6 @@ func (c *HisApiController) Refund() {
6534 6645
 			infos = append(infos, &info.HisDoctorAdviceInfo)
6535 6646
 		}
6536 6647
 		if info.ProjectId > 0 && info.AdviceId == 0 {
6537
-			fmt.Println("info232323233232233", info.PatientId)
6538 6648
 			if info.HisPrescriptionProject.Type == 3 {
6539 6649
 				var good models.DialysisBeforePrepareGoods
6540 6650
 				var newGood models.NewDialysisBeforePrepareGoods
@@ -6545,6 +6655,7 @@ func (c *HisApiController) Refund() {
6545 6655
 				good.StorehouseId = houseConfig.StorehouseOutInfo
6546 6656
 				good.ProjectId = info.HisPrescriptionProject.ID
6547 6657
 				good.PatientId = info.PatientId
6658
+				good.OrderId = order_id
6548 6659
 				goods = append(goods, &good)
6549 6660
 
6550 6661
 				newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
@@ -6556,6 +6667,7 @@ func (c *HisApiController) Refund() {
6556 6667
 				newGood.RecordDate = order.SettleAccountsDate
6557 6668
 				newGood.UserOrgId = order.UserOrgId
6558 6669
 				newGood.PatientId = info.PatientId
6670
+				newGood.OrderId = order_id
6559 6671
 				newGoods = append(newGoods, &newGood)
6560 6672
 			}
6561 6673
 		}

+ 31 - 4
controllers/mobile_api_controllers/dialysis_api_controller.go Прегледај датотеку

@@ -1385,6 +1385,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
1385 1385
 	water_machine := c.GetString("water_machine")
1386 1386
 	add_amount, _ := c.GetFloat("add_amount")
1387 1387
 	reduce_amount, _ := c.GetFloat("reduce_amount")
1388
+	dialysis_remark := c.GetString("dialysis_remark")
1388 1389
 	appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
1389 1390
 
1390 1391
 	//template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
@@ -1497,6 +1498,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
1497 1498
 		WaterMachine:               water_machine,
1498 1499
 		AddAmount:                  add_amount,
1499 1500
 		ReduceAmount:               reduce_amount,
1501
+		DialysisRemark:             dialysis_remark,
1500 1502
 	}
1501 1503
 
1502 1504
 	//查询最近透析准备表里是否存在 透析器 灌流器
@@ -1842,7 +1844,10 @@ func (c *DialysisAPIController) Finish() {
1842 1844
 		tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
1843 1845
 		tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
1844 1846
 		tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
1845
-		tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
1847
+		if adminUserInfo.Org.Id != 10445 {
1848
+			tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
1849
+		}
1850
+
1846 1851
 		tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
1847 1852
 
1848 1853
 	}
@@ -2043,6 +2048,7 @@ func (c *DialysisAPIController) Finish() {
2043 2048
 		redis.Set(keyOne, "", time.Second)
2044 2049
 		//结束时候透析次数加1
2045 2050
 		service.UpdateSolutionByPatientId(id)
2051
+
2046 2052
 		dialysisOrder.Stage = 2
2047 2053
 		dialysisOrder.FinishNurse = nurseID
2048 2054
 		dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
@@ -2339,6 +2345,19 @@ func (this *DialysisAPIController) StartDialysis() {
2339 2345
 
2340 2346
 		createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
2341 2347
 		service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
2348
+
2349
+		if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
2350
+			//统计该患者总次数
2351
+			dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
2352
+			service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
2353
+		}
2354
+
2355
+		if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
2356
+			//统计该患者总次数
2357
+			dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
2358
+			service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
2359
+		}
2360
+
2342 2361
 		redis := service.RedisClient()
2343 2362
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
2344 2363
 		redis.Set(key, "", time.Second)
@@ -2633,6 +2652,7 @@ func (c *DialysisAPIController) PostSolution() {
2633 2652
 	drhy_water := c.GetString("drhy_water")
2634 2653
 	dry_water_hour := c.GetString("dry_water_hour")
2635 2654
 	water_machine := c.GetString("water_machine")
2655
+	dialysis_remark := c.GetString("dialysis_remark")
2636 2656
 	if mode_id > 0 {
2637 2657
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
2638 2658
 	}
@@ -2746,6 +2766,7 @@ func (c *DialysisAPIController) PostSolution() {
2746 2766
 		WaterMachine:               water_machine,
2747 2767
 		AddAmount:                  add_amount,
2748 2768
 		ReduceAmount:               reduce_amount,
2769
+		DialysisRemark:             dialysis_remark,
2749 2770
 	}
2750 2771
 
2751 2772
 	_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
@@ -2844,6 +2865,7 @@ func (c *DialysisAPIController) PostSolution() {
2844 2865
 		MaxUltrafiltrationRate:     max_ultrafiltration_rate,
2845 2866
 		PreImpulse:                 impulse,
2846 2867
 		SolutionStatus:             1,
2868
+		DialysisRemark:             dialysis_remark,
2847 2869
 	}
2848 2870
 
2849 2871
 	//针对河间咸的
@@ -6722,7 +6744,7 @@ func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *model
6722 6744
 	//扣减出库数量
6723 6745
 	service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
6724 6746
 	//查询剩余库存
6725
-	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID)
6747
+	goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
6726 6748
 	var sum_count int64
6727 6749
 	for _, item := range goodList {
6728 6750
 		sum_count += item.StockCount
@@ -7165,7 +7187,8 @@ func (this *DialysisAPIController) ExectionMobileAdvice() {
7165 7187
 				}
7166 7188
 				sum_out_count += prescribing_number
7167 7189
 			}
7168
-			drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
7190
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7191
+			drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
7169 7192
 
7170 7193
 			//库存不足
7171 7194
 			if sum_out_count > drugStockOut.FlushCount {
@@ -7285,7 +7308,8 @@ func (this *DialysisAPIController) ExectionMobileAdvice() {
7285 7308
 					}
7286 7309
 					sum_out_count += prescribing_number
7287 7310
 				}
7288
-				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId)
7311
+				houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
7312
+				drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
7289 7313
 
7290 7314
 				//库存不足
7291 7315
 				if sum_out_count > drugStockOut.FlushCount {
@@ -7627,6 +7651,7 @@ func (this *DialysisAPIController) CheckSchedule() {
7627 7651
 		if schedule.ID == 0 {
7628 7652
 			this.ServeSuccessJSON(map[string]interface{}{
7629 7653
 				"status": 0,
7654
+				"msg":    "请求失败",
7630 7655
 			})
7631 7656
 
7632 7657
 		} else {
@@ -7647,6 +7672,7 @@ func (this *DialysisAPIController) CheckSchedule() {
7647 7672
 					} else {
7648 7673
 						this.ServeSuccessJSON(map[string]interface{}{
7649 7674
 							"status": 0,
7675
+							"msg":    "",
7650 7676
 						})
7651 7677
 					}
7652 7678
 				}
@@ -7663,6 +7689,7 @@ func (this *DialysisAPIController) CheckSchedule() {
7663 7689
 	} else {
7664 7690
 		this.ServeSuccessJSON(map[string]interface{}{
7665 7691
 			"status": 0,
7692
+			"msg":    "",
7666 7693
 		})
7667 7694
 
7668 7695
 	}

+ 26 - 0
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go Прегледај датотеку

@@ -2869,3 +2869,29 @@ func (this *NewDialysisApiController) GetTreateSummary() {
2869 2869
 		return
2870 2870
 	}
2871 2871
 }
2872
+
2873
+func (this *NewDialysisApiController) CommitDialysisOrder() {
2874
+
2875
+	org_id := this.GetMobileAdminUserInfo().Org.Id
2876
+
2877
+	//查询所有患者
2878
+
2879
+	list, err := service.GetAllPatientScheduleList(org_id)
2880
+
2881
+	for _, item := range list {
2882
+		//查询所有患者的2022年12月31日以前的上机记录
2883
+		orderList, _ := service.GetAllDialysiOrderList(item.ID, org_id)
2884
+		for _, it := range orderList {
2885
+			dialysOrder, _ := service.GetDialysisTotalCountThree(it.UserOrgId, it.PatientId, it.DialysisDate)
2886
+			service.UpdateDialysisOrderSix(it.PatientId, it.DialysisDate, it.UserOrgId, dialysOrder.Count)
2887
+		}
2888
+	}
2889
+
2890
+	if err == nil {
2891
+		this.ServeSuccessJSON(map[string]interface{}{
2892
+			"list": list,
2893
+		})
2894
+		return
2895
+	}
2896
+
2897
+}

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

@@ -166,6 +166,8 @@ func NewMobileAPIControllersRegisterRouters() {
166 166
 	beego.Router("/m/api/patient/getvascularaccessdetail", &NewDialysisApiController{}, "Get:GetVascularAccessDetail")
167 167
 	beego.Router("/m/api/patient/getalldoctorlist", &NewDialysisApiController{}, "Get:GetAllDoctorList")
168 168
 	beego.Router("/m/api/patient/gettreatesummay", &NewDialysisApiController{}, "Get:GetTreateSummary")
169
+	//脚本
170
+	beego.Router("/m/api/patient/commitdialysisOrder", &NewDialysisApiController{}, "Get:CommitDialysisOrder")
169 171
 
170 172
 	//His相关
171 173
 	beego.Router("/m/api/hispatientlist/get", &MobileHisApiController{}, "Get:GetHisPatientList")

+ 0 - 3
controllers/patient_api_controller.go Прегледај датотеку

@@ -4526,10 +4526,7 @@ func (c *PatientApiController) GetRemindPatientList() {
4526 4526
 	limit, _ := c.GetInt64("limit", 10)
4527 4527
 	adminUserInfo := c.GetAdminUserInfo()
4528 4528
 	total, patients, _ := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
4529
-	fmt.Println("机构ID2222222222222", c.GetAdminUserInfo().CurrentOrgId)
4530
-
4531 4529
 	_, errcode := service.GetOrgFollowIsExist(c.GetAdminUserInfo().CurrentOrgId)
4532
-	fmt.Println("机构ID2222222222222", errcode)
4533 4530
 	if errcode == gorm.ErrRecordNotFound {
4534 4531
 		information, err := service.GetAdminUserRoleInformation(0)
4535 4532
 		if err != nil {

+ 36 - 12
controllers/print_data_api_controller.go Прегледај датотеку

@@ -37,7 +37,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
37 37
 	idStrs := strings.Split(schIDStr, ",")
38 38
 	adminUserInfo := this.GetAdminUserInfo()
39 39
 
40
-	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
40
+	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 {
41 41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
42 42
 		for _, item := range schedules {
43 43
 
@@ -81,14 +81,24 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
81 81
 			item.Summer = summerVM
82 82
 
83 83
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
84
-			if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
84
+			if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 && this.GetAdminUserInfo().CurrentOrgId != 10345 {
85 85
 				item.Count = list.Count
86 86
 			}
87
-			if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
88
-				listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
87
+			if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 || this.GetAdminUserInfo().CurrentOrgId == 10345 {
88
+				if item.ScheduleDate <= 1640966400 {
89
+					listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
90
+
91
+					item.Patient.TotalDialysis = listOne.Count
92
+					item.Count = listOne.Count
93
+				}
94
+
95
+				if item.ScheduleDate >= 1672502400 {
96
+					listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
97
+
98
+					item.Patient.TotalDialysis = listOne.Count
99
+					item.Count = listOne.Count
100
+				}
89 101
 
90
-				item.Patient.TotalDialysis = listOne.Count
91
-				item.Count = listOne.Count
92 102
 			}
93 103
 		}
94 104
 		if getScheduleErr != nil {
@@ -117,18 +127,32 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
117 127
 		})
118 128
 	}
119 129
 
120
-	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
130
+	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 {
121 131
 		schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
122 132
 		for _, item := range schedules {
123 133
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
124
-			if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 {
134
+			if this.GetAdminUserInfo().CurrentOrgId != 10101 && this.GetAdminUserInfo().CurrentOrgId != 9671 && this.GetAdminUserInfo().CurrentOrgId != 10345 {
125 135
 				item.Count = list.Count
126 136
 			}
127
-			if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 {
128
-				listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
137
+			if this.GetAdminUserInfo().CurrentOrgId == 10101 || this.GetAdminUserInfo().CurrentOrgId == 9671 || this.GetAdminUserInfo().CurrentOrgId == 10345 {
138
+				//listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
139
+
140
+				//item.Patient.TotalDialysis = listOne.Count
141
+				//item.Count = listOne.Count
142
+
143
+				if item.ScheduleDate <= 1640966400 {
144
+					listOne, _ := service.GetDialysisOrderCountEight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
145
+
146
+					item.Patient.TotalDialysis = listOne.Count
147
+					item.Count = listOne.Count
148
+				}
149
+
150
+				if item.ScheduleDate >= 1672502400 {
151
+					listOne, _ := service.GetDialysisOrderCountNight(adminUserInfo.CurrentOrgId, item.PatientID, item.ScheduleDate)
129 152
 
130
-				item.Patient.TotalDialysis = listOne.Count
131
-				item.Count = listOne.Count
153
+					item.Patient.TotalDialysis = listOne.Count
154
+					item.Count = listOne.Count
155
+				}
132 156
 			}
133 157
 		}
134 158
 		if getScheduleErr != nil {

+ 283 - 86
controllers/schedule_api_controller.go Прегледај датотеку

@@ -63,6 +63,7 @@ func ScheduleApiRegistRouters() {
63 63
 
64 64
 	beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
65 65
 	beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
66
+	beego.Router("/api/schedule/scheduletwo", &ScheduleApiController{}, "Get:GetScheduleTwo")
66 67
 	beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
67 68
 	beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
68 69
 	beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
@@ -72,7 +73,7 @@ func ScheduleApiRegistRouters() {
72 73
 	beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
73 74
 	beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
74 75
 
75
-	beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSch")
76
+	beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
76 77
 	beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
77 78
 
78 79
 	beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
@@ -83,6 +84,8 @@ func ScheduleApiRegistRouters() {
83 84
 
84 85
 	beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
85 86
 
87
+	beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
88
+
86 89
 }
87 90
 func (c *ScheduleApiController) BatchPostSmartSch() {
88 91
 	patient_id, _ := c.GetInt64("patient_id")
@@ -119,6 +122,7 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
119 122
 				sch_id := int64(items["sch_id"].(float64))
120 123
 				if sch_id > 0 { //修改排班信息
121 124
 					schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
125
+					fmt.Println("2222222")
122 126
 
123 127
 					if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
124 128
 						utils.ErrorLog("mode_id")
@@ -381,7 +385,10 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
381 385
 
382 386
 				} else { //新的排班信息
383 387
 
388
+					fmt.Println("111111111")
384 389
 					if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
390
+						fmt.Println("33333333")
391
+
385 392
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
386 393
 						return
387 394
 					}
@@ -400,6 +407,15 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
400 407
 						return
401 408
 					}
402 409
 					schedule.ScheduleDate = theTime.Unix()
410
+					//existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
411
+					//
412
+					//if existSch.ID > 0{
413
+					//	fmt.Println("555555555")
414
+					//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
415
+					//	return
416
+					//
417
+					//}
418
+
403 419
 					timeNow := time.Now().Format("2006-01-02")
404 420
 					if timeNow > scheduleDate {
405 421
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
@@ -468,7 +484,10 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
468 484
 
469 485
 					sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
470 486
 
471
-					if sch.ID > 0 {
487
+					fmt.Println(sch.PatientId)
488
+					fmt.Println(schedule.PatientId)
489
+
490
+					if sch.ID > 0 && sch.PatientId != patient_id {
472 491
 						week_type, _ := items["week_type"].(string)
473 492
 						week_name, _ := items["week_name"].(string)
474 493
 
@@ -540,7 +559,32 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
540 559
 			}
541 560
 		}
542 561
 	}
562
+	////删除数据
563
+	if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
543 564
 
565
+		schs, _ := dataBody["del_schs"].([]interface{})
566
+		if len(schs) > 0 {
567
+			for _, item := range schs {
568
+				items := item.(map[string]interface{})
569
+				if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
570
+					utils.ErrorLog("id")
571
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
572
+					return
573
+				}
574
+				var schedule models.Schedule
575
+				sch_id := int64(items["sch_id"].(float64))
576
+				if sch_id > 0 { //修改排班信息
577
+					schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
578
+					schedule.Status = 0
579
+					service.SaveSch(schedule)
580
+				}
581
+
582
+				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
583
+
584
+			}
585
+		}
586
+	}
587
+	////修改或保存数据
544 588
 	if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
545 589
 
546 590
 		schs, _ := dataBody["smart_schs"].([]interface{})
@@ -658,33 +702,34 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
658 702
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
659 703
 						return
660 704
 					}
661
-
705
+					var DialysisMachineName string
662 706
 					so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
663 707
 					filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
664 708
 					filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
665 709
 					filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
666 710
 
667 711
 					if filedRecordOne.IsShow == 1 {
668
-						schedule.DialysisMachineName = so.DialysisDialyszers
712
+						DialysisMachineName = so.DialysisDialyszers
669 713
 					}
670 714
 					if filedRecordThree.IsShow == 1 {
671
-						if len(schedule.DialysisMachineName) > 0 {
672
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
715
+						if len(DialysisMachineName) > 0 {
716
+							DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
673 717
 
674 718
 						} else {
675
-							schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
719
+							DialysisMachineName = so.DialyzerPerfusionApparatus
676 720
 
677 721
 						}
678 722
 					}
679 723
 					if filedRecordTwo.IsShow == 1 {
680
-						if len(schedule.DialysisMachineName) > 0 {
681
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
724
+						if len(DialysisMachineName) > 0 {
725
+							DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
682 726
 
683 727
 						} else {
684
-							schedule.DialysisMachineName = so.DialysisIrrigation
728
+							DialysisMachineName = so.DialysisIrrigation
685 729
 
686 730
 						}
687 731
 					}
732
+					schedule.DialysisMachineName = DialysisMachineName
688 733
 
689 734
 					service.SaveSch(schedule)
690 735
 				} else { //新的排班信息
@@ -778,17 +823,11 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
778 823
 
779 824
 					sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
780 825
 
781
-					if sch.ID > 0 {
826
+					if sch.ID > 0 && sch.PatientId != patient_id {
782 827
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
783 828
 						return
784 829
 					}
785
-
786
-					schedule.ModeId = modeId
787
-					schedule.PatientId = patient_id
788
-					schedule.CreatedTime = time.Now().Unix()
789
-					schedule.UpdatedTime = time.Now().Unix()
790
-					schedule.Status = 1
791
-					schedule.UserOrgId = adminInfo.CurrentOrgId
830
+					var DialysisMachineName string
792 831
 
793 832
 					so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
794 833
 					filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
@@ -796,48 +835,98 @@ func (c *ScheduleApiController) BatchPostSmartSch() {
796 835
 					filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
797 836
 
798 837
 					if filedRecordOne.IsShow == 1 {
799
-						schedule.DialysisMachineName = so.DialysisDialyszers
838
+						DialysisMachineName = so.DialysisDialyszers
800 839
 					}
801 840
 					if filedRecordThree.IsShow == 1 {
802 841
 						if len(schedule.DialysisMachineName) > 0 {
803
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
842
+							DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
804 843
 
805 844
 						} else {
806
-							schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
845
+							DialysisMachineName = so.DialyzerPerfusionApparatus
807 846
 
808 847
 						}
809 848
 					}
810 849
 					if filedRecordTwo.IsShow == 1 {
811
-						if len(schedule.DialysisMachineName) > 0 {
812
-							schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
850
+						if len(DialysisMachineName) > 0 {
851
+							DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
813 852
 
814 853
 						} else {
815
-							schedule.DialysisMachineName = so.DialysisIrrigation
854
+							DialysisMachineName = so.DialysisIrrigation
816 855
 
817 856
 						}
818 857
 					}
858
+					schedule.DialysisMachineName = DialysisMachineName
859
+
860
+					//判断当前保存的患者是否已经有排班
861
+					existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
862
+					if existSchedule.ID > 0 {
863
+						existSchedule.ModeId = modeId
864
+						existSchedule.BedId = schedule.BedId
865
+						existSchedule.PartitionId = schedule.PartitionId
866
+						existSchedule.ScheduleType = schedule.ScheduleType
867
+						existSchedule.DialysisMachineName = schedule.DialysisMachineName
868
+						service.SaveSmartSch(existSchedule)
819 869
 
820
-					daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
821
-					if daySchedule.ID > 0 {
822
-						daySchedule.ModeId = schedule.ModeId
823
-						daySchedule.ScheduleType = schedule.ScheduleType
824
-						daySchedule.PartitionId = schedule.PartitionId
825
-						daySchedule.BedId = schedule.BedId
826
-						daySchedule.DialysisMachineName = schedule.DialysisMachineName
827
-						service.SaveSch(daySchedule)
828 870
 					} else {
829
-						service.CreateSchedule(&schedule)
871
+						schedule.ModeId = modeId
872
+						schedule.PatientId = patient_id
873
+						schedule.CreatedTime = time.Now().Unix()
874
+						schedule.UpdatedTime = time.Now().Unix()
875
+						schedule.Status = 1
876
+						schedule.UserOrgId = adminInfo.CurrentOrgId
877
+
878
+						var DialysisMachineName string
879
+						so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
880
+						filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
881
+						filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
882
+						filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
883
+
884
+						if filedRecordOne.IsShow == 1 {
885
+							DialysisMachineName = so.DialysisDialyszers
886
+						}
887
+						if filedRecordThree.IsShow == 1 {
888
+							if len(DialysisMachineName) > 0 {
889
+								DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
890
+
891
+							} else {
892
+								DialysisMachineName = so.DialyzerPerfusionApparatus
893
+
894
+							}
895
+						}
896
+						if filedRecordTwo.IsShow == 1 {
897
+							if len(DialysisMachineName) > 0 {
898
+								DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
899
+
900
+							} else {
901
+								DialysisMachineName = so.DialysisIrrigation
902
+
903
+							}
904
+						}
905
+						schedule.DialysisMachineName = DialysisMachineName
906
+						//schedule.DialysisMachineName = schedule.DialysisMachineName
907
+						daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
908
+						if daySchedule.ID > 0 {
909
+							daySchedule.ModeId = schedule.ModeId
910
+							daySchedule.ScheduleType = schedule.ScheduleType
911
+							daySchedule.PartitionId = schedule.PartitionId
912
+							daySchedule.BedId = schedule.BedId
913
+							daySchedule.DialysisMachineName = schedule.DialysisMachineName
914
+							service.SaveSch(daySchedule)
915
+						} else {
916
+							service.CreateSchedule(&schedule)
917
+						}
830 918
 					}
831 919
 				}
920
+
832 921
 				c.ServeSuccessJSON(map[string]interface{}{
833 922
 					"msg": "保存成功",
834 923
 				})
835
-
836 924
 				HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
837 925
 
838 926
 			}
839 927
 		}
840 928
 	}
929
+
841 930
 }
842 931
 func HandleRedis(org_id int64, sch_date int64) {
843 932
 	redis := service.RedisClient()
@@ -861,7 +950,25 @@ func HandleRedis(org_id int64, sch_date int64) {
861 950
 
862 951
 }
863 952
 
864
-func (c *ScheduleApiController) GetPatientSch() {
953
+func (c *ScheduleApiController) GetSmartSch() {
954
+	patient_id, _ := c.GetInt64("patient_id")
955
+	fmt.Println("~~~~~~")
956
+	fmt.Println(patient_id)
957
+	fmt.Println("~~~~~~")
958
+
959
+	adminUserInfo := c.GetAdminUserInfo()
960
+	sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
961
+	if err != nil {
962
+		utils.ErrorLog(err.Error())
963
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
964
+		return
965
+	}
966
+	c.ServeSuccessJSON(map[string]interface{}{
967
+		"sch": sch,
968
+	})
969
+}
970
+
971
+func (c *ScheduleApiController) GetPatient() {
865 972
 	keyWord := c.GetString("keyword")
866 973
 	adminUserInfo := c.GetAdminUserInfo()
867 974
 	patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
@@ -876,6 +983,7 @@ func (c *ScheduleApiController) GetPatientSch() {
876 983
 }
877 984
 
878 985
 func (c *ScheduleApiController) GetPatientSchTemplate() {
986
+	//patient_id, _ := c.GetInt64("patient_id",0)
879 987
 	keyWord := c.GetString("keyword")
880 988
 	adminUserInfo := c.GetAdminUserInfo()
881 989
 	patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
@@ -1264,32 +1372,34 @@ func (c *ScheduleApiController) CreateSchedule() {
1264 1372
 	schedule.UserOrgId = adminUserInfo.CurrentOrgId
1265 1373
 	schedule.IsExport = 5
1266 1374
 
1375
+	var DialysisMachineName string
1267 1376
 	so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
1268 1377
 	filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
1269 1378
 	filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
1270 1379
 	filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
1271 1380
 
1272 1381
 	if filedRecordOne.IsShow == 1 {
1273
-		schedule.DialysisMachineName = so.DialysisDialyszers
1382
+		DialysisMachineName = so.DialysisDialyszers
1274 1383
 	}
1275 1384
 	if filedRecordThree.IsShow == 1 {
1276
-		if len(schedule.DialysisMachineName) > 0 {
1277
-			schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1385
+		if len(DialysisMachineName) > 0 {
1386
+			DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1278 1387
 
1279 1388
 		} else {
1280
-			schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1389
+			DialysisMachineName = so.DialyzerPerfusionApparatus
1281 1390
 
1282 1391
 		}
1283 1392
 	}
1284 1393
 	if filedRecordTwo.IsShow == 1 {
1285
-		if len(schedule.DialysisMachineName) > 0 {
1286
-			schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1394
+		if len(DialysisMachineName) > 0 {
1395
+			DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
1287 1396
 
1288 1397
 		} else {
1289
-			schedule.DialysisMachineName = so.DialysisIrrigation
1398
+			DialysisMachineName = so.DialysisIrrigation
1290 1399
 
1291 1400
 		}
1292 1401
 	}
1402
+	schedule.DialysisMachineName = DialysisMachineName
1293 1403
 
1294 1404
 	bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
1295 1405
 	if bed == nil {
@@ -1494,28 +1604,29 @@ func (c *ScheduleApiController) ChangeSchedule() {
1494 1604
 		filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
1495 1605
 		filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
1496 1606
 		filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
1497
-
1607
+		var DialysisMachineName string
1498 1608
 		if filedRecordOne.IsShow == 1 {
1499
-			schedule.DialysisMachineName = so.DialysisDialyszers
1609
+			DialysisMachineName = so.DialysisDialyszers
1500 1610
 		}
1501 1611
 		if filedRecordThree.IsShow == 1 {
1502 1612
 			if len(schedule.DialysisMachineName) > 0 {
1503
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1613
+				DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
1504 1614
 
1505 1615
 			} else {
1506
-				schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
1616
+				DialysisMachineName = so.DialyzerPerfusionApparatus
1507 1617
 
1508 1618
 			}
1509 1619
 		}
1510 1620
 		if filedRecordTwo.IsShow == 1 {
1511
-			if len(schedule.DialysisMachineName) > 0 {
1512
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1621
+			if len(DialysisMachineName) > 0 {
1622
+				DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
1513 1623
 
1514 1624
 			} else {
1515
-				schedule.DialysisMachineName = so.DialysisIrrigation
1625
+				DialysisMachineName = so.DialysisIrrigation
1516 1626
 
1517 1627
 			}
1518 1628
 		}
1629
+		schedule.DialysisMachineName = DialysisMachineName
1519 1630
 
1520 1631
 		order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
1521 1632
 		if err != nil {
@@ -2418,32 +2529,35 @@ func (this *ScheduleApiController) ExportSchedule() {
2418 2529
 			sch.Status = 1
2419 2530
 			sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
2420 2531
 			sch.IsExport = 1
2532
+
2533
+			var DialysisMachineName string
2421 2534
 			so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
2422 2535
 			filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
2423 2536
 			filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
2424 2537
 			filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
2425 2538
 
2426 2539
 			if filedRecordOne.IsShow == 1 {
2427
-				sch.DialysisMachineName = so.DialysisDialyszers
2540
+				DialysisMachineName = so.DialysisDialyszers
2428 2541
 			}
2429 2542
 			if filedRecordThree.IsShow == 1 {
2430
-				if len(sch.DialysisMachineName) > 0 {
2431
-					sch.DialysisMachineName = sch.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
2543
+				if len(DialysisMachineName) > 0 {
2544
+					DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
2432 2545
 
2433 2546
 				} else {
2434
-					sch.DialysisMachineName = so.DialyzerPerfusionApparatus
2547
+					DialysisMachineName = so.DialyzerPerfusionApparatus
2435 2548
 
2436 2549
 				}
2437 2550
 			}
2438 2551
 			if filedRecordTwo.IsShow == 1 {
2439
-				if len(sch.DialysisMachineName) > 0 {
2440
-					sch.DialysisMachineName = sch.DialysisMachineName + "," + so.DialysisIrrigation
2552
+				if len(DialysisMachineName) > 0 {
2553
+					DialysisMachineName = sch.DialysisMachineName + "," + so.DialysisIrrigation
2441 2554
 
2442 2555
 				} else {
2443
-					sch.DialysisMachineName = so.DialysisIrrigation
2556
+					DialysisMachineName = so.DialysisIrrigation
2444 2557
 
2445 2558
 				}
2446 2559
 			}
2560
+			sch.DialysisMachineName = DialysisMachineName
2447 2561
 
2448 2562
 			schedules = append(schedules, &sch)
2449 2563
 		}
@@ -2455,21 +2569,29 @@ func (this *ScheduleApiController) ExportSchedule() {
2455 2569
 			date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
2456 2570
 			clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
2457 2571
 
2572
+			service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
2573
+
2458 2574
 			if err == nil {
2459 2575
 				for _, item := range schedules {
2460 2576
 					if item.ScheduleDate > clear_schedule_date {
2461 2577
 						//查询该患者是否转出获取死亡
2578
+						fmt.Println("11111323242423")
2462 2579
 
2463 2580
 						//查找当天日期是否存在
2464 2581
 						_, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
2465 2582
 						if errcode == gorm.ErrRecordNotFound {
2466 2583
 							//查询该床位是否有患者
2584
+							fmt.Println("errcodes")
2467 2585
 							sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
2586
+							fmt.Println("errcodes")
2587
+							fmt.Println(errcodes)
2588
+							fmt.Println(sch)
2468 2589
 
2469 2590
 							if errcodes == gorm.ErrRecordNotFound {
2591
+								fmt.Println("1111111")
2470 2592
 								service.CreateSchedule(item)
2471 2593
 							} else if errcodes == nil {
2472
-
2594
+								fmt.Println("1111222222222")
2473 2595
 								//清除当天该床位已有的患者
2474 2596
 								service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
2475 2597
 								service.CreateSchedule(item)
@@ -2477,15 +2599,17 @@ func (this *ScheduleApiController) ExportSchedule() {
2477 2599
 
2478 2600
 						} else if errcode == nil {
2479 2601
 							schedule := models.XtSchedule{
2480
-								PartitionId:  item.PartitionId,
2481
-								BedId:        item.BedId,
2482
-								PatientId:    item.PatientId,
2483
-								ScheduleDate: item.ScheduleDate,
2484
-								ScheduleType: item.ScheduleType,
2485
-								ScheduleWeek: item.ScheduleWeek,
2486
-								ModeId:       item.ModeId,
2487
-								Status:       1,
2602
+								PartitionId:         item.PartitionId,
2603
+								BedId:               item.BedId,
2604
+								PatientId:           item.PatientId,
2605
+								ScheduleDate:        item.ScheduleDate,
2606
+								ScheduleType:        item.ScheduleType,
2607
+								ScheduleWeek:        item.ScheduleWeek,
2608
+								ModeId:              1,
2609
+								Status:              1,
2610
+								DialysisMachineName: item.DialysisMachineName,
2488 2611
 							}
2612
+							fmt.Println("1111222222223333333333333333332")
2489 2613
 
2490 2614
 							service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
2491 2615
 						}
@@ -3321,32 +3445,35 @@ func (this *ScheduleApiController) GetCopyPatientSchedules() {
3321 3445
 			CreatedTime:  time.Now().Unix(),
3322 3446
 		}
3323 3447
 
3448
+		var DialysisMachineName string
3449
+
3324 3450
 		so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
3325 3451
 		filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
3326 3452
 		filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
3327 3453
 		filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
3328 3454
 
3329 3455
 		if filedRecordOne.IsShow == 1 {
3330
-			schedule.DialysisMachineName = so.DialysisDialyszers
3456
+			DialysisMachineName = so.DialysisDialyszers
3331 3457
 		}
3332 3458
 		if filedRecordThree.IsShow == 1 {
3333
-			if len(schedule.DialysisMachineName) > 0 {
3334
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3459
+			if len(DialysisMachineName) > 0 {
3460
+				DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
3335 3461
 
3336 3462
 			} else {
3337
-				schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
3463
+				DialysisMachineName = so.DialyzerPerfusionApparatus
3338 3464
 
3339 3465
 			}
3340 3466
 		}
3341 3467
 		if filedRecordTwo.IsShow == 1 {
3342
-			if len(schedule.DialysisMachineName) > 0 {
3343
-				schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
3468
+			if len(DialysisMachineName) > 0 {
3469
+				DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
3344 3470
 
3345 3471
 			} else {
3346
-				schedule.DialysisMachineName = so.DialysisIrrigation
3472
+				DialysisMachineName = so.DialysisIrrigation
3347 3473
 
3348 3474
 			}
3349 3475
 		}
3476
+		schedule.DialysisMachineName = DialysisMachineName
3350 3477
 
3351 3478
 		err = service.AddPatientSchedule(&schedule)
3352 3479
 
@@ -3868,6 +3995,72 @@ func (c *ScheduleApiController) GetScheduleOne() {
3868 3995
 	return
3869 3996
 }
3870 3997
 
3998
+func (c *ScheduleApiController) GetScheduleTwo() {
3999
+
4000
+	week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
4001
+	patitionIdStr := c.GetString("patitionid")
4002
+
4003
+	ids := strings.Split(patitionIdStr, ",")
4004
+
4005
+	schedule_type, _ := c.GetInt64("schedule_type")
4006
+
4007
+	adminInfo := c.GetAdminUserInfo()
4008
+	weekDateStr := c.GetString("week_date")
4009
+	WeekDayIds := strings.Split(weekDateStr, ",")
4010
+
4011
+	thisTime := time.Now()
4012
+	today := thisTime.Format("2006-01-02")
4013
+	if week < 1 || week > 4 {
4014
+		week = 2
4015
+	}
4016
+	if week == 1 {
4017
+		thisTime = thisTime.AddDate(0, 0, -7)
4018
+	} else if week == 3 {
4019
+		thisTime = thisTime.AddDate(0, 0, 7)
4020
+	} else if week == 4 {
4021
+		thisTime = thisTime.AddDate(0, 0, 14)
4022
+	}
4023
+
4024
+	weekDay := int(thisTime.Weekday())
4025
+	if weekDay == 0 {
4026
+		weekDay = 7
4027
+	}
4028
+	weekEnd := 7 - weekDay
4029
+	weekStart := weekEnd - 6
4030
+	weekTitle := make([]string, 0)
4031
+	days := make([]string, 0)
4032
+	for index := weekStart; index <= weekEnd; index++ {
4033
+		theDay := thisTime.AddDate(0, 0, index)
4034
+		indexYear, indexMonthTime, indexDay := theDay.Date()
4035
+		indexMonth := int(indexMonthTime)
4036
+		indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
4037
+		weekTitle = append(weekTitle, indexWeek)
4038
+		days = append(days, theDay.Format("2006-01-02"))
4039
+	}
4040
+
4041
+	weekStartDay := thisTime.AddDate(0, 0, weekStart)
4042
+	weekEndDay := thisTime.AddDate(0, 0, weekEnd)
4043
+	weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
4044
+	weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
4045
+
4046
+	timeLayout := "2006-01-02 15:04:05"
4047
+	loc, _ := time.LoadLocation("Local")
4048
+	theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
4049
+	theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
4050
+	weekStartPoint := theStarTime.Unix()
4051
+	weekEndPoint := theEndTime.Unix()
4052
+
4053
+	schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
4054
+
4055
+	c.ServeSuccessJSON(map[string]interface{}{
4056
+		"days":      days,
4057
+		"weekTitle": weekTitle,
4058
+		"schdules":  schdules,
4059
+		"today":     today,
4060
+	})
4061
+	return
4062
+}
4063
+
3871 4064
 func (c *ScheduleApiController) SaveScheduleTemplate() {
3872 4065
 
3873 4066
 	template_id, _ := c.GetInt64("template_id")
@@ -3917,7 +4110,6 @@ func (c *ScheduleApiController) ChangeFuncPrint() {
3917 4110
 	}
3918 4111
 
3919 4112
 	_, errcode := service.GetDataPrintByOrgId(orgId)
3920
-	fmt.Println("errcode222234444555556t66", errcode)
3921 4113
 	if errcode == gorm.ErrRecordNotFound {
3922 4114
 		service.CreateDataPrint(&dataPrint)
3923 4115
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -4030,32 +4222,34 @@ func (c *ScheduleApiController) SynchroSchedule() {
4030 4222
 				UpdatedTime:  0,
4031 4223
 			}
4032 4224
 
4225
+			var DialysisMachineName string
4033 4226
 			so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
4034 4227
 			filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
4035 4228
 			filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
4036 4229
 			filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
4037 4230
 
4038 4231
 			if filedRecordOne.IsShow == 1 {
4039
-				schedule.DialysisMachineName = so.DialysisDialyszers
4232
+				DialysisMachineName = so.DialysisDialyszers
4040 4233
 			}
4041 4234
 			if filedRecordThree.IsShow == 1 {
4042
-				if len(schedule.DialysisMachineName) > 0 {
4043
-					schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4235
+				if len(DialysisMachineName) > 0 {
4236
+					DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4044 4237
 
4045 4238
 				} else {
4046
-					schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
4239
+					DialysisMachineName = so.DialyzerPerfusionApparatus
4047 4240
 
4048 4241
 				}
4049 4242
 			}
4050 4243
 			if filedRecordTwo.IsShow == 1 {
4051
-				if len(schedule.DialysisMachineName) > 0 {
4052
-					schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
4244
+				if len(DialysisMachineName) > 0 {
4245
+					DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
4053 4246
 
4054 4247
 				} else {
4055
-					schedule.DialysisMachineName = so.DialysisIrrigation
4248
+					DialysisMachineName = so.DialysisIrrigation
4056 4249
 
4057 4250
 				}
4058 4251
 			}
4252
+			schedule.DialysisMachineName = DialysisMachineName
4059 4253
 
4060 4254
 			service.CreatePatientSchedule(&schedule)
4061 4255
 		}
@@ -4119,32 +4313,35 @@ func (c *ScheduleApiController) SynchroSchedule() {
4119 4313
 					CreatedTime:  time.Now().Unix(),
4120 4314
 					UpdatedTime:  0,
4121 4315
 				}
4316
+
4317
+				var DialysisMachineName string
4122 4318
 				so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
4123 4319
 				filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
4124 4320
 				filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
4125 4321
 				filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
4126 4322
 
4127 4323
 				if filedRecordOne.IsShow == 1 {
4128
-					schedule.DialysisMachineName = so.DialysisDialyszers
4324
+					DialysisMachineName = so.DialysisDialyszers
4129 4325
 				}
4130 4326
 				if filedRecordThree.IsShow == 1 {
4131
-					if len(schedule.DialysisMachineName) > 0 {
4132
-						schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4327
+					if len(DialysisMachineName) > 0 {
4328
+						DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
4133 4329
 
4134 4330
 					} else {
4135
-						schedule.DialysisMachineName = so.DialyzerPerfusionApparatus
4331
+						DialysisMachineName = so.DialyzerPerfusionApparatus
4136 4332
 
4137 4333
 					}
4138 4334
 				}
4139 4335
 				if filedRecordTwo.IsShow == 1 {
4140 4336
 					if len(schedule.DialysisMachineName) > 0 {
4141
-						schedule.DialysisMachineName = schedule.DialysisMachineName + "," + so.DialysisIrrigation
4337
+						DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
4142 4338
 
4143 4339
 					} else {
4144
-						schedule.DialysisMachineName = so.DialysisIrrigation
4340
+						DialysisMachineName = so.DialysisIrrigation
4145 4341
 
4146 4342
 					}
4147 4343
 				}
4344
+				schedule.DialysisMachineName = DialysisMachineName
4148 4345
 				service.CreatePatientSchedule(&schedule)
4149 4346
 			}
4150 4347
 		}

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

@@ -6,6 +6,7 @@ import (
6 6
 	"XT_New/service"
7 7
 	"encoding/json"
8 8
 	"fmt"
9
+	"strconv"
9 10
 	"strings"
10 11
 	"time"
11 12
 
@@ -19,7 +20,30 @@ func PatientScheduleTemplateAPIControllerRegistRouters() {
19 20
 
20 21
 	beego.Router("/api/patients/list", &PatientScheduleTemplateAPIController{}, "get:GetPatientList")
21 22
 
23
+	beego.Router("/api/schedule/update_schtemplate", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedulesTemplate")
24
+	beego.Router("/api/schtemplate_device/get", &ScheduleApiController{}, "Get:GetTemplateDevicesNumbers")
25
+
22 26
 	// beego.Router("/api/test", &TestCtr{}, "get:Test")
27
+
28
+}
29
+func (c *ScheduleApiController) GetTemplateDevicesNumbers() {
30
+	sch_type, _ := c.GetInt("sch_type", 0)
31
+	zone_id, _ := c.GetInt64("zone_id", 0)
32
+	patient_id, _ := c.GetInt64("patient_id", 0)
33
+	template_id, _ := c.GetInt64("template_id", 0)
34
+
35
+	weekday, _ := c.GetInt64("weekday")
36
+
37
+	deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildTemplateDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, weekday, sch_type, zone_id, patient_id, template_id)
38
+	if getDeviceNumbersErr != nil {
39
+		c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
40
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
41
+		return
42
+	}
43
+	c.ServeSuccessJSON(map[string]interface{}{
44
+		"devices": deviceNumbers,
45
+	})
46
+
23 47
 }
24 48
 
25 49
 // type TestCtr struct {
@@ -189,6 +213,7 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
189 213
 		return
190 214
 	}
191 215
 	templateMode.Week = int64(week_time)
216
+	templateMode.OriginalWeek = int64(week_time)
192 217
 
193 218
 	if mode != templateMode.Mode {
194 219
 		if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2  则直接清除下四周的排班
@@ -422,6 +447,10 @@ func (this *PatientScheduleTemplateAPIController) SetMode() {
422 447
 			service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3)
423 448
 		}
424 449
 
450
+	} else {
451
+		fmt.Println("~~~~~~~~")
452
+		service.UpdateTemplateItemModeWeek(adminUserInfo.CurrentOrgId, templateMode.ID, templateMode.OriginalWeek)
453
+
425 454
 	}
426 455
 
427 456
 	this.ServeSuccessJSON(nil)
@@ -619,14 +648,17 @@ func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
619 648
 		return
620 649
 	}
621 650
 
622
-	newItems, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItemsByTemplateID(adminUserInfo.CurrentOrgId)
651
+	//newItems, getTemplateItemsErr := service.GetAllPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId)
652
+	templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
653
+
654
+	//newItems, getTemplateItemsErr := service.GetAllPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId)
623 655
 	if getTemplateItemsErr != nil {
624 656
 		this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
625 657
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
626 658
 		return
627 659
 	}
628 660
 	this.ServeSuccessJSON(map[string]interface{}{
629
-		"items": newItems,
661
+		"items": templates,
630 662
 	})
631 663
 }
632 664
 
@@ -648,3 +680,109 @@ func (this *PatientScheduleTemplateAPIController) GetPatientList() {
648 680
 	})
649 681
 
650 682
 }
683
+
684
+type ParamModelEditSchedule struct {
685
+	ID             int64  `json:"sch_id"`
686
+	DeviceNumberID int64  `json:"jihao_id"`
687
+	PatientID      int64  `json:"patient_id"`
688
+	Mode           int64  `json:"mode_id"`
689
+	Weekday        int64  `json:"schedule_week"`
690
+	TimeType       int64  `json:"time_type"`
691
+	TemplateID     int64  `json:"t_id"`
692
+	Title          string `json:"title"`
693
+}
694
+
695
+func (this *PatientScheduleTemplateAPIController) UpdateSchedulesTemplate() {
696
+	addOrEditSchedulesJSON := this.GetString("edit_schs")
697
+	//delSchedulesJSON := this.GetString("del_schs")
698
+
699
+	fmt.Println(addOrEditSchedulesJSON)
700
+	var addOrEditSchedules []*ParamModelEditSchedule
701
+	//var delSchedules []*ParamModelEditSchedule
702
+
703
+	parseErr := json.Unmarshal([]byte(addOrEditSchedulesJSON), &addOrEditSchedules)
704
+	//parseDelErr := json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
705
+
706
+	fmt.Println(parseErr)
707
+	if parseErr != nil {
708
+		this.ErrorLog("解析增加编辑排班的数组参数失败:%v", parseErr)
709
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
710
+		return
711
+	}
712
+	//if parseDelErr != nil {
713
+	//	this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
714
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
715
+	//	return
716
+	//}
717
+
718
+	for _, item := range addOrEditSchedules {
719
+
720
+		if item.ID > 0 { //已经存在的数据
721
+			src_template, _ := service.GetScheduleTemplateItem(item.ID)
722
+			src_template.DeviceNumberID = item.DeviceNumberID
723
+			src_template.TimeType = int8(item.TimeType)
724
+			src_template.TreatMode = item.Mode
725
+			//service.SaveSchTemplateItem(src_template)
726
+			fmt.Println("11111")
727
+		} else {
728
+			schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
729
+			fmt.Println("222222")
730
+
731
+			if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
732
+				fmt.Println("333333333")
733
+				src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)
734
+				src_template.DeviceNumberID = item.DeviceNumberID
735
+				src_template.TimeType = int8(item.TimeType)
736
+				src_template.TreatMode = item.Mode
737
+				service.SaveSchTemplateItem(src_template)
738
+
739
+			} else {
740
+				schItem, _ := service.GetScheduleTemplateOne(this.GetAdminUserInfo().CurrentOrgId, item.DeviceNumberID, item.TemplateID, item.Weekday)
741
+
742
+				if schItem.ID == 0 { //床位未被占用
743
+
744
+					var template models.PatientScheduleTemplateItem
745
+					template.TreatMode = item.Mode
746
+					template.TemplateID = int64(item.TemplateID)
747
+					template.TimeType = int8(item.TimeType)
748
+					template.DeviceNumberID = item.DeviceNumberID
749
+					template.CreateTime = time.Now().Unix()
750
+					template.ModifyTime = time.Now().Unix()
751
+					template.OrgID = this.GetAdminUserInfo().CurrentOrgId
752
+					template.PatientID = item.PatientID
753
+					template.Weekday = int8(item.Weekday)
754
+					template.Status = 1
755
+					service.SaveSchTemplateItem(template)
756
+
757
+				} else { //床位被占用 1.被自己占用,2。被别人占用
758
+					//fmt.Println("555555555")
759
+
760
+					if schItem.PatientID != 0 && schItem.PatientID == item.PatientID { //当天该患者已经存在排班则设为修改操作
761
+						//fmt.Println("66666")
762
+						src_template, _ := service.GetScheduleTemplateItem(schItem.ID)
763
+						src_template.DeviceNumberID = item.DeviceNumberID
764
+						src_template.TimeType = int8(item.TimeType)
765
+						src_template.TreatMode = item.Mode
766
+						service.SaveSchTemplateItem(src_template)
767
+
768
+					} else if schItem.PatientID != 0 && schItem.PatientID != item.PatientID { //当天该床位被其他人占用,则无法保存
769
+						//fmt.Println("7777777")
770
+						json := make(map[string]interface{})
771
+						json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班,无法保存"
772
+						json["state"] = 0
773
+						this.Data["json"] = json
774
+						this.ServeJSON()
775
+						break
776
+					}
777
+				}
778
+
779
+			}
780
+
781
+		}
782
+	}
783
+
784
+	templates, _ := service.GetOrgPatientScheduleTemplateItems(this.GetAdminUserInfo().CurrentOrgId)
785
+	this.ServeSuccessJSON(map[string]interface{}{
786
+		"items": templates,
787
+	})
788
+}

+ 297 - 149
controllers/secondary_order_api_contorller.go Прегледај датотеку

@@ -1397,118 +1397,6 @@ func (this *SecondaryOrderApiController) CheckSecondOrer() {
1397 1397
 		}
1398 1398
 	}
1399 1399
 
1400
-	//获取所有的入库仓库
1401
-	//druglist, _ := service.GetDrugWarehouseInfoStorehouseList(orgId)
1402
-	//for _, item := range druglist {
1403
-	//	//查询该药品该仓库是否有数据
1404
-	//	drug, _ := service.GetDrugStockCout(item.DrugId, item.StorehouseId, item.OrgId)
1405
-	//
1406
-	//	//查询该仓库该药品的入库数量
1407
-	//	medical, _ := service.GetBaseDrugMedical(item.DrugId)
1408
-	//
1409
-	//	var sum_in_count int64
1410
-	//	var flush_count int64
1411
-	//	var sum_out_count int64
1412
-	//	var cancel_out_count int64
1413
-	//	//查询入库数量和剩余库存
1414
-	//	infolist, _ := service.GetDrugWarehouseInfoByStorehouseId(item.StorehouseId, item.DrugId, item.OrgId)
1415
-	//	for _, it := range infolist {
1416
-	//		if it.MaxUnit == medical.MaxUnit {
1417
-	//			it.WarehousingCount = it.WarehousingCount * medical.MinNumber
1418
-	//			it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
1419
-	//		}
1420
-	//		sum_in_count += it.WarehousingCount
1421
-	//		flush_count += it.StockMaxNumber + it.StockMinNumber
1422
-	//	}
1423
-	//
1424
-	//	//获取出库数量
1425
-	//	outinfolist, _ := service.GetDrugFlowStockOutCount(item.StorehouseId, item.DrugId, item.OrgId)
1426
-	//	for _, it := range outinfolist {
1427
-	//		if it.MaxUnit == medical.MaxUnit {
1428
-	//			it.Count = it.Count * medical.MinNumber
1429
-	//		}
1430
-	//		sum_out_count += it.Count
1431
-	//	}
1432
-	//
1433
-	//	//获取退库数量
1434
-	//	cancelinfolist, _ := service.GetDrugFlowStockCancelCount(item.StorehouseId, item.DrugId, item.OrgId)
1435
-	//	for _, it := range cancelinfolist {
1436
-	//		if it.MaxUnit == medical.MaxUnit {
1437
-	//			it.Count = it.Count * medical.MinNumber
1438
-	//		}
1439
-	//		cancel_out_count += it.Count
1440
-	//	}
1441
-	//
1442
-	//	//新增
1443
-	//	if drug.ID == 0 {
1444
-	//		drugstock := models.XtDrugStockCount{
1445
-	//			UserOrgId:      orgId,
1446
-	//			StorehouseId:   item.StorehouseId,
1447
-	//			SumInCount:     sum_in_count,
1448
-	//			SumOutCount:    sum_out_count - cancel_out_count,
1449
-	//			SumCancelCount: cancel_out_count,
1450
-	//			DrugId:         item.DrugId,
1451
-	//			Ctime:          time.Now().Unix(),
1452
-	//			Mtime:          0,
1453
-	//			Status:         1,
1454
-	//			FlushCount:     flush_count,
1455
-	//			SumActOutCount: sum_out_count,
1456
-	//		}
1457
-	//		service.CreateDrugStockCount(drugstock)
1458
-	//	}
1459
-	//}
1460
-	//
1461
-	////获取入库数量
1462
-	//
1463
-	//
1464
-	//
1465
-	//////获取入库数据
1466
-	//goodlist, _ := service.GetSendGoodInformation(orgId)
1467
-	//for _, it := range goodlist {
1468
-	//	//查询是否有数据
1469
-	//	_, errcode := service.GetStockFlush(it.StorehouseId, it.GoodId, it.OrgId)
1470
-	//	//获取总退库数量
1471
-	//	var cancel_count int64
1472
-	//	var out_count int64
1473
-	//	var act_count int64
1474
-	//	//退库总数量
1475
-	//	cancellist, _ := service.GetAllCancelCount(it.StorehouseId, it.GoodId, it.OrgId)
1476
-	//	for _, item := range cancellist {
1477
-	//		cancel_count += item.Count
1478
-	//	}
1479
-	//	//出库总数量
1480
-	//	outlist, _ := service.GetAllStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1481
-	//	for _, item := range outlist {
1482
-	//		out_count += item.Count
1483
-	//	}
1484
-	//
1485
-	//	//实际出库总数量
1486
-	//	actlist, _ := service.GetActStockOutCount(it.StorehouseId, it.GoodId, it.OrgId)
1487
-	//	for _, item := range actlist {
1488
-	//		act_count += item.Count
1489
-	//	}
1490
-	//
1491
-	//	if errcode == gorm.ErrRecordNotFound {
1492
-	//		good := models.XtGoodStockCount{
1493
-	//			UserOrgId:        it.OrgId,
1494
-	//			GoodId:           it.GoodId,
1495
-	//			StorehouseId:     it.StorehouseId,
1496
-	//			Status:           1,
1497
-	//			Ctime:            time.Now().Unix(),
1498
-	//			Mtime:            0,
1499
-	//			StockInCount:     it.WarehousingCount,
1500
-	//			StockOutCount:    out_count - cancel_count,
1501
-	//			StockCancelCount: cancel_count,
1502
-	//			FlushCount:       it.StockCount,
1503
-	//			StockActOutCount: act_count,
1504
-	//		}
1505
-	//		service.CreateGoodCountSix(good)
1506
-	//	}
1507
-	//	if errcode == nil {
1508
-	//		service.UpdateGoodCountSend(it.WarehousingCount, it.StockCount, out_count, it.StorehouseId, it.GoodId, it.OrgId, cancel_count, act_count)
1509
-	//	}
1510
-	//}
1511
-
1512 1400
 	this.ServeSuccessJSON(map[string]interface{}{
1513 1401
 		"msg": 1,
1514 1402
 	})
@@ -1547,6 +1435,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1547 1435
 	for _, item := range list {
1548 1436
 		//药品
1549 1437
 		if item.IsSource == 1 {
1438
+
1550 1439
 			medical, _ := service.GetBaseDrugMedical(item.ProjectId)
1551 1440
 			//查询该仓库的药品库存是否满足调出数量
1552 1441
 			drugInfoList, _ := service.GetDrugWarehouseInfoByStoreHouseIdOne(item.ProjectId, item.StorehouseInId, item.UserOrgId, item.ID)
@@ -1568,6 +1457,7 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1568 1457
 			}
1569 1458
 
1570 1459
 			if total_count > total {
1460
+
1571 1461
 				goodObj, _ := service.GetDrugByGoodId(item.ProjectId)
1572 1462
 				storehouse, _ := service.FindStoreHouseByStorehouseId(item.StorehouseInId, item.UserOrgId)
1573 1463
 				this.ServeSuccessJSON(map[string]interface{}{
@@ -1639,38 +1529,177 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1639 1529
 				total_count = item.Count
1640 1530
 			}
1641 1531
 
1532
+			fmt.Println("total_count2332232333233223", total_count)
1533
+			fmt.Println("totoal2323232332322332", total)
1642 1534
 			if total_count <= total {
1643 1535
 
1644
-				//回退库存,查询该订单出库记录
1645
-				drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1646
-				for _, it := range drugOutList {
1647
-
1648
-					if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1649
-						//回退库存
1650
-						service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1651
-					}
1536
+				timeStr := time.Now().Format("2006-01-02")
1537
+				timeArr := strings.Split(timeStr, "-")
1538
+				creater := this.GetAdminUserInfo().AdminUser.Id
1539
+				drug_total, _ := service.FindAllDrugWarehouseOut(orgId)
1540
+				recordDateStr := time.Now().Format("2006-01-02")
1541
+				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
1542
+				record_date := recordDate.Unix()
1543
+				drug_total = drug_total + 1
1544
+				drug_warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1545
+				number, _ := strconv.ParseInt(drug_warehousing_out_order, 10, 64)
1546
+				number = number + drug_total
1547
+				drug_warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1548
+				operation_time := time.Now().Unix()
1549
+
1550
+				drugWarehouseOut := models.DrugWarehouseOut{
1551
+					WarehouseOutOrderNumber: drug_warehousing_out_order,
1552
+					OperationTime:           operation_time,
1553
+					OrgId:                   orgId,
1554
+					Creater:                 creater,
1555
+					Ctime:                   time.Now().Unix(),
1556
+					Status:                  1,
1557
+					WarehouseOutTime:        record_date,
1558
+					Type:                    2,
1559
+					StorehouseId:            item.StorehouseInId,
1560
+					SecondWarehouseId:       item.WarehouseId,
1561
+					IsSys:                   12,
1562
+					IsCheck:                 1,
1563
+				}
1564
+				_, drugerrcodes := service.GetDrugWarehouseBySyS(orgId, 12, item.WarehouseId, record_date)
1652 1565
 
1653
-					if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
1654
-						//回退库存
1655
-						service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1656
-					}
1566
+				if drugerrcodes == gorm.ErrRecordNotFound {
1567
+					service.AddSigleDrugWarehouseOut(&drugWarehouseOut)
1568
+				}
1657 1569
 
1658
-					if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1570
+				drugOut, _ := service.GetLastDrugWarehouseOutById(12, item.WarehouseId, orgId, record_date)
1659 1571
 
1660
-						service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
1661
-					}
1572
+				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1573
+					WarehouseOutOrderNumber: drugOut.WarehouseOutOrderNumber,
1574
+					WarehouseOutId:          drugOut.ID,
1575
+					DrugId:                  item.ProjectId,
1576
+					Count:                   item.Count,
1577
+					Price:                   medical.RetailPrice,
1578
+					TotalPrice:              0,
1579
+					Status:                  1,
1580
+					Ctime:                   time.Now().Unix(),
1581
+					Remark:                  item.Remake,
1582
+					OrgId:                   orgId,
1583
+					Type:                    2,
1584
+					Manufacturer:            0,
1585
+					Dealer:                  0,
1586
+					RetailPrice:             item.MinPrice,
1587
+					RetailTotalPrice:        0,
1588
+					CountUnit:               item.SencondUnit,
1589
+					ExpiryDate:              0,
1590
+					ProductDate:             0,
1591
+					Number:                  "",
1592
+					BatchNumber:             "",
1593
+					IsSys:                   0,
1594
+					WarehouseInfoId:         0,
1595
+					StorehouseId:            item.StorehouseInId,
1596
+					SecondWarehouseInfoId:   item.ID,
1597
+					IsCheck:                 1,
1598
+				}
1599
+				drup, _ := service.FindBaseDrugLibRecord(orgId, item.ProjectId)
1600
+
1601
+				drug_in_total, _ := service.FindAllWarehouseTotalOne(orgId)
1602
+				drug_in_total = drug_in_total + 1
1603
+
1604
+				warehousing_order := "YPRKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(drug_in_total, 10)
1605
+
1606
+				drug_warehousing := models.DrugWarehouse{
1607
+					WarehousingOrder:  warehousing_order,
1608
+					OperationTime:     operation_time,
1609
+					OrgId:             orgId,
1610
+					Creater:           creater,
1611
+					Ctime:             time.Now().Unix(),
1612
+					Status:            1,
1613
+					WarehousingTime:   record_date,
1614
+					Type:              1,
1615
+					StorehouseId:      item.StorehouseOutId,
1616
+					IsSys:             13,
1617
+					SecondWarehouseId: item.WarehouseId,
1618
+					IsCheck:           1,
1619
+				}
1662 1620
 
1663
-					//查询入库单
1664
-					storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
1665
-					//删除入库单
1666
-					service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1621
+				//查询该调拨单是否有生成入库单
1622
+				_, drugerrcodess := service.GetDrugWarehouseingBySys(13, item.WarehouseId, orgId, record_date)
1623
+				if drugerrcodess == gorm.ErrRecordNotFound {
1624
+					service.CreateDrugWaresing(drug_warehousing)
1625
+				}
1667 1626
 
1668
-					//查询出单
1669
-					storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
1627
+				drugInfoObj, _ := service.GetLastDrugWarehouseBySys(13, item.WarehouseId, orgId, record_date)
1628
+
1629
+				drugwarehouseInfo := &models.DrugWarehouseInfo{
1630
+					WarehousingOrder:      drugInfoObj.WarehousingOrder,
1631
+					WarehousingId:         drugInfoObj.ID,
1632
+					DrugId:                item.ProjectId,
1633
+					Number:                "",
1634
+					ProductDate:           0,
1635
+					ExpiryDate:            0,
1636
+					WarehousingCount:      0,
1637
+					Price:                 0,
1638
+					TotalPrice:            0,
1639
+					Status:                1,
1640
+					Ctime:                 time.Now().Unix(),
1641
+					Remark:                "",
1642
+					OrgId:                 orgId,
1643
+					Type:                  2,
1644
+					Manufacturer:          0,
1645
+					Dealer:                0,
1646
+					StockMaxNumber:        0,
1647
+					RetailTotalPrice:      0,
1648
+					BatchNumber:           "",
1649
+					MaxUnit:               "",
1650
+					MinUnit:               "",
1651
+					RetailPrice:           0,
1652
+					StorehouseId:          item.StorehouseOutId,
1653
+					SecondWarehouseInfoId: item.ID,
1654
+					IsCheck:               1,
1655
+				}
1656
+				fmt.Println("尽力发的233223323232")
1657
+				service.AutoDrugDeliverInfoTwelve(orgId, item.Count, &drugWarehouseOut, &drup, warehouseOutInfo, drugwarehouseInfo)
1670 1658
 
1671
-					//删除出库单
1672
-					service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1659
+				//查询默认仓库
1660
+				storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
1661
+				//更新字典里面的库存
1662
+				stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.ProjectId)
1663
+				var sum_count int64
1664
+				for _, its := range stockInfo {
1665
+					baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
1666
+					if its.MaxUnit == baseDrug.MaxUnit {
1667
+						its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
1668
+					}
1669
+					sum_count += its.StockMaxNumber + its.StockMinNumber
1673 1670
 				}
1671
+				service.UpdateBaseDrugSumTwo(item.ProjectId, sum_count, item.UserOrgId)
1672
+
1673
+				//回退库存,查询该订单出库记录
1674
+				//drugOutList, _ := service.GetStoreDrugWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1675
+				//for _, it := range drugOutList {
1676
+				//
1677
+				//	if medical.MaxUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1678
+				//		//回退库存
1679
+				//		service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1680
+				//	}
1681
+				//
1682
+				//	if medical.MaxUnit == it.CountUnit && medical.MaxUnit == medical.MinUnit {
1683
+				//		//回退库存
1684
+				//		service.ModifyDrugStoreWarehouseInfo(it.WarehouseInfoId, it.Count)
1685
+				//	}
1686
+				//
1687
+				//	if medical.MinUnit == it.CountUnit && medical.MaxUnit != medical.MinUnit {
1688
+				//
1689
+				//		service.ModifyDrugStoreWarehouseInfoOne(it.WarehouseInfoId, it.Count)
1690
+				//	}
1691
+				//
1692
+				//	//查询入库单
1693
+				//	//storeWareing, _ := service.GetStoreDrugWarehouseById(item.WarehouseId, it.OrgId)
1694
+				//	//删除入库单
1695
+				//	//service.DeleteStoreWarehousingId(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1696
+				//
1697
+				//	//查询出单
1698
+				//	//storeWarehouseOut, _ := service.GetStoreDrugWarehouseOutById(it.WarehouseOutId, it.OrgId)
1699
+				//
1700
+				//	//删除出库单
1701
+				// 	//service.DeleteStoreWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1702
+				//}
1674 1703
 
1675 1704
 			}
1676 1705
 
@@ -1716,21 +1745,140 @@ func (this *SecondaryOrderApiController) ReturnCheckSecondOrder() {
1716 1745
 			//满足调拨
1717 1746
 			if item.Count <= total {
1718 1747
 
1719
-				//回退库存,查询该订单出库记录
1720
-				outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1721
-				for _, it := range outList {
1722
-					//回退库存
1723
-					service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
1724
-
1725
-					//获取入库单
1726
-					storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
1727
-					//删除入库单 入库流水
1728
-					service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1729
-					//获取出库单
1730
-					storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
1731
-					//删除出库单
1732
-					service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1748
+				timeStr := time.Now().Format("2006-01-02")
1749
+				timeArr := strings.Split(timeStr, "-")
1750
+				total, _ := service.FindAllWarehouseOut(orgId)
1751
+
1752
+				total = total + 1
1753
+				warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1754
+				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1755
+				number = number + total
1756
+				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1757
+				operation_time := time.Now().Unix()
1758
+				creater := this.GetAdminUserInfo().AdminUser.Id
1759
+				recordDateStr := time.Now().Format("2006-01-02")
1760
+				recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
1761
+				record_date := recordDate.Unix()
1762
+
1763
+				totals, _ := service.FindAllWarehouseTotal(orgId)
1764
+				totals = totals + 1
1765
+				warehousing_order := "RKD" + strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(totals, 10)
1766
+				//创建出库单
1767
+				goodObj, _ := service.GetGoodInformationByGoodId(item.ProjectId)
1768
+				warehouseOut := models.WarehouseOut{
1769
+					WarehouseOutOrderNumber: warehousing_out_order,
1770
+					OperationTime:           operation_time,
1771
+					OrgId:                   orgId,
1772
+					Creater:                 creater,
1773
+					Ctime:                   time.Now().Unix(),
1774
+					Status:                  1,
1775
+					WarehouseOutTime:        record_date,
1776
+					Type:                    1,
1777
+					StorehouseId:            item.StorehouseInId,
1778
+					IsSys:                   12,
1779
+					SecondWarehouseId:       item.WarehouseId,
1780
+					IsCheck:                 1,
1781
+				}
1782
+
1783
+				//查询今日是否存在调拨出库
1784
+				_, errcodes := service.FindStockOutByIsSysSix(orgId, 12, record_date, item.WarehouseId)
1785
+				if errcodes == gorm.ErrRecordNotFound {
1786
+					service.AddSigleWarehouseOut(&warehouseOut)
1787
+				}
1788
+
1789
+				out, _ := service.GetLastWarehouseOutBySys(12, orgId, record_date, item.WarehouseId)
1790
+				warehouseOutInfo := &models.WarehouseOutInfo{
1791
+					WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1792
+					WarehouseOutId:          out.ID,
1793
+					GoodId:                  item.ProjectId,
1794
+					GoodTypeId:              goodObj.GoodTypeId,
1795
+					Count:                   item.Count,
1796
+					Price:                   item.MinPrice,
1797
+					TotalPrice:              0,
1798
+					Status:                  1,
1799
+					Ctime:                   time.Now().Unix(),
1800
+					Remark:                  item.Remake,
1801
+					OrgId:                   orgId,
1802
+					Type:                    1,
1803
+					Manufacturer:            0,
1804
+					Number:                  "",
1805
+					ExpiryDate:              0,
1806
+					ProductDate:             0,
1807
+					Dealer:                  0,
1808
+					LicenseNumber:           "",
1809
+					WarehouseInfotId:        0,
1810
+					StorehouseId:            item.StorehouseInId,
1811
+					SecondWarehouseInfoId:   item.ID,
1812
+					IsCheck:                 1,
1813
+				}
1814
+
1815
+				//入库操作
1816
+				warehousing := models.Warehousing{
1817
+					WarehousingOrder:  warehousing_order,
1818
+					OperationTime:     operation_time,
1819
+					OrgId:             orgId,
1820
+					Creater:           creater,
1821
+					Ctime:             time.Now().Unix(),
1822
+					Status:            1,
1823
+					WarehousingTime:   record_date,
1824
+					Type:              1,
1825
+					StorehouseId:      item.StorehouseOutId,
1826
+					IsSys:             12,
1827
+					SecondWarehouseId: item.WarehouseId,
1828
+					IsCheck:           1,
1829
+				}
1830
+				//查询该调拨单是否有生成入库单
1831
+				_, errcodess := service.GetWarehouseBySecondWarehouseId(12, item.WarehouseId, orgId, record_date)
1832
+				if errcodess == gorm.ErrRecordNotFound {
1833
+					service.AddSigleWarehouse(&warehousing)
1733 1834
 				}
1835
+				infoObj, _ := service.GetLastWarehouseById(12, item.WarehouseId, orgId, record_date)
1836
+
1837
+				warehouseInfo := &models.WarehousingInfo{
1838
+					WarehousingOrder:      infoObj.WarehousingOrder,
1839
+					WarehousingId:         infoObj.ID,
1840
+					GoodId:                item.ProjectId,
1841
+					Number:                "",
1842
+					GoodTypeId:            goodObj.GoodTypeId,
1843
+					ProductDate:           0,
1844
+					ExpiryDate:            0,
1845
+					WarehousingCount:      item.Count,
1846
+					Price:                 goodObj.BuyPrice,
1847
+					TotalPrice:            0,
1848
+					Status:                1,
1849
+					Ctime:                 time.Now().Unix(),
1850
+					Remark:                item.Remake,
1851
+					OrgId:                 orgId,
1852
+					Type:                  1,
1853
+					Manufacturer:          0,
1854
+					StockCount:            item.Count,
1855
+					Dealer:                0,
1856
+					LicenseNumber:         "",
1857
+					PackingPrice:          item.MinPrice,
1858
+					StorehouseId:          item.StorehouseOutId,
1859
+					SecondWarehouseInfoId: item.ID,
1860
+					IsCheck:               1,
1861
+				}
1862
+
1863
+				//出库逻辑
1864
+				parseDateErr := service.ConsumablesDeliveryTwelve(orgId, record_date, warehouseOutInfo, &warehouseOut, item.Count, creater, warehouseInfo)
1865
+				fmt.Println(parseDateErr)
1866
+
1867
+				//回退库存,查询该订单出库记录
1868
+				//outList, _ := service.GetStoreWarehouseOutList(item.ProjectId, item.ID, item.UserOrgId)
1869
+				//for _, it := range outList {
1870
+				//	//回退库存
1871
+				//	service.ModifyStoreWarehouseById(it.WarehouseInfotId, it.Count)
1872
+				//
1873
+				//	//获取入库单
1874
+				//	//storeWareing, _ := service.GetStoreWarehouseById(item.WarehouseId, it.OrgId)
1875
+				//	//删除入库单 入库流水
1876
+				//	//service.ModifyStoreWarehouse(storeWareing.ID, storeWareing.OrgId, item.ProjectId)
1877
+				//	//获取出库单
1878
+				//	//storeWarehouseOut, _ := service.GetStoreWarehouseOutById(it.WarehouseOutId, it.OrgId)
1879
+				//	//删除出库单
1880
+				//	//service.ModifyWarehouseOut(storeWarehouseOut.ID, storeWarehouseOut.OrgId, item.ProjectId)
1881
+				//}
1734 1882
 			}
1735 1883
 
1736 1884
 			//查询默认仓库

+ 0 - 1
controllers/self_drug_api_congtroller.go Прегледај датотеку

@@ -3410,7 +3410,6 @@ func (this *SelfDrugApiController) GetDrugNewQuery() {
3410 3410
 	for _, it := range drug {
3411 3411
 		var sum_count int64
3412 3412
 		var limit_count int64
3413
-		fmt.Println("it233323323232323223", it.DrugName)
3414 3413
 		drugInfo, _ := service.GetDrugWarehouseInfoName(it.ID, orgId)
3415 3414
 		for _, item := range drugInfo {
3416 3415
 

+ 57 - 0
controllers/stock_in_api_controller.go Прегледај датотеку

@@ -154,6 +154,8 @@ func StockManagerApiRegistRouters() {
154 154
 	beego.Router("/api/settle/stock", &StockManagerApiController{}, "Get:HandleSettleStock")
155 155
 	beego.Router("/api/settle/cancelstock", &StockManagerApiController{}, "Get:HandleRefundStock")
156 156
 
157
+	beego.Router("/api/stock/getnewgoodwarehouseinfo", &StockManagerApiController{}, "Get:GetNewGoodWarehouseInfo")
158
+
157 159
 }
158 160
 func (c *StockManagerApiController) HandleRefundStock() {
159 161
 	order_id, _ := c.GetInt64("order_id", 0)
@@ -663,6 +665,7 @@ func (c *StockManagerApiController) EditWarehouse() {
663 665
 				manufacturer := int64(items["manufacturer"].(float64))
664 666
 				dealer := int64(items["dealer"].(float64))
665 667
 				license_number, _ := items["license_number"].(string)
668
+				register_number, _ := items["register_number"].(string)
666 669
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
667 670
 					utils.ErrorLog("id")
668 671
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -694,6 +697,7 @@ func (c *StockManagerApiController) EditWarehouse() {
694 697
 						PackingPrice:     packing_price,
695 698
 						StorehouseId:     storehouse_id,
696 699
 						IsCheck:          2,
700
+						RegisterNumber:   register_number,
697 701
 					}
698 702
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
699 703
 
@@ -721,6 +725,7 @@ func (c *StockManagerApiController) EditWarehouse() {
721 725
 						LicenseNumber:    license_number,
722 726
 						PackingPrice:     packing_price,
723 727
 						StorehouseId:     storehouse_id,
728
+						RegisterNumber:   register_number,
724 729
 					}
725 730
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
726 731
 
@@ -745,6 +750,7 @@ func (c *StockManagerApiController) EditWarehouse() {
745 750
 						ConsumableType:      1,
746 751
 						WarehousingDetailId: warehouseInfo.ID,
747 752
 						StorehouseId:        storehouse_id,
753
+						RegisterNumber:      register_number,
748 754
 					}
749 755
 
750 756
 					stockFlow = append(stockFlow, flow)
@@ -7801,3 +7807,54 @@ func (this *StockManagerApiController) GetInvetoryWarehouseInfoList() {
7801 7807
 		"dealerList":       dealerList,
7802 7808
 	})
7803 7809
 }
7810
+
7811
+func (this *StockManagerApiController) GetNewGoodWarehouseInfo() {
7812
+
7813
+	timeLayout := "2006-01-02"
7814
+	loc, _ := time.LoadLocation("Local")
7815
+	start_time := this.GetString("start_time")
7816
+	end_time := this.GetString("end_time")
7817
+	var startTime int64
7818
+	if len(start_time) > 0 {
7819
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
7820
+		if err != nil {
7821
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7822
+			return
7823
+		}
7824
+		startTime = theTime.Unix()
7825
+
7826
+	}
7827
+	var endTime int64
7828
+	if len(end_time) > 0 {
7829
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
7830
+		if err != nil {
7831
+			utils.ErrorLog(err.Error())
7832
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
7833
+			return
7834
+		}
7835
+		endTime = theTime.Unix()
7836
+	}
7837
+	storehouse_id, _ := this.GetInt64("storehouse_id")
7838
+
7839
+	keywords := this.GetString("keywords")
7840
+
7841
+	orgId := this.GetAdminUserInfo().CurrentOrgId
7842
+
7843
+	var goodids []int64
7844
+	//查询商品名称
7845
+	if len(keywords) > 0 {
7846
+		//查询商品名称
7847
+		list, _ := service.GetGoodInforByGoodName(keywords, orgId)
7848
+		for _, item := range list {
7849
+			goodids = append(goodids, item.ID)
7850
+			//入库详情但里面查询
7851
+		}
7852
+	}
7853
+
7854
+	list, _ := service.GetNewGoodWarehouseInfo(startTime, endTime, orgId, goodids, storehouse_id)
7855
+	this.ServeSuccessJSON(map[string]interface{}{
7856
+		"list": list,
7857
+		//"manufacturerList": manufacturerList,
7858
+		//"dealerList":       dealerList,
7859
+	})
7860
+}

+ 1 - 1
main.go Прегледај датотеку

@@ -15,7 +15,7 @@ func main() {
15 15
 
16 16
 	//service.BeginAutoCreateWeekDisinfectionJob()
17 17
 	//service.BeginAutoCreatePlanJob()
18
-	//service.AutoClearSchedules()
18
+	//	//service.AutoClearSchedules()
19 19
 	//service.BeginAutoCreateStaffScheduleJob()
20 20
 	//service.BeginAutoCreateDrugJob()
21 21
 	//service.BeginAutoCreateStockJob()

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

@@ -849,6 +849,7 @@ type DialysisOrder struct {
849 849
 	NucleinDate                int64         `gorm:"column:nuclein_date" json:"nuclein_date" form:"nuclein_date"`
850 850
 	ScheduleRemark             string        `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
851 851
 	OrderRemark                string        `gorm:"column:order_remark" json:"order_remark" form:"order_remark"`
852
+	DialysisTotal              int64         `gorm:"column:dialysis_total" json:"dialysis_total" form:"dialysis_total"`
852 853
 }
853 854
 
854 855
 func (DialysisOrder) TableName() string {
@@ -1096,6 +1097,7 @@ type DialysisBeforePrepareGoods struct {
1096 1097
 	ProjectId         int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
1097 1098
 	StorehouseId      int64  `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
1098 1099
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1100
+	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1099 1101
 }
1100 1102
 
1101 1103
 type NewDialysisBeforePrepareGoods struct {
@@ -1111,6 +1113,7 @@ type NewDialysisBeforePrepareGoods struct {
1111 1113
 	UserOrgId                          int64                            `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1112 1114
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1113 1115
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1116
+	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1114 1117
 }
1115 1118
 
1116 1119
 type OldDialysisBeforePrepareGoods struct {
@@ -1385,3 +1388,34 @@ type XtDialysisOrderSix struct {
1385 1388
 func (XtDialysisOrderSix) TableName() string {
1386 1389
 	return "xt_dialysis_order"
1387 1390
 }
1391
+
1392
+type HisDoctorAdviceFourty struct {
1393
+	ID                    int64                    `gorm:"column:id" json:"id" form:"id"`
1394
+	UserOrgId             int64                    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1395
+	PatientId             int64                    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1396
+	AdviceDate            int64                    `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
1397
+	StartTime             int64                    `gorm:"column:start_time" json:"start_time" form:"start_time"`
1398
+	AdviceName            string                   `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
1399
+	PrescribingNumber     float64                  `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
1400
+	PrescribingNumberUnit string                   `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
1401
+	Status                int64                    `gorm:"column:status" json:"status" form:"status"`
1402
+	CreatedTime           int64                    `gorm:"column:created_time" json:"created_time" form:"created_time"`
1403
+	UpdatedTime           int64                    `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1404
+	ParentId              int64                    `gorm:"column:parent_id" json:"parent_id" form:"parent_id"`
1405
+	ExecutionTime         int64                    `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
1406
+	ExecutionStaff        int64                    `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
1407
+	ExecutionState        int64                    `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
1408
+	Checker               int64                    `gorm:"column:checker" json:"checker" form:"checker"`
1409
+	CheckTime             int64                    `gorm:"column:check_time" json:"check_time" form:"check_time"`
1410
+	CheckState            int64                    `gorm:"column:check_state" json:"check_state" form:"check_state"`
1411
+	ChildDoctorAdvice     []*HisDoctorAdviceFourty `gorm:"ForeignKey:DrugId;AssociationForeignKey:DrugId" json:"child"`
1412
+	IsCheck               int64                    `gorm:"-" json:"is_check" form:"is_check"`
1413
+	Way                   int64                    `gorm:"column:way" json:"way" form:"way"`
1414
+	DrugId                int64                    `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
1415
+	IsSettle              int64                    `gorm:"column:is_settle" json:"is_settle" form:"is_settle"`
1416
+	Drug                  Drug                     `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
1417
+}
1418
+
1419
+func (HisDoctorAdviceFourty) TableName() string {
1420
+	return "his_doctor_advice_info"
1421
+}

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

@@ -587,3 +587,112 @@ type XtDrugWarehouseFlushInfo struct {
587 587
 func (XtDrugWarehouseFlushInfo) TableName() string {
588 588
 	return "xt_drug_warehouse_flush_info"
589 589
 }
590
+
591
+type DrugFlowNight struct {
592
+	ID                        int64             `gorm:"column:id" json:"id" form:"id"`
593
+	WarehousingId             int64             `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
594
+	DrugId                    int64             `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
595
+	Number                    string            `gorm:"column:number" json:"number" form:"number"`
596
+	BatchNumber               string            `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
597
+	Count                     int64             `gorm:"column:count" json:"count" form:"count"`
598
+	UserOrgId                 int64             `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
599
+	PatientId                 int64             `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
600
+	SystemTime                int64             `gorm:"column:system_time" json:"system_time" form:"system_time"`
601
+	ConsumableType            int64             `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
602
+	IsSys                     int64             `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
603
+	WarehousingOrder          string            `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
604
+	WarehouseOutId            int64             `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
605
+	WarehouseOutOrderNumber   string            `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
606
+	IsEdit                    int64             `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
607
+	CancelStockId             int64             `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
608
+	CancelOrderNumber         string            `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
609
+	Manufacturer              int64             `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
610
+	Dealer                    int64             `gorm:"column:dealer" json:"dealer" form:"dealer"`
611
+	Creator                   int64             `gorm:"column:creator" json:"creator" form:"creator"`
612
+	UpdateCreator             int64             `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
613
+	Status                    int64             `gorm:"column:status" json:"status" form:"status"`
614
+	Ctime                     int64             `gorm:"column:ctime" json:"ctime" form:"ctime"`
615
+	Mtime                     int64             `gorm:"column:mtime" json:"mtime" form:"mtime"`
616
+	Price                     float64           `gorm:"column:price" json:"price" form:"price"`
617
+	WarehousingDetailId       int64             `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
618
+	WarehouseOutDetailId      int64             `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
619
+	CancelOutDetailId         int64             `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
620
+	ExpireDate                int64             `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
621
+	ProductDate               int64             `gorm:"column:product_date" json:"product_date" form:"product_date"`
622
+	MaxUnit                   string            `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
623
+	MinUnit                   string            `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
624
+	StockMaxNumber            int64             `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
625
+	StockMinNumber            int64             `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
626
+	LastStockMaxNumber        int64             `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
627
+	LastStockMinNumber        int64             `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
628
+	BaseDrugLibSeven          BaseDrugLibSeven  `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
629
+	AdviceId                  int64             `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
630
+	SupplyWarehouseId         int64             `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
631
+	SupplyCancelOutId         int64             `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
632
+	SupplyWarehouseDetailInfo int64             `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
633
+	StorehouseId              int64             `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
634
+	SecondWarehouseInfoId     int64             `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
635
+	AdminUserId               int64             `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
636
+	LastPrice                 float64           `gorm:"column:last_price" json:"last_price" form:"last_price"`
637
+	StockCount                string            `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
638
+	PharmacyId                int64             `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
639
+	DrugWarehouseInfoOne      DrugWarehouseInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehousingDetailId"json:"xt_drug_warehouse_info" `
640
+	IsRead                    int64             `gorm:"column:is_read" json:"is_read" form:"is_read"`
641
+	IsCheck                   int64             `gorm:"column:is_check" json:"is_check" form:"is_check"`
642
+	OverCount                 int64             `gorm:"column:over_count" json:"over_count" form:"over_count"`
643
+	RetailPrice               float64           `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
644
+	OrderId                   int64             `gorm:"column:order_id" json:"order_id" form:"order_id"`
645
+}
646
+
647
+func (DrugFlowNight) TableName() string {
648
+	return "xt_drug_flow"
649
+}
650
+
651
+type DrugWarehouseOutInfoNight struct {
652
+	ID                      int64            `gorm:"column:id" json:"id" form:"id"`
653
+	WarehouseOutId          int64            `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
654
+	DrugId                  int64            `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
655
+	WarehousingOutTarget    int64            `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
656
+	Count                   int64            `gorm:"column:count" json:"count" form:"count"`
657
+	CountUnit               string           `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
658
+	Price                   float64          `gorm:"column:price" json:"price" form:"price"`
659
+	TotalPrice              float64          `gorm:"column:total_price" json:"total_price" form:"total_price"`
660
+	ProductDate             int64            `gorm:"column:product_date" json:"product_date" form:"product_date"`
661
+	ExpiryDate              int64            `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
662
+	Mtime                   int64            `gorm:"column:mtime" json:"mtime" form:"mtime"`
663
+	Ctime                   int64            `gorm:"column:ctime" json:"ctime" form:"ctime"`
664
+	Status                  int64            `gorm:"column:status" json:"status" form:"status"`
665
+	OrgId                   int64            `gorm:"column:org_id" json:"org_id" form:"org_id"`
666
+	Remark                  string           `gorm:"column:remark" json:"remark" form:"remark"`
667
+	IsCancel                int64            `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
668
+	WarehouseOutOrderNumber string           `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
669
+	Type                    int64            `gorm:"column:type" json:"type" form:"type"`
670
+	Dealer                  int64            `gorm:"column:dealer" json:"dealer" form:"dealer"`
671
+	Manufacturer            int64            `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
672
+	IsSys                   int64            `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
673
+	SysRecordTime           int64            `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
674
+	RetailPrice             float64          `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
675
+	RetailTotalPrice        float64          `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
676
+	Number                  string           `gorm:"column:number" json:"number" form:"number"`
677
+	BatchNumber             string           `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
678
+	PatientId               int64            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
679
+	WarehouseInfoId         int64            `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
680
+	AdviceId                int64            `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
681
+	SupplyCancelOutId       int64            `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
682
+	SupplyWarehouseId       int64            `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
683
+	IsSource                int64            `gorm:"column:is_source" json:"is_source" form:"is_source"`
684
+	StorehouseId            int64            `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
685
+	SecondWarehouseInfoId   int64            `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
686
+	AdminUserId             int64            `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
687
+	LastPrice               float64          `gorm:"column:last_price" json:"last_price" form:"last_price"`
688
+	StockCount              string           `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
689
+	PharmacyId              int64            `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
690
+	IsCheck                 int64            `gorm:"column:is_check" json:"is_check" form:"is_check"`
691
+	Drug                    BaseDrugLibSeven `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
692
+	OverCount               int64            `gorm:"column:over_count" json:"over_count" form:"over_count"`
693
+	OrderId                 int64            `gorm:"column:order_id" json:"order_id" form:"order_id"`
694
+}
695
+
696
+func (DrugWarehouseOutInfoNight) TableName() string {
697
+	return "xt_drug_warehouse_out_info"
698
+}

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

@@ -41,14 +41,15 @@ func (VMMonitorPatients) TableName() string {
41 41
 }
42 42
 
43 43
 type VMMonitorDialysisOrder struct {
44
-	ID           int64        `gorm:"column:id" json:"id"`
45
-	DialysisDate int64        `gorm:"column:dialysis_date" json:"dialysis_date"`
46
-	UserOrgId    int64        `gorm:"column:user_org_id" json:"user_org_id"`
47
-	PatientId    int64        `gorm:"column:patient_id" json:"patient_id"`
48
-	BedID        int64        `gorm:"column:bed_id" json:"bed_id"`
49
-	Status       int64        `gorm:"column:status" json:"status"`
50
-	DeviceNumber DeviceNumber `gorm:"ForeignKey:BedId" json:"device_number"`
51
-	StartTime    int64        `gorm:"column:start_time" json:"start_time"`
44
+	ID            int64        `gorm:"column:id" json:"id"`
45
+	DialysisDate  int64        `gorm:"column:dialysis_date" json:"dialysis_date"`
46
+	UserOrgId     int64        `gorm:"column:user_org_id" json:"user_org_id"`
47
+	PatientId     int64        `gorm:"column:patient_id" json:"patient_id"`
48
+	BedID         int64        `gorm:"column:bed_id" json:"bed_id"`
49
+	Status        int64        `gorm:"column:status" json:"status"`
50
+	DeviceNumber  DeviceNumber `gorm:"ForeignKey:BedId" json:"device_number"`
51
+	StartTime     int64        `gorm:"column:start_time" json:"start_time"`
52
+	DialysisTotal int64        `gorm:"column:dialysis_total" json:"dialysis_total" form:"dialysis_total"`
52 53
 }
53 54
 
54 55
 func (VMMonitorDialysisOrder) TableName() string {

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

@@ -356,6 +356,7 @@ type DialysisPrescription struct {
356 356
 	WaterMachine               string        `gorm:"column:water_machine" json:"water_machine" form:"water_machine"`
357 357
 	AddAmount                  float64       `gorm:"column:add_amount" json:"add_amount" form:"add_amount"`
358 358
 	ReduceAmount               float64       `gorm:"column:reduce_amount" json:"reduce_amount" form:"reduce_amount"`
359
+	DialysisRemark             string        `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
359 360
 }
360 361
 
361 362
 func (DialysisPrescription) TableName() string {
@@ -562,6 +563,7 @@ type DialysisSolution struct {
562 563
 	MaxUltrafiltrationRate     float64 `gorm:"column:max_ultrafiltration_rate" json:"max_ultrafiltration_rate" form:"max_ultrafiltration_rate"`
563 564
 	PreImpulse                 float64 `gorm:"column:pre_impulse" json:"pre_impulse" form:"pre_impulse"`
564 565
 	SolutionStatus             int64   `gorm:"column:solution_status" json:"solution_status" form:"solution_status"`
566
+	DialysisRemark             string  `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
565 567
 }
566 568
 
567 569
 func (DialysisSolution) TableName() string {

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

@@ -9,6 +9,7 @@ type PatientScheduleTemplateMode struct {
9 9
 	CreateTime   int64 `gorm:"column:ctime" json:"-" form:"ctime"`
10 10
 	ModifyTime   int64 `gorm:"column:mtime" json:"-" form:"mtime"`
11 11
 	Week         int64 `gorm:"column:week" json:"-" form:"week"`
12
+	OriginalWeek int64 `gorm:"column:original_week" json:"original_week" form:"original_week"`
12 13
 }
13 14
 
14 15
 func (PatientScheduleTemplateMode) TableName() string {

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

@@ -523,3 +523,27 @@ type ScheduleTwentyOne struct {
523 523
 func (ScheduleTwentyOne) TableName() string {
524 524
 	return "xt_schedule"
525 525
 }
526
+
527
+type VmBloodScheduleOne struct {
528
+	ID              int64                      `gorm:"column:id" json:"id" form:"id"`
529
+	UserOrgId       int64                      `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
530
+	PartitionId     int64                      `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
531
+	BedId           int64                      `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
532
+	PatientId       int64                      `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
533
+	ScheduleDate    int64                      `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
534
+	ScheduleType    int64                      `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
535
+	ScheduleWeek    int64                      `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
536
+	ModeId          int64                      `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
537
+	Status          int64                      `gorm:"column:status" json:"status" form:"status"`
538
+	CreatedTime     int64                      `gorm:"column:created_time" json:"created_time" form:"created_time"`
539
+	UpdatedTime     int64                      `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
540
+	IsExport        int64                      `gorm:"column:is_export" json:"is_export" form:"is_export"`
541
+	DeviceNumber    *NewMDeviceNumberVM        `gorm:"ForeignKey:BedId" json:"device_number"`
542
+	SchedualPatient *NewMSchedualPatientVMList `gorm:"ForeignKey:PatientId" json:"patient"`
543
+	XtDoctorAdvice  []*XtDoctorAdvice          `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"xt_doctor_advice"`
544
+	HisDoctorAdvice []*HisDoctorAdviceFourty   `gorm:"ForeignKey:PatientId,AdviceDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_doctor_advice"`
545
+}
546
+
547
+func (VmBloodScheduleOne) TableName() string {
548
+	return "xt_schedule"
549
+}

+ 18 - 17
models/smart_sch.go Прегледај датотеку

@@ -6,7 +6,7 @@ type SmartSchPatient struct {
6 6
 	Name       string `gorm:"column:name" json:"name" form:"name"`
7 7
 	DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
8 8
 
9
-	SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
9
+	//SmartSchedule []*SmartSchedule `gorm:"-" json:"sch"`
10 10
 }
11 11
 
12 12
 func (SmartSchPatient) TableName() string {
@@ -27,22 +27,23 @@ func (SmartSchTemplatePatient) TableName() string {
27 27
 }
28 28
 
29 29
 type SmartSchedule struct {
30
-	ID                 int64              `gorm:"column:id" json:"id" form:"id"`
31
-	UserOrgId          int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
32
-	PartitionId        int64              `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
33
-	BedId              int64              `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
34
-	PatientId          int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
35
-	ScheduleDate       int64              `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
36
-	ScheduleType       int64              `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
37
-	ScheduleWeek       int64              `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
38
-	ModeId             int64              `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
39
-	Status             int64              `gorm:"column:status" json:"status" form:"status"`
40
-	CreatedTime        int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
41
-	UpdatedTime        int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
42
-	IsExport           int64              `gorm:"column:is_export" json:"is_export" form:"is_export"`
43
-	DeviceZone         DeviceZone         `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
44
-	DeviceNumber       DeviceNumber       `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
45
-	SmSchDialysisOrder SmSchDialysisOrder `json:"order" gorm:"foreignkey:BedId,PatientId,DialysisDate;AssociationForeignKey:BedId,PatientId,ScheduleDate;"`
30
+	ID                  int64              `gorm:"column:id" json:"id" form:"id"`
31
+	UserOrgId           int64              `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
32
+	PartitionId         int64              `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
33
+	BedId               int64              `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
34
+	PatientId           int64              `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
35
+	ScheduleDate        int64              `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
36
+	ScheduleType        int64              `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
37
+	ScheduleWeek        int64              `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
38
+	ModeId              int64              `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
39
+	Status              int64              `gorm:"column:status" json:"status" form:"status"`
40
+	CreatedTime         int64              `gorm:"column:created_time" json:"created_time" form:"created_time"`
41
+	UpdatedTime         int64              `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
42
+	IsExport            int64              `gorm:"column:is_export" json:"is_export" form:"is_export"`
43
+	DeviceZone          DeviceZone         `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:PartitionId;"`
44
+	DeviceNumber        DeviceNumber       `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:BedId;"`
45
+	SmSchDialysisOrder  SmSchDialysisOrder `json:"order" gorm:"-"`
46
+	DialysisMachineName string             `gorm:"column:dialysis_machine_name" json:"dialysis_machine_name" form:"dialysis_machine_name"`
46 47
 }
47 48
 
48 49
 func (SmartSchedule) TableName() string {

+ 2 - 1
models/stock_models.go Прегледај датотеку

@@ -152,7 +152,8 @@ func (WarehousingInfo) TableName() string {
152 152
 }
153 153
 
154 154
 type WarehousingInfoSeven struct {
155
-	StockCount int64 `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
155
+	StockCount   int64 `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
156
+	StorehouseId int64 `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
156 157
 }
157 158
 
158 159
 func (WarehousingInfoSeven) TableName() string {

+ 27 - 5
service/device_service.go Прегледај датотеку

@@ -391,11 +391,13 @@ func UpdateDeviceGroup(group *models.DeviceGroup) error {
391 391
 //////// 机号 Number
392 392
 
393 393
 type DeviceNumberVM struct {
394
-	ID     int64  `gorm:"column:id" json:"id"`
395
-	OrgID  int64  `gorm:"column:org_id" json:"-"`
396
-	Number string `gorm:"column:number" json:"number"`
397
-	ZoneID int64  `gorm:"column:zone_id" json:"zone_id"`
398
-	Status int64  `gorm:"column:status" json:"status" form:"status"`
394
+	ID      int64  `gorm:"column:id" json:"id"`
395
+	OrgID   int64  `gorm:"column:org_id" json:"-"`
396
+	Number  string `gorm:"column:number" json:"number"`
397
+	ZoneID  int64  `gorm:"column:zone_id" json:"zone_id"`
398
+	Status  int64  `gorm:"column:status" json:"status" form:"status"`
399
+	Sort    int64  `gorm:"column:sort" json:"sort" form:"sort"`
400
+	GroupId int64  `gorm:"column:group_id" json:"group_id" form:"group_id"`
399 401
 }
400 402
 
401 403
 func (DeviceNumberVM) TableName() string {
@@ -834,3 +836,23 @@ func UpdateScheduleById(id int64, schedule models.Schedule) error {
834 836
 	err := XTWriteDB().Model(&models.Schedule{}).Where("id = ? and status =1", id).Update(map[string]interface{}{"patient_id": schedule.PatientId, "mode_id": schedule.ModeId}).Error
835 837
 	return err
836 838
 }
839
+
840
+func GetScheduleTemplateForDeviceNumber(orgID int64, deviceNumberID int64, template_id int64, week_type int64, time_type int64) (models.PatientScheduleTemplateItem, error) {
841
+	var item models.PatientScheduleTemplateItem
842
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ? AND time_type = ?", deviceNumberID, orgID, template_id, week_type, time_type).First(&item).Error
843
+	return item, err
844
+}
845
+
846
+//某模板下,某周几下,该床位是否有患者
847
+func GetScheduleTemplateOne(orgID int64, deviceNumberID int64, template_id int64, week_type int64) (models.PatientScheduleTemplateItem, error) {
848
+	var item models.PatientScheduleTemplateItem
849
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ?", deviceNumberID, orgID, template_id, week_type).First(&item).Error
850
+	return item, err
851
+}
852
+
853
+//某模板下,某周几下,是否有排班
854
+func GetScheduleTemplateTwo(orgID int64, template_id int64, week_type int64, patient_id int64) (models.PatientScheduleTemplateItem, error) {
855
+	var item models.PatientScheduleTemplateItem
856
+	err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("patient_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ?", patient_id, orgID, template_id, week_type).First(&item).Error
857
+	return item, err
858
+}

+ 20 - 8
service/dialysis_solution_service.go Прегледај датотеку

@@ -216,9 +216,9 @@ func GetDialysisGoodTotalCount(orgID int64, schedule_type int64, partition_id in
216 216
 
217 217
 }
218 218
 
219
-func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
219
+func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
220 220
 
221
-	db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
221
+	db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
222 222
 
223 223
 	if scheduleDate > 0 {
224 224
 		db = db.Where("schedule_date = ?", scheduleDate)
@@ -235,8 +235,9 @@ func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id
235 235
 	err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
236 236
 		Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
237 237
 		Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
238
-		Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
239
-		Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
238
+		Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
239
+			return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
240
+		}).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
240 241
 
241 242
 	return schedule, err
242 243
 
@@ -364,7 +365,6 @@ func SaveHisDialysis(orgid int64, ids []string) error {
364 365
 }
365 366
 
366 367
 func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodScheduleTwo, total int64, err error) {
367
-	fmt.Println("ids23322332323232hhha", ids)
368 368
 	db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
369 369
 	offset := (page - 1) * limit
370 370
 	if scheduleDate > 0 {
@@ -391,7 +391,7 @@ func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page i
391 391
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
392 392
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
393 393
 					return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
394
-						return db.Where("user_org_id = ? and status = 1 and type = 3", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
394
+						return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
395 395
 					})
396 396
 				})
397 397
 			})
@@ -405,7 +405,7 @@ func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page i
405 405
 			Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
406 406
 				return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
407 407
 					return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
408
-						return db.Where("user_org_id = ? and status = 1 and type = 3", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
408
+						return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
409 409
 					})
410 410
 				})
411 411
 			}).Find(&schedule).Error
@@ -437,10 +437,22 @@ func GetHisDialysisGoodCount(orgID int64, schedule_type int64, partition_id int6
437 437
 		Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
438 438
 			return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
439 439
 				return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
440
-					return db.Where("user_org_id = ? and status = 1 and type = 3", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
440
+					return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
441 441
 				})
442 442
 			})
443 443
 		}).Find(&schedule).Error
444 444
 
445 445
 	return schedule, err
446 446
 }
447
+
448
+func GeAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
449
+
450
+	err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Find(&advice).Error
451
+	return advice, err
452
+}
453
+
454
+func GetHisAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.HisDoctorAdviceFourty, err error) {
455
+
456
+	err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Preload("Drug", "org_id = ? and status=1", user_org_id).Find(&advice).Error
457
+	return advice, err
458
+}

+ 8 - 2
service/gobal_config_service.go Прегледај датотеку

@@ -902,6 +902,12 @@ func GetDrugWarehouseOutDetailSeventy(id int64, org_id int64) (info []*models.Dr
902 902
 	return info, err
903 903
 }
904 904
 
905
+func GetDrugWarehouseOutDetailNighty(id int64, org_id int64) (info []*models.DrugWarehouseOutInfoNight, err error) {
906
+
907
+	err = XTReadDB().Where("warehouse_out_id in(?) and org_id = ? and status =1", id, org_id).Preload("Drug", "org_id = ? and status = 1", org_id).Find(&info).Error
908
+	return info, err
909
+}
910
+
905 911
 func GetDrugStockFlowDetail(record_time int64, orgid int64) (drugflow []*models.XtDrugAutomaticReduceDetail, err error) {
906 912
 
907 913
 	err = XTReadDB().Where("record_time = ? and org_id = ? and status = 1", record_time, orgid).Preload("XtBaseDrug", "status = 1").Find(&drugflow).Error
@@ -945,7 +951,7 @@ func GetDrugFlowList(id int64, orgid int64) (stockflow []*models.DrugFlow, err e
945 951
 	return stockflow, err
946 952
 }
947 953
 
948
-func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
954
+func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlowNight, err error) {
949 955
 
950 956
 	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
951 957
 	return drugFlow, err
@@ -953,7 +959,7 @@ func GetDrugFlowListGroupById(id int64, orgid int64) (drugFlow []*models.DrugFlo
953 959
 
954 960
 func GetDrugFlowListGroupByIdOne(id int64, orgid int64) (drugFlow []*models.DrugFlow, err error) {
955 961
 
956
-	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("batch_number").Find(&drugFlow).Error
962
+	err = XTReadDB().Where("warehouse_out_id in(?) and user_org_id = ? and status = 1", id, orgid).Group("warehousing_detail_id").Find(&drugFlow).Error
957 963
 	return drugFlow, err
958 964
 }
959 965
 

+ 4 - 4
service/his_service.go Прегледај датотеку

@@ -2676,19 +2676,19 @@ func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
2676 2676
 	return
2677 2677
 }
2678 2678
 
2679
-func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64) (models.XtDrugStockCount, error) {
2679
+func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
2680 2680
 
2681 2681
 	drug := models.XtDrugStockCount{}
2682 2682
 
2683
-	err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1", drug_id, user_org_id).Find(&drug).Error
2683
+	err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1 and storehouse_id =?", drug_id, user_org_id, storehouse_id).Find(&drug).Error
2684 2684
 
2685 2685
 	return drug, err
2686 2686
 }
2687 2687
 
2688
-func GetStockGoodList(good_id int64, org_id int64) (models.XtGoodStockCount, error) {
2688
+func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
2689 2689
 
2690 2690
 	stockCount := models.XtGoodStockCount{}
2691
-	err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1", good_id, org_id).Find(&stockCount).Error
2691
+	err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
2692 2692
 	return stockCount, err
2693 2693
 }
2694 2694
 

+ 36 - 15
service/manage_center_service.go Прегледај датотеку

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"fmt"
5 6
 	"github.com/jinzhu/gorm"
6 7
 	"strconv"
7 8
 	"strings"
@@ -210,6 +211,12 @@ func GetDrugAutoWarehouseOutEight(patient_id int64, advicedate int64, drugid int
210 211
 	return detail, err
211 212
 }
212 213
 
214
+func GetDrugAutoWarehouseOutTen(patient_id int64, advicedate int64, drugid int64, adviceid int64, warehouse_info_id int64) (models.DrugWarehouseOutInfo, error) {
215
+	detail := models.DrugWarehouseOutInfo{}
216
+	err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", patient_id, advicedate, drugid, adviceid, warehouse_info_id).Find(&detail).Error
217
+	return detail, err
218
+}
219
+
213 220
 func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
214 221
 
215 222
 	err = XTReadDB().Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&night).Error
@@ -430,11 +437,11 @@ func GetAllDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
430 437
 
431 438
 func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
432 439
 
433
-	//查询该病人该药品是否有库存记录
440
+	//查询该批次病人该药品出库数据
434 441
 	info, _ := GetDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
435
-
436 442
 	list, _ := GetDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
437 443
 
444
+	fmt.Println("lsit233323232323233232332wo", list)
438 445
 	storeHouseConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
439 446
 	//退库
440 447
 	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
@@ -442,24 +449,35 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
442 449
 	//如果剩余数量 + 退库数量 < 总入库数量
443 450
 	if len(list) > 0 {
444 451
 		for _, its := range list {
452
+			fmt.Println("its,23322323323223232332wo", its.WarehouseInfoId)
453
+
454
+			//查询该批次病人该药品出库数据
455
+			infos, _ := GetDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
456
+			fmt.Println("info2332323232332233223wo", infos.Count)
445 457
 			//查询该药品出库批次总入库数量
446
-			druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, info.OrgId)
458
+			druginfo, _ := GetDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
447 459
 
448 460
 			var out_count int64  //该批次出库库存
449 461
 			var sum_count int64  //该批次总库存
450 462
 			var over_count int64 //剩余数量
451 463
 
452
-			over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
453
-			if info.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
454
-				out_count = info.Count * drug.MinNumber
464
+			if druginfo.MaxUnit != druginfo.MinUnit {
465
+				over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
466
+			}
467
+			if druginfo.MaxUnit == druginfo.MinUnit {
468
+				over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
469
+			}
470
+
471
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
472
+				out_count = infos.Count * drug.MinNumber
455 473
 
456 474
 			}
457
-			if info.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
458
-				out_count = info.Count
475
+			if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
476
+				out_count = infos.Count
459 477
 			}
460 478
 
461
-			if info.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
462
-				out_count = info.Count
479
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
480
+				out_count = infos.Count
463 481
 			}
464 482
 
465 483
 			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
@@ -474,9 +492,12 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
474 492
 				sum_count = druginfo.WarehousingCount
475 493
 			}
476 494
 
495
+			fmt.Println("//剩余数量", over_count)
496
+			fmt.Println("该批出出库数量3223323232wo", out_count)
497
+			fmt.Println("g该批次总库存wowowoowow", sum_count)
477 498
 			if (over_count + out_count) <= sum_count {
478 499
 				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
479
-
500
+					fmt.Print("itscoutn233232223999wi", its.Count)
480 501
 					//退库
481 502
 					warehouseInfo := models.DrugWarehouseInfo{
482 503
 						StockMinNumber: its.Count,
@@ -490,7 +511,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
490 511
 
491 512
 				}
492 513
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
493
-
514
+					fmt.Print("itscoutn999888", its.Count)
494 515
 					warehouseInfo := models.DrugWarehouseInfo{
495 516
 						StockMaxNumber: its.Count,
496 517
 					}
@@ -503,7 +524,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
503 524
 				}
504 525
 
505 526
 				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
506
-
527
+					fmt.Print("itscoutnwohhhhwhw", its.Count)
507 528
 					warehouseInfo := models.DrugWarehouseInfo{
508 529
 						StockMaxNumber: its.Count,
509 530
 					}
@@ -892,7 +913,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
892 913
 func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater int64) error {
893 914
 
894 915
 	//查询已经出库数量
895
-	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId)
916
+	info, _ := GetWareOutInfo(good.GoodId, good.RecordDate, good.UserOrgId, good.PatientId, good.OrderId)
896 917
 	if len(info) > 0 {
897 918
 		houseConfig, _ := GetAllStoreHouseConfig(good.UserOrgId)
898 919
 
@@ -1001,7 +1022,7 @@ func GoodAutoAddCancelInfo(good *models.NewDialysisBeforePrepareGoods, creater i
1001 1022
 			//出库数量减少
1002 1023
 			UpdateSumCount(good.UserOrgId, houseConfig.StorehouseOutInfo, good.GoodId, good.Count)
1003 1024
 			//删除出库表
1004
-			DeleteAutoRedeceDetailTen(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId)
1025
+			DeleteAutoRedeceDetailTenOne(good.UserOrgId, item.PatientId, item.SysRecordTime, item.GoodId, item.OrderId)
1005 1026
 
1006 1027
 			goodListOne, _ := GetSumGoodList(item.OrgId, houseConfig.StorehouseOutInfo, item.GoodId)
1007 1028
 			var flush_count int64

+ 34 - 0
service/mobile_dialysis_service.go Прегледај датотеку

@@ -2755,6 +2755,11 @@ func GetDialysisOrderCountOne(orgID int64, patient_id int64, recordDate int64) (
2755 2755
 	return
2756 2756
 }
2757 2757
 
2758
+func GetDialysisOrderCountTwo(orgID int64, patient_id int64, recordDate int64) (count int64, err error) {
2759
+	err = readDb.Model(&models.DialysisOrder{}).Where("dialysis_date>=1672502400 and  dialysis_date <= ? AND status = 1 AND stage = 2 AND user_org_id = ? AND patient_id = ?", recordDate, orgID, patient_id).Count(&count).Error
2760
+	return
2761
+}
2762
+
2758 2763
 func GetFirstDateOfMonth(d time.Time) time.Time {
2759 2764
 	d = d.AddDate(0, 0, -d.Day()+1)
2760 2765
 	return GetZeroTime(d)
@@ -5188,3 +5193,32 @@ func UpdateMobilePatient(org_id int64, patient_id int64, schedule_remark string)
5188 5193
 	err = XTWriteDB().Model(models.XtPatientsNew{}).Where("user_org_id = ? and id = ? and status = 1", org_id, patient_id).Updates(map[string]interface{}{"schedule_remark": schedule_remark}).Error
5189 5194
 	return err
5190 5195
 }
5196
+
5197
+func GetDialysisTotalCount(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
5198
+
5199
+	order := models.BloodDialysisOrderCount{}
5200
+	db := XTReadDB().Table("xt_dialysis_order as o")
5201
+
5202
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
5203
+
5204
+	return order, err
5205
+}
5206
+
5207
+func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialysisOrderCount, error) {
5208
+
5209
+	order := models.BloodDialysisOrderCount{}
5210
+	db := XTReadDB().Table("xt_dialysis_order as o")
5211
+
5212
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1672502400 and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
5213
+
5214
+	return order, err
5215
+}
5216
+
5217
+func UpdateDialysisOrder(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
5218
+
5219
+	order := models.DialysisOrder{}
5220
+
5221
+	err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
5222
+
5223
+	return order, err
5224
+}

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

@@ -370,9 +370,9 @@ func UpdateLastAutoCount(id int64, count int64) error {
370 370
 	return err
371 371
 }
372 372
 
373
-func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
373
+func GetWareOutInfo(good_id int64, record_date int64, user_org_id int64, patient_id int64, order_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
374 374
 
375
-	err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ?", good_id, record_date, user_org_id, patient_id).Find(&outinfo).Error
375
+	err = XTReadDB().Where("good_id = ? and sys_record_time = ? and org_id = ? and status = 1 and patient_id = ? and order_id = ?", good_id, record_date, user_org_id, patient_id, order_id).Find(&outinfo).Error
376 376
 	return outinfo, err
377 377
 }
378 378
 

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

@@ -50,7 +50,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
50 50
 		UpdateHisPrescriptionProjectStatus(goods.GoodId, record_time, orgID, patient_id)
51 51
 
52 52
 		//查询剩余库存
53
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
53
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
54 54
 		var sum_count int64
55 55
 		for _, item := range goodList {
56 56
 			sum_count += item.StockCount
@@ -312,7 +312,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
312 312
 		if errThree != nil {
313 313
 			return errThree
314 314
 		}
315
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
315
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
316 316
 		var sum_count int64
317 317
 		for _, item := range goodList {
318 318
 			sum_count += item.StockCount
@@ -1457,7 +1457,6 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1457 1457
 
1458 1458
 		//查询今日该药品该患者是否有出库数据
1459 1459
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
1460
-		fmt.Println("lastDrugOutInfowwowowowoowowowowowowowowo", lastDrugOutInfo.ID)
1461 1460
 		if lastDrugOutInfo.ID == 0 {
1462 1461
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1463 1462
 			if errOne != nil {
@@ -1849,6 +1848,9 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1849 1848
 			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
1850 1849
 		}
1851 1850
 
1851
+		fmt.Println("libai", out_count)
1852
+		fmt.Println("cancel", cancel_count)
1853
+		fmt.Println("deliver_number", deliver_number)
1852 1854
 		if deliver_number < (out_count - cancel_count) {
1853 1855
 			operation_time := time.Now().Unix()
1854 1856
 
@@ -1997,13 +1999,13 @@ func GetSigleDrugWarehouseOutInfo(patient_id int64, advice_date int64, orgid int
1997 1999
 func GetSigleDrugWarehouseOutInfoOne(patient_id int64, advice_date int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
1998 2000
 
1999 2001
 	info := models.XtDrugWarehouseOutInfo{}
2000
-	err = XTReadDB().Where("patient_id = ? and advice_date = ? and org_id = ? and status = 1", patient_id, advice_date, orgid).Find(&info).Error
2002
+	err = XTReadDB().Where("patient_id = ? and sys_record_time = ? and org_id = ? and status = 1", patient_id, advice_date, orgid).Find(&info).Error
2001 2003
 	return info, err
2002 2004
 }
2003 2005
 
2004 2006
 func UpdateSingleDrugWarehouseOutInfoSix(patient_id int64, advice_date int64, orgid int64, info *models.DrugWarehouseOutInfo, advice_id int64) error {
2005 2007
 
2006
-	err := XTWriteDB().Model(&models.XtDrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time = ? and org_id = ? and advice_id = ?", patient_id, advice_date, orgid, advice_id).Update(map[string]interface{}{"count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "number": info.Number, "batch_number": info.BatchNumber, "count_unit": info.CountUnit, "warehouse_info_id": info.WarehouseInfoId, "storehouse_id": info.StorehouseId}).Error
2008
+	err := XTWriteDB().Model(&models.XtDrugWarehouseOutInfo{}).Where("patient_id = ? and sys_record_time = ? and org_id = ? and advice_id = ? and status= 1", patient_id, advice_date, orgid, advice_id).Update(map[string]interface{}{"count": info.Count, "price": info.Price, "total_price": info.TotalPrice, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "remark": info.Remark, "dealer": info.Dealer, "manufacturer": info.Manufacturer, "retail_price": info.RetailPrice, "number": info.Number, "batch_number": info.BatchNumber, "count_unit": info.CountUnit, "warehouse_info_id": info.WarehouseInfoId, "storehouse_id": info.StorehouseId}).Error
2007 2009
 	return err
2008 2010
 }
2009 2011
 
@@ -2069,6 +2071,12 @@ func FindDrugWarehouseOutInfoCount(drugid int64, patient_id int64, record_date i
2069 2071
 	return flow, err
2070 2072
 }
2071 2073
 
2074
+func FindDrugSettleWarehouseOutInfoCount(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (flow []*models.DrugFlow, err error) {
2075
+
2076
+	err = XTReadDB().Where("drug_id = ? and patient_id = ? and system_time = ? and user_org_id = ? and consumable_type = 15 and status = 1 and advice_id = ?", drugid, patient_id, record_date, org_id, advice_id).Find(&flow).Error
2077
+	return flow, err
2078
+}
2079
+
2072 2080
 func FindDrugCancelOutInfo(drugid int64, patient_id int64, record_date int64, org_id int64, advice_id int64) (flow []*models.DrugFlow, err error) {
2073 2081
 	err = XTReadDB().Where("drug_id = ? and patient_id = ? and system_time = ? and user_org_id = ? and consumable_type = 7 and status = 1 and advice_id = ?", drugid, patient_id, record_date, org_id, advice_id).Find(&flow).Error
2074 2082
 	return flow, err
@@ -2078,7 +2086,7 @@ func FindDrugCancelStock(return_date int64, org_id int64) (*models.DrugCancelSto
2078 2086
 
2079 2087
 	stock := models.DrugCancelStock{}
2080 2088
 	var err error
2081
-	err = XTReadDB().Where("return_date = ? and org_id = ? and status = 1", return_date, org_id).Find(&stock).Error
2089
+	err = XTReadDB().Where("return_time = ? and org_id = ? and status = 1", return_date, org_id).Find(&stock).Error
2082 2090
 	if err == gorm.ErrRecordNotFound {
2083 2091
 		return nil, err
2084 2092
 	}
@@ -2091,7 +2099,7 @@ func FindDrugCancelStock(return_date int64, org_id int64) (*models.DrugCancelSto
2091 2099
 func FindLastDrugCancelStock(advice_date int64, org_id int64) (models.DrugCancelStock, error) {
2092 2100
 
2093 2101
 	cancelStock := models.DrugCancelStock{}
2094
-	err := XTReadDB().Where("return_date = ? and org_id = ? and status = 1", advice_date, org_id).Find(&cancelStock).Error
2102
+	err := XTReadDB().Where("return_time = ? and org_id = ? and status = 1", advice_date, org_id).Find(&cancelStock).Error
2095 2103
 	return cancelStock, err
2096 2104
 }
2097 2105
 
@@ -2122,15 +2130,19 @@ func UpdateHisPrescriptionProjectStatus(project_id int64, record_time int64, use
2122 2130
 }
2123 2131
 
2124 2132
 // 药品自动出库 递归方式
2125
-func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {
2133
+func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, prescribingCount float64) (err error) {
2126 2134
 
2127 2135
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
2128 2136
 	var deliver_number int64 = 0
2137
+	var deliver_number_one int64 = 0
2129 2138
 	var stock_number int64 = 0
2130 2139
 
2131 2140
 	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
2132 2141
 	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2133 2142
 
2143
+	prescribingCount_temp := strconv.FormatFloat(math.Abs(prescribingCount), 'f', 0, 64)
2144
+	prescribe_count, _ := strconv.ParseInt(prescribingCount_temp, 10, 64)
2145
+
2134 2146
 	var drug_price float64
2135 2147
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2136 2148
 		deliver_number = count * drup.MinNumber
@@ -2140,6 +2152,14 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2140 2152
 
2141 2153
 	}
2142 2154
 
2155
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
2156
+		deliver_number_one = prescribe_count * drup.MinNumber
2157
+
2158
+	} else {
2159
+		deliver_number_one = prescribe_count
2160
+
2161
+	}
2162
+
2143 2163
 	if advice.PrescribingNumberUnit == drup.MaxUnit {
2144 2164
 		drug_price = drup.RetailPrice
2145 2165
 	}
@@ -2157,7 +2177,8 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2157 2177
 	// 如果没有对应的库存,则报错
2158 2178
 	storeConfig, _ := GetAllStoreHouseConfig(advice.UserOrgId)
2159 2179
 	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2160
-	if lastWarehouse.StockMinNumber >= drup.MinNumber {
2180
+
2181
+	if lastWarehouse.StockMinNumber >= drup.MinNumber && lastWarehouse.MaxUnit != lastWarehouse.MinUnit {
2161 2182
 		var stockMax int64
2162 2183
 		var stockMin int64
2163 2184
 		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
@@ -2169,7 +2190,6 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2169 2190
 	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
2170 2191
 
2171 2192
 	if err != nil {
2172
-
2173 2193
 		return err
2174 2194
 	}
2175 2195
 	// 将该批次的剩余库存数量转换为拆零数量
@@ -2191,6 +2211,8 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2191 2211
 	}
2192 2212
 
2193 2213
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
2214
+	fmt.Println("剩余库存2332233223232323", stock_number)
2215
+	fmt.Println("出库数量233232332323232", deliver_number)
2194 2216
 	if stock_number >= deliver_number {
2195 2217
 
2196 2218
 		var maxNumber int64 = 0
@@ -2228,41 +2250,83 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2228 2250
 
2229 2251
 		warehouse.Mtime = time.Now().Unix()
2230 2252
 
2231
-		fmt.Println("minnU目标而332322323323233223323223我", minNumber)
2232
-		fmt.Println("max_number232232332232322wo", maxNumber)
2233
-		fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
2253
+		//fmt.Println("minnU目标而332322323323233223323223我", minNumber)
2254
+		//fmt.Println("max_number232232332232322wo", maxNumber)
2255
+		//fmt.Println(" warehouse.StockMinNumber", warehouse.StockMinNumber)
2234 2256
 
2235
-		if warehouse.StockMinNumber < minNumber {
2257
+		if warehouse.MaxUnit != warehouse.MinUnit {
2258
+			if warehouse.StockMinNumber < minNumber {
2236 2259
 
2237
-			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2238
-			if warehouse.MaxUnit != warehouse.MinUnit {
2239
-				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2240
-			}
2241
-		} else {
2242
-			if minNumber > 0 {
2243
-				if (warehouse.StockMinNumber - minNumber) >= 0 {
2244
-					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2260
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
2261
+				if warehouse.MaxUnit != warehouse.MinUnit {
2262
+					warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
2245 2263
 				}
2264
+			} else {
2265
+				if minNumber > 0 {
2266
+					if (warehouse.StockMinNumber - minNumber) >= 0 {
2267
+						warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2268
+					}
2246 2269
 
2247
-			}
2270
+				}
2248 2271
 
2249
-			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
2250
-				if warehouse.StockMinNumber > 0 {
2251
-					if warehouse.StockMinNumber-deliver_number >= 0 {
2272
+				if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
2273
+					if warehouse.StockMinNumber > 0 {
2274
+						if warehouse.StockMinNumber-deliver_number >= 0 {
2275
+							warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2276
+						}
2277
+
2278
+					}
2279
+
2280
+				}
2281
+
2282
+				if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
2283
+					if (warehouse.StockMinNumber - deliver_number) >= 0 {
2252 2284
 						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2253 2285
 					}
2254 2286
 
2255 2287
 				}
2256 2288
 
2257 2289
 			}
2258
-
2259 2290
 		}
2260 2291
 
2261
-		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
2262
-			if (warehouse.StockMinNumber - deliver_number) >= 0 {
2263
-				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2292
+		if warehouse.MinUnit == warehouse.MaxUnit {
2293
+			//fmt.Println("minNUMBER233223233223322323",minNumber)
2294
+			//fmt.Println("warehouse.StockMinNumber",warehouse.StockMinNumber)
2295
+			//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
2296
+			if warehouse.StockMaxNumber > 0 && warehouse.StockMinNumber == 0 && warehouse.StockMaxNumber >= minNumber {
2297
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - minNumber
2298
+
2264 2299
 			}
2265 2300
 
2301
+			if warehouse.StockMaxNumber == 0 && warehouse.StockMinNumber > 0 && warehouse.StockMinNumber >= minNumber {
2302
+				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2303
+			}
2304
+
2305
+			if warehouse.StockMaxNumber > 0 && warehouse.StockMinNumber > 0 && (warehouse.StockMaxNumber+warehouse.StockMinNumber) > minNumber {
2306
+
2307
+				var out_false int64 = 0
2308
+				if warehouse.StockMinNumber >= minNumber {
2309
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
2310
+					out_false = 1
2311
+				}
2312
+				fmt.Println("out_false233223233223wo", out_false)
2313
+				if warehouse.StockMinNumber < minNumber && out_false == 0 {
2314
+
2315
+					var over_total int64
2316
+					over_total = warehouse.StockMinNumber
2317
+					warehouse.StockMinNumber = 0
2318
+					warehouse.StockMaxNumber = warehouse.StockMaxNumber - (minNumber - over_total)
2319
+				}
2320
+			}
2321
+
2322
+			//if warehouse.StockMaxNumber < minNumber && warehouse.StockMaxNumber < minNumber && (warehouse.StockMaxNumber + warehouse.StockMinNumber) > minNumber {
2323
+			//  var over_count int64
2324
+			//  over_count = warehouse.StockMinNumber
2325
+			//  warehouse.StockMinNumber = 0
2326
+			//  warehouse.StockMaxNumber = warehouse.StockMaxNumber - (minNumber -over_count)
2327
+			//
2328
+			//}
2329
+
2266 2330
 		}
2267 2331
 
2268 2332
 		if drup.MaxUnit != drup.MinUnit {
@@ -2323,7 +2387,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2323 2387
 
2324 2388
 		//查询今日该药品该患者是否有出库数据
2325 2389
 		lastDrugOutInfo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
2326
-
2390
+		fmt.Println("lastDrugOutInfo0000000293293292392392393293239239", lastDrugOutInfo)
2327 2391
 		if lastDrugOutInfo.ID == 0 {
2328 2392
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2329 2393
 			if errOne != nil {
@@ -2338,7 +2402,10 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2338 2402
 			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2339 2403
 				his_count = lastDrugOutInfo.Count
2340 2404
 			}
2405
+			fmt.Println("deliver_numberwode8888888823832832832832832832823823-------------------------", deliver_number)
2406
+			fmt.Println("his_countnide-------------------------------------------------------", his_count)
2341 2407
 			if deliver_number != his_count {
2408
+				//warehouseOutInfo.Count = deliver_number_one
2342 2409
 				errThree := UpdateSigleDrugWarehouseOutInfo(lastDrugOutInfo.ID, warehouseOutInfo)
2343 2410
 				if errThree != nil {
2344 2411
 					return errThree
@@ -2349,7 +2416,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2349 2416
 		var out_count int64
2350 2417
 		var cancel_count int64
2351 2418
 		//查询出库数据
2352
-		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2419
+		infoCountList, _ := FindDrugSettleWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2353 2420
 		//查询退库数据
2354 2421
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2355 2422
 		for _, item := range infoCountList {
@@ -2360,11 +2427,11 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2360 2427
 			cancel_count += item.Count
2361 2428
 		}
2362 2429
 
2363
-		fmt.Println("deliver_number", deliver_number)
2430
+		fmt.Println("deliver_number_one", deliver_number)
2364 2431
 		fmt.Println("out_count", out_count)
2365 2432
 		fmt.Println("cancel_count", cancel_count)
2366 2433
 		//如果本次出库数据大于历史出库数据 新增1条流水
2367
-		if deliver_number > (out_count - cancel_count) {
2434
+		if deliver_number_one > (out_count - cancel_count) {
2368 2435
 			drugflow := models.DrugFlow{
2369 2436
 				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2370 2437
 				WarehouseOutId:          warehouseout.ID,
@@ -2372,7 +2439,46 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2372 2439
 				Number:                  warehouse.Number,
2373 2440
 				ProductDate:             warehouse.ProductDate,
2374 2441
 				ExpireDate:              warehouse.ExpiryDate,
2375
-				Count:                   deliver_number - (out_count - cancel_count), //按最小单位计算,
2442
+				Count:                   deliver_number_one - (out_count - cancel_count), //按最小单位计算,
2443
+				Price:                   warehouse.RetailPrice,
2444
+				Status:                  1,
2445
+				Ctime:                   time.Now().Unix(),
2446
+				UserOrgId:               orgID,
2447
+				Manufacturer:            warehouse.Manufacturer,
2448
+				Dealer:                  warehouse.Dealer,
2449
+				BatchNumber:             warehouse.BatchNumber,
2450
+				MaxUnit:                 drup.MinUnit,
2451
+				ConsumableType:          15,
2452
+				IsEdit:                  1,
2453
+				Creator:                 advice.ExecutionStaff,
2454
+				IsSys:                   1,
2455
+				PatientId:               advice.PatientId,
2456
+				SystemTime:              advice.AdviceDate,
2457
+				WarehousingDetailId:     warehouse.ID,
2458
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
2459
+				StorehouseId:            storeConfig.DrugStorehouseOut,
2460
+				WarehouseOutDetailId:    lastDrugOutInfo.ID,
2461
+				OverCount:               sum_count,
2462
+				AdviceId:                advice.ID,
2463
+				LastPrice:               warehouse.Price,
2464
+				OrderId:                 warehouseout.OrderId,
2465
+			}
2466
+
2467
+			CreateDrugFlowOne(drugflow)
2468
+			//出库数量相加
2469
+			AddDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count)
2470
+
2471
+		}
2472
+
2473
+		if deliver_number == (out_count - cancel_count) {
2474
+			drugflow := models.DrugFlow{
2475
+				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
2476
+				WarehouseOutId:          warehouseout.ID,
2477
+				DrugId:                  advice.DrugId,
2478
+				Number:                  warehouse.Number,
2479
+				ProductDate:             warehouse.ProductDate,
2480
+				ExpireDate:              warehouse.ExpiryDate,
2481
+				Count:                   deliver_number, //按最小单位计算,
2376 2482
 				Price:                   warehouse.RetailPrice,
2377 2483
 				Status:                  1,
2378 2484
 				Ctime:                   time.Now().Unix(),
@@ -2404,7 +2510,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2404 2510
 		}
2405 2511
 
2406 2512
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
2407
-		if deliver_number < (out_count - cancel_count) {
2513
+		if deliver_number_one < (out_count - cancel_count) {
2408 2514
 
2409 2515
 			operation_time := time.Now().Unix()
2410 2516
 
@@ -2438,9 +2544,9 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2438 2544
 
2439 2545
 			manufactureName, _ := GetManufactureById(warehouse.Manufacturer)
2440 2546
 			dealer, _ := GetDealerById(warehouse.Dealer)
2441
-			cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
2547
+			//cancelInfo, _ := GetLastDrugCancelStockById(advice.UserOrgId)
2442 2548
 			cancelStockInfo := models.DrugCancelStockInfo{
2443
-				OrderNumber:      cancelInfo.OrderNumber,
2549
+				OrderNumber:      lastDrugCancelStock.OrderNumber,
2444 2550
 				CancelStockId:    lastDrugCancelStock.ID,
2445 2551
 				DrugId:           advice.DrugId,
2446 2552
 				Count:            (out_count - cancel_count) - deliver_number,
@@ -2475,14 +2581,14 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2475 2581
 				UserOrgId:               advice.UserOrgId,
2476 2582
 				PatientId:               advice.PatientId,
2477 2583
 				SystemTime:              advice.AdviceDate,
2478
-				ConsumableType:          16,
2584
+				ConsumableType:          7,
2479 2585
 				IsSys:                   0,
2480 2586
 				WarehousingOrder:        "",
2481 2587
 				WarehouseOutId:          0,
2482 2588
 				WarehouseOutOrderNumber: "",
2483 2589
 				IsEdit:                  0,
2484 2590
 				CancelStockId:           cancelStock.ID,
2485
-				CancelOrderNumber:       cancelStock.OrderNumber,
2591
+				CancelOrderNumber:       lastDrugCancelStock.OrderNumber,
2486 2592
 				Manufacturer:            warehouse.Manufacturer,
2487 2593
 				Dealer:                  warehouse.Dealer,
2488 2594
 				Creator:                 advice.ExecutionStaff,
@@ -2612,17 +2718,21 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2612 2718
 			OrderId:                 warehouseout.OrderId,
2613 2719
 		}
2614 2720
 		//查询是否存在出库数据
2615
-		_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
2616
-		if errCode == gorm.ErrRecordNotFound {
2721
+
2722
+		lastDrugOutInfoTwo, _ := GetNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID)
2723
+		//_, errCode := GetSigleDrugWarehouseOutInfo(advice.PatientId, advice.AdviceDate, orgID)
2724
+		//fmt.Println("errcoedee232233223233232323232323233223232323322323232323232323",errCode)
2725
+		if lastDrugOutInfoTwo.ID == 0 {
2617 2726
 
2618 2727
 			errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2619 2728
 			if errOne != nil {
2620 2729
 				return errOne
2621 2730
 			}
2622 2731
 		}
2623
-		if errCode == nil {
2732
+		if lastDrugOutInfoTwo.ID > 0 {
2624 2733
 
2625 2734
 			lastDrugOutInfo, _ := GetSigleDrugWarehouseOutInfoOne(advice.PatientId, advice.AdviceDate, orgID)
2735
+			fmt.Println("中国人民肌肤32323223332332232322323喔", lastDrugOutInfo)
2626 2736
 			var his_count int64
2627 2737
 			if lastDrugOutInfo.CountUnit == drup.MaxUnit {
2628 2738
 				his_count = lastDrugOutInfo.Count * drup.MinNumber
@@ -2630,7 +2740,10 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2630 2740
 			if lastDrugOutInfo.CountUnit == drup.MinUnit {
2631 2741
 				his_count = lastDrugOutInfo.Count
2632 2742
 			}
2743
+			fmt.Println("deliver_number3232323232wowooww", deliver_number)
2744
+			fmt.Println("his_count99999992i2222wo", his_count)
2633 2745
 			if deliver_number != his_count {
2746
+
2634 2747
 				errThree := UpdateSingleDrugWarehouseOutInfoSix(advice.PatientId, advice.AdviceDate, orgID, warehouseOutInfo, advice.ID)
2635 2748
 				if errThree != nil {
2636 2749
 					return errThree
@@ -2670,7 +2783,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2670 2783
 		var out_count int64
2671 2784
 		var cancel_count int64
2672 2785
 		//查询出库数据
2673
-		infoCountList, _ := FindDrugWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2786
+		infoCountList, _ := FindDrugSettleWarehouseOutInfoCount(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2674 2787
 		//查询退库数据
2675 2788
 		cancelInfoList, _ := FindDrugCancelOutInfo(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID)
2676 2789
 		for _, item := range infoCountList {
@@ -2681,6 +2794,9 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2681 2794
 			cancel_count += item.Count
2682 2795
 		}
2683 2796
 
2797
+		fmt.Println("出库数量", deliver_number)
2798
+		fmt.Println("out_coutn233232322323wo", cancel_count)
2799
+		fmt.Println("out_count99988233232", out_count)
2684 2800
 		//如果本次出库数据大于历史出库数据 新增1条流水
2685 2801
 		if deliver_number > (out_count - cancel_count) {
2686 2802
 
@@ -2722,6 +2838,7 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2722 2838
 		}
2723 2839
 
2724 2840
 		if deliver_number < (out_count - cancel_count) {
2841
+			fmt.Println("即那里3232232323")
2725 2842
 			operation_time := time.Now().Unix()
2726 2843
 
2727 2844
 			ctime := time.Now().Unix()
@@ -2791,14 +2908,14 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2791 2908
 				UserOrgId:               advice.UserOrgId,
2792 2909
 				PatientId:               advice.PatientId,
2793 2910
 				SystemTime:              advice.AdviceDate,
2794
-				ConsumableType:          16,
2911
+				ConsumableType:          7,
2795 2912
 				IsSys:                   0,
2796 2913
 				WarehousingOrder:        "",
2797 2914
 				WarehouseOutId:          0,
2798 2915
 				WarehouseOutOrderNumber: "",
2799 2916
 				IsEdit:                  0,
2800 2917
 				CancelStockId:           cancelStock.ID,
2801
-				CancelOrderNumber:       cancelStock.OrderNumber,
2918
+				CancelOrderNumber:       lastDrugCancelStock.OrderNumber,
2802 2919
 				Manufacturer:            warehouse.Manufacturer,
2803 2920
 				Dealer:                  warehouse.Dealer,
2804 2921
 				Creator:                 advice.ExecutionStaff,
@@ -2834,8 +2951,9 @@ func HisSettleDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseo
2834 2951
 
2835 2952
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
2836 2953
 		advice.PrescribingNumberUnit = drup.MinUnit
2954
+		fmt.Println("剩余库存9999999233232", overPlusNumber)
2837 2955
 
2838
-		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
2956
+		HisSettleDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, prescribingCount)
2839 2957
 	}
2840 2958
 
2841 2959
 	return

+ 29 - 0
service/patient_schedule_template_service.go Прегледај датотеку

@@ -925,3 +925,32 @@ func GetOrgPatientScheduleTemplateModeTwo(orgID int64) (models.PatientScheduleTe
925 925
 	err := readDb.Model(&models.PatientScheduleTemplateMode{}).Where("org_id = ? AND status = 1", orgID).First(&mode).Error
926 926
 	return mode, err
927 927
 }
928
+
929
+func GetAllPatientScheduleTemplateItemsWithoutPatientByTemplateID(orgID int64) ([]*models.PatientScheduleTemplateItem, error) {
930
+	var items []*models.PatientScheduleTemplateItem
931
+	err := readDb.Raw("select item.id,item.org_id,item.template_id,item.device_number_id,item.patient_id,item.treat_mode,item.weekday,item.time_type,item.status,item.status,item.ctime,item.mtime from xt_patient_schedule_template_item as item left join xt_patients as patient on item.patient_id = patient.id where item.org_id = ? AND item.status = 1 and patient.lapseto = 1 and patient.status = 1", orgID).Scan(&items).Error
932
+	// err := readDb.
933
+	// 	Model(&models.PatientScheduleTemplateItem{}).
934
+	// 	Where("org_id = ? AND template_id = ? AND status = 1", orgID, templateID).
935
+	// 	Find(&items).
936
+	// 	Error
937
+	if err != nil {
938
+		return nil, err
939
+	}
940
+	return items, nil
941
+}
942
+
943
+func GetScheduleTemplateItem(id int64) (item models.PatientScheduleTemplateItem, err error) {
944
+	err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", id).First(&item).Error
945
+	return
946
+}
947
+
948
+func SaveSchTemplateItem(item models.PatientScheduleTemplateItem) (err error) {
949
+	err = writeDb.Save(&item).Error
950
+	return
951
+}
952
+
953
+func UpdateTemplateItemModeWeek(orgID int64, id int64, week_time int64) {
954
+	readDb.Model(&models.PatientScheduleTemplateMode{}).Where("org_id = ? AND status = 1 AND id = ? ", orgID, id).Updates(map[string]interface{}{"original_week": week_time, "week": week_time})
955
+	return
956
+}

+ 6 - 1
service/patient_service.go Прегледај датотеку

@@ -2517,7 +2517,7 @@ func GetAllPatientListByListOne(orgID int64) (patients []*models.VMMonitorPatien
2517 2517
 	patient_info_str, _ := redis.Get(key).Result()
2518 2518
 
2519 2519
 	if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
2520
-		err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error
2520
+		err = readDb.Model(&models.VMMonitorPatients{}).Where("user_org_id=? and status=1", orgID).Find(&patients).Error
2521 2521
 		if err != nil {
2522 2522
 			if err == gorm.ErrRecordNotFound {
2523 2523
 				return nil, nil
@@ -2738,3 +2738,8 @@ func GetAllSchedulesByPatientInfo(org_id int64, patient_id int64, mode_id int64)
2738 2738
 	}
2739 2739
 	return record, nil
2740 2740
 }
2741
+
2742
+func UpdateScheduleByExport(org_id int64, shcheduledate int64) error {
2743
+	err := XTWriteDB().Model(models.XtSchedule{}).Where("user_org_id = ? and schedule_date > ?", org_id, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
2744
+	return err
2745
+}

+ 33 - 0
service/patientmanage_service.go Прегледај датотеку

@@ -1879,3 +1879,36 @@ func DeleteHospitalSummary(id []string) error {
1879 1879
 	err := XTWriteDB().Model(models.XtHospitalSummary{}).Where("id in (?) and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
1880 1880
 	return err
1881 1881
 }
1882
+
1883
+func GetAllPatientScheduleList(org_id int64) (patient []*models.PatientsThirty, err error) {
1884
+
1885
+	err = XTReadDB().Where("user_org_id = ? and status = 1", org_id).Find(&patient).Error
1886
+
1887
+	return patient, err
1888
+}
1889
+
1890
+func GetAllDialysiOrderList(patient_id int64, org_id int64) (order []*models.DialysisOrder, err error) {
1891
+
1892
+	err = XTReadDB().Where("patient_id = ? and user_org_id = ? and status= 1 and dialysis_date<=1672416000", patient_id, org_id).Find(&order).Error
1893
+
1894
+	return order, err
1895
+}
1896
+
1897
+func GetDialysisTotalCountThree(org_id int64, patient_id int64, dialysis_date int64) (models.BloodDialysisOrderCount, error) {
1898
+
1899
+	order := models.BloodDialysisOrderCount{}
1900
+	db := XTReadDB().Table("xt_dialysis_order as o")
1901
+
1902
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date<=? and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id, dialysis_date).Scan(&order).Error
1903
+
1904
+	return order, err
1905
+}
1906
+
1907
+func UpdateDialysisOrderSix(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
1908
+
1909
+	order := models.DialysisOrder{}
1910
+
1911
+	err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
1912
+
1913
+	return order, err
1914
+}

+ 1 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go Прегледај датотеку

@@ -215,6 +215,7 @@ type PrescriptionVM struct {
215 215
 	OxygenUptake               int64   `gorm:"column:oxygen_uptake" json:"oxygen_uptake" form:"oxygen_uptake"`
216 216
 	OxygenFlow                 string  `gorm:"column:oxygen_flow" json:"oxygen_flow" form:"oxygen_flow"`
217 217
 	OxygenTime                 string  `gorm:"column:oxygen_time" json:"oxygen_time" form:"oxygen_time"`
218
+	DialysisRemark             string  `gorm:"column:dialysis_remark" json:"dialysis_remark" form:"dialysis_remark"`
218 219
 }
219 220
 
220 221
 func (PrescriptionVM) TableName() string {

+ 7 - 1
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go Прегледај датотеку

@@ -57,7 +57,7 @@ func GetSchedules(orgID int64, schIDs []string) ([]*ScheduleVM, error) {
57 57
 		return nil, err
58 58
 	}
59 59
 	for _, item := range schedules {
60
-		if orgID != 10101 {
60
+		if orgID != 10101 && orgID != 10445 {
61 61
 			dialysis_count, _ := GetDialysisOrderCount(orgID, item.PatientID, item.ScheduleDate)
62 62
 
63 63
 			item.Patient.TotalDialysis = dialysis_count
@@ -227,6 +227,12 @@ func GetDialysisOrderCountEight(orgID int64, patient_id int64, recordDate int64)
227 227
 	return order, err
228 228
 }
229 229
 
230
+func GetDialysisOrderCountNight(orgID int64, patient_id int64, recordDate int64) (models.VmDialysisOrder, error) {
231
+	order := models.VmDialysisOrder{}
232
+	err := p_service.XTReadDB().Raw("SELECT Count(id) as count,Max(dialysis_date) as dialysis_date  from xt_dialysis_order where dialysis_date>=1672502400 and dialysis_date <= ? AND status = 1 AND stage = 2 AND patient_id = ? and user_org_id = ?", recordDate, patient_id, orgID).Scan(&order).Error
233
+	return order, err
234
+}
235
+
230 236
 func GetOutStockTotalCountTwo(startime int64, endtime int64, orgid int64) (autoMatic []*models.NewXtAutomaticReduceDetail, err error) {
231 237
 
232 238
 	err = p_service.XTReadDB().Raw("SELECT good_id,SUM(b.count) as count FROM (SELECT DISTINCT x.patient_id,x.good_id,x.record_time,x.count FROM xt_automatic_reduce_detail as x WHERE x.org_id = ? and x.record_time >= ? and x.record_time<=? and `status` = 1)  as b GROUP BY good_id", orgid, startime, endtime).Scan(&autoMatic).Error

+ 56 - 9
service/schedule_service.go Прегледај датотеку

@@ -36,7 +36,9 @@ func GetSchedulePartitionPanelTwo(orgID int64, schIDs []string) (partitions []*m
36 36
 		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
37 37
 	}
38 38
 	if len(schIDs) > 0 {
39
-		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1 and zone_id in(?)", orgID, schIDs).Where("org_id=? and status=1 and id in(?)", orgID, schIDs).Find(&partitions).Error
39
+		err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", func(db *gorm.DB) *gorm.DB {
40
+			return db.Where("org_id=? and status=1 and zone_id in (?)", orgID, schIDs).Order("sort desc")
41
+		}).Where("org_id=? and status=1 and id in(?)", orgID, schIDs).Find(&partitions).Error
40 42
 	}
41 43
 
42 44
 	return
@@ -112,7 +114,6 @@ func GetWeekScheduleOne(orgID int64, start, end int64, partionid int64, schedule
112 114
 func GetWeekScheduleTwo(orgID int64, start, end int64, schIds []string, scheduletype int64) (schedules []*models.Schedule, err error) {
113 115
 
114 116
 	db := readDb.Table("xt_schedule as s")
115
-	fmt.Println("schIds2222222")
116 117
 	if len(schIds) > 0 {
117 118
 		db = db.Where("s.partition_id in (?)", schIds)
118 119
 	}
@@ -128,6 +129,28 @@ func GetWeekScheduleTwo(orgID int64, start, end int64, schIds []string, schedule
128 129
 	return
129 130
 }
130 131
 
132
+func GetWeekScheduleThree(orgID int64, start, end int64, schIds []string, scheduletype int64, WeekDayIds []string) (schedules []*models.Schedule, err error) {
133
+
134
+	db := readDb.Table("xt_schedule as s")
135
+
136
+	if len(schIds) > 0 {
137
+		db = db.Where("s.partition_id in (?)", schIds)
138
+	}
139
+	if scheduletype > 0 {
140
+		db = db.Where("s.schedule_type = ?", scheduletype)
141
+	}
142
+	if len(WeekDayIds) > 0 {
143
+		db = db.Where("s.schedule_week in(?)", WeekDayIds)
144
+	}
145
+	err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
146
+		Joins("JOIN xt_patients as p ON p.id = s.patient_id").
147
+		Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
148
+		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, s.status, s.created_time, s.updated_time,s.dialysis_machine_name, p.name as patient").
149
+		Order("updated_time asc").
150
+		Find(&schedules).Error
151
+	return
152
+}
153
+
131 154
 func GetDaySchedule(orgID, start, end, patientID int64) (schedule models.Schedule, err error) {
132 155
 	err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and patient_id=? and schedule_date>=? and schedule_date<=? and status=1", orgID, patientID, start, end).First(&schedule).Error
133 156
 	return
@@ -259,7 +282,7 @@ func UpdateScheduleByOrgId(patientid int64, scheduledate int64, orgid int64, mod
259 282
 }
260 283
 
261 284
 func UpdateScheduleByOrgIdOne(patientid int64, scheduledate int64, orgid int64, sch *models.XtSchedule) error {
262
-	err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, scheduledate, orgid).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix()}).Error
285
+	err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, scheduledate, orgid).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix(), "dialysis_machine_name": sch.DialysisMachineName}).Error
263 286
 	return err
264 287
 }
265 288
 
@@ -300,12 +323,36 @@ func UpdateScheduleOne(id int64, schedule models.Schedule) error {
300 323
 //参数一:当前操作的患者的排班     参数二被替换床位对应的排班
301 324
 func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) {
302 325
 	utx := XTWriteDB()
303
-	var tempPatientID int64
304
-	var tempPatientIDTwo int64
305
-	tempPatientID = schone.PatientId
306
-	tempPatientIDTwo = schtwo.PatientId
307
-	schone.PatientId = tempPatientIDTwo
308
-	schtwo.PatientId = tempPatientID
326
+	//床位
327
+	var tempBedID int64
328
+	var tempBedIDTwo int64
329
+
330
+	//分區
331
+	var tempPID int64
332
+	var tempPIDTwo int64
333
+
334
+	//上下午
335
+	var tempTypeID int64
336
+	var tempTypeTwo int64
337
+
338
+	tempBedID = schone.BedId
339
+	tempBedIDTwo = schtwo.BedId
340
+
341
+	tempPID = schone.PartitionId
342
+	tempPIDTwo = schtwo.PartitionId
343
+
344
+	tempTypeID = schone.ScheduleType
345
+	tempTypeTwo = schtwo.ScheduleType
346
+
347
+	schone.BedId = tempBedIDTwo
348
+	schtwo.BedId = tempBedID
349
+
350
+	schone.PartitionId = tempPIDTwo
351
+	schtwo.PartitionId = tempPID
352
+
353
+	schone.ScheduleType = tempTypeTwo
354
+	schtwo.ScheduleType = tempTypeID
355
+
309 356
 	utx.Save(&schone)
310 357
 	utx.Save(&schtwo)
311 358
 

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

@@ -1516,7 +1516,7 @@ func GetGoodPatientList(orgid int64, keyword string) (patient []*models.XtPatien
1516 1516
 
1517 1517
 func GetWarehouseOutDetailByPatientIdOne(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (info []*models.WarehouseOutInfo, total int64, err error) {
1518 1518
 
1519
-	db := XTReadDB().Model(&info).Where("status = 1 and is_sys = 1")
1519
+	db := XTReadDB().Model(&info).Where("status = 1 and (is_sys = 1 or is_sys = 5)")
1520 1520
 	offset := (page - 1) * limit
1521 1521
 	if orgid > 0 {
1522 1522
 		db = db.Where("org_id = ?", orgid)
@@ -1536,7 +1536,7 @@ func GetWarehouseOutDetailByPatientIdOne(orgid int64, patient_id int64, startime
1536 1536
 
1537 1537
 func GetWarehouseOutDetailByPatientId(orgid int64, patient_id int64, startime int64, endtime int64) (info []*models.WarehouseOutInfo, err error) {
1538 1538
 
1539
-	db := XTReadDB().Model(&info).Where("status = 1 and is_sys = 1")
1539
+	db := XTReadDB().Model(&info).Where("status = 1 and (is_sys = 1 or is_sys =5)")
1540 1540
 	if orgid > 0 {
1541 1541
 		db = db.Where("org_id = ?", orgid)
1542 1542
 	}

+ 88 - 40
service/smart_sch.go Прегледај датотеку

@@ -15,21 +15,41 @@ func GetSmartSchPatientByKeyWord(orgID int64, keywords string) (patient []*model
15 15
 		err = db.Find(&patient).Error
16 16
 	}
17 17
 
18
-	for _, item := range patient {
19
-		var sch []*models.SmartSchedule
20
-		now := time.Now()
18
+	//for _, item := range patient {
19
+	//	var sch []*models.SmartSchedule
20
+	//	now := time.Now()
21
+	//
22
+	//	offset := int(time.Monday - now.Weekday())
23
+	//	if offset > 0 {
24
+	//		offset = -6
25
+	//	}
26
+	//
27
+	//	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
28
+	//	readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
29
+	//		Preload("DeviceZone", "status = 1").
30
+	//		Preload("SmSchDialysisOrder", "status = 1").
31
+	//		Preload("DeviceNumber", "status = 1").Find(&sch)
32
+	//	item.SmartSchedule = sch
33
+	//}
21 34
 
22
-		offset := int(time.Monday - now.Weekday())
23
-		if offset > 0 {
24
-			offset = -6
25
-		}
35
+	return
36
+}
37
+
38
+func GetSmartSchPatientByPatientID(orgID int64, id int64) (sch []*models.SmartSchedule, err error) {
39
+	now := time.Now()
40
+	offset := int(time.Monday - now.Weekday())
41
+	if offset > 0 {
42
+		offset = -6
43
+	}
44
+	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
45
+	readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, id, weekStart.Unix()).
46
+		Preload("DeviceZone", "status = 1").
47
+		Preload("DeviceNumber", "status = 1").Find(&sch)
26 48
 
27
-		weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
28
-		readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, item.ID, weekStart.Unix()).
29
-			Preload("DeviceZone", "status = 1").
30
-			Preload("SmSchDialysisOrder", "status = 1").
31
-			Preload("DeviceNumber", "status = 1").Find(&sch)
32
-		item.SmartSchedule = sch
49
+	for _, item := range sch {
50
+		var order models.SmSchDialysisOrder
51
+		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? AND bed_id = ?", orgID, item.PatientId, item.ScheduleDate, item.BedId).First(&order)
52
+		item.SmSchDialysisOrder = order
33 53
 	}
34 54
 
35 55
 	return
@@ -43,32 +63,31 @@ func GetSmartSchTemplatePatientByKeyWord(orgID int64, keywords string) (patient
43 63
 	} else {
44 64
 		err = db.Find(&patient).Error
45 65
 	}
46
-
47
-	for _, item := range patient {
48
-		mode, _ := GetOrgPatientScheduleTemplateModeTwo(item.UserOrgId)
49
-		if mode.ID > 0 {
50
-			if mode.Mode == 1 {
51
-				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 1)
52
-				item.XtPatientScheduleTemplateId = schs
53
-
54
-			} else if mode.Mode == 2 {
55
-				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 2)
56
-
57
-				item.XtPatientScheduleTemplateId = schs
58
-
59
-			} else if mode.Mode == 3 {
60
-				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 3)
61
-				item.XtPatientScheduleTemplateId = schs
62
-
63
-			} else if mode.Mode == 4 {
64
-
65
-				schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 4)
66
-				item.XtPatientScheduleTemplateId = schs
67
-
68
-			}
69
-		}
70
-
71
-	}
66
+	//for _, item := range patient {
67
+	//	mode, _ := GetOrgPatientScheduleTemplateModeTwo(item.UserOrgId)
68
+	//	if mode.ID > 0 {
69
+	//		if mode.Mode == 1 {
70
+	//			schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 1)
71
+	//			item.XtPatientScheduleTemplateId = schs
72
+	//
73
+	//		} else if mode.Mode == 2 {
74
+	//			schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 2)
75
+	//
76
+	//			item.XtPatientScheduleTemplateId = schs
77
+	//
78
+	//		} else if mode.Mode == 3 {
79
+	//			schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 3)
80
+	//			item.XtPatientScheduleTemplateId = schs
81
+	//
82
+	//		} else if mode.Mode == 4 {
83
+	//
84
+	//			schs, _ := GetSmartSchTemplatePatientByID(item.UserOrgId, item.ID, 4)
85
+	//			item.XtPatientScheduleTemplateId = schs
86
+	//
87
+	//		}
88
+	//	}
89
+	//
90
+	//}
72 91
 	return
73 92
 }
74 93
 
@@ -81,8 +100,13 @@ func GetSmartSchPatientByID(orgID int64, patient_id int64) (schs []*models.Smart
81 100
 	weekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
82 101
 	err = readDb.Model(&models.SmartSchedule{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND schedule_date >= ?", orgID, patient_id, weekStart.Unix()).
83 102
 		Preload("DeviceZone", "status = 1").
84
-		Preload("SmSchDialysisOrder", "status = 1").
85 103
 		Preload("DeviceNumber", "status = 1").Find(&schs).Error
104
+
105
+	for _, item := range schs {
106
+		var order models.SmSchDialysisOrder
107
+		readDb.Model(&models.SmSchDialysisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND dialysis_date = ? AND bed_id = ?", orgID, item.PatientId, item.ScheduleDate, item.BedId).First(&order)
108
+		item.SmSchDialysisOrder = order
109
+	}
86 110
 	return
87 111
 }
88 112
 
@@ -118,3 +142,27 @@ func GetScheduleByZoneAndBed(org_id int64, partitionId int64, bed_id int64, sche
118 142
 	err = readDb.Model(&models.SmartSchedule{}).Where("bed_id = ? AND user_org_id = ? AND schedule_date = ? AND partition_id = ? AND schedule_type = ?  AND status = 1", bed_id, org_id, schedule_date, partitionId, sch_type).First(&sch).Error
119 143
 	return
120 144
 }
145
+
146
+func GetScheduleByDate(org_id int64, schedule_date int64, patient_id int64) (sch models.SmartSchedule, err error) {
147
+	err = readDb.Model(&models.SmartSchedule{}).Where(" user_org_id = ? AND schedule_date = ? AND status = 1 AND patient_id = ?", org_id, schedule_date, patient_id).First(&sch).Error
148
+	return
149
+}
150
+func SaveSmartSch(sch models.SmartSchedule) {
151
+	writeDb.Save(&sch)
152
+	return
153
+}
154
+
155
+func GetAllAvaildTemplateDeviceNumbersByZone(orgID int64, weekday int64, schedule_type int, zone_id int64, patient_id int64, template_id int64) ([]*DeviceNumberViewModel, error) {
156
+	var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
157
+	rows, err := readDb.Raw("SELECT n.*, z.name as zone_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id AND z.id = ?   WHERE (n.org_id = ? AND n.status = 1) AND NOT EXISTS (Select * FROM xt_patient_schedule_template_item as s Where s.`weekday` = ? AND s.patient_id <> ?  AND  s.org_id = n.org_id AND s.`device_number_id` = n.id  AND s.`time_type` = ? AND s.status = 1 AND s.template_id = ?)", zone_id, orgID, weekday, patient_id, schedule_type, template_id).Rows()
158
+	defer rows.Close()
159
+	if err != nil {
160
+		return nil, err
161
+	}
162
+	for rows.Next() {
163
+		var vm DeviceNumberViewModel
164
+		readDb.ScanRows(rows, &vm)
165
+		vms = append(vms, &vm)
166
+	}
167
+	return vms, nil
168
+}

+ 66 - 3
service/stock_service.go Прегледај датотеку

@@ -3883,16 +3883,30 @@ func UpdateAutoGood(orgid int64, patient_id int64, recordtime int64, goodid int6
3883 3883
 	return err
3884 3884
 }
3885 3885
 
3886
-func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64) error {
3886
+func DeleteAutoRedeceDetailTen(orgid int64, patient_id int64, recordtime int64, goodid int64, project_id int64) error {
3887 3887
 
3888 3888
 	detail := models.BloodAutomaticReduceDetail{}
3889 3889
 	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? ", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3890 3890
 	info := models.WarehouseOutInfo{}
3891
-	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3891
+	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3892 3892
 	prepare := models.DialysisBeforePrepare{}
3893 3893
 	err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3894 3894
 	flow := models.VmStockFlow{}
3895
-	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"is_read": 1}).Error
3895
+	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and project_id = ?", orgid, patient_id, recordtime, goodid, project_id).Updates(map[string]interface{}{"is_read": 1}).Error
3896
+	return err
3897
+
3898
+}
3899
+
3900
+func DeleteAutoRedeceDetailTenOne(orgid int64, patient_id int64, recordtime int64, goodid int64, order_id int64) error {
3901
+
3902
+	detail := models.BloodAutomaticReduceDetail{}
3903
+	err := XTWriteDB().Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? ", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3904
+	info := models.WarehouseOutInfo{}
3905
+	err = XTWriteDB().Model(&info).Where("org_id = ? and patient_id = ? and sys_record_time = ? and good_id = ? and status = 1 and order_id = ?", orgid, patient_id, recordtime, goodid, order_id).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3906
+	prepare := models.DialysisBeforePrepare{}
3907
+	err = XTWriteDB().Model(&prepare).Where("user_org_id = ? and patient_id = ? and record_date = ? and good_id = ? and status = 1", orgid, patient_id, recordtime, goodid).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3908
+	flow := models.VmStockFlow{}
3909
+	err = XTWriteDB().Model(&flow).Where("user_org_id = ? and patient_id = ? and system_time = ? and good_id = ? and status = 1 and order_id = ?", orgid, patient_id, recordtime, goodid, order_id).Updates(map[string]interface{}{"is_read": 1}).Error
3896 3910
 	return err
3897 3911
 
3898 3912
 }
@@ -4009,6 +4023,12 @@ func GetGoodWarehouseInfoSeven(good_id int64) (info []*models.WarehousingInfoSev
4009 4023
 	return info, err
4010 4024
 }
4011 4025
 
4026
+func GetGoodWarehouseInfoSevenTen(good_id int64, storehouse_id int64) (info []*models.WarehousingInfoSeven, err error) {
4027
+
4028
+	err = readDb.Select("stock_count").Where("good_id = ? and status = 1 and stock_count<>0 and storehouse_id = ?", good_id, storehouse_id).Find(&info).Error
4029
+	return info, err
4030
+}
4031
+
4012 4032
 func GetAllStockList(page int64, limit int64, startime int64, endtime int64, good_type int64, keyword string, orgid int64) (info []*models.VmWarehousingInfo, total int64, err error) {
4013 4033
 
4014 4034
 	offset := (page - 1) * limit
@@ -5072,6 +5092,12 @@ func GetStockFlowIsBatchNumberThree(patient_id int64, record_time int64, good_id
5072 5092
 	return flow, nil
5073 5093
 }
5074 5094
 
5095
+func GetStockFlowIsBatchNumberFour(patient_id int64, record_time int64, good_id int64, project_id int64) (flow []*models.VmStockFlow, err error) {
5096
+
5097
+	err = XTReadDB().Where("patient_id = ? and system_time = ? and good_id = ? and status = 1 and consumable_type =7 and project_id = ?", patient_id, record_time, good_id, project_id).Find(&flow).Error
5098
+	return flow, nil
5099
+}
5100
+
5075 5101
 func GetWarehouseOutInfoIsExist(id int64) (*models.WarehouseOutInfo, error) {
5076 5102
 
5077 5103
 	info := models.WarehouseOutInfo{}
@@ -8340,3 +8366,40 @@ func GetWarehouseOutInfoIsExistThree(good_id int64, patient_id int64, record_tim
8340 8366
 	err := XTReadDB().Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
8341 8367
 	return info, err
8342 8368
 }
8369
+
8370
+func GetWarehouseOutInfoIsExistSix(good_id int64, patient_id int64, record_time int64, project_id int64) (*models.WarehouseOutInfo, error) {
8371
+
8372
+	info := models.WarehouseOutInfo{}
8373
+	var err error
8374
+	err = XTReadDB().Model(&info).Where("good_id = ? and sys_record_time = ? and status = 1 and patient_id = ? and project_id = ?", good_id, record_time, patient_id, project_id).Find(&info).Error
8375
+	if err == gorm.ErrRecordNotFound {
8376
+		return nil, err
8377
+	}
8378
+	if err != nil {
8379
+		return nil, err
8380
+	}
8381
+	return &info, nil
8382
+}
8383
+
8384
+func GetNewGoodWarehouseInfo(startime int64, endtime int64, orgid int64, good_id []int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
8385
+
8386
+	db := XTReadDB().Model(&info).Where("status = 1")
8387
+
8388
+	if startime > 0 {
8389
+		db = db.Where("ctime>=?", startime)
8390
+	}
8391
+	if endtime > 0 {
8392
+		db = db.Where("ctime<=?", endtime)
8393
+	}
8394
+	if orgid > 0 {
8395
+		db = db.Where("org_id = ?", orgid)
8396
+	}
8397
+	if len(good_id) > 0 {
8398
+		db = db.Where("good_id in(?)", good_id)
8399
+	}
8400
+	if storehouse_id > 0 {
8401
+		db = db.Where("storehouse_id = ?", storehouse_id)
8402
+	}
8403
+	err = db.Find(&info).Error
8404
+	return info, err
8405
+}

+ 84 - 51
service/warhouse_service.go Прегледај датотеку

@@ -7493,7 +7493,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
7493 7493
 			return errThree
7494 7494
 		}
7495 7495
 		//查询剩余库存
7496
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
7496
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
7497 7497
 		var sum_count int64
7498 7498
 		for _, item := range goodList {
7499 7499
 			sum_count += item.StockCount
@@ -7721,7 +7721,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
7721 7721
 		if errThree != nil {
7722 7722
 			return errThree
7723 7723
 		}
7724
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
7724
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
7725 7725
 		var sum_count int64
7726 7726
 		for _, item := range goodList {
7727 7727
 			sum_count += item.StockCount
@@ -7936,7 +7936,8 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
7936 7936
 			return errThree
7937 7937
 		}
7938 7938
 		//查询剩余库存
7939
-		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID)
7939
+		houseConfig, _ := GetAllStoreHouseConfig(orgID)
7940
+		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
7940 7941
 		var sum_count int64
7941 7942
 		for _, item := range goodList {
7942 7943
 			sum_count += item.StockCount
@@ -7947,7 +7948,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
7947 7948
 		} else {
7948 7949
 			delete_count = ware.Count
7949 7950
 		}
7950
-		houseConfig, _ := GetAllStoreHouseConfig(orgID)
7951
+
7951 7952
 		// 在出库记录表里记录退库详情
7952 7953
 		warehouseOutInfo := &models.WarehouseOutInfo{
7953 7954
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -10209,6 +10210,7 @@ func AddWarehosingInfo(info *models.WarehousingInfo) error {
10209 10210
 // 药品出库 递归方式
10210 10211
 func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo, drugWarehouse *models.DrugWarehouseInfo) (err error) {
10211 10212
 
10213
+	fmt.Println("尽力2333223333233323322332")
10212 10214
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
10213 10215
 	var deliver_number int64 = 0
10214 10216
 	var stock_number int64 = 0
@@ -10222,8 +10224,10 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10222 10224
 	// 根据先进先出原则,查询最先入库的批次,进行出库
10223 10225
 	// 如果没有对应的库存,则报错
10224 10226
 	//开启事物
10225
-	storeConfig, _ := GetAllStoreHouseConfig(orgID)
10226
-	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
10227
+	//storeConfig, _ := GetAllStoreHouseConfig(orgID)
10228
+	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, warehouseout.StorehouseId)
10229
+	fmt.Println("lastWarehouse.StockMinNumber", lastWarehouse.StockMinNumber)
10230
+	fmt.Println("drup.MinNumber", drup.MinNumber)
10227 10231
 	if lastWarehouse.StockMinNumber >= drup.MinNumber {
10228 10232
 		var stockMax int64
10229 10233
 		var stockMin int64
@@ -10244,6 +10248,8 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10244 10248
 
10245 10249
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
10246 10250
 
10251
+	fmt.Println("stock23233233232", stock_number)
10252
+	fmt.Println("deliver_number", deliver_number)
10247 10253
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
10248 10254
 	if stock_number >= deliver_number {
10249 10255
 
@@ -10328,6 +10334,8 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10328 10334
 			maxNumber = prescribingNumber
10329 10335
 		}
10330 10336
 
10337
+		//fmt.Println("warehouse.StockMaxNumber",warehouse.StockMaxNumber)
10338
+		//fmt.Println("maxNumber9899923323232wo",maxNumber)
10331 10339
 		if warehouse.StockMaxNumber < maxNumber {
10332 10340
 
10333 10341
 			return errors.New("库存数量不足")
@@ -10347,22 +10355,11 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
10347 10355
 			warehouse.StockMinNumber = 0
10348 10356
 		}
10349 10357
 
10358
+		fmt.Println("warehouse.StockMaxNumber323232323233232332", warehouse.StockMaxNumber)
10350 10359
 		if warehouse.StockMaxNumber < 0 {
10351 10360
 			return errors.New("库存数量不足")
10352 10361
 		}
10353 10362
 
10354
-		////扣减库存
10355
-		//if(warehouse.StockMaxNumber > 0){
10356
-		//  var sum_count int64
10357
-		//  sum_count = maxNumber * drup.MinNumber
10358
-		//  ModifyDrugReduceInformationSix(warehouse.DrugId,sum_count,warehouse.OrgId,warehouse.RetailPrice)
10359
-		//}
10360
-		//if(warehouse.StockMinNumber > 0){
10361
-		//  var sum_count int64
10362
-		//  sum_count = minNumber
10363
-		//  ModifyDrugReduceInformationSix(warehouse.DrugId,sum_count,warehouse.OrgId,warehouse.RetailPrice)
10364
-		//}
10365
-
10366 10363
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
10367 10364
 
10368 10365
 		if errThree != nil {
@@ -11306,7 +11303,7 @@ func ConsumablesDeliveryThirty(orgID int64, record_time int64, goods *models.War
11306 11303
 		}
11307 11304
 
11308 11305
 		//查询剩余库存
11309
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
11306
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
11310 11307
 		var sum_count int64
11311 11308
 		for _, item := range goodList {
11312 11309
 			sum_count += item.StockCount
@@ -11477,7 +11474,7 @@ func ConsumablesDeliveryThirty(orgID int64, record_time int64, goods *models.War
11477 11474
 		}
11478 11475
 
11479 11476
 		//查询剩余库存
11480
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
11477
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
11481 11478
 		var sum_count int64
11482 11479
 		for _, item := range goodList {
11483 11480
 			sum_count += item.StockCount
@@ -11773,6 +11770,7 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
11773 11770
 			OverCount:               over_count,
11774 11771
 			RetailPrice:             retail_price, //手动出库出库价格
11775 11772
 			WarehousingId:           warehouse.ID,
11773
+			SystemTime:              advice.SysRecordTime,
11776 11774
 		}
11777 11775
 		if warehouse.RetailPrice == 0 {
11778 11776
 			drugflow.Price = advice.Price
@@ -11840,6 +11838,7 @@ func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehous
11840 11838
 			RetailPrice:             retail_price, //手动出库出库价格
11841 11839
 			WarehousingId:           warehouse.ID,
11842 11840
 			WarehousingDetailId:     warehouse.ID,
11841
+			SystemTime:              advice.SysRecordTime,
11843 11842
 		}
11844 11843
 
11845 11844
 		CreateDrugFlowOne(drugflow)
@@ -11898,9 +11897,9 @@ func FindLastDrugWarehouseOutInfo(orgid int64) (models.DrugWarehouseOutInfo, err
11898 11897
 	return info, err
11899 11898
 }
11900 11899
 
11901
-func GetAllGoodSumCount(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
11900
+func GetAllGoodSumCount(goodid int64, orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
11902 11901
 
11903
-	err = XTReadDB().Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0", goodid, orgid).Find(&info).Error
11902
+	err = XTReadDB().Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goodid, orgid, storehouse_id).Find(&info).Error
11904 11903
 	return info, err
11905 11904
 }
11906 11905
 
@@ -12220,7 +12219,7 @@ func HisSettleDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctor
12220 12219
 		if drup.ID > 0 {
12221 12220
 			prescribingNumber := advice.PrescribingNumber
12222 12221
 
12223
-			HisSettleDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice)
12222
+			HisSettleDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber)
12224 12223
 
12225 12224
 		} else {
12226 12225
 			return errors.New("药品信息不存在")
@@ -12265,6 +12264,9 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12265 12264
 	stock_number = warehouse.StockCount
12266 12265
 
12267 12266
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
12267
+
12268
+	fmt.Println("stock_numnber233232232323", stock_number)
12269
+	fmt.Println("deliver_nmuberwooeooo2oo23", deliver_number)
12268 12270
 	if stock_number >= deliver_number {
12269 12271
 		maxNumber = goods.Count
12270 12272
 		warehouse.StockCount = warehouse.StockCount - maxNumber
@@ -12291,7 +12293,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12291 12293
 		}
12292 12294
 
12293 12295
 		//查询剩余库存
12294
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12296
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12295 12297
 		var sum_count int64
12296 12298
 		for _, item := range goodList {
12297 12299
 			sum_count += item.StockCount
@@ -12496,7 +12498,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12496 12498
 		}
12497 12499
 
12498 12500
 		//查询剩余库存
12499
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12501
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12500 12502
 		var sum_count int64
12501 12503
 		for _, item := range goodList {
12502 12504
 			sum_count += item.StockCount
@@ -12531,7 +12533,7 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12531 12533
 			RegisterNumber:          warehouse.RegisterNumber,
12532 12534
 			OrderId:                 order_id,
12533 12535
 		}
12534
-		OutInfo.Count = goods.Count
12536
+		OutInfo.Count = stock_number
12535 12537
 
12536 12538
 		AddSigleWarehouseOutInfo(OutInfo)
12537 12539
 
@@ -12636,7 +12638,17 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12636 12638
 
12637 12639
 	goods.Count = deliver_number - stock_number
12638 12640
 	prepare := &models.DialysisBeforePrepare{
12639
-		Count: deliver_number - stock_number,
12641
+		Count:        deliver_number - stock_number,
12642
+		GoodTypeId:   goods.GoodTypeId,
12643
+		GoodId:       goods.GoodId,
12644
+		PatientId:    goods.PatientId,
12645
+		RecordDate:   goods.RecordDate,
12646
+		UserOrgId:    orgID,
12647
+		Ctime:        time.Now().Unix(),
12648
+		Creater:      goods.Creater,
12649
+		CommdityCode: goods.CommdityCode,
12650
+		Status:       1,
12651
+		StorehouseId: goods.StorehouseId,
12640 12652
 	}
12641 12653
 	ConsumableSettleDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, order_id)
12642 12654
 
@@ -12644,12 +12656,12 @@ func ConsumableSettleDelivery(orgID int64, patient_id int64, record_time int64,
12644 12656
 }
12645 12657
 
12646 12658
 //保存处方出库
12647
-func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64) (err error) {
12659
+func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64, count int64) (err error) {
12648 12660
 
12649 12661
 	var deliver_number int64 = 0
12650 12662
 	var stock_number int64 = 0
12651 12663
 	var maxNumber int64 = 0
12652
-	fmt.Println("223323233233223233223233223woo", goods.Count)
12664
+
12653 12665
 	deliver_number = goods.Count
12654 12666
 
12655 12667
 	// 根据先进先出原则,查询最先入库的批次,进行出库
@@ -12676,6 +12688,8 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12676 12688
 
12677 12689
 	stock_number = warehouse.StockCount
12678 12690
 
12691
+	fmt.Println("sotck_number233223322o", stock_number)
12692
+	fmt.Println("deliver_number", deliver_number)
12679 12693
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
12680 12694
 	if stock_number >= deliver_number {
12681 12695
 		maxNumber = goods.Count
@@ -12703,7 +12717,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12703 12717
 		}
12704 12718
 
12705 12719
 		//查询剩余库存
12706
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
12720
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
12707 12721
 		var sum_count int64
12708 12722
 		for _, item := range goodList {
12709 12723
 			sum_count += item.StockCount
@@ -12760,9 +12774,9 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12760 12774
 			RegisterNumber:          warehouse.RegisterNumber,
12761 12775
 		}
12762 12776
 		fmt.Println("goods.count2323232233232233232322332322332", goods.Count)
12763
-		OutInfo.Count = goods.Count
12777
+		OutInfo.Count = count
12764 12778
 
12765
-		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
12779
+		_, errcodes := GetWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId)
12766 12780
 		if errcodes == gorm.ErrRecordNotFound {
12767 12781
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
12768 12782
 			if errOne != nil {
@@ -12771,7 +12785,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12771 12785
 		} else if errcodes == nil {
12772 12786
 
12773 12787
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
12774
-			if goods.Count != outInfoOne.Count {
12788
+			if count != outInfoOne.Count {
12775 12789
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
12776 12790
 			}
12777 12791
 
@@ -12780,6 +12794,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12780 12794
 		lastOut, _ := FindWarehouseOutInfoByPatientIdTwo(patient_id, record_time, goods.GoodId, orgID, goods.ProjectId)
12781 12795
 		//查询已经出库的数据
12782 12796
 		flowGood, _ := GetStockFlowIsBatchNumberSix(patient_id, record_time, goods.GoodId, goods.ProjectId)
12797
+		fmt.Println("flowgood23323223323222323wo", flowGood)
12783 12798
 		var out_count int64
12784 12799
 		var out_count_one int64
12785 12800
 		for _, item := range flowGood {
@@ -12787,22 +12802,23 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12787 12802
 		}
12788 12803
 
12789 12804
 		//查询退库数据
12790
-		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
12805
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberFour(patient_id, record_time, goods.GoodId, goods.ProjectId)
12791 12806
 		for _, item := range flowGoodTwo {
12792 12807
 			out_count_one += item.Count
12793 12808
 		}
12794 12809
 
12795 12810
 		//如果本次出库数据大于历史出库数据 新增1条流水
12796
-		fmt.Println("goods_count233232323223", goods.Count)
12797
-		fmt.Println("out_count - out_count_one", out_count-out_count_one)
12798
-		if goods.Count > (out_count - out_count_one) {
12811
+		fmt.Println("out_count23323233232wo", out_count)
12812
+		fmt.Println("goods_count233232323223", count)
12813
+		fmt.Println("out_count - out_count_one", out_count_one)
12814
+		if count > (out_count - out_count_one) {
12799 12815
 
12800 12816
 			stockFlow := models.VmStockFlow{
12801 12817
 				WarehousingId:           warehouse.ID,
12802 12818
 				GoodId:                  goods.GoodId,
12803 12819
 				Number:                  warehouse.Number,
12804 12820
 				LicenseNumber:           warehouse.LicenseNumber,
12805
-				Count:                   goods.Count - out_count + out_count_one,
12821
+				Count:                   count - out_count + out_count_one,
12806 12822
 				UserOrgId:               orgID,
12807 12823
 				PatientId:               goods.PatientId,
12808 12824
 				SystemTime:              record_time,
@@ -12878,7 +12894,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12878 12894
 
12879 12895
 		//如果本次出库数据小于历史出库数据 新增1条退库流水
12880 12896
 
12881
-		if goods.Count < (out_count - out_count_one) {
12897
+		if count < (out_count - out_count_one) {
12882 12898
 
12883 12899
 			operation_time := time.Now().Unix()
12884 12900
 
@@ -12914,7 +12930,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12914 12930
 				GoodId:          goods.GoodId,
12915 12931
 				CancelStockId:   cancel.ID,
12916 12932
 				GoodTypeId:      goods.GoodTypeId,
12917
-				Count:           out_count - out_count_one - goods.Count,
12933
+				Count:           out_count - out_count_one - count,
12918 12934
 				Price:           warehouse.PackingPrice,
12919 12935
 				Total:           0,
12920 12936
 				ProductDate:     warehouse.ProductDate,
@@ -12948,7 +12964,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12948 12964
 				GoodId:                  goods.GoodId,
12949 12965
 				Number:                  warehouse.Number,
12950 12966
 				LicenseNumber:           warehouse.LicenseNumber,
12951
-				Count:                   out_count - out_count_one - goods.Count,
12967
+				Count:                   out_count - out_count_one - count,
12952 12968
 				UserOrgId:               orgID,
12953 12969
 				PatientId:               patient_id,
12954 12970
 				SystemTime:              record_time,
@@ -12988,6 +13004,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
12988 13004
 
12989 13005
 			//退库数量增加
12990 13006
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13007
+			ModifyAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId)
12991 13008
 		}
12992 13009
 
12993 13010
 		//添加入库ID
@@ -13054,11 +13071,12 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13054 13071
 		}
13055 13072
 
13056 13073
 		//查询剩余库存
13057
-		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID)
13074
+		goodList, _ := GetAllGoodSumCount(goods.GoodId, orgID, goods.StorehouseId)
13058 13075
 		var sum_count int64
13059 13076
 		for _, item := range goodList {
13060 13077
 			sum_count += item.StockCount
13061 13078
 		}
13079
+		fmt.Println("剩余库存", sum_count)
13062 13080
 
13063 13081
 		OutInfo := &models.WarehouseOutInfo{
13064 13082
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -13088,9 +13106,9 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13088 13106
 			OverCount:               sum_count,
13089 13107
 			RegisterNumber:          warehouse.RegisterNumber,
13090 13108
 		}
13091
-		OutInfo.Count = goods.Count
13109
+		OutInfo.Count = stock_number
13092 13110
 
13093
-		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
13111
+		_, errcodes := GetWarehouseOutInfoIsExistSix(goods.GoodId, patient_id, record_time, goods.ProjectId)
13094 13112
 		if errcodes == gorm.ErrRecordNotFound {
13095 13113
 			errOne := AddSigleWarehouseOutInfo(OutInfo)
13096 13114
 			if errOne != nil {
@@ -13099,7 +13117,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13099 13117
 		} else if errcodes == nil {
13100 13118
 
13101 13119
 			outInfoOne, _ := GetWarehouseOutInfoIsExistThree(goods.GoodId, patient_id, record_time, goods.ProjectId)
13102
-			if goods.Count != outInfoOne.Count {
13120
+			if count != outInfoOne.Count {
13103 13121
 				UpdatedWarehouseOutInfo(OutInfo, goods.GoodId, patient_id, record_time, goods.ProjectId)
13104 13122
 			}
13105 13123
 
@@ -13117,8 +13135,10 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13117 13135
 		for _, item := range flowGoodTwo {
13118 13136
 			out_count_one += item.Count
13119 13137
 		}
13138
+		fmt.Println("出库数量", stock_number)
13139
+		fmt.Println("历史出库数据", out_count-out_count_one)
13120 13140
 		//如果出库数量 大于 历史出库数据 新增1条流水
13121
-		if goods.Count > out_count-out_count_one {
13141
+		if count > out_count-out_count_one {
13122 13142
 			stockFlow := models.VmStockFlow{
13123 13143
 				WarehousingId:           warehouse.ID,
13124 13144
 				GoodId:                  goods.GoodId,
@@ -13201,7 +13221,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13201 13221
 		}
13202 13222
 
13203 13223
 		//退库
13204
-		if goods.Count < out_count-out_count_one {
13224
+		if count < out_count-out_count_one {
13205 13225
 
13206 13226
 			operation_time := time.Now().Unix()
13207 13227
 
@@ -13237,7 +13257,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13237 13257
 				GoodId:          goods.GoodId,
13238 13258
 				CancelStockId:   cancel.ID,
13239 13259
 				GoodTypeId:      goods.GoodTypeId,
13240
-				Count:           out_count - out_count_one - goods.Count,
13260
+				Count:           out_count - out_count_one - count,
13241 13261
 				Price:           warehouse.PackingPrice,
13242 13262
 				Total:           0,
13243 13263
 				ProductDate:     warehouse.ProductDate,
@@ -13271,7 +13291,7 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13271 13291
 				GoodId:                  goods.GoodId,
13272 13292
 				Number:                  warehouse.Number,
13273 13293
 				LicenseNumber:           warehouse.LicenseNumber,
13274
-				Count:                   out_count - goods.Count,
13294
+				Count:                   out_count - count,
13275 13295
 				UserOrgId:               orgID,
13276 13296
 				PatientId:               patient_id,
13277 13297
 				SystemTime:              record_time,
@@ -13311,6 +13331,8 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13311 13331
 
13312 13332
 			//退库数量增加
13313 13333
 			UpdateSumAddCancelCount(orgID, goods.GoodId, goods.StorehouseId, flow.Count)
13334
+			//实际出库减少
13335
+			ModifyAddGoodSumCount(goods.StorehouseId, flow.Count, orgID, goods.GoodId)
13314 13336
 		}
13315 13337
 
13316 13338
 		errWarehouse := UpdateGoodWarehouseOutById(goods.ID, warehouse.ID, orgID, sum_count)
@@ -13335,9 +13357,20 @@ func ConsumablePrescriptionDelivery(orgID int64, patient_id int64, record_time i
13335 13357
 
13336 13358
 	goods.Count = deliver_number - stock_number
13337 13359
 	prepare := &models.DialysisBeforePrepare{
13338
-		Count: deliver_number - stock_number,
13360
+		Count:        deliver_number - stock_number,
13361
+		GoodTypeId:   goods.GoodTypeId,
13362
+		GoodId:       goods.GoodId,
13363
+		PatientId:    goods.PatientId,
13364
+		RecordDate:   goods.RecordDate,
13365
+		UserOrgId:    orgID,
13366
+		Ctime:        time.Now().Unix(),
13367
+		Creater:      creator,
13368
+		Status:       1,
13369
+		StorehouseId: goods.StorehouseId,
13370
+		ProjectId:    goods.ProjectId,
13339 13371
 	}
13340
-	ConsumablePrescriptionDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator)
13372
+	fmt.Println("剩余出库数量", prepare.Count)
13373
+	ConsumablePrescriptionDelivery(orgID, patient_id, record_time, prepare, warehouseOut, creator, count)
13341 13374
 
13342 13375
 	return nil
13343 13376
 }