Ver código fonte

11月9日库存管理

XMLWAN 2 anos atrás
pai
commit
6ead79f58c

+ 3 - 1
controllers/dialysis_api_controller.go Ver arquivo

@@ -3910,9 +3910,11 @@ func (c *DialysisApiController) GetInitPrintData() {
3910 3910
 	record_date, _ := c.GetInt64("record_date")
3911 3911
 	orgId := c.GetAdminUserInfo().CurrentOrgId
3912 3912
 	list, err := service.GetInitPrintData(patient_id, record_date, orgId)
3913
+	assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
3913 3914
 	if err == nil {
3914 3915
 		c.ServeSuccessJSON(map[string]interface{}{
3915
-			"list": list,
3916
+			"list":                    list,
3917
+			"assessmentAfterDislysis": assessmentAfterDislysis,
3916 3918
 		})
3917 3919
 		return
3918 3920
 

+ 265 - 280
controllers/his_api_controller.go Ver arquivo

@@ -965,6 +965,8 @@ func (c *HisApiController) CreateHisPrescription() {
965 965
 	adminInfo := c.GetAdminUserInfo()
966 966
 	recordDateTime := theTime.Unix()
967 967
 
968
+	//查询默认出库仓库库存
969
+	storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
968 970
 	role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
969 971
 
970 972
 	if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
@@ -981,69 +983,6 @@ func (c *HisApiController) CreateHisPrescription() {
981 983
 
982 984
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
983 985
 
984
-	//已发药和已收费限制逻辑
985
-	isMidicine := false
986
-	isCharge := false
987
-	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
988
-		prescriptions, _ := dataBody["prescriptions"].([]interface{})
989
-		if len(prescriptions) > 0 {
990
-			for _, item := range prescriptions {
991
-				items := item.(map[string]interface{})
992
-				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
993
-					utils.ErrorLog("id")
994
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
995
-					return
996
-				}
997
-				id := int64(items["id"].(float64))
998
-				if id > 0 {
999
-					new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
1000
-					if err != nil {
1001
-						if new_prescription.OrderStatus == 2 {
1002
-							isCharge = true
1003
-						}
1004
-					}
1005
-				}
1006
-
1007
-				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
1008
-					advices := items["advices"].([]interface{})
1009
-					fmt.Println("~~~~~~~~4")
1010
-
1011
-					if len(advices) > 0 {
1012
-						for _, advice := range advices {
1013
-							fmt.Println("~~~~~~~~3")
1014
-
1015
-							var adviceId int64
1016
-							if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1017
-								adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1018
-							}
1019
-							if adviceId > 0 {
1020
-								his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
1021
-								fmt.Println("~~~~~~~~1")
1022
-								fmt.Println("~~~~~~~~1")
1023
-
1024
-								if err == nil {
1025
-									if his_advice_info.IsMedicine == 1 {
1026
-										fmt.Println("~~~~~~~~2")
1027
-										isMidicine = true
1028
-									}
1029
-								}
1030
-							}
1031
-						}
1032
-					}
1033
-				}
1034
-			}
1035
-		}
1036
-	}
1037
-	if isMidicine == true {
1038
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
1039
-		return
1040
-	}
1041
-	if isCharge == true {
1042
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
1043
-		return
1044
-	}
1045
-	//已发药和已收费限制逻辑
1046
-
1047 986
 	if drugStockConfig.IsOpen == 1 {
1048 987
 		//校验库存总量
1049 988
 		if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
@@ -1081,8 +1020,7 @@ func (c *HisApiController) CreateHisPrescription() {
1081 1020
 									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1082 1021
 									return
1083 1022
 								}
1084
-								//查询默认出库仓库库存
1085
-								storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1023
+
1086 1024
 								//查询药品的所有库存
1087 1025
 								list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1088 1026
 
@@ -1095,14 +1033,14 @@ func (c *HisApiController) CreateHisPrescription() {
1095 1033
 								advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1096 1034
 
1097 1035
 								//查询最新批次库存
1098
-								//info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1099
-								//var batch_number_count int64
1100
-								//batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1101
-								//batch_number_counts := strconv.FormatInt(batch_number_count, 10)
1036
+								info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1037
+								var batch_number_count int64
1038
+								batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1039
+								batch_number_counts := strconv.FormatInt(batch_number_count, 10)
1102 1040
 								//新增处方
1103 1041
 								if advicelist.ID == 0 {
1104 1042
 									all_count, _ := strconv.ParseFloat(totals, 64)
1105
-									//batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1043
+									batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1106 1044
 									if prescribingNumberUnit == drug.MinUnit {
1107 1045
 
1108 1046
 										if drug.IsUse != 1 {
@@ -1111,10 +1049,10 @@ func (c *HisApiController) CreateHisPrescription() {
1111 1049
 												return
1112 1050
 											}
1113 1051
 
1114
-											//if prescribing_number > batch_number_all_count {
1115
-											//	c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1116
-											//	return
1117
-											//}
1052
+											if prescribing_number > batch_number_all_count {
1053
+												c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1054
+												return
1055
+											}
1118 1056
 
1119 1057
 										}
1120 1058
 
@@ -1127,10 +1065,10 @@ func (c *HisApiController) CreateHisPrescription() {
1127 1065
 												return
1128 1066
 											}
1129 1067
 
1130
-											//if num > batch_number_all_count {
1131
-											//	c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1132
-											//	return
1133
-											//}
1068
+											if num > batch_number_all_count {
1069
+												c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1070
+												return
1071
+											}
1134 1072
 										}
1135 1073
 									}
1136 1074
 								}
@@ -1167,9 +1105,8 @@ func (c *HisApiController) CreateHisPrescription() {
1167 1105
 											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1168 1106
 											return
1169 1107
 										}
1170
-										houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1171 1108
 										//查询药品的所有库存
1172
-										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
1109
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1173 1110
 										var total_count int64
1174 1111
 										for _, it := range list {
1175 1112
 											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
@@ -1181,27 +1118,27 @@ func (c *HisApiController) CreateHisPrescription() {
1181 1118
 										//新增处方
1182 1119
 										if advicelist.ID == 0 {
1183 1120
 											//查询最新批次库存
1184
-											//info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1185
-											//var batch_number_count int64
1186
-											//batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1187
-											//batch_number_counts := strconv.FormatInt(batch_number_count, 10)
1121
+											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1122
+											var batch_number_count int64
1123
+											batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1124
+											batch_number_counts := strconv.FormatInt(batch_number_count, 10)
1188 1125
 											all_count, _ := strconv.ParseFloat(totals, 64)
1189 1126
 											if prescribingNumberUnit == drug.MinUnit {
1190
-												//batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1127
+												batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1191 1128
 												if drug.IsUse != 1 {
1192 1129
 													if prescribing_number > all_count {
1193 1130
 														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1194 1131
 														return
1195 1132
 													}
1196
-													//if prescribing_number > batch_number_all_count {
1197
-													//	c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1198
-													//	return
1199
-													//}
1133
+													if prescribing_number > batch_number_all_count {
1134
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1135
+														return
1136
+													}
1200 1137
 												}
1201 1138
 
1202 1139
 											} else {
1203 1140
 												if prescribingNumberUnit == drug.MaxUnit {
1204
-													//batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1141
+													batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1205 1142
 													num := prescribing_number * float64(drug.MinNumber)
1206 1143
 													if drug.IsUse != 1 {
1207 1144
 														if num > all_count {
@@ -1209,10 +1146,10 @@ func (c *HisApiController) CreateHisPrescription() {
1209 1146
 															return
1210 1147
 														}
1211 1148
 
1212
-														//if prescribing_number > batch_number_all_count {
1213
-														//	c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1214
-														//	return
1215
-														//}
1149
+														if prescribing_number > batch_number_all_count {
1150
+															c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1151
+															return
1152
+														}
1216 1153
 													}
1217 1154
 
1218 1155
 												}
@@ -1220,10 +1157,11 @@ func (c *HisApiController) CreateHisPrescription() {
1220 1157
 										}
1221 1158
 										//修改处方
1222 1159
 										if advicelist.ID > 0 {
1160
+											fmt.Println("232323232323232332323o2323o23o23o23o3o")
1223 1161
 											//查询最新批次库存
1224
-											//info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1225
-											//var batch_number_count int64
1226
-											//batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1162
+											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1163
+											var batch_number_count int64
1164
+											batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1227 1165
 
1228 1166
 											var device_number int64
1229 1167
 
@@ -1247,7 +1185,8 @@ func (c *HisApiController) CreateHisPrescription() {
1247 1185
 												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1248 1186
 												number_count = prescribingNumberInt
1249 1187
 											}
1250
-
1188
+											fmt.Println("number-count23323232233223", number_count)
1189
+											fmt.Println("device_number232323322323233223", device_number)
1251 1190
 											//如果修改的数量大于之前修改的数量
1252 1191
 											if (number_count - device_number) > 0 {
1253 1192
 												//如果修改的差数量 大于库存数量
@@ -1256,64 +1195,249 @@ func (c *HisApiController) CreateHisPrescription() {
1256 1195
 														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1257 1196
 														return
1258 1197
 													}
1259
-													//if (number_count - device_number) > batch_number_count {
1260
-													//	c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1261
-													//	return
1262
-													//}
1198
+													fmt.Println("(number_count - device_number3232323232332", number_count-device_number)
1199
+													fmt.Println("(number_count - device_number3232323232332", batch_number_count)
1200
+													if (number_count - device_number) > batch_number_count {
1201
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1202
+														return
1203
+													}
1204
+
1205
+													// 查询该药品最后一次出库记录
1206
+													outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1207
+													var out_count int64
1208
+													var in_count int64
1209
+													var stock_max_number int64
1210
+													var stock_min_number int64
1211
+													for _, it := range outInfo {
1212
+														if it.CountUnit == drug.MaxUnit {
1213
+															it.Count = it.Count * drug.MinNumber
1214
+														}
1215
+														out_count += it.Count
1216
+														warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
1217
+														stock_max_number = warehouseInfoList.StockMaxNumber
1218
+														stock_min_number = warehouseInfoList.StockMinNumber
1219
+														if warehouseInfoList.MaxUnit == drug.MaxUnit {
1220
+															in_count = warehouseInfoList.WarehousingCount * drug.MinNumber
1221
+														}
1222
+														if warehouseInfoList.MaxUnit == drug.MinUnit {
1223
+															in_count = warehouseInfoList.WarehousingCount
1224
+														}
1225
+													}
1226
+													if (out_count + (number_count - device_number)) > in_count {
1227
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
1228
+														return
1229
+													}
1230
+
1263 1231
 												}
1264 1232
 
1265 1233
 											}
1266
-											//没通过药房发药的才退库
1267
-											if drug.IsPharmacy != 1 {
1268
-												if device_number != number_count {
1269 1234
 
1270
-													// 查询该药品最后一次出库记录
1271
-													druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
1235
+											if device_number != number_count {
1236
+
1237
+												// 查询该药品最后一次出库记录
1238
+												druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
1239
+
1240
+												//回退库存
1241
+												if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1242
+
1243
+													service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
1244
+												}
1245
+												if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1246
+													var stock_max_number int64
1247
+													var stock_min_number int64
1248
+
1249
+													if number_count >= drug.MinNumber {
1272 1250
 
1273
-													//回退库存
1274
-													if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1251
+														stock_max_number = device_number / drug.MinNumber
1252
+														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
1253
+														stock_min_number = device_number % drug.MinNumber
1254
+														service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
1275 1255
 
1276
-														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
1256
+													} else {
1257
+
1258
+														service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
1277 1259
 													}
1278
-													if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
1279
-														var stock_max_number int64
1280
-														var stock_min_number int64
1260
+												}
1261
+
1262
+												if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
1263
+													service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
1264
+												}
1265
+												//删除记录
1266
+												service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
1267
+
1268
+												//查询默认仓库剩余多少库存
1269
+												var sum_count int64
1270
+												stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1271
+												for _, its := range stockInfo {
1272
+													sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1273
+												}
1274
+												service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
1275
+
1276
+											}
1277
+										}
1278
+									}
1279
+								}
1280
+
1281
+								//保存处方开药
1282
+								if drugOutConfig.IsOpen == 1 {
1283
+									//修改处方
1284
+									for _, advice := range advices {
1285
+										var drug_id int64
1286
+										var prescribing_number float64
1287
+										var prescribingNumberUnit string
1288
+										var prescribingNumber string
1289
+
1290
+										var adviceId int64
1291
+										if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
1292
+											drug_id = int64(advice.(map[string]interface{})["id"].(float64))
1293
+										}
1294
+										if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
1295
+											prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
1296
+											prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
1297
+											prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
1298
+										}
1299
+
1300
+										if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
1301
+											prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
1302
+										}
1281 1303
 
1282
-														if number_count >= drug.MinNumber {
1304
+										if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
1305
+											adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
1306
+										}
1283 1307
 
1284
-															stock_max_number = device_number / drug.MinNumber
1285
-															service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
1286
-															stock_min_number = device_number % drug.MinNumber
1287
-															service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
1308
+										drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
1309
+										if drug.ID == 0 {
1310
+											c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1311
+											return
1312
+										}
1313
+										//查询药品的所有库存
1314
+										list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
1315
+										var total_count int64
1316
+										for _, it := range list {
1317
+											total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
1318
+										}
1319
+										totals := strconv.FormatInt(total_count, 10)
1320
+										//查询该药品是否存在开药记录
1321
+										advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
1288 1322
 
1289
-														} else {
1323
+										//新增处方
1324
+										if advicelist.ID == 0 {
1325
+											//查询最新批次库存
1326
+											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1327
+											var batch_number_count int64
1328
+											batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1329
+											batch_number_counts := strconv.FormatInt(batch_number_count, 10)
1330
+											all_count, _ := strconv.ParseFloat(totals, 64)
1331
+											if prescribingNumberUnit == drug.MinUnit {
1332
+												batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1333
+												if drug.IsUse != 1 {
1334
+													if prescribing_number > all_count {
1335
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1336
+														return
1337
+													}
1338
+													if prescribing_number > batch_number_all_count {
1339
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1340
+														return
1341
+													}
1342
+												}
1290 1343
 
1291
-															service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
1344
+											} else {
1345
+												if prescribingNumberUnit == drug.MaxUnit {
1346
+													batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
1347
+													num := prescribing_number * float64(drug.MinNumber)
1348
+													if drug.IsUse != 1 {
1349
+														if num > all_count {
1350
+															c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1351
+															return
1352
+														}
1353
+
1354
+														if prescribing_number > batch_number_all_count {
1355
+															c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1356
+															return
1292 1357
 														}
1293 1358
 													}
1294 1359
 
1295
-													if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
1296
-														service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
1360
+												}
1361
+											}
1362
+										}
1363
+										//修改处方
1364
+										if advicelist.ID > 0 {
1365
+											//查询最新批次库存
1366
+											info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
1367
+											var batch_number_count int64
1368
+											batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
1369
+
1370
+											var device_number int64
1371
+
1372
+											if advicelist.PrescribingNumberUnit == drug.MaxUnit {
1373
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1374
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1375
+												device_number = prescribingNumberInt * drug.MinNumber
1376
+											}
1377
+											if advicelist.PrescribingNumberUnit == drug.MinUnit {
1378
+												prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
1379
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
1380
+												device_number = prescribingNumberInt
1381
+											}
1382
+
1383
+											var number_count int64
1384
+											if prescribingNumberUnit == drug.MaxUnit {
1385
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1386
+												number_count = prescribingNumberInt * drug.MinNumber
1387
+											}
1388
+											if prescribingNumberUnit == drug.MinUnit {
1389
+												prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1390
+												number_count = prescribingNumberInt
1391
+											}
1392
+											//如果修改的数量大于之前修改的数量
1393
+											if (number_count - device_number) > 0 {
1394
+												//如果修改的差数量 大于库存数量
1395
+												if drug.IsUse != 1 {
1396
+													if (number_count - device_number) > total_count {
1397
+														c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
1398
+														return
1399
+													}
1400
+													if (number_count - device_number) > batch_number_count {
1401
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
1402
+														return
1403
+													}
1404
+
1405
+													//查询历史出库数据总批次
1406
+													// 查询该药品最后一次出库记录
1407
+													outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
1408
+													var out_count int64
1409
+													var in_count int64
1410
+													var stock_max_number int64
1411
+													var stock_min_number int64
1412
+													for _, it := range outInfo {
1413
+														if it.CountUnit == drug.MaxUnit {
1414
+															it.Count = it.Count * drug.MinNumber
1415
+														}
1416
+														out_count += it.Count
1417
+														warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
1418
+														stock_max_number = warehouseInfoList.StockMaxNumber
1419
+														stock_min_number = warehouseInfoList.StockMinNumber
1420
+														if warehouseInfoList.MaxUnit == drug.MaxUnit {
1421
+															in_count = warehouseInfoList.WarehousingCount * drug.MinNumber
1422
+														}
1423
+														if warehouseInfoList.MaxUnit == drug.MinUnit {
1424
+															in_count = warehouseInfoList.WarehousingCount
1425
+														}
1297 1426
 													}
1298
-													//删除记录
1299
-													service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
1300
-
1301
-													//查询默认仓库
1302
-													storeHouseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
1303
-													//查询默认仓库剩余多少库存
1304
-													var sum_count int64
1305
-													stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
1306
-													for _, its := range stockInfo {
1307
-														sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
1427
+													//fmt.Println("out_count23323232233233223",out_count)
1428
+													//fmt.Println("+(number_count - device_number)",(number_count - device_number))
1429
+													//fmt.Println("in_count23322323222222",in_count)
1430
+													if (out_count + (number_count - device_number)) > in_count {
1431
+														c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
1432
+														return
1308 1433
 													}
1309
-													service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
1310 1434
 
1311 1435
 												}
1312 1436
 											}
1313
-
1314 1437
 										}
1315 1438
 									}
1316 1439
 								}
1440
+
1317 1441
 							}
1318 1442
 						}
1319 1443
 					}
@@ -1406,8 +1530,7 @@ func (c *HisApiController) CreateHisPrescription() {
1406 1530
 												service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
1407 1531
 
1408 1532
 												//查询默认仓库
1409
-												storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
1410
-												stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, item.OrgId)
1533
+												stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
1411 1534
 												var total_count int64
1412 1535
 												for _, it := range stockList {
1413 1536
 													total_count += it.StockCount
@@ -1472,7 +1595,6 @@ func (c *HisApiController) CreateHisPrescription() {
1472 1595
 		defer redis.Close()
1473 1596
 	} else {
1474 1597
 		hpInfo = models.HisPrescriptionInfo{
1475
-
1476 1598
 			ID:                 info.ID,
1477 1599
 			UserOrgId:          adminInfo.CurrentOrgId,
1478 1600
 			RecordDate:         info.RecordDate,
@@ -1510,8 +1632,6 @@ func (c *HisApiController) CreateHisPrescription() {
1510 1632
 	var adviceList []models.HisDoctorAdviceInfo
1511 1633
 	var projectList []models.HisPrescriptionProject
1512 1634
 
1513
-	//var hisLis  []models.HisList
1514
-
1515 1635
 	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
1516 1636
 		prescriptions, _ := dataBody["prescriptions"].([]interface{})
1517 1637
 
@@ -1605,7 +1725,6 @@ func (c *HisApiController) CreateHisPrescription() {
1605 1725
 					tempPrescription.Modifier = adminInfo.AdminUser.Id
1606 1726
 					tempPrescription.Mtime = time.Now().Unix()
1607 1727
 					tempPrescription.Doctor = role.UserName
1608
-
1609 1728
 					//tempPrescription.OrderStatus = order_status
1610 1729
 					tempPrescription.PreTime = pTime
1611 1730
 					tempPrescription.MedType = med_type
@@ -1789,15 +1908,6 @@ func (c *HisApiController) CreateHisPrescription() {
1789 1908
 
1790 1909
 							service.SaveHisProjectTwo(&p)
1791 1910
 
1792
-							//if p.Type == 3 { //处理透前准备耗材数量数据
1793
-							//	consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
1794
-							//	if consumables.ID > 0 {
1795
-							//		cnt, _ := strconv.ParseInt(p.Count, 10, 64)
1796
-							//		consumables.Count = cnt
1797
-							//		service.UpdateConsumables(&consumables)
1798
-							//	}
1799
-							//}
1800
-
1801 1911
 						}
1802 1912
 					}
1803 1913
 				}
@@ -1841,18 +1951,17 @@ func (c *HisApiController) CreateHisPrescription() {
1841 1951
 
1842 1952
 		//查询今日该患者开的药品处方
1843 1953
 		hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
1844
-		storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
1845 1954
 		drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
1846 1955
 		if drugOutConfig.IsOpen == 1 {
1847 1956
 			for _, item := range hisdoctorlist {
1848 1957
 				drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
1849
-
1850 1958
 				// 查询该药品最后一次出库记录
1851 1959
 				druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
1852 1960
 
1853 1961
 				if len(druginfo) > 0 {
1854 1962
 					//回退库存
1855 1963
 					for _, it := range druginfo {
1964
+
1856 1965
 						if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
1857 1966
 							service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
1858 1967
 						}
@@ -1876,7 +1985,7 @@ func (c *HisApiController) CreateHisPrescription() {
1876 1985
 					}
1877 1986
 
1878 1987
 					//更新字典里面的库存
1879
-					stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1988
+					stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
1880 1989
 					var sum_count int64
1881 1990
 					for _, its := range stockInfo {
1882 1991
 						sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
@@ -2190,47 +2299,6 @@ func (c *HisApiController) DeletePrescription() {
2190 2299
 
2191 2300
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
2192 2301
 
2193
-	//已收费和已发药限制逻辑
2194
-	isCharge := false
2195
-	isMedicine := false
2196
-	new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
2197
-	new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
2198
-
2199
-	for _, item := range new_prescriptions {
2200
-		if item.IsMedicine == 1 {
2201
-			isMedicine = true
2202
-		}
2203
-	}
2204
-
2205
-	for _, item := range new_prescriptions {
2206
-		if item.OrderStatus == 2 {
2207
-			isCharge = true
2208
-		}
2209
-	}
2210
-
2211
-	if p_err != nil {
2212
-		if new_prescription.ID > 0 {
2213
-			if new_prescription.OrderStatus == 2 {
2214
-				isCharge = true
2215
-			}
2216
-		}
2217
-	}
2218
-	for _, item := range advices {
2219
-		if item.IsMedicine == 1 {
2220
-			isMedicine = true
2221
-		}
2222
-	}
2223
-	if isCharge {
2224
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
2225
-		return
2226
-	}
2227
-
2228
-	if isMedicine {
2229
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
2230
-		return
2231
-	}
2232
-	//已收费和已发药限制逻辑
2233
-
2234 2302
 	if len(projects) > 0 {
2235 2303
 		for _, item := range projects {
2236 2304
 			service.DeletePrintInfo(item.ID) //删除打印信息
@@ -2459,63 +2527,13 @@ func (c *HisApiController) DeletePrescription() {
2459 2527
 	return
2460 2528
 
2461 2529
 }
2530
+
2462 2531
 func (c *HisApiController) DeleteDoctorAdvice() {
2463 2532
 	id, _ := c.GetInt64("id")
2464 2533
 	advice, _ := service.GetHisDoctorAdvicesById(id)
2465 2534
 
2466 2535
 	_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
2467 2536
 
2468
-	//已收费和已发药的限制逻辑
2469
-	isCharge := false
2470
-	isMedicine := false
2471
-	new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
2472
-
2473
-	//获取今天该患者所有处方,判断是否发药或者收费
2474
-	new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
2475
-	for _, item := range new_prescriptions {
2476
-		if item.IsMedicine == 1 {
2477
-			isMedicine = true
2478
-		}
2479
-	}
2480
-	for _, item := range new_prescriptions {
2481
-		if item.OrderStatus == 2 {
2482
-			isCharge = true
2483
-		}
2484
-	}
2485
-
2486
-	if isMedicine {
2487
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
2488
-		return
2489
-	}
2490
-
2491
-	if isCharge {
2492
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
2493
-		return
2494
-	}
2495
-
2496
-	advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
2497
-	for _, item := range advices {
2498
-		if item.IsMedicine == 1 {
2499
-			isMedicine = true
2500
-		}
2501
-	}
2502
-
2503
-	if isMedicine {
2504
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
2505
-		return
2506
-	}
2507
-	if new_prescription.ID > 0 {
2508
-		if new_prescription.OrderStatus == 2 {
2509
-			isCharge = true
2510
-		}
2511
-	}
2512
-
2513
-	if isCharge {
2514
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
2515
-		return
2516
-	}
2517
-	//已收费和已发药的限制逻辑
2518
-
2519 2537
 	err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
2520 2538
 	redis := service.RedisClient()
2521 2539
 	keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
@@ -2555,6 +2573,7 @@ func (c *HisApiController) DeleteDoctorAdvice() {
2555 2573
 		return
2556 2574
 	}
2557 2575
 }
2576
+
2558 2577
 func (c *HisApiController) DeleteProject() {
2559 2578
 	id, _ := c.GetInt64("id")
2560 2579
 	adminInfo := c.GetAdminUserInfo()
@@ -2562,40 +2581,6 @@ func (c *HisApiController) DeleteProject() {
2562 2581
 	//	var consumable models.DialysisBeforePrepare
2563 2582
 	_, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
2564 2583
 
2565
-	isCharge := false
2566
-	isMedicine := false
2567
-	new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
2568
-	new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
2569
-	for _, item := range new_prescriptions {
2570
-		if item.IsMedicine == 1 {
2571
-			isMedicine = true
2572
-		}
2573
-	}
2574
-	for _, item := range new_prescriptions {
2575
-		if item.OrderStatus == 2 {
2576
-			isCharge = true
2577
-		}
2578
-	}
2579
-	if isMedicine {
2580
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
2581
-		return
2582
-	}
2583
-	if isCharge {
2584
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
2585
-		return
2586
-	}
2587
-
2588
-	if new_prescription.ID > 0 {
2589
-		if new_prescription.OrderStatus == 2 {
2590
-			isCharge = true
2591
-		}
2592
-	}
2593
-
2594
-	if isCharge {
2595
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
2596
-		return
2597
-	}
2598
-
2599 2584
 	service.DeletePrintInfo(id)
2600 2585
 	label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
2601 2586
 	label.Status = 0
@@ -3508,7 +3493,7 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo,
3508 3493
 					advice.CheckState = hisAdvice.CheckState
3509 3494
 					advice.StartTime = hisAdvice.StartTime
3510 3495
 					advice.HospApprFlag = hisAdvice.HospApprFlag
3511
-					advice.IsMedicine = hisAdvice.IsMedicine
3496
+
3512 3497
 					if hisAdvice.UserOrgId == 10028 {
3513 3498
 						if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
3514 3499
 							advice.ExecutionTime = 0
@@ -6238,7 +6223,7 @@ func (c *HisApiController) GetFaPiaoData() {
6238 6223
 				operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
6239 6224
 			}
6240 6225
 
6241
-			if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
6226
+			if item.MedChrgitmType == "08" { //材料费
6242 6227
 				materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
6243 6228
 				materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
6244 6229
 				materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()

+ 2 - 2
service/gobal_config_service.go Ver arquivo

@@ -18,12 +18,12 @@ func CreateDrugAutomaticReduceRecord(config *models.DrugStockConfig) (err error)
18 18
 }
19 19
 
20 20
 func FindAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.GobalConfig) {
21
-	err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
21
+	err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).First(&config).Error
22 22
 	return
23 23
 }
24 24
 
25 25
 func FindDrugStockAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.DrugStockConfig) {
26
-	err = readDb.Model(&models.DrugStockConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
26
+	err = readDb.Model(&models.DrugStockConfig{}).Where("status = 1 AND org_id = ?", org_id).First(&config).Error
27 27
 	return
28 28
 }
29 29
 func UpdateAutomaticReduceRecord(config *models.GobalConfig) (err error) {

+ 155 - 31
service/mobile_dialysis_service.go Ver arquivo

@@ -1334,7 +1334,7 @@ type MDoctorAdviceVM struct {
1334 1334
 	WeekDay               string  `gorm:"column:week_day" json:"week_day"`
1335 1335
 	TemplateId            string  `gorm:"column:template_id" json:"template_id"`
1336 1336
 	Modifier              int64   `gorm:"column:modifier" json:"modifier" form:"modifier"`
1337
-	IsMedicine			  int64	  `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
1337
+	IsMedicine            int64   `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
1338 1338
 }
1339 1339
 
1340 1340
 func (MDoctorAdviceVM) TableName() string {
@@ -2825,6 +2825,20 @@ func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, pa
2825 2825
 	if len(keywords) != 0 {
2826 2826
 		keywords = "%" + keywords + "%"
2827 2827
 		db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
2828
+		if schedule_type != 0 {
2829
+			db = db.Where("schedule_type = ?", schedule_type)
2830
+		}
2831
+		if partition_id != 0 {
2832
+			db = db.Where("partition_id = ?", partition_id)
2833
+		}
2834
+		if good_type == 1 {
2835
+			db = db.Where("patient_id in(?)", ids)
2836
+		}
2837
+		if good_type == 2 {
2838
+			if len(ids) > 0 {
2839
+				db = db.Where("patient_id not in(?)", ids)
2840
+			}
2841
+		}
2828 2842
 	} else {
2829 2843
 		if schedule_type != 0 {
2830 2844
 			db = db.Where("schedule_type = ?", schedule_type)
@@ -2836,7 +2850,9 @@ func PCGetDialysisGoods(orgID int64, scheduleDate int64, schedule_type int64, pa
2836 2850
 			db = db.Where("patient_id in(?)", ids)
2837 2851
 		}
2838 2852
 		if good_type == 2 {
2839
-			db = db.Where("patient_id not in(?)", ids)
2853
+			if len(ids) > 0 {
2854
+				db = db.Where("patient_id not in(?)", ids)
2855
+			}
2840 2856
 		}
2841 2857
 		db = db.Count(&total)
2842 2858
 		offset := (page - 1) * limit
@@ -3698,11 +3714,13 @@ func GetHisPrescriptionProject(org_id int64, patient_id int64, record_date int64
3698 3714
 
3699 3715
 func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay string, patientType int, adminUserId int64, patient_id int64, execution_state int64) ([]*HisMScheduleProjectVM, error) {
3700 3716
 	var vms []*HisMScheduleProjectVM
3701
-
3717
+	fmt.Println("patient_id233232332", patient_id)
3718
+	fmt.Println("execution_state2323323322332", execution_state)
3719
+	fmt.Println("patientType2323323322332", patientType)
3702 3720
 	if patientType == 0 {
3703 3721
 
3704 3722
 		if patient_id > 0 {
3705
-			if execution_state > 0 {
3723
+			if execution_state == 1 {
3706 3724
 				db := readDb.
3707 3725
 					Table("xt_schedule").
3708 3726
 					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
@@ -3716,13 +3734,33 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3716 3734
 						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3717 3735
 					}).
3718 3736
 					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3719
-						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3737
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3720 3738
 					}).Where("status = 1 AND user_org_id = ?", orgID)
3721 3739
 				if scheduleDate != 0 {
3722 3740
 					db = db.Where("schedule_date = ?", scheduleDate)
3723 3741
 				}
3724 3742
 				err = db.Find(&vms).Error
3725
-			} else {
3743
+			} else if execution_state == 2 {
3744
+				db := readDb.
3745
+					Table("xt_schedule").
3746
+					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3747
+					Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3748
+						return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3749
+					}).
3750
+					Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3751
+					Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3752
+					Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3753
+					Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3754
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3755
+					}).
3756
+					Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3757
+						return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3758
+					}).Where("status = 1 AND user_org_id = ?", orgID)
3759
+				if scheduleDate != 0 {
3760
+					db = db.Where("schedule_date = ?", scheduleDate)
3761
+				}
3762
+				err = db.Find(&vms).Error
3763
+			} else if execution_state == 0 {
3726 3764
 				db := readDb.
3727 3765
 					Table("xt_schedule").
3728 3766
 					Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
@@ -3746,7 +3784,7 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3746 3784
 
3747 3785
 		} else {
3748 3786
 			if patient_id > 0 {
3749
-				if execution_state > 0 {
3787
+				if execution_state == 1 {
3750 3788
 					db := readDb.
3751 3789
 						Table("xt_schedule").
3752 3790
 						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
@@ -3760,13 +3798,33 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3760 3798
 							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3761 3799
 						}).
3762 3800
 						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3763
-							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3801
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3764 3802
 						}).Where("status = 1 AND user_org_id = ?", orgID)
3765 3803
 					if scheduleDate != 0 {
3766 3804
 						db = db.Where("schedule_date = ?", scheduleDate)
3767 3805
 					}
3768 3806
 					err = db.Find(&vms).Error
3769
-				} else {
3807
+				} else if execution_state == 2 {
3808
+					db := readDb.
3809
+						Table("xt_schedule").
3810
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
3811
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3812
+							return db.Where("status = 1 AND user_org_id = ? and patient_id = ?", orgID, patient_id).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3813
+						}).
3814
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3815
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3816
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ? and patient_id = ?", orgID, scheduleDate, patient_id).
3817
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3818
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3819
+						}).
3820
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3821
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3822
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3823
+					if scheduleDate != 0 {
3824
+						db = db.Where("schedule_date = ?", scheduleDate)
3825
+					}
3826
+					err = db.Find(&vms).Error
3827
+				} else if execution_state == 0 {
3770 3828
 					db := readDb.
3771 3829
 						Table("xt_schedule").
3772 3830
 						Preload("SchedualPatient", "status = 1 AND user_org_id = ? and id= ?", orgID, patient_id).
@@ -3789,7 +3847,7 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3789 3847
 				}
3790 3848
 
3791 3849
 			} else {
3792
-				if execution_state > 0 {
3850
+				if execution_state == 1 {
3793 3851
 					db := readDb.
3794 3852
 						Table("xt_schedule").
3795 3853
 						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
@@ -3803,13 +3861,34 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3803 3861
 							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("HisProject").Preload("GoodInfo", "status=1")
3804 3862
 						}).
3805 3863
 						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3806
-							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3864
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state = ?", orgID, scheduleDate, execution_state).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3807 3865
 						}).Where("status = 1 AND user_org_id = ?", orgID)
3808 3866
 					if scheduleDate != 0 {
3809 3867
 						db = db.Where("schedule_date = ?", scheduleDate)
3810 3868
 					}
3811 3869
 					err = db.Find(&vms).Error
3812
-				} else {
3870
+				} else if execution_state == 2 {
3871
+					fmt.Println("j氯332n323232n323ℹ️33232323232")
3872
+					db := readDb.
3873
+						Table("xt_schedule").
3874
+						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3875
+						Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3876
+							return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3877
+						}).
3878
+						Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3879
+						Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3880
+						Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3881
+						Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3882
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0  and execution_state =0 ", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3883
+						}).
3884
+						Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3885
+							return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0 and execution_state =0 ", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3886
+						}).Where("status = 1 AND user_org_id = ?", orgID)
3887
+					if scheduleDate != 0 {
3888
+						db = db.Where("schedule_date = ?", scheduleDate)
3889
+					}
3890
+					err = db.Find(&vms).Error
3891
+				} else if execution_state == 0 {
3813 3892
 					db := readDb.
3814 3893
 						Table("xt_schedule").
3815 3894
 						Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
@@ -3837,26 +3916,71 @@ func GetPCHisPrescriptionProject(orgID int64, scheduleDate int64, deliverWay str
3837 3916
 	}
3838 3917
 
3839 3918
 	if patientType > 0 {
3840
-		db := readDb.
3841
-			Table("xt_schedule").
3842
-			Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3843
-			Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3844
-				return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3845
-			}).
3846
-			Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3847
-			Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3848
-			Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3849
-			Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
3850
-			Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3851
-				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3852
-			}).
3853
-			Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3854
-				return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3855
-			}).Where("status = 1 AND user_org_id = ?", orgID)
3856
-		if scheduleDate != 0 {
3857
-			db = db.Where("schedule_date = ?", scheduleDate)
3919
+		if execution_state == 1 {
3920
+			db := readDb.
3921
+				Table("xt_schedule").
3922
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3923
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3924
+					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3925
+				}).
3926
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3927
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3928
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3929
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
3930
+				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3931
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 1", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3932
+				}).
3933
+				Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3934
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3935
+				}).Where("status = 1 AND user_org_id = ?", orgID)
3936
+			if scheduleDate != 0 {
3937
+				db = db.Where("schedule_date = ?", scheduleDate)
3938
+			}
3939
+			err = db.Find(&vms).Error
3940
+		} else if execution_state == 2 {
3941
+			db := readDb.
3942
+				Table("xt_schedule").
3943
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3944
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3945
+					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3946
+				}).
3947
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3948
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3949
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3950
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
3951
+				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3952
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0 and execution_state = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3953
+				}).
3954
+				Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3955
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3956
+				}).Where("status = 1 AND user_org_id = ?", orgID)
3957
+			if scheduleDate != 0 {
3958
+				db = db.Where("schedule_date = ?", scheduleDate)
3959
+			}
3960
+			err = db.Find(&vms).Error
3961
+		} else if execution_state == 0 {
3962
+			db := readDb.
3963
+				Table("xt_schedule").
3964
+				Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
3965
+				Preload("DialysisOrder", func(db *gorm.DB) *gorm.DB {
3966
+					return db.Where("status = 1 AND user_org_id = ?", orgID).Preload("DeviceNumber", "status = 1 AND org_id= ?", orgID)
3967
+				}).
3968
+				Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
3969
+				Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
3970
+				Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate).
3971
+				Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? AND advice_date = ? and  (advice_doctor = ? or execution_staff = ?) ", orgID, scheduleDate, adminUserId, adminUserId).
3972
+				Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
3973
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id = 0", orgID, scheduleDate).Preload("HisProject").Preload("GoodInfo", "status=1")
3974
+				}).
3975
+				Preload("HisPrescriptionTeamProject", func(db *gorm.DB) *gorm.DB {
3976
+					return db.Where("status = 1 AND user_org_id = ? AND record_date = ? AND team_id > 0", orgID, scheduleDate).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
3977
+				}).Where("status = 1 AND user_org_id = ?", orgID)
3978
+			if scheduleDate != 0 {
3979
+				db = db.Where("schedule_date = ?", scheduleDate)
3980
+			}
3981
+			err = db.Find(&vms).Error
3858 3982
 		}
3859
-		err = db.Find(&vms).Error
3983
+
3860 3984
 	}
3861 3985
 
3862 3986
 	return vms, err

+ 10 - 4
service/schedule_service.go Ver arquivo

@@ -1174,12 +1174,18 @@ func GetInitPrintData(patient_id int64, scheduleDate int64, orgid int64) (list [
1174 1174
 		db = db.Where("x.schedule_date >=? and x.schedule_date<=?", scheduleDate, scheduleDate)
1175 1175
 	}
1176 1176
 	err = db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1 and dialysis_date =?", scheduleDate).Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =?", scheduleDate).Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
1177
-		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1")
1178
-	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ?", scheduleDate).Preload("DialysisPrescription", "status = 1 and record_date = ?", scheduleDate).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
1179
-		return db.Where("status =1").Order("id asc")
1177
+		return db.Where("status =1 and parent_id = 0 and advice_date = ?", scheduleDate).Preload("ChildDoctorAdvice", "status = 1 and patient_id = ?", patient_id)
1178
+	}).Preload("HisDoctorAdviceInfo", "status = 1 and advice_date = ? and patient_id = ?", scheduleDate, patient_id).Preload("DialysisPrescription", "status = 1 and record_date = ? and patient_id = ?", scheduleDate, patient_id).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
1179
+		return db.Where("status =1 and patient_id = ?", patient_id).Order("id asc")
1180 1180
 	}).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
1181
-		return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgid, scheduleDate)
1181
+		return db.Where("user_org_id = ? and status = 1 and assessment_date < ? and patient_id = ?", orgid, scheduleDate, patient_id)
1182 1182
 	}).Find(&list).Error
1183 1183
 
1184 1184
 	return list, err
1185 1185
 }
1186
+
1187
+func GetLastWeightAfter(patient_id int64, scheduleDate int64, orgid int64) (models.AssessmentAfterDislysis, error) {
1188
+	dislysis := models.AssessmentAfterDislysis{}
1189
+	err := XTReadDB().Where("user_org_id = ? and  patient_id = ? and assessment_date < ? and status = 1", orgid, patient_id, scheduleDate).Order("id desc").First(&dislysis).Error
1190
+	return dislysis, err
1191
+}

+ 1 - 1
service/secondary_service.go Ver arquivo

@@ -827,7 +827,7 @@ func GetAllStoreHouseListTwo(orgid int64) (list []*models.VmStorehouseNameOne, e
827 827
 func GetAllStoreHouseConfig(orgid int64) (models.XtStorehouseConfig, error) {
828 828
 
829 829
 	config := models.XtStorehouseConfig{}
830
-	err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
830
+	err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).First(&config).Error
831 831
 	return config, err
832 832
 }
833 833
 

+ 2 - 2
service/stock_service.go Ver arquivo

@@ -5236,7 +5236,7 @@ func GetHisAdviceListByDrugIdTwo(patient_id int64, advice_date int64, orgid int6
5236 5236
 func GetHisAdviceListByDrugIdEight(drugid int64, patient_id int64, advice_date int64, advice_id int64) (models.HisDoctorAdviceInfo, error) {
5237 5237
 
5238 5238
 	info := models.HisDoctorAdviceInfo{}
5239
-	err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1 and id =?", drugid, patient_id, advice_date, advice_id).Find(&info).Error
5239
+	err := XTReadDB().Model(&info).Where("drug_id = ? and patient_id = ? and advice_date = ? and status = 1 and id =?", drugid, patient_id, advice_date, advice_id).First(&info).Error
5240 5240
 	return info, err
5241 5241
 }
5242 5242
 
@@ -6970,7 +6970,7 @@ func GetDrugOpenConfig(orgid int64) (*models.DrugOutConfig, error) {
6970 6970
 func GetDrugOpenConfigOne(orgid int64) (models.DrugOutConfig, error) {
6971 6971
 
6972 6972
 	config := models.DrugOutConfig{}
6973
-	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&config).Error
6973
+	err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).First(&config).Error
6974 6974
 
6975 6975
 	return config, err
6976 6976
 }

+ 9 - 23
service/warhouse_service.go Ver arquivo

@@ -69,7 +69,7 @@ func DrugsDelivery(orgID int64, creater int64, advice *models.DoctorAdvice) (err
69 69
 		drup, _ := FindBaseDrugLibRecord(orgID, advice.DrugId)
70 70
 		if drup.ID > 0 {
71 71
 			prescribingNumber := advice.PrescribingNumber
72
-			fmt.Println("出库数量233322332233232233223323232我的", advice.PrescribingNumber, advice.PrescribingNumberUnit)
72
+
73 73
 			DrugDeliverInfo(orgID, prescribingNumber, &out, &drup, advice)
74 74
 
75 75
 		} else {
@@ -122,8 +122,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
122 122
 		var stockMin int64
123 123
 		stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
124 124
 		stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
125
-		fmt.Println("stockMax332332332233232", stockMax)
126
-		fmt.Println("stockMax332332332233232", stockMin)
125
+
127 126
 		ChangeMaxNumber(lastWarehouse.ID, stockMax)
128 127
 		UpdateMinNumber(lastWarehouse.ID, stockMin)
129 128
 	}
@@ -142,8 +141,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
142 141
 	//baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
143 142
 
144 143
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
145
-	fmt.Println("剩余库存", stock_number)
146
-	fmt.Println("出库数量", deliver_number)
144
+
147 145
 	if stock_number >= deliver_number {
148 146
 
149 147
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
@@ -206,7 +204,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
206 204
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
207 205
 		fmt.Println(errOne)
208 206
 		//查询是否存在数据
209
-		fmt.Println("deliver_number2o222222222222", deliver_number)
207
+
210 208
 		details := &models.DrugAutomaticReduceDetail{
211 209
 			WarehouseOutId:          warehouseout.ID,
212 210
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
@@ -245,9 +243,6 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
245 243
 			}
246 244
 		}
247 245
 
248
-		fmt.Println("maxNumber", maxNumber)
249
-		fmt.Println("minNumber", minNumber)
250
-
251 246
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
252 247
 
253 248
 		if warehouse.StockMaxNumber < 0 {
@@ -301,7 +296,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
301 296
 
302 297
 		return nil
303 298
 	} else {
304
-		fmt.Println("库存数量", stock_number)
299
+
305 300
 		// 当该批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
306 301
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
307 302
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
@@ -422,7 +417,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
422 417
 
423 418
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
424 419
 		prescribingNumber_two_temp := deliver_number - stock_number
425
-		fmt.Println("剩余库存", prescribingNumber_two_temp)
420
+
426 421
 		overPlusNumber := float64(prescribingNumber_two_temp)
427 422
 
428 423
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
@@ -4984,7 +4979,7 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4984 4979
 		}
4985 4980
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
4986 4981
 		prescribingNumber_two_temp := deliver_number - stock_number
4987
-		fmt.Println("深谷数据", prescribingNumber_two_temp)
4982
+
4988 4983
 		advice.CountUnit = drup.MinUnit
4989 4984
 
4990 4985
 		AutoDrugDeliverInfoTwentyOne(orgID, prescribingNumber_two_temp, warehouseout, drup, advice)
@@ -5171,21 +5166,12 @@ func ConsumablesDeliveryThirty(orgID int64, record_time int64, goods *models.War
5171 5166
 // 药品手动出库 递归方式
5172 5167
 func AutoDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo) (err error) {
5173 5168
 	//开事务
5174
-	//tx := XTWriteDB().Begin()
5175 5169
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
5176 5170
 	var deliver_number int64 = 0
5177 5171
 	var stock_number int64 = 0
5178
-	//fmt.Println("出库数量",prescribingNumber)
5179
-	//fmt.Println("出库数量",drup.MinNumber)
5180
-	//fmt.Println("dnaeiw",advice.CountUnit)
5181
-	//if advice.CountUnit == drup.MaxUnit {
5182
-	//  deliver_number = prescribingNumber * drup.MinNumber
5183
-	//} else {
5172
+
5184 5173
 	deliver_number = prescribingNumber
5185
-	//}
5186
-	//fmt.Println("出库数量2323223323232322323232323",deliver_number)
5187
-	// 根据先进先出原则,查询最先入库的批次,进行出库
5188
-	// 如果没有对应的库存,则报错
5174
+
5189 5175
 	//开启事物
5190 5176
 	lastWarehouse, _ := FindLastDrugWarehousingInfoByID(advice.DrugId, warehouseout.StorehouseId)
5191 5177
 	if lastWarehouse.StockMinNumber >= drup.MinNumber {