Browse Source

2024/6/17

28169 7 months ago
parent
commit
b6fe48f415

+ 2 - 2
controllers/base_api_controller.go View File

@@ -94,7 +94,7 @@ func (this *BaseAuthAPIController) Prepare() {
94 94
 		subscibes[4] = &subscibe
95 95
 		var adminUserInfo service.AdminUserInfo
96 96
 		adminUserInfo.CurrentOrgId = 10666 //机构id小英9675或4
97
-		adminUserInfo.CurrentAppId = 18173 //4
97
+		adminUserInfo.CurrentAppId = 17876 //4
98 98
 		adminUserInfo.AdminUser = &userAdmin
99 99
 		adminUserInfo.Subscibes = subscibes
100 100
 		this.SetSession("admin_user_info", &adminUserInfo)
@@ -340,7 +340,7 @@ func (this *BaseServeAPIController) Prepare() {
340 340
 		subscibes[4] = &subscibe
341 341
 		var adminUserInfo service.AdminUserInfo
342 342
 		adminUserInfo.CurrentOrgId = 10666 //机构id小英9675或4
343
-		adminUserInfo.CurrentAppId = 18173 //4
343
+		adminUserInfo.CurrentAppId = 17876 //4
344 344
 		adminUserInfo.AdminUser = &userAdmin
345 345
 		adminUserInfo.Subscibes = subscibes
346 346
 		this.SetSession("admin_user_info", &adminUserInfo)

+ 676 - 8
controllers/his_api_controller.go View File

@@ -3182,11 +3182,10 @@ func (c *HisApiController) CreateHisPrescription() {
3182 3182
 	}
3183 3183
 
3184 3184
 	//定义切片
3185
-
3186 3185
 	var adviceList []models.HisDoctorAdviceInfo
3187 3186
 	var projectList []models.HisPrescriptionProject
3188 3187
 
3189
-	if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10666 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 9675 {
3188
+	if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 9675 {
3190 3189
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3191 3190
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
3192 3191
 
@@ -3367,7 +3366,7 @@ func (c *HisApiController) CreateHisPrescription() {
3367 3366
 								if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
3368 3367
 									total_count += prescribingNumberSeven
3369 3368
 								}
3370
-								if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
3369
+								if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
3371 3370
 									storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3372 3371
 									lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
3373 3372
 									if s.Price != lastWarehouse.RetailPrice {
@@ -3724,7 +3723,7 @@ func (c *HisApiController) CreateHisPrescription() {
3724 3723
 									projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
3725 3724
 									p.IsOut = projectDetail.IsOut
3726 3725
 								}
3727
-								if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
3726
+								if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
3728 3727
 									storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3729 3728
 									if p.Type == 3 {
3730 3729
 										lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
@@ -4940,6 +4939,443 @@ func (c *HisApiController) CreateHisPrescription() {
4940 4939
 					}
4941 4940
 				}
4942 4941
 			}
4942
+
4943
+			////同步到自备药
4944
+			selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
4945
+
4946
+			fmt.Println("selfPrescriptionOpen--------------------------------------------------", selfPrescriptionOpen.IsOpen)
4947
+			if selfPrescriptionOpen.IsOpen == 1 {
4948
+
4949
+				timeStr := time.Now().Format("2006-01-02")
4950
+				timeArr := strings.Split(timeStr, "-")
4951
+				total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
4952
+				total = total + 1
4953
+
4954
+				operation_time := time.Now().Unix()
4955
+				creater := adminInfo.AdminUser.Id
4956
+
4957
+				warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
4958
+
4959
+				warehousing := models.XtSelfDrugWarehouse{
4960
+					WarehousingOrder: warehousing_order,
4961
+					OperationTime:    operation_time,
4962
+					OrgId:            adminInfo.CurrentOrgId,
4963
+					Creater:          creater,
4964
+					Ctime:            time.Now().Unix(),
4965
+					Status:           1,
4966
+					WarehousingTime:  recordDateTime,
4967
+					Type:             0,
4968
+					StorehouseId:     0,
4969
+					IsCheck:          1,
4970
+					PatientId:        patient_id,
4971
+					IsSys:            1,
4972
+				}
4973
+
4974
+				selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
4975
+
4976
+				if selfDrugWarehouse.ID == 0 {
4977
+					service.AddSelfDrugWarehouse(&warehousing, tx)
4978
+				}
4979
+				if selfDrugWarehouse.ID > 0 {
4980
+					service.UpdateSelfDrugWarehouse(&warehousing, tx)
4981
+				}
4982
+				info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
4983
+				fmt.Println(info)
4984
+
4985
+				for _, item := range hisdoctorlist {
4986
+
4987
+					//查询该病人的该药品是否已经入库
4988
+					selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
4989
+					selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
4990
+					var in_count int64
4991
+					if len(selfdruginfo) > 0 {
4992
+						for _, item := range selfdruginfo {
4993
+							var in_count_one int64
4994
+							if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
4995
+								in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
4996
+							}
4997
+
4998
+							if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
4999
+								in_count_one = item.WarehousingCount
5000
+							}
5001
+
5002
+							if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5003
+								in_count_one = item.WarehousingCount
5004
+							}
5005
+
5006
+							in_count += in_count_one
5007
+						}
5008
+
5009
+					}
5010
+
5011
+					fmt.Println("selfBasedrug--------------------", selfBasedrug.IsSelfDrug)
5012
+					if selfBasedrug.IsSelfDrug == 1 {
5013
+						var total_count int64
5014
+
5015
+						prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
5016
+						prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
5017
+
5018
+						if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5019
+							total_count += prescribingNumberSeven * selfBasedrug.MinNumber
5020
+						}
5021
+
5022
+						if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5023
+							total_count += prescribingNumberSeven
5024
+						}
5025
+
5026
+						if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5027
+							total_count += prescribingNumberSeven
5028
+						}
5029
+
5030
+						fmt.Println("tota_count==================================", total_count)
5031
+						fmt.Println("in_count==================================", in_count)
5032
+						//入库
5033
+						if total_count > in_count {
5034
+
5035
+							selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
5036
+								WarehousingOrder: warehousing_order,
5037
+								WarehousingId:    info.ID,
5038
+								DrugId:           item.DrugId,
5039
+								Number:           "",
5040
+								ProductDate:      0,
5041
+								ExpiryDate:       0,
5042
+								WarehousingCount: total_count - in_count,
5043
+								WarehouseingUnit: selfBasedrug.MinUnit,
5044
+								Price:            0,
5045
+								TotalPrice:       0,
5046
+								Status:           1,
5047
+								Ctime:            time.Now().Unix(),
5048
+								Remark:           "",
5049
+								OrgId:            adminInfo.CurrentOrgId,
5050
+								Type:             0,
5051
+								Manufacturer:     selfBasedrug.Manufacturer,
5052
+								Dealer:           selfBasedrug.Dealer,
5053
+								StockMaxNumber:   total_count - in_count,
5054
+								RetailTotalPrice: 0,
5055
+								BatchNumber:      "",
5056
+								MaxUnit:          selfBasedrug.MinUnit,
5057
+								MinUnit:          selfBasedrug.MinUnit,
5058
+								RetailPrice:      0,
5059
+								StorehouseId:     0,
5060
+								IsCheck:          1,
5061
+								StockMinNumber:   0,
5062
+								PatientId:        patient_id,
5063
+								IsSys:            1,
5064
+								RecordDate:       item.RecordDate,
5065
+								AdviceId:         item.ID,
5066
+							}
5067
+
5068
+							service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
5069
+
5070
+							lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
5071
+							Creator := adminInfo.AdminUser.Id
5072
+
5073
+							//查询默认仓库剩余多少库存
5074
+							list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
5075
+							var sum_count int64
5076
+							for _, it := range list {
5077
+								baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5078
+								if it.MaxUnit == baseDrug.MaxUnit {
5079
+									it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
5080
+									it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
5081
+								}
5082
+								sum_count += it.StockMaxNumber + it.StockMinNumber
5083
+							}
5084
+							flow := &models.XtSelfDrugFlow{
5085
+								WarehousingId:           info.ID,
5086
+								DrugId:                  item.DrugId,
5087
+								Number:                  "",
5088
+								BatchNumber:             "",
5089
+								Count:                   total_count - in_count,
5090
+								UserOrgId:               adminInfo.CurrentOrgId,
5091
+								PatientId:               item.PatientId,
5092
+								SystemTime:              time.Now().Unix(),
5093
+								ConsumableType:          1,
5094
+								IsSys:                   1,
5095
+								WarehousingOrder:        warehousing_order,
5096
+								WarehouseOutId:          0,
5097
+								WarehouseOutOrderNumber: "",
5098
+								IsEdit:                  0,
5099
+								CancelStockId:           0,
5100
+								CancelOrderNumber:       "",
5101
+								Manufacturer:            selfBasedrug.Manufacturer,
5102
+								Dealer:                  selfBasedrug.Dealer,
5103
+								Creator:                 Creator,
5104
+								UpdateCreator:           Creator,
5105
+								Status:                  1,
5106
+								Ctime:                   item.AdviceDate,
5107
+								Mtime:                   0,
5108
+								Price:                   item.Price,
5109
+								WarehousingDetailId:     lastDrugWarhouseInfo.ID,
5110
+								WarehouseOutDetailId:    0,
5111
+								CancelOutDetailId:       0,
5112
+								ExpireDate:              0,
5113
+								ProductDate:             0,
5114
+								MaxUnit:                 selfBasedrug.MinUnit,
5115
+								MinUnit:                 selfBasedrug.MinUnit,
5116
+								StorehouseId:            0,
5117
+								OverCount:               sum_count,
5118
+								OperateTime:             time.Now().Unix(),
5119
+								AdviceId:                item.ID,
5120
+							}
5121
+							service.CreateSelfDrugFlow(flow, tx)
5122
+
5123
+							drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
5124
+
5125
+							var total_count int64 // 入库总数量
5126
+							var over_count int64  //剩余库存
5127
+							for _, it := range drugInfolist {
5128
+								if it.MaxUnit == selfBasedrug.MaxUnit {
5129
+									it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
5130
+									it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
5131
+								}
5132
+							}
5133
+							for _, it := range drugInfolist {
5134
+								total_count += it.WarehousingCount
5135
+								over_count += it.StockMaxNumber + it.StockMinNumber
5136
+
5137
+							}
5138
+							//查询该仓库是否有默认数据
5139
+							selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
5140
+
5141
+							if selfDrugStock.ID == 0 {
5142
+								drugStock := models.XtSelfDrugStockCount{
5143
+									UserOrgId:      item.UserOrgId,
5144
+									PatientId:      item.PatientId,
5145
+									SumInCount:     total_count,
5146
+									SumOutCount:    0,
5147
+									SumCancelCount: 0,
5148
+									DrugId:         item.DrugId,
5149
+									Ctime:          time.Now().Unix(),
5150
+									Mtime:          0,
5151
+									Status:         1,
5152
+									FlushCount:     over_count,
5153
+									SumActOutCount: 0,
5154
+								}
5155
+								service.CreateSelfDrugStockSum(drugStock, tx)
5156
+
5157
+							}
5158
+							if selfDrugStock.ID > 0 {
5159
+								service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
5160
+							}
5161
+
5162
+						}
5163
+
5164
+						//查询这个单据的出库数量
5165
+
5166
+						drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
5167
+
5168
+						var his_out_count int64
5169
+						for _, item := range drugFlowList {
5170
+							his_out_count += item.Count
5171
+						}
5172
+
5173
+						//如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
5174
+						if (total_count + his_out_count) <= in_count {
5175
+							// 出库
5176
+							if total_count < in_count {
5177
+
5178
+								var cha_count int64
5179
+
5180
+								cha_count = in_count - total_count
5181
+
5182
+								var stock_number int64 = 0
5183
+								//查询库存是否充足
5184
+								warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
5185
+
5186
+								// 将该批次的剩余库存数量转换为拆零数量
5187
+								if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5188
+
5189
+									stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
5190
+
5191
+								}
5192
+								if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5193
+
5194
+									stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
5195
+
5196
+								}
5197
+								if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5198
+
5199
+									stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
5200
+
5201
+								}
5202
+
5203
+								if stock_number >= cha_count {
5204
+
5205
+									var maxNumber int64 = 0
5206
+									var minNumber int64 = 0
5207
+
5208
+									maxNumber = cha_count / selfBasedrug.MinNumber
5209
+									minNumber = cha_count % selfBasedrug.MinNumber
5210
+
5211
+									fmt.Println("maxNumber----------------------------", maxNumber)
5212
+									fmt.Println("minNumber----------------------------", minNumber)
5213
+									if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5214
+										minNumber = maxNumber
5215
+									}
5216
+
5217
+									if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5218
+										if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
5219
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
5220
+											return
5221
+										}
5222
+									}
5223
+
5224
+									if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5225
+
5226
+										warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
5227
+									}
5228
+
5229
+									if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5230
+
5231
+										warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5232
+									}
5233
+									if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5234
+
5235
+										warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5236
+									}
5237
+
5238
+									if warehouse.StockMaxNumber < 0 {
5239
+										warehouse.StockMaxNumber = 0
5240
+									}
5241
+									if warehouse.StockMinNumber < 0 {
5242
+										warehouse.StockMinNumber = 0
5243
+									}
5244
+
5245
+									warehouse.Mtime = time.Now().Unix()
5246
+
5247
+									if warehouse.StockMinNumber < minNumber {
5248
+										warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
5249
+										if warehouse.MaxUnit != warehouse.MinUnit {
5250
+											warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
5251
+										}
5252
+										if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
5253
+											warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
5254
+										}
5255
+									} else {
5256
+										if minNumber > 0 {
5257
+											if (warehouse.StockMinNumber - minNumber) >= 0 {
5258
+												warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
5259
+											}
5260
+
5261
+										}
5262
+
5263
+										if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
5264
+
5265
+											if warehouse.StockMinNumber > 0 {
5266
+												if warehouse.StockMinNumber-cha_count >= 0 {
5267
+													warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
5268
+												}
5269
+
5270
+											}
5271
+
5272
+										}
5273
+
5274
+									}
5275
+
5276
+									if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
5277
+										if (warehouse.StockMinNumber - cha_count) >= 0 {
5278
+											warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
5279
+										}
5280
+
5281
+									}
5282
+
5283
+									if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5284
+										if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
5285
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
5286
+											return
5287
+										}
5288
+									}
5289
+									if warehouse.StockMinNumber <= 0 {
5290
+										warehouse.StockMinNumber = 0
5291
+									}
5292
+
5293
+									service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
5294
+
5295
+									//查询该药品剩余库存
5296
+									infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
5297
+									var over_count int64
5298
+									for _, its := range infolist {
5299
+										if its.MaxUnit == selfBasedrug.MaxUnit {
5300
+											its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
5301
+										}
5302
+										over_count += its.StockMaxNumber + its.StockMinNumber
5303
+									}
5304
+
5305
+									drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
5306
+									drugflow := models.XtSelfDrugFlow{
5307
+										WarehouseOutId:          0,
5308
+										WarehouseOutOrderNumber: warehousing_order,
5309
+										WarehousingOrder:        warehousing_order,
5310
+										DrugId:                  item.DrugId,
5311
+										Number:                  warehouse.Number,
5312
+										ProductDate:             warehouse.ProductDate,
5313
+										ExpireDate:              warehouse.ExpiryDate,
5314
+										Count:                   cha_count,
5315
+										Price:                   warehouse.RetailPrice,
5316
+										Status:                  1,
5317
+										Ctime:                   item.AdviceDate,
5318
+										Mtime:                   time.Now().Unix(),
5319
+										UserOrgId:               item.UserOrgId,
5320
+										Manufacturer:            warehouse.Manufacturer,
5321
+										Dealer:                  warehouse.Dealer,
5322
+										BatchNumber:             warehouse.BatchNumber,
5323
+										MaxUnit:                 selfBasedrug.MinUnit,
5324
+										ConsumableType:          20,
5325
+										IsEdit:                  1,
5326
+										Creator:                 0,
5327
+										IsSys:                   3,
5328
+										WarehouseOutDetailId:    drugWareInfo.ID,
5329
+										AdviceId:                item.ID,
5330
+										SupplyWarehouseId:       warehouse.SupplyWarehouseId,
5331
+										StorehouseId:            0,
5332
+										AdminUserId:             creater,
5333
+										LastPrice:               warehouse.Price,
5334
+										StockCount:              "",
5335
+										WarehousingDetailId:     0,
5336
+										OverCount:               over_count,
5337
+										RetailPrice:             item.Price, //手动出库出库价格
5338
+										WarehousingId:           warehouse.ID,
5339
+										SystemTime:              item.AdviceDate,
5340
+										PatientId:               item.PatientId,
5341
+										Remark:                  "保存处方入库数据差",
5342
+										OperateTime:             time.Now().Unix(),
5343
+									}
5344
+									if warehouse.RetailPrice == 0 {
5345
+										drugflow.Price = item.Price
5346
+									}
5347
+									service.CreateSelfDrugFlowOne(drugflow, tx)
5348
+
5349
+									var out_count int64
5350
+									out_count = in_count - total_count
5351
+
5352
+									fmt.Println("in_count------------------", in_count)
5353
+									fmt.Println("total_count------------------", total_count)
5354
+									//添加出库数量
5355
+									service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
5356
+
5357
+									//查询剩余库存
5358
+									stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
5359
+									var sum_count int64
5360
+									for _, its := range stockInfo {
5361
+										if its.MaxUnit == selfBasedrug.MaxUnit {
5362
+											its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
5363
+										}
5364
+										sum_count += its.StockMaxNumber + its.StockMinNumber
5365
+									}
5366
+									service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
5367
+								} else {
5368
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
5369
+									return
5370
+								}
5371
+							}
5372
+						}
5373
+
5374
+					}
5375
+
5376
+				}
5377
+			}
5378
+
4943 5379
 		}
4944 5380
 		tx.Commit()
4945 5381
 		if err == nil {
@@ -5251,10 +5687,129 @@ func (c *HisApiController) CreateHisPrescription() {
5251 5687
 //}
5252 5688
 
5253 5689
 func (c *HisApiController) DeletePrescription() {
5690
+
5254 5691
 	prescription_id, _ := c.GetInt64("id")
5255 5692
 	projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
5256 5693
 	advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
5257
-	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
5694
+
5695
+	////同步到自备药
5696
+	selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
5697
+	var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
5698
+	if selfPrescriptionOpen.IsOpen == 1 {
5699
+		// 开始主事务
5700
+		db := service.XTWriteDB()
5701
+		tx := db.Begin()
5702
+
5703
+		// 在函数结束时处理事务回滚
5704
+		defer func() {
5705
+			if r := recover(); r != nil {
5706
+				tx.Rollback()
5707
+			}
5708
+		}()
5709
+		for _, item := range advices {
5710
+			selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
5711
+
5712
+			var total_count int64
5713
+			prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
5714
+			prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
5715
+
5716
+			if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5717
+				total_count += prescribingNumberSeven * selfBasedrug.MinNumber
5718
+			}
5719
+
5720
+			if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
5721
+				total_count += prescribingNumberSeven
5722
+			}
5723
+
5724
+			if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
5725
+				total_count += prescribingNumberSeven
5726
+			}
5727
+			//出库
5728
+			warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
5729
+				DrugId:           item.DrugId,
5730
+				Count:            total_count,
5731
+				Price:            0,
5732
+				TotalPrice:       0,
5733
+				Status:           1,
5734
+				Ctime:            item.AdviceDate,
5735
+				Mtime:            item.AdviceDate,
5736
+				Remark:           "",
5737
+				OrgId:            item.UserOrgId,
5738
+				Type:             0,
5739
+				Manufacturer:     selfBasedrug.Manufacturer,
5740
+				Dealer:           selfBasedrug.Dealer,
5741
+				RetailPrice:      0,
5742
+				RetailTotalPrice: 0,
5743
+				CountUnit:        item.PrescribingNumberUnit,
5744
+				ExpiryDate:       0,
5745
+				ProductDate:      0,
5746
+				Number:           "",
5747
+				BatchNumber:      "",
5748
+				IsSys:            0,
5749
+				WarehouseInfoId:  0,
5750
+				AdminUserId:      0,
5751
+				StockCount:       "",
5752
+				IsCheck:          2,
5753
+				SysRecordTime:    item.AdviceDate,
5754
+				PatientId:        item.PatientId,
5755
+				ClassType:        "",
5756
+			}
5757
+			warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
5758
+		}
5759
+
5760
+		for _, it := range warehousingOutInfo {
5761
+
5762
+			timeStr := time.Now().Format("2006-01-02")
5763
+			timeArr := strings.Split(timeStr, "-")
5764
+			total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
5765
+
5766
+			total = total + 1
5767
+			warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5768
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5769
+			number = number + total
5770
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
5771
+			operation_time := time.Now().Unix()
5772
+
5773
+			creater := c.GetAdminUserInfo().AdminUser.Id
5774
+			//创建一个出库单
5775
+			drugWarehouseOut := models.XtSelfDrugWarehouseOut{
5776
+				WarehouseOutOrderNumber: warehousing_out_order,
5777
+				OperationTime:           operation_time,
5778
+				OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
5779
+				Creater:                 creater,
5780
+				Ctime:                   time.Now().Unix(),
5781
+				Status:                  1,
5782
+				WarehouseOutTime:        it.SysRecordTime,
5783
+				Type:                    0,
5784
+				PatientId:               it.PatientId,
5785
+				IsCheck:                 2,
5786
+			}
5787
+
5788
+			//查询今日是否有出库数据
5789
+			lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx)
5790
+
5791
+			if lastWarehouseOut.ID == 0 {
5792
+				service.AddSelfSigleDrugWarehouseOut(&lastWarehouseOut, tx)
5793
+			}
5794
+
5795
+			medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5796
+			drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
5797
+			//出库逻辑
5798
+			service.AutoSelfDrugDeliverInfoFourtyOne(c.GetAdminUserInfo().CurrentOrgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
5799
+
5800
+			//查询剩余库存
5801
+			stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
5802
+			var sum_count int64
5803
+			for _, its := range stockInfo {
5804
+				if its.MaxUnit == medical.MaxUnit {
5805
+					its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
5806
+				}
5807
+				sum_count += its.StockMaxNumber + its.StockMinNumber
5808
+			}
5809
+			service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
5810
+		}
5811
+
5812
+	}
5258 5813
 
5259 5814
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
5260 5815
 
@@ -5267,11 +5822,9 @@ func (c *HisApiController) DeletePrescription() {
5267 5822
 	new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
5268 5823
 	new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
5269 5824
 
5270
-	//for _, item := range new_prescriptions {
5271 5825
 	if new_prescription.IsMedicine == 1 {
5272 5826
 		isMedicine = true
5273 5827
 	}
5274
-	//}
5275 5828
 
5276 5829
 	for _, item := range new_prescriptions {
5277 5830
 		if item.OrderStatus == 4 {
@@ -5810,8 +6363,123 @@ func (c *HisApiController) DeleteDoctorAdvice() {
5810 6363
 	id, _ := c.GetInt64("id")
5811 6364
 	advice, _ := service.GetHisDoctorAdvicesById(id)
5812 6365
 
5813
-	//_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
6366
+	////同步到自备药
6367
+	selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
6368
+	var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
6369
+	if selfPrescriptionOpen.IsOpen == 1 {
6370
+		// 开始主事务
6371
+		db := service.XTWriteDB()
6372
+		tx := db.Begin()
6373
+
6374
+		// 在函数结束时处理事务回滚
6375
+		defer func() {
6376
+			if r := recover(); r != nil {
6377
+				tx.Rollback()
6378
+			}
6379
+		}()
6380
+
6381
+		selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
5814 6382
 
6383
+		var total_count int64
6384
+		prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
6385
+		prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
6386
+
6387
+		if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
6388
+			total_count += prescribingNumberSeven * selfBasedrug.MinNumber
6389
+		}
6390
+
6391
+		if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
6392
+			total_count += prescribingNumberSeven
6393
+		}
6394
+
6395
+		if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
6396
+			total_count += prescribingNumberSeven
6397
+		}
6398
+		//出库
6399
+		warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
6400
+			DrugId:           advice.DrugId,
6401
+			Count:            total_count,
6402
+			Price:            0,
6403
+			TotalPrice:       0,
6404
+			Status:           1,
6405
+			Ctime:            advice.AdviceDate,
6406
+			Mtime:            advice.AdviceDate,
6407
+			Remark:           "",
6408
+			OrgId:            advice.UserOrgId,
6409
+			Type:             0,
6410
+			Manufacturer:     selfBasedrug.Manufacturer,
6411
+			Dealer:           selfBasedrug.Dealer,
6412
+			RetailPrice:      0,
6413
+			RetailTotalPrice: 0,
6414
+			CountUnit:        advice.PrescribingNumberUnit,
6415
+			ExpiryDate:       0,
6416
+			ProductDate:      0,
6417
+			Number:           "",
6418
+			BatchNumber:      "",
6419
+			IsSys:            0,
6420
+			WarehouseInfoId:  0,
6421
+			AdminUserId:      0,
6422
+			StockCount:       "",
6423
+			IsCheck:          2,
6424
+			SysRecordTime:    advice.AdviceDate,
6425
+			PatientId:        advice.PatientId,
6426
+			ClassType:        "",
6427
+		}
6428
+		warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
6429
+
6430
+		for _, it := range warehousingOutInfo {
6431
+
6432
+			timeStr := time.Now().Format("2006-01-02")
6433
+			timeArr := strings.Split(timeStr, "-")
6434
+			total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
6435
+
6436
+			total = total + 1
6437
+			warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
6438
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
6439
+			number = number + total
6440
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
6441
+			operation_time := time.Now().Unix()
6442
+
6443
+			creater := c.GetAdminUserInfo().AdminUser.Id
6444
+			//创建一个出库单
6445
+			drugWarehouseOut := models.XtSelfDrugWarehouseOut{
6446
+				WarehouseOutOrderNumber: warehousing_out_order,
6447
+				OperationTime:           operation_time,
6448
+				OrgId:                   c.GetAdminUserInfo().CurrentOrgId,
6449
+				Creater:                 creater,
6450
+				Ctime:                   time.Now().Unix(),
6451
+				Status:                  1,
6452
+				WarehouseOutTime:        it.SysRecordTime,
6453
+				Type:                    0,
6454
+				PatientId:               it.PatientId,
6455
+				IsCheck:                 2,
6456
+			}
6457
+
6458
+			//查询今日是否有出库数据
6459
+			lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx)
6460
+
6461
+			if lastWarehouseOut.ID == 0 {
6462
+				service.AddSelfSigleDrugWarehouseOut(&lastWarehouseOut, tx)
6463
+			}
6464
+
6465
+			medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
6466
+			drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
6467
+			//出库逻辑
6468
+			service.AutoSelfDrugDeliverInfoFourtyOne(c.GetAdminUserInfo().CurrentOrgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
6469
+
6470
+			//查询剩余库存
6471
+			stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
6472
+			var sum_count int64
6473
+			for _, its := range stockInfo {
6474
+				if its.MaxUnit == medical.MaxUnit {
6475
+					its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
6476
+				}
6477
+				sum_count += its.StockMaxNumber + its.StockMinNumber
6478
+			}
6479
+			service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
6480
+		}
6481
+
6482
+	}
5815 6483
 	drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
5816 6484
 
5817 6485
 	//已收费和已发药的限制逻辑

+ 4 - 0
controllers/manager_center_api_controller.go View File

@@ -164,6 +164,7 @@ func (c *ManagerCenterApiController) CreateBaseDrugLib() {
164 164
 	is_project, _ := c.GetInt64("is_project")
165 165
 	is_show, _ := c.GetInt64("is_show")
166 166
 	adminInfo := c.GetAdminUserInfo()
167
+	is_self_drug, _ := c.GetInt64("is_self_drug")
167 168
 
168 169
 	hans := drug_name // 要转换的汉字字符串
169 170
 
@@ -254,6 +255,7 @@ func (c *ManagerCenterApiController) CreateBaseDrugLib() {
254 255
 		Bck01b:                      "10",
255 256
 		IsProject:                   is_project,
256 257
 		IsShow:                      is_show,
258
+		IsSelfDrug:                  is_self_drug,
257 259
 	}
258 260
 	drugLib.FirstLetter = firstLetter
259 261
 	drugLib.Pinyin = firstLetter
@@ -366,6 +368,7 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
366 368
 	bby01 := c.GetString("bby01")
367 369
 	is_project, _ := c.GetInt64("is_project")
368 370
 	is_show, _ := c.GetInt64("is_show")
371
+	is_self_drug, _ := c.GetInt64("is_self_drug")
369 372
 	adminInfo := c.GetAdminUserInfo()
370 373
 	drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, id)
371 374
 
@@ -461,6 +464,7 @@ func (c *ManagerCenterApiController) EditBaseDrugLib() {
461 464
 		IsProject:                   is_project,
462 465
 		FirstLetter:                 firstLetter,
463 466
 		IsShow:                      is_show,
467
+		IsSelfDrug:                  is_self_drug,
464 468
 	}
465 469
 	if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
466 470
 

+ 48 - 0
controllers/mobile_api_controllers/check_weight_api_controller.go View File

@@ -1036,6 +1036,54 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
1036 1036
 			afterevaluation.PulseFrequency = 80
1037 1037
 		}
1038 1038
 
1039
+		if adminUserInfo.Org.Id == 10693 {
1040
+
1041
+			afterevaluation.ActualUltrafiltration = assessmentAfterDislysis.ActualUltrafiltration
1042
+
1043
+			afterevaluation.SystolicBloodPressure = assessmentAfterDislysis.SystolicBloodPressure
1044
+
1045
+			afterevaluation.DiastolicBloodPressure = assessmentAfterDislysis.DiastolicBloodPressure
1046
+
1047
+			afterevaluation.PulseFrequency = assessmentAfterDislysis.PulseFrequency
1048
+
1049
+			if afterevaluation.ActualUltrafiltration == 0 {
1050
+
1051
+				lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, theAssessmentDateTime)
1052
+
1053
+				UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
1054
+				afterevaluation.ActualUltrafiltration = UltrafiltrationVolumeOne
1055
+
1056
+			}
1057
+
1058
+			if afterevaluation.SystolicBloodPressure == 0 {
1059
+				lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
1060
+
1061
+				systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
1062
+
1063
+				afterevaluation.SystolicBloodPressure = systolicBloodPressureOne
1064
+			}
1065
+
1066
+			if afterevaluation.DiastolicBloodPressure == 0 {
1067
+
1068
+				lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, theAssessmentDateTime)
1069
+				MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
1070
+				afterevaluation.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
1071
+			}
1072
+
1073
+			if afterevaluation.PulseFrequency == 0 {
1074
+				lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, theAssessmentDateTime)
1075
+				PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
1076
+				afterevaluation.PulseFrequency = PulseFrequencyOne
1077
+			}
1078
+
1079
+			if afterevaluation.ActualDisplacement == 0 {
1080
+
1081
+				lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, theAssessmentDateTime)
1082
+				DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
1083
+				afterevaluation.ActualDisplacement = DisplacementQuantityOne
1084
+			}
1085
+		}
1086
+
1039 1087
 		err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
1040 1088
 
1041 1089
 		//记录日志

+ 83 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -1609,6 +1609,47 @@ func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
1609 1609
 			}
1610 1610
 		}
1611 1611
 
1612
+		//孝康
1613
+		//孝康
1614
+		if adminUserInfo.Org.Id == 10693 {
1615
+
1616
+			if assessmentAfterDislysis.ActualUltrafiltration == 0 {
1617
+
1618
+				lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1619
+
1620
+				UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
1621
+
1622
+				assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
1623
+
1624
+			}
1625
+
1626
+			if assessmentAfterDislysis.SystolicBloodPressure == 0 {
1627
+				lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1628
+				systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
1629
+				assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
1630
+			}
1631
+
1632
+			if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
1633
+
1634
+				lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1635
+				MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
1636
+				assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
1637
+			}
1638
+
1639
+			if assessmentAfterDislysis.PulseFrequency == 0 {
1640
+				lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1641
+				PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
1642
+				assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
1643
+			}
1644
+
1645
+			if assessmentAfterDislysis.ActualDisplacement == 0 {
1646
+
1647
+				lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1648
+				DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
1649
+				assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
1650
+			}
1651
+		}
1652
+
1612 1653
 		err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
1613 1654
 
1614 1655
 		//记录日志
@@ -1701,6 +1742,48 @@ func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
1701 1742
 				assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
1702 1743
 			}
1703 1744
 		}
1745
+
1746
+		//孝康
1747
+		if adminUserInfo.Org.Id == 10693 {
1748
+
1749
+			fmt.Println("adminUserInfo.Org.Id", assessmentAfterDislysis.ActualUltrafiltration)
1750
+			if assessmentAfterDislysis.ActualUltrafiltration == 0 {
1751
+
1752
+				lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1753
+
1754
+				UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
1755
+
1756
+				assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
1757
+
1758
+			}
1759
+
1760
+			if assessmentAfterDislysis.SystolicBloodPressure == 0 {
1761
+				lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1762
+				systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
1763
+				assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
1764
+			}
1765
+
1766
+			if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
1767
+
1768
+				lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1769
+				MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
1770
+				assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
1771
+			}
1772
+
1773
+			if assessmentAfterDislysis.PulseFrequency == 0 {
1774
+				lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1775
+				PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
1776
+				assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
1777
+			}
1778
+
1779
+			if assessmentAfterDislysis.ActualDisplacement == 0 {
1780
+
1781
+				lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
1782
+				DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
1783
+				assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
1784
+			}
1785
+		}
1786
+
1704 1787
 		err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
1705 1788
 
1706 1789
 		//记录日志

+ 1 - 1
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go View File

@@ -2996,7 +2996,7 @@ func (this *NewDialysisApiController) GetInspectionGroup() {
2996 2996
 
2997 2997
 	patient, _ := service.GetPatientDetailTwo(patient_id)
2998 2998
 	inspection, _ := service.GetInspectionGroup(patient.BloodId, org_id)
2999
-	fmt.Println("inspection+++++++++=============", inspection)
2999
+
3000 3000
 	if len(inspection) > 0 {
3001 3001
 		for _, item := range inspection {
3002 3002
 			lastInspection, _ := service.GetLastInspectionProject(item.PatientId, org_id, item.ProjectId)

+ 8 - 0
controllers/patient_api_controller.go View File

@@ -1745,6 +1745,14 @@ func (c *PatientApiController) CreateGroupAdvice() {
1745 1745
 
1746 1746
 		}
1747 1747
 
1748
+		//针对康桥
1749
+		if adminUserInfo.CurrentOrgId == 10702 {
1750
+			if adviceType == 3 {
1751
+				adviceType = 2
1752
+			}
1753
+
1754
+		}
1755
+
1748 1756
 		if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
1749 1757
 			executionFrequency, _ := adviceNameM["execution_frequency"].(string)
1750 1758
 			advice.ExecutionFrequency = executionFrequency

+ 1 - 1
controllers/schedule_api_controller.go View File

@@ -4800,7 +4800,7 @@ func (c *ScheduleApiController) GetScheduleOne() {
4800 4800
 	schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
4801 4801
 	timenow := time.Now().Format("2006-01-02")
4802 4802
 	timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timenow)
4803
-	if adminInfo.CurrentOrgId == 10346 || adminInfo.CurrentOrgId == 10585 {
4803
+	if adminInfo.CurrentOrgId == 10346 || adminInfo.CurrentOrgId == 10585 || adminInfo.CurrentOrgId == 10495 {
4804 4804
 
4805 4805
 		if len(schdules) > 0 {
4806 4806
 			//获取长期医嘱里面的透析器灌流器

+ 544 - 37
controllers/self_drug_api_congtroller.go View File

@@ -149,6 +149,8 @@ func SelfDrugRouters() {
149 149
 
150 150
 	beego.Router("/api/drug/tocheckselfwarehouseinginfo", &SelfDrugApiController{}, "Get:TocheckSelfWarehouseingInfo")
151 151
 
152
+	beego.Router("/api/drug/returnselfcheckwarehouse", &SelfDrugApiController{}, "Get:ReturnSelfCheckWarehouse")
153
+
152 154
 	beego.Router("/api/drug/getselfdrugbatchnumber", &SelfDrugApiController{}, "Get:GetSelfDrugBatchNumber")
153 155
 
154 156
 	beego.Router("/api/drug/postsetfdrugwarehouseout", &SelfDrugApiController{}, "Post:PostSelfDrugWarehouseOut")
@@ -162,6 +164,22 @@ func SelfDrugRouters() {
162 164
 	beego.Router("/api/drug/modifyselfdrugwarehouseout", &SelfDrugApiController{}, "Post:ModifySelfDrugWarehouseOut")
163 165
 
164 166
 	beego.Router("/api/drug/getselfdrugquery", &SelfDrugApiController{}, "Get:GetSelfDrugQuery")
167
+
168
+	beego.Router("/api/drug/checkselfdrugoutquery", &SelfDrugApiController{}, "Get:CheckSelfDrugOutQuery")
169
+
170
+	beego.Router("/api/drug/returncheckselfoutdrugquery", &SelfDrugApiController{}, "Get:ReturnCheckSelfOutDrugQuery")
171
+
172
+	beego.Router("/api/drug/getselfdrugflow", &SelfDrugApiController{}, "Get:GetSelfDrugFlow")
173
+
174
+	beego.Router("/api/drug/getselfdrugbatchnumberlist", &SelfDrugApiController{}, "Get:GetSelfDrugBatchNumberList")
175
+
176
+	beego.Router("/api/drug/getallselfdrugwarehouse", &SelfDrugApiController{}, "Get:GetAllSelfDrugWarehouse")
177
+
178
+	beego.Router("/api/drug/deleteselfwarehouse", &SelfDrugApiController{}, "Get:DeleteSelfWarehouse")
179
+
180
+	beego.Router("/api/drug/getallselfdrugwarehouseout", &SelfDrugApiController{}, "Get:GetAllSelfDrugWarehouseOut")
181
+
182
+	beego.Router("/api/drug/deleteselfwarehouseoutlist", &SelfDrugApiController{}, "Get:DeleteSelfWarehouseOutList")
165 183
 }
166 184
 
167 185
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -4760,7 +4778,6 @@ func (c *SelfDrugApiController) GetSelfDrugWarehouseInfoByID() {
4760 4778
 
4761 4779
 	id, _ := c.GetInt64("id")
4762 4780
 	info, _ := service.GetSelfDrugWarehouseInfoByID(id)
4763
-
4764 4781
 	warehouseInfo, _ := service.GetSelfDrugWarehouseInfo(info.WarehousingId)
4765 4782
 	orgId := c.GetAdminUserInfo().CurrentOrgId
4766 4783
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
@@ -4784,7 +4801,6 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouse() {
4784 4801
 	warehousing_time := c.GetString("warehousing_time")
4785 4802
 	warehousing_id, _ := c.GetInt64("warehousing_id")
4786 4803
 	adminUserInfo := c.GetAdminUserInfo()
4787
-
4788 4804
 	warehousingDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", warehousing_time)
4789 4805
 
4790 4806
 	if parseDateErr != nil {
@@ -4809,31 +4825,8 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouse() {
4809 4825
 	total, _ := service.FindSelfAllWarehouseTotal(adminUserInfo.CurrentOrgId, tx)
4810 4826
 	total = total + 1
4811 4827
 
4812
-	//operation_time := time.Now().Unix()
4813
-	//creater := adminUserInfo.AdminUser.Id
4814
-
4815 4828
 	warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
4816 4829
 
4817
-	//warehousing := models.XtSelfDrugWarehouse{
4818
-	//	ID:               warehousing_id,
4819
-	//	WarehousingOrder: warehousing_order,
4820
-	//	OperationTime:    operation_time,
4821
-	//	OrgId:            adminUserInfo.CurrentOrgId,
4822
-	//	Creater:          creater,
4823
-	//	Ctime:            time.Now().Unix(),
4824
-	//	Status:           1,
4825
-	//	WarehousingTime:  warehousingDate.Unix(),
4826
-	//	Type:             0,
4827
-	//	StorehouseId:     0,
4828
-	//	IsCheck:          2,
4829
-	//	PatientId:        patient_id,
4830
-	//}
4831
-	//if warehousing_id == 0 {
4832
-	//	service.AddSelfDrugWarehouse(&warehousing, tx)
4833
-	//}
4834
-	//if warehousing_id > 0 {
4835
-	//	service.UpdateSelfDrugWarehouse(&warehousing, tx)
4836
-	//}
4837 4830
 	info, _ := service.FindLastSelfWarehousing(adminUserInfo.CurrentOrgId, patient_id, tx)
4838 4831
 	dataBody := make(map[string]interface{}, 0)
4839 4832
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -5017,9 +5010,9 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5017 5010
 
5018 5011
 	id, _ := c.GetInt64("warehousing_id")
5019 5012
 	patient_id, _ := c.GetInt64("patient_id")
5020
-	orgId := c.GetAdminUserInfo().CurrentOrgId
5021
-	info, _ := service.GetSelfWarehouseInfoByWarehouseInfo(id, patient_id, orgId)
5022 5013
 
5014
+	orgId := c.GetAdminUserInfo().CurrentOrgId
5015
+	checker := c.GetAdminUserInfo().AdminUser.Id
5023 5016
 	db := service.XTWriteDB()
5024 5017
 	tx := db.Begin()
5025 5018
 	defer func() {
@@ -5029,16 +5022,21 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5029 5022
 			tx.Commit()
5030 5023
 		}
5031 5024
 	}()
5025
+	//更改核对状态
5026
+	service.CheckSelfWarehousingInfo(id, orgId, checker, tx)
5027
+	info, _ := service.GetSelfWarehouseInfoByWarehouseInfo(id, patient_id, orgId, tx)
5032 5028
 	if len(info) > 0 {
5033 5029
 		for _, item := range info {
5034
-			medical, _ := service.GetBaseDrugMedical(item.DrugId)
5030
+			medical, _ := service.GetSelfBaseDrugMedical(item.DrugId, tx)
5035 5031
 
5036 5032
 			if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5033
+
5037 5034
 				//新增库存
5038 5035
 				service.AddSelfDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
5039 5036
 
5040 5037
 			}
5041 5038
 			if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
5039
+
5042 5040
 				//新增库存
5043 5041
 				service.AddSelfDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
5044 5042
 
@@ -5058,7 +5056,7 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5058 5056
 			var sum_count int64
5059 5057
 			var sum_in_count int64
5060 5058
 			for _, it := range list {
5061
-				baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
5059
+				baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5062 5060
 				if it.MaxUnit == baseDrug.MaxUnit {
5063 5061
 					it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
5064 5062
 					it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
@@ -5068,7 +5066,7 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5068 5066
 			}
5069 5067
 
5070 5068
 			flow := &models.XtSelfDrugFlow{
5071
-				WarehousingId:           0,
5069
+				WarehousingId:           id,
5072 5070
 				DrugId:                  item.DrugId,
5073 5071
 				Number:                  item.Number,
5074 5072
 				BatchNumber:             item.BatchNumber,
@@ -5084,8 +5082,8 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5084 5082
 				IsEdit:                  0,
5085 5083
 				CancelStockId:           0,
5086 5084
 				CancelOrderNumber:       "",
5087
-				Manufacturer:            0,
5088
-				Dealer:                  0,
5085
+				Manufacturer:            item.Manufacturer,
5086
+				Dealer:                  item.Dealer,
5089 5087
 				Creator:                 Creator,
5090 5088
 				UpdateCreator:           Creator,
5091 5089
 				Status:                  1,
@@ -5106,10 +5104,11 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5106 5104
 			service.CreateSelfDrugFlow(flow, tx)
5107 5105
 
5108 5106
 			drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.OrgId, item.DrugId, tx)
5107
+
5109 5108
 			var total_count int64 // 入库总数量
5110 5109
 			var over_count int64  //剩余库存
5111 5110
 			for _, it := range drugInfolist {
5112
-				baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
5111
+				baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5113 5112
 				if it.MaxUnit == baseDrug.MaxUnit {
5114 5113
 					it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
5115 5114
 					it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
@@ -5120,8 +5119,9 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5120 5119
 				over_count += it.StockMaxNumber + it.StockMinNumber
5121 5120
 			}
5122 5121
 			//查询该仓库是否有默认数据
5123
-			_, errcode := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.OrgId, tx)
5124
-			if errcode == gorm.ErrRecordNotFound {
5122
+			selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.OrgId, tx)
5123
+
5124
+			if selfDrugStock.ID == 0 {
5125 5125
 				drugStock := models.XtSelfDrugStockCount{
5126 5126
 					UserOrgId:      item.OrgId,
5127 5127
 					PatientId:      item.PatientId,
@@ -5137,7 +5137,8 @@ func (c *SelfDrugApiController) TocheckSelfWarehouseingInfo() {
5137 5137
 				}
5138 5138
 				service.CreateSelfDrugStockSum(drugStock, tx)
5139 5139
 
5140
-			} else if errcode == nil {
5140
+			}
5141
+			if selfDrugStock.ID > 0 {
5141 5142
 				service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.OrgId, total_count, over_count, tx)
5142 5143
 			}
5143 5144
 
@@ -5665,7 +5666,513 @@ func (c *SelfDrugApiController) ModifySelfDrugWarehouseOut() {
5665 5666
 
5666 5667
 func (c *SelfDrugApiController) GetSelfDrugQuery() {
5667 5668
 
5669
+	keyword := c.GetString("keyword")
5670
+	limit, _ := c.GetInt64("limit")
5671
+	page, _ := c.GetInt64("page")
5672
+	var goodIds []int64
5673
+	org_id := c.GetAdminUserInfo().CurrentOrgId
5674
+	drugList, _ := service.GetDrugNameByword(org_id, keyword)
5668 5675
 	orgId := c.GetAdminUserInfo().CurrentOrgId
5676
+	for _, it := range drugList {
5677
+		goodIds = append(goodIds, it.ID)
5678
+	}
5679
+	list, total, _ := service.GetSelfDrugQuery(orgId, goodIds, limit, page)
5680
+	var drugType = "药品类型"
5681
+	drugTypeParent, _ := service.GetDrugDataConfig(0, drugType)
5682
+	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, org_id)
5683
+	manufacturerList, _ := service.GetAllManufacturerList(orgId)
5684
+	dealerList, _ := service.GetAllDealerList(orgId)
5685
+	c.ServeSuccessJSON(map[string]interface{}{
5686
+		"list":             list,
5687
+		"total":            total,
5688
+		"manufacturerList": manufacturerList,
5689
+		"dealerList":       dealerList,
5690
+		"drugTypeList":     drugTypeList,
5691
+	})
5692
+	return
5693
+}
5669 5694
 
5670
-	service.GetSelfDrugQuery(orgId)
5695
+func (c *SelfDrugApiController) CheckSelfDrugOutQuery() {
5696
+
5697
+	db := service.XTWriteDB()
5698
+	tx := db.Begin()
5699
+	defer func() {
5700
+		if r := recover(); r != nil {
5701
+			tx.Rollback()
5702
+		} else {
5703
+			tx.Commit()
5704
+		}
5705
+	}()
5706
+	warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
5707
+
5708
+	patient_id, _ := c.GetInt64("patient_id")
5709
+
5710
+	orgId := c.GetAdminUserInfo().CurrentOrgId
5711
+	warehousingOutInfoList, _ := service.GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id, orgId, tx)
5712
+	drugWarehouseOut, _ := service.GetSelfDrugWarehouseOutByLastId(warehouse_out_id, tx)
5713
+
5714
+	for _, it := range warehousingOutInfoList {
5715
+		var total_count int64
5716
+		var out_count int64
5717
+		//查询剩余库存
5718
+		stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
5719
+		drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
5720
+
5721
+		for _, item := range stockInfo {
5722
+			if item.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
5723
+				item.StockMaxNumber = item.StockMaxNumber * drup.MinNumber
5724
+			}
5725
+
5726
+			total_count += item.StockMaxNumber + item.StockMinNumber
5727
+		}
5728
+
5729
+		//出库数量累加
5730
+		if it.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
5731
+			out_count = it.Count * drup.MinNumber
5732
+		}
5733
+
5734
+		if it.CountUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
5735
+			out_count = it.Count
5736
+		}
5737
+
5738
+		if it.CountUnit == drup.MinUnit && drup.MaxUnit == drup.MinUnit {
5739
+			out_count = it.Count
5740
+		}
5741
+
5742
+		if out_count > total_count {
5743
+			c.ServeSuccessJSON(map[string]interface{}{
5744
+				"warehousingOutInfoList": warehousingOutInfoList,
5745
+				"drug_name":              drup.DrugName,
5746
+				"dose":                   drup.Dose,
5747
+				"dose_unit":              drup.DoseUnit,
5748
+				"min_number":             drup.MinNumber,
5749
+				"min_unit":               drup.MinUnit,
5750
+				"max_unit":               drup.MaxUnit,
5751
+				"msg":                    2,
5752
+			})
5753
+			return
5754
+		}
5755
+	}
5756
+	warehousingOutInfoListTwo, _ := service.GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id, orgId, tx)
5757
+
5758
+	for _, it := range warehousingOutInfoListTwo {
5759
+		medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5760
+		////出库数量累加
5761
+		var out_count_one int64
5762
+
5763
+		if it.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5764
+			out_count_one = it.Count * medical.MinNumber
5765
+		}
5766
+
5767
+		if it.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
5768
+			out_count_one = it.Count
5769
+		}
5770
+
5771
+		if it.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
5772
+			out_count_one = it.Count
5773
+		}
5774
+		service.AddSelfDrugCount(it.DrugId, it.OrgId, patient_id, out_count_one, tx)
5775
+
5776
+	}
5777
+	warehousingOutInfoListThree, _ := service.GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id, orgId, tx)
5778
+	for _, it := range warehousingOutInfoListThree {
5779
+		medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5780
+		drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
5781
+		//出库逻辑
5782
+		service.AutoSelfDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
5783
+
5784
+		//查询剩余库存
5785
+		stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
5786
+		var sum_count int64
5787
+		for _, its := range stockInfo {
5788
+			if its.MaxUnit == medical.MaxUnit {
5789
+				its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
5790
+			}
5791
+			sum_count += its.StockMaxNumber + its.StockMinNumber
5792
+		}
5793
+		service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
5794
+	}
5795
+
5796
+	out := models.XtSelfDrugWarehouseOut{
5797
+		IsCheck: 1,
5798
+	}
5799
+	//更新审核状态
5800
+	service.UpdateSelfCheckDrugOut(out, warehouse_out_id, tx)
5801
+
5802
+	c.ServeSuccessJSON(map[string]interface{}{
5803
+		"warehousingOutInfoList": warehousingOutInfoList,
5804
+		"drug_name":              "",
5805
+		"dose":                   "",
5806
+		"dose_unit":              "",
5807
+		"min_number":             "",
5808
+		"min_unit":               "",
5809
+		"max_unit":               "",
5810
+		"msg":                    1,
5811
+	})
5812
+}
5813
+
5814
+func (c *SelfDrugApiController) ReturnCheckSelfOutDrugQuery() {
5815
+
5816
+	db := service.XTWriteDB()
5817
+	tx := db.Begin()
5818
+	defer func() {
5819
+		if r := recover(); r != nil {
5820
+			tx.Rollback()
5821
+		} else {
5822
+			tx.Commit()
5823
+		}
5824
+	}()
5825
+
5826
+	warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
5827
+
5828
+	out := models.XtSelfDrugWarehouseOut{
5829
+		IsCheck: 2,
5830
+	}
5831
+	service.UpdateSelfCheckDrugOut(out, warehouse_out_id, tx)
5832
+
5833
+	outInfo := models.XtSelfDrugWarehouseOutInfo{
5834
+		IsCheck: 2,
5835
+	}
5836
+	service.UpdateSelfCheckDrugOutInfoList(outInfo, warehouse_out_id, tx)
5837
+
5838
+	orgId := c.GetAdminUserInfo().CurrentOrgId
5839
+	list, _ := service.GetSelfDrugWarehouseOutListById(warehouse_out_id, orgId, tx)
5840
+
5841
+	//调用出库逻辑
5842
+	for _, item := range list {
5843
+		medical, _ := service.GetSelfBaseDrugMedical(item.DrugId, tx)
5844
+		if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5845
+			service.UpdateSelfDrugMaxNumber(item.Count, item.WarehouseInfoId, tx)
5846
+			drugInfoList, _ := service.FindSelfDrugWarehouseInfoList(item.DrugId, item.OrgId, tx)
5847
+			var drug_max_number int64
5848
+			var drug_min_number int64
5849
+			for _, item := range drugInfoList {
5850
+				drug_max_number += item.StockMaxNumber
5851
+				drug_min_number += item.StockMinNumber
5852
+			}
5853
+		}
5854
+		if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
5855
+			service.UpdateSelfDrugMaxNumber(item.Count, item.WarehouseInfoId, tx)
5856
+
5857
+			service.DeleteSelfDrugOutFlow(item.ID, item.OrgId, tx)
5858
+		}
5859
+		if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
5860
+
5861
+			service.UpdateSelfDrugMinNumber(item.Count, item.WarehouseInfoId, tx)
5862
+
5863
+			service.DeleteSelfDrugOutFlow(item.ID, item.OrgId, tx)
5864
+		}
5865
+
5866
+		//出库数量累加
5867
+		var out_count int64
5868
+		if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5869
+			out_count = item.Count * medical.MinNumber
5870
+		}
5871
+
5872
+		if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
5873
+			out_count = item.Count
5874
+		}
5875
+
5876
+		if item.CountUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5877
+			out_count = item.Count
5878
+		}
5879
+		//增加出库数量
5880
+		service.ReduceSelfDrugCount(item.DrugId, item.OrgId, item.PatientId, out_count, tx)
5881
+
5882
+		//查询该药品剩余库存
5883
+		infolist, _ := service.FindSelfDrugWarehouseInfoFlushCountByStorehouse(item.DrugId, item.OrgId, item.PatientId, tx)
5884
+		var over_count int64
5885
+		for _, its := range infolist {
5886
+			baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
5887
+
5888
+			if its.MaxUnit == baseDrug.MaxUnit {
5889
+				its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
5890
+			}
5891
+			over_count += its.StockMaxNumber + its.StockMinNumber
5892
+		}
5893
+
5894
+		service.UpdateSelfDrugStockCount(item.DrugId, item.OrgId, item.PatientId, over_count, tx)
5895
+
5896
+	}
5897
+	c.ServeSuccessJSON(map[string]interface{}{
5898
+		"out": out,
5899
+	})
5900
+}
5901
+
5902
+func (c *SelfDrugApiController) ReturnSelfCheckWarehouse() {
5903
+
5904
+	db := service.XTWriteDB()
5905
+	tx := db.Begin()
5906
+	defer func() {
5907
+		if r := recover(); r != nil {
5908
+			tx.Rollback()
5909
+		} else {
5910
+			tx.Commit()
5911
+		}
5912
+	}()
5913
+
5914
+	warehousing_id, _ := c.GetInt64("warehousing_id")
5915
+	patient_id, _ := c.GetInt64("patient_id")
5916
+	orgId := c.GetAdminUserInfo().CurrentOrgId
5917
+
5918
+	list, _ := service.GetSelfWarehousingInfoByList(warehousing_id, orgId, tx)
5919
+	for _, item := range list {
5920
+		//查询该药品是否有出库数据
5921
+		outInfo, _ := service.GetSelfDrugWarehouseOutByWarehouseInfoId(item.ID, item.DrugId, item.OrgId, tx)
5922
+		if len(outInfo) > 0 {
5923
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCheckGoodParamWrong)
5924
+			return
5925
+		}
5926
+
5927
+	}
5928
+	for _, item := range list {
5929
+		//删除流水
5930
+		service.UpdateSelfWarehousingInfoFlow(item.ID, orgId, tx)
5931
+		medical, _ := service.GetSelfBaseDrugMedical(item.DrugId, tx)
5932
+		if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5933
+			//新增库存
5934
+			service.AddSelfDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
5935
+		}
5936
+		if item.MaxUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
5937
+			//新增库存
5938
+			service.AddSelfDrugReturnWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
5939
+		}
5940
+		if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
5941
+			//新增库存
5942
+			service.AddSelfDrugReturnWarehouseStockMinNumber(item.WarehousingCount, item.ID, tx)
5943
+		}
5944
+
5945
+		var total_count int64
5946
+		if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5947
+			total_count = item.WarehousingCount * medical.MinNumber
5948
+		}
5949
+		if item.MaxUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
5950
+			total_count = item.WarehousingCount
5951
+		}
5952
+		if item.MaxUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
5953
+			total_count = item.WarehousingCount * medical.MinNumber
5954
+		}
5955
+		drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(patient_id, item.OrgId, item.DrugId, tx)
5956
+		var over_count int64 //剩余库存
5957
+		for _, it := range drugInfolist {
5958
+			if it.MaxUnit == medical.MaxUnit {
5959
+				it.StockMaxNumber = it.StockMaxNumber * medical.MinNumber
5960
+			}
5961
+		}
5962
+		for _, it := range drugInfolist {
5963
+			over_count += it.StockMaxNumber*medical.MinNumber + it.StockMinNumber
5964
+		}
5965
+		//扣减库存
5966
+		service.ReduceSelfDrugStockCount(patient_id, item.DrugId, item.OrgId, total_count, over_count, tx)
5967
+
5968
+	}
5969
+	//更新审核
5970
+	err := service.ReturnSelfCheckWarehouseingInfo(warehousing_id, orgId, tx)
5971
+
5972
+	if err == nil {
5973
+		c.ServeSuccessJSON(map[string]interface{}{
5974
+			"msg": "反审核成功!",
5975
+		})
5976
+		return
5977
+	}
5978
+}
5979
+
5980
+func (c *SelfDrugApiController) GetSelfDrugFlow() {
5981
+
5982
+	drug_id, _ := c.GetInt64("drug_id")
5983
+	start_time := c.GetString("start_time")
5984
+	end_time := c.GetString("end_time")
5985
+	orgId := c.GetAdminUserInfo().CurrentOrgId
5986
+	page, _ := c.GetInt64("page")
5987
+	limit, _ := c.GetInt64("limit")
5988
+	timeLayout := "2006-01-02"
5989
+	loc, _ := time.LoadLocation("Local")
5990
+	var startTime int64
5991
+	if len(start_time) > 0 {
5992
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
5993
+		if err != nil {
5994
+			fmt.Println(err)
5995
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
5996
+			return
5997
+		}
5998
+		startTime = theTime.Unix()
5999
+	}
6000
+	var endTime int64
6001
+	if len(end_time) > 0 {
6002
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
6003
+		if err != nil {
6004
+			utils.ErrorLog(err.Error())
6005
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6006
+			return
6007
+		}
6008
+		endTime = theTime.Unix()
6009
+	}
6010
+	list, total, _ := service.GetSelfDrugFlow(drug_id, startTime, endTime, orgId, page, limit)
6011
+	drug, _ := service.GetSelfBasedrugById(drug_id, orgId)
6012
+	patients, _ := service.GetAllpatient(orgId)
6013
+	c.ServeSuccessJSON(map[string]interface{}{
6014
+		"list":     list,
6015
+		"total":    total,
6016
+		"drug":     drug,
6017
+		"patients": patients,
6018
+	})
6019
+}
6020
+
6021
+func (c *SelfDrugApiController) GetSelfDrugBatchNumberList() {
6022
+
6023
+	drug_id, _ := c.GetInt64("drug_id")
6024
+	start_time := c.GetString("start_time")
6025
+	end_time := c.GetString("end_time")
6026
+	orgId := c.GetAdminUserInfo().CurrentOrgId
6027
+	page, _ := c.GetInt64("page")
6028
+	limit, _ := c.GetInt64("limit")
6029
+	timeLayout := "2006-01-02"
6030
+	loc, _ := time.LoadLocation("Local")
6031
+	var startTime int64
6032
+	if len(start_time) > 0 {
6033
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6034
+		if err != nil {
6035
+			fmt.Println(err)
6036
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6037
+			return
6038
+		}
6039
+		startTime = theTime.Unix()
6040
+	}
6041
+	var endTime int64
6042
+	if len(end_time) > 0 {
6043
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
6044
+		if err != nil {
6045
+			utils.ErrorLog(err.Error())
6046
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6047
+			return
6048
+		}
6049
+		endTime = theTime.Unix()
6050
+	}
6051
+
6052
+	list, total, _ := service.GetSelfDrugBatchNumberList(drug_id, startTime, endTime, orgId, page, limit)
6053
+	drug, _ := service.GetSelfBasedrugById(drug_id, orgId)
6054
+	c.ServeSuccessJSON(map[string]interface{}{
6055
+		"list":  list,
6056
+		"total": total,
6057
+		"drug":  drug,
6058
+	})
6059
+}
6060
+
6061
+func (c *SelfDrugApiController) GetAllSelfDrugWarehouse() {
6062
+
6063
+	keyword := c.GetString("keyword")
6064
+
6065
+	start_time := c.GetString("start_time")
6066
+
6067
+	end_time := c.GetString("end_time")
6068
+
6069
+	patient_id, _ := c.GetInt64("patient_id")
6070
+
6071
+	timeLayout := "2006-01-02"
6072
+	loc, _ := time.LoadLocation("Local")
6073
+	var startTime int64
6074
+	if len(start_time) > 0 {
6075
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6076
+		if err != nil {
6077
+			fmt.Println(err)
6078
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6079
+			return
6080
+		}
6081
+		startTime = theTime.Unix()
6082
+	}
6083
+	var endTime int64
6084
+	if len(end_time) > 0 {
6085
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
6086
+		if err != nil {
6087
+			utils.ErrorLog(err.Error())
6088
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6089
+			return
6090
+		}
6091
+		endTime = theTime.Unix()
6092
+	}
6093
+
6094
+	check_type, _ := c.GetInt64("check_type")
6095
+
6096
+	limit, _ := c.GetInt64("limit")
6097
+
6098
+	page, _ := c.GetInt64("page")
6099
+
6100
+	orgId := c.GetAdminUserInfo().CurrentOrgId
6101
+
6102
+	appId := c.GetAdminUserInfo().CurrentAppId
6103
+
6104
+	list, total, _ := service.GetAllSelfDrugWarehouse(keyword, startTime, endTime, check_type, orgId, page, limit, patient_id)
6105
+
6106
+	doctorList, _ := service.GetAllDoctorList(orgId, appId)
6107
+
6108
+	c.ServeSuccessJSON(map[string]interface{}{
6109
+		"list":       list,
6110
+		"total":      total,
6111
+		"doctorList": doctorList,
6112
+	})
6113
+}
6114
+
6115
+func (c *SelfDrugApiController) DeleteSelfWarehouse() {
6116
+
6117
+	id, _ := c.GetInt64("id")
6118
+
6119
+	service.DeleteSelfWarehouse(id)
6120
+
6121
+	c.ServeSuccessJSON(map[string]interface{}{
6122
+		"ok": "msg",
6123
+	})
6124
+}
6125
+
6126
+func (c *SelfDrugApiController) GetAllSelfDrugWarehouseOut() {
6127
+
6128
+	start_time := c.GetString("start_time")
6129
+	end_time := c.GetString("end_time")
6130
+	keyword := c.GetString("keyword")
6131
+	orgId := c.GetAdminUserInfo().CurrentOrgId
6132
+	appId := c.GetAdminUserInfo().CurrentAppId
6133
+	page, _ := c.GetInt64("page")
6134
+	limit, _ := c.GetInt64("limit")
6135
+	patient_id, _ := c.GetInt64("patient_id")
6136
+	timeLayout := "2006-01-02"
6137
+	loc, _ := time.LoadLocation("Local")
6138
+	var startTime int64
6139
+	if len(start_time) > 0 {
6140
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6141
+		if err != nil {
6142
+			fmt.Println(err)
6143
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6144
+			return
6145
+		}
6146
+		startTime = theTime.Unix()
6147
+	}
6148
+	var endTime int64
6149
+	if len(end_time) > 0 {
6150
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
6151
+		if err != nil {
6152
+			utils.ErrorLog(err.Error())
6153
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6154
+			return
6155
+		}
6156
+		endTime = theTime.Unix()
6157
+	}
6158
+
6159
+	list, total, _ := service.GetAllSelfDrugWarehouseOut(startTime, endTime, orgId, page, limit, patient_id, keyword)
6160
+	doctorList, _ := service.GetAllDoctorList(orgId, appId)
6161
+	c.ServeSuccessJSON(map[string]interface{}{
6162
+		"list":       list,
6163
+		"total":      total,
6164
+		"doctorList": doctorList,
6165
+	})
6166
+
6167
+}
6168
+
6169
+func (c *SelfDrugApiController) DeleteSelfWarehouseOutList() {
6170
+
6171
+	id, _ := c.GetInt64("id")
6172
+
6173
+	service.DeleteSelfWarehouseOutList(id)
6174
+
6175
+	c.ServeSuccessJSON(map[string]interface{}{
6176
+		"ok": "msg",
6177
+	})
5671 6178
 }

+ 6 - 1
controllers/stock_in_api_controller.go View File

@@ -4429,7 +4429,11 @@ func (this *StockManagerApiController) AddDrugInformation() {
4429 4429
 		min_price, _ := strconv.ParseFloat(min_prices, 64)
4430 4430
 		drug.MinPrice = min_price
4431 4431
 		dose := goodNameM["dose"].(string)
4432
-		//dose, _ := strconv.ParseFloat(doses, 64)
4432
+
4433
+		is_self_drug := int64(goodNameM["is_self_drug"].(float64))
4434
+
4435
+		drug.IsSelfDrug = is_self_drug
4436
+
4433 4437
 		if len(dose) < 0 { //名字为空则生成一条导入错误日志
4434 4438
 			err_log := models.ExportErrLog{
4435 4439
 				LogType:    4,
@@ -4541,6 +4545,7 @@ func (this *StockManagerApiController) AddDrugInformation() {
4541 4545
 				PrescribingNumber:           item.PrescribingNumber,
4542 4546
 				PrescribingNumberUnit:       item.PrescribingNumberUnit,
4543 4547
 				FirstLetter:                 item.FirstLetter,
4548
+				IsSelfDrug:                  item.IsSelfDrug,
4544 4549
 			}
4545 4550
 
4546 4551
 			//查询同种药品同种规格是否存在

+ 71 - 67
models/drug.go View File

@@ -89,6 +89,7 @@ type BaseDrugLib struct {
89 89
 	IsProject          int64  `gorm:"column:is_project" json:"is_project" form:"is_project"`
90 90
 	DrugDosageFormName string `gorm:"column:drug_dosage_form_name" json:"drug_dosage_form_name" form:"drug_dosage_form_name"`
91 91
 	IsShow             int64  `gorm:"column:is_show" json:"is_show" form:"is_show"`
92
+	IsSelfDrug         int64  `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
92 93
 }
93 94
 
94 95
 func (BaseDrugLib) TableName() string {
@@ -367,6 +368,7 @@ type XtSelfDrugWarehouseInfo struct {
367 368
 	IsSys                     int64            `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
368 369
 	RecordDate                int64            `gorm:"column:record_date" json:"record_date" form:"record_date"`
369 370
 	BaseDrugLib               BaseDrugLibSeven `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
371
+	AdviceId                  int64            `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
370 372
 }
371 373
 
372 374
 func (XtSelfDrugWarehouseInfo) TableName() string {
@@ -401,60 +403,61 @@ func (XtSelfDrugWarehouse) TableName() string {
401 403
 }
402 404
 
403 405
 type XtSelfDrugFlow struct {
404
-	ID                        int64   `gorm:"column:id" json:"id" form:"id"`
405
-	WarehousingId             int64   `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
406
-	DrugId                    int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
407
-	Number                    string  `gorm:"column:number" json:"number" form:"number"`
408
-	BatchNumber               string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
409
-	Count                     int64   `gorm:"column:count" json:"count" form:"count"`
410
-	UserOrgId                 int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
411
-	PatientId                 int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
412
-	SystemTime                int64   `gorm:"column:system_time" json:"system_time" form:"system_time"`
413
-	ConsumableType            int64   `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
414
-	IsSys                     int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
415
-	WarehousingOrder          string  `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
416
-	WarehouseOutId            int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
417
-	WarehouseOutOrderNumber   string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
418
-	IsEdit                    int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
419
-	CancelStockId             int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
420
-	CancelOrderNumber         string  `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
421
-	Manufacturer              int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
422
-	Dealer                    int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
423
-	Creator                   int64   `gorm:"column:creator" json:"creator" form:"creator"`
424
-	UpdateCreator             int64   `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
425
-	Status                    int64   `gorm:"column:status" json:"status" form:"status"`
426
-	Ctime                     int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
427
-	Mtime                     int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
428
-	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
429
-	WarehousingDetailId       int64   `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
430
-	WarehouseOutDetailId      int64   `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
431
-	CancelOutDetailId         int64   `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
432
-	ExpireDate                int64   `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
433
-	ProductDate               int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
434
-	MaxUnit                   string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
435
-	MinUnit                   string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
436
-	StockMaxNumber            int64   `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
437
-	StockMinNumber            int64   `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
438
-	LastStockMaxNumber        int64   `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
439
-	LastStockMinNumber        int64   `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
440
-	AdviceId                  int64   `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
441
-	SupplyWarehouseId         int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
442
-	SupplyCancelOutId         int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
443
-	SupplyWarehouseDetailInfo int64   `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
444
-	StorehouseId              int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
445
-	SecondWarehouseInfoId     int64   `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
446
-	AdminUserId               int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
447
-	LastPrice                 float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
448
-	StockCount                string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
449
-	PharmacyId                int64   `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
450
-	IsRead                    int64   `gorm:"column:is_read" json:"is_read" form:"is_read"`
451
-	OverCount                 int64   `gorm:"column:over_count" json:"over_count" form:"over_count"`
452
-	IsCheck                   int64   `gorm:"column:is_check" json:"is_check" form:"is_check"`
453
-	RetailPrice               float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
454
-	OrderId                   int64   `gorm:"column:order_id" json:"order_id" form:"order_id"`
455
-	FlushOverCount            int64   `gorm:"column:flush_over_count" json:"flush_over_count" form:"flush_over_count"`
456
-	Remark                    string  `gorm:"column:remark" json:"remark" form:"remark"`
457
-	OperateTime               int64   `gorm:"column:operate_time" json:"operate_time" form:"operate_time"`
406
+	ID                        int64       `gorm:"column:id" json:"id" form:"id"`
407
+	WarehousingId             int64       `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
408
+	DrugId                    int64       `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
409
+	Number                    string      `gorm:"column:number" json:"number" form:"number"`
410
+	BatchNumber               string      `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
411
+	Count                     int64       `gorm:"column:count" json:"count" form:"count"`
412
+	UserOrgId                 int64       `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
413
+	PatientId                 int64       `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
414
+	SystemTime                int64       `gorm:"column:system_time" json:"system_time" form:"system_time"`
415
+	ConsumableType            int64       `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
416
+	IsSys                     int64       `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
417
+	WarehousingOrder          string      `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
418
+	WarehouseOutId            int64       `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
419
+	WarehouseOutOrderNumber   string      `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
420
+	IsEdit                    int64       `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
421
+	CancelStockId             int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
422
+	CancelOrderNumber         string      `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
423
+	Manufacturer              int64       `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
424
+	Dealer                    int64       `gorm:"column:dealer" json:"dealer" form:"dealer"`
425
+	Creator                   int64       `gorm:"column:creator" json:"creator" form:"creator"`
426
+	UpdateCreator             int64       `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
427
+	Status                    int64       `gorm:"column:status" json:"status" form:"status"`
428
+	Ctime                     int64       `gorm:"column:ctime" json:"ctime" form:"ctime"`
429
+	Mtime                     int64       `gorm:"column:mtime" json:"mtime" form:"mtime"`
430
+	Price                     float64     `gorm:"column:price" json:"price" form:"price"`
431
+	WarehousingDetailId       int64       `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
432
+	WarehouseOutDetailId      int64       `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
433
+	CancelOutDetailId         int64       `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
434
+	ExpireDate                int64       `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
435
+	ProductDate               int64       `gorm:"column:product_date" json:"product_date" form:"product_date"`
436
+	MaxUnit                   string      `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
437
+	MinUnit                   string      `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
438
+	StockMaxNumber            int64       `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
439
+	StockMinNumber            int64       `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
440
+	LastStockMaxNumber        int64       `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
441
+	LastStockMinNumber        int64       `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
442
+	AdviceId                  int64       `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
443
+	SupplyWarehouseId         int64       `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
444
+	SupplyCancelOutId         int64       `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
445
+	SupplyWarehouseDetailInfo int64       `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
446
+	StorehouseId              int64       `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
447
+	SecondWarehouseInfoId     int64       `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
448
+	AdminUserId               int64       `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
449
+	LastPrice                 float64     `gorm:"column:last_price" json:"last_price" form:"last_price"`
450
+	StockCount                string      `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
451
+	PharmacyId                int64       `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
452
+	IsRead                    int64       `gorm:"column:is_read" json:"is_read" form:"is_read"`
453
+	OverCount                 int64       `gorm:"column:over_count" json:"over_count" form:"over_count"`
454
+	IsCheck                   int64       `gorm:"column:is_check" json:"is_check" form:"is_check"`
455
+	RetailPrice               float64     `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
456
+	OrderId                   int64       `gorm:"column:order_id" json:"order_id" form:"order_id"`
457
+	FlushOverCount            int64       `gorm:"column:flush_over_count" json:"flush_over_count" form:"flush_over_count"`
458
+	Remark                    string      `gorm:"column:remark" json:"remark" form:"remark"`
459
+	OperateTime               int64       `gorm:"column:operate_time" json:"operate_time" form:"operate_time"`
460
+	BaseDrugLib               BaseDrugLib `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
458 461
 }
459 462
 
460 463
 func (XtSelfDrugFlow) TableName() string {
@@ -462,19 +465,20 @@ func (XtSelfDrugFlow) TableName() string {
462 465
 }
463 466
 
464 467
 type XtSelfDrugStockCount struct {
465
-	ID             int64 `gorm:"column:id" json:"id" form:"id"`
466
-	UserOrgId      int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
467
-	PatientId      int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
468
-	SumInCount     int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
469
-	SumOutCount    int64 `gorm:"column:sum_out_count" json:"sum_out_count" form:"sum_out_count"`
470
-	SumCancelCount int64 `gorm:"column:sum_cancel_count" json:"sum_cancel_count" form:"sum_cancel_count"`
471
-	DrugId         int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
472
-	Ctime          int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
473
-	Mtime          int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
474
-	Status         int64 `gorm:"column:status" json:"status" form:"status"`
475
-	FlushCount     int64 `gorm:"column:flush_count" json:"flush_count" form:"flush_count"`
476
-	SumActOutCount int64 `gorm:"column:sum_act_out_count" json:"sum_act_out_count" form:"sum_act_out_count"`
477
-	SumOldCount    int64 `gorm:"column:sum_old_count" json:"sum_old_count" form:"sum_old_count"`
468
+	ID             int64       `gorm:"column:id" json:"id" form:"id"`
469
+	UserOrgId      int64       `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
470
+	PatientId      int64       `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
471
+	SumInCount     int64       `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
472
+	SumOutCount    int64       `gorm:"column:sum_out_count" json:"sum_out_count" form:"sum_out_count"`
473
+	SumCancelCount int64       `gorm:"column:sum_cancel_count" json:"sum_cancel_count" form:"sum_cancel_count"`
474
+	DrugId         int64       `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
475
+	Ctime          int64       `gorm:"column:ctime" json:"ctime" form:"ctime"`
476
+	Mtime          int64       `gorm:"column:mtime" json:"mtime" form:"mtime"`
477
+	Status         int64       `gorm:"column:status" json:"status" form:"status"`
478
+	FlushCount     int64       `gorm:"column:flush_count" json:"flush_count" form:"flush_count"`
479
+	SumActOutCount int64       `gorm:"column:sum_act_out_count" json:"sum_act_out_count" form:"sum_act_out_count"`
480
+	SumOldCount    int64       `gorm:"column:sum_old_count" json:"sum_old_count" form:"sum_old_count"`
481
+	BaseDrugLib    BaseDrugLib `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
478 482
 }
479 483
 
480 484
 func (XtSelfDrugStockCount) TableName() string {

+ 35 - 0
service/mobile_dialysis_service.go View File

@@ -2672,6 +2672,41 @@ func GetLastMonitorRecord(orgID int64, patientID int64, beforeDate int64) (*mode
2672 2672
 	return &record, nil
2673 2673
 }
2674 2674
 
2675
+func GetLastMonitorRecordTwenty(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
2676
+	var record models.MonitoringRecord
2677
+	err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and ultrafiltration_volume_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
2678
+
2679
+	return record, nil
2680
+}
2681
+
2682
+func GetLastMonitorRecordTwentyOne(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
2683
+	var record models.MonitoringRecord
2684
+	err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_systolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
2685
+
2686
+	return record, nil
2687
+}
2688
+
2689
+func GetLastMonitorRecordTwentyTwo(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
2690
+	var record models.MonitoringRecord
2691
+	err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and monitor_diastolic_blood_pressure_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
2692
+
2693
+	return record, nil
2694
+}
2695
+
2696
+func GetLastMonitorRecordTwentyThree(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
2697
+	var record models.MonitoringRecord
2698
+	err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and pulse_frequency_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
2699
+
2700
+	return record, nil
2701
+}
2702
+
2703
+func GetLastMonitorRecordTwentyFour(orgID int64, patientID int64, beforeDate int64) (models.MonitoringRecord, error) {
2704
+	var record models.MonitoringRecord
2705
+	err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id = ? and status = 1 and monitoring_date = ? and displacement_quantity_one!=''", patientID, orgID, beforeDate).Order("operate_time desc").First(&record).Error
2706
+
2707
+	return record, nil
2708
+}
2709
+
2675 2710
 // 获取 maxDate 之前一次的透后评估记录
2676 2711
 func GetLastTimeAssessmentAfterDislysis(orgID int64, patientID int64, maxDate int64) (*models.AssessmentAfterDislysis, error) {
2677 2712
 	var record models.AssessmentAfterDislysis

+ 7 - 7
service/new_stock_service.go View File

@@ -655,14 +655,14 @@ func GetSelfDrugStockCount(patient_id int64, drug_id int64, org_id int64, tx *go
655 655
 	drugStockCount := models.XtSelfDrugStockCount{}
656 656
 	var err error
657 657
 	err = tx.Where("patient_id = ? and drug_id = ? and user_org_id  = ? and status = 1", patient_id, drug_id, org_id).Find(&drugStockCount).Error
658
-	if err == gorm.ErrRecordNotFound {
659
-		tx.Rollback()
660
-		return nil, err
661
-	}
662
-	if err != nil {
663
-		tx.Rollback()
664
-		return nil, err
658
+	if err != gorm.ErrRecordNotFound {
659
+		if err != nil {
660
+			tx.Rollback()
661
+			return nil, err
662
+		}
663
+
665 664
 	}
665
+
666 666
 	return &drugStockCount, nil
667 667
 }
668 668
 

+ 625 - 11
service/self_drug_service.go View File

@@ -3587,6 +3587,20 @@ func AddSelfDrugWarehouse(warehouse *models.XtSelfDrugWarehouse, tx *gorm.DB) er
3587 3587
 	return err
3588 3588
 }
3589 3589
 
3590
+func GetSelfDrugWarehouseByWaresingId(patient_id int64, record_time int64, org_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouse, error) {
3591
+
3592
+	warehouse := models.XtSelfDrugWarehouse{}
3593
+	err := tx.Where("patient_id = ? and warehousing_time = ? and org_id = ? and is_sys=1 and status=1", patient_id, record_time, org_id).Find(&warehouse).Error
3594
+
3595
+	if err != gorm.ErrRecordNotFound {
3596
+		if err != nil {
3597
+			tx.Rollback()
3598
+			return warehouse, err
3599
+		}
3600
+	}
3601
+	return warehouse, err
3602
+}
3603
+
3590 3604
 func UpdateSelfDrugWarehouse(warehouse *models.XtSelfDrugWarehouse, tx *gorm.DB) error {
3591 3605
 
3592 3606
 	err := tx.Save(&warehouse).Error
@@ -3630,7 +3644,7 @@ func GetSelfDrugWarehouseInfoByID(id int64) (models.XtSelfDrugWarehouseInfo, err
3630 3644
 
3631 3645
 	selfDrugWarehouseInfo := models.XtSelfDrugWarehouseInfo{}
3632 3646
 
3633
-	err := XTReadDB().Where("id = ? and status=1", id).Preload("BaseDrugLib", "status=1").Find(&selfDrugWarehouseInfo).Error
3647
+	err := XTReadDB().Where("warehousing_id = ? and status=1", id).Preload("BaseDrugLib", "status=1").Find(&selfDrugWarehouseInfo).Error
3634 3648
 
3635 3649
 	return selfDrugWarehouseInfo, err
3636 3650
 }
@@ -3658,9 +3672,16 @@ func DeleteSelfDrugWarehouse(id int64, tx *gorm.DB) error {
3658 3672
 	return err
3659 3673
 }
3660 3674
 
3661
-func GetSelfWarehouseInfoByWarehouseInfo(id int64, patient_id int64, org_id int64) (info []*models.XtSelfDrugWarehouseInfo, err error) {
3675
+func GetSelfWarehouseInfoByWarehouseInfo(id int64, patient_id int64, org_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
3676
+
3677
+	err = tx.Where("warehousing_id =? and patient_id =? and status=1 and org_id =?", id, patient_id, org_id).Find(&info).Error
3662 3678
 
3663
-	err = XTReadDB().Where("warehousing_id =? and patient_id =? and status=1 and org_id =?", id, patient_id, org_id).Find(&info).Error
3679
+	if err != gorm.ErrRecordNotFound {
3680
+		if err != nil {
3681
+			tx.Rollback()
3682
+			return info, err
3683
+		}
3684
+	}
3664 3685
 	return info, err
3665 3686
 }
3666 3687
 
@@ -3671,7 +3692,7 @@ func AddSelfDrugWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) erro
3671 3692
 		tx.Rollback()
3672 3693
 		return err
3673 3694
 	}
3674
-	err = tx.Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
3695
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
3675 3696
 	if err != nil {
3676 3697
 		tx.Rollback()
3677 3698
 		return err
@@ -3682,12 +3703,16 @@ func AddSelfDrugWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) erro
3682 3703
 
3683 3704
 func AddSelfDrugWarehouseStockMinNumber(count int64, id int64, tx *gorm.DB) error {
3684 3705
 
3685
-	err := XTWriteDB().Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
3706
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
3707
+	if err != nil {
3708
+		tx.Rollback()
3709
+		return err
3710
+	}
3711
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
3686 3712
 	if err != nil {
3687 3713
 		tx.Rollback()
3688 3714
 		return err
3689 3715
 	}
3690
-	err = XTWriteDB().Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
3691 3716
 
3692 3717
 	return err
3693 3718
 }
@@ -3699,7 +3724,7 @@ func GetDrugSumCountByPatient(patient_id int64, org_id int64, drug_id int64, tx
3699 3724
 	if err != gorm.ErrRecordNotFound {
3700 3725
 		if err != nil {
3701 3726
 			tx.Rollback()
3702
-			return
3727
+			return info, err
3703 3728
 		}
3704 3729
 	}
3705 3730
 
@@ -3719,7 +3744,6 @@ func CreateSelfDrugFlow(flow *models.XtSelfDrugFlow, tx *gorm.DB) error {
3719 3744
 func GetSelfDrugSumCountByStorehouseId(patient_id int64, orgid int64, drug_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
3720 3745
 
3721 3746
 	err = tx.Where("patient_id = ? and org_id = ? and status = 1  and drug_id =? and is_check = 1", patient_id, orgid, drug_id).Find(&info).Error
3722
-
3723 3747
 	if err != gorm.ErrRecordNotFound {
3724 3748
 		if err != nil {
3725 3749
 			tx.Rollback()
@@ -3791,14 +3815,604 @@ func DeleteSelfWarehouseOut(id int64) (models.XtSelfDrugWarehouseOutInfo, error)
3791 3815
 func GetSelfDrugWarehouseOutById(id int64) (models.XtSelfDrugWarehouseOutInfo, error) {
3792 3816
 
3793 3817
 	outInfo := models.XtSelfDrugWarehouseOutInfo{}
3794
-	err = XTReadDB().Where("id = ? and status =1", id).Preload("BaseDrugLib", "status=1").Find(&outInfo).Error
3818
+	err = XTReadDB().Where("warehouse_out_id = ? and status =1", id).Preload("BaseDrugLib", "status=1").Find(&outInfo).Error
3795 3819
 
3796 3820
 	return outInfo, err
3797 3821
 }
3798 3822
 
3799
-func GetSelfDrugQuery(user_org_id int64) (drug []*models.XtSelfDrugStockCount, err error) {
3823
+func GetSelfDrugQuery(user_org_id int64, ids []int64, limit int64, page int64) (drug []*models.XtSelfDrugStockCount, total int64, err error) {
3824
+
3825
+	db := XTReadDB().Model(&drug).Where("status=1")
3826
+	offset := (page - 1) * limit
3827
+	if len(ids) > 0 {
3828
+		db = db.Where("drug_id in(?)", ids)
3829
+	}
3800 3830
 
3801
-	err = XTReadDB().Where("user_org_id = ? and status=1", user_org_id).Find(&drug).Error
3831
+	err = db.Count(&total).Offset(offset).Limit(limit).Where("user_org_id = ? and status=1", user_org_id).Preload("BaseDrugLib", "org_id = ? and status =1", user_org_id).Find(&drug).Error
3802 3832
 
3833
+	return drug, total, err
3834
+}
3835
+
3836
+func GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id int64, orgId int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseOutInfo, err error) {
3837
+
3838
+	err = tx.Where("warehouse_out_id = ? and org_id  =? and status = 1", warehouse_out_id, orgId).Preload("BaseDrugLib", "status=1").Find(&info).Error
3839
+	if err != gorm.ErrRecordNotFound {
3840
+		if err != nil {
3841
+			tx.Rollback()
3842
+			return
3843
+		}
3844
+	}
3845
+	return info, err
3846
+}
3847
+
3848
+func GetSelfDrugWarehouseOutByLastId(id int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
3849
+	out := models.XtSelfDrugWarehouseOut{}
3850
+	err := tx.Where("id = ? and status = 1", id).Find(&out).Error
3851
+
3852
+	if err != gorm.ErrRecordNotFound {
3853
+		if err != nil {
3854
+			tx.Rollback()
3855
+			return out, err
3856
+		}
3857
+	}
3858
+	return out, err
3859
+}
3860
+
3861
+func GetSelfDrugAllStockInfo(patient_id int64, orgid int64, drugid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
3862
+
3863
+	err = tx.Where("patient_id  = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", patient_id, orgid, drugid).Find(&info).Error
3864
+	if err != gorm.ErrRecordNotFound {
3865
+		if err != nil {
3866
+			tx.Rollback()
3867
+			return info, err
3868
+		}
3869
+	}
3870
+	return info, err
3871
+}
3872
+
3873
+func FindSelfBaseDrugLibRecord(org_id int64, id int64, tx *gorm.DB) (lib models.BaseDrugLib, err error) {
3874
+	err = tx.Model(&models.BaseDrugLib{}).Where("id = ? AND org_id = ?  AND status = 1", id, org_id).First(&lib).Error
3875
+
3876
+	if err != gorm.ErrRecordNotFound {
3877
+		if err != nil {
3878
+			tx.Rollback()
3879
+			return lib, err
3880
+		}
3881
+	}
3882
+	return lib, err
3883
+}
3884
+
3885
+func GetSelfBaseDrugMedical(id int64, tx *gorm.DB) (models.XtBaseDrug, error) {
3886
+	drug := models.XtBaseDrug{}
3887
+	err := tx.Model(&drug).Where("id = ? and status = 1", id).Find(&drug).Error
3888
+	if err != gorm.ErrRecordNotFound {
3889
+		if err != nil {
3890
+			tx.Rollback()
3891
+			return drug, err
3892
+		}
3893
+	}
3803 3894
 	return drug, err
3804 3895
 }
3896
+
3897
+func AddSelfDrugCount(drug_id int64, org_id int64, patient_id int64, out_count int64, tx *gorm.DB) error {
3898
+
3899
+	err := tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count + ?", out_count)).Error
3900
+	if err != nil {
3901
+		tx.Rollback()
3902
+		return err
3903
+	}
3904
+
3905
+	err = tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count + ?", out_count)).Error
3906
+	if err != nil {
3907
+		tx.Rollback()
3908
+		return err
3909
+	}
3910
+	return err
3911
+}
3912
+
3913
+func UpdateSelfCheckDrugOut(out models.XtSelfDrugWarehouseOut, id int64, tx *gorm.DB) error {
3914
+
3915
+	err := tx.Model(&models.XtSelfDrugWarehouseOut{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": out.IsCheck}).Error
3916
+	if err != nil {
3917
+		tx.Rollback()
3918
+		return err
3919
+	}
3920
+	err = tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 1}).Error
3921
+	if err != nil {
3922
+		tx.Rollback()
3923
+		return err
3924
+	}
3925
+	return err
3926
+}
3927
+
3928
+func FindSelfLastDrugWarehousingInfoByID(drug_id int64, patient_id int64, tx *gorm.DB) (info models.XtSelfDrugWarehouseInfo, err error) {
3929
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("drug_id = ? AND status = 1 AND (stock_max_number > 0 or stock_min_number > 0) and patient_id = ? and is_check = 1", drug_id, patient_id).Order("ctime").First(&info).Error
3930
+	if err != gorm.ErrRecordNotFound {
3931
+		if err != nil {
3932
+			tx.Rollback()
3933
+			return info, err
3934
+		}
3935
+	}
3936
+	return info, err
3937
+}
3938
+
3939
+func ChangeSelfMaxNumber(id int64, count int64, tx *gorm.DB) error {
3940
+
3941
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
3942
+
3943
+	if err != nil {
3944
+		tx.Rollback()
3945
+		return err
3946
+	}
3947
+	return err
3948
+
3949
+}
3950
+
3951
+func UpdateSelfMinNumber(id int64, count int64, tx *gorm.DB) error {
3952
+
3953
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Update(map[string]interface{}{"stock_min_number": count}).Error
3954
+	if err != nil {
3955
+		tx.Rollback()
3956
+		return err
3957
+	}
3958
+	return err
3959
+}
3960
+
3961
+func ChangeSelfMaxNumberOne(id int64, count int64, tx *gorm.DB) error {
3962
+
3963
+	err = tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1 and is_check = 1", id).Updates(map[string]interface{}{"stock_max_number": count, "stock_min_number": 0}).Error
3964
+
3965
+	if err != nil {
3966
+		tx.Rollback()
3967
+		return err
3968
+	}
3969
+	return err
3970
+
3971
+}
3972
+
3973
+func UpDateSelfDrugWarehouseInfoByStock(info *models.XtSelfDrugWarehouseInfo, tx *gorm.DB) (err error) {
3974
+
3975
+	err = tx.Save(&info).Error
3976
+	if err != nil {
3977
+		tx.Rollback()
3978
+		return err
3979
+	}
3980
+	return err
3981
+}
3982
+
3983
+func FindSelfDrugWarehouseInfoFlushCount(drug_id int64, orgid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
3984
+
3985
+	err = tx.Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1", drug_id, orgid).Find(&info).Error
3986
+
3987
+	if err != nil {
3988
+		tx.Rollback()
3989
+		return info, err
3990
+	}
3991
+	return info, err
3992
+}
3993
+
3994
+func GetSelfLastWarehouseOutInfoById(drugid int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOutInfo, error) {
3995
+
3996
+	flow := models.XtSelfDrugWarehouseOutInfo{}
3997
+	err := tx.Where("drug_id = ? and status = 1", drugid).Last(&flow).Error
3998
+
3999
+	if err != gorm.ErrRecordNotFound {
4000
+		if err != nil {
4001
+			tx.Rollback()
4002
+			return flow, err
4003
+		}
4004
+	}
4005
+	return flow, err
4006
+}
4007
+
4008
+func UpdateSelfDrugWarehouseOutInfo(id int64, warehouse_info_id int64, org_id int64, over_count int64, drug_price float64, tx *gorm.DB) error {
4009
+
4010
+	err = tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("id = ? and org_id = ? and status = 1", id, org_id).Update(map[string]interface{}{"warehouse_info_id": warehouse_info_id, "over_count": over_count, "price": drug_price, "retail_price": drug_price}).Error
4011
+	if err != nil {
4012
+		tx.Rollback()
4013
+		return err
4014
+	}
4015
+	return err
4016
+}
4017
+
4018
+func UpdateSelfCheckDrugOutInfoList(info models.XtSelfDrugWarehouseOutInfo, warehouse_out_id int64, tx *gorm.DB) error {
4019
+
4020
+	err := tx.Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ?  and status = 1", warehouse_out_id).Update(map[string]interface{}{"is_check": 2}).Error
4021
+	if err != nil {
4022
+		tx.Rollback()
4023
+		return err
4024
+	}
4025
+	return err
4026
+}
4027
+
4028
+func UpdateSelfDrugMaxNumber(count int64, id int64, tx *gorm.DB) error {
4029
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4030
+	if err != nil {
4031
+		tx.Rollback()
4032
+		return err
4033
+	}
4034
+	return err
4035
+}
4036
+
4037
+func UpdateSelfDrugMinNumber(count int64, id int64, tx *gorm.DB) error {
4038
+
4039
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4040
+	if err != nil {
4041
+		tx.Rollback()
4042
+		return err
4043
+	}
4044
+	return err
4045
+}
4046
+
4047
+func ModifySelfReduceDrugInformation(id int64, count int64, orgid int64, tx *gorm.DB) error {
4048
+
4049
+	err = tx.Model(&models.BaseDrugLib{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", count)).Error
4050
+	if err != nil {
4051
+		tx.Rollback()
4052
+		return err
4053
+	}
4054
+	return err
4055
+}
4056
+
4057
+func DeleteSelfDrugOutFlow(id int64, orgid int64, tx *gorm.DB) error {
4058
+
4059
+	err := tx.Model(models.XtSelfDrugFlow{}).Where("warehouse_out_detail_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
4060
+	if err != nil {
4061
+		tx.Rollback()
4062
+		return err
4063
+	}
4064
+	return err
4065
+}
4066
+
4067
+func ReduceSelfDrugCount(drug_id int64, org_id int64, patient_id int64, out_count int64, tx *gorm.DB) error {
4068
+
4069
+	err := tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", out_count)).Error
4070
+	if err != nil {
4071
+		tx.Rollback()
4072
+		return err
4073
+	}
4074
+	err = tx.Model(&models.XtSelfDrugStockCount{}).Where("patient_id = ? and status = 1 and user_org_id = ? and drug_id = ?", patient_id, org_id, drug_id).UpdateColumn("sum_act_out_count", gorm.Expr("sum_act_out_count - ?", out_count)).Error
4075
+	if err != nil {
4076
+		tx.Rollback()
4077
+		return err
4078
+	}
4079
+	return err
4080
+}
4081
+
4082
+func UpdateSelfDrugStockCount(drug_id int64, org_id int64, patient_id int64, flush_count int64, tx *gorm.DB) error {
4083
+
4084
+	drug := models.XtSelfDrugStockCount{}
4085
+
4086
+	err := tx.Model(&drug).Where("drug_id = ? and user_org_id = ? and patient_id = ? and status = 1", drug_id, org_id, patient_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
4087
+	if err != nil {
4088
+		tx.Rollback()
4089
+		return err
4090
+	}
4091
+
4092
+	return err
4093
+}
4094
+
4095
+func FindSelfDrugWarehouseInfoFlushCountByStorehouse(drug_id int64, orgid int64, patient_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
4096
+
4097
+	err = tx.Where("drug_id = ? and org_id = ? and status = 1 and is_check = 1 and patient_id =?", drug_id, orgid, patient_id).Find(&info).Error
4098
+
4099
+	if err != nil {
4100
+		tx.Rollback()
4101
+		return info, err
4102
+	}
4103
+
4104
+	return info, err
4105
+}
4106
+
4107
+func GetSelfWarehousingInfoByList(id int64, orgid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
4108
+
4109
+	err = tx.Where("warehousing_id = ? and org_id = ? and status = 1", id, orgid).Find(&info).Error
4110
+
4111
+	if err != nil {
4112
+		tx.Rollback()
4113
+		return info, err
4114
+	}
4115
+	return info, err
4116
+}
4117
+
4118
+func GetSelfDrugWarehouseOutByWarehouseInfoId(warehouse_info_id int64, drug_id int64, orgid int64, tx *gorm.DB) (outInfo []*models.XtSelfDrugWarehouseOutInfo, err error) {
4119
+
4120
+	err = tx.Where("warehouse_info_id = ? and drug_id = ? and org_id = ? and is_check = 1 and status = 1", warehouse_info_id, drug_id, orgid).Find(&outInfo).Error
4121
+	if err != gorm.ErrRecordNotFound {
4122
+		if err != nil {
4123
+			tx.Rollback()
4124
+			return outInfo, err
4125
+		}
4126
+	}
4127
+	return outInfo, err
4128
+}
4129
+
4130
+func UpdateSelfWarehousingInfoFlow(id int64, orgid int64, tx *gorm.DB) error {
4131
+
4132
+	err := tx.Model(&models.XtSelfDrugFlow{}).Where("warehousing_id = ? and user_org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"status": 0}).Error
4133
+	if err != nil {
4134
+		tx.Rollback()
4135
+		return err
4136
+	}
4137
+	return err
4138
+}
4139
+
4140
+func AddSelfDrugReturnWarehouseStockMaxNumber(count int64, id int64, tx *gorm.DB) error {
4141
+
4142
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number - ?", count)).Error
4143
+	if err != nil {
4144
+		tx.Rollback()
4145
+		return err
4146
+	}
4147
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
4148
+	if err != nil {
4149
+		tx.Rollback()
4150
+		return err
4151
+	}
4152
+
4153
+	return err
4154
+}
4155
+
4156
+func AddSelfDrugReturnWarehouseStockMinNumber(count int64, id int64, tx *gorm.DB) error {
4157
+
4158
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number - ?", count)).Error
4159
+	if err != nil {
4160
+		tx.Rollback()
4161
+		return err
4162
+	}
4163
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"is_check": 2}).Error
4164
+	if err != nil {
4165
+		tx.Rollback()
4166
+		return err
4167
+	}
4168
+	return err
4169
+}
4170
+
4171
+func ReduceSelfDrugStockCount(patient_id int64, drug_id int64, user_org_id int64, waresing_count int64, over_count int64, tx *gorm.DB) error {
4172
+
4173
+	err = tx.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id  = ? and drug_id = ? and status = 1", user_org_id, patient_id, drug_id).UpdateColumn("sum_in_count", gorm.Expr("sum_in_count - ?", waresing_count)).Error
4174
+	if err != nil {
4175
+		tx.Rollback()
4176
+		return err
4177
+	}
4178
+	err = tx.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1", user_org_id, patient_id, drug_id).Update(map[string]interface{}{"flush_count": over_count}).Error
4179
+	if err != nil {
4180
+		tx.Rollback()
4181
+		return err
4182
+	}
4183
+	return err
4184
+}
4185
+
4186
+func ReturnSelfCheckWarehouseingInfo(id int64, orgid int64, tx *gorm.DB) error {
4187
+
4188
+	err := tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
4189
+	if err != nil {
4190
+		tx.Rollback()
4191
+		return err
4192
+	}
4193
+	err = tx.Model(&models.XtSelfDrugWarehouseInfo{}).Where("warehousing_id = ? and status = 1 and org_id = ?", id, orgid).Update(map[string]interface{}{"is_check": 2}).Error
4194
+	if err != nil {
4195
+		tx.Rollback()
4196
+		return err
4197
+	}
4198
+	return err
4199
+}
4200
+
4201
+func CheckSelfWarehousingInfo(id int64, orgid int64, checker int64, tx *gorm.DB) error {
4202
+
4203
+	err := tx.Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and org_id = ? and status = 1", id, orgid).Update(map[string]interface{}{"is_check": 1, "checker": checker}).Error
4204
+	if err != nil {
4205
+		tx.Rollback()
4206
+		return err
4207
+	}
4208
+	return err
4209
+}
4210
+
4211
+func GetSelfDrugFlow(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4212
+
4213
+	db := XTReadDB().Model(&flow).Where("status=1")
4214
+
4215
+	if drug_id > 0 {
4216
+		db = db.Where("drug_id =?", drug_id)
4217
+	}
4218
+	if start_time > 0 {
4219
+		db = db.Where("ctime>=?", start_time)
4220
+	}
4221
+	if end_time > 0 {
4222
+		db = db.Where("etime <=?", end_time)
4223
+	}
4224
+	if user_org_id > 0 {
4225
+		db = db.Where("user_org_id =?", user_org_id)
4226
+	}
4227
+
4228
+	offset := (page - 1) * limit
4229
+
4230
+	err = db.Count(&total).Offset(offset).Limit(limit).Preload("BaseDrugLib", "status=1 and org_id = ?", user_org_id).Order("id desc").Find(&flow).Error
4231
+
4232
+	return flow, total, err
4233
+}
4234
+
4235
+func GetSelfBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
4236
+
4237
+	lib := models.BaseDrugLib{}
4238
+
4239
+	err := XTReadDB().Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
4240
+
4241
+	return lib, err
4242
+}
4243
+
4244
+func GetSelfDrugBatchNumberList(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4245
+
4246
+	db := XTReadDB().Model(&flow).Where("status=1 and consumable_type =1")
4247
+
4248
+	if drug_id > 0 {
4249
+		db = db.Where("drug_id =?", drug_id)
4250
+	}
4251
+	if start_time > 0 {
4252
+		db = db.Where("ctime>=?", start_time)
4253
+	}
4254
+	if end_time > 0 {
4255
+		db = db.Where("etime <=?", end_time)
4256
+	}
4257
+	if user_org_id > 0 {
4258
+		db = db.Where("user_org_id =?", user_org_id)
4259
+	}
4260
+
4261
+	offset := (page - 1) * limit
4262
+
4263
+	err = db.Count(&total).Offset(offset).Limit(limit).Find(&flow).Error
4264
+
4265
+	return flow, total, err
4266
+}
4267
+
4268
+func GetAllSelfDrugWarehouse(keyword string, start_time int64, end_time int64, check_type int64, orgId int64, page int64, limit int64, patient_id int64) (warehouse []*models.XtSelfDrugWarehouse, total int64, err error) {
4269
+
4270
+	db := XTReadDB().Model(&warehouse).Where("status=1")
4271
+
4272
+	likeKey := "%" + keyword + "%"
4273
+
4274
+	if len(keyword) > 0 {
4275
+		db = db.Where("warehousing_order like ?", likeKey)
4276
+	}
4277
+
4278
+	if start_time > 0 {
4279
+		db = db.Where("operation_time>=?", start_time)
4280
+	}
4281
+	if end_time > 0 {
4282
+		db = db.Where("operation_time<=?", end_time)
4283
+	}
4284
+
4285
+	if check_type > 0 {
4286
+		db = db.Where("is_check = ?", check_type)
4287
+	}
4288
+	if orgId > 0 {
4289
+		db = db.Where("org_id = ?", orgId)
4290
+	}
4291
+	if patient_id > 0 {
4292
+		db = db.Where("patient_id=?", patient_id)
4293
+	}
4294
+
4295
+	offset := (page - 1) * limit
4296
+
4297
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("operation_time desc").Find(&warehouse).Error
4298
+
4299
+	return warehouse, total, err
4300
+}
4301
+
4302
+func DeleteSelfWarehouse(id int64) error {
4303
+
4304
+	err := XTWriteDB().Model(&models.XtSelfDrugWarehouse{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4305
+
4306
+	err = XTWriteDB().Model(&models.XtSelfDrugWarehouseInfo{}).Where("warehousing_id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4307
+
4308
+	return err
4309
+}
4310
+
4311
+func GetAllSelfDrugWarehouseOut(start_time int64, end_time int64, org_id int64, page int64, limit int64, patient_id int64, keyword string) (out []*models.XtSelfDrugWarehouseOut, total int64, err error) {
4312
+
4313
+	db := XTReadDB().Model(&out).Where("status=1")
4314
+	offset := (page - 1) * limit
4315
+
4316
+	likeKey := "%" + keyword + "%"
4317
+
4318
+	if len(keyword) > 0 {
4319
+		db = db.Where("warehouse_out_order_number like ?", likeKey)
4320
+	}
4321
+	if start_time > 0 {
4322
+		db = db.Where("operation_time>=?", start_time)
4323
+	}
4324
+
4325
+	if end_time > 0 {
4326
+		db = db.Where("operation_time<=?", end_time)
4327
+	}
4328
+
4329
+	if org_id > 0 {
4330
+		db = db.Where("org_id = ?", org_id)
4331
+	}
4332
+
4333
+	if patient_id > 0 {
4334
+		db = db.Where("patient_id = ?", patient_id)
4335
+	}
4336
+
4337
+	err = db.Count(&total).Offset(offset).Limit(limit).Order("operation_time desc").Find(&out).Error
4338
+
4339
+	return out, total, err
4340
+}
4341
+
4342
+func DeleteSelfWarehouseOutList(id int64) (models.XtSelfDrugWarehouseOut, error) {
4343
+
4344
+	warehouseOut := models.XtSelfDrugWarehouseOut{}
4345
+
4346
+	err := XTWriteDB().Model(&warehouseOut).Where("id = ? an status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4347
+
4348
+	err = XTWriteDB().Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("warehouse_out_id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
4349
+
4350
+	return warehouseOut, err
4351
+}
4352
+
4353
+func FindSelfDrugWarehouseInfoList(drugid int64, orgid int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
4354
+
4355
+	err = tx.Where("drug_id = ? and org_id = ? and status =1 and is_check =1  and (stock_max_number>0 or stock_min_number>0)", drugid, orgid).Find(&info).Error
4356
+
4357
+	if err != gorm.ErrRecordNotFound {
4358
+		if err != nil {
4359
+			tx.Rollback()
4360
+			return info, err
4361
+		}
4362
+	}
4363
+	return info, err
4364
+}
4365
+
4366
+func GetSelfDrugWarehouseInfoByInfo(advice_id int64, patient_id int64, advice_date int64, user_org_id int64, drug_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
4367
+
4368
+	err = tx.Where("advice_id = ? and patient_id = ? and record_date = ? and org_id = ? and status=1 and drug_id = ?", advice_id, patient_id, advice_date, user_org_id, drug_id).Find(&info).Error
4369
+
4370
+	return info, err
4371
+}
4372
+
4373
+func CreateSelfDrugWarehouseInfo(info *models.XtSelfDrugWarehouseInfo, tx *gorm.DB) error {
4374
+
4375
+	err := tx.Create(&info).Error
4376
+
4377
+	if err != nil {
4378
+		tx.Rollback()
4379
+		return err
4380
+	}
4381
+
4382
+	return err
4383
+}
4384
+
4385
+func GetLastSelfDrugWarehouseInfoById(org_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouseInfo, error) {
4386
+
4387
+	info := models.XtSelfDrugWarehouseInfo{}
4388
+
4389
+	err := tx.Where("org_id = ? and status =1", org_id).Last(&info).Error
4390
+
4391
+	return info, err
4392
+}
4393
+
4394
+func GetSelfDrugWarehouseOutDrugFlow(patient_id int64, drug_id int64, user_org_id int64, advice_id int64, tx *gorm.DB) (flow []*models.XtSelfDrugFlow, err error) {
4395
+
4396
+	err = tx.Where("patient_id = ? and drug_id = ? and user_org_id =? and status=1 and consumable_type =20 and advice_id =?", patient_id, drug_id, user_org_id, advice_id).Find(&flow).Error
4397
+
4398
+	if err != gorm.ErrRecordNotFound {
4399
+		if err != nil {
4400
+			tx.Rollback()
4401
+			return
4402
+		}
4403
+	}
4404
+	return flow, err
4405
+}
4406
+
4407
+func GetSelfDrugLastWarehouseOutTwety(orgid int64, record_date int64, tx *gorm.DB) (models.XtSelfDrugWarehouseOut, error) {
4408
+	out := models.XtSelfDrugWarehouseOut{}
4409
+	err := tx.Where("org_id = ? and status = 1 and warehouse_out_time = ?", orgid, record_date).Find(&out).Error
4410
+	if err != gorm.ErrRecordNotFound {
4411
+		if err != nil {
4412
+			tx.Rollback()
4413
+			return out, err
4414
+		}
4415
+
4416
+	}
4417
+	return out, err
4418
+}

+ 26 - 0
service/stock_service.go View File

@@ -1577,6 +1577,22 @@ func AddSigleDrugWarehouseOut(warehouseOut *models.DrugWarehouseOut) error {
1577 1577
 
1578 1578
 }
1579 1579
 
1580
+func GetSigleDrugWarehouseOutByPatientId(warehousing_time int64, patient_id int64, tx *gorm.DB) (models.XtSelfDrugWarehouse, error) {
1581
+
1582
+	selfDrugWarehouse := models.XtSelfDrugWarehouse{}
1583
+
1584
+	err := tx.Where("warehousing_time = ? and patient_id = ? and is_sys =1 and status=1", warehousing_time, patient_id).Find(&selfDrugWarehouse).Error
1585
+
1586
+	if err != gorm.ErrRecordNotFound {
1587
+		if err != nil {
1588
+			tx.Rollback()
1589
+			return selfDrugWarehouse, err
1590
+		}
1591
+	}
1592
+
1593
+	return selfDrugWarehouse, err
1594
+}
1595
+
1580 1596
 func AddSelfSigleDrugWarehouseOut(warehouseOut *models.XtSelfDrugWarehouseOut, tx *gorm.DB) error {
1581 1597
 
1582 1598
 	err := tx.Create(&warehouseOut).Error
@@ -9385,3 +9401,13 @@ func UpdateSelfDrugOutConfig(config models.XtSelfDrugOutConfig) error {
9385 9401
 
9386 9402
 	return err
9387 9403
 }
9404
+
9405
+func CreateSelfDrugFlowOne(flow models.XtSelfDrugFlow, tx *gorm.DB) error {
9406
+
9407
+	err := tx.Create(&flow).Error
9408
+	if err != nil {
9409
+		tx.Rollback()
9410
+		return err
9411
+	}
9412
+	return err
9413
+}

+ 301 - 0
service/warhouse_service.go View File

@@ -9734,3 +9734,304 @@ func NewMobileHisGoodAutoCancelInfo(orgID int64, creater int64, project *models.
9734 9734
 	}
9735 9735
 	return err
9736 9736
 }
9737
+
9738
+// 药品手动出库 递归方式
9739
+func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehouseout *models.XtSelfDrugWarehouseOut, drup *models.BaseDrugLib, advice *models.XtSelfDrugWarehouseOutInfo, unit string, tx *gorm.DB) (err error) {
9740
+
9741
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
9742
+	var deliver_number int64 = 0
9743
+
9744
+	var stock_number int64 = 0
9745
+
9746
+	var drug_price float64
9747
+	if advice.CountUnit == drup.MaxUnit {
9748
+		deliver_number = prescribingNumber * drup.MinNumber
9749
+
9750
+	} else {
9751
+		deliver_number = prescribingNumber
9752
+
9753
+	}
9754
+	if advice.CountUnit == drup.MaxUnit {
9755
+		drug_price = drup.RetailPrice
9756
+	}
9757
+	fmt.Println(drug_price)
9758
+
9759
+	if advice.CountUnit == drup.MinUnit {
9760
+		drug_price = drup.MinPrice
9761
+	}
9762
+
9763
+	if advice.CountUnit != drup.MaxUnit || advice.CountUnit != drup.MinUnit {
9764
+		drug_price = drup.RetailPrice
9765
+	}
9766
+
9767
+	// 根据先进先出原则,查询最先入库的批次,进行出库
9768
+	// 如果没有对应的库存,则报错
9769
+	lastWarehouse, _ := FindSelfLastDrugWarehousingInfoByID(advice.DrugId, advice.PatientId, tx)
9770
+
9771
+	if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
9772
+		if lastWarehouse.StockMinNumber >= drup.MinNumber {
9773
+			var stockMax int64
9774
+			var stockMin int64
9775
+			stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
9776
+			stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
9777
+
9778
+			ChangeSelfMaxNumber(lastWarehouse.ID, stockMax, tx)
9779
+			UpdateSelfMinNumber(lastWarehouse.ID, stockMin, tx)
9780
+
9781
+		}
9782
+	}
9783
+
9784
+	if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
9785
+
9786
+		lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
9787
+		ChangeSelfMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
9788
+
9789
+	}
9790
+
9791
+	warehouse, err := FindSelfLastDrugWarehousingInfoByID(advice.DrugId, advice.PatientId, tx)
9792
+
9793
+	// 将该批次的剩余库存数量转换为拆零数量
9794
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
9795
+
9796
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
9797
+
9798
+	}
9799
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
9800
+
9801
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
9802
+
9803
+	}
9804
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
9805
+
9806
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
9807
+
9808
+	}
9809
+	if stock_number >= deliver_number {
9810
+
9811
+		var maxNumber int64 = 0
9812
+		var minNumber int64 = 0
9813
+
9814
+		maxNumber = deliver_number / drup.MinNumber
9815
+		minNumber = deliver_number % drup.MinNumber
9816
+
9817
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
9818
+			minNumber = maxNumber
9819
+		}
9820
+
9821
+		if drup.MaxUnit != drup.MinUnit {
9822
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
9823
+				return errors.New("库存数量不足")
9824
+			}
9825
+		}
9826
+
9827
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
9828
+
9829
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
9830
+		}
9831
+
9832
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
9833
+
9834
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
9835
+		}
9836
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
9837
+
9838
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
9839
+		}
9840
+
9841
+		if warehouse.StockMaxNumber < 0 {
9842
+			warehouse.StockMaxNumber = 0
9843
+		}
9844
+		if warehouse.StockMinNumber < 0 {
9845
+			warehouse.StockMinNumber = 0
9846
+		}
9847
+
9848
+		warehouse.Mtime = time.Now().Unix()
9849
+
9850
+		if warehouse.StockMinNumber < minNumber {
9851
+			//fmt.Println("金4")
9852
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
9853
+			if warehouse.MaxUnit != warehouse.MinUnit {
9854
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
9855
+			}
9856
+			if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
9857
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
9858
+			}
9859
+		} else {
9860
+			//fmt.Println("金5")
9861
+			if minNumber > 0 {
9862
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
9863
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
9864
+				}
9865
+
9866
+			}
9867
+
9868
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
9869
+				//fmt.Println("6")
9870
+				if warehouse.StockMinNumber > 0 {
9871
+					if warehouse.StockMinNumber-deliver_number >= 0 {
9872
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
9873
+					}
9874
+
9875
+				}
9876
+
9877
+			}
9878
+
9879
+		}
9880
+
9881
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
9882
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
9883
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
9884
+			}
9885
+
9886
+		}
9887
+
9888
+		if drup.MaxUnit != drup.MinUnit {
9889
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
9890
+				return errors.New("库存数量不足")
9891
+			}
9892
+		}
9893
+		if warehouse.StockMinNumber <= 0 {
9894
+			warehouse.StockMinNumber = 0
9895
+		}
9896
+
9897
+		errThree := UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
9898
+
9899
+		if errThree != nil {
9900
+			return errors.New("扣减库存失败")
9901
+		}
9902
+
9903
+		//查询该药品剩余库存
9904
+		infolist, _ := FindSelfDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId, tx)
9905
+		var over_count int64
9906
+		for _, its := range infolist {
9907
+			if its.MaxUnit == drup.MaxUnit {
9908
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
9909
+			}
9910
+			over_count += its.StockMaxNumber + its.StockMinNumber
9911
+		}
9912
+
9913
+		drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
9914
+		drugflow := models.XtSelfDrugFlow{
9915
+			WarehouseOutId:          warehouseout.ID,
9916
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
9917
+			DrugId:                  advice.DrugId,
9918
+			Number:                  warehouse.Number,
9919
+			ProductDate:             advice.ProductDate,
9920
+			ExpireDate:              advice.ExpiryDate,
9921
+			Count:                   deliver_number,
9922
+			Price:                   warehouse.RetailPrice,
9923
+			Status:                  1,
9924
+			Ctime:                   advice.SysRecordTime,
9925
+			Mtime:                   time.Now().Unix(),
9926
+			UserOrgId:               advice.OrgId,
9927
+			Manufacturer:            advice.Manufacturer,
9928
+			Dealer:                  advice.Dealer,
9929
+			BatchNumber:             warehouse.BatchNumber,
9930
+			MaxUnit:                 drup.MinUnit,
9931
+			ConsumableType:          2,
9932
+			IsEdit:                  1,
9933
+			Creator:                 0,
9934
+			IsSys:                   0,
9935
+			WarehouseOutDetailId:    drugWareInfo.ID,
9936
+			AdviceId:                advice.ID,
9937
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
9938
+			StorehouseId:            advice.StorehouseId,
9939
+			AdminUserId:             advice.AdminUserId,
9940
+			LastPrice:               warehouse.Price,
9941
+			StockCount:              advice.StockCount,
9942
+			WarehousingDetailId:     warehouse.ID,
9943
+			OverCount:               over_count,
9944
+			RetailPrice:             drug_price, //手动出库出库价格
9945
+			WarehousingId:           warehouse.ID,
9946
+			SystemTime:              advice.SysRecordTime,
9947
+			PatientId:               advice.PatientId,
9948
+			Remark:                  advice.Remark,
9949
+			OperateTime:             time.Now().Unix(),
9950
+		}
9951
+		if warehouse.RetailPrice == 0 {
9952
+			drugflow.Price = advice.Price
9953
+		}
9954
+
9955
+		CreateSelfDrugFlowOne(drugflow, tx)
9956
+
9957
+		//更新出库id
9958
+		UpdateSelfDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
9959
+
9960
+		return nil
9961
+
9962
+	} else {
9963
+		stock_number_int := strconv.FormatInt(stock_number, 10)
9964
+		stock_number_int_count, _ := strconv.ParseFloat(stock_number_int, 64)
9965
+		drug_price = stock_number_int_count * advice.Price
9966
+		//扣减库存
9967
+		warehouse.StockMaxNumber = 0
9968
+		warehouse.StockMinNumber = 0
9969
+		warehouse.Mtime = time.Now().Unix()
9970
+
9971
+		errThree := UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
9972
+		if errThree != nil {
9973
+			return errThree
9974
+		}
9975
+
9976
+		//查询该药品剩余库存
9977
+		infolist, _ := FindDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId)
9978
+		var over_count int64
9979
+		for _, its := range infolist {
9980
+			if its.MaxUnit == drup.MaxUnit {
9981
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
9982
+			}
9983
+			over_count += its.StockMaxNumber + its.StockMinNumber
9984
+		}
9985
+		drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
9986
+		drugflow := models.XtSelfDrugFlow{
9987
+			WarehouseOutId:          warehouseout.ID,
9988
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
9989
+			DrugId:                  advice.DrugId,
9990
+			Number:                  warehouse.Number,
9991
+			ProductDate:             advice.ProductDate,
9992
+			ExpireDate:              advice.ExpiryDate,
9993
+			Count:                   stock_number,
9994
+			Price:                   warehouse.RetailPrice,
9995
+			Status:                  1,
9996
+			Ctime:                   advice.SysRecordTime,
9997
+			Mtime:                   time.Now().Unix(),
9998
+			UserOrgId:               advice.OrgId,
9999
+			Manufacturer:            advice.Manufacturer,
10000
+			Dealer:                  advice.Dealer,
10001
+			BatchNumber:             warehouse.BatchNumber,
10002
+			MaxUnit:                 drup.MinUnit,
10003
+			ConsumableType:          2,
10004
+			IsEdit:                  1,
10005
+			Creator:                 0,
10006
+			IsSys:                   0,
10007
+			WarehouseOutDetailId:    drugWareInfo.ID,
10008
+			AdviceId:                advice.ID,
10009
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10010
+			StorehouseId:            advice.StorehouseId,
10011
+			AdminUserId:             advice.AdminUserId,
10012
+			LastPrice:               warehouse.Price,
10013
+			StockCount:              advice.StockCount,
10014
+			OverCount:               over_count,
10015
+			RetailPrice:             drug_price, //手动出库出库价格
10016
+			WarehousingId:           warehouse.ID,
10017
+			WarehousingDetailId:     warehouse.ID,
10018
+			SystemTime:              advice.SysRecordTime,
10019
+			PatientId:               advice.PatientId,
10020
+			Remark:                  advice.Remark,
10021
+			OperateTime:             time.Now().Unix(),
10022
+		}
10023
+
10024
+		CreateSelfDrugFlowOne(drugflow, tx)
10025
+		//更新出库id
10026
+		UpdateSelfDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
10027
+		// 出库完成后,要将该批次库存清零
10028
+
10029
+		prescribingNumber_two_temp := deliver_number - stock_number
10030
+
10031
+		advice.CountUnit = drup.MinUnit
10032
+
10033
+		AutoSelfDrugDeliverInfoFourtyOne(orgID, prescribingNumber_two_temp, warehouseout, drup, advice, unit, tx)
10034
+	}
10035
+
10036
+	return
10037
+}