Browse Source

2024/6/17

28169 8 months ago
parent
commit
fe52c914d2

BIN
XT_New.exe View File


+ 6 - 6
controllers/base_api_controller.go View File

@@ -83,7 +83,7 @@ func (this *BaseAuthAPIController) Prepare() {
83 83
 		userAdmin.ModifyTime = 1530786071
84 84
 		var subscibe models.ServeSubscibe
85 85
 		subscibe.ID = 11
86
-		subscibe.OrgId = 10653 //机构id
86
+		subscibe.OrgId = 10580 //机构id
87 87
 		subscibe.PeriodStart = 1547447814
88 88
 		subscibe.PeriodEnd = 1550039814
89 89
 		subscibe.State = 1
@@ -93,8 +93,8 @@ func (this *BaseAuthAPIController) Prepare() {
93 93
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
94 94
 		subscibes[4] = &subscibe
95 95
 		var adminUserInfo service.AdminUserInfo
96
-		adminUserInfo.CurrentOrgId = 10653 //机构id小英9675或4
97
-		adminUserInfo.CurrentAppId = 12123 //4
96
+		adminUserInfo.CurrentOrgId = 10580 //机构id小英9675或4
97
+		adminUserInfo.CurrentAppId = 17997 //4
98 98
 		adminUserInfo.AdminUser = &userAdmin
99 99
 		adminUserInfo.Subscibes = subscibes
100 100
 		this.SetSession("admin_user_info", &adminUserInfo)
@@ -329,7 +329,7 @@ func (this *BaseServeAPIController) Prepare() {
329 329
 		userAdmin.ModifyTime = 1530786071
330 330
 		var subscibe models.ServeSubscibe
331 331
 		subscibe.ID = 11
332
-		subscibe.OrgId = 10653 //机构id小英9675或4
332
+		subscibe.OrgId = 10580 //机构id小英9675或4
333 333
 		subscibe.PeriodStart = 1538035409
334 334
 		subscibe.PeriodEnd = 1569571409
335 335
 		subscibe.State = 1
@@ -339,8 +339,8 @@ func (this *BaseServeAPIController) Prepare() {
339 339
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
340 340
 		subscibes[4] = &subscibe
341 341
 		var adminUserInfo service.AdminUserInfo
342
-		adminUserInfo.CurrentOrgId = 10653 //机构id小英9675或4
343
-		adminUserInfo.CurrentAppId = 12123 //4
342
+		adminUserInfo.CurrentOrgId = 10580 //机构id小英9675或4
343
+		adminUserInfo.CurrentAppId = 17997 //4
344 344
 		adminUserInfo.AdminUser = &userAdmin
345 345
 		adminUserInfo.Subscibes = subscibes
346 346
 		this.SetSession("admin_user_info", &adminUserInfo)

+ 77 - 87
controllers/his_api_controller.go View File

@@ -1909,29 +1909,6 @@ func (c *HisApiController) CreateHisPrescription() {
1909 1909
 					}
1910 1910
 				}
1911 1911
 
1912
-				//if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
1913
-				//	advices := items["advices"].([]interface{})
1914
-				//
1915
-				//	if len(advices) > 0 {
1916
-				//		for _, advice := range advices {
1917
-				//
1918
-				//			var adviceId int64
1919
-				//			if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1920
-				//				adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1921
-				//			}
1922
-				//			if adviceId > 0 {
1923
-				//				his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
1924
-				//
1925
-				//				if err == nil {
1926
-				//					if his_advice_info.IsMedicine == 1 {
1927
-				//
1928
-				//						isMidicine = true
1929
-				//					}
1930
-				//				}
1931
-				//			}
1932
-				//		}
1933
-				//	}
1934
-				//}
1935 1912
 			}
1936 1913
 		}
1937 1914
 	}
@@ -2185,6 +2162,7 @@ func (c *HisApiController) CreateHisPrescription() {
2185 2162
 	}
2186 2163
 
2187 2164
 	//已发药和已收费限制逻辑
2165
+	//执行出库的逻辑
2188 2166
 	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
2189 2167
 		//校验库存总量
2190 2168
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
@@ -2303,6 +2281,7 @@ func (c *HisApiController) CreateHisPrescription() {
2303 2281
 									}
2304 2282
 								}
2305 2283
 
2284
+								//不是保存处方出库
2306 2285
 								drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
2307 2286
 								if drugOutConfig.IsOpen != 1 {
2308 2287
 									//修改处方
@@ -2355,6 +2334,12 @@ func (c *HisApiController) CreateHisPrescription() {
2355 2334
 											batch_number_counts := strconv.FormatInt(batch_number_count, 10)
2356 2335
 
2357 2336
 											all_count, _ := strconv.ParseFloat(totals, 64)
2337
+
2338
+											if all_count == 0 {
2339
+												tx.Rollback()
2340
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
2341
+												return
2342
+											}
2358 2343
 											if prescribingNumberUnit == drug.MinUnit {
2359 2344
 												batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
2360 2345
 												if drug.IsUse != 1 {
@@ -2426,21 +2411,26 @@ func (c *HisApiController) CreateHisPrescription() {
2426 2411
 												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
2427 2412
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
2428 2413
 												device_number = prescribingNumberInt * drug.MinNumber
2414
+
2429 2415
 											}
2430 2416
 											if advicelist.PrescribingNumberUnit == drug.MinUnit {
2431 2417
 												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
2432 2418
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
2433 2419
 												device_number = prescribingNumberInt
2420
+
2421
+												//回退库存
2434 2422
 											}
2435 2423
 
2436 2424
 											var number_count int64
2437 2425
 											if prescribingNumberUnit == drug.MaxUnit {
2438 2426
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2439 2427
 												number_count = prescribingNumberInt * drug.MinNumber
2428
+												//回退库存
2440 2429
 											}
2441 2430
 											if prescribingNumberUnit == drug.MinUnit {
2442 2431
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2443 2432
 												number_count = prescribingNumberInt
2433
+												//回退库存
2444 2434
 											}
2445 2435
 
2446 2436
 											//如果修改的数量大于之前修改的数量
@@ -2499,7 +2489,6 @@ func (c *HisApiController) CreateHisPrescription() {
2499 2489
 															var sum_in_count int64
2500 2490
 															warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
2501 2491
 															sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
2502
-															fmt.Println("sum_in_count", sum_in_count)
2503 2492
 															//如果修改的数量大于有库存的第一个批次
2504 2493
 															if number_count > sum_in_count {
2505 2494
 																tx.Rollback()
@@ -2512,60 +2501,69 @@ func (c *HisApiController) CreateHisPrescription() {
2512 2501
 												}
2513 2502
 
2514 2503
 											}
2515
-											pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
2516
-
2517
-											if pharmacyConfig.IsOpen != 1 {
2518
-												if device_number != number_count {
2519
-
2520
-													// 查询该药品最后一次出库记录
2521
-													druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
2522
-
2523
-													//回退库存
2524
-													if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
2525
-
2526
-														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
2527
-
2528
-													}
2529
-													if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
2530
-														var stock_max_number int64
2531
-														var stock_min_number int64
2532
-
2533
-														if number_count >= drug.MinNumber {
2534
-
2535
-															stock_max_number = device_number / drug.MinNumber
2536
-															service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
2537
-
2538
-															stock_min_number = device_number % drug.MinNumber
2539
-															service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
2540
-
2541
-														} else {
2542
-
2543
-															service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
2544
-
2545
-														}
2546
-													}
2547
-
2548
-													if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
2549
-														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
2550
-
2551
-													}
2552
-													//删除记录
2553
-													service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
2554
-
2555
-													//查询默认仓库剩余多少库存
2556
-													var sum_count int64
2557
-													stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
2558
-													for _, its := range stockInfo {
2559
-														if its.MaxUnit == drug.MaxUnit {
2560
-															its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
2561
-														}
2562
-														sum_count += its.StockMaxNumber + its.StockMinNumber
2563
-													}
2564 2504
 
2565
-													service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
2566
-
2567
-												}
2568
-											}
2505
+											//药品发药
2506
+											//pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
2507
+											//不使用药品发药的功能
2508
+											//if pharmacyConfig.IsOpen != 1 {
2509
+											//	if device_number != number_count {
2510
+											//
2511
+											//		//查询该药品的出库记录
2512
+											//		outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
2513
+											//		if len(outListExport) > 0 {
2514
+											//			//
2515
+											//			for _, item := range outListExport {
2516
+											//				//回退库存
2517
+											//				if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
2518
+											//					service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
2519
+											//				}
2520
+											//				if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
2521
+											//					var stock_max_number int64
2522
+											//					var stock_min_number int64
2523
+											//
2524
+											//					if number_count >= drug.MinNumber {
2525
+											//
2526
+											//						stock_max_number = device_number / drug.MinNumber
2527
+											//						service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
2528
+											//
2529
+											//						stock_min_number = device_number % drug.MinNumber
2530
+											//						service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
2531
+											//
2532
+											//					} else {
2533
+											//
2534
+											//						service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
2535
+											//
2536
+											//					}
2537
+											//				}
2538
+											//
2539
+											//				if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
2540
+											//					service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
2541
+											//				}
2542
+											//			}
2543
+											//		}
2544
+											//
2545
+											//		service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
2546
+											//		var sum_count int64
2547
+											//		orgId := c.GetAdminUserInfo().CurrentOrgId
2548
+											//		stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
2549
+											//		for _, its := range stockInfo {
2550
+											//			if its.MaxUnit == drug.MaxUnit {
2551
+											//				its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
2552
+											//			}
2553
+											//			sum_count += its.StockMaxNumber + its.StockMinNumber
2554
+											//		}
2555
+											//		//更新字典里面的库存
2556
+											//		service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
2557
+											//
2558
+											//		//剩余库存
2559
+											//		service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
2560
+											//
2561
+											//		over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
2562
+											//		//减少出库数量
2563
+											//		service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
2564
+											//
2565
+											//	}
2566
+											//}
2569 2567
 
2570 2568
 										}
2571 2569
 									}
@@ -2707,9 +2705,7 @@ func (c *HisApiController) CreateHisPrescription() {
2707 2705
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2708 2706
 												number_count = prescribingNumberInt
2709 2707
 											}
2710
-											fmt.Println("number_count--------------", number_count)
2711
-											fmt.Println("device_number--------------", device_number)
2712
-											fmt.Println("batch_number_count", batch_number_count)
2708
+
2713 2709
 											//如果修改的数量大于之前修改的数量
2714 2710
 											if (number_count - device_number) > 0 {
2715 2711
 												//如果修改的差数量 大于库存数量
@@ -3180,7 +3176,7 @@ func (c *HisApiController) CreateHisPrescription() {
3180 3176
 	var adviceList []models.HisDoctorAdviceInfo
3181 3177
 	var projectList []models.HisPrescriptionProject
3182 3178
 
3183
-	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 {
3179
+	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 {
3184 3180
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
3185 3181
 			prescriptions, _ := dataBody["prescriptions"].([]interface{})
3186 3182
 
@@ -3554,17 +3550,11 @@ func (c *HisApiController) CreateHisPrescription() {
3554 3550
 													history_count += prescribingNumberSevenTy
3555 3551
 												}
3556 3552
 
3557
-												fmt.Println("drug_nam,e---------------", drug.DrugName)
3558
-												fmt.Println("local_count0000000000000000000000000000000000000000000", local_count)
3559
-												fmt.Println("history_count999999999999999999999999999999999999999", history_count)
3560
-
3561 3553
 												//如果当前出库数量大于历史出库数量则需要出库
3562 3554
 												if local_count > history_count {
3563 3555
 													//按最小单位出库
3564 3556
 													var cha_count = local_count - history_count
3565 3557
 
3566
-													//fmt.Println("cha_count000000000000000000000000000", cha_count)
3567
-
3568 3558
 													newadviceInfo.PrescribingNumber = float64(cha_count)
3569 3559
 													newadviceInfo.PrescribingNumberUnit = drug.MinUnit
3570 3560
 

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

@@ -87,7 +87,7 @@ func (this *DialysisAPIController) Scheduals() {
87 87
 	defer redis.Close()
88 88
 
89 89
 	key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
90
-	//redis.Set(key, "", time.Second)
90
+	redis.Set(key, "", time.Second)
91 91
 	scheduals_json_str, _ := redis.Get(key).Result()
92 92
 
93 93
 	patients, _ := service.GetAllPatientListSix(orgID)
@@ -10760,6 +10760,55 @@ func (c *DialysisAPIController) MobileCoverSch() {
10760 10760
 	}
10761 10761
 }
10762 10762
 
10763
-//func BatchExectime() {
10764
-//
10765
-//}
10763
+func (c *DialysisAPIController) BatchCheckAdvice() {
10764
+
10765
+	patient_id, _ := c.GetInt64("patient_id")
10766
+
10767
+	advice_date, _ := c.GetInt64("advice_date")
10768
+
10769
+	org_id := c.GetMobileAdminUserInfo().Org.Id
10770
+
10771
+	creater := c.GetMobileAdminUserInfo().AdminUser.Id
10772
+
10773
+	//查询是his系统还是血透系统
10774
+	_, configs := service.FindXTHisRecordByOrgId(org_id)
10775
+
10776
+	//his客户
10777
+	if configs.IsOpen == 1 {
10778
+
10779
+		adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
10780
+		for _, item := range adviceList {
10781
+			service.BatchCheckHisAdvice(item.ID, creater)
10782
+		}
10783
+		projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
10784
+		for _, item := range projectList {
10785
+			service.BatchCheckProject(item.ID, creater)
10786
+		}
10787
+
10788
+		c.ServeSuccessJSON(map[string]interface{}{
10789
+			"adviceList":  adviceList,
10790
+			"projectList": projectList,
10791
+		})
10792
+
10793
+	}
10794
+
10795
+	if configs.IsOpen != 1 {
10796
+
10797
+		adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
10798
+
10799
+		for _, item := range adviceList {
10800
+			service.BatchAdviceList(item.ID, creater)
10801
+		}
10802
+		projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
10803
+		for _, item := range projectList {
10804
+			service.BatchCheckProject(item.ID, creater)
10805
+		}
10806
+
10807
+		c.ServeSuccessJSON(map[string]interface{}{
10808
+			"adviceList":  adviceList,
10809
+			"projectList": projectList,
10810
+		})
10811
+	}
10812
+
10813
+	return
10814
+}

+ 1 - 2
controllers/mobile_api_controllers/mobile_api_router_register.go View File

@@ -212,6 +212,5 @@ func MobileAPIControllersRegisterRouters() {
212 212
 
213 213
 	beego.Router("/m/api/sch/coversch", &DialysisAPIController{}, "Get:MobileCoverSch")
214 214
 
215
-	//beego.Router("/m/api/batchandleexectime", &DialysisAPIController{}, "Get:BatchExectime")
216
-
215
+	beego.Router("/m/api/batchcheckadvice", &DialysisAPIController{}, "Get:BatchCheckAdvice")
217 216
 }

+ 127 - 7
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -1354,8 +1354,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1354 1354
 				}
1355 1355
 			}
1356 1356
 
1357
-			//err = service.SaveHisDoctorAdvice(item)
1358
-
1359 1357
 			service.SaveHisDoctorAdviceOne(item, tx)
1360 1358
 
1361 1359
 			//记录日志
@@ -1504,15 +1502,22 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1504 1502
 					list, _ := service.GetDrugTotalCountTwoTwety(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut, tx)
1505 1503
 
1506 1504
 					//判断单位是否相等
1507
-					if medical.MaxUnit == advice.PrescribingNumberUnit {
1505
+					if medical.MaxUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
1508 1506
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1509 1507
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1510 1508
 						//转化为最小单位
1511 1509
 						total = list.Count*medical.MinNumber + list.StockMinNumber
1512 1510
 						prescribing_number_total = count * medical.MinNumber
1513 1511
 					}
1514
-					//fmt.Println("医嘱开的数量", total)
1515
-					if medical.MinUnit == advice.PrescribingNumberUnit {
1512
+
1513
+					if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit != medical.MinUnit {
1514
+						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1515
+						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1516
+						total = list.Count*medical.MinNumber + list.StockMinNumber
1517
+						prescribing_number_total = count
1518
+					}
1519
+
1520
+					if medical.MinUnit == advice.PrescribingNumberUnit && medical.MaxUnit == medical.MinUnit {
1516 1521
 						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1517 1522
 						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1518 1523
 						total = list.Count*medical.MinNumber + list.StockMinNumber
@@ -1637,8 +1642,122 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1637 1642
 								}
1638 1643
 								if pharmacyConfig.IsOpen != 1 {
1639 1644
 
1640
-									//service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1641
-									service.NewHisDrugsDelivery(adminInfo.Org.Id, creater, &advice, tx)
1645
+									//查询已经出库数量
1646
+
1647
+									outListExport, _ := service.GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
1648
+
1649
+									var out_count int64
1650
+									if len(outListExport) > 0 {
1651
+										for _, item := range outListExport {
1652
+											if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
1653
+												out_count = item.Count * medical.MinNumber
1654
+											}
1655
+											if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
1656
+												out_count = item.Count
1657
+											}
1658
+											if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
1659
+												out_count = item.Count * medical.MinNumber
1660
+											}
1661
+
1662
+										}
1663
+									}
1664
+
1665
+									newadviceInfo := &models.HisDoctorAdviceInfo{
1666
+										ID:                    advice.ID,
1667
+										UserOrgId:             advice.UserOrgId,
1668
+										PatientId:             advice.PatientId,
1669
+										HisPatientId:          advice.HisPatientId,
1670
+										AdviceType:            advice.AdviceType,
1671
+										AdviceDate:            advice.AdviceDate,
1672
+										StartTime:             advice.StartTime,
1673
+										AdviceName:            advice.AdviceName,
1674
+										AdviceDesc:            advice.AdviceDesc,
1675
+										ReminderDate:          advice.ReminderDate,
1676
+										SingleDose:            advice.SingleDose,
1677
+										SingleDoseUnit:        advice.SingleDoseUnit,
1678
+										PrescribingNumber:     advice.PrescribingNumber,
1679
+										PrescribingNumberUnit: advice.PrescribingNumberUnit,
1680
+										DeliveryWay:           advice.DeliveryWay,
1681
+										ExecutionFrequency:    advice.ExecutionFrequency,
1682
+										AdviceDoctor:          advice.AdviceDoctor,
1683
+										Status:                advice.Status,
1684
+										CreatedTime:           advice.CreatedTime,
1685
+										UpdatedTime:           advice.UpdatedTime,
1686
+										AdviceAffirm:          advice.AdviceAffirm,
1687
+										Remark:                advice.Remark,
1688
+										StopTime:              advice.StopTime,
1689
+										StopReason:            advice.StopReason,
1690
+										StopDoctor:            advice.StopDoctor,
1691
+										StopState:             advice.StopState,
1692
+										ParentId:              advice.ParentId,
1693
+										ExecutionTime:         advice.ExecutionTime,
1694
+										ExecutionStaff:        advice.ExecutionStaff,
1695
+										ExecutionState:        advice.ExecutionState,
1696
+										Checker:               advice.Checker,
1697
+										RecordDate:            advice.RecordDate,
1698
+										DialysisOrderId:       advice.DialysisOrderId,
1699
+										CheckTime:             advice.CheckTime,
1700
+										CheckState:            advice.CheckState,
1701
+										DrugSpec:              advice.DrugSpec,
1702
+										DrugSpecUnit:          advice.DrugSpecUnit,
1703
+										Groupno:               advice.Groupno,
1704
+										RemindType:            advice.RemindType,
1705
+										FrequencyType:         advice.FrequencyType,
1706
+										DayCount:              advice.DayCount,
1707
+										WeekDay:               advice.WeekDay,
1708
+										TemplateId:            advice.TemplateId,
1709
+										Modifier:              advice.Modifier,
1710
+										DrugId:                advice.DrugId,
1711
+										Price:                 advice.Price,
1712
+										PrescriptionId:        advice.PrescriptionId,
1713
+										MedListCodg:           advice.MedListCodg,
1714
+										FeedetlSn:             advice.FeedetlSn,
1715
+										Day:                   advice.DayCount,
1716
+										ChildDoctorAdvice:     nil,
1717
+										Drug:                  models.Drug{},
1718
+										Diagnosis:             advice.Diagnosis,
1719
+										Way:                   advice.Way,
1720
+										HospApprFlag:          advice.HospApprFlag,
1721
+										LmtUsedFlag:           advice.LmtUsedFlag,
1722
+										HisOrderInfo:          models.HisOrderInfo{},
1723
+										IsMedicine:            advice.IsMedicine,
1724
+										ExecutionFrequencyId:  advice.ExecutionFrequencyId,
1725
+										Child:                 nil,
1726
+										IsSettle:              advice.IsSettle,
1727
+										IsMobile:              advice.IsMobile,
1728
+										IsSelfDrug:            advice.IsSelfDrug,
1729
+										DrugWayCount:          advice.DrugWayCount,
1730
+									}
1731
+
1732
+									//如果当前医嘱数量大于历史出库数据则需要出库
1733
+									if prescribing_number_total > out_count {
1734
+
1735
+										//按最小单位出库
1736
+										var cha_count = prescribing_number_total - out_count
1737
+
1738
+										newadviceInfo.PrescribingNumber = float64(cha_count)
1739
+										newadviceInfo.PrescribingNumberUnit = medical.MinUnit
1740
+
1741
+										service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
1742
+
1743
+									}
1744
+
1745
+									//如果当前医嘱数量小于历史出库数据则需要退库
1746
+									if prescribing_number_total < out_count {
1747
+										var cha_count = out_count - prescribing_number_total
1748
+										drug, _ := service.FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
1749
+										service.NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
1750
+										service.NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
1751
+
1752
+									}
1753
+
1754
+									if prescribing_number_total == out_count {
1755
+										if out_count == 0 {
1756
+											service.NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
1757
+										}
1758
+
1759
+									}
1760
+
1642 1761
 									if adminInfo.Org.Id == 3877 || adminInfo.Org.Id == 10265 {
1643 1762
 										//查询该药品是否有出库记录
1644 1763
 										flowMap, _ := service.GetDrugFLowByAdviceByIdOne(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate, tx)
@@ -1695,6 +1814,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1695 1814
 
1696 1815
 			}
1697 1816
 		}
1817
+
1698 1818
 		tx.Commit()
1699 1819
 		for _, item := range advices {
1700 1820
 			advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)

+ 16 - 4
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go View File

@@ -2969,7 +2969,7 @@ func (this *NewDialysisApiController) GetNextInspectionDetail() {
2969 2969
 	org_id := this.GetMobileAdminUserInfo().Org.Id
2970 2970
 
2971 2971
 	inspection, _ := service.GetNextInspection(patients.BloodId, date, project_id, org_id)
2972
-	fmt.Println("inspection", inspection.InspectDate)
2972
+
2973 2973
 	if inspection.InspectDate > 0 {
2974 2974
 		InspectionDetail, err := service.GetLastInspectionDetail(patients.BloodId, inspection.InspectDate, project_id, org_id)
2975 2975
 		if err != nil {
@@ -2994,7 +2994,8 @@ func (this *NewDialysisApiController) GetInspectionGroup() {
2994 2994
 
2995 2995
 	org_id := this.GetMobileAdminUserInfo().Org.Id
2996 2996
 
2997
-	inspection, _ := service.GetInspectionGroup(patient_id, org_id)
2997
+	patient, _ := service.GetPatientDetailTwo(patient_id)
2998
+	inspection, _ := service.GetInspectionGroup(patient.BloodId, org_id)
2998 2999
 
2999 3000
 	if len(inspection) > 0 {
3000 3001
 		for _, item := range inspection {
@@ -3018,9 +3019,20 @@ func (this *NewDialysisApiController) GetInspectionByProject() {
3018 3019
 
3019 3020
 	org_id := this.GetMobileAdminUserInfo().Org.Id
3020 3021
 
3021
-	inspection, _ := service.GetInspectionByProject(patient_id, project_id, org_id)
3022
+	patient, _ := service.GetPatientDetailTwo(patient_id)
3023
+
3024
+	inspection, _ := service.GetInspectionGroupByRecordDate(patient.BloodId, project_id, org_id)
3025
+
3026
+	if len(inspection) > 0 {
3027
+		for _, item := range inspection {
3028
+			inspeclist, _ := service.GetInspectionByProject(patient.BloodId, project_id, org_id, item.InspectDate)
3029
+			for _, it := range inspeclist {
3030
+				item.Child = append(item.Child, it)
3031
+			}
3032
+		}
3033
+	}
3022 3034
 
3023
-	patients, _ := service.GetPatientByIDOne(org_id, patient_id)
3035
+	patients, _ := service.GetPatientByIDOne(org_id, patient.BloodId)
3024 3036
 
3025 3037
 	this.ServeSuccessJSON(map[string]interface{}{
3026 3038
 		"inspection": inspection,

+ 253 - 2
controllers/patient_api_controller.go View File

@@ -2909,7 +2909,130 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2909 2909
 						if medical.IsUse == 2 {
2910 2910
 							if config.IsOpen != 1 {
2911 2911
 								if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
2912
-									service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
2912
+									// 开始主事务
2913
+									db := service.XTWriteDB()
2914
+									tx := db.Begin()
2915
+
2916
+									// 在函数结束时处理事务回滚
2917
+									defer func() {
2918
+										if r := recover(); r != nil {
2919
+											tx.Rollback()
2920
+										}
2921
+									}()
2922
+									creater := c.GetAdminUserInfo().AdminUser.Id
2923
+									outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
2924
+									var out_count int64
2925
+									if len(outListExport) > 0 {
2926
+										for _, item := range outListExport {
2927
+											if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
2928
+												out_count = item.Count * medical.MinNumber
2929
+											}
2930
+											if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
2931
+												out_count = item.Count
2932
+											}
2933
+											if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
2934
+												out_count = item.Count * medical.MinNumber
2935
+											}
2936
+
2937
+										}
2938
+									}
2939
+
2940
+									newadviceInfo := &models.HisDoctorAdviceInfo{
2941
+										ID:                    item.ID,
2942
+										UserOrgId:             item.UserOrgId,
2943
+										PatientId:             item.PatientId,
2944
+										HisPatientId:          item.HisPatientId,
2945
+										AdviceType:            item.AdviceType,
2946
+										AdviceDate:            item.AdviceDate,
2947
+										StartTime:             item.StartTime,
2948
+										AdviceName:            item.AdviceName,
2949
+										AdviceDesc:            item.AdviceDesc,
2950
+										ReminderDate:          item.ReminderDate,
2951
+										SingleDose:            item.SingleDose,
2952
+										SingleDoseUnit:        item.SingleDoseUnit,
2953
+										PrescribingNumber:     item.PrescribingNumber,
2954
+										PrescribingNumberUnit: item.PrescribingNumberUnit,
2955
+										DeliveryWay:           item.DeliveryWay,
2956
+										ExecutionFrequency:    item.ExecutionFrequency,
2957
+										AdviceDoctor:          item.AdviceDoctor,
2958
+										Status:                item.Status,
2959
+										CreatedTime:           item.CreatedTime,
2960
+										UpdatedTime:           item.UpdatedTime,
2961
+										AdviceAffirm:          item.AdviceAffirm,
2962
+										Remark:                item.Remark,
2963
+										StopTime:              item.StopTime,
2964
+										StopReason:            item.StopReason,
2965
+										StopDoctor:            item.StopDoctor,
2966
+										StopState:             item.StopState,
2967
+										ParentId:              item.ParentId,
2968
+										ExecutionTime:         item.ExecutionTime,
2969
+										ExecutionStaff:        item.ExecutionStaff,
2970
+										ExecutionState:        item.ExecutionState,
2971
+										Checker:               item.Checker,
2972
+										RecordDate:            item.RecordDate,
2973
+										DialysisOrderId:       item.DialysisOrderId,
2974
+										CheckTime:             item.CheckTime,
2975
+										CheckState:            item.CheckState,
2976
+										DrugSpec:              item.DrugSpec,
2977
+										DrugSpecUnit:          item.DrugSpecUnit,
2978
+										Groupno:               item.Groupno,
2979
+										RemindType:            item.RemindType,
2980
+										FrequencyType:         item.FrequencyType,
2981
+										DayCount:              item.DayCount,
2982
+										WeekDay:               item.WeekDay,
2983
+										TemplateId:            item.TemplateId,
2984
+										Modifier:              item.Modifier,
2985
+										DrugId:                item.DrugId,
2986
+										Price:                 item.Price,
2987
+										PrescriptionId:        item.PrescriptionId,
2988
+										MedListCodg:           item.MedListCodg,
2989
+										FeedetlSn:             item.FeedetlSn,
2990
+										Day:                   item.DayCount,
2991
+										ChildDoctorAdvice:     nil,
2992
+										Drug:                  models.Drug{},
2993
+										Diagnosis:             item.Diagnosis,
2994
+										Way:                   item.Way,
2995
+										HospApprFlag:          item.HospApprFlag,
2996
+										LmtUsedFlag:           item.LmtUsedFlag,
2997
+										HisOrderInfo:          models.HisOrderInfo{},
2998
+										IsMedicine:            item.IsMedicine,
2999
+										ExecutionFrequencyId:  item.ExecutionFrequencyId,
3000
+										Child:                 nil,
3001
+										IsSettle:              item.IsSettle,
3002
+										IsMobile:              item.IsMobile,
3003
+										IsSelfDrug:            item.IsSelfDrug,
3004
+										DrugWayCount:          item.DrugWayCount,
3005
+									}
3006
+
3007
+									//如果当前医嘱数量大于历史出库数据则需要出库
3008
+									if prescribing_number_total > out_count {
3009
+
3010
+										//按最小单位出库
3011
+										var cha_count = prescribing_number_total - out_count
3012
+
3013
+										item.PrescribingNumber = float64(cha_count)
3014
+										item.PrescribingNumberUnit = medical.MinUnit
3015
+
3016
+										service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
3017
+
3018
+									}
3019
+
3020
+									//如果当前医嘱数量小于历史出库数据则需要退库
3021
+									if prescribing_number_total < out_count {
3022
+										var cha_count = out_count - prescribing_number_total
3023
+										drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
3024
+										service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
3025
+										service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
3026
+
3027
+									}
3028
+
3029
+									if prescribing_number_total == out_count {
3030
+										if out_count == 0 {
3031
+											service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
3032
+										}
3033
+
3034
+									}
3035
+									//service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
2913 3036
 
2914 3037
 									if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
2915 3038
 										//查询该药品是否有出库记录
@@ -2939,10 +3062,138 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2939 3062
 											return
2940 3063
 										}
2941 3064
 									}
3065
+
3066
+									tx.Commit()
2942 3067
 								}
2943 3068
 								//不通过药房发药
2944 3069
 								if pharmacyConfig.IsOpen != 1 {
2945
-									service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
3070
+									//service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
3071
+									// 开始主事务
3072
+									db := service.XTWriteDB()
3073
+									tx := db.Begin()
3074
+
3075
+									// 在函数结束时处理事务回滚
3076
+									defer func() {
3077
+										if r := recover(); r != nil {
3078
+											tx.Rollback()
3079
+										}
3080
+									}()
3081
+									creater := c.GetAdminUserInfo().AdminUser.Id
3082
+									outListExport, _ := service.GetWarehouseOutListExport(item.DrugId, item.PatientId, item.AdviceDate, item.ID)
3083
+									var out_count int64
3084
+									if len(outListExport) > 0 {
3085
+										for _, item := range outListExport {
3086
+											if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
3087
+												out_count = item.Count * medical.MinNumber
3088
+											}
3089
+											if item.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
3090
+												out_count = item.Count
3091
+											}
3092
+											if item.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
3093
+												out_count = item.Count * medical.MinNumber
3094
+											}
3095
+
3096
+										}
3097
+									}
3098
+
3099
+									newadviceInfo := &models.HisDoctorAdviceInfo{
3100
+										ID:                    item.ID,
3101
+										UserOrgId:             item.UserOrgId,
3102
+										PatientId:             item.PatientId,
3103
+										HisPatientId:          item.HisPatientId,
3104
+										AdviceType:            item.AdviceType,
3105
+										AdviceDate:            item.AdviceDate,
3106
+										StartTime:             item.StartTime,
3107
+										AdviceName:            item.AdviceName,
3108
+										AdviceDesc:            item.AdviceDesc,
3109
+										ReminderDate:          item.ReminderDate,
3110
+										SingleDose:            item.SingleDose,
3111
+										SingleDoseUnit:        item.SingleDoseUnit,
3112
+										PrescribingNumber:     item.PrescribingNumber,
3113
+										PrescribingNumberUnit: item.PrescribingNumberUnit,
3114
+										DeliveryWay:           item.DeliveryWay,
3115
+										ExecutionFrequency:    item.ExecutionFrequency,
3116
+										AdviceDoctor:          item.AdviceDoctor,
3117
+										Status:                item.Status,
3118
+										CreatedTime:           item.CreatedTime,
3119
+										UpdatedTime:           item.UpdatedTime,
3120
+										AdviceAffirm:          item.AdviceAffirm,
3121
+										Remark:                item.Remark,
3122
+										StopTime:              item.StopTime,
3123
+										StopReason:            item.StopReason,
3124
+										StopDoctor:            item.StopDoctor,
3125
+										StopState:             item.StopState,
3126
+										ParentId:              item.ParentId,
3127
+										ExecutionTime:         item.ExecutionTime,
3128
+										ExecutionStaff:        item.ExecutionStaff,
3129
+										ExecutionState:        item.ExecutionState,
3130
+										Checker:               item.Checker,
3131
+										RecordDate:            item.RecordDate,
3132
+										DialysisOrderId:       item.DialysisOrderId,
3133
+										CheckTime:             item.CheckTime,
3134
+										CheckState:            item.CheckState,
3135
+										DrugSpec:              item.DrugSpec,
3136
+										DrugSpecUnit:          item.DrugSpecUnit,
3137
+										Groupno:               item.Groupno,
3138
+										RemindType:            item.RemindType,
3139
+										FrequencyType:         item.FrequencyType,
3140
+										DayCount:              item.DayCount,
3141
+										WeekDay:               item.WeekDay,
3142
+										TemplateId:            item.TemplateId,
3143
+										Modifier:              item.Modifier,
3144
+										DrugId:                item.DrugId,
3145
+										Price:                 item.Price,
3146
+										PrescriptionId:        item.PrescriptionId,
3147
+										MedListCodg:           item.MedListCodg,
3148
+										FeedetlSn:             item.FeedetlSn,
3149
+										Day:                   item.DayCount,
3150
+										ChildDoctorAdvice:     nil,
3151
+										Drug:                  models.Drug{},
3152
+										Diagnosis:             item.Diagnosis,
3153
+										Way:                   item.Way,
3154
+										HospApprFlag:          item.HospApprFlag,
3155
+										LmtUsedFlag:           item.LmtUsedFlag,
3156
+										HisOrderInfo:          models.HisOrderInfo{},
3157
+										IsMedicine:            item.IsMedicine,
3158
+										ExecutionFrequencyId:  item.ExecutionFrequencyId,
3159
+										Child:                 nil,
3160
+										IsSettle:              item.IsSettle,
3161
+										IsMobile:              item.IsMobile,
3162
+										IsSelfDrug:            item.IsSelfDrug,
3163
+										DrugWayCount:          item.DrugWayCount,
3164
+									}
3165
+
3166
+									//如果当前医嘱数量大于历史出库数据则需要出库
3167
+									if prescribing_number_total > out_count {
3168
+
3169
+										//按最小单位出库
3170
+										var cha_count = prescribing_number_total - out_count
3171
+
3172
+										newadviceInfo.PrescribingNumber = float64(cha_count)
3173
+										newadviceInfo.PrescribingNumberUnit = medical.MinUnit
3174
+
3175
+										service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
3176
+
3177
+									}
3178
+
3179
+									//如果当前医嘱数量小于历史出库数据则需要退库
3180
+									if prescribing_number_total < out_count {
3181
+										var cha_count = out_count - prescribing_number_total
3182
+										drug, _ := service.FindBaseDrugLibRecordSeven(item.UserOrgId, item.DrugId)
3183
+										service.NewHisDrugCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
3184
+										service.NewHisDrugAutoCancelInfo(item.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
3185
+
3186
+									}
3187
+
3188
+									if prescribing_number_total == out_count {
3189
+										if out_count == 0 {
3190
+											service.NewHisDrugsDelivery(item.UserOrgId, creater, newadviceInfo, tx)
3191
+										}
3192
+
3193
+									}
3194
+									//service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
3195
+
3196
+									tx.Commit()
2946 3197
 									if item.UserOrgId == 3877 || item.UserOrgId == 10265 {
2947 3198
 										//查询该药品是否有出库记录
2948 3199
 										flowMap, _ := service.GetDrugFLowByAdviceById(item.DrugId, item.PatientId, item.UserOrgId, item.AdviceDate)

+ 2 - 2
controllers/pharmacy_controller.go View File

@@ -446,7 +446,7 @@ func (this *PharmacyController) DispensingMedicine() {
446 446
 		}
447 447
 	}
448 448
 
449
-	if orgid != 10480 && orgid != 10188 {
449
+	if orgid != 10480 && orgid != 10188 && orgid != 10217 && orgid != 10164 && orgid != 10666 {
450 450
 		//发药
451 451
 		err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
452 452
 		if err != nil {
@@ -461,7 +461,7 @@ func (this *PharmacyController) DispensingMedicine() {
461 461
 		return
462 462
 	}
463 463
 
464
-	if orgid == 10480 || orgid == 10188 {
464
+	if orgid == 10480 || orgid == 10188 || orgid == 10217 || orgid == 10164 || orgid == 10666 {
465 465
 		//发药逻辑
466 466
 
467 467
 		service.DispensingMedicineOne(orgid, patient_id, stime, etime, creater)

+ 6 - 6
controllers/sign_api_controller.go View File

@@ -1223,7 +1223,7 @@ func (this *SignApiController) ToAutoDrug() {
1223 1223
 
1224 1224
 func (this *SignApiController) ToAutoDiagnose() {
1225 1225
 
1226
-	//orgId := this.GetAdminUserInfo().CurrentOrgId
1226
+	orgId := this.GetAdminUserInfo().CurrentOrgId
1227 1227
 
1228 1228
 	//order, _ := service.GetDialysisOrderTotalCount()
1229 1229
 	//
@@ -1238,11 +1238,11 @@ func (this *SignApiController) ToAutoDiagnose() {
1238 1238
 	//	service.UpdateAllPatient(item.BloodId, item.Diagnose, item.UserOrgId)
1239 1239
 	//}
1240 1240
 
1241
-	//list, _ := service.GetAllDialysisOrder(14749)
1242
-	//for _, item := range list {
1243
-	//	schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType)
1244
-	//	service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
1245
-	//}
1241
+	list, _ := service.GetAllDialysisOrder(14749)
1242
+	for _, item := range list {
1243
+		schedule, _ := service.GetLastScheduleByUserOrg(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType)
1244
+		service.UpdateScheduleByOrder(item.PatientId, item.DialysisDate, orgId, item.BedId, item.ZoneId, item.SchedualType, schedule.ID)
1245
+	}
1246 1246
 
1247 1247
 	//drugList, _ := service.GetAllBaseDrugList(10318)
1248 1248
 	//for _, item := range drugList {

+ 1 - 0
models/inspection_models.go View File

@@ -19,6 +19,7 @@ type Inspection struct {
19 19
 	Name         string `gorm:"-" json:"name" form:"name"`
20 20
 	DialysisNo   string `gorm:"-" json:"dialysis_no" form:"dialysis_no"`
21 21
 	Date         string `gorm:"-" json:"date" form:"date"`
22
+	Child        []*Inspection
22 23
 }
23 24
 
24 25
 func (Inspection) TableName() string {

+ 42 - 0
service/dialysis_service.go View File

@@ -2457,3 +2457,45 @@ func CreateMonitorRecordLog(log models.XtMonitorRecordLog) error {
2457 2457
 	err := XTWriteDB().Create(&log).Error
2458 2458
 	return err
2459 2459
 }
2460
+
2461
+func GetAllHisAdviceList(patient_id int64, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) {
2462
+
2463
+	err = XTReadDB().Where("patient_id = ? and advice_date =? and user_org_id = ? and status =1", patient_id, advice_date, user_org_id).Find(&advice).Error
2464
+
2465
+	return advice, err
2466
+}
2467
+
2468
+func BatchCheckHisAdvice(id int64, creater int64) error {
2469
+
2470
+	err := XTWriteDB().Model(&models.HisDoctorAdvice{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"checker": creater, "check_state": 1, "check_time": time.Now().Unix()}).Error
2471
+
2472
+	return err
2473
+}
2474
+
2475
+func BatchAdviceList(id int64, creater int64) error {
2476
+
2477
+	err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": creater, "check_state": 1, "check_time": time.Now().Unix()}).Error
2478
+
2479
+	return err
2480
+}
2481
+
2482
+func GetMobileProjectList(patient_id int64, advice_date int64, user_org_id int64) (project []*models.HisPrescriptionProject, err error) {
2483
+
2484
+	err = XTReadDB().Where("patient_id  = ? and status=1 and record_date = ? and user_org_id = ?", patient_id, advice_date, user_org_id).Find(&project).Error
2485
+
2486
+	return project, err
2487
+}
2488
+
2489
+func BatchCheckProject(id int64, creater int64) error {
2490
+
2491
+	err = XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": creater, "check_state": 1, "check_time": time.Now().Unix()}).Error
2492
+
2493
+	return err
2494
+}
2495
+
2496
+func GetAllAdviceList(patient_id int64, advice_date int64, user_org_id int64) (advice []*models.DoctorAdvice, err error) {
2497
+
2498
+	err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id = ? and status=1", patient_id, advice_date, user_org_id).Find(&advice).Error
2499
+
2500
+	return advice, err
2501
+}

+ 10 - 3
service/inspection_service.go View File

@@ -364,7 +364,7 @@ func GetInspectionGroup(patient_id int64, org_id int64) (inspection []*models.Ne
364 364
 		db = db.Where("org_id = ?", org_id)
365 365
 	}
366 366
 
367
-	err = db.Order("inspect_date desc").Group("project_id").Scan(&inspection).Error
367
+	err = db.Order("inspect_date asc").Group("project_id").Scan(&inspection).Error
368 368
 	return inspection, err
369 369
 }
370 370
 
@@ -396,9 +396,16 @@ func GetInspectionByProjectId(patient_id int64, org_id int64, project_id int64)
396 396
 
397 397
 }
398 398
 
399
-func GetInspectionByProject(patient_id int64, project_id int64, org_id int64) (inspection []*models.XtInspection, err error) {
399
+func GetInspectionGroupByRecordDate(patient_id int64, project_id int64, org_id int64) (inspetion []*models.Inspection, err error) {
400 400
 
401
-	err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ? and status=1", patient_id, project_id, org_id).Order("id desc").Find(&inspection).Error
401
+	err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ? and status=1", patient_id, project_id, org_id).Order("inspect_date asc").Limit(10).Group("inspect_date").Find(&inspetion).Error
402
+
403
+	return inspetion, err
404
+}
405
+
406
+func GetInspectionByProject(patient_id int64, project_id int64, org_id int64, record_date int64) (inspection []*models.Inspection, err error) {
407
+
408
+	err = XTReadDB().Where("patient_id = ? and project_id = ? and org_id = ? and status=1 and inspect_date =?", patient_id, project_id, org_id, record_date).Order("id desc").Find(&inspection).Error
402 409
 
403 410
 	return inspection, err
404 411
 }

+ 3 - 3
service/manage_center_service.go View File

@@ -641,7 +641,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
641 641
 				Creator:                 creater,
642 642
 				UpdateCreator:           0,
643 643
 				Status:                  1,
644
-				Ctime:                   time.Now().Unix(),
644
+				Ctime:                   info.SysRecordTime,
645 645
 				Mtime:                   0,
646 646
 				Price:                   info.Price,
647 647
 				WarehousingDetailId:     info.WarehouseInfoId,
@@ -763,7 +763,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
763 763
 				Creator:                 creater,
764 764
 				UpdateCreator:           0,
765 765
 				Status:                  1,
766
-				Ctime:                   time.Now().Unix(),
766
+				Ctime:                   info.SysRecordTime,
767 767
 				Mtime:                   0,
768 768
 				Price:                   info.Price,
769 769
 				WarehousingDetailId:     info.WarehouseInfoId,
@@ -874,7 +874,7 @@ func DrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) er
874 874
 				Creator:                 creater,
875 875
 				UpdateCreator:           0,
876 876
 				Status:                  1,
877
-				Ctime:                   time.Now().Unix(),
877
+				Ctime:                   info.SysRecordTime,
878 878
 				Mtime:                   0,
879 879
 				Price:                   info.Price,
880 880
 				WarehousingDetailId:     info.WarehouseInfoId,

+ 465 - 0
service/new_warehouse_service.go View File

@@ -5280,3 +5280,468 @@ func ReduceDrugWarehouseOut(drug_id int64, total_count int64, storehouse_id int6
5280 5280
 	ut.Commit()
5281 5281
 	return err
5282 5282
 }
5283
+
5284
+func HisStoryBloodHisDrugDeliverInfoOne(orgID int64, prescribingNumber float64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.HisDoctorAdviceInfo, hisprescribingNumber float64, unit string, tx *gorm.DB) (err error) {
5285
+
5286
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
5287
+	var deliver_number int64 = 0
5288
+
5289
+	var stock_number int64 = 0
5290
+
5291
+	var stock_number_one int64 = 0
5292
+
5293
+	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
5294
+	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
5295
+
5296
+	prescribingNumber_temp_one := strconv.FormatFloat(math.Abs(hisprescribingNumber), 'f', 0, 64)
5297
+	count_one, _ := strconv.ParseInt(prescribingNumber_temp_one, 10, 64)
5298
+
5299
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
5300
+		deliver_number = count * drup.MinNumber
5301
+
5302
+	} else {
5303
+		deliver_number = count
5304
+
5305
+	}
5306
+
5307
+	if advice.PrescribingNumberUnit == drup.MaxUnit {
5308
+		stock_number_one = count_one * drup.MinNumber
5309
+	} else {
5310
+		stock_number_one = count_one
5311
+	}
5312
+
5313
+	fmt.Println(stock_number_one)
5314
+
5315
+	// 根据先进先出原则,查询最先入库的批次,进行出库
5316
+	// 如果没有对应的库存,则报错
5317
+	storeConfig, _ := GetNewAllStoreHouseConfig(advice.UserOrgId, tx)
5318
+	lastWarehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut, tx)
5319
+
5320
+	if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
5321
+		if lastWarehouse.StockMinNumber >= drup.MinNumber {
5322
+			var stockMax int64
5323
+			var stockMin int64
5324
+			stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
5325
+			stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
5326
+
5327
+			ChangeNewMaxNumber(lastWarehouse.ID, stockMax, tx)
5328
+			UpdateNewMinNumber(lastWarehouse.ID, stockMin, tx)
5329
+
5330
+		}
5331
+	}
5332
+
5333
+	if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
5334
+
5335
+		lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
5336
+		ChangeNewMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
5337
+
5338
+	}
5339
+
5340
+	warehouse, _ := FindNewLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut, tx)
5341
+
5342
+	// 将该批次的剩余库存数量转换为拆零数量
5343
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
5344
+
5345
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
5346
+
5347
+	}
5348
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
5349
+
5350
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
5351
+
5352
+	}
5353
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
5354
+
5355
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
5356
+
5357
+	}
5358
+
5359
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
5360
+	if stock_number >= deliver_number {
5361
+
5362
+		var maxNumber int64 = 0
5363
+		var minNumber int64 = 0
5364
+
5365
+		maxNumber = deliver_number / drup.MinNumber
5366
+		minNumber = deliver_number % drup.MinNumber
5367
+
5368
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
5369
+			minNumber = maxNumber
5370
+		}
5371
+
5372
+		if drup.MaxUnit != drup.MinUnit {
5373
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
5374
+				return errors.New("库存数量不足")
5375
+			}
5376
+		}
5377
+
5378
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
5379
+
5380
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
5381
+		}
5382
+
5383
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
5384
+
5385
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5386
+		}
5387
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
5388
+
5389
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
5390
+		}
5391
+
5392
+		if warehouse.StockMaxNumber < 0 {
5393
+			warehouse.StockMaxNumber = 0
5394
+		}
5395
+		if warehouse.StockMinNumber < 0 {
5396
+			warehouse.StockMinNumber = 0
5397
+		}
5398
+
5399
+		warehouse.Mtime = time.Now().Unix()
5400
+
5401
+		//fmt.Println("hahhahahah", warehouse.StockMinNumber)
5402
+		//fmt.Println("howowowoowow", minNumber)
5403
+		if warehouse.StockMinNumber < minNumber {
5404
+
5405
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
5406
+			if warehouse.MaxUnit != warehouse.MinUnit {
5407
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
5408
+			}
5409
+			if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
5410
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
5411
+			}
5412
+		} else {
5413
+
5414
+			if minNumber > 0 {
5415
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
5416
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
5417
+				}
5418
+
5419
+			}
5420
+
5421
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
5422
+
5423
+				if warehouse.StockMinNumber > 0 {
5424
+					if warehouse.StockMinNumber-deliver_number >= 0 {
5425
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
5426
+					}
5427
+
5428
+				}
5429
+
5430
+			}
5431
+
5432
+		}
5433
+
5434
+		//fmt.Println("maxNumber", maxNumber)
5435
+		//fmt.Println("minNumber", maxNumber)
5436
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
5437
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
5438
+
5439
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
5440
+			}
5441
+
5442
+		}
5443
+
5444
+		if drup.MaxUnit != drup.MinUnit {
5445
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
5446
+				return errors.New("库存数量不足")
5447
+			}
5448
+		}
5449
+		if warehouse.StockMinNumber <= 0 {
5450
+			warehouse.StockMinNumber = 0
5451
+		}
5452
+
5453
+		//扣减库存数据
5454
+		UpDateNewDrugWarehouseInfoByStock(&warehouse, tx)
5455
+
5456
+		////查询剩余库存
5457
+		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
5458
+		var sum_count int64
5459
+		for _, its := range stockInfo {
5460
+			if its.MaxUnit == drup.MaxUnit {
5461
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
5462
+			}
5463
+			sum_count += its.StockMaxNumber + its.StockMinNumber
5464
+		}
5465
+
5466
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
5467
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
5468
+			WarehouseOutId:          warehouseout.ID,
5469
+			Status:                  1,
5470
+			Ctime:                   advice.RecordDate,
5471
+			Mtime:                   time.Now().Unix(),
5472
+			Remark:                  warehouse.Remark,
5473
+			OrgId:                   orgID,
5474
+			Type:                    1,
5475
+			Manufacturer:            warehouse.Manufacturer,
5476
+			Dealer:                  warehouse.Dealer,
5477
+			IsSys:                   1,
5478
+			SysRecordTime:           advice.RecordDate,
5479
+			DrugId:                  advice.DrugId,
5480
+			Number:                  warehouse.Number,
5481
+			BatchNumber:             warehouse.BatchNumber,
5482
+			Price:                   warehouse.RetailPrice,
5483
+			CountUnit:               drup.MinUnit,
5484
+			RetailPrice:             warehouse.RetailPrice,
5485
+			ProductDate:             warehouse.ProductDate,
5486
+			ExpiryDate:              warehouse.ExpiryDate,
5487
+			PatientId:               advice.PatientId,
5488
+			Count:                   deliver_number, //出最小单位
5489
+			WarehouseInfoId:         warehouse.ID,
5490
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
5491
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5492
+			IsCheck:                 1,
5493
+			OverCount:               sum_count,
5494
+			AdviceId:                advice.ID,
5495
+		}
5496
+
5497
+		//查询今日该药品该患者是否有出库数据
5498
+		lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
5499
+
5500
+		if lastDrugOutInfo.ID == 0 {
5501
+			AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
5502
+		}
5503
+		//如果有数量则新增数量
5504
+		if lastDrugOutInfo.ID > 0 {
5505
+
5506
+			UpdateSigleDrugWarehouseOutInfoDetail(lastDrugOutInfo.ID, warehouseOutInfo.Count, tx)
5507
+
5508
+		}
5509
+
5510
+		drugflow := models.DrugFlow{
5511
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
5512
+			WarehouseOutId:          warehouseout.ID,
5513
+			DrugId:                  advice.DrugId,
5514
+			Number:                  warehouse.Number,
5515
+			ProductDate:             warehouse.ProductDate,
5516
+			ExpireDate:              warehouse.ExpiryDate,
5517
+			Count:                   deliver_number, //按最小单位计算,
5518
+			Price:                   warehouse.RetailPrice,
5519
+			Status:                  1,
5520
+			Ctime:                   advice.AdviceDate,
5521
+			Mtime:                   time.Now().Unix(),
5522
+			UserOrgId:               orgID,
5523
+			Manufacturer:            warehouse.Manufacturer,
5524
+			Dealer:                  warehouse.Dealer,
5525
+			BatchNumber:             warehouse.BatchNumber,
5526
+			MaxUnit:                 drup.MinUnit,
5527
+			ConsumableType:          3,
5528
+			IsEdit:                  1,
5529
+			Creator:                 advice.ExecutionStaff,
5530
+			IsSys:                   1,
5531
+			PatientId:               advice.PatientId,
5532
+			SystemTime:              advice.AdviceDate,
5533
+			WarehousingDetailId:     warehouse.ID,
5534
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
5535
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5536
+			WarehouseOutDetailId:    lastDrugOutInfo.ID,
5537
+			OverCount:               sum_count,
5538
+			AdviceId:                advice.ID,
5539
+			LastPrice:               warehouse.Price,
5540
+			OperateTime:             time.Now().Unix(),
5541
+		}
5542
+
5543
+		CreateNewDrugFlowOne(drugflow, tx)
5544
+
5545
+		AddNewDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count, tx)
5546
+
5547
+		//查询是否存在数据
5548
+		details := &models.DrugAutomaticReduceDetail{
5549
+			WarehouseOutId:          warehouseout.ID,
5550
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
5551
+			PatientId:               advice.PatientId,
5552
+			Ctime:                   advice.RecordDate,
5553
+			Mtime:                   time.Now().Unix(),
5554
+			Status:                  1,
5555
+			RecordTime:              advice.RecordDate,
5556
+			OrgId:                   orgID,
5557
+			DrugId:                  advice.DrugId,
5558
+			Count:                   deliver_number,
5559
+			CountUnit:               drup.MinUnit,
5560
+			WarehouseInfoId:         warehouse.ID,
5561
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5562
+			AdviceId:                advice.ID,
5563
+		}
5564
+
5565
+		//查找是否有数据
5566
+		autoMaticReduceDetail, _ := GetDrugAutoMaticReduceDetail(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
5567
+
5568
+		if autoMaticReduceDetail.ID == 0 {
5569
+			AddNewSigleDrugAutoReduceRecordInfo(details, tx)
5570
+		}
5571
+
5572
+		if autoMaticReduceDetail.ID > 0 {
5573
+			UpdateNewSingleDrugAutoReduceRecordInfo(autoMaticReduceDetail.ID, deliver_number, tx)
5574
+		}
5575
+
5576
+		return nil
5577
+
5578
+	} else {
5579
+
5580
+		info := models.XtDrugWarehouseInfo{
5581
+			ID:                warehouse.ID,
5582
+			WarehousingId:     warehouse.WarehousingId,
5583
+			DrugId:            warehouse.DrugId,
5584
+			Number:            warehouse.Number,
5585
+			ProductDate:       warehouse.ProductDate,
5586
+			ExpiryDate:        warehouse.ExpiryDate,
5587
+			WarehousingCount:  warehouse.WarehousingCount,
5588
+			Price:             warehouse.RetailPrice,
5589
+			TotalPrice:        warehouse.TotalPrice,
5590
+			Dealer:            warehouse.Dealer,
5591
+			Manufacturer:      warehouse.Manufacturer,
5592
+			Remark:            warehouse.Remark,
5593
+			Ctime:             warehouse.Ctime,
5594
+			Mtime:             warehouse.Mtime,
5595
+			Status:            1,
5596
+			OrgId:             warehouse.OrgId,
5597
+			IsReturn:          warehouse.IsReturn,
5598
+			WarehousingOrder:  warehouse.WarehousingOrder,
5599
+			Type:              warehouse.Type,
5600
+			RetailPrice:       warehouse.RetailPrice,
5601
+			RetailTotalPrice:  warehouse.RetailPrice,
5602
+			StockMaxNumber:    0,
5603
+			StockMinNumber:    0,
5604
+			BatchNumber:       warehouse.BatchNumber,
5605
+			MaxUnit:           warehouse.MaxUnit,
5606
+			MinUnit:           drup.MinUnit,
5607
+			WarehousingInfoId: warehouse.WarehousingInfoId,
5608
+			SupplyWarehouseId: warehouse.SupplyWarehouseId,
5609
+			StorehouseId:      storeConfig.DrugStorehouseOut,
5610
+			IsCheck:           1,
5611
+		}
5612
+		//扣减库存
5613
+		UpDateNewDrugWarehouseInfoByStock(&info, tx)
5614
+
5615
+		//查询剩余库存
5616
+		stockInfo, _ := GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgID, advice.DrugId, tx)
5617
+		var sum_count int64
5618
+		for _, its := range stockInfo {
5619
+			if its.MaxUnit == drup.MaxUnit {
5620
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
5621
+			}
5622
+			sum_count += its.StockMaxNumber + its.StockMinNumber
5623
+		}
5624
+
5625
+		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
5626
+		warehouseOutInfo := &models.DrugWarehouseOutInfo{
5627
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
5628
+			WarehouseOutId:          warehouseout.ID,
5629
+			Status:                  1,
5630
+			Ctime:                   advice.RecordDate,
5631
+			Mtime:                   time.Now().Unix(),
5632
+			Remark:                  warehouse.Remark,
5633
+			OrgId:                   orgID,
5634
+			Type:                    1,
5635
+			Manufacturer:            warehouse.Manufacturer,
5636
+			Dealer:                  warehouse.Dealer,
5637
+			IsSys:                   1,
5638
+			SysRecordTime:           advice.RecordDate,
5639
+			DrugId:                  advice.DrugId,
5640
+			Number:                  warehouse.Number,
5641
+			BatchNumber:             warehouse.BatchNumber,
5642
+			Price:                   warehouse.RetailPrice,
5643
+			CountUnit:               drup.MinUnit,
5644
+			ProductDate:             warehouse.ProductDate,
5645
+			ExpiryDate:              warehouse.ExpiryDate,
5646
+			PatientId:               advice.PatientId,
5647
+			Count:                   stock_number,
5648
+			WarehouseInfoId:         warehouse.ID,
5649
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
5650
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5651
+			IsCheck:                 1,
5652
+			OverCount:               sum_count,
5653
+			AdviceId:                advice.ID,
5654
+		}
5655
+
5656
+		//查询今日该药品该患者是否有出库数据
5657
+		lastDrugOutInfo, _ := GetNewNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
5658
+
5659
+		if lastDrugOutInfo.ID == 0 {
5660
+			AddNewSigleDrugWarehouseOutInfo(warehouseOutInfo, tx)
5661
+		}
5662
+		//如果有数量则新增数量
5663
+		if lastDrugOutInfo.ID > 0 {
5664
+
5665
+			UpdateSigleDrugWarehouseOutInfoDetail(lastDrugOutInfo.ID, warehouseOutInfo.Count, tx)
5666
+
5667
+		}
5668
+
5669
+		//查询是否存在数据
5670
+		details := &models.DrugAutomaticReduceDetail{
5671
+			WarehouseOutId:          warehouseout.ID,
5672
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
5673
+			PatientId:               advice.PatientId,
5674
+			Ctime:                   advice.RecordDate,
5675
+			Mtime:                   time.Now().Unix(),
5676
+			Status:                  1,
5677
+			RecordTime:              advice.RecordDate,
5678
+			OrgId:                   orgID,
5679
+			DrugId:                  advice.DrugId,
5680
+			Count:                   stock_number,
5681
+			CountUnit:               drup.MinUnit,
5682
+			WarehouseInfoId:         warehouse.ID,
5683
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5684
+			AdviceId:                advice.ID,
5685
+		}
5686
+
5687
+		//查找是否有数据
5688
+		autoMaticReduceDetail, _ := GetDrugAutoMaticReduceDetail(advice.DrugId, advice.PatientId, advice.RecordDate, advice.UserOrgId, advice.ID, warehouse.ID, tx)
5689
+
5690
+		if autoMaticReduceDetail.ID == 0 {
5691
+			AddNewSigleDrugAutoReduceRecordInfo(details, tx)
5692
+		}
5693
+
5694
+		if autoMaticReduceDetail.ID > 0 {
5695
+			UpdateNewSingleDrugAutoReduceRecordInfo(autoMaticReduceDetail.ID, deliver_number, tx)
5696
+		}
5697
+
5698
+		drugflow := models.DrugFlow{
5699
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
5700
+			WarehouseOutId:          warehouseout.ID,
5701
+			DrugId:                  advice.DrugId,
5702
+			Number:                  warehouse.Number,
5703
+			ProductDate:             warehouse.ProductDate,
5704
+			ExpireDate:              warehouse.ExpiryDate,
5705
+			Count:                   stock_number,
5706
+			Price:                   warehouse.RetailPrice,
5707
+			Status:                  1,
5708
+			Ctime:                   advice.AdviceDate,
5709
+			Mtime:                   time.Now().Unix(),
5710
+			UserOrgId:               orgID,
5711
+			Manufacturer:            warehouse.Manufacturer,
5712
+			Dealer:                  warehouse.Dealer,
5713
+			BatchNumber:             warehouse.BatchNumber,
5714
+			MaxUnit:                 drup.MinUnit,
5715
+			ConsumableType:          3,
5716
+			IsEdit:                  1,
5717
+			Creator:                 advice.ExecutionStaff,
5718
+			IsSys:                   1,
5719
+			PatientId:               advice.PatientId,
5720
+			WarehousingDetailId:     warehouse.ID,
5721
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
5722
+			StorehouseId:            storeConfig.DrugStorehouseOut,
5723
+			WarehouseOutDetailId:    lastDrugOutInfo.ID,
5724
+			OverCount:               sum_count,
5725
+			AdviceId:                advice.ID,
5726
+			LastPrice:               warehouse.Price,
5727
+			SystemTime:              advice.AdviceDate,
5728
+			OperateTime:             time.Now().Unix(),
5729
+		}
5730
+
5731
+		CreateNewDrugFlowOne(drugflow, tx)
5732
+		//出库数量相加
5733
+		AddNewDrugCount(advice.DrugId, orgID, storeConfig.DrugStorehouseOut, drugflow.Count, tx)
5734
+
5735
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
5736
+		prescribingNumber_two_temp := deliver_number - stock_number
5737
+
5738
+		overPlusNumber := float64(prescribingNumber_two_temp)
5739
+
5740
+		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
5741
+		advice.PrescribingNumberUnit = drup.MinUnit
5742
+
5743
+		HisStoryBloodHisDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice, hisprescribingNumber, unit, tx)
5744
+	}
5745
+
5746
+	return
5747
+}

+ 1 - 1
service/pharmacy_service.go View File

@@ -869,7 +869,7 @@ func DispensingMedicineOne(orgid, patient_id, stime, etime, creater int64) (err
869 869
 			pharmacyConfig := IsPharmacyConfig(orgid)
870 870
 			if pharmacyConfig == true {
871 871
 				//扣减库存
872
-				err = HisDrugsDelivery(orgid, creater, item)
872
+				err = HisFaDrugsDelivery(orgid, creater, item)
873 873
 				if err != nil {
874 874
 					err = fmt.Errorf("!:%v", err)
875 875
 					return

+ 1 - 1
service/schedule_service.go View File

@@ -1918,7 +1918,7 @@ func UpdateMobileSchedule(id_two int64, mode_id int64, bed_id int64, zone_id int
1918 1918
 
1919 1919
 func GetPatientGoodCountToday(patient_id int64, schedule_date int64, user_org_id int64) (list []*models.WarehouseOutInfo, err error) {
1920 1920
 
1921
-	err = XTReadDB().Where("patient_id =? and sys_record_time=? and org_id = ? and status=1", patient_id, schedule_date, user_org_id).Find(&list).Error
1921
+	err = XTReadDB().Where("patient_id =? and sys_record_time=? and org_id = ? and status=1 and count>0", patient_id, schedule_date, user_org_id).Find(&list).Error
1922 1922
 	return list, err
1923 1923
 }
1924 1924
 

+ 1 - 1
service/sign_service.go View File

@@ -2112,7 +2112,7 @@ func UpdateAllPatient(id int64, diagose string, orgid int64) error {
2112 2112
 
2113 2113
 func GetAllDialysisOrder(user_org_id int64) (list []*models.XtDialysisOrder, err error) {
2114 2114
 
2115
-	err = XTReadDB().Where("patient_id = ? and status =1", 29083).Find(&list).Error
2115
+	err = XTReadDB().Where("patient_id = ? and status =1", 26973).Find(&list).Error
2116 2116
 
2117 2117
 	return list, err
2118 2118
 }

+ 21 - 0
service/stock_service.go View File

@@ -3487,6 +3487,13 @@ func UpdateSigleDrugWarehouseOutInfoDetail(id int64, count int64, tx *gorm.DB) e
3487 3487
 	return err
3488 3488
 }
3489 3489
 
3490
+func UpdateSigleDrugWarehouseOutInfoDetailOne(id int64, count int64, tx *gorm.DB) error {
3491
+
3492
+	err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"count": count}).Error
3493
+
3494
+	return err
3495
+}
3496
+
3490 3497
 func AddSigleAutoReduceRecordInfo(detail *models.AutomaticReduceDetail) error {
3491 3498
 	ut := writeDb.Begin()
3492 3499
 	err := ut.Create(&detail).Error
@@ -5924,12 +5931,26 @@ func GetHisAdviceListByDrugIdEight(drugid int64, patient_id int64, advice_date i
5924 5931
 	return info, err
5925 5932
 }
5926 5933
 
5934
+func GetHisAdviceListByDrugIdNight(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.HisDoctorAdviceInfo, error) {
5935
+
5936
+	info := models.HisDoctorAdviceInfo{}
5937
+	err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1 and id =?", drugid, patient_id, advice_date, advice_id).Find(&info).Error
5938
+	return info, err
5939
+}
5940
+
5927 5941
 func GetLastDrugWarehouseOutByDrugId(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
5928 5942
 	detail := models.DrugAutomaticReduceDetail{}
5929 5943
 	err := XTReadDB().Model(&detail).Where("drug_id = ? and patient_id = ? and record_time = ? and status = 1 and advice_id = ?", drugid, patient_id, advice_date, advice_id).Last(&detail).Error
5930 5944
 	return detail, err
5931 5945
 }
5932 5946
 
5947
+func GetWarehouseOutListExport(drug_id int64, patient_id int64, record_date int64, advice_id int64) (out []*models.XtDrugWarehouseOutInfo, err error) {
5948
+
5949
+	err = XTReadDB().Where("drug_id = ? and patient_id = ? and sys_record_time = ? and advice_id =? and status =1", drug_id, patient_id, record_date, advice_id).Find(&out).Error
5950
+
5951
+	return out, err
5952
+}
5953
+
5933 5954
 func GetLastDrugWarehouseOutByDrugIdTwenty(drugid int64, patient_id int64, advice_date int64, advice_id int64) (out []*models.DrugWarehouseOutInfo, err error) {
5934 5955
 
5935 5956
 	err = XTReadDB().Where("advice_id = ?  and drug_id = ? and patient_id = ? and sys_record_time = ? and status = 1 and is_check = 1", advice_id, drugid, patient_id, advice_date).Find(&out).Error

+ 5 - 2
service/user_service.go View File

@@ -218,7 +218,10 @@ func GetAllHisDoctor(orgid int64) (appRole []*models.App_Role, err error) {
218 218
 
219 219
 func GetDrugFlowDetailById(drug_id int64, org_id int64) (flow []*models.DrugFlow, err error) {
220 220
 
221
-	err = XTReadDB().Model(&flow).Where("drug_id = ? and status =1 and user_org_id =?", drug_id, org_id).Order("ctime asc").Find(&flow).Error
222
-
221
+	if org_id == 10217 {
222
+		err = XTReadDB().Model(&flow).Where("drug_id = ? and status =1 and user_org_id =? and system_time>=1717171200", drug_id, org_id).Order("ctime asc").Find(&flow).Error
223
+	} else {
224
+		err = XTReadDB().Model(&flow).Where("drug_id = ? and status =1 and user_org_id =?", drug_id, org_id).Order("ctime asc").Find(&flow).Error
225
+	}
223 226
 	return flow, err
224 227
 }

+ 276 - 3
service/warhouse_service.go View File

@@ -8606,7 +8606,6 @@ func ConsumableNewPrescriptionDelivery(orgID int64, patient_id int64, record_tim
8606 8606
 // 保存处方出库
8607 8607
 func ConsumableNewHisPrescriptionDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, creator int64, tx *gorm.DB) (err error) {
8608 8608
 
8609
-	fmt.Println("出库时间-------------------------------------------------", record_time)
8610 8609
 	var deliver_number int64 = 0
8611 8610
 	var stock_number int64 = 0
8612 8611
 	var maxNumber int64 = 0
@@ -8887,8 +8886,7 @@ func NewHisGoodCancelInfo(orgID int64, creater int64, project *models.HisPrescri
8887 8886
 
8888 8887
 	out_count = GoodOutInfo.Count
8889 8888
 	//如果最后1条出库数量大于退库数量,则直接退库,满足退库要求
8890
-	fmt.Println("out_count---------------------------------------", out_count)
8891
-	fmt.Println("cha_count++++++++++++++++++++++++++++++++++++++=", cha_count)
8889
+
8892 8890
 	if out_count >= cha_count {
8893 8891
 		//退库 退回 cha_count 的数量
8894 8892
 		ModifyNewGoodWarehouseInfoStockMinNumber(cha_count, GoodOutInfo.GoodId, GoodOutInfo.OrgId, GoodOutInfo.WarehouseInfotId, tx)
@@ -9169,3 +9167,278 @@ func NewHisGoodAutoCancelInfo(orgID int64, creater int64, project *models.HisPre
9169 9167
 	}
9170 9168
 	return err
9171 9169
 }
9170
+
9171
+func NewHisDrugsDeliveryOne(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo, tx *gorm.DB) (err error) {
9172
+
9173
+	// 1.判断药品是否来自专用字典的药品库
9174
+	// 2.判断当天当前机构有没有创建出库单,没有则创建
9175
+	// 3.创建出库流程
9176
+	// 3.1 实现先进先出逻辑 由于药品执行后,不可以修改和删除,所以不考虑出库后的退库和修改出库数量等
9177
+
9178
+	isHasWay := false
9179
+	record_time := int64(0)
9180
+	isHasWay = true
9181
+	record_time = advice.RecordDate
9182
+
9183
+	if isHasWay {
9184
+		//判断当天当前机构有没有创建出库单,没有则创建
9185
+		out, err := FindNewDrugStockOutByIsSys(orgID, 1, record_time, tx)
9186
+		houseConfig, _ := GetAllStoreHouseConfig(orgID)
9187
+		if err == gorm.ErrRecordNotFound {
9188
+			timeStr := time.Now().Format("2006-01-02")
9189
+			timeArr := strings.Split(timeStr, "-")
9190
+			total, _ := FindAllDrugWarehouseOut(orgID)
9191
+			total = total + 1
9192
+			warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
9193
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
9194
+			number = number + total
9195
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
9196
+
9197
+			warehouseOut := models.DrugWarehouseOut{
9198
+				WarehouseOutOrderNumber: warehousing_out_order,
9199
+				OperationTime:           time.Now().Unix(),
9200
+				OrgId:                   orgID,
9201
+				Creater:                 creater,
9202
+				Ctime:                   time.Now().Unix(),
9203
+				Status:                  1,
9204
+				WarehouseOutTime:        record_time,
9205
+				Dealer:                  0,
9206
+				Manufacturer:            0,
9207
+				Type:                    1,
9208
+				IsSys:                   1,
9209
+				StorehouseId:            houseConfig.DrugStorehouseOut,
9210
+				IsCheck:                 1,
9211
+			}
9212
+			err := AddNewSigleDrugWarehouseOut(&warehouseOut, tx)
9213
+			if err != nil {
9214
+				utils.TraceLog("创建出库单失败 err = %v", err)
9215
+				return err
9216
+			} else {
9217
+				out = warehouseOut
9218
+			}
9219
+		}
9220
+
9221
+		//出库流程
9222
+		//1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
9223
+		drup, _ := FindNewBaseDrugLibRecord(orgID, advice.DrugId, tx)
9224
+		if drup.ID > 0 {
9225
+			prescribingNumber := advice.PrescribingNumber
9226
+			HisStoryBloodHisDrugDeliverInfoOne(orgID, prescribingNumber, &out, &drup, advice, prescribingNumber, advice.PrescribingNumberUnit, tx)
9227
+
9228
+		} else {
9229
+			return errors.New("药品信息不存在")
9230
+		}
9231
+
9232
+	}
9233
+
9234
+	return
9235
+}
9236
+
9237
+func HisFaDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo) (err error) {
9238
+
9239
+	// 1.判断药品是否来自专用字典的药品库
9240
+	// 2.判断当天当前机构有没有创建出库单,没有则创建
9241
+	// 3.创建出库流程
9242
+	// 3.1 实现先进先出逻辑 由于药品执行后,不可以修改和删除,所以不考虑出库后的退库和修改出库数量等
9243
+
9244
+	isHasWay := false
9245
+	record_time := int64(0)
9246
+	isHasWay = true
9247
+	record_time = advice.RecordDate
9248
+
9249
+	if isHasWay {
9250
+		//判断当天当前机构有没有创建出库单,没有则创建
9251
+		out, err := FindDrugStockOutByIsSys(orgID, 1, record_time)
9252
+		fmt.Println(out)
9253
+		houseConfig, _ := GetAllStoreHouseConfig(orgID)
9254
+		if err == gorm.ErrRecordNotFound {
9255
+			timeStr := time.Now().Format("2006-01-02")
9256
+			timeArr := strings.Split(timeStr, "-")
9257
+			total, _ := FindAllDrugWarehouseOut(orgID)
9258
+			total = total + 1
9259
+			warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
9260
+			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
9261
+			number = number + total
9262
+			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
9263
+
9264
+			warehouseOut := models.DrugWarehouseOut{
9265
+				WarehouseOutOrderNumber: warehousing_out_order,
9266
+				OperationTime:           time.Now().Unix(),
9267
+				OrgId:                   orgID,
9268
+				Creater:                 creater,
9269
+				Ctime:                   time.Now().Unix(),
9270
+				Status:                  1,
9271
+				WarehouseOutTime:        record_time,
9272
+				Dealer:                  0,
9273
+				Manufacturer:            0,
9274
+				Type:                    1,
9275
+				IsSys:                   1,
9276
+				StorehouseId:            houseConfig.DrugStorehouseOut,
9277
+				IsCheck:                 1,
9278
+			}
9279
+			err := AddSigleDrugWarehouseOut(&warehouseOut)
9280
+			if err != nil {
9281
+				utils.TraceLog("创建出库单失败 err = %v", err)
9282
+				return err
9283
+			} else {
9284
+				out = warehouseOut
9285
+			}
9286
+		}
9287
+
9288
+		// 出库流程
9289
+		// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
9290
+		drup, _ := FindBaseDrugLibRecord(orgID, advice.DrugId)
9291
+		if drup.ID > 0 {
9292
+			//var now_count int64
9293
+			////prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
9294
+			////now_count, _ = strconv.ParseInt(prescribingNumber_temp, 10, 64)
9295
+
9296
+			var now_count int64
9297
+
9298
+			if advice.PrescribingNumberUnit == drup.MaxUnit {
9299
+				prescribingNumberOne := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
9300
+				prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
9301
+				now_count = prescribingNumberInt * drup.MinNumber
9302
+
9303
+			}
9304
+			if advice.PrescribingNumberUnit == drup.MinUnit {
9305
+				prescribingNumberOne := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
9306
+				prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
9307
+				now_count = prescribingNumberInt
9308
+
9309
+				//回退库存
9310
+			}
9311
+
9312
+			outListExport, _ := GetWarehouseOutListExport(advice.DrugId, advice.PatientId, advice.AdviceDate, advice.ID)
9313
+
9314
+			var out_count int64
9315
+			if len(outListExport) > 0 {
9316
+				for _, item := range outListExport {
9317
+					if item.CountUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
9318
+						out_count = item.Count * drup.MinNumber
9319
+					}
9320
+					if item.CountUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
9321
+						out_count = item.Count
9322
+					}
9323
+					if item.CountUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
9324
+						out_count = item.Count * drup.MinNumber
9325
+					}
9326
+
9327
+				}
9328
+			}
9329
+
9330
+			newadviceInfo := &models.HisDoctorAdviceInfo{
9331
+				ID:                    advice.ID,
9332
+				UserOrgId:             advice.UserOrgId,
9333
+				PatientId:             advice.PatientId,
9334
+				HisPatientId:          advice.HisPatientId,
9335
+				AdviceType:            advice.AdviceType,
9336
+				AdviceDate:            advice.AdviceDate,
9337
+				StartTime:             advice.StartTime,
9338
+				AdviceName:            advice.AdviceName,
9339
+				AdviceDesc:            advice.AdviceDesc,
9340
+				ReminderDate:          advice.ReminderDate,
9341
+				SingleDose:            advice.SingleDose,
9342
+				SingleDoseUnit:        advice.SingleDoseUnit,
9343
+				PrescribingNumber:     advice.PrescribingNumber,
9344
+				PrescribingNumberUnit: advice.PrescribingNumberUnit,
9345
+				DeliveryWay:           advice.DeliveryWay,
9346
+				ExecutionFrequency:    advice.ExecutionFrequency,
9347
+				AdviceDoctor:          advice.AdviceDoctor,
9348
+				Status:                advice.Status,
9349
+				CreatedTime:           advice.CreatedTime,
9350
+				UpdatedTime:           advice.UpdatedTime,
9351
+				AdviceAffirm:          advice.AdviceAffirm,
9352
+				Remark:                advice.Remark,
9353
+				StopTime:              advice.StopTime,
9354
+				StopReason:            advice.StopReason,
9355
+				StopDoctor:            advice.StopDoctor,
9356
+				StopState:             advice.StopState,
9357
+				ParentId:              advice.ParentId,
9358
+				ExecutionTime:         advice.ExecutionTime,
9359
+				ExecutionStaff:        advice.ExecutionStaff,
9360
+				ExecutionState:        advice.ExecutionState,
9361
+				Checker:               advice.Checker,
9362
+				RecordDate:            advice.RecordDate,
9363
+				DialysisOrderId:       advice.DialysisOrderId,
9364
+				CheckTime:             advice.CheckTime,
9365
+				CheckState:            advice.CheckState,
9366
+				DrugSpec:              advice.DrugSpec,
9367
+				DrugSpecUnit:          advice.DrugSpecUnit,
9368
+				Groupno:               advice.Groupno,
9369
+				RemindType:            advice.RemindType,
9370
+				FrequencyType:         advice.FrequencyType,
9371
+				DayCount:              advice.DayCount,
9372
+				WeekDay:               advice.WeekDay,
9373
+				TemplateId:            advice.TemplateId,
9374
+				Modifier:              advice.Modifier,
9375
+				DrugId:                advice.DrugId,
9376
+				Price:                 advice.Price,
9377
+				PrescriptionId:        advice.PrescriptionId,
9378
+				MedListCodg:           advice.MedListCodg,
9379
+				FeedetlSn:             advice.FeedetlSn,
9380
+				Day:                   advice.DayCount,
9381
+				ChildDoctorAdvice:     nil,
9382
+				Drug:                  models.Drug{},
9383
+				Diagnosis:             advice.Diagnosis,
9384
+				Way:                   advice.Way,
9385
+				HospApprFlag:          advice.HospApprFlag,
9386
+				LmtUsedFlag:           advice.LmtUsedFlag,
9387
+				HisOrderInfo:          models.HisOrderInfo{},
9388
+				IsMedicine:            advice.IsMedicine,
9389
+				ExecutionFrequencyId:  advice.ExecutionFrequencyId,
9390
+				Child:                 nil,
9391
+				IsSettle:              advice.IsSettle,
9392
+				IsMobile:              advice.IsMobile,
9393
+				IsSelfDrug:            advice.IsSelfDrug,
9394
+				DrugWayCount:          advice.DrugWayCount,
9395
+			}
9396
+
9397
+			db := XTWriteDB()
9398
+			tx := db.Begin()
9399
+
9400
+			// 在函数结束时处理事务回滚
9401
+			defer func() {
9402
+				if r := recover(); r != nil {
9403
+					tx.Rollback()
9404
+				} else {
9405
+					tx.Commit()
9406
+				}
9407
+			}()
9408
+
9409
+			//如果当前医嘱数量大于历史出库数据则需要出库
9410
+			if now_count > out_count {
9411
+
9412
+				//按最小单位出库
9413
+				var cha_count = now_count - out_count
9414
+
9415
+				newadviceInfo.PrescribingNumber = float64(cha_count)
9416
+				newadviceInfo.PrescribingNumberUnit = drup.MinUnit
9417
+
9418
+				NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
9419
+
9420
+			}
9421
+
9422
+			//如果当前医嘱数量小于历史出库数据则需要退库
9423
+			if now_count < out_count {
9424
+				var cha_count = out_count - now_count
9425
+				drug, _ := FindBaseDrugLibRecordSeven(advice.UserOrgId, advice.DrugId)
9426
+				NewHisDrugCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
9427
+				NewHisDrugAutoCancelInfo(advice.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
9428
+
9429
+			}
9430
+
9431
+			if now_count == out_count {
9432
+				if out_count == 0 {
9433
+					NewHisDrugsDelivery(advice.UserOrgId, creater, newadviceInfo, tx)
9434
+				}
9435
+
9436
+			}
9437
+		} else {
9438
+			return errors.New("药品信息不存在")
9439
+		}
9440
+
9441
+	}
9442
+
9443
+	return
9444
+}