Browse Source

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

test_user 2 years ago
parent
commit
c970180b2e
29 changed files with 1748 additions and 473 deletions
  1. 1 1
      conf/app.conf
  2. 15 6
      controllers/dialysis_api_controller.go
  3. 17 3
      controllers/doctors_api_controller.go
  4. 196 4
      controllers/his_api_controller.go
  5. 7 2
      controllers/mobile_api_controllers/check_weight_api_controller.go
  6. 300 244
      controllers/mobile_api_controllers/dialysis_api_controller.go
  7. 13 3
      controllers/mobile_api_controllers/patient_api_controller.go
  8. 0 6
      controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go
  9. 14 0
      controllers/new_mobile_api_controllers/mobile_his_api_controller.go
  10. 2 0
      controllers/new_mobile_api_controllers/new_mobile_api_router_register.go
  11. 28 8
      controllers/patient_api_controller.go
  12. 152 55
      controllers/pharmacy_controller.go
  13. 5 2
      controllers/print_data_api_controller.go
  14. 1 1
      controllers/self_drug_api_congtroller.go
  15. 4 0
      models/dialysis.go
  16. 3 0
      models/patient_models.go
  17. 11 0
      models/pharmacy_models.go
  18. 1 1
      routers/router.go
  19. 7 1
      service/dialysis_service.go
  20. 3 3
      service/dialysis_solution_service.go
  21. 12 0
      service/his_service.go
  22. 27 3
      service/mobile_dialysis_service.go
  23. 602 8
      service/new_warehouse_service.go
  24. 2 2
      service/patientmanage_service.go
  25. 185 115
      service/pharmacy_service.go
  26. 1 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go
  27. 8 0
      service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go
  28. 8 0
      service/stock_service.go
  29. 123 5
      service/warhouse_service.go

+ 1 - 1
conf/app.conf View File

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

+ 15 - 6
controllers/dialysis_api_controller.go View File

@@ -582,7 +582,7 @@ func (c *DialysisApiController) PostPrescription() {
582 582
 			if filedConfig.ID > 0 {
583 583
 				str = dialyzerPerfusionApparatus
584 584
 			} else {
585
-				str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
585
+				str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
586 586
 			}
587 587
 			service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
588 588
 		}
@@ -858,7 +858,8 @@ func (c *DialysisApiController) PostSoulution() {
858 858
 		if filedConfig.ID > 0 {
859 859
 			str = dialyzerPerfusionApparatus
860 860
 		} else {
861
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
861
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
862
+
862 863
 		}
863 864
 		service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
864 865
 	}
@@ -1353,6 +1354,8 @@ func (c *DialysisApiController) PostDouleCheck() {
1353 1354
 	pipeline_connection_desc := c.GetString("pipeline_connection_desc")
1354 1355
 	collator, _ := c.GetInt64("collator", 0)
1355 1356
 	employee_number := c.GetString("employee_number")
1357
+	dialyzer_batch_number := c.GetString("dialyzer_batch_number")
1358
+	needle_batch_number := c.GetString("needle_batch_number")
1356 1359
 	if id <= 0 {
1357 1360
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1358 1361
 		return
@@ -1423,6 +1426,8 @@ func (c *DialysisApiController) PostDouleCheck() {
1423 1426
 		UpdatedTime:                time.Now().Unix(),
1424 1427
 		CheckDate:                  recordDate.Unix(),
1425 1428
 		EmployeeNumber:             employee_number,
1429
+		DialyzerBatchNumber:        dialyzer_batch_number,
1430
+		NeedleBatchNumber:          needle_batch_number,
1426 1431
 	}
1427 1432
 
1428 1433
 	_, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
@@ -1460,6 +1465,7 @@ func (c *DialysisApiController) PostDouleCheck() {
1460 1465
 		doubleCheck.CreatedTime = check.CreatedTime
1461 1466
 		doubleCheck.UpdatedTime = time.Now().Unix()
1462 1467
 		doubleCheck.ID = check.ID
1468
+
1463 1469
 		redis := service.RedisClient()
1464 1470
 		err := service.UpdateDoubleCheck(&doubleCheck)
1465 1471
 		key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
@@ -4391,7 +4397,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
4391 4397
 			}
4392 4398
 
4393 4399
 			//长沙南雅
4394
-			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 {
4400
+			if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
4395 4401
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
4396 4402
 
4397 4403
 				record.UltrafiltrationRate = ultrafiltration_rate
@@ -4420,7 +4426,7 @@ func (this *DialysisApiController) GetTodayMonitor() {
4420 4426
 	}
4421 4427
 
4422 4428
 	//长沙南雅
4423
-	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 {
4429
+	if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
4424 4430
 
4425 4431
 		if ultrafiltration_rate > 0 {
4426 4432
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
@@ -6033,14 +6039,17 @@ func (this *DialysisApiController) GetDialysisAdviceToday() {
6033 6039
 
6034 6040
 	schedule_type, _ := this.GetInt64("schedule_type")
6035 6041
 
6036
-	partion_type, _ := this.GetInt64("partion_type")
6042
+	//partion_type, _ := this.GetInt64("partion_type")
6037 6043
 
6044
+	partion_type := this.GetString("partion_type")
6045
+	var ids []string
6046
+	ids = strings.Split(partion_type, ",")
6038 6047
 	start_time := this.GetString("selected_date")
6039 6048
 	timeLayout := "2006-01-02"
6040 6049
 	loc, _ := time.LoadLocation("Local")
6041 6050
 	startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
6042 6051
 
6043
-	list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, partion_type, startTime.Unix())
6052
+	list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
6044 6053
 
6045 6054
 	drug, _ := service.GetAllBaseDrugListTwenty(orgId)
6046 6055
 	_, config := service.FindXTHisRecordByOrgId(orgId)

+ 17 - 3
controllers/doctors_api_controller.go View File

@@ -123,6 +123,8 @@ func (c *DoctorsApiController) ScheduleAdvices() {
123 123
 		hisAdvices, err := service.GetHisDoctorAdvicesTwentyOne(orgID, date.Unix(), delivery_way, schedule_type, partition_type, patient_id, excution_way, 0, execution_frequency)
124 124
 		adminUser, _ := service.GetAllAdminUsers(orgID, adminUserInfo.CurrentAppId)
125 125
 		project, _ := service.GetPCHisPrescriptionProject(orgID, date.Unix(), delivery_way, patientType, partition_type, patient_id, excution_way)
126
+
127
+		drug, _ := service.GetAllBaseDrugListTwenty(orgID)
126 128
 		for _, item := range project {
127 129
 			index := 0
128 130
 			for _, subItem := range item.HisPrescriptionTeamProject {
@@ -152,6 +154,7 @@ func (c *DoctorsApiController) ScheduleAdvices() {
152 154
 				"config":         config,
153 155
 				"project_config": project_config,
154 156
 				"project":        project,
157
+				"drug":           drug,
155 158
 			})
156 159
 		}
157 160
 	}
@@ -1485,7 +1488,8 @@ func (c *DoctorsApiController) CreateFirstDisease() {
1485 1488
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1486 1489
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1487 1490
 	treatment_plan := dataBody["treatment_plan"].(string)
1488
-
1491
+	inspect_date := dataBody["inspect_date"].(string)
1492
+	project_id := dataBody["project_id"].(string)
1489 1493
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1490 1494
 	firstdisease := models.XtPatientFirstDisease{
1491 1495
 		Title:                 title,
@@ -1502,6 +1506,8 @@ func (c *DoctorsApiController) CreateFirstDisease() {
1502 1506
 		Ctime:                 time.Now().Unix(),
1503 1507
 		Mtime:                 0,
1504 1508
 		Status:                1,
1509
+		ProjectId:             project_id,
1510
+		InspectDate:           inspect_date,
1505 1511
 	}
1506 1512
 
1507 1513
 	error := service.CreatePatientFirstDisease(firstdisease)
@@ -1540,9 +1546,14 @@ func (c *DoctorsApiController) GetFirstDetailById() {
1540 1546
 
1541 1547
 	id, _ := c.GetInt64("id")
1542 1548
 	list, err := service.GetFirstDetailById(id)
1549
+	ids := strings.Split(list.ProjectId, ",")
1550
+	datelist := strings.Split(list.InspectDate, ",")
1551
+	fmt.Println("list232323232323w", datelist)
1552
+	inspectlist, err := service.GetInspectionItemlist(list.PatientId, datelist, ids)
1543 1553
 	if err == nil {
1544 1554
 		c.ServeSuccessJSON(map[string]interface{}{
1545
-			"detail": list,
1555
+			"detail":      list,
1556
+			"inspectlist": inspectlist,
1546 1557
 		})
1547 1558
 		return
1548 1559
 	}
@@ -1568,7 +1579,8 @@ func (c *DoctorsApiController) UpdateFirstDisease() {
1568 1579
 	diagnostic_basis := dataBody["diagnostic_basis"].(string)
1569 1580
 	differential_diagnosis := dataBody["differential_diagnosis"].(string)
1570 1581
 	treatment_plan := dataBody["treatment_plan"].(string)
1571
-
1582
+	inspect_date := dataBody["inspect_date"].(string)
1583
+	project_id := dataBody["project_id"].(string)
1572 1584
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1573 1585
 	firstdisease := models.XtPatientFirstDisease{
1574 1586
 		Title:                 title,
@@ -1586,6 +1598,8 @@ func (c *DoctorsApiController) UpdateFirstDisease() {
1586 1598
 		Mtime:                 0,
1587 1599
 		Status:                1,
1588 1600
 		ID:                    id,
1601
+		InspectDate:           inspect_date,
1602
+		ProjectId:             project_id,
1589 1603
 	}
1590 1604
 
1591 1605
 	error := service.UpdatePatientFirstDisease(firstdisease, id)

+ 196 - 4
controllers/his_api_controller.go View File

@@ -1054,8 +1054,201 @@ func (c *HisApiController) CreateHisPrescription() {
1054 1054
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
1055 1055
 		return
1056 1056
 	}
1057
-	//已发药和已收费限制逻辑
1058 1057
 
1058
+	pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
1059
+
1060
+	fmt.Println("0230032032032032032032023---------------", pharmacyConfig.IsOpen)
1061
+	//药品发药出库
1062
+	if pharmacyConfig.IsOpen == 1 {
1063
+		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1064
+			prescriptions, _ := dataBody["prescriptions"].([]interface{})
1065
+			if len(prescriptions) > 0 {
1066
+				for _, item := range prescriptions {
1067
+					items := item.(map[string]interface{})
1068
+					if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
1069
+						advices := items["advices"].([]interface{})
1070
+						if len(advices) > 0 {
1071
+							for _, advice := range advices {
1072
+								var drug_id int64
1073
+								var prescribing_number float64
1074
+								var prescribingNumberUnit string
1075
+
1076
+								var adviceId int64
1077
+								if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1078
+									drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1079
+								}
1080
+								if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1081
+									prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1082
+									prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1083
+								}
1084
+
1085
+								if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1086
+									prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1087
+								}
1088
+
1089
+								if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1090
+									adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1091
+								}
1092
+
1093
+								drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1094
+								if drug.ID == 0 {
1095
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1096
+									return
1097
+								}
1098
+
1099
+								//查询药品的所有库存
1100
+								list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1101
+
1102
+								var total_count int64
1103
+								for _, it := range list {
1104
+									total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1105
+								}
1106
+								totals := strconv.FormatInt(total_count, 10)
1107
+								//查询该药品是否存在开药记录
1108
+								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1109
+
1110
+								//新增处方
1111
+								if advicelist.ID == 0 {
1112
+									all_count, _ := strconv.ParseFloat(totals, 64)
1113
+									if prescribingNumberUnit == drug.MinUnit {
1114
+
1115
+										if drug.IsUse != 1 {
1116
+											if prescribing_number > all_count {
1117
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1118
+												return
1119
+											}
1120
+
1121
+										}
1122
+
1123
+									}
1124
+									if prescribingNumberUnit == drug.MaxUnit {
1125
+										num := prescribing_number * float64(drug.MinNumber)
1126
+										if drug.IsUse != 1 {
1127
+											if num > all_count {
1128
+												c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1129
+												return
1130
+											}
1131
+										}
1132
+									}
1133
+								}
1134
+
1135
+								drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1136
+								if drugOutConfig.IsOpen != 1 {
1137
+									//修改处方
1138
+									for _, advice := range advices {
1139
+										var drug_id int64
1140
+										var prescribing_number float64
1141
+										var prescribingNumberUnit string
1142
+										var prescribingNumber string
1143
+
1144
+										var adviceId int64
1145
+										if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1146
+											drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1147
+										}
1148
+										if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1149
+											prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1150
+											prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1151
+											prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
1152
+										}
1153
+
1154
+										if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1155
+											prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1156
+										}
1157
+
1158
+										if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1159
+											adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1160
+										}
1161
+
1162
+										drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1163
+										if drug.ID == 0 {
1164
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1165
+											return
1166
+										}
1167
+										//查询药品的所有库存
1168
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1169
+										var total_count int64
1170
+										for _, it := range list {
1171
+											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1172
+										}
1173
+										totals := strconv.FormatInt(total_count, 10)
1174
+										//查询该药品是否存在开药记录
1175
+										advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1176
+
1177
+										//新增处方
1178
+										if advicelist.ID == 0 {
1179
+
1180
+											all_count, _ := strconv.ParseFloat(totals, 64)
1181
+											if prescribingNumberUnit == drug.MinUnit {
1182
+												if drug.IsUse != 1 {
1183
+													if prescribing_number > all_count {
1184
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1185
+														return
1186
+													}
1187
+
1188
+												}
1189
+
1190
+											} else {
1191
+												if prescribingNumberUnit == drug.MaxUnit {
1192
+													num := prescribing_number * float64(drug.MinNumber)
1193
+													if drug.IsUse != 1 {
1194
+														if num > all_count {
1195
+															c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1196
+															return
1197
+														}
1198
+
1199
+													}
1200
+
1201
+												}
1202
+											}
1203
+										}
1204
+										//修改处方
1205
+										if advicelist.ID > 0 {
1206
+
1207
+											var device_number int64
1208
+
1209
+											if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1210
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1211
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1212
+												device_number = prescribingNumberInt * drug.MinNumber
1213
+											}
1214
+											if advicelist.PrescribingNumberUnit == drug.MinUnit {
1215
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1216
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1217
+												device_number = prescribingNumberInt
1218
+											}
1219
+
1220
+											var number_count int64
1221
+											if prescribingNumberUnit == drug.MaxUnit {
1222
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1223
+												number_count = prescribingNumberInt * drug.MinNumber
1224
+											}
1225
+											if prescribingNumberUnit == drug.MinUnit {
1226
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1227
+												number_count = prescribingNumberInt
1228
+											}
1229
+
1230
+											//如果修改的数量大于之前修改的数量
1231
+											if (number_count - device_number) > 0 {
1232
+												//如果修改的差数量 大于库存数量
1233
+												if drug.IsUse != 1 {
1234
+													if (number_count - device_number) > total_count {
1235
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1236
+														return
1237
+													}
1238
+												}
1239
+											}
1240
+										}
1241
+									}
1242
+								}
1243
+							}
1244
+						}
1245
+					}
1246
+				}
1247
+			}
1248
+		}
1249
+	}
1250
+
1251
+	//已发药和已收费限制逻辑
1059 1252
 	if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
1060 1253
 		//校验库存总量
1061 1254
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
@@ -1282,7 +1475,7 @@ func (c *HisApiController) CreateHisPrescription() {
1282 1475
 														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1283 1476
 														return
1284 1477
 													}
1285
-													if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
1478
+													if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
1286 1479
 														// 查询该药品最后一次出库记录
1287 1480
 														outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1288 1481
 
@@ -1755,7 +1948,6 @@ func (c *HisApiController) CreateHisPrescription() {
1755 1948
 
1756 1949
 											}
1757 1950
 
1758
-											//删除记录
1759 1951
 											service.DeleteAutoWarehouse(patient_id, recordDateTime)
1760 1952
 
1761 1953
 										}
@@ -2389,7 +2581,7 @@ func (c *HisApiController) CreateHisPrescription() {
2389 2581
 						//如果历史数和当前数据不想等才进行退库出库
2390 2582
 						if out_count != parseIntCount {
2391 2583
 							service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
2392
-							fmt.Println("9999999----------------------------------------")
2584
+
2393 2585
 							service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
2394 2586
 							detail := models.AutomaticReduceDetail{
2395 2587
 								WarehouseOutId:          0,

+ 7 - 2
controllers/mobile_api_controllers/check_weight_api_controller.go View File

@@ -269,7 +269,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
269 269
 
270 270
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
271 271
 
272
-	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
272
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
273 273
 		if adminUserInfo.Org.Id != 10447 {
274 274
 			dewater_amount = dewater_amount * 1000
275 275
 		}
@@ -378,6 +378,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
378 378
 			newprescribe.RecordDate = theAssessmentDateTime
379 379
 			newprescribe.DewaterAmount = dewater_amount
380 380
 			newprescribe.TargetUltrafiltration = dewater_amount
381
+			newprescribe.PrescriptionWater = dewater_amount
381 382
 			newprescribe.Status = 1
382 383
 			if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
383 384
 				newprescribe.Remark = dialysisSolution.Remark
@@ -461,6 +462,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
461 462
 				newprescribe.RecordDate = theAssessmentDateTime
462 463
 				newprescribe.DewaterAmount = dewater_amount
463 464
 				newprescribe.TargetUltrafiltration = dewater_amount
465
+				newprescribe.PrescriptionWater = dewater_amount
464 466
 				newprescribe.Status = 1
465 467
 				newprescribe.Remark = lastDialysisPrescribe.Remark
466 468
 				if adminUserInfo.Org.Id == 10340 {
@@ -681,7 +683,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
681 683
 					evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
682 684
 				}
683 685
 
684
-				if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
686
+				if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
685 687
 					evaluation.PulseFrequency = 80
686 688
 				}
687 689
 				if adminUserInfo.Org.Id == 10440 {
@@ -690,6 +692,9 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
690 692
 				if adminUserInfo.Org.Id == 10469 {
691 693
 					evaluation.Temperature = 36.5
692 694
 				}
695
+				if adminUserInfo.Org.Id == 10471 {
696
+					evaluation.Temperature = 36.5
697
+				}
693 698
 			}
694 699
 		} else {
695 700
 			evaluation.UpdatedTime = time.Now().Unix()

+ 300 - 244
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -744,7 +744,8 @@ func (c *DialysisAPIController) PostDoubleCheck() {
744 744
 	pipeline_connection_desc := c.GetString("pipeline_connection_desc")
745 745
 	collator, _ := c.GetInt64("collator", 0)
746 746
 	employee_number := c.GetString("employee_number")
747
-
747
+	dialyzer_batch_number := c.GetString("dialyzer_batch_number")
748
+	needle_batch_number := c.GetString("needle_batch_number")
748 749
 	if id <= 0 {
749 750
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
750 751
 		return
@@ -828,6 +829,8 @@ func (c *DialysisAPIController) PostDoubleCheck() {
828 829
 		CheckDate:                  recordDate.Unix(),
829 830
 		UpdatedTime:                time.Now().Unix(),
830 831
 		EmployeeNumber:             employee_number,
832
+		DialyzerBatchNumber:        dialyzer_batch_number,
833
+		NeedleBatchNumber:          needle_batch_number,
831 834
 	}
832 835
 
833 836
 	_, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
@@ -885,6 +888,8 @@ func (c *DialysisAPIController) PostDoubleCheck() {
885 888
 		doubleCheck.CreatedTime = check.CreatedTime
886 889
 		doubleCheck.ID = check.ID
887 890
 		doubleCheck.EmployeeNumber = employee_number
891
+		doubleCheck.NeedleBatchNumber = needle_batch_number
892
+		doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
888 893
 		err := service.UpdateDoubleCheck(&doubleCheck)
889 894
 		//针对长沙南雅
890 895
 		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
@@ -1490,7 +1495,7 @@ func (c *DialysisAPIController) PostDialysisPrescription() {
1490 1495
 		if filedConfig.ID > 0 {
1491 1496
 			str = dialyzerPerfusionApparatus
1492 1497
 		} else {
1493
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
1498
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
1494 1499
 		}
1495 1500
 		service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
1496 1501
 	}
@@ -2391,6 +2396,19 @@ func (c *DialysisAPIController) Finish() {
2391 2396
 		dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
2392 2397
 		dialysisOrder.EndTime = endDate.Unix()
2393 2398
 
2399
+		// 长沙南雅需求
2400
+		if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
2401
+
2402
+			//获取最后1条监测的数据
2403
+			fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
2404
+			lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
2405
+			var accumulatedBloodVolume float64
2406
+			accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
2407
+			fmt.Println("累计血容量", accumulatedBloodVolume)
2408
+			err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
2409
+			fmt.Println(err)
2410
+		}
2411
+
2394 2412
 		go func() {
2395 2413
 			ssoDomain := beego.AppConfig.String("call_domain")
2396 2414
 			api := ssoDomain + "/index/downpatient"
@@ -3022,7 +3040,7 @@ func (c *DialysisAPIController) PostSolution() {
3022 3040
 		if filedConfig.ID > 0 {
3023 3041
 			str = dialyzerPerfusionApparatus
3024 3042
 		} else {
3025
-			str = dialysis_dialyszers + "/" + dialysis_irrigation + "/" + dialysis_strainer
3043
+			str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
3026 3044
 		}
3027 3045
 		service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
3028 3046
 	}
@@ -3604,10 +3622,9 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
3604 3622
 				record.UltrafiltrationRate = ultrafiltration_rate
3605 3623
 			}
3606 3624
 
3607
-			fmt.Println("adminiNof2323323232", adminInfo.Org.Id)
3608
-			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10469 {
3625
+			if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10471 {
3609 3626
 				ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
3610
-				fmt.Println("ooooooooooo", ultrafiltration_rate)
3627
+
3611 3628
 				record.UltrafiltrationRate = ultrafiltration_rate
3612 3629
 			}
3613 3630
 			//if template.TemplateId == 47 {
@@ -3636,19 +3653,19 @@ func (this *DialysisAPIController) GetLastMonitorRecordTody() {
3636 3653
 	}
3637 3654
 
3638 3655
 	//长沙南雅
3639
-	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 {
3640
-		fmt.Println("ultrafiltration_rate-------", ultrafiltration_rate)
3656
+	if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10471 {
3657
+
3641 3658
 		if ultrafiltration_rate > 0 {
3642 3659
 			ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
3643
-			fmt.Println("ultrafiltration_volume=======", ultrafiltration_volume)
3660
+
3644 3661
 			record.UltrafiltrationVolume = ultrafiltration_volume
3645 3662
 		}
3646 3663
 
3647 3664
 	}
3648 3665
 	//长沙南雅累计血容量自动计算
3649
-	if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 {
3650
-		record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
3651
-	}
3666
+	//if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 ||  adminInfo.Org.Id == 3877{
3667
+	//	record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
3668
+	//}
3652 3669
 
3653 3670
 	if template.TemplateId == 47 || template.TemplateId == 54 {
3654 3671
 		record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
@@ -4564,6 +4581,7 @@ func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
4564 4581
 	}
4565 4582
 
4566 4583
 	if len(advices) > 0 {
4584
+
4567 4585
 		list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
4568 4586
 		key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
4569 4587
 		redis := service.RedisClient()
@@ -4904,8 +4922,6 @@ func (c *DialysisAPIController) CreateConsumables() {
4904 4922
 			}
4905 4923
 		}
4906 4924
 
4907
-		fmt.Println("active------------------------------------", active)
4908
-		fmt.Println("len------------------------------", len(goods))
4909 4925
 		//新增
4910 4926
 		if active == 1 && len(goods) > 0 {
4911 4927
 			for _, item := range dialysisBefor {
@@ -5677,124 +5693,89 @@ func (c *DialysisAPIController) EditConsumables() {
5677 5693
 
5678 5694
 				}
5679 5695
 
5680
-				//退库
5681
-				for _, item := range cancelbefor {
5682
-					warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5683
-					creater := adminInfo.AdminUser.Id
5696
+				if len(cancelbefor) > 0 {
5684 5697
 					//退库
5685
-					//err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, cancelbefor, adminInfo.AdminUser.Id, item.Count)
5686
-					//查询该患者当天已经出库的耗材信息
5698
+					for _, item := range cancelbefor {
5699
+						warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
5700
+						creater := adminInfo.AdminUser.Id
5687 5701
 
5688
-					warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
5702
+						//查询该患者当天已经出库的耗材信息
5703
+						warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
5689 5704
 
5690
-					var delete_count int64 = 0
5705
+						var delete_count int64 = 0
5691 5706
 
5692
-					delete_count = warehouseOutInfos.Count - item.Count
5707
+						delete_count = warehouseOutInfos.Count - item.Count
5693 5708
 
5694
-					//增加库存数量
5695
-					service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5709
+						//增加库存数量
5710
+						service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
5696 5711
 
5697
-					//增加出库库存数量
5698
-					service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5712
+						//减少实际出库库存数量
5713
+						service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
5699 5714
 
5700
-					// 删除出库完成后,要增加对应批次的库存数量
5715
+						// 删除出库完成后,要增加对应批次的库存数量
5701 5716
 
5702
-					service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5717
+						service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
5703 5718
 
5704
-					houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5719
+						houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5705 5720
 
5706
-					//更新剩余库存
5707
-					goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5708
-					var flush_count int64
5709
-					for _, it := range goodListOne {
5710
-						flush_count += it.StockCount
5711
-					}
5712
-					service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5721
+						//更新剩余库存
5722
+						goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5723
+						var flush_count int64
5724
+						for _, it := range goodListOne {
5725
+							flush_count += it.StockCount
5726
+						}
5727
+						service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
5713 5728
 
5714
-					//查询剩余库存
5715
-					goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5716
-					var sum_count int64
5717
-					for _, item := range goodList {
5718
-						sum_count += item.StockCount
5719
-					}
5729
+						//查询剩余库存
5730
+						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5731
+						var sum_count int64
5732
+						for _, item := range goodList {
5733
+							sum_count += item.StockCount
5734
+						}
5720 5735
 
5721
-					// 在出库记录表里记录退库详情
5722
-					warehouseOutInfo := &models.WarehouseOutInfo{
5723
-						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5724
-						WarehouseOutId:          warehouseOut.ID,
5725
-						Status:                  1,
5726
-						Ctime:                   time.Now().Unix(),
5727
-						OrgId:                   adminInfo.Org.Id,
5728
-						Type:                    1,
5729
-						IsSys:                   1,
5730
-						SysRecordTime:           record_time,
5731
-						GoodTypeId:              item.GoodTypeId,
5732
-						GoodId:                  item.GoodId,
5733
-						PatientId:               patient_id,
5734
-						ConsumableType:          2,
5735
-						StorehouseId:            houseConfig.StorehouseOutInfo,
5736
-						IsCheck:                 1,
5737
-						OverCount:               sum_count,
5738
-					}
5739
-					warehouseOutInfo.Count = item.Count
5740
-
5741
-					stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5742
-					warehouseOutInfo.Price = stockInInfo.Price
5743
-					warehouseOutInfo.Dealer = stockInInfo.Dealer
5744
-					warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5745
-					warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5746
-					warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5747
-					warehouseOutInfo.Number = warehouseOutInfos.Number
5748
-					warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5749
-					warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5750
-					//查找当天是否存在出库记录
5751
-					_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5752
-
5753
-					if errcod == gorm.ErrRecordNotFound {
5754
-						service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5755
-						//插入详情明细表
5756
-						stockFlow := models.VmStockFlow{
5736
+						// 在出库记录表里记录退库详情
5737
+						warehouseOutInfo := &models.WarehouseOutInfo{
5757 5738
 							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5758 5739
 							WarehouseOutId:          warehouseOut.ID,
5759
-							GoodId:                  item.GoodId,
5760
-							Number:                  warehouseOutInfos.Number,
5761
-							ProductDate:             stockInInfo.ProductDate,
5762
-							ExpireDate:              stockInInfo.ExpiryDate,
5763
-							Count:                   item.Count,
5764
-							Price:                   stockInInfo.Price,
5765 5740
 							Status:                  1,
5766 5741
 							Ctime:                   time.Now().Unix(),
5767
-							UserOrgId:               adminInfo.Org.Id,
5768
-							Manufacturer:            stockInInfo.Manufacturer,
5769
-							Dealer:                  stockInInfo.Dealer,
5770
-							LicenseNumber:           stockInInfo.LicenseNumber,
5771
-							IsEdit:                  2,
5772
-							Creator:                 creater,
5773
-							SystemTime:              record_time,
5774
-							ConsumableType:          3,
5775
-							WarehousingDetailId:     0,
5742
+							OrgId:                   adminInfo.Org.Id,
5743
+							Type:                    1,
5776 5744
 							IsSys:                   1,
5777
-							UpdateCreator:           creater,
5745
+							SysRecordTime:           record_time,
5746
+							GoodTypeId:              item.GoodTypeId,
5747
+							GoodId:                  item.GoodId,
5778 5748
 							PatientId:               patient_id,
5749
+							ConsumableType:          2,
5779 5750
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5751
+							IsCheck:                 1,
5752
+							OverCount:               sum_count,
5780 5753
 						}
5781
-						exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5782
-						if errflow == gorm.ErrRecordNotFound {
5783
-							//创建流水表
5784
-							err := service.CreateStockFlowOne(stockFlow)
5785
-							fmt.Println("err", err)
5786
-						} else if errflow == nil {
5754
+						warehouseOutInfo.Count = item.Count
5755
+
5756
+						stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
5757
+						warehouseOutInfo.Price = stockInInfo.Price
5758
+						warehouseOutInfo.Dealer = stockInInfo.Dealer
5759
+						warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
5760
+						warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
5761
+						warehouseOutInfo.ProductDate = stockInInfo.ProductDate
5762
+						warehouseOutInfo.Number = warehouseOutInfos.Number
5763
+						warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
5764
+						warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
5765
+						//查找当天是否存在出库记录
5766
+						_, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
5767
+
5768
+						if errcod == gorm.ErrRecordNotFound {
5769
+							service.AddSigleWarehouseOutInfo(warehouseOutInfo)
5787 5770
 							//插入详情明细表
5788 5771
 							stockFlow := models.VmStockFlow{
5789
-								ID:                      exsit.ID,
5790
-								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5791 5772
 								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5792 5773
 								WarehouseOutId:          warehouseOut.ID,
5793 5774
 								GoodId:                  item.GoodId,
5794 5775
 								Number:                  warehouseOutInfos.Number,
5795 5776
 								ProductDate:             stockInInfo.ProductDate,
5796 5777
 								ExpireDate:              stockInInfo.ExpiryDate,
5797
-								Count:                   exsit.Count - delete_count,
5778
+								Count:                   item.Count,
5798 5779
 								Price:                   stockInInfo.Price,
5799 5780
 								Status:                  1,
5800 5781
 								Ctime:                   time.Now().Unix(),
@@ -5812,131 +5793,207 @@ func (c *DialysisAPIController) EditConsumables() {
5812 5793
 								PatientId:               patient_id,
5813 5794
 								StorehouseId:            houseConfig.StorehouseOutInfo,
5814 5795
 							}
5796
+							exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5797
+							if errflow == gorm.ErrRecordNotFound {
5798
+								//创建流水表
5799
+								err := service.CreateStockFlowOne(stockFlow)
5800
+								fmt.Println("err", err)
5801
+							} else if errflow == nil {
5802
+								//插入详情明细表
5803
+								stockFlow := models.VmStockFlow{
5804
+									ID:                      exsit.ID,
5805
+									WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5806
+									WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5807
+									WarehouseOutId:          warehouseOut.ID,
5808
+									GoodId:                  item.GoodId,
5809
+									Number:                  warehouseOutInfos.Number,
5810
+									ProductDate:             stockInInfo.ProductDate,
5811
+									ExpireDate:              stockInInfo.ExpiryDate,
5812
+									Count:                   exsit.Count - delete_count,
5813
+									Price:                   stockInInfo.Price,
5814
+									Status:                  1,
5815
+									Ctime:                   time.Now().Unix(),
5816
+									UserOrgId:               adminInfo.Org.Id,
5817
+									Manufacturer:            stockInInfo.Manufacturer,
5818
+									Dealer:                  stockInInfo.Dealer,
5819
+									LicenseNumber:           stockInInfo.LicenseNumber,
5820
+									IsEdit:                  2,
5821
+									Creator:                 creater,
5822
+									SystemTime:              record_time,
5823
+									ConsumableType:          3,
5824
+									WarehousingDetailId:     0,
5825
+									IsSys:                   1,
5826
+									UpdateCreator:           creater,
5827
+									PatientId:               patient_id,
5828
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5829
+								}
5815 5830
 
5816
-							service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5817
-						}
5831
+								service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5832
+							}
5818 5833
 
5819
-					} else if errcod == nil {
5820
-						service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5834
+						} else if errcod == nil {
5835
+							service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
5821 5836
 
5822
-						fmt.Println("进来-------------------------------------------------")
5837
+							//查询剩余库存
5838
+							goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5839
+							var sum_count int64
5840
+							for _, item := range goodList {
5841
+								sum_count += item.StockCount
5842
+							}
5823 5843
 
5824
-						//查询剩余库存
5825
-						goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
5826
-						var sum_count int64
5827
-						for _, item := range goodList {
5828
-							sum_count += item.StockCount
5844
+							//创建退库单,生成退库数据
5845
+							houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5846
+							good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
5847
+
5848
+							operation_time := time.Now().Unix()
5849
+							creater := adminInfo.AdminUser.Id
5850
+							//创建退库单
5851
+							timeStr := time.Now().Format("2006-01-02")
5852
+							timeArr := strings.Split(timeStr, "-")
5853
+							total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
5854
+							total = total + 1
5855
+							orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
5856
+
5857
+							cancelStock := models.CancelStock{
5858
+								OrderNumber:  orderNumber,
5859
+								OperaTime:    operation_time,
5860
+								OrgId:        adminInfo.Org.Id,
5861
+								Creater:      creater,
5862
+								Ctime:        time.Now().Unix(),
5863
+								Status:       1,
5864
+								ReturnTime:   record_time,
5865
+								Type:         1,
5866
+								StorehouseId: houseConfig.StorehouseOutInfo,
5867
+								IsCheck:      1,
5868
+							}
5869
+							_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
5870
+							if msgerrkonde == gorm.ErrRecordNotFound {
5871
+								service.AddSigleCancelStock(&cancelStock)
5872
+							}
5873
+							cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
5874
+
5875
+							//查询是否有出库
5876
+							info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
5877
+
5878
+							manufacturer, _ := service.GetManufactureById(info.Manufacturer)
5879
+							deaerler, _ := service.GetDealerById(info.Dealer)
5880
+
5881
+							if info.ID > 0 {
5882
+								cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
5883
+								cancelStockInfo := models.CancelStockInfo{
5884
+									GoodId:          item.GoodId,
5885
+									CancelStockId:   cancel.ID,
5886
+									GoodTypeId:      good.GoodTypeId,
5887
+									Count:           delete_count,
5888
+									Price:           info.Price,
5889
+									Total:           0,
5890
+									ProductDate:     info.ProductDate,
5891
+									ExpiryDate:      info.ExpiryDate,
5892
+									Ctime:           time.Now().Unix(),
5893
+									Status:          1,
5894
+									OrgId:           adminInfo.Org.Id,
5895
+									OrderNumber:     cancel.OrderNumber,
5896
+									Type:            0,
5897
+									Dealer:          deaerler.DealerName,
5898
+									Manufacturer:    manufacturer.ManufacturerName,
5899
+									Number:          info.Number,
5900
+									RegisterAccount: "",
5901
+									Remark:          "",
5902
+									WarehouseInfoId: info.WarehouseInfotId,
5903
+									PatientId:       info.PatientId,
5904
+									RecordDate:      info.SysRecordTime,
5905
+									StorehouseId:    houseConfig.StorehouseOutInfo,
5906
+									IsCheck:         1,
5907
+								}
5908
+
5909
+								service.CreateCancelStockInfoOne(&cancelStockInfo)
5910
+
5911
+								//退库数量增加
5912
+								service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
5913
+
5914
+								//查询剩余库存
5915
+								goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
5916
+								var over_count int64
5917
+								for _, it := range goodList {
5918
+									over_count += it.StockCount
5919
+								}
5920
+
5921
+								flow := models.VmStockFlow{
5922
+									WarehousingId:           info.WarehouseInfotId,
5923
+									GoodId:                  item.GoodId,
5924
+									Number:                  info.Number,
5925
+									LicenseNumber:           info.LicenseNumber,
5926
+									Count:                   delete_count,
5927
+									UserOrgId:               adminInfo.Org.Id,
5928
+									PatientId:               patient_id,
5929
+									SystemTime:              info.SysRecordTime,
5930
+									ConsumableType:          7,
5931
+									IsSys:                   0,
5932
+									WarehousingOrder:        "",
5933
+									WarehouseOutId:          info.WarehouseOutId,
5934
+									WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
5935
+									IsEdit:                  0,
5936
+									CancelStockId:           cancel.ID,
5937
+									CancelOrderNumber:       cancel.OrderNumber,
5938
+									Manufacturer:            manufacturer.ID,
5939
+									Dealer:                  0,
5940
+									Creator:                 adminInfo.AdminUser.Id,
5941
+									UpdateCreator:           0,
5942
+									Status:                  1,
5943
+									Ctime:                   time.Now().Unix(),
5944
+									Mtime:                   0,
5945
+									Price:                   info.Price,
5946
+									WarehousingDetailId:     info.WarehouseInfotId,
5947
+									WarehouseOutDetailId:    info.ID,
5948
+									CancelOutDetailId:       cancelInfo.ID,
5949
+									ProductDate:             info.ProductDate,
5950
+									ExpireDate:              info.ExpiryDate,
5951
+									StorehouseId:            houseConfig.StorehouseOutInfo,
5952
+									OverCount:               over_count,
5953
+								}
5954
+								service.CreateStockFlowOne(flow)
5955
+
5956
+							}
5829 5957
 						}
5830
-						//插入详情明细表
5831
-						stockFlow := models.VmStockFlow{
5832
-							WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5833
-							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5834
-							WarehouseOutId:          warehouseOut.ID,
5958
+
5959
+						//更改自动出库的表格
5960
+						details := models.BloodAutomaticReduceDetail{
5961
+							WarehouseOutId:          warehouseOutInfo.ID,
5962
+							WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5963
+							PatientId:               patient_id,
5964
+							Ctime:                   time.Now().Unix(),
5965
+							Mtime:                   time.Now().Unix(),
5966
+							Status:                  1,
5967
+							RecordTime:              record_time,
5968
+							OrgId:                   adminInfo.Org.Id,
5835 5969
 							GoodId:                  item.GoodId,
5836
-							Number:                  warehouseOutInfos.Number,
5837
-							ProductDate:             stockInInfo.ProductDate,
5838
-							ExpireDate:              stockInInfo.ExpiryDate,
5970
+							GoodTypeId:              item.GoodTypeId,
5839 5971
 							Count:                   item.Count,
5840
-							Price:                   stockInInfo.Price,
5841
-							Status:                  1,
5842
-							Ctime:                   time.Now().Unix(),
5843
-							UserOrgId:               adminInfo.Org.Id,
5844
-							Manufacturer:            stockInInfo.Manufacturer,
5845
-							Dealer:                  stockInInfo.Dealer,
5846
-							LicenseNumber:           stockInInfo.LicenseNumber,
5847
-							IsEdit:                  2,
5848
-							Creator:                 creater,
5849
-							SystemTime:              record_time,
5850
-							ConsumableType:          3,
5851
-							WarehousingDetailId:     0,
5852
-							IsSys:                   1,
5853
-							UpdateCreator:           creater,
5854
-							PatientId:               patient_id,
5855
-							ReturnCount:             delete_count,
5856 5972
 							StorehouseId:            houseConfig.StorehouseOutInfo,
5857
-							OverCount:               sum_count,
5858 5973
 						}
5859
-						exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
5974
+						//查询当天耗材是否已经存在数据
5975
+						_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5860 5976
 
5861
-						if errflows == gorm.ErrRecordNotFound {
5862
-							//创建流水表
5863
-							service.CreateStockFlowOne(stockFlow)
5864
-						} else if errflows == nil {
5865
-							stockFlow := models.VmStockFlow{
5866
-								WarehousingId:           warehouseOutInfos.WarehouseInfotId,
5867
-								ID:                      exsit.ID,
5868
-								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
5869
-								WarehouseOutId:          warehouseOut.ID,
5870
-								GoodId:                  item.GoodId,
5871
-								Number:                  warehouseOutInfos.Number,
5872
-								ProductDate:             stockInInfo.ProductDate,
5873
-								ExpireDate:              stockInInfo.ExpiryDate,
5874
-								Count:                   exsit.Count - delete_count,
5875
-								Price:                   stockInInfo.Price,
5876
-								Status:                  1,
5877
-								Ctime:                   time.Now().Unix(),
5878
-								UserOrgId:               adminInfo.Org.Id,
5879
-								Manufacturer:            stockInInfo.Manufacturer,
5880
-								Dealer:                  stockInInfo.Dealer,
5881
-								LicenseNumber:           stockInInfo.LicenseNumber,
5882
-								IsEdit:                  2,
5883
-								Creator:                 creater,
5884
-								SystemTime:              record_time,
5885
-								ConsumableType:          3,
5886
-								WarehousingDetailId:     0,
5887
-								IsSys:                   1,
5888
-								UpdateCreator:           creater,
5889
-								PatientId:               patient_id,
5890
-								ReturnCount:             delete_count,
5891
-								StorehouseId:            houseConfig.StorehouseOutInfo,
5892
-								OverCount:               exsit.OverCount + delete_count,
5893
-							}
5894
-							fmt.Println("stockFlow--------------------", stockFlow.OverCount)
5895
-							service.UpdatedStockFlowFive(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
5896
-						}
5977
+						if errcode == gorm.ErrRecordNotFound {
5978
+							service.CreateAutoReduceRecord(&details)
5897 5979
 
5898
-					}
5980
+						} else if errcode == nil {
5981
+							service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5982
+							service.CreateAutoReduceRecord(&details)
5899 5983
 
5900
-					//更改自动出库的表格
5901
-					details := models.BloodAutomaticReduceDetail{
5902
-						WarehouseOutId:          warehouseOutInfo.ID,
5903
-						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
5904
-						PatientId:               patient_id,
5905
-						Ctime:                   time.Now().Unix(),
5906
-						Mtime:                   time.Now().Unix(),
5907
-						Status:                  1,
5908
-						RecordTime:              record_time,
5909
-						OrgId:                   adminInfo.Org.Id,
5910
-						GoodId:                  item.GoodId,
5911
-						GoodTypeId:              item.GoodTypeId,
5912
-						Count:                   item.Count,
5913
-						StorehouseId:            houseConfig.StorehouseOutInfo,
5914
-					}
5915
-					//查询当天耗材是否已经存在数据
5916
-					_, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5917
-
5918
-					if errcode == gorm.ErrRecordNotFound {
5919
-						service.CreateAutoReduceRecord(&details)
5984
+						}
5920 5985
 
5921
-					} else if errcode == nil {
5922
-						service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
5923
-						service.CreateAutoReduceRecord(&details)
5986
+						//查询默认仓库
5987
+						storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5988
+						stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5989
+						var total_count int64
5990
+						for _, it := range stockList {
5991
+							total_count += it.StockCount
5992
+						}
5993
+						//基础库插入数据
5994
+						service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5924 5995
 
5925 5996
 					}
5926
-
5927
-					//errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, item.GoodId, delete_count, patient_id)
5928
-					//fmt.Println("errOne", errOne)
5929
-
5930
-					//查询默认仓库
5931
-					storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
5932
-					stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
5933
-					var total_count int64
5934
-					for _, it := range stockList {
5935
-						total_count += it.StockCount
5936
-					}
5937
-					//基础库插入数据
5938
-					service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
5939
-
5940 5997
 				}
5941 5998
 
5942 5999
 				fmt.Println("lnet---------------------------", len(outbefor))
@@ -5950,26 +6007,9 @@ func (c *DialysisAPIController) EditConsumables() {
5950 6007
 						//计算当前出库和最后一次出库数据相差数据
5951 6008
 						last_total = item.Count - goodInfoOne.Count
5952 6009
 
5953
-						//查询该批次剩余库存
5954
-						lastInfo, _ := service.GetLastStockOut(goodInfoOne.WarehouseInfotId)
5955
-
5956
-						if lastInfo.StockCount == 0 {
5957
-							//查询该耗材的总库存
5958
-							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
5959
-							if wareinfo.StockCount == 0 {
5960
-								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
5961
-								c.ServeSuccessJSON(map[string]interface{}{
5962
-									"message":            "1",
5963
-									"good_name":          goodObj.GoodName,
5964
-									"specification_name": goodObj.SpecificationName,
5965
-								})
5966
-								return
5967
-							}
5968
-
5969
-						}
5970
-
5971 6010
 						//查询该耗材的总库存
5972 6011
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
6012
+
5973 6013
 						// 如果库存差大于剩余库存则提示库存不足
5974 6014
 						if last_total > wareinfo.StockCount {
5975 6015
 							goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
@@ -6035,8 +6075,7 @@ func (c *DialysisAPIController) EditConsumables() {
6035 6075
 								ProjectId:    0,
6036 6076
 								StorehouseId: houseConfig.StorehouseOutInfo,
6037 6077
 							}
6038
-							//fmt.Println("prepare", prepare.Count)
6039
-							//fmt.Println("count", item.Count)
6078
+
6040 6079
 							service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
6041 6080
 							//增加出库数量
6042 6081
 							service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
@@ -6096,6 +6135,7 @@ func (c *DialysisAPIController) EditConsumables() {
6096 6135
 					for _, it := range goodList {
6097 6136
 						flush_count += it.StockCount
6098 6137
 					}
6138
+
6099 6139
 					service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
6100 6140
 
6101 6141
 				}
@@ -6360,13 +6400,19 @@ func (c *DialysisAPIController) CreateOtherStockOutInfo() {
6360 6400
 				}
6361 6401
 				project_id := int64(items["project_id"].(float64))
6362 6402
 
6403
+				new_count := int64(items["new_count"].(float64))
6404
+				old_count := int64(items["old_count"].(float64))
6405
+
6363 6406
 				prepare := &models.DialysisBeforePrepareGoods{
6364 6407
 					GoodId:       good_id,
6365 6408
 					GoodTypeId:   good_type_id,
6366 6409
 					Count:        count,
6367 6410
 					ProjectId:    project_id,
6368 6411
 					StorehouseId: houseConfig.StorehouseOutInfo,
6412
+					NewCount:     new_count,
6413
+					OldCount:     old_count,
6369 6414
 				}
6415
+
6370 6416
 				beforePrepares = append(beforePrepares, prepare)
6371 6417
 
6372 6418
 				newPrepare := &models.NewDialysisBeforePrepareGoods{
@@ -6375,25 +6421,35 @@ func (c *DialysisAPIController) CreateOtherStockOutInfo() {
6375 6421
 					Count:        count,
6376 6422
 					ProjectId:    project_id,
6377 6423
 					StorehouseId: houseConfig.StorehouseOutInfo,
6424
+					NewCount:     new_count,
6425
+					OldCount:     old_count,
6378 6426
 				}
6427
+
6379 6428
 				newBeforePrepares = append(newBeforePrepares, newPrepare)
6429
+
6380 6430
 			}
6381 6431
 		}
6382 6432
 	}
6383 6433
 
6384 6434
 	//查询是否有库存
6435
+
6385 6436
 	for _, item := range beforePrepares {
6386
-		storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6387
-		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
6388
-		if item.Count > warehouse.Count {
6389
-			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6390
-			c.ServeSuccessJSON(map[string]interface{}{
6391
-				"message":            "1",
6392
-				"good_name":          goodObj.GoodName,
6393
-				"specification_name": goodObj.SpecificationName,
6394
-			})
6395
-			return
6437
+
6438
+		if item.NewCount > 0 {
6439
+			storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
6440
+			warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
6441
+
6442
+			if item.Count > warehouse.Count {
6443
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
6444
+				c.ServeSuccessJSON(map[string]interface{}{
6445
+					"message":            "1",
6446
+					"good_name":          goodObj.GoodName,
6447
+					"specification_name": goodObj.SpecificationName,
6448
+				})
6449
+				return
6450
+			}
6396 6451
 		}
6452
+
6397 6453
 	}
6398 6454
 
6399 6455
 	//出库逻辑

+ 13 - 3
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -3640,7 +3640,6 @@ func (c *PatientApiController) CreateGroupAdvice() {
3640 3640
 			return
3641 3641
 		}
3642 3642
 		advice_date, _ := dataBody["advice_date"].(string)
3643
-		fmt.Println("advice_date----------------------------------", advice_date)
3644 3643
 
3645 3644
 		var advicedateunix int64
3646 3645
 		if len(advice_date) > 0 {
@@ -3674,12 +3673,16 @@ func (c *PatientApiController) CreateGroupAdvice() {
3674 3673
 			return
3675 3674
 		}
3676 3675
 		startTime, _ := dataBody["start_time"].(string)
3676
+
3677 3677
 		if len(startTime) == 0 {
3678 3678
 			utils.ErrorLog("len(start_time) == 0")
3679 3679
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3680 3680
 			return
3681 3681
 		}
3682 3682
 		theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
3683
+
3684
+		theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
3685
+
3683 3686
 		if err != nil {
3684 3687
 			utils.ErrorLog(err.Error())
3685 3688
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -3707,8 +3710,15 @@ func (c *PatientApiController) CreateGroupAdvice() {
3707 3710
 			advice.Remark = Remark
3708 3711
 			advice.AdviceType = adviceType
3709 3712
 			advice.StartTime = StartTime
3710
-			advice.AdviceDate = AdviceDate
3711
-			advice.RecordDate = RecordDate
3713
+			if adminUserInfo.Org.Id == 10340 {
3714
+				advice.AdviceDate = AdviceDate
3715
+				advice.RecordDate = RecordDate
3716
+			}
3717
+			if adminUserInfo.Org.Id != 10340 {
3718
+				advice.AdviceDate = theTimeOne.Unix()
3719
+				advice.RecordDate = theTimeOne.Unix()
3720
+			}
3721
+
3712 3722
 			advice.Status = 1
3713 3723
 			advice.CreatedTime = time.Now().Unix()
3714 3724
 			advice.UpdatedTime = time.Now().Unix()

+ 0 - 6
controllers/new_mobile_api_controllers/dialysis_parameter_api_controller.go View File

@@ -30,18 +30,12 @@ func (this *DialysisParamerterApiController) GetMobileDialysisParameters() {
30 30
 	loc, _ := time.LoadLocation("Local")
31 31
 	adminUserInfo := this.GetMobileAdminUserInfo()
32 32
 	orgid := adminUserInfo.Org.Id
33
-	fmt.Println(orgid)
34 33
 	keywords := this.GetString("keyword")
35 34
 	start_time := this.GetString("start_time")
36
-	fmt.Println("start_time", start_time)
37 35
 	limit, _ := this.GetInt64("limit")
38
-	fmt.Println(limit)
39 36
 	page, _ := this.GetInt64("page")
40
-	fmt.Println(page)
41 37
 	partitionType, _ := this.GetInt64("partitionType")
42
-	fmt.Println("partiontype", partitionType)
43 38
 	scheduleType, _ := this.GetInt64("scheduleType")
44
-	fmt.Println(scheduleType)
45 39
 
46 40
 	theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
47 41
 	if len(keywords) > 0 {

+ 14 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go View File

@@ -1255,3 +1255,17 @@ func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patie
1255 1255
 	}
1256 1256
 	return
1257 1257
 }
1258
+
1259
+func (c *MobileHisApiController) GetPatientPlan() {
1260
+
1261
+	plan, _ := service.GetPatientPlan(10340)
1262
+
1263
+	for _, item := range plan {
1264
+		service.UpdatePatienPlan(item.ID, item.TreatmentPlan)
1265
+	}
1266
+	c.ServeSuccessJSON(map[string]interface{}{
1267
+		"plan": plan,
1268
+		"msg":  "ok",
1269
+	})
1270
+	return
1271
+}

+ 2 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go View File

@@ -180,4 +180,6 @@ func NewMobileAPIControllersRegisterRouters() {
180 180
 	beego.Router("/m/api/hisproject/delete", &MobileHisApiController{}, "Post:DeleteProject")
181 181
 	beego.Router("/m/api/prescription/create", &MobileHisApiController{}, "Post:CreateHisPrescription")
182 182
 
183
+	beego.Router("/m/api/patient/getpatientplan", &MobileHisApiController{}, "Get:GetPatientPlan")
184
+
183 185
 }

+ 28 - 8
controllers/patient_api_controller.go View File

@@ -84,7 +84,7 @@ func PatientApiRegistRouters() {
84 84
 
85 85
 }
86 86
 
87
-//GetPatientsList 取患者列表
87
+// GetPatientsList 取患者列表
88 88
 func (c *PatientApiController) GetPatientsList() {
89 89
 	var err error
90 90
 	defer func() {
@@ -157,7 +157,7 @@ func (c *PatientApiController) GetPatientsList() {
157 157
 
158 158
 }
159 159
 
160
-//GetPatientTotal
160
+// GetPatientTotal
161 161
 func (c *PatientApiController) GetPatientTotal() {
162 162
 	adminUserInfo := c.GetAdminUserInfo()
163 163
 
@@ -182,7 +182,7 @@ func (c *PatientApiController) GetPatientsAllList() {
182 182
 	return
183 183
 }
184 184
 
185
-//GenerateDialysisNo 生成透析号
185
+// GenerateDialysisNo 生成透析号
186 186
 func (c *PatientApiController) GenerateDialysisNo() {
187 187
 	adminUserInfo := c.GetAdminUserInfo()
188 188
 
@@ -206,7 +206,7 @@ func (c *PatientApiController) GenerateDialysisNo() {
206 206
 	return
207 207
 }
208 208
 
209
-//CreatePatient 创建患者
209
+// CreatePatient 创建患者
210 210
 func (c *PatientApiController) CreatePatient() {
211 211
 	record_date := c.GetString("record_date")
212 212
 	is_infectious, _ := c.GetInt64("is_infectious")
@@ -443,7 +443,7 @@ func (c *PatientApiController) CreatePatient() {
443 443
 	return
444 444
 }
445 445
 
446
-//EditPatient 修改
446
+// EditPatient 修改
447 447
 func (c *PatientApiController) EditPatient() {
448 448
 	id, _ := c.GetInt64("id", 0)
449 449
 
@@ -1074,7 +1074,7 @@ func (c *PatientApiController) DeleteDialysisSolution() {
1074 1074
 	return
1075 1075
 }
1076 1076
 
1077
-//GetDryWeights 取患者干体重调整铺
1077
+// GetDryWeights 取患者干体重调整铺
1078 1078
 func (c *PatientApiController) GetDryWeights() {
1079 1079
 	page, _ := c.GetInt64("page", 1)
1080 1080
 	limit, _ := c.GetInt64("limit", 10)
@@ -1289,9 +1289,9 @@ func (c *PatientApiController) CreateGroupAdvice() {
1289 1289
 	Remark := ""
1290 1290
 	if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
1291 1291
 		remark, _ := dataBody["remark"].(string)
1292
+
1292 1293
 		Remark = remark
1293 1294
 	}
1294
-
1295 1295
 	var advices []*models.GroupAdvice
1296 1296
 	if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
1297 1297
 		utils.ErrorLog("adviceNames")
@@ -1323,6 +1323,7 @@ func (c *PatientApiController) CreateGroupAdvice() {
1323 1323
 			return
1324 1324
 		}
1325 1325
 		adviceName, _ := adviceNameM["advice_name"].(string)
1326
+		fmt.Println("adviceceNMAE--------------------------------", adviceName)
1326 1327
 		if len(adviceName) == 0 {
1327 1328
 			utils.ErrorLog("len(advice_name) == 0")
1328 1329
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1416,6 +1417,10 @@ func (c *PatientApiController) CreateGroupAdvice() {
1416 1417
 			advice.DrugNameId = drug_name_id
1417 1418
 		}
1418 1419
 
1420
+		remark, _ := adviceNameM["remark"].(string)
1421
+		fmt.Println("哦哦撒搜哦搜搜哦remark-----------------------------------", remark)
1422
+		advice.Remark = remark
1423
+
1419 1424
 		if adviceType == 1 {
1420 1425
 
1421 1426
 			if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
@@ -1470,6 +1475,7 @@ func (c *PatientApiController) CreateGroupAdvice() {
1470 1475
 					child.PatientId = patientInfo.ID
1471 1476
 					child.AdviceDoctor = adminUserInfo.AdminUser.Id
1472 1477
 					child.IsSettle = 2
1478
+
1473 1479
 					if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
1474 1480
 						utils.ErrorLog("child advice_name")
1475 1481
 						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1535,6 +1541,20 @@ func (c *PatientApiController) CreateGroupAdvice() {
1535 1541
 
1536 1542
 					child.DeliveryWay = advice.DeliveryWay
1537 1543
 					child.ExecutionFrequency = advice.ExecutionFrequency
1544
+
1545
+					if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10340 || adminUserInfo.CurrentOrgId == 9671 {
1546
+						if child.PrescribingNumber == 0 {
1547
+							child.PrescribingNumber = 1
1548
+						}
1549
+						//查询该患者今日有没有双人核对
1550
+						check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.CurrentOrgId, patientInfo.ID, child.AdviceDate)
1551
+
1552
+						if check.ID > 0 {
1553
+							child.Checker = check.Modifier
1554
+							child.CheckState = 1
1555
+							child.CheckTime = time.Now().Unix()
1556
+						}
1557
+					}
1538 1558
 					advice.Children = append(advice.Children, &child)
1539 1559
 				}
1540 1560
 			}
@@ -3014,7 +3034,7 @@ func (c *PatientApiController) DeleteGroupAdvice() {
3014 3034
 	return
3015 3035
 }
3016 3036
 
3017
-//GetDoctorAdvices 医嘱列表
3037
+// GetDoctorAdvices 医嘱列表
3018 3038
 func (c *PatientApiController) GetDoctorAdvices() {
3019 3039
 	id, _ := c.GetInt64("id", 0)
3020 3040
 	adviceType, _ := c.GetInt64("advice_type", 0)

+ 152 - 55
controllers/pharmacy_controller.go View File

@@ -7,6 +7,8 @@ import (
7 7
 	"XT_New/utils"
8 8
 	"fmt"
9 9
 	"github.com/astaxie/beego"
10
+	"math"
11
+	"strconv"
10 12
 	"time"
11 13
 )
12 14
 
@@ -78,16 +80,7 @@ func (this *PharmacyController) TodayNumber() {
78 80
 	times := this.GetString("time", "")
79 81
 	timeLayout := "2006-01-02"
80 82
 	loc, _ := time.LoadLocation("Local")
81
-	//shift, err := this.GetInt64("shift", 0) //班次
82
-	//if err != nil {
83
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
84
-	//	return
85
-	//}
86
-	//partition, err := this.GetInt64("partition", 0) //分区
87
-	//if err != nil {
88
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
89
-	//	return
90
-	//}
83
+
91 84
 	var stime, etime int64
92 85
 	if times == "" {
93 86
 		stime, etime = service.GetNowTime()
@@ -96,26 +89,47 @@ func (this *PharmacyController) TodayNumber() {
96 89
 		stime = stmp.Unix()
97 90
 		etime = stime + 86399
98 91
 	}
99
-	//查询表里当天的数据
100
-	var wtotal int
101
-	wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
102
-	if err != nil {
103
-		utils.ErrorLog(err.Error())
104
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
92
+
93
+	if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
94
+		//查询表里当天的数据
95
+		var wtotal int
96
+		wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
97
+
98
+		if err != nil {
99
+			utils.ErrorLog(err.Error())
100
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
101
+			return
102
+		}
103
+
104
+		var itotal int
105
+		itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
106
+
107
+		if err != nil {
108
+			utils.ErrorLog(err.Error())
109
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
110
+			return
111
+		}
112
+		this.ServeSuccessJSON(map[string]interface{}{
113
+			"wtotal": wtotal,
114
+			"itotal": itotal,
115
+		})
105 116
 		return
106 117
 	}
107
-	var itotal int
108
-	itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
109
-	if err != nil {
110
-		utils.ErrorLog(err.Error())
111
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
118
+
119
+	if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
120
+		var wtotal int
121
+		var itotal int
122
+		//查找出库数量
123
+		wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
124
+
125
+		itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
126
+		this.ServeSuccessJSON(map[string]interface{}{
127
+			"wtotal": wtotal,
128
+			"itotal": itotal,
129
+		})
112 130
 		return
113 131
 	}
114
-	this.ServeSuccessJSON(map[string]interface{}{
115
-		"wtotal": wtotal,
116
-		"itotal": itotal,
117
-	})
118
-	return
132
+
119 133
 }
120 134
 func (this *PharmacyController) IssuedDrug() {
121 135
 	var err error
@@ -150,24 +164,43 @@ func (this *PharmacyController) IssuedDrug() {
150 164
 		stime = stmp.Unix()
151 165
 		etime = stime + 86399
152 166
 	}
153
-	//查询表里当天的数据
154
-	var flist []*models.TmpPatient
155
-	flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
156
-	if err != nil {
157
-		utils.ErrorLog(err.Error())
158
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
159
-		return
167
+
168
+	if orgid == 10164 || orgid == 3877 || orgid == 10188 || orgid == 10217 || orgid == 9671 {
169
+		list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1)
170
+		fmt.Println("list23323232323232", list)
171
+		var flist []models.TmpPatientOne
172
+		if len(list) > 0 {
173
+			for _, item := range list {
174
+				patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
175
+				flist = append(flist, patientlist)
176
+			}
177
+		}
178
+		this.ServeSuccessJSON(map[string]interface{}{
179
+			"list": flist,
180
+		})
160 181
 	}
161
-	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
162
-	if err != nil {
163
-		utils.ErrorLog(err.Error())
164
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
182
+
183
+	if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 {
184
+		//查询表里当天的数据
185
+		var flist []*models.TmpPatient
186
+		flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
187
+		if err != nil {
188
+			utils.ErrorLog(err.Error())
189
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
190
+			return
191
+		}
192
+		listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
193
+		if err != nil {
194
+			utils.ErrorLog(err.Error())
195
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
196
+			return
197
+		}
198
+		this.ServeSuccessJSON(map[string]interface{}{
199
+			"list": listt,
200
+		})
165 201
 		return
166 202
 	}
167
-	this.ServeSuccessJSON(map[string]interface{}{
168
-		"list": listt,
169
-	})
170
-	return
203
+
171 204
 }
172 205
 func (this *PharmacyController) WaitingDrug() {
173 206
 	var err error
@@ -202,24 +235,47 @@ func (this *PharmacyController) WaitingDrug() {
202 235
 		stime = stmp.Unix()
203 236
 		etime = stime + 86399
204 237
 	}
205
-	//查询表里当天的数据
206
-	var flist []*models.TmpPatient
207
-	flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
208
-	if err != nil {
209
-		utils.ErrorLog(err.Error())
210
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
238
+
239
+	if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
240
+		//查询表里当天的数据
241
+		var flist []*models.TmpPatient
242
+		flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
243
+
244
+		if err != nil {
245
+			utils.ErrorLog(err.Error())
246
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
247
+			return
248
+		}
249
+		listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
250
+		if err != nil {
251
+			utils.ErrorLog(err.Error())
252
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
253
+			return
254
+		}
255
+		this.ServeSuccessJSON(map[string]interface{}{
256
+			"list": listt,
257
+		})
211 258
 		return
212 259
 	}
213
-	listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
214
-	if err != nil {
215
-		utils.ErrorLog(err.Error())
216
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
260
+
261
+	//当天已发药的人数
262
+	if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
263
+
264
+		list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0)
265
+
266
+		var flist []models.TmpPatientOne
267
+		if len(list) > 0 {
268
+			for _, item := range list {
269
+				patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
270
+				flist = append(flist, patientlist)
271
+			}
272
+		}
273
+		this.ServeSuccessJSON(map[string]interface{}{
274
+			"list": flist,
275
+		})
217 276
 		return
218 277
 	}
219
-	this.ServeSuccessJSON(map[string]interface{}{
220
-		"list": listt,
221
-	})
222
-	return
278
+
223 279
 }
224 280
 
225 281
 //
@@ -290,6 +346,47 @@ func (this *PharmacyController) DispensingMedicine() {
290 346
 		etime = stime + 86399
291 347
 	}
292 348
 
349
+	advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
350
+	if len(advicelist) > 0 {
351
+		var total int64
352
+		var prescribing_number_total int64
353
+		for _, item := range advicelist {
354
+			houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
355
+			//查询该药品是否有库存
356
+			list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
357
+
358
+			//查询改药品信息
359
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
360
+			//判断单位是否相等
361
+			if medical.MaxUnit == item.PrescribingNumberUnit {
362
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
363
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
364
+				//转化为最小单位
365
+				total = list.Count*medical.MinNumber + list.StockMinNumber
366
+				prescribing_number_total = count * medical.MinNumber
367
+			}
368
+			if medical.MinUnit == item.PrescribingNumberUnit {
369
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
370
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
371
+				total = list.Count*medical.MinNumber + list.StockMinNumber
372
+				prescribing_number_total = count
373
+			}
374
+
375
+			if medical.IsUse != 1 {
376
+				//如果出库数量大于库存数量
377
+				if prescribing_number_total > total {
378
+					err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
379
+					if err != nil {
380
+						utils.ErrorLog(err.Error())
381
+						this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
382
+						return
383
+					}
384
+				}
385
+			}
386
+
387
+		}
388
+	}
389
+
293 390
 	err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
294 391
 	if err != nil {
295 392
 		utils.ErrorLog(err.Error())

+ 5 - 2
controllers/print_data_api_controller.go View File

@@ -37,7 +37,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
37 37
 	idStrs := strings.Split(schIDStr, ",")
38 38
 	adminUserInfo := this.GetAdminUserInfo()
39 39
 
40
-	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 {
40
+	if this.GetAdminUserInfo().CurrentOrgId == 10016 || this.GetAdminUserInfo().CurrentOrgId == 9882 || this.GetAdminUserInfo().CurrentOrgId == 10138 || this.GetAdminUserInfo().CurrentOrgId == 10278 || this.GetAdminUserInfo().CurrentOrgId == 9841 || this.GetAdminUserInfo().CurrentOrgId == 9845 || this.GetAdminUserInfo().CurrentOrgId == 10081 || this.GetAdminUserInfo().CurrentOrgId == 10215 || this.GetAdminUserInfo().CurrentOrgId == 10121 || this.GetAdminUserInfo().CurrentOrgId == 10234 || this.GetAdminUserInfo().CurrentOrgId == 10188 || this.GetAdminUserInfo().CurrentOrgId == 10217 || this.GetAdminUserInfo().CurrentOrgId == 10340 {
41 41
 		schedules, getScheduleErr := service.GetSchedulesSeven(adminUserInfo.CurrentOrgId, idStrs)
42 42
 		for _, item := range schedules {
43 43
 
@@ -136,7 +136,7 @@ func (this *PrintDataAPIController) ScheduleDialysisRecordPrintData() {
136 136
 		})
137 137
 	}
138 138
 
139
-	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 {
139
+	if this.GetAdminUserInfo().CurrentOrgId != 10016 && this.GetAdminUserInfo().CurrentOrgId != 9882 && this.GetAdminUserInfo().CurrentOrgId != 10138 && this.GetAdminUserInfo().CurrentOrgId != 10278 && this.GetAdminUserInfo().CurrentOrgId != 9841 && this.GetAdminUserInfo().CurrentOrgId != 9845 && this.GetAdminUserInfo().CurrentOrgId != 10081 && this.GetAdminUserInfo().CurrentOrgId != 10215 && this.GetAdminUserInfo().CurrentOrgId != 10121 && this.GetAdminUserInfo().CurrentOrgId != 10234 && this.GetAdminUserInfo().CurrentOrgId != 10188 && this.GetAdminUserInfo().CurrentOrgId != 10217 && this.GetAdminUserInfo().CurrentOrgId != 10340 {
140 140
 		schedules, getScheduleErr := service.GetSchedules(adminUserInfo.CurrentOrgId, idStrs)
141 141
 		for _, item := range schedules {
142 142
 			list, _ := service.GetDialysisOrderCountSeven(item.PatientID, item.ScheduleDate)
@@ -259,6 +259,8 @@ func (this *PrintDataAPIController) CourseRecordPrintData() {
259 259
 	patient, _ := service.GetPatientDetail(adminUserInfo.CurrentOrgId, patient_id)
260 260
 
261 261
 	adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
262
+
263
+	operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId)
262 264
 	if err != nil {
263 265
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
264 266
 		return
@@ -267,6 +269,7 @@ func (this *PrintDataAPIController) CourseRecordPrintData() {
267 269
 			"record":    record,
268 270
 			"patient":   patient,
269 271
 			"adminUser": adminUser,
272
+			"operators": operators,
270 273
 		})
271 274
 	}
272 275
 }

+ 1 - 1
controllers/self_drug_api_congtroller.go View File

@@ -2716,7 +2716,7 @@ func (this *SelfDrugApiController) GetInventoryModeList() {
2716 2716
 	})
2717 2717
 }
2718 2718
 
2719
-//库存优化接口
2719
+// 库存优化接口
2720 2720
 func (this *SelfDrugApiController) GetStorehouseList() {
2721 2721
 
2722 2722
 	orgId := this.GetAdminUserInfo().CurrentOrgId

+ 4 - 0
models/dialysis.go View File

@@ -549,6 +549,8 @@ type DoubleCheck struct {
549 549
 	CheckTime                  int64  `gorm:"column:check_time" json:"check_time"`
550 550
 	FirstCheckTime             int64  `gorm:"column:first_check_time" json:"first_check_time"`
551 551
 	EmployeeNumber             string `gorm:"column:employee_number" json:"employee_number" form:"employee_number"`
552
+	DialyzerBatchNumber        string `gorm:"column:dialyzer_batch_number" json:"dialyzer_batch_number" form:"dialyzer_batch_number"`
553
+	NeedleBatchNumber          string `gorm:"column:needle_batch_number" json:"needle_batch_number" form:"needle_batch_number"`
552 554
 }
553 555
 
554 556
 func (DoubleCheck) TableName() string {
@@ -1103,6 +1105,7 @@ type DialysisBeforePrepareGoods struct {
1103 1105
 	PatientId         int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1104 1106
 	OrderId           int64  `gorm:"column:order_id" json:"order_id" form:"order_id"`
1105 1107
 	NewCount          int64  `gorm:"column:new_count" json:"new_count" form:"new_count"`
1108
+	OldCount          int64  `gorm:"column:old_count" json:"old_count" form:"old_count"`
1106 1109
 }
1107 1110
 
1108 1111
 type NewDialysisBeforePrepareGoods struct {
@@ -1119,6 +1122,7 @@ type NewDialysisBeforePrepareGoods struct {
1119 1122
 	ChildNewDialysisBeforePrepareGoods []*NewDialysisBeforePrepareGoods `gorm:"ForeignKey:GoodId;AssociationForeignKey:GoodId" json:"child"`
1120 1123
 	PatientId                          int64                            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
1121 1124
 	OrderId                            int64                            `gorm:"column:order_id" json:"order_id" form:"order_id"`
1125
+	OldCount                           int64                            `gorm:"column:old_count" json:"old_count" form:"old_count"`
1122 1126
 }
1123 1127
 
1124 1128
 type OldDialysisBeforePrepareGoods struct {

+ 3 - 0
models/patient_models.go View File

@@ -1176,6 +1176,7 @@ type XtPatients struct {
1176 1176
 	UserSysBeforeCount           int64   `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
1177 1177
 	SchRemark                    string  `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
1178 1178
 	ScheduleRemark               string  `gorm:"column:schedule_remark" json:"schedule_remark" form:"schedule_remark"`
1179
+	TreatmentPlan                string  `gorm:"column:treatment_plan" json:"treatment_plan" form:"treatment_plan"`
1179 1180
 }
1180 1181
 
1181 1182
 func (XtPatients) TableName() string {
@@ -1817,6 +1818,8 @@ type XtPatientFirstDisease struct {
1817 1818
 	Ctime                 int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
1818 1819
 	Mtime                 int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
1819 1820
 	Status                int64  `gorm:"column:status" json:"status" form:"status"`
1821
+	ProjectId             string `gorm:"column:project_id" json:"project_id" form:"project_id"`
1822
+	InspectDate           string `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
1820 1823
 }
1821 1824
 
1822 1825
 func (XtPatientFirstDisease) TableName() string {

+ 11 - 0
models/pharmacy_models.go View File

@@ -31,6 +31,17 @@ type TmpPatient struct {
31 31
 	PatientID  int64
32 32
 	Name       string
33 33
 	DialysisNo string //透析号
34
+
35
+}
36
+
37
+type TmpPatientOne struct {
38
+	PatientID  int64  `gorm:"column:id" json:"PatientID" form:"id"`
39
+	DialysisNo string `gorm:"column:dialysis_no" json:"DialysisNo" form:"dialysis_no"`
40
+	Name       string `gorm:"column:name" json:"Name" form:"name"`
41
+}
42
+
43
+func (TmpPatientOne) TableName() string {
44
+	return "xt_patients"
34 45
 }
35 46
 
36 47
 //药品信息

+ 1 - 1
routers/router.go View File

@@ -11,7 +11,7 @@ import (
11 11
 func init() {
12 12
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
13 13
 		//AllowAllOrigins:  true,
14
-		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com"},
14
+		AllowOrigins: []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://localhost:9529", "http://localhost:9531", "http://xt.test.shengws.com", "http://new_mobile.test.sgjyun.com", "https://api.xt.test.sgjyun.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://mobile.sgjyun.com", "http://mobile.kuyicloud.com", "https://mobile.kuyicloud.com"},
15 15
 		//AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9528", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com","http://mobile.sgjyun.com","http://mobile.kuyicloud.com"},
16 16
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
17 17
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-XSRF-TOKEN", "Permission", "KyToken"},

+ 7 - 1
service/dialysis_service.go View File

@@ -1593,7 +1593,7 @@ func GetAllPcAdvicestByList(orgID int64, scheduleDate int64) (advices []*VMDocto
1593 1593
 	advice_list_str, _ := redis.Get(key).Result()
1594 1594
 
1595 1595
 	if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
1596
-		err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ? ", orgID, scheduleDate).Find(&advices).Error
1596
+		err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ?", orgID, scheduleDate).Find(&advices).Error
1597 1597
 		if err != nil {
1598 1598
 			if err == gorm.ErrRecordNotFound {
1599 1599
 				if len(advices) <= 0 {
@@ -2084,3 +2084,9 @@ func UpdateDoctorAdviceList(id int64, checker int64) error {
2084 2084
 	err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error
2085 2085
 	return err
2086 2086
 }
2087
+
2088
+func UpdateLastMonitorRecordToday(accumulated_blood_volume float64, id int64) error {
2089
+
2090
+	err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error
2091
+	return err
2092
+}

+ 3 - 3
service/dialysis_solution_service.go View File

@@ -495,7 +495,7 @@ func GetDialysisAdviceSchedulistSeven(orgID int64, schedule_type int64, partitio
495 495
 
496 496
 }
497 497
 
498
-func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
498
+func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
499 499
 
500 500
 	db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
501 501
 
@@ -505,8 +505,8 @@ func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_
505 505
 	if schedule_type > 0 {
506 506
 		db = db.Where("schedule_type = ?", schedule_type)
507 507
 	}
508
-	if partition_id > 0 {
509
-		db = db.Where("partition_id = ?", partition_id)
508
+	if len(partition_id) > 0 {
509
+		db = db.Where("partition_id in(?)", partition_id)
510 510
 	}
511 511
 
512 512
 	if orgID > 0 {

+ 12 - 0
service/his_service.go View File

@@ -2702,3 +2702,15 @@ func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
2702 2702
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
2703 2703
 	return order, err
2704 2704
 }
2705
+
2706
+func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
2707
+
2708
+	err = XTReadDB().Where("user_org_id = ? and status=  1", orgid).Find(&patient).Error
2709
+	return patient, err
2710
+}
2711
+
2712
+func UpdatePatienPlan(id int64, trement_plan string) error {
2713
+
2714
+	err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
2715
+	return err
2716
+}

+ 27 - 3
service/mobile_dialysis_service.go View File

@@ -4357,8 +4357,14 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
4357 4357
 func UpdateStockGoods(good_id int64, record_time int64, patient_id int64, count int64) error {
4358 4358
 
4359 4359
 	prepare := models.DialysisBeforePrepare{}
4360
+	var err error
4361
+	if count > 0 {
4362
+		err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
4363
+	}
4364
+	if count <= 0 {
4365
+		err = XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count, "status": 0}).Error
4366
+	}
4360 4367
 
4361
-	err := XTWriteDB().Model(&prepare).Where("good_id= ? and record_date = ? and patient_id = ? and count  <> 0 and status = 1", good_id, record_time, patient_id).Updates(map[string]interface{}{"count": count}).Error
4362 4368
 	return err
4363 4369
 }
4364 4370
 
@@ -4477,6 +4483,12 @@ func GetFistMonitor(orgid int64, patient_id int64, dialysis_date int64) (models.
4477 4483
 }
4478 4484
 
4479 4485
 func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceType int, patientType int, adminUserId int64, deliverWay string, scheduleType int64, partitonType int64, patient_id int64, execution_state int64, cost_type int64, execution_frequency string) ([]*MScheduleDoctorAdviceVM, error) {
4486
+
4487
+	fmt.Println("execution_frequency---------------------------", execution_frequency)
4488
+	fmt.Println("cost_type-----------", cost_type)
4489
+	fmt.Println("adviceType-----------", adviceType)
4490
+	fmt.Println("patientType---------", patientType)
4491
+	fmt.Println("len(deliverWay)--------", len(deliverWay))
4480 4492
 	var vms []*MScheduleDoctorAdviceVM
4481 4493
 	adviceWhere := ""
4482 4494
 	adviceCondition := []interface{}{}
@@ -5316,6 +5328,7 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
5316 5328
 		}
5317 5329
 
5318 5330
 	} else if adviceType == 2 && len(deliverWay) > 0 {
5331
+
5319 5332
 		if patientType == 0 {
5320 5333
 			if patient_id > 0 {
5321 5334
 				if execution_state > 0 {
@@ -5592,6 +5605,11 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
5592 5605
 		}
5593 5606
 
5594 5607
 	} else if adviceType == 2 && len(deliverWay) <= 0 {
5608
+		fmt.Println("寄哪里233223322323233232", patientType)
5609
+		fmt.Println("patient_id", patient_id)
5610
+		fmt.Println("execution_state000000", execution_state)
5611
+		fmt.Println("cost_type", cost_type)
5612
+		fmt.Println("len23323232", len(execution_frequency))
5595 5613
 		if patientType == 0 {
5596 5614
 			if patient_id > 0 {
5597 5615
 				if execution_state > 0 {
@@ -5668,8 +5686,14 @@ func MobileGetScheduleDoctorAdvicesOne(orgID int64, scheduleDate int64, adviceTy
5668 5686
 						}
5669 5687
 
5670 5688
 					} else {
5671
-						adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
5672
-						adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
5689
+						if len(execution_frequency) > 0 {
5690
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ? and execution_frequency = ?"
5691
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate, execution_frequency)
5692
+						} else {
5693
+							adviceWhere = "status = 1 AND user_org_id = ? AND advice_type = 2 AND record_date = ?"
5694
+							adviceCondition = append(adviceCondition, adviceWhere, orgID, scheduleDate)
5695
+						}
5696
+
5673 5697
 					}
5674 5698
 
5675 5699
 				}

+ 602 - 8
service/new_warehouse_service.go View File

@@ -26,8 +26,10 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
26 26
 	// 如果没有对应的库存,则报错
27 27
 
28 28
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
29
-	if err != nil {
30
-		return errors.New("库存数量不足")
29
+	if goods.Count > 0 {
30
+		if err != nil {
31
+			return errors.New("库存数量不足")
32
+		}
31 33
 	}
32 34
 
33 35
 	stock_number = warehouse.StockCount
@@ -36,6 +38,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
36 38
 	if stock_number >= deliver_number {
37 39
 
38 40
 		maxNumber = goods.Count
41
+
39 42
 		//出库
40 43
 		warehouse.StockCount = warehouse.StockCount - maxNumber
41 44
 		warehouse.Mtime = time.Now().Unix()
@@ -352,7 +355,7 @@ func ConsumablesGoodDelivery(orgID int64, patient_id int64, record_time int64, g
352 355
 			warehouseOutInfo.Price = goodsInfo.PackingPrice
353 356
 		}
354 357
 		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
355
-		//fmt.Println("errcodes23332322332323223", errcodes, goods.ProjectId)
358
+
356 359
 		if errcodes == gorm.ErrRecordNotFound {
357 360
 			errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
358 361
 			if errOne != nil {
@@ -1494,11 +1497,14 @@ func BloodHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseou
1494 1497
 			cancel_count += item.Count
1495 1498
 		}
1496 1499
 
1497
-		fmt.Println("deliver_number", deliver_number)
1498
-		fmt.Println("out_count", out_count)
1499
-		fmt.Println("cancel_count", cancel_count)
1500
+		//fmt.Println("deliver_number", deliver_number)
1501
+		//fmt.Println("out_count", out_count)
1502
+		//fmt.Println("cancel_count", cancel_count)
1503
+		//
1504
+		//fmt.Println("出库数据", deliver_number)
1505
+		//fmt.Println("出库流水---------------------", out_count, cancel_count)
1500 1506
 		//如果本次出库数据大于历史出库数据 新增1条流水
1501
-		if deliver_number > (out_count - cancel_count) {
1507
+		if deliver_number >= (out_count - cancel_count) {
1502 1508
 			drugflow := models.DrugFlow{
1503 1509
 				WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
1504 1510
 				WarehouseOutId:          warehouseout.ID,
@@ -3004,7 +3010,8 @@ func ConsumablesGoodDeliveryFivety(orgID int64, patient_id int64, record_time in
3004 3010
 		if warehouse.StockCount < 0 {
3005 3011
 			return errors.New("库存数量不足")
3006 3012
 		}
3007
-		err := tx.Save(&warehouse).Error
3013
+		var info models.WarehousingInfo
3014
+		err := tx.Model(&info).Where("id = ?", warehouse.ID).Updates(map[string]interface{}{"stock_count": warehouse.StockCount}).Error
3008 3015
 		if err != nil {
3009 3016
 			return err
3010 3017
 		}
@@ -3548,3 +3555,590 @@ func ConsumablesGoodDeliveryFivety(orgID int64, patient_id int64, record_time in
3548 3555
 	}
3549 3556
 	return err
3550 3557
 }
3558
+
3559
+func ConsumablesGoodDeliveryNew(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
3560
+
3561
+	//开事务
3562
+	tx := XTWriteDB().Begin()
3563
+	if err != nil {
3564
+		utils.ErrorLog("事务失败,原因为: %v", err)
3565
+		tx.Rollback()
3566
+	} else {
3567
+		fmt.Println("err-----------------------", err)
3568
+		tx.Commit()
3569
+	}
3570
+	var deliver_number int64 = 0
3571
+	var stock_number int64 = 0
3572
+	var maxNumber int64 = 0
3573
+
3574
+	deliver_number = goods.Count
3575
+
3576
+	// 根据先进先出原则,查询最先入库的批次,进行出库
3577
+	// 如果没有对应的库存,则报错
3578
+
3579
+	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId, goods.StorehouseId)
3580
+	if goods.Count > 0 {
3581
+		if err != nil {
3582
+			return errors.New("库存数量不足")
3583
+		}
3584
+	}
3585
+
3586
+	stock_number = warehouse.StockCount
3587
+
3588
+	// 当库存数量大于或等于出库数量的话,则正常出库该批次
3589
+	if stock_number >= deliver_number {
3590
+
3591
+		maxNumber = goods.Count
3592
+
3593
+		//出库
3594
+		warehouse.StockCount = warehouse.StockCount - maxNumber
3595
+		warehouse.Mtime = time.Now().Unix()
3596
+		if warehouse.StockCount < 0 {
3597
+			return errors.New("库存数量不足")
3598
+		}
3599
+
3600
+		err := tx.Save(&warehouse).Error
3601
+		if err != nil {
3602
+			return err
3603
+		}
3604
+		//更新his_prescripton_project出库状态值
3605
+		UpdateHisPrescriptionProjectStatus(goods.GoodId, record_time, orgID, patient_id)
3606
+
3607
+		var info []*models.WarehousingInfo
3608
+		err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goods.GoodId, orgID, goods.StorehouseId).Find(&info).Error
3609
+		var sum_count int64
3610
+		for _, item := range info {
3611
+			sum_count += item.StockCount
3612
+		}
3613
+
3614
+		warehouseOutInfo := &models.WarehouseOutInfo{
3615
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3616
+			WarehouseOutId:          warehouseOut.ID,
3617
+			WarehouseInfotId:        warehouse.ID,
3618
+			Status:                  1,
3619
+			Ctime:                   time.Now().Unix(),
3620
+			Remark:                  warehouse.Remark,
3621
+			OrgId:                   orgID,
3622
+			Type:                    1,
3623
+			Manufacturer:            warehouse.Manufacturer,
3624
+			Dealer:                  warehouse.Dealer,
3625
+			IsSys:                   1,
3626
+			SysRecordTime:           record_time,
3627
+			GoodTypeId:              goods.GoodTypeId,
3628
+			GoodId:                  goods.GoodId,
3629
+			PatientId:               patient_id,
3630
+			Number:                  warehouse.Number,
3631
+			LicenseNumber:           warehouse.LicenseNumber,
3632
+			Price:                   warehouse.PackingPrice,
3633
+			ExpiryDate:              warehouse.ExpiryDate,
3634
+			ProductDate:             warehouse.ProductDate,
3635
+			ProjectId:               goods.ProjectId,
3636
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3637
+			StorehouseId:            goods.StorehouseId,
3638
+			IsCheck:                 1,
3639
+			OverCount:               sum_count,
3640
+			RegisterNumber:          warehouse.RegisterNumber,
3641
+		}
3642
+		warehouseOutInfo.Count = count
3643
+		if orgID == 9671 || orgID == 10265 {
3644
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3645
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3646
+		}
3647
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3648
+		if errcodes == gorm.ErrRecordNotFound {
3649
+			err := tx.Create(&warehouseOutInfo).Error
3650
+			if err != nil {
3651
+				return err
3652
+			}
3653
+		} else if errcodes == nil {
3654
+
3655
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3656
+			if count != outInfoOne.Count {
3657
+
3658
+				outInfo := models.WarehouseOutInfo{}
3659
+				err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3660
+				if err != nil {
3661
+					return err
3662
+				}
3663
+			}
3664
+
3665
+		}
3666
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3667
+
3668
+		//查询已经出库的数据
3669
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3670
+		var out_count int64
3671
+		var out_count_one int64
3672
+		for _, item := range flowGood {
3673
+			out_count += item.Count
3674
+		}
3675
+
3676
+		//查询退库数据
3677
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3678
+		for _, item := range flowGoodTwo {
3679
+			out_count_one += item.Count
3680
+		}
3681
+		//如果本次出库数据大于历史出库数据 新增1条流水
3682
+		if count > (out_count - out_count_one) {
3683
+
3684
+			flow := models.VmStockFlow{
3685
+				WarehouseOutId:          warehouseOut.ID,
3686
+				WarehousingId:           warehouse.ID,
3687
+				GoodId:                  goods.GoodId,
3688
+				Number:                  warehouse.Number,
3689
+				ProductDate:             warehouse.ProductDate,
3690
+				ExpireDate:              warehouse.ExpiryDate,
3691
+				Count:                   count - out_count + out_count_one,
3692
+				Price:                   warehouse.PackingPrice,
3693
+				Status:                  1,
3694
+				Ctime:                   time.Now().Unix(),
3695
+				UserOrgId:               orgID,
3696
+				Manufacturer:            warehouse.Manufacturer,
3697
+				Dealer:                  warehouse.Dealer,
3698
+				LicenseNumber:           warehouse.LicenseNumber,
3699
+				IsEdit:                  2,
3700
+				Creator:                 warehouseOut.Creater,
3701
+				SystemTime:              record_time,
3702
+				ConsumableType:          3,
3703
+				WarehouseOutDetailId:    lastOut.ID,
3704
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3705
+				IsSys:                   1,
3706
+				PatientId:               patient_id,
3707
+				ProjectId:               goods.ProjectId,
3708
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3709
+				StorehouseId:            goods.StorehouseId,
3710
+				OverCount:               sum_count,
3711
+				BuyPrice:                warehouse.Price,
3712
+				RegisterNumber:          warehouse.RegisterNumber,
3713
+			}
3714
+			if orgID == 9671 || orgID == 10265 {
3715
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3716
+				flow.Price = goodsInfo.PackingPrice
3717
+				flow.BuyPrice = goodsInfo.BuyPrice
3718
+			}
3719
+
3720
+			err := tx.Create(&flow).Error
3721
+			if err != nil {
3722
+				return err
3723
+			}
3724
+
3725
+		}
3726
+
3727
+		//如果本次出库数据小于历史出库数据 新增1条退库流水
3728
+
3729
+		if count < (out_count - out_count_one) {
3730
+
3731
+			operation_time := time.Now().Unix()
3732
+
3733
+			//创建退库单
3734
+			timeStr := time.Now().Format("2006-01-02")
3735
+			timeArr := strings.Split(timeStr, "-")
3736
+			total, _ := FindAllCancelStockTotal(orgID)
3737
+			total = total + 1
3738
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
3739
+
3740
+			cancelStock := models.CancelStock{
3741
+				OrderNumber:  orderNumber,
3742
+				OperaTime:    operation_time,
3743
+				OrgId:        orgID,
3744
+				Creater:      warehouseOut.Creater,
3745
+				Ctime:        time.Now().Unix(),
3746
+				Status:       1,
3747
+				ReturnTime:   record_time,
3748
+				Type:         1,
3749
+				StorehouseId: goods.StorehouseId,
3750
+				IsCheck:      1,
3751
+			}
3752
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
3753
+			if msgerrkonde == gorm.ErrRecordNotFound {
3754
+
3755
+				err := tx.Create(&cancelStock).Error
3756
+				if err != nil {
3757
+					return err
3758
+				}
3759
+			}
3760
+
3761
+			cancel, _ := GetLastCancelStockById(orgID)
3762
+
3763
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
3764
+			deaerler, _ := GetDealerById(warehouse.Dealer)
3765
+			cancelStockInfo := models.CancelStockInfo{
3766
+				GoodId:          goods.GoodId,
3767
+				CancelStockId:   cancel.ID,
3768
+				GoodTypeId:      goods.GoodTypeId,
3769
+				Count:           out_count - out_count_one - count,
3770
+				Price:           warehouse.PackingPrice,
3771
+				Total:           0,
3772
+				ProductDate:     warehouse.ProductDate,
3773
+				ExpiryDate:      warehouse.ExpiryDate,
3774
+				Ctime:           time.Now().Unix(),
3775
+				Status:          1,
3776
+				OrgId:           orgID,
3777
+				OrderNumber:     cancel.OrderNumber,
3778
+				Type:            0,
3779
+				Dealer:          deaerler.DealerName,
3780
+				Manufacturer:    manufacturer.ManufacturerName,
3781
+				Number:          warehouse.Number,
3782
+				RegisterAccount: "",
3783
+				Remark:          "",
3784
+				WarehouseInfoId: warehouse.ID,
3785
+				PatientId:       patient_id,
3786
+				RecordDate:      record_time,
3787
+				StorehouseId:    goods.StorehouseId,
3788
+				IsCheck:         1,
3789
+			}
3790
+			if orgID == 9671 || orgID == 10265 {
3791
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3792
+				cancelStockInfo.Price = goodsInfo.PackingPrice
3793
+			}
3794
+
3795
+			err := tx.Create(&cancelStockInfo).Error
3796
+			if err != nil {
3797
+				return err
3798
+			}
3799
+
3800
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
3801
+
3802
+			flow := models.VmStockFlow{
3803
+				WarehousingId:           warehouse.ID,
3804
+				GoodId:                  goods.GoodId,
3805
+				Number:                  warehouse.Number,
3806
+				LicenseNumber:           warehouse.LicenseNumber,
3807
+				Count:                   out_count - out_count_one - count,
3808
+				UserOrgId:               orgID,
3809
+				PatientId:               patient_id,
3810
+				SystemTime:              record_time,
3811
+				ConsumableType:          7,
3812
+				IsSys:                   1,
3813
+				WarehousingOrder:        "",
3814
+				WarehouseOutId:          lastOut.WarehouseOutId,
3815
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
3816
+				IsEdit:                  0,
3817
+				CancelStockId:           cancel.ID,
3818
+				CancelOrderNumber:       cancel.OrderNumber,
3819
+				Manufacturer:            manufacturer.ID,
3820
+				Dealer:                  0,
3821
+				Creator:                 warehouseOut.Creater,
3822
+				UpdateCreator:           0,
3823
+				Status:                  1,
3824
+				Ctime:                   time.Now().Unix(),
3825
+				Mtime:                   0,
3826
+				Price:                   warehouse.PackingPrice,
3827
+				WarehousingDetailId:     warehouse.ID,
3828
+				WarehouseOutDetailId:    lastOut.ID,
3829
+				CancelOutDetailId:       cancelInfo.ID,
3830
+				ProductDate:             warehouse.ProductDate,
3831
+				ExpireDate:              warehouse.ExpiryDate,
3832
+				StorehouseId:            goods.StorehouseId,
3833
+				BuyPrice:                warehouse.Price,
3834
+				ProjectId:               goods.ProjectId,
3835
+				OverCount:               sum_count,
3836
+				RegisterNumber:          warehouse.RegisterNumber,
3837
+			}
3838
+			if orgID == 9671 || orgID == 10265 {
3839
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3840
+				flow.Price = goodsInfo.PackingPrice
3841
+				flow.BuyPrice = goodsInfo.BuyPrice
3842
+			}
3843
+
3844
+			err = tx.Create(&flow).Error
3845
+			if err != nil {
3846
+				return err
3847
+			}
3848
+		}
3849
+
3850
+		details := models.BloodAutomaticReduceDetail{
3851
+			WarehouseOutId:          lastOut.ID,
3852
+			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
3853
+			PatientId:               patient_id,
3854
+			Ctime:                   time.Now().Unix(),
3855
+			Mtime:                   time.Now().Unix(),
3856
+			Status:                  1,
3857
+			RecordTime:              record_time,
3858
+			OrgId:                   orgID,
3859
+			GoodId:                  goods.GoodId,
3860
+			GoodTypeId:              goods.GoodTypeId,
3861
+			Count:                   count,
3862
+			ProjectId:               goods.ProjectId,
3863
+			StorehouseId:            goods.StorehouseId,
3864
+		}
3865
+
3866
+		////查询该耗材已经出库的数量
3867
+		_, errcode := GetAutoMaticReduceDetailTwenty(orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId)
3868
+		if errcode == gorm.ErrRecordNotFound {
3869
+
3870
+			err := tx.Create(&details).Error
3871
+			if err != nil {
3872
+				return err
3873
+			}
3874
+		} else if errcode == nil {
3875
+
3876
+			detail := models.BloodAutomaticReduceDetail{}
3877
+			err := tx.Model(&detail).Where("org_id = ? and patient_id = ? and record_time = ? and status =1 and good_id = ? and good_type_id = ?", orgID, patient_id, record_time, goods.GoodId, goods.GoodTypeId).Updates(map[string]interface{}{"status": 0, "count": 0}).Error
3878
+			if err != nil {
3879
+				return err
3880
+			}
3881
+
3882
+			err = tx.Create(&detail).Error
3883
+			if err != nil {
3884
+				return err
3885
+			}
3886
+		}
3887
+
3888
+		return nil
3889
+	} else {
3890
+
3891
+		// 当刚批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
3892
+		warehouse.StockCount = 0
3893
+		warehouse.Mtime = time.Now().Unix()
3894
+
3895
+		err := tx.Save(&warehouse).Error
3896
+		if err != nil {
3897
+			return err
3898
+		}
3899
+		var info []*models.WarehousingInfo
3900
+		err = tx.Where("good_id = ? and org_id = ? and is_check =1 and status= 1 and stock_count > 0 and storehouse_id = ?", goods.GoodId, orgID, goods.StorehouseId).Find(&info).Error
3901
+		var sum_count int64
3902
+		for _, item := range info {
3903
+			sum_count += item.StockCount
3904
+		}
3905
+		warehouseOutInfo := &models.WarehouseOutInfo{
3906
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3907
+			WarehouseOutId:          warehouseOut.ID,
3908
+			WarehouseInfotId:        warehouse.ID,
3909
+			Status:                  1,
3910
+			Ctime:                   time.Now().Unix(),
3911
+			Remark:                  warehouse.Remark,
3912
+			OrgId:                   orgID,
3913
+			Type:                    1,
3914
+			Manufacturer:            warehouse.Manufacturer,
3915
+			Dealer:                  warehouse.Dealer,
3916
+			IsSys:                   1,
3917
+			SysRecordTime:           record_time,
3918
+			GoodTypeId:              goods.GoodTypeId,
3919
+			GoodId:                  goods.GoodId,
3920
+			PatientId:               patient_id,
3921
+			Number:                  warehouse.Number,
3922
+			LicenseNumber:           warehouse.LicenseNumber,
3923
+			Price:                   warehouse.PackingPrice,
3924
+			ExpiryDate:              warehouse.ExpiryDate,
3925
+			ProductDate:             warehouse.ProductDate,
3926
+			ProjectId:               goods.ProjectId,
3927
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
3928
+			StorehouseId:            goods.StorehouseId,
3929
+			IsCheck:                 1,
3930
+			OverCount:               sum_count,
3931
+			RegisterNumber:          warehouse.RegisterNumber,
3932
+		}
3933
+		warehouseOutInfo.Count = stock_number
3934
+		if orgID == 9671 || orgID == 10265 {
3935
+			goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
3936
+			warehouseOutInfo.Price = goodsInfo.PackingPrice
3937
+		}
3938
+		_, errcodes := GetWarehouseOutInfoIsExistOne(goods.GoodId, patient_id, record_time, goods.ProjectId)
3939
+
3940
+		if errcodes == gorm.ErrRecordNotFound {
3941
+
3942
+			errors := tx.Create(warehouseOutInfo).Error
3943
+			if errors != nil {
3944
+				return errors
3945
+			}
3946
+		} else if errcodes == nil {
3947
+			goods.Count = deliver_number - stock_number
3948
+			//更新数量为  该批次剩余数量  + 还有未出的数量
3949
+			warehouseOutInfo.Count = stock_number
3950
+			outInfoOne, _ := GetWarehouseOutInfoIsExistTwo(goods.GoodId, patient_id, record_time, goods.ProjectId)
3951
+			if count != outInfoOne.Count {
3952
+
3953
+				outInfo := models.WarehouseOutInfo{}
3954
+				err := tx.Model(&outInfo).Where("good_id = ? and patient_id = ? and sys_record_time  =? and status = 1", goods.GoodId, patient_id, record_time).Updates(map[string]interface{}{"warehouse_out_id": warehouseOutInfo.WarehouseOutId, "WarehouseOutOrderNumber": warehouseOutInfo.WarehouseOutOrderNumber, "sys_record_time": warehouseOutInfo.SysRecordTime, "good_type_id": warehouseOutInfo.GoodTypeId, "patient_id": warehouseOutInfo.PatientId, "consumable_type": warehouseOutInfo.ConsumableType, "count": warehouseOutInfo.Count, "price": warehouseOutInfo.Price, "dealer": warehouseOutInfo.Dealer, "manufacturer": warehouseOutInfo.Manufacturer, "number": warehouseOutInfo.Number, "license_number": warehouseOutInfo.LicenseNumber, "over_count": warehouseOutInfo.OverCount}).Error
3955
+				if err != nil {
3956
+					return err
3957
+				}
3958
+			}
3959
+
3960
+		}
3961
+		lastOut, _ := FindWarehouseOutInfoByPatientId(patient_id, record_time, goods.GoodId, orgID)
3962
+		//查询该该批次已经出库的数据
3963
+		flowGood, _ := GetStockFlowIsBatchNumber(warehouse.ID, patient_id, record_time, goods.GoodId)
3964
+		var out_count int64
3965
+		var out_count_one int64
3966
+		for _, item := range flowGood {
3967
+			out_count += item.Count
3968
+		}
3969
+		flowGoodTwo, _ := GetStockFlowIsBatchNumberThree(patient_id, record_time, goods.GoodId)
3970
+		for _, item := range flowGoodTwo {
3971
+			out_count_one += item.Count
3972
+		}
3973
+		//如果出库数量 大于 历史出库数据 新增1条流水
3974
+		if count > out_count-out_count_one {
3975
+			flow := models.VmStockFlow{
3976
+				WarehouseOutId:          warehouseOut.ID,
3977
+				WarehousingId:           warehouse.ID,
3978
+				GoodId:                  goods.GoodId,
3979
+				Number:                  warehouse.Number,
3980
+				ProductDate:             warehouse.ProductDate,
3981
+				ExpireDate:              warehouse.ExpiryDate,
3982
+				Count:                   stock_number,
3983
+				Price:                   warehouse.PackingPrice,
3984
+				Status:                  1,
3985
+				Ctime:                   time.Now().Unix(),
3986
+				UserOrgId:               orgID,
3987
+				Manufacturer:            warehouse.Manufacturer,
3988
+				Dealer:                  warehouse.Dealer,
3989
+				LicenseNumber:           warehouse.LicenseNumber,
3990
+				IsEdit:                  2,
3991
+				Creator:                 warehouseOut.Creater,
3992
+				SystemTime:              record_time,
3993
+				ConsumableType:          3,
3994
+				WarehouseOutDetailId:    lastOut.ID,
3995
+				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
3996
+				IsSys:                   1,
3997
+				PatientId:               patient_id,
3998
+				ProjectId:               goods.ProjectId,
3999
+				SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4000
+				StorehouseId:            goods.StorehouseId,
4001
+				OverCount:               sum_count,
4002
+				BuyPrice:                warehouse.Price,
4003
+				RegisterNumber:          warehouse.RegisterNumber,
4004
+			}
4005
+			if orgID == 9671 || orgID == 10265 {
4006
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4007
+				flow.Price = goodsInfo.PackingPrice
4008
+				flow.BuyPrice = goodsInfo.BuyPrice
4009
+			}
4010
+
4011
+			err := tx.Create(&flow).Error
4012
+			if err != nil {
4013
+				return err
4014
+			}
4015
+		}
4016
+		//退库
4017
+		if count < out_count-out_count_one {
4018
+			operation_time := time.Now().Unix()
4019
+
4020
+			//创建退库单
4021
+			timeStr := time.Now().Format("2006-01-02")
4022
+			timeArr := strings.Split(timeStr, "-")
4023
+			total, _ := FindAllCancelStockTotal(orgID)
4024
+			total = total + 1
4025
+			orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
4026
+
4027
+			cancelStock := models.CancelStock{
4028
+				OrderNumber:  orderNumber,
4029
+				OperaTime:    operation_time,
4030
+				OrgId:        orgID,
4031
+				Creater:      warehouseOut.Creater,
4032
+				Ctime:        time.Now().Unix(),
4033
+				Status:       1,
4034
+				ReturnTime:   record_time,
4035
+				Type:         1,
4036
+				StorehouseId: goods.StorehouseId,
4037
+				IsCheck:      1,
4038
+			}
4039
+			_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, orgID)
4040
+			if msgerrkonde == gorm.ErrRecordNotFound {
4041
+
4042
+				err := tx.Create(&cancelStock).Error
4043
+				if err != nil {
4044
+					return err
4045
+				}
4046
+			}
4047
+
4048
+			cancel, _ := GetLastCancelStockById(orgID)
4049
+
4050
+			manufacturer, _ := GetManufactureById(warehouse.Manufacturer)
4051
+			deaerler, _ := GetDealerById(warehouse.Dealer)
4052
+			cancelStockInfo := models.CancelStockInfo{
4053
+				GoodId:          goods.GoodId,
4054
+				CancelStockId:   cancel.ID,
4055
+				GoodTypeId:      goods.GoodTypeId,
4056
+				Count:           out_count - out_count_one - count,
4057
+				Price:           warehouse.PackingPrice,
4058
+				Total:           0,
4059
+				ProductDate:     warehouse.ProductDate,
4060
+				ExpiryDate:      warehouse.ExpiryDate,
4061
+				Ctime:           time.Now().Unix(),
4062
+				Status:          1,
4063
+				OrgId:           orgID,
4064
+				OrderNumber:     cancel.OrderNumber,
4065
+				Type:            0,
4066
+				Dealer:          deaerler.DealerName,
4067
+				Manufacturer:    manufacturer.ManufacturerName,
4068
+				Number:          warehouse.Number,
4069
+				RegisterAccount: "",
4070
+				Remark:          "",
4071
+				WarehouseInfoId: warehouse.ID,
4072
+				PatientId:       patient_id,
4073
+				RecordDate:      record_time,
4074
+				StorehouseId:    goods.StorehouseId,
4075
+				IsCheck:         1,
4076
+			}
4077
+			if orgID == 9671 || orgID == 10265 {
4078
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4079
+				cancelStockInfo.Price = goodsInfo.PackingPrice
4080
+			}
4081
+
4082
+			err := tx.Create(&cancelStockInfo).Error
4083
+			if err != nil {
4084
+				return err
4085
+			}
4086
+
4087
+			cancelInfo, _ := GetLastCancelStockInfoByGoodId(goods.GoodId)
4088
+
4089
+			flow := models.VmStockFlow{
4090
+				WarehousingId:           warehouse.ID,
4091
+				GoodId:                  goods.GoodId,
4092
+				Number:                  warehouse.Number,
4093
+				LicenseNumber:           warehouse.LicenseNumber,
4094
+				Count:                   out_count - count,
4095
+				UserOrgId:               orgID,
4096
+				PatientId:               patient_id,
4097
+				SystemTime:              record_time,
4098
+				ConsumableType:          7,
4099
+				IsSys:                   1,
4100
+				WarehousingOrder:        "",
4101
+				WarehouseOutId:          lastOut.WarehouseOutId,
4102
+				WarehouseOutOrderNumber: lastOut.WarehouseOutOrderNumber,
4103
+				IsEdit:                  0,
4104
+				CancelStockId:           cancel.ID,
4105
+				CancelOrderNumber:       cancel.OrderNumber,
4106
+				Manufacturer:            manufacturer.ID,
4107
+				Dealer:                  0,
4108
+				Creator:                 warehouseOut.Creater,
4109
+				UpdateCreator:           0,
4110
+				Status:                  1,
4111
+				Ctime:                   time.Now().Unix(),
4112
+				Mtime:                   0,
4113
+				Price:                   warehouse.PackingPrice,
4114
+				WarehousingDetailId:     warehouse.ID,
4115
+				WarehouseOutDetailId:    lastOut.ID,
4116
+				CancelOutDetailId:       cancelInfo.ID,
4117
+				ProductDate:             warehouse.ProductDate,
4118
+				ExpireDate:              warehouse.ExpiryDate,
4119
+				StorehouseId:            goods.StorehouseId,
4120
+				BuyPrice:                warehouse.Price,
4121
+				ProjectId:               goods.ProjectId,
4122
+				OverCount:               sum_count,
4123
+				RegisterNumber:          warehouse.RegisterNumber,
4124
+			}
4125
+			if orgID == 9671 || orgID == 10265 {
4126
+				goodsInfo, _ := FindeGoodInfo(orgID, goods.ProjectId)
4127
+				flow.Price = goodsInfo.PackingPrice
4128
+				flow.BuyPrice = goodsInfo.BuyPrice
4129
+			}
4130
+			err = tx.Create(&flow).Error
4131
+			if err != nil {
4132
+				return err
4133
+			}
4134
+		}
4135
+
4136
+		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
4137
+		goods.Count = deliver_number - stock_number
4138
+
4139
+		ConsumablesGoodDelivery(orgID, patient_id, record_time, goods, warehouseOut, count)
4140
+
4141
+	}
4142
+
4143
+	return nil
4144
+}

+ 2 - 2
service/patientmanage_service.go View File

@@ -1055,7 +1055,7 @@ func GetInspectionDetail(patientid int64, date int64, orgid int64, projectid int
1055 1055
 	if projectid > 0 {
1056 1056
 		db = db.Where("x.project_id = ?", projectid)
1057 1057
 	}
1058
-	err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0)   ").Scan(&inspection).Error
1058
+	err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0)   ").Scan(&inspection).Error
1059 1059
 	return inspection, err
1060 1060
 }
1061 1061
 
@@ -1948,7 +1948,7 @@ func GetFirstDetailById(id int64) (models.XtPatientFirstDisease, error) {
1948 1948
 
1949 1949
 func UpdatePatientFirstDisease(disease models.XtPatientFirstDisease, id int64) error {
1950 1950
 
1951
-	err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan}).Error
1951
+	err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan, "project_id": disease.ProjectId, "inspect_date": disease.InspectDate}).Error
1952 1952
 	return err
1953 1953
 }
1954 1954
 

+ 185 - 115
service/pharmacy_service.go View File

@@ -30,7 +30,6 @@ func SaveErrs(org_id int64, input *context.BeegoInput, err error) {
30 30
 	XTWriteDB().Create(&tmp)
31 31
 }
32 32
 
33
-//
34 33
 func SavePharmacy() (err error) {
35 34
 	var advice_info []*models.HisDoctorAdviceInfo
36 35
 	err = XTReadDB().Raw("select * from xt_doctor_advice where id > 21780 and id < 21790").Scan(&advice_info).Error
@@ -40,18 +39,18 @@ func SavePharmacy() (err error) {
40 39
 	return nil
41 40
 }
42 41
 
43
-//查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
42
+// 查询药房中某一天的患者人数,is_medicine:0未发,1已发(改)
44 43
 func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err error) {
45 44
 	//orgid = 9675
46 45
 	InitDrugidIsNil(orgid, stime, etime)
47 46
 	var tmp []*models.TmpTTT
48 47
 	if is_medicine == 0 {
49 48
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
50
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
49
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
51 50
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
52 51
 			"union "+
53 52
 			"select distinct patient_id from xt_doctor_advice where "+
54
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 0 and "+
53
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 0 and "+
55 54
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
56 55
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
57 56
 		if err != nil {
@@ -59,11 +58,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
59 58
 		}
60 59
 	} else {
61 60
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
62
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
61
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
63 62
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
64 63
 			"union "+
65 64
 			"select distinct patient_id from xt_doctor_advice where "+
66
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = 1 and "+
65
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = 1 and "+
67 66
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
68 67
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
69 68
 		if err != nil {
@@ -75,7 +74,53 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
75 74
 
76 75
 }
77 76
 
78
-//(改)
77
+func GetTodayAdviceCount(stime, etime, orgid, is_medicine int64) (num int, err error) {
78
+
79
+	//orgid = 9675
80
+	InitDrugidIsNil(orgid, stime, etime)
81
+	var tmp []*models.TmpTTT
82
+	if is_medicine == 0 {
83
+		err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=0 group by patient_id",
84
+			stime, etime, orgid).Scan(&tmp).Error
85
+		if err != nil {
86
+			return
87
+		}
88
+	} else {
89
+		err = XTReadDB().Raw("select * from his_doctor_advice_info where status= 1 and advice_date>=? and advice_date<=? and user_org_id=? and is_medicine=1 group by patient_id",
90
+			stime, etime, orgid).Scan(&tmp).Error
91
+		if err != nil {
92
+			return
93
+		}
94
+	}
95
+
96
+	return len(tmp), err
97
+}
98
+
99
+func GetTodayAdviceCountOne(stime int64, etime int64, orgid int64, is_medicine int64) (advice []*models.HisDoctorAdviceInfo, err error) {
100
+
101
+	db := XTReadDB().Model(&advice).Where("status=1 and is_medicine = ?", is_medicine)
102
+	if stime > 0 {
103
+		db = db.Where("advice_date>=?", stime)
104
+	}
105
+	if etime > 0 {
106
+		db = db.Where("advice_date<=?", stime)
107
+	}
108
+	if orgid > 0 {
109
+		db = db.Where("user_org_id = ?", orgid)
110
+	}
111
+
112
+	err = db.Group("patient_id").Find(&advice).Error
113
+	return advice, err
114
+}
115
+
116
+func GetPatientByAdviceId(patient_id int64) (models.TmpPatientOne, error) {
117
+
118
+	patient := models.TmpPatientOne{}
119
+	err = XTReadDB().Where("id = ?", patient_id).Find(&patient).Error
120
+	return patient, err
121
+}
122
+
123
+// (改)
79 124
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
80 125
 	InitDrugidIsNil(orgid, stime, etime)
81 126
 	//病人
@@ -85,22 +130,22 @@ func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list
85 130
 		if keyword != "" {
86 131
 			keyword = "%" + keyword + "%"
87 132
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
88
-				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
133
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
89 134
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
90 135
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
91 136
 				"union "+
92 137
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
93
-				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
138
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
94 139
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
95 140
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
96 141
 				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
97 142
 		} else {
98 143
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
99
-				"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
144
+				"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
100 145
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
101 146
 				"union "+
102 147
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
103
-				"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and is_medicine = ? and "+
148
+				"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and is_medicine = ? and "+
104 149
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
105 150
 				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
106 151
 		}
@@ -150,7 +195,7 @@ func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list
150 195
 
151 196
 }
152 197
 
153
-//查询患者(改)
198
+// 查询患者(改)
154 199
 func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
155 200
 
156 201
 	for i := 0; i < len(tmp); i++ {
@@ -167,19 +212,19 @@ func GetManyUsers(tmp []int64) (list []*models.TmpPatient, err error) {
167 212
 	return
168 213
 }
169 214
 
170
-//查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
215
+// 查询患者当天时间段中的药,is_medicine:0未发,1已发(改)
171 216
 func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (pp []*models.PharmacyContent, err error) {
172 217
 	InitDrugidIsNil(orgid, stime, etime)
173 218
 	var tmp []*models.HisDoctorAdviceInfoL
174 219
 	if is_medicine == 0 {
175 220
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
176
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
221
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
177 222
 		if err != nil {
178 223
 			return pp, err
179 224
 		}
180 225
 	} else {
181 226
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
182
-			"status = 1 and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
227
+			"status = 1 and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp).Error
183 228
 		if err != nil {
184 229
 			return pp, err
185 230
 		}
@@ -202,13 +247,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
202 247
 	var tmp_advice []*models.XtDoctorAdviceL
203 248
 	if is_medicine == 0 {
204 249
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
205
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
250
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
206 251
 		if err != nil {
207 252
 			return pp, err
208 253
 		}
209 254
 	} else {
210 255
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
211
-			"status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
256
+			"status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and user_org_id = ? and patient_id = ? and is_medicine = ? and drug_id in (select id from xt_base_drug where org_id = ? and status = 1)", stime, etime, orgid, patient_id, is_medicine, orgid).Find(&tmp_advice).Error
212 257
 		if err != nil {
213 258
 			return pp, err
214 259
 		}
@@ -230,14 +275,14 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
230 275
 	return
231 276
 }
232 277
 
233
-//获取创建者姓名(改)
278
+// 获取创建者姓名(改)
234 279
 func GetAdminUserName(doctor, orgid int64) string {
235 280
 	var tmp models.VmUserAdminRole
236 281
 	XTReadDB().Model(&models.VmUserAdminRole{}).Where("admin_user_id = ? and org_id = ? and status = 1", doctor, orgid).Find(&tmp)
237 282
 	return tmp.UserName
238 283
 }
239 284
 
240
-//查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
285
+// 查询该机构的药房配置,true: 通过药房发药,false:不通过药房发药。如果没有该机构的信息则生成一条数据
241 286
 func GetOrgIdPharmacyConfig(orgid int64) bool {
242 287
 	var total int
243 288
 	var tmp_pharmacy models.PharmacyConfig
@@ -263,7 +308,7 @@ func GetOrgIdPharmacyConfig(orgid int64) bool {
263 308
 	}
264 309
 }
265 310
 
266
-//修改该机构的药房配置
311
+// 修改该机构的药房配置
267 312
 func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
268 313
 	if isopen == 1 || isopen == 2 {
269 314
 		err = XTWriteDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{
@@ -276,21 +321,21 @@ func ModifyPharmacyConfig(orgid, isopen int64) (err error) {
276 321
 	return
277 322
 }
278 323
 
279
-//查询该药品是否通过药房发药.0否;1是
324
+// 查询该药品是否通过药房发药.0否;1是
280 325
 func DrugAllocation(drug_id int64) (is_pharmacy int64, err error) {
281 326
 	tmp := models.BaseDrugLib{}
282 327
 	err = XTReadDB().Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).Find(&tmp).Error
283 328
 	return tmp.IsPharmacy, err
284 329
 }
285 330
 
286
-//根据id查询该药是否发药
331
+// 根据id查询该药是否发药
287 332
 func MedicineState(id int64) (is_medicine models.HisDoctorAdviceInfoL, err error) {
288 333
 	tmp := models.HisDoctorAdviceInfoL{}
289 334
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("id = ?", id).Find(&tmp).Error
290 335
 	return tmp, err
291 336
 }
292 337
 
293
-//发药明细列表(
338
+// 发药明细列表(
294 339
 func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword string) (dislist []*models.DispensingList, total int64, err error) {
295 340
 	var fenye []*models.Pharmary //分页用的
296 341
 	offset := (page - 1) * limit
@@ -329,7 +374,7 @@ func DispensingDetailsList(stime, etime, orgid, page, limit int64, keyword strin
329 374
 	return
330 375
 }
331 376
 
332
-//处方详情//////////////////////
377
+// 处方详情//////////////////////
333 378
 func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.PrescripDetails, err error) {
334 379
 	var tmp []*models.HisDoctorAdviceInfoL
335 380
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
@@ -371,7 +416,7 @@ func PrescriptionDetails(patient_id, record_date, orgid int64) (pre []*models.Pr
371 416
 	return
372 417
 }
373 418
 
374
-//查询病人的his id
419
+// 查询病人的his id
375 420
 func GetHisID(prescription_id, orgid int64) (id int64) {
376 421
 	var tmp models.HisPrintPrescription
377 422
 	XTReadDB().Model(&models.HisPrintPrescription{}).Where("id = ?", prescription_id).Find(&tmp)
@@ -380,7 +425,7 @@ func GetHisID(prescription_id, orgid int64) (id int64) {
380 425
 	return fin.ID
381 426
 }
382 427
 
383
-//根据药品id获取药品信息
428
+// 根据药品id获取药品信息
384 429
 func GetDrugNameTX(id int64, tx *gorm.DB) (tmp models.SpBaseDrug, err error) {
385 430
 	err = tx.Model(&models.SpBaseDrug{}).Where("id = ? and status = 1", id).Find(&tmp).Error
386 431
 	return
@@ -392,7 +437,7 @@ func GetXtManufacturer(id int64, tx *gorm.DB) (name string, err error) {
392 437
 	return
393 438
 }
394 439
 
395
-//查询药品(使用keyword)
440
+// 查询药品(使用keyword)
396 441
 func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDrug, error) {
397 442
 	var tmp []*models.PharmacyBaseDrug
398 443
 	tt := make(map[int64]models.PharmacyBaseDrug)
@@ -403,7 +448,7 @@ func GetManyDrugs(orgid int64, keyword string) (map[int64]models.PharmacyBaseDru
403 448
 	return tt, err
404 449
 }
405 450
 
406
-//查询(
451
+// 查询(
407 452
 func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (finlly []*models.ListOfDrugs, err error) {
408 453
 	InitDrugidIsNil(orgid, stime, etime)
409 454
 	var tmp []*models.TmpLLL
@@ -474,7 +519,7 @@ func GetTodayMedicine(stime, etime, orgid, is_medicine int64, keyword string) (f
474 519
 	return
475 520
 }
476 521
 
477
-//根据药品id获取药品规格(
522
+// 根据药品id获取药品规格(
478 523
 func FindDrugSpecifications(id int64) (name, specifications string) {
479 524
 	var tmp models.PharmacyBaseDrug
480 525
 	XTReadDB().Model(&models.PharmacyBaseDrug{}).Where("id = ?", id).Find(&tmp)
@@ -483,7 +528,7 @@ func FindDrugSpecifications(id int64) (name, specifications string) {
483 528
 	return
484 529
 }
485 530
 
486
-//根据药品id获取当前药品出库仓库的库存数量
531
+// 根据药品id获取当前药品出库仓库的库存数量
487 532
 func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
488 533
 	//获取药品拆零数量
489 534
 	var phar models.PharmacyBaseDrug
@@ -516,7 +561,7 @@ func GetInventoryQuantity(orgid, drugid int64) (number string, err error) {
516 561
 	return
517 562
 }
518 563
 
519
-//获取该药品的病人信息(
564
+// 获取该药品的病人信息(
520 565
 func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*models.PatientInformation, err error) { ///////////////
521 566
 	InitDrugidIsNil(orgid, stime, etime)
522 567
 	var tmp []*models.HisDoctorAdviceInfoL
@@ -566,7 +611,7 @@ func FindMedicationList(orgid, drug_id, stime, etime, is_medicine int64) (pp []*
566 611
 	return
567 612
 }
568 613
 
569
-//患者发药按钮点击(
614
+// 患者发药按钮点击(
570 615
 func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err error) {
571 616
 	//开事务
572 617
 	tx := XTWriteDB().Begin()
@@ -581,7 +626,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
581 626
 	time_now := time.Now().Unix()
582 627
 	var hids []*models.TmpID
583 628
 	var xids []*models.TmpID
584
-	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and created_time >= ? and created_time <= ? "+
629
+	err = tx.Raw("select id from his_doctor_advice_info where status = 1 and advice_date >= ? and advice_date <= ? "+
585 630
 		"and user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ", stime, etime, orgid, patient_id, orgid).Scan(&hids).Error
586 631
 	if err != nil {
587 632
 		return
@@ -601,7 +646,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
601 646
 			if PettyCash(v.DrugId) {
602 647
 				continue
603 648
 			}
604
-			//判断药品库存是否充足
649
+			////判断药品库存是否充足
605 650
 			kou := FenDrugInventory(v, orgid)
606 651
 			if !kou {
607 652
 				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
@@ -630,48 +675,52 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
630 675
 		return err1
631 676
 	}
632 677
 
633
-	err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and created_time >= ? and created_time <= ? and "+
634
-		"user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
635
-	if err != nil {
636
-		return
637
-	}
638
-	xid := make([]int64, 0)
639
-	for _, v := range xids {
640
-		xid = append(xid, v.Id)
641
-	}
642
-	var advice []*models.HisDoctorAdviceInfo
643
-	err = tx.Raw("select * from xt_doctor_advice where id in (?) and status = 1", xid).Scan(&advice).Error
644
-	if err != nil {
645
-		return
646
-	}
647
-	for _, v := range advice {
648
-		tmp_bool := IsPharmacyConfig(orgid)
649
-		if tmp_bool {
650
-			if PettyCash(v.DrugId) {
651
-				continue
652
-			}
653
-			kou := FenDrugInventory(v, orgid)
654
-			if !kou {
655
-				err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
656
-				return
657
-			}
658
-			//扣减库存
659
-			err = FenStock(orgid, creater, v)
660
-			if err != nil {
661
-				err = fmt.Errorf("!:%v", err)
662
-				return
678
+	//针对大丰响水
679
+	if orgid != 10217 && orgid != 10188 && orgid != 9671 && orgid != 10164 {
680
+		err = tx.Raw("select id from xt_doctor_advice where status = 1 and (advice_type = 2 or advice_type = 3) and advice_date >= ? and advice_date <= ? and "+
681
+			"user_org_id = ? and patient_id = ? and is_medicine = 0 and drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1)", stime, etime, orgid, patient_id, orgid).Scan(&xids).Error
682
+		if err != nil {
683
+			return
684
+		}
685
+		xid := make([]int64, 0)
686
+		for _, v := range xids {
687
+			xid = append(xid, v.Id)
688
+		}
689
+		var advice []*models.HisDoctorAdviceInfo
690
+		err = tx.Raw("select * from xt_doctor_advice where id in (?) and status = 1", xid).Scan(&advice).Error
691
+		if err != nil {
692
+			return
693
+		}
694
+
695
+		for _, v := range advice {
696
+			tmp_bool := IsPharmacyConfig(orgid)
697
+			if tmp_bool {
698
+				if PettyCash(v.DrugId) {
699
+					continue
700
+				}
701
+				kou := FenDrugInventory(v, orgid)
702
+				if !kou {
703
+					err = fmt.Errorf(FindDrugsName(v.DrugId) + "库存不足")
704
+					return
705
+				}
706
+				//扣减库存
707
+				err = FenStock(orgid, creater, v)
708
+				if err != nil {
709
+					err = fmt.Errorf("!:%v", err)
710
+					return
711
+				}
663 712
 			}
664 713
 		}
665
-	}
666
-	//修改状态
667
-	errs1 := XTWriteDB().Model(&models.XtDoctorAdviceL{}).Where("id in (?)", xid).Updates(map[string]interface{}{
668
-		"is_medicine":     1,
669
-		"people":          0,
670
-		"dispensing_time": time_now,
671
-		"updated_time":    time.Now().Unix(),
672
-	}).Error
673
-	if errs1 != nil {
674
-		return errs1
714
+		//修改状态
715
+		errs1 := XTWriteDB().Model(&models.XtDoctorAdviceL{}).Where("id in (?)", xid).Updates(map[string]interface{}{
716
+			"is_medicine":     1,
717
+			"people":          0,
718
+			"dispensing_time": time_now,
719
+			"updated_time":    time.Now().Unix(),
720
+		}).Error
721
+		if errs1 != nil {
722
+			return errs1
723
+		}
675 724
 	}
676 725
 
677 726
 	//生成明细记录
@@ -688,7 +737,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
688 737
 	return
689 738
 }
690 739
 
691
-//患者退药按钮点击
740
+// 患者退药按钮点击
692 741
 func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error) {
693 742
 	//开事务
694 743
 	tx := XTWriteDB().Begin()
@@ -829,7 +878,7 @@ func DrugWithdrawal(orgid, patient_id, stime, etime, creater int64) (err error)
829 878
 	return
830 879
 }
831 880
 
832
-//获取患者名称
881
+// 获取患者名称
833 882
 func FindUserName(patient_id int64) (name string) {
834 883
 	var tmp models.GetHisName
835 884
 	XTReadDB().Model(&models.GetHisName{}).Where("id = ?", patient_id).Find(&tmp)
@@ -837,7 +886,7 @@ func FindUserName(patient_id int64) (name string) {
837 886
 	return
838 887
 }
839 888
 
840
-//获取药品名称
889
+// 获取药品名称
841 890
 func FindDrugsName(drug_id int64) (name string) {
842 891
 	var tmp models.Drug
843 892
 	XTReadDB().Model(&models.Drug{}).Where("id = ?", drug_id).Find(&tmp)
@@ -845,7 +894,7 @@ func FindDrugsName(drug_id int64) (name string) {
845 894
 	return
846 895
 }
847 896
 
848
-//药品发药按钮点击(
897
+// 药品发药按钮点击(
849 898
 func MedicineDeparture(ids string, creater, orgid int64) (err error) {
850 899
 	//开事务
851 900
 	tx := XTWriteDB().Begin()
@@ -995,14 +1044,14 @@ func MedicineDeparture(ids string, creater, orgid int64) (err error) {
995 1044
 	return
996 1045
 }
997 1046
 
998
-//获取领药人姓名(
1047
+// 获取领药人姓名(
999 1048
 func GetUserAdminName(id, orgID int64) string {
1000 1049
 	var tmp models.XTSgjUserAdminRole
1001 1050
 	XTReadDB().Model(&models.XTSgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgID).Find(&tmp)
1002 1051
 	return tmp.UserName
1003 1052
 }
1004 1053
 
1005
-//根据id查询是否已发药,true已发药,false未发药gai
1054
+// 根据id查询是否已发药,true已发药,false未发药gai
1006 1055
 func GiveTheMedicine(id int64) bool {
1007 1056
 	var xue models.PharmacyDoctorAdvice
1008 1057
 	XTReadDB().Model(&models.PharmacyDoctorAdvice{}).Where("id = ?", id).Find(&xue)
@@ -1012,7 +1061,7 @@ func GiveTheMedicine(id int64) bool {
1012 1061
 	return false
1013 1062
 }
1014 1063
 
1015
-//查询改组中的药品是否包含已发药的,true已发药,false未发药
1064
+// 查询改组中的药品是否包含已发药的,true已发药,false未发药
1016 1065
 func GiveGroupMedicine(orgid, groupNo int64) bool {
1017 1066
 	var total int
1018 1067
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("user_org_id = ? and groupno = ? and status = 1 and is_medicine = 1", orgid, groupNo).Count(&total)
@@ -1022,7 +1071,7 @@ func GiveGroupMedicine(orgid, groupNo int64) bool {
1022 1071
 	return false
1023 1072
 }
1024 1073
 
1025
-//查询处方中是否包含已发药的
1074
+// 查询处方中是否包含已发药的
1026 1075
 func GiveChuMedicine(id int64) bool {
1027 1076
 	var total int
1028 1077
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", id).Count(&total)
@@ -1032,7 +1081,7 @@ func GiveChuMedicine(id int64) bool {
1032 1081
 	return false
1033 1082
 }
1034 1083
 
1035
-//根据处方id查找该处方中是否存在已发药的药品
1084
+// 根据处方id查找该处方中是否存在已发药的药品
1036 1085
 func IsChuIssuedDrugs(prescription_id int64) bool {
1037 1086
 	var total int
1038 1087
 	XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where("prescription_id = ? and status = 1 and is_medicine = 1", prescription_id).Count(&total)
@@ -1042,8 +1091,8 @@ func IsChuIssuedDrugs(prescription_id int64) bool {
1042 1091
 	return false
1043 1092
 }
1044 1093
 
1045
-//判断该药品是否通过药房管理出库,true是,false否
1046
-//id 药品id,org_id 机构id
1094
+// 判断该药品是否通过药房管理出库,true是,false否
1095
+// id 药品id,org_id 机构id
1047 1096
 func IsPharmacyDelivery(id, org_id int64) bool {
1048 1097
 	//判断药品是否通过药房管理
1049 1098
 	var total01 int
@@ -1057,7 +1106,7 @@ func IsPharmacyDelivery(id, org_id int64) bool {
1057 1106
 	return false
1058 1107
 }
1059 1108
 
1060
-//判断机构是否通过药房管理出库
1109
+// 判断机构是否通过药房管理出库
1061 1110
 func IsPharmacyConfig(orgid int64) (bo bool) {
1062 1111
 	var total int
1063 1112
 	XTReadDB().Model(&models.PharmacyConfig{}).Where("user_org_id = ? and is_open = 1 and status = 1", orgid).Count(&total)
@@ -1067,7 +1116,7 @@ func IsPharmacyConfig(orgid int64) (bo bool) {
1067 1116
 	return false
1068 1117
 }
1069 1118
 
1070
-//根据患者id和发药时间,获取医生的id和姓名
1119
+// 根据患者id和发药时间,获取医生的id和姓名
1071 1120
 func GetDoctorIds(id, recordtime, orgid int64) (doctor_id int64, doctor_name string, err error) {
1072 1121
 	var tmp []*models.TmpAdviceDoctor
1073 1122
 	//var tmp []int64
@@ -1091,7 +1140,7 @@ func MapToJson(param map[string]interface{}) string {
1091 1140
 	return dataString
1092 1141
 }
1093 1142
 
1094
-//封装扣减库存
1143
+// 封装扣减库存
1095 1144
 func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1096 1145
 
1097 1146
 	err = HisDrugsDelivery(orgid, creater, v)
@@ -1118,7 +1167,7 @@ func FenStock(orgid, creater int64, v *models.HisDoctorAdviceInfo) (err error) {
1118 1167
 	return
1119 1168
 }
1120 1169
 
1121
-//封装查询药品库存是否足够
1170
+// 封装查询药品库存是否足够
1122 1171
 func FenDrugInventory(item *models.HisDoctorAdviceInfo, orgid int64) bool {
1123 1172
 	var total int64
1124 1173
 	var prescribing_number_total int64
@@ -1233,7 +1282,7 @@ func GetAdviceId2(id, orgid, execution_staff int64, thetime time.Time) (bo bool,
1233 1282
 	return false, err
1234 1283
 }
1235 1284
 
1236
-//判断药品是否零用
1285
+// 判断药品是否零用
1237 1286
 func PettyCash(id int64) bool {
1238 1287
 	drug := models.XtBaseDrug{}
1239 1288
 	XTReadDB().Model(&drug).Where("id = ? and status = 1", id).Find(&drug)
@@ -1243,16 +1292,16 @@ func PettyCash(id int64) bool {
1243 1292
 	return false
1244 1293
 }
1245 1294
 
1246
-//初始化
1295
+// 初始化
1247 1296
 func InitDrugidIsNil(orgid, stime, etime int64) {
1248 1297
 	var advice []*models.DoctorAdvice
1249 1298
 	XTReadDB().Model(&models.DoctorAdvice{}).Where("drug_id = 0 and user_org_id = ? and status = 1 and created_time >= ? and created_time <= ?", orgid, stime, etime).Find(&advice)
1250 1299
 	for _, v := range advice {
1251
-		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ?) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1300
+		XTWriteDB().Exec("update xt_doctor_advice set drug_id = (select id from xt_base_drug where drug_name = ? and org_id = ? and status = 1 limit 1) where id = ?", v.AdviceName, v.UserOrgId, v.ID)
1252 1301
 	}
1253 1302
 }
1254 1303
 
1255
-//改变处方状态(发药
1304
+// 改变处方状态(发药
1256 1305
 func ChangeHisPrescription(tmp []int64) (err error) {
1257 1306
 	var advice_info []*models.HisDoctorAdviceInfo
1258 1307
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
@@ -1279,7 +1328,7 @@ func ChangeHisPrescription(tmp []int64) (err error) {
1279 1328
 	return
1280 1329
 }
1281 1330
 
1282
-//改变处方状态(退药
1331
+// 改变处方状态(退药
1283 1332
 func ChangeHisPrescriptionT(tmp []int64) (err error) {
1284 1333
 	var advice_info []*models.HisDoctorAdviceInfo
1285 1334
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", tmp).Find(&advice_info).Error
@@ -1311,7 +1360,7 @@ func ChangeHisPrescriptionT(tmp []int64) (err error) {
1311 1360
 	return
1312 1361
 }
1313 1362
 
1314
-//改变处方状态
1363
+// 改变处方状态
1315 1364
 func ChangeHisPrescriptionid(id string) (err error) {
1316 1365
 	var advice models.HisDoctorAdviceInfo
1317 1366
 	err = XTReadDB().Model(&models.HisDoctorAdviceInfo{}).Where("id = ? and status = 1", id).Find(&advice).Error
@@ -1331,7 +1380,7 @@ func ChangeHisPrescriptionid(id string) (err error) {
1331 1380
 	return
1332 1381
 }
1333 1382
 
1334
-//获取药品规格
1383
+// 获取药品规格
1335 1384
 func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrugs, err error) {
1336 1385
 	var g errgroup.Group
1337 1386
 	var lib []*models.BaseDrugLib
@@ -1368,7 +1417,7 @@ func ReplacementDrugs(orgid int64, special bool) (list []*models.ReplacementDrug
1368 1417
 	return
1369 1418
 }
1370 1419
 
1371
-//获取药品规格,不考虑特殊病
1420
+// 获取药品规格,不考虑特殊病
1372 1421
 func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error) {
1373 1422
 	var lib []*models.BaseDrugLib
1374 1423
 	err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1 and drug_status not like '%停用%' ", orgid).Find(&lib).Error
@@ -1390,14 +1439,14 @@ func ReplacementDrugsT(orgid int64) (list []*models.ReplacementDrugs, err error)
1390 1439
 	return
1391 1440
 }
1392 1441
 
1393
-//根据药品id获取药品名字
1442
+// 根据药品id获取药品名字
1394 1443
 func IdToDrugName(id int64) (name string) {
1395 1444
 	var lib models.BaseDrugLib
1396 1445
 	readDb.Model(&models.BaseDrugLib{}).Where("id = ?", id).Find(&lib)
1397 1446
 	return lib.DrugName
1398 1447
 }
1399 1448
 
1400
-//获取项目和耗材和套餐
1449
+// 获取项目和耗材和套餐
1401 1450
 func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1402 1451
 
1403 1452
 	var project []*models.XtHisProject
@@ -1439,7 +1488,7 @@ func ProjectConsumables3(orgid int64) (list []*models.DropDownList, err error) {
1439 1488
 	return
1440 1489
 }
1441 1490
 
1442
-//获取项目和耗材
1491
+// 获取项目和耗材
1443 1492
 func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList, err error) {
1444 1493
 
1445 1494
 	var project []*models.XtHisProject
@@ -1477,7 +1526,7 @@ func ProjectConsumables2(orgid int64, special bool) (list []*models.DropDownList
1477 1526
 	return
1478 1527
 }
1479 1528
 
1480
-//获取项目和耗材不考虑特殊病
1529
+// 获取项目和耗材不考虑特殊病
1481 1530
 func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error) {
1482 1531
 
1483 1532
 	var project []*models.XtHisProject
@@ -1507,7 +1556,7 @@ func ProjectConsumables2T(orgid int64) (list []*models.DropDownList, err error)
1507 1556
 	return
1508 1557
 }
1509 1558
 
1510
-//查询药品
1559
+// 查询药品
1511 1560
 func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1512 1561
 	var total int
1513 1562
 	XTReadDB().Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1 and "+
@@ -1519,7 +1568,7 @@ func FindPatientDrug(orgid, patient_id, drugid, mode int64) bool {
1519 1568
 	return false
1520 1569
 }
1521 1570
 
1522
-//查询项目
1571
+// 查询项目
1523 1572
 func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1524 1573
 	var total int
1525 1574
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 2 and "+
@@ -1531,7 +1580,7 @@ func FindPatientXiang(orgid, patient_id, drugid, mode int64) bool {
1531 1580
 	return false
1532 1581
 }
1533 1582
 
1534
-//查询耗材
1583
+// 查询耗材
1535 1584
 func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1536 1585
 	var total int
1537 1586
 	XTReadDB().Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and status = 1 and type = 3 and "+
@@ -1543,7 +1592,7 @@ func FindPatientXiang2(orgid, patient_id, drugid, mode int64) bool {
1543 1592
 	return false
1544 1593
 }
1545 1594
 
1546
-//types处方类型,1.药品 2.项目,model透析模式
1595
+// types处方类型,1.药品 2.项目,model透析模式
1547 1596
 func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1548 1597
 	type tmpid struct {
1549 1598
 		Id int64
@@ -1557,7 +1606,7 @@ func GetHisInfoTempalteId(model, orgid, types int64) (tp []int64) {
1557 1606
 	return
1558 1607
 }
1559 1608
 
1560
-//替换药品处方模板
1609
+// 替换药品处方模板
1561 1610
 func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionAdviceTemplate, tx *gorm.DB) (err error) {
1562 1611
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1563 1612
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
@@ -1577,7 +1626,7 @@ func ReplaceDrugPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int6
1577 1626
 	return err
1578 1627
 }
1579 1628
 
1580
-//替换项目模板
1629
+// 替换项目模板
1581 1630
 func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, s models.HisPrescriptionProjectTemplate, tx *gorm.DB) (err error) {
1582 1631
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1583 1632
 		"status = 1 and prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
@@ -1599,7 +1648,7 @@ func ReplaceProjectPrescriptionTemplate(orgid, patient_id, drugid int64, ids []i
1599 1648
 	return err
1600 1649
 }
1601 1650
 
1602
-//删除项目模板
1651
+// 删除项目模板
1603 1652
 func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1604 1653
 	err = tx.Model(&models.HisPrescriptionProjectTemplate{}).Where("user_org_id = ? and patient_id = ? and project_id = ? and "+
1605 1654
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
@@ -1609,7 +1658,7 @@ func DeleteProjectTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gor
1609 1658
 	return err
1610 1659
 }
1611 1660
 
1612
-//删除处方模板
1661
+// 删除处方模板
1613 1662
 func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx *gorm.DB) (err error) {
1614 1663
 	err = tx.Model(&models.HisPrescriptionAdviceTemplate{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and "+
1615 1664
 		"prescription_id in (?)", orgid, patient_id, drugid, ids).Updates(map[string]interface{}{
@@ -1619,7 +1668,7 @@ func DeletePrescriptionTemplate(orgid, patient_id, drugid int64, ids []int64, tx
1619 1668
 	return err
1620 1669
 }
1621 1670
 
1622
-//根据透析模式和患者id获取该患者的处方内容
1671
+// 根据透析模式和患者id获取该患者的处方内容
1623 1672
 func PTemplateInformation(orgid, mode_id, patient_id int64) (tmp interface{}, err error) {
1624 1673
 	//获取处方id
1625 1674
 	var tt []*models.HisPrescriptionTemplate
@@ -1695,7 +1744,7 @@ func DeleteOne(types, id int64) (err error) {
1695 1744
 
1696 1745
 }
1697 1746
 
1698
-//收尾工作
1747
+// 收尾工作
1699 1748
 func Scavenger(orgid int64) (err error) {
1700 1749
 	//开事务
1701 1750
 	tx := XTWriteDB().Begin()
@@ -1764,7 +1813,7 @@ func Scavenger(orgid int64) (err error) {
1764 1813
 	return
1765 1814
 }
1766 1815
 
1767
-//分区和收费(患者发药
1816
+// 分区和收费(患者发药
1768 1817
 func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*models.TmpPatient) (tmp []*models.TmpPatient, err error) {
1769 1818
 	//获取排班
1770 1819
 	var sch []*models.XtScheduleTwo
@@ -1794,7 +1843,7 @@ func PartitionAndLayout(stime, etime, orgid, shift, partition int64, flist []*mo
1794 1843
 	return
1795 1844
 }
1796 1845
 
1797
-//分区和收费(药品发药
1846
+// 分区和收费(药品发药
1798 1847
 func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, partition int64, flist []*models.PatientInformation) (tmp []*models.PatientInformation, err error) {
1799 1848
 	//获取排班
1800 1849
 	var sch []*models.XtScheduleTwo
@@ -1833,7 +1882,7 @@ func PartitionAndLayoutDrug(deliveryway string, stime, etime, orgid, shift, part
1833 1882
 	return
1834 1883
 }
1835 1884
 
1836
-//给药途径
1885
+// 给药途径
1837 1886
 func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs) (tmp []*models.ListOfDrugs, err error) {
1838 1887
 	//查询药品
1839 1888
 	var pp []*models.PharmacyBaseDrug
@@ -1860,7 +1909,7 @@ func Administration(deliveryway string, orgid int64, flist []*models.ListOfDrugs
1860 1909
 	return
1861 1910
 }
1862 1911
 
1863
-//计算总量
1912
+// 计算总量
1864 1913
 func CalculateTheTotalAmount(tmp []*models.PatientInformation, drug_id int64) (total string, err error) {
1865 1914
 	//获取药品信息
1866 1915
 	var t models.SpBaseDrug
@@ -1912,3 +1961,24 @@ func GetAllValidDeviceZones02(orgID int64) ([]*models.DeviceZone, error) {
1912 1961
 	}
1913 1962
 	return zones, nil
1914 1963
 }
1964
+
1965
+func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
1966
+
1967
+	db := XTReadDB().Model(&advice).Where("status= 1")
1968
+
1969
+	if orgid > 0 {
1970
+		db = db.Where("user_org_id = ?", orgid)
1971
+	}
1972
+	if patient_id > 0 {
1973
+		db = db.Where("patient_id = ?", patient_id)
1974
+	}
1975
+	if stime > 0 {
1976
+		db = db.Where("advice_date >=?", stime)
1977
+	}
1978
+	if etime > 0 {
1979
+		db = db.Where("advice_date<=?", etime)
1980
+	}
1981
+	err = db.Find(&advice).Error
1982
+
1983
+	return advice, err
1984
+}

+ 1 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_models.go View File

@@ -104,6 +104,7 @@ type DialysisOrderVM struct {
104 104
 	WashpipeNurse  int64           `gorm:"column:washpipe_nurse" json:"washpipe_nurse" form:"washpipe_nurse"`
105 105
 	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
106 106
 	QualityNurseId int64           `gorm:"column:quality_nurse_id" json:"quality_nurse_id" form:"quality_nurse_id"`
107
+	Url            string          `gorm:"column:url" json:"url" form:"url"`
107 108
 }
108 109
 
109 110
 func (DialysisOrderVM) TableName() string {

+ 8 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go View File

@@ -479,3 +479,11 @@ func GetBatchSummerVM(orgid int64, patient_id int64, assessment_date int64) (*Su
479 479
 	err := p_service.XTReadDB().Where("user_org_id = ? and patient_id = ? and assessment_date =? and status = 1", orgid, patient_id, assessment_date).Find(&SummerVM).Error
480 480
 	return &SummerVM, err
481 481
 }
482
+
483
+func GetAdminUserEsTwo(orgid int64) (admin []*models.UserAdminRoles, err error) {
484
+	db := p_service.UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
485
+	table := p_service.UserReadDB().Table("sgj_user_admin_electronic_signature as s")
486
+	fmt.Println("table", table)
487
+	err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error
488
+	return admin, err
489
+}

+ 8 - 0
service/stock_service.go View File

@@ -8508,3 +8508,11 @@ func GetGoodOutOpenConfigOne(user_org_id int64) (models.XtGoodOutConfig, error)
8508 8508
 	err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&config).Error
8509 8509
 	return config, err
8510 8510
 }
8511
+
8512
+func UpdateDeleteAutoGood(good_id int64, record_date int64, patient_id int64) error {
8513
+
8514
+	err := XTWriteDB().Model(&models.AutomaticReduceDetail{}).Where("good_id = ? and record_time = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
8515
+
8516
+	err = XTWriteDB().Model(&models.DialysisBeforePrepare{}).Where("good_id = ? and record_date = ? and patient_id = ?", good_id, record_date, patient_id).Updates(map[string]interface{}{"status": 1}).Error
8517
+	return err
8518
+}

+ 123 - 5
service/warhouse_service.go View File

@@ -1208,6 +1208,7 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1208 1208
 
1209 1209
 	//查询该患者当天已经出库的耗材信息
1210 1210
 	goods_yc, _ := FindConsumablesByDateTwo(orgID, patient_id, record_time)
1211
+
1211 1212
 	// 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
1212 1213
 	for i := len(goods_yc) - 1; i >= 0; i-- {
1213 1214
 		goods_yc_temp := goods_yc[i]
@@ -1244,7 +1245,8 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1244 1245
 
1245 1246
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
1246 1247
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
1247
-
1248
+	fmt.Println("len233333333333333w", len(goods_yc))
1249
+	fmt.Println("需要出库的数据", len(goods))
1248 1250
 	if len(goods) > 0 {
1249 1251
 		out, err := FindStockOutByIsSys(orgID, 1, record_time)
1250 1252
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
@@ -1293,15 +1295,15 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1293 1295
 
1294 1296
 			var cha_count int64
1295 1297
 			var cha_count_two int64
1298
+			//查询已经出库的数量
1296 1299
 			flowGood, _ := GetStockFlowIsBatchNumberTwo(patient_id, record_time, item.GoodId)
1297 1300
 			var out_count int64
1298 1301
 			for _, item := range flowGood {
1299 1302
 				out_count += item.Count
1300 1303
 			}
1304
+			//已经出库的数量 减掉目前需要出库的数据
1301 1305
 			cha_count = item.Count - out_count
1302
-			//fmt.Println("item.Count", item.Count)
1303
-			//fmt.Println("item.Count", out_count)
1304
-			//fmt.Println("cha_count2323223232323223", cha_count)
1306
+
1305 1307
 			cha_count_two = out_count - item.Count
1306 1308
 
1307 1309
 			prepare := models.DialysisBeforePrepare{
@@ -1313,17 +1315,22 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1313 1315
 			}
1314 1316
 
1315 1317
 			ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
1318
+
1316 1319
 			//数量增加
1317 1320
 			if cha_count > 0 {
1318 1321
 				//出库数量累加
1319 1322
 				ModifyGoodSumCount(houseConfig.StorehouseOutInfo, cha_count, orgID, item.GoodId)
1320 1323
 			}
1321
-			//数量减少
1324
+
1325
+			//已经出库的数据 大于 目前需要出库的数据
1322 1326
 			if cha_count_two > 0 {
1327
+
1323 1328
 				ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, cha_count_two, orgID, item.GoodId)
1324 1329
 				//退库数量增加
1325 1330
 				UpdateSumAddCancelCount(orgID, item.GoodId, houseConfig.StorehouseOutInfo, cha_count_two)
1326 1331
 
1332
+				//生成退库单
1333
+
1327 1334
 			}
1328 1335
 			//更新剩余库存
1329 1336
 			goodListSix, _ := GetSumGoodList(orgID, houseConfig.StorehouseOutInfo, item.GoodId)
@@ -1826,6 +1833,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1826 1833
 		if errThree != nil {
1827 1834
 			return errThree
1828 1835
 		}
1836
+		fmt.Println("errThreee23333333333333333333333", errThree)
1829 1837
 		//查询剩余库存
1830 1838
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)
1831 1839
 		goodList, _ := GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
@@ -1833,6 +1841,7 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1833 1841
 		for _, item := range goodList {
1834 1842
 			sum_count += item.StockCount
1835 1843
 		}
1844
+		fmt.Println("sum_count++++++++++++++++++++++++++++++++=", sum_count)
1836 1845
 		// 判断当前出库的数据和删除出库数量
1837 1846
 		if good_yc.Count <= ware.Count {
1838 1847
 			delete_count = good_yc.Count
@@ -1902,6 +1911,103 @@ func ConsumablesDeliveryDelete(orgID int64, patient_id int64, record_time int64,
1902 1911
 		//退库数量相加
1903 1912
 		UpdateSumAddCancelCount(good_yc.UserOrgId, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
1904 1913
 
1914
+		operation_time := time.Now().Unix()
1915
+		//创建退库单
1916
+		timeStr := time.Now().Format("2006-01-02")
1917
+		timeArr := strings.Split(timeStr, "-")
1918
+		total, _ := FindAllCancelStockTotal(good_yc.UserOrgId)
1919
+		total = total + 1
1920
+		orderNumber := "CKTKD" + strconv.FormatInt(good_yc.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
1921
+
1922
+		cancelStock := models.CancelStock{
1923
+			OrderNumber:  orderNumber,
1924
+			OperaTime:    operation_time,
1925
+			OrgId:        good_yc.UserOrgId,
1926
+			Creater:      warehouseOut.Creater,
1927
+			Ctime:        time.Now().Unix(),
1928
+			Status:       1,
1929
+			ReturnTime:   record_time,
1930
+			Type:         1,
1931
+			StorehouseId: houseConfig.StorehouseOutInfo,
1932
+			IsCheck:      1,
1933
+		}
1934
+		_, msgerrkonde := GetCancelStockDetailByOrderNumberOne(record_time, good_yc.UserOrgId)
1935
+		if msgerrkonde == gorm.ErrRecordNotFound {
1936
+			AddSigleCancelStock(&cancelStock)
1937
+		}
1938
+		cancel, _ := GetLastCancelStockById(good_yc.UserOrgId)
1939
+
1940
+		manufacturer, _ := GetManufactureById(ware.Manufacturer)
1941
+		deaerler, _ := GetDealerById(ware.Dealer)
1942
+
1943
+		cancelStockInfo := models.CancelStockInfo{
1944
+			GoodId:          ware.GoodId,
1945
+			CancelStockId:   cancel.ID,
1946
+			GoodTypeId:      ware.GoodTypeId,
1947
+			Count:           delete_count,
1948
+			Price:           ware.Price,
1949
+			Total:           0,
1950
+			ProductDate:     ware.ProductDate,
1951
+			ExpiryDate:      ware.ExpiryDate,
1952
+			Ctime:           time.Now().Unix(),
1953
+			Status:          1,
1954
+			OrgId:           good_yc.UserOrgId,
1955
+			OrderNumber:     cancel.OrderNumber,
1956
+			Type:            0,
1957
+			Dealer:          deaerler.DealerName,
1958
+			Manufacturer:    manufacturer.ManufacturerName,
1959
+			Number:          ware.Number,
1960
+			RegisterAccount: "",
1961
+			Remark:          "",
1962
+			WarehouseInfoId: ware.WarehouseInfotId,
1963
+			PatientId:       ware.PatientId,
1964
+			RecordDate:      record_time,
1965
+			StorehouseId:    houseConfig.StorehouseOutInfo,
1966
+			IsCheck:         1,
1967
+		}
1968
+
1969
+		CreateCancelStockInfoOne(&cancelStockInfo)
1970
+		cancelInfo, _ := GetLastCancelStockInfoByGoodId(ware.GoodId)
1971
+		goodListOne, _ := GetSumGoodList(good_yc.UserOrgId, houseConfig.StorehouseOutInfo, good_yc.GoodId)
1972
+		var over_count int64
1973
+		for _, it := range goodListOne {
1974
+			over_count += it.StockCount
1975
+		}
1976
+		flow := models.VmStockFlow{
1977
+			WarehousingId:           ware.WarehouseInfotId,
1978
+			GoodId:                  ware.GoodId,
1979
+			Number:                  ware.Number,
1980
+			LicenseNumber:           ware.LicenseNumber,
1981
+			Count:                   ware.Count,
1982
+			UserOrgId:               ware.OrgId,
1983
+			PatientId:               ware.PatientId,
1984
+			SystemTime:              record_time,
1985
+			ConsumableType:          7,
1986
+			IsSys:                   0,
1987
+			WarehousingOrder:        "",
1988
+			WarehouseOutId:          ware.WarehouseOutId,
1989
+			WarehouseOutOrderNumber: ware.WarehouseOutOrderNumber,
1990
+			IsEdit:                  0,
1991
+			CancelStockId:           cancel.ID,
1992
+			CancelOrderNumber:       cancel.OrderNumber,
1993
+			Manufacturer:            manufacturer.ID,
1994
+			Dealer:                  0,
1995
+			Creator:                 warehouseOut.Creater,
1996
+			UpdateCreator:           0,
1997
+			Status:                  1,
1998
+			Ctime:                   time.Now().Unix(),
1999
+			Mtime:                   0,
2000
+			Price:                   ware.Price,
2001
+			WarehousingDetailId:     ware.WarehouseInfotId,
2002
+			WarehouseOutDetailId:    ware.ID,
2003
+			CancelOutDetailId:       cancelInfo.ID,
2004
+			ProductDate:             ware.ProductDate,
2005
+			ExpireDate:              ware.ExpiryDate,
2006
+			StorehouseId:            houseConfig.StorehouseOutInfo,
2007
+			OverCount:               over_count,
2008
+		}
2009
+		CreateStockFlowOne(flow)
2010
+
1905 2011
 		// 增加了对应的库存后,看看还有多少需要退库的
1906 2012
 		good_yc.Count = good_yc.Count - delete_count
1907 2013
 		if good_yc.Count == 0 {
@@ -6044,6 +6150,18 @@ func ModifyReduceGoodSumCount(storehouse_id int64, count int64, user_org_id int6
6044 6150
 	return err
6045 6151
 }
6046 6152
 
6153
+func ModifyReduceGoodSumCountTwenty(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6154
+	ut := XTWriteDB().Begin()
6155
+
6156
+	err = ut.Model(&models.XtGoodStockCount{}).Where("storehouse_id = ? and status = 1 and user_org_id  = ? and good_id =?", storehouse_id, user_org_id, good_id).UpdateColumn("stock_out_count", gorm.Expr("stock_out_count - ?", count)).Error
6157
+	if err != nil {
6158
+		ut.Rollback()
6159
+		return err
6160
+	}
6161
+	ut.Commit()
6162
+	return err
6163
+}
6164
+
6047 6165
 func ModifyAddGoodSumCount(storehouse_id int64, count int64, user_org_id int64, good_id int64) error {
6048 6166
 	ut := XTWriteDB().Begin()
6049 6167