Browse Source

2024/6/17

28169 4 weeks ago
parent
commit
7eeee314b7

BIN
XT_New.exe View File


+ 50 - 3
controllers/drug_stock_api_contorller.go View File

@@ -3297,8 +3297,24 @@ func (c *StockDrugApiController) CheckWarehousingInfo() {
3297 3297
 	service.CheckNewWarehousingInfo(warehousing_id, orgId, checker, tx)
3298 3298
 
3299 3299
 	list, _ := service.GetNewWarehousingInfoByList(warehousing_id, orgId, tx)
3300
+
3301
+	var is_success = 2
3300 3302
 	for _, item := range list {
3303
+		var his_warehousing_count = item.WarehousingCount
3304
+		var his_max_unit = item.MaxUnit
3305
+		var in_cout int64
3301 3306
 		medical, _ := service.GetNewBaseDrugMedical(item.DrugId, tx)
3307
+
3308
+		if his_max_unit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
3309
+			in_cout = his_warehousing_count * medical.MinNumber
3310
+		}
3311
+		if his_max_unit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
3312
+			in_cout = his_warehousing_count
3313
+		}
3314
+		if his_max_unit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
3315
+			in_cout = his_warehousing_count
3316
+		}
3317
+
3302 3318
 		if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
3303 3319
 			//新增库存
3304 3320
 			service.AddNewDrugWarehouseStockMaxNumber(item.WarehousingCount, item.ID, tx)
@@ -3412,10 +3428,35 @@ func (c *StockDrugApiController) CheckWarehousingInfo() {
3412 3428
 		if drugStockCount.ID > 0 {
3413 3429
 			service.UpdateNewDrugStockSum(item.StorehouseId, item.DrugId, item.OrgId, total_count, over_count, tx)
3414 3430
 		}
3415
-	}
3416 3431
 
3417
-	tx.Commit()
3432
+		flowList, _ := service.GetNewDrugFlowList(item.DrugId, item.OrgId, item.ID, tx)
3433
+		var his_count int64
3434
+		if len(flowList) > 0 {
3435
+			for _, item := range flowList {
3436
+				baseDrug, _ := service.GetNewBaseDrugMedical(item.DrugId, tx)
3437
+				if item.MaxUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
3438
+					his_count = item.Count * baseDrug.MinNumber
3439
+				}
3440
+				if item.MaxUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
3441
+					his_count = item.Count
3442
+				}
3443
+				if item.MaxUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
3444
+					his_count = item.Count
3445
+				}
3446
+			}
3447
+		}
3418 3448
 
3449
+		if in_cout != his_count {
3450
+			is_success = 1
3451
+			tx.Rollback()
3452
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFlow)
3453
+			return
3454
+		}
3455
+	}
3456
+
3457
+	if is_success != 1 {
3458
+		tx.Commit()
3459
+	}
3419 3460
 	c.ServeSuccessJSON(map[string]interface{}{
3420 3461
 		"list": list,
3421 3462
 	})
@@ -3743,11 +3784,16 @@ func (c *StockDrugApiController) ToReturnCheck() {
3743 3784
 	//调用出库逻辑
3744 3785
 	for _, item := range list {
3745 3786
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
3787
+
3746 3788
 		if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
3747
-			service.UpdateNewDrugMaxNumber(item.Count, item.WarehouseInfoId, tx)
3789
+
3748 3790
 			var sum_out_count int64
3749 3791
 			sum_out_count = item.Count * medical.MinNumber
3792
+
3793
+			service.UpdateNewDrugMaxNumberOne(sum_out_count, item.WarehouseInfoId, tx)
3794
+
3750 3795
 			service.ModifyNewReduceDrugInformation(item.DrugId, sum_out_count, item.OrgId, tx)
3796
+
3751 3797
 			drugInfoList, _ := service.FindNewDrugWarehouseInfoList(item.DrugId, item.OrgId, tx)
3752 3798
 			var drug_max_number int64
3753 3799
 			var drug_min_number int64
@@ -3776,6 +3822,7 @@ func (c *StockDrugApiController) ToReturnCheck() {
3776 3822
 			service.CreatedNewDrugFlushInfo(drugFlushInfo, tx)
3777 3823
 			service.DeleteNewDrugOutFlow(item.ID, item.OrgId, tx)
3778 3824
 		}
3825
+
3779 3826
 		if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
3780 3827
 			service.UpdateDrugMaxNumber(item.Count, item.WarehouseInfoId)
3781 3828
 			var sum_out_count int64

+ 84 - 0
controllers/self_drug_api_congtroller.go View File

@@ -191,6 +191,10 @@ func SelfDrugRouters() {
191 191
 
192 192
 	beego.Router("/api/drug/modifydrugcodewarehouseinfo", &SelfDrugApiController{}, "Post:ModifyDrugCodeWarehosueInfo")
193 193
 
194
+	beego.Router("/api/drug/getpatientadvicelist", &SelfDrugApiController{}, "Get:GetPatientAdviceList")
195
+
196
+	beego.Router("/api/drug/getpatientadvicelistdetail", &SelfDrugApiController{}, "Get:GetPatientAdviceListDetail")
197
+
194 198
 }
195 199
 
196 200
 func (this *SelfDrugApiController) GetCurrentPatient() {
@@ -6474,3 +6478,83 @@ func (c *SelfDrugApiController) ModifyDrugCodeWarehosueInfo() {
6474 6478
 	})
6475 6479
 
6476 6480
 }
6481
+
6482
+func (this *SelfDrugApiController) GetPatientAdviceList() {
6483
+
6484
+	patient_id, _ := this.GetInt64("patient_id")
6485
+
6486
+	start_time := this.GetString("start_time")
6487
+
6488
+	end_time := this.GetString("end_time")
6489
+
6490
+	timeLayout := "2006-01-02"
6491
+	loc, _ := time.LoadLocation("Local")
6492
+	var startTime int64
6493
+	if len(start_time) > 0 {
6494
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6495
+		if err != nil {
6496
+			fmt.Println(err)
6497
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6498
+			return
6499
+		}
6500
+		startTime = theTime.Unix()
6501
+	}
6502
+	var endTime int64
6503
+	if len(end_time) > 0 {
6504
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
6505
+		if err != nil {
6506
+			utils.ErrorLog(err.Error())
6507
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6508
+			return
6509
+		}
6510
+		endTime = theTime.Unix()
6511
+	}
6512
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6513
+
6514
+	adviceList, _ := service.GetNewPatientAdviceList(patient_id, startTime, endTime, orgId)
6515
+	this.ServeSuccessJSON(map[string]interface{}{
6516
+		"adviceList": adviceList,
6517
+	})
6518
+}
6519
+
6520
+func (this *SelfDrugApiController) GetPatientAdviceListDetail() {
6521
+
6522
+	patient_id, _ := this.GetInt64("patient_id")
6523
+
6524
+	start_time := this.GetString("start_time")
6525
+
6526
+	end_time := this.GetString("end_time")
6527
+
6528
+	timeLayout := "2006-01-02"
6529
+	loc, _ := time.LoadLocation("Local")
6530
+	var startTime int64
6531
+	if len(start_time) > 0 {
6532
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6533
+		if err != nil {
6534
+			fmt.Println(err)
6535
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6536
+			return
6537
+		}
6538
+		startTime = theTime.Unix()
6539
+	}
6540
+	var endTime int64
6541
+	if len(end_time) > 0 {
6542
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
6543
+		if err != nil {
6544
+			utils.ErrorLog(err.Error())
6545
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
6546
+			return
6547
+		}
6548
+		endTime = theTime.Unix()
6549
+	}
6550
+	orgId := this.GetAdminUserInfo().CurrentOrgId
6551
+
6552
+	advice_name := this.GetString("advice_name")
6553
+
6554
+	adviceList, _ := service.GetPatientAdviceListDetail(patient_id, startTime, endTime, orgId, advice_name)
6555
+
6556
+	this.ServeSuccessJSON(map[string]interface{}{
6557
+		"adviceList": adviceList,
6558
+	})
6559
+
6560
+}

+ 23 - 3
controllers/stock_in_api_controller.go View File

@@ -7474,12 +7474,13 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7474 7474
 	checker := this.GetAdminUserInfo().AdminUser.Id
7475 7475
 	//更改审核状态
7476 7476
 	err := service.UpdateNewCheckWarehouseInfo(warehousing_info_id, checker, tx)
7477
+	var is_success = 2
7477 7478
 	if err == nil {
7478 7479
 		list, _ := service.GetNewWarehouseInfoList(warehousing_info_id, orgId, tx)
7479 7480
 
7480 7481
 		for _, item := range list {
7482
+			var now_count = item.WarehousingCount
7481 7483
 			service.UpdateNewWarehouseInfoByIdListThree(item.WarehousingCount, item.ID, tx)
7482
-
7483 7484
 			//查询该耗材剩余库存库
7484 7485
 			stockList, _ := service.GetNewStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, orgId, tx)
7485 7486
 			var total_count int64
@@ -7562,10 +7563,29 @@ func (this *StockManagerApiController) CheckWarehouseInfo() {
7562 7563
 			if stockCount.ID > 0 {
7563 7564
 				service.UpdateNewGoodStockCount(orgId, item.StorehouseId, item.GoodId, item.WarehousingCount, flush_count, tx)
7564 7565
 			}
7566
+
7567
+			//查询该耗材的流水数量
7568
+			goodFlowList, _ := service.GetInitGoodFlow(orgId, item.GoodId, item.ID, tx)
7569
+
7570
+			var flow_count int64
7571
+			if len(goodFlowList) > 0 {
7572
+				for _, item := range goodFlowList {
7573
+					flow_count += item.Count
7574
+				}
7575
+			}
7576
+
7577
+			if now_count != flow_count {
7578
+				is_success = 1
7579
+				tx.Rollback()
7580
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFlow)
7581
+				return
7582
+			}
7583
+
7565 7584
 		}
7566 7585
 	}
7567
-
7568
-	tx.Commit()
7586
+	if is_success != 1 {
7587
+		tx.Commit()
7588
+	}
7569 7589
 
7570 7590
 	if err == nil {
7571 7591
 		this.ServeSuccessJSON(map[string]interface{}{

+ 1 - 1
service/mobile_dialysis_service.go View File

@@ -8269,7 +8269,7 @@ func GetDialysisTotalCountOne(org_id int64, patient_id int64) (models.BloodDialy
8269 8269
 	order := models.BloodDialysisOrderCount{}
8270 8270
 	db := XTReadDB().Table("xt_dialysis_order as o")
8271 8271
 
8272
-	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1704038400 and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
8272
+	err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date>=1735660800 and  x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id).Scan(&order).Error
8273 8273
 
8274 8274
 	return order, err
8275 8275
 }

+ 85 - 1
service/stock_service.go View File

@@ -9176,6 +9176,18 @@ func UpdateNewDrugMaxNumber(count int64, id int64, tx *gorm.DB) error {
9176 9176
 	return err
9177 9177
 }
9178 9178
 
9179
+func UpdateNewDrugMaxNumberOne(count int64, id int64, tx *gorm.DB) error {
9180
+
9181
+	err := tx.Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
9182
+	if err != gorm.ErrRecordNotFound {
9183
+		if err != nil {
9184
+			tx.Rollback()
9185
+			return err
9186
+		}
9187
+	}
9188
+	return err
9189
+}
9190
+
9179 9191
 func UpdateDrugMinNumber(count int64, id int64) error {
9180 9192
 	err := XTWriteDB().Model(&models.DrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
9181 9193
 	return err
@@ -10903,7 +10915,7 @@ func GetHisDrugCodeQuery(orgId int64, start_time int64, end_time int64, limit in
10903 10915
 		db = db.Where("is_upload = 2 or is_upload =0")
10904 10916
 	}
10905 10917
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("record_date desc").Find(&list).Error
10906
-	fmt.Println("totla====================", total)
10918
+
10907 10919
 	return list, total, err
10908 10920
 }
10909 10921
 
@@ -10926,3 +10938,75 @@ func GetNewGoodWarehouseOutInfo(good_id int64, user_org_id int64, warehouse_out_
10926 10938
 	}
10927 10939
 	return info, err
10928 10940
 }
10941
+
10942
+func GetInitGoodFlow(user_org_id int64, good_id int64, warehousing_detail_id int64, tx *gorm.DB) (list []*models.VmStockFlow, err error) {
10943
+
10944
+	err = tx.Where("user_org_id = ? and good_id = ? and warehousing_detail_id = ? and status=1", user_org_id, good_id, warehousing_detail_id).Find(&list).Error
10945
+
10946
+	if err != gorm.ErrRecordNotFound {
10947
+		if err != nil {
10948
+			tx.Rollback()
10949
+			return list, err
10950
+		}
10951
+	}
10952
+	return list, err
10953
+}
10954
+
10955
+func GetNewDrugFlowList(drug_id int64, user_org_id int64, warehousing_detail_id int64, tx *gorm.DB) (flow []*models.DrugFlow, err error) {
10956
+
10957
+	err = tx.Where("drug_id = ? and user_org_id =? and warehousing_detail_id = ? and status=1", drug_id, user_org_id, warehousing_detail_id).Find(&flow).Error
10958
+	if err != gorm.ErrRecordNotFound {
10959
+		if err != nil {
10960
+			tx.Rollback()
10961
+			return flow, err
10962
+		}
10963
+	}
10964
+	return flow, err
10965
+}
10966
+
10967
+func GetNewPatientAdviceList(patient_id int64, start_time int64, end_time int64, user_org_id int64) (advice []*models.DoctorAdvice, err error) {
10968
+
10969
+	db := XTReadDB().Model(&advice).Where("status=1 and advice_type =2")
10970
+
10971
+	if patient_id > 0 {
10972
+		db = db.Where("patient_id = ?", patient_id)
10973
+	}
10974
+	if start_time > 0 {
10975
+		db = db.Where("advice_date>=?", start_time)
10976
+	}
10977
+	if end_time > 0 {
10978
+		db = db.Where("advice_date<=?", end_time)
10979
+	}
10980
+	if user_org_id > 0 {
10981
+		db = db.Where("user_org_id = ?", user_org_id)
10982
+	}
10983
+	err = db.Find(&advice).Error
10984
+
10985
+	return advice, err
10986
+}
10987
+
10988
+func GetPatientAdviceListDetail(patient_id int64, start_time int64, end_time int64, user_org_id int64, advice_name string) (advice []*models.DoctorAdvice, err error) {
10989
+
10990
+	db := XTReadDB().Model(&advice).Where("status = 1")
10991
+
10992
+	if patient_id > 0 {
10993
+		db = db.Where("patient_id = ?", patient_id)
10994
+	}
10995
+	if start_time > 0 {
10996
+		db = db.Where("advice_date>=?", start_time)
10997
+	}
10998
+
10999
+	if end_time > 0 {
11000
+		db = db.Where("advice_date<=?", end_time)
11001
+	}
11002
+
11003
+	if user_org_id > 0 {
11004
+		db = db.Where("user_org_id = ?", user_org_id)
11005
+	}
11006
+	if len(advice_name) > 0 {
11007
+		db = db.Where("advice_name =?", advice_name)
11008
+	}
11009
+	err = db.Order("advice_date asc").Find(&advice).Error
11010
+
11011
+	return advice, err
11012
+}