Ver código fonte

历史排班

28169 1 ano atrás
pai
commit
cb14ea48f9

+ 8 - 0
controllers/manager_center_api_controller.go Ver arquivo

234
 	count := service.FindBaseDrugLibRecordCountOne(drugLib)
234
 	count := service.FindBaseDrugLibRecordCountOne(drugLib)
235
 
235
 
236
 	if count == 0 {
236
 	if count == 0 {
237
+		if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
238
+
239
+			drugLib.DrugSpec = drugLib.Dose + drugLib.DoseUnit + "*" + string(drugLib.MinNumber) + drugLib.MinUnit + "/" + drugLib.MaxUnit
240
+		}
237
 		err := service.CreateBaseDrugLib(drugLib)
241
 		err := service.CreateBaseDrugLib(drugLib)
238
 		if err == nil {
242
 		if err == nil {
239
 			c.ServeSuccessJSON(map[string]interface{}{
243
 			c.ServeSuccessJSON(map[string]interface{}{
399
 		SumInCount:                  sum_in_count,
403
 		SumInCount:                  sum_in_count,
400
 		IsPharmacy:                  is_pharmacy,
404
 		IsPharmacy:                  is_pharmacy,
401
 	}
405
 	}
406
+	if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
407
+
408
+		drugLib.DrugSpec = drugLib.Dose + drugLib.DoseUnit + "*" + string(drugLib.MinNumber) + drugLib.MinUnit + "/" + drugLib.MaxUnit
409
+	}
402
 
410
 
403
 	err := service.UpdateBaseDrugLib(drugLib)
411
 	err := service.UpdateBaseDrugLib(drugLib)
404
 
412
 

+ 390 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go Ver arquivo

6157
 	//去重
6157
 	//去重
6158
 	consumables = RemoveRepeatedGood(consumables)
6158
 	consumables = RemoveRepeatedGood(consumables)
6159
 
6159
 
6160
+	if adminInfo.Org.Id == 9919 {
6161
+		houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6162
+		//查询是否有库存
6163
+		for _, item := range consumables {
6164
+			warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
6165
+
6166
+			if item.Count > warehouse.Count {
6167
+				goodErrcode := models.XtGoodErrcode{
6168
+					UserOrgId:      item.UserOrgId,
6169
+					Errcode:        "自动出库库存不足",
6170
+					GoodId:         item.GoodId,
6171
+					Status:         1,
6172
+					Ctime:          time.Now().Unix(),
6173
+					Mtime:          0,
6174
+					Count:          0,
6175
+					StockCount:     0,
6176
+					Creater:        creator,
6177
+					BatchNumberId:  warehouse.ID,
6178
+					WarehouseOutId: 0,
6179
+				}
6180
+				service.CreateGoodErrcode(goodErrcode)
6181
+
6182
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6183
+				c.ServeSuccessJSON(map[string]interface{}{
6184
+					"message":            "1",
6185
+					"good_name":          goodObj.GoodName,
6186
+					"specification_name": goodObj.SpecificationName,
6187
+				})
6188
+				return
6189
+			}
6190
+		}
6191
+
6192
+		//查询是否有出库单
6193
+		out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
6194
+		if err == gorm.ErrRecordNotFound {
6195
+			//没有记录,则创建出库单
6196
+			timeStr := time.Now().Format("2006-01-02")
6197
+			timeArr := strings.Split(timeStr, "-")
6198
+			total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
6199
+			total = total + 1
6200
+			warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
6201
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
6202
+			number = number + total
6203
+			warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
6204
+			creater := adminInfo.AdminUser.Id
6205
+			warehouseOut := models.WarehouseOut{
6206
+				WarehouseOutOrderNumber: warehousing_out_order,
6207
+				OperationTime:           time.Now().Unix(),
6208
+				OrgId:                   adminInfo.Org.Id,
6209
+				Creater:                 creater,
6210
+				Ctime:                   time.Now().Unix(),
6211
+				Status:                  1,
6212
+				WarehouseOutTime:        record_time,
6213
+				Dealer:                  0,
6214
+				Manufacturer:            0,
6215
+				Type:                    1,
6216
+				IsSys:                   1,
6217
+				StorehouseId:            houseConfig.StorehouseOutInfo,
6218
+				IsCheck:                 1,
6219
+			}
6220
+			err := service.AddSigleWarehouseOut(&warehouseOut)
6221
+			if err != nil {
6222
+				goodErrcode := models.XtGoodErrcode{
6223
+					UserOrgId:      adminInfo.Org.Id,
6224
+					Errcode:        "创建出库单失败",
6225
+					GoodId:         0,
6226
+					Status:         1,
6227
+					Ctime:          time.Now().Unix(),
6228
+					Mtime:          0,
6229
+					Count:          0,
6230
+					StockCount:     0,
6231
+					Creater:        creator,
6232
+					BatchNumberId:  0,
6233
+					WarehouseOutId: 0,
6234
+				}
6235
+				service.CreateGoodErrcode(goodErrcode)
6236
+				utils.TraceLog("创建出库单失败 err = %v", err)
6237
+
6238
+			} else {
6239
+
6240
+				for _, item := range consumables {
6241
+					//出库
6242
+					err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
6243
+
6244
+					//err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
6245
+
6246
+					if err == nil {
6247
+						goodErrcode := models.XtGoodErrcode{
6248
+							UserOrgId:      adminInfo.Org.Id,
6249
+							Errcode:        "自动出库接口报错",
6250
+							GoodId:         0,
6251
+							Status:         1,
6252
+							Ctime:          time.Now().Unix(),
6253
+							Mtime:          0,
6254
+							Count:          0,
6255
+							StockCount:     0,
6256
+							Creater:        creator,
6257
+							BatchNumberId:  0,
6258
+							WarehouseOutId: 0,
6259
+						}
6260
+						service.CreateGoodErrcode(goodErrcode)
6261
+						utils.TraceLog("创建出库单失败 err = %v", err)
6262
+					}
6263
+
6264
+					//查询
6265
+
6266
+					//出库数量相加
6267
+					errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
6268
+					if errs != nil {
6269
+						goodErrcode := models.XtGoodErrcode{
6270
+							UserOrgId:      item.UserOrgId,
6271
+							Errcode:        "创建剩余库存字段报错",
6272
+							GoodId:         item.GoodId,
6273
+							Status:         1,
6274
+							Ctime:          time.Now().Unix(),
6275
+							Mtime:          0,
6276
+							Count:          0,
6277
+							StockCount:     0,
6278
+							Creater:        creater,
6279
+							BatchNumberId:  0,
6280
+							WarehouseOutId: 0,
6281
+						}
6282
+						service.CreateGoodErrcode(goodErrcode)
6283
+					}
6284
+				}
6285
+
6286
+				list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
6287
+				if len(list) == 0 {
6288
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
6289
+					return
6290
+				}
6291
+				for _, item := range list {
6292
+					prepare := models.DialysisBeforePrepare{
6293
+						UserOrgId:    adminInfo.Org.Id,
6294
+						PatientId:    patient_id,
6295
+						RecordDate:   record_time,
6296
+						GoodId:       item.GoodId,
6297
+						GoodTypeId:   item.GoodTypeId,
6298
+						Count:        item.Count,
6299
+						Creater:      adminInfo.AdminUser.Id,
6300
+						Status:       1,
6301
+						Ctime:        time.Now().Unix(),
6302
+						StorehouseId: houseConfig.StorehouseOutInfo,
6303
+					}
6304
+					//清空准备表数据
6305
+					err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
6306
+					if err != nil {
6307
+						goodErrcode := models.XtGoodErrcode{
6308
+							UserOrgId:      item.OrgId,
6309
+							Errcode:        "自动出库清空准备表数据报错",
6310
+							GoodId:         item.GoodId,
6311
+							Status:         1,
6312
+							Ctime:          time.Now().Unix(),
6313
+							Mtime:          0,
6314
+							Count:          0,
6315
+							StockCount:     0,
6316
+							Creater:        creater,
6317
+							BatchNumberId:  0,
6318
+							WarehouseOutId: 0,
6319
+						}
6320
+						service.CreateGoodErrcode(goodErrcode)
6321
+					}
6322
+					errs := service.CreateDialysisBeforePrepareOne(&prepare)
6323
+					if errs != nil {
6324
+						goodErrcode := models.XtGoodErrcode{
6325
+							UserOrgId:      item.OrgId,
6326
+							Errcode:        "自动出库创建准备表数据报错",
6327
+							GoodId:         item.GoodId,
6328
+							Status:         1,
6329
+							Ctime:          time.Now().Unix(),
6330
+							Mtime:          0,
6331
+							Count:          0,
6332
+							StockCount:     0,
6333
+							Creater:        creater,
6334
+							BatchNumberId:  0,
6335
+							WarehouseOutId: 0,
6336
+						}
6337
+						service.CreateGoodErrcode(goodErrcode)
6338
+					}
6339
+
6340
+					//查询默认仓库
6341
+					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6342
+					stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
6343
+					var total_count int64
6344
+					for _, it := range stockList {
6345
+						total_count += it.StockCount
6346
+					}
6347
+					//基础库插入数据
6348
+					errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
6349
+					if errcodes != nil {
6350
+						goodErrcode := models.XtGoodErrcode{
6351
+							UserOrgId:      item.OrgId,
6352
+							Errcode:        "自动出库基础库插入数据",
6353
+							GoodId:         item.GoodId,
6354
+							Status:         1,
6355
+							Ctime:          time.Now().Unix(),
6356
+							Mtime:          0,
6357
+							Count:          0,
6358
+							StockCount:     0,
6359
+							Creater:        creater,
6360
+							BatchNumberId:  0,
6361
+							WarehouseOutId: 0,
6362
+						}
6363
+						service.CreateGoodErrcode(goodErrcode)
6364
+					}
6365
+
6366
+					goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
6367
+					var flush_count int64
6368
+					for _, it := range goodList {
6369
+						flush_count += it.StockCount
6370
+					}
6371
+
6372
+					errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
6373
+					if errsss != nil {
6374
+						goodErrcode := models.XtGoodErrcode{
6375
+							UserOrgId:      item.OrgId,
6376
+							Errcode:        "自动出库剩余库存更新数据",
6377
+							GoodId:         item.GoodId,
6378
+							Status:         1,
6379
+							Ctime:          time.Now().Unix(),
6380
+							Mtime:          0,
6381
+							Count:          0,
6382
+							StockCount:     0,
6383
+							Creater:        creater,
6384
+							BatchNumberId:  0,
6385
+							WarehouseOutId: 0,
6386
+						}
6387
+						service.CreateGoodErrcode(goodErrcode)
6388
+					}
6389
+				}
6390
+			}
6391
+			//
6392
+		} else if err == nil {
6393
+			for _, item := range consumables {
6394
+				//出库
6395
+				err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
6396
+				//err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
6397
+				if err != nil {
6398
+					goodErrcode := models.XtGoodErrcode{
6399
+						UserOrgId:      adminInfo.Org.Id,
6400
+						Errcode:        "自动出库接口报错",
6401
+						GoodId:         0,
6402
+						Status:         1,
6403
+						Ctime:          time.Now().Unix(),
6404
+						Mtime:          0,
6405
+						Count:          0,
6406
+						StockCount:     0,
6407
+						Creater:        creator,
6408
+						BatchNumberId:  0,
6409
+						WarehouseOutId: 0,
6410
+					}
6411
+					service.CreateGoodErrcode(goodErrcode)
6412
+				}
6413
+
6414
+				//出库数量相加
6415
+				errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
6416
+				if errss != nil {
6417
+					goodErrcode := models.XtGoodErrcode{
6418
+						UserOrgId:      item.UserOrgId,
6419
+						Errcode:        "创建剩余库存字段报错",
6420
+						GoodId:         item.GoodId,
6421
+						Status:         1,
6422
+						Ctime:          time.Now().Unix(),
6423
+						Mtime:          time.Now().Unix(),
6424
+						Count:          0,
6425
+						StockCount:     0,
6426
+						Creater:        item.Creater,
6427
+						BatchNumberId:  0,
6428
+						WarehouseOutId: 0,
6429
+					}
6430
+					service.CreateGoodErrcode(goodErrcode)
6431
+				}
6432
+
6433
+				list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
6434
+				if len(list) == 0 {
6435
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
6436
+					return
6437
+				}
6438
+				for _, item := range list {
6439
+					prepare := models.DialysisBeforePrepare{
6440
+						UserOrgId:    adminInfo.Org.Id,
6441
+						PatientId:    patient_id,
6442
+						RecordDate:   record_time,
6443
+						GoodId:       item.GoodId,
6444
+						GoodTypeId:   item.GoodTypeId,
6445
+						Count:        item.Count,
6446
+						Creater:      adminInfo.AdminUser.Id,
6447
+						Status:       1,
6448
+						Ctime:        time.Now().Unix(),
6449
+						StorehouseId: houseConfig.StorehouseOutInfo,
6450
+					}
6451
+
6452
+					//清空准备表数据
6453
+					errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
6454
+					if errs != nil {
6455
+						goodErrcode := models.XtGoodErrcode{
6456
+							UserOrgId:      adminInfo.Org.Id,
6457
+							Errcode:        "自动出库清空准备表数据报错",
6458
+							GoodId:         0,
6459
+							Status:         1,
6460
+							Ctime:          time.Now().Unix(),
6461
+							Mtime:          0,
6462
+							Count:          0,
6463
+							StockCount:     0,
6464
+							Creater:        creator,
6465
+							BatchNumberId:  0,
6466
+							WarehouseOutId: 0,
6467
+						}
6468
+						service.CreateGoodErrcode(goodErrcode)
6469
+					}
6470
+					errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
6471
+					if errcodes != nil {
6472
+						goodErrcode := models.XtGoodErrcode{
6473
+							UserOrgId:      adminInfo.Org.Id,
6474
+							Errcode:        "自动出库创建准备表数据报错",
6475
+							GoodId:         0,
6476
+							Status:         1,
6477
+							Ctime:          time.Now().Unix(),
6478
+							Mtime:          0,
6479
+							Count:          0,
6480
+							StockCount:     0,
6481
+							Creater:        creator,
6482
+							BatchNumberId:  0,
6483
+							WarehouseOutId: 0,
6484
+						}
6485
+						service.CreateGoodErrcode(goodErrcode)
6486
+					}
6487
+
6488
+					//查询默认仓库
6489
+					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6490
+					stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
6491
+					var total_count int64
6492
+					for _, it := range stockList {
6493
+						total_count += it.StockCount
6494
+					}
6495
+					//基础库插入数据
6496
+					errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
6497
+					if errcodes != nil {
6498
+						goodErrcode := models.XtGoodErrcode{
6499
+							UserOrgId:      adminInfo.Org.Id,
6500
+							Errcode:        "自动出库基础库插入数据报错",
6501
+							GoodId:         0,
6502
+							Status:         1,
6503
+							Ctime:          time.Now().Unix(),
6504
+							Mtime:          0,
6505
+							Count:          0,
6506
+							StockCount:     0,
6507
+							Creater:        creator,
6508
+							BatchNumberId:  0,
6509
+							WarehouseOutId: 0,
6510
+						}
6511
+						service.CreateGoodErrcode(goodErrcode)
6512
+					}
6513
+
6514
+					goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
6515
+					var flush_count int64
6516
+					for _, it := range goodList {
6517
+						flush_count += it.StockCount
6518
+					}
6519
+
6520
+					errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
6521
+					creater := c.GetMobileAdminUserInfo().AdminUser.Id
6522
+					if errss != nil {
6523
+						goodErrcode := models.XtGoodErrcode{
6524
+							UserOrgId:      item.OrgId,
6525
+							Errcode:        "自动出库剩余库存更新数据",
6526
+							GoodId:         item.GoodId,
6527
+							Status:         1,
6528
+							Ctime:          time.Now().Unix(),
6529
+							Mtime:          0,
6530
+							Count:          0,
6531
+							StockCount:     0,
6532
+							Creater:        creater,
6533
+							BatchNumberId:  0,
6534
+							WarehouseOutId: 0,
6535
+						}
6536
+						service.CreateGoodErrcode(goodErrcode)
6537
+					}
6538
+
6539
+				}
6540
+			}
6541
+		}
6542
+		c.ServeSuccessJSON(map[string]interface{}{
6543
+			"msg":                "提交成功",
6544
+			"message":            "2",
6545
+			"good_name":          "",
6546
+			"specification_name": "",
6547
+		})
6548
+		return
6549
+	}
6160
 	if record.IsOpen == 1 {
6550
 	if record.IsOpen == 1 {
6161
 		houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6551
 		houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6162
 		//查询是否有库存
6552
 		//查询是否有库存

+ 9 - 6
controllers/mobile_api_controllers/patient_api_controller.go Ver arquivo

2649
 	// 插入透析处方
2649
 	// 插入透析处方
2650
 	if dialysisPrescribe == nil && dialysisSolution != nil {
2650
 	if dialysisPrescribe == nil && dialysisSolution != nil {
2651
 		var newprescribe models.DialysisPrescription
2651
 		var newprescribe models.DialysisPrescription
2652
-		newprescribe.UserOrgId = dialysisSolution.UserOrgId
2653
-		newprescribe.PatientId = dialysisSolution.PatientId
2652
+		newprescribe.UserOrgId = adminUserInfo.Org.Id
2653
+		newprescribe.PatientId = id
2654
 		newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
2654
 		newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
2655
 		newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
2655
 		newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
2656
 		newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
2656
 		newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
2812
 	if dialysisPrescribe == nil && dialysisSolution == nil {
2812
 	if dialysisPrescribe == nil && dialysisSolution == nil {
2813
 		if lastDialysisPrescribe != nil {
2813
 		if lastDialysisPrescribe != nil {
2814
 			var newprescribe models.DialysisPrescription
2814
 			var newprescribe models.DialysisPrescription
2815
-			newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
2816
-			newprescribe.PatientId = lastDialysisPrescribe.PatientId
2815
+			newprescribe.UserOrgId = adminUserInfo.Org.Id
2816
+			newprescribe.PatientId = id
2817
 			newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
2817
 			newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
2818
 			newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
2818
 			newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
2819
 			newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
2819
 			newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
2966
 		} else if system_dialysisPrescribe != nil {
2966
 		} else if system_dialysisPrescribe != nil {
2967
 
2967
 
2968
 			var newprescribe models.DialysisPrescription
2968
 			var newprescribe models.DialysisPrescription
2969
-			newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
2969
+			newprescribe.UserOrgId = adminUserInfo.Org.Id
2970
 			newprescribe.PatientId = id
2970
 			newprescribe.PatientId = id
2971
 			newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
2971
 			newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
2972
 			newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
2972
 			newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
3133
 			newprescribe.Status = 1
3133
 			newprescribe.Status = 1
3134
 
3134
 
3135
 			_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
3135
 			_, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
3136
-			newprescribe.ID = dialysisPrescription.ID
3136
+			if dialysisPrescription.ID > 0 {
3137
+				newprescribe.ID = dialysisPrescription.ID
3138
+			}
3139
+
3137
 			if dialysisPrescription.ID == 0 {
3140
 			if dialysisPrescription.ID == 0 {
3138
 				if adminUserInfo.Org.Id == 10340 {
3141
 				if adminUserInfo.Org.Id == 10340 {
3139
 					newprescribe.Sodium = 138
3142
 					newprescribe.Sodium = 138

+ 32 - 7
service/warhouse_service.go Ver arquivo

622
 			BloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit)
622
 			BloodHisDrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit)
623
 
623
 
624
 			//查询今日出库的数据
624
 			//查询今日出库的数据
625
-			//if orgID == 10188 || orgID == 10217 || orgID == 10344 {
626
-			//	//查询这个患者今日用过的总数量
627
-			//	GetDrugFlowByWatch(advice.PatientId, advice.DrugId, advice.AdviceDate, advice.UserOrgId)
628
-			//}
625
+			if orgID == 10188 || orgID == 10217 || orgID == 10344 {
626
+				//查询这个患者今日用过的总数量
627
+				listDrugFlow, _ := GetDrugFlowByWatch(advice.PatientId, advice.DrugId, advice.AdviceDate, advice.UserOrgId)
628
+				for _, item := range listDrugFlow {
629
+
630
+					outInfor, _ := GetDrugWarehouseOutInfor(item.WarehouseOutDetailId, item.UserOrgId)
631
+					if item.MaxUnit == outInfor.CountUnit {
632
+						if item.Count != outInfor.Count {
633
+							UpdateDrugWarehouseOutInfoById(outInfor.ID, item.Count)
634
+						}
635
+					}
636
+
637
+				}
638
+			}
629
 
639
 
630
 		} else {
640
 		} else {
631
 			return errors.New("药品信息不存在")
641
 			return errors.New("药品信息不存在")
636
 	return
646
 	return
637
 }
647
 }
638
 
648
 
639
-//func GetDrugFlowByWatch(patient_id int64, drug_id int64, advice_date) {
640
-//
641
-//}
649
+func GetDrugFlowByWatch(patient_id int64, drug_id int64, advice_date int64, user_org_id int64) (list []*models.DrugFlow, err error) {
650
+
651
+	err = XTReadDB().Where("patient_id = ? and drug_id = ? and system_time = ? and user_org_id = ? and status =1 and consumable_type = 3", patient_id, drug_id, advice_date, user_org_id).Find(&list).Error
652
+	return list, err
653
+}
654
+
655
+func GetDrugWarehouseOutInfor(id int64, user_org_id int64) (models.DrugWarehouseOutInfo, error) {
656
+
657
+	outInfo := models.DrugWarehouseOutInfo{}
658
+	err := XTReadDB().Where("id = ? and user_org_id = ?", id, user_org_id).Find(&outInfo).Error
659
+	return outInfo, err
660
+}
661
+
662
+func UpdateDrugWarehouseOutInfoById(id int64, count int64) error {
663
+
664
+	err := XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"count": count}).Error
665
+	return err
666
+}
642
 
667
 
643
 // 药品出库 递归方式
668
 // 药品出库 递归方式
644
 func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {
669
 func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo) (err error) {