|
@@ -1054,53 +1054,145 @@ func (c *HisApiController) CreateHisPrescription() {
|
1054
|
1054
|
drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
|
1055
|
1055
|
if drugOutConfig.IsOpen != 1 {
|
1056
|
1056
|
//修改处方
|
1057
|
|
- if advicelist.ID > 0 {
|
1058
|
|
- all_count, _ := strconv.ParseFloat(totals, 64) //总库存
|
1059
|
|
- var his_count int64 //历史出库数据
|
1060
|
|
- if advicelist.PrescribingNumberUnit == drug.MaxUnit {
|
1061
|
|
- strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
|
1062
|
|
- intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
|
1063
|
|
- his_count = intPrescribingNumber * drug.MinNumber
|
|
1057
|
+ for _, advice := range advices {
|
|
1058
|
+ var drug_id int64
|
|
1059
|
+ var prescribing_number float64
|
|
1060
|
+ var prescribingNumberUnit string
|
|
1061
|
+ var prescribingNumber string
|
|
1062
|
+
|
|
1063
|
+ var adviceId int64
|
|
1064
|
+ if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
|
|
1065
|
+ drug_id = int64(advice.(map[string]interface{})["id"].(float64))
|
1064
|
1066
|
}
|
1065
|
|
- if advicelist.PrescribingNumberUnit == drug.MinUnit {
|
1066
|
|
- strPrescribingNumber := strconv.FormatFloat(advicelist.PrescribingNumber, 'E', -1, 64)
|
1067
|
|
- intPrescribingNumber, _ := strconv.ParseInt(strPrescribingNumber, 10, 64)
|
1068
|
|
- his_count = intPrescribingNumber
|
|
1067
|
+ if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
|
|
1068
|
+ prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
|
|
1069
|
+ prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
|
|
1070
|
+ prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
|
1069
|
1071
|
}
|
1070
|
1072
|
|
1071
|
|
- if prescribingNumberUnit == drug.MinUnit {
|
|
1073
|
+ if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
|
|
1074
|
+ prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
|
|
1075
|
+ }
|
1072
|
1076
|
|
1073
|
|
- float_prescribing_number := strconv.FormatFloat(prescribing_number, 'f', -1, 64)
|
1074
|
|
- int_prescribing_number, _ := strconv.ParseInt(float_prescribing_number, 10, 64)
|
1075
|
|
- float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
|
1076
|
|
- int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
|
|
1077
|
+ if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
|
|
1078
|
+ adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
|
|
1079
|
+ }
|
1077
|
1080
|
|
1078
|
|
- fmt.Println("总库存我的", int_all_count)
|
1079
|
|
- fmt.Println("现在出库库存", int_prescribing_number)
|
1080
|
|
- fmt.Println("历史出库数据", his_count)
|
1081
|
|
- if (int_prescribing_number - his_count) > int_all_count {
|
1082
|
|
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
1083
|
|
- return
|
|
1081
|
+ drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
|
|
1082
|
+ if drug.ID == 0 {
|
|
1083
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
1084
|
+ return
|
|
1085
|
+ }
|
|
1086
|
+ houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
|
|
1087
|
+ //查询药品的所有库存
|
|
1088
|
+ list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
|
|
1089
|
+ var total_count int64
|
|
1090
|
+ for _, it := range list {
|
|
1091
|
+ total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
|
|
1092
|
+ }
|
|
1093
|
+ totals := strconv.FormatInt(total_count, 10)
|
|
1094
|
+ //查询该药品是否存在开药记录
|
|
1095
|
+ advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
|
|
1096
|
+
|
|
1097
|
+ //新增处方
|
|
1098
|
+ if advicelist.ID == 0 {
|
|
1099
|
+ all_count, _ := strconv.ParseFloat(totals, 64)
|
|
1100
|
+ if prescribingNumberUnit == drug.MinUnit {
|
|
1101
|
+ if prescribing_number > all_count {
|
|
1102
|
+ c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
|
1103
|
+ return
|
|
1104
|
+ }
|
|
1105
|
+ } else {
|
|
1106
|
+ if prescribingNumberUnit == drug.MaxUnit {
|
|
1107
|
+ num := prescribing_number * float64(drug.MinNumber)
|
|
1108
|
+ if num > all_count {
|
|
1109
|
+ c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
|
1110
|
+ return
|
|
1111
|
+ }
|
|
1112
|
+ }
|
1084
|
1113
|
}
|
1085
|
|
-
|
1086
|
1114
|
}
|
1087
|
|
- if prescribingNumberUnit == drug.MaxUnit {
|
1088
|
|
- float_all_count := strconv.FormatFloat(all_count, 'f', -1, 64)
|
1089
|
|
- int_all_count, _ := strconv.ParseInt(float_all_count, 10, 64)
|
1090
|
|
- num := prescribing_number * float64(drug.MinNumber)
|
1091
|
|
- num_str_count := strconv.FormatFloat(num, 'f', -1, 64)
|
1092
|
|
- num_int_count, _ := strconv.ParseInt(num_str_count, 10, 64)
|
1093
|
|
- fmt.Println("总库存我的", int_all_count)
|
1094
|
|
- fmt.Println("现在出库库存", num_str_count)
|
1095
|
|
- fmt.Println("历史出库数据", his_count)
|
1096
|
|
- if (num_int_count - his_count) > int_all_count {
|
1097
|
|
- c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
1098
|
|
- return
|
|
1115
|
+ //修改处方
|
|
1116
|
+ if advicelist.ID > 0 {
|
|
1117
|
+ var device_number int64
|
|
1118
|
+
|
|
1119
|
+ if advicelist.PrescribingNumberUnit == drug.MaxUnit {
|
|
1120
|
+ prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
|
|
1121
|
+ prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
|
|
1122
|
+ device_number = prescribingNumberInt * drug.MinNumber
|
|
1123
|
+ }
|
|
1124
|
+ if advicelist.PrescribingNumberUnit == drug.MinUnit {
|
|
1125
|
+ prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
|
|
1126
|
+ prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
|
|
1127
|
+ device_number = prescribingNumberInt
|
|
1128
|
+ }
|
|
1129
|
+
|
|
1130
|
+ var number_count int64
|
|
1131
|
+ if prescribingNumberUnit == drug.MaxUnit {
|
|
1132
|
+ prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
1133
|
+ number_count = prescribingNumberInt * drug.MinNumber
|
|
1134
|
+ }
|
|
1135
|
+ if prescribingNumberUnit == drug.MinUnit {
|
|
1136
|
+ prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
|
|
1137
|
+ number_count = prescribingNumberInt
|
|
1138
|
+ }
|
|
1139
|
+
|
|
1140
|
+ //如果修改的数量大于之前修改的数量
|
|
1141
|
+ if (number_count - device_number) > 0 {
|
|
1142
|
+ //如果修改的差数量 大于库存数量
|
|
1143
|
+ if (number_count - device_number) > total_count {
|
|
1144
|
+ c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
|
|
1145
|
+ return
|
|
1146
|
+ }
|
|
1147
|
+ }
|
|
1148
|
+
|
|
1149
|
+ if device_number != number_count {
|
|
1150
|
+
|
|
1151
|
+ // 查询该药品最后一次出库记录
|
|
1152
|
+ druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
|
|
1153
|
+
|
|
1154
|
+ //回退库存
|
|
1155
|
+ if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
|
|
1156
|
+
|
|
1157
|
+ service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
|
|
1158
|
+ }
|
|
1159
|
+ if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
|
|
1160
|
+ var stock_max_number int64
|
|
1161
|
+ var stock_min_number int64
|
|
1162
|
+
|
|
1163
|
+ if number_count >= drug.MinNumber {
|
|
1164
|
+
|
|
1165
|
+ stock_max_number = device_number / drug.MinNumber
|
|
1166
|
+ service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
|
|
1167
|
+ stock_min_number = device_number % drug.MinNumber
|
|
1168
|
+ service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
|
|
1169
|
+
|
|
1170
|
+ } else {
|
|
1171
|
+
|
|
1172
|
+ service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
|
|
1173
|
+ }
|
|
1174
|
+ }
|
|
1175
|
+
|
|
1176
|
+ if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
|
|
1177
|
+ service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
|
|
1178
|
+ }
|
|
1179
|
+ //删除记录
|
|
1180
|
+ service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
|
|
1181
|
+
|
|
1182
|
+ //查询默认仓库
|
|
1183
|
+ storeHouseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
|
|
1184
|
+ //查询默认仓库剩余多少库存
|
|
1185
|
+ var sum_count int64
|
|
1186
|
+ stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
|
|
1187
|
+ for _, its := range stockInfo {
|
|
1188
|
+ sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
|
|
1189
|
+ }
|
|
1190
|
+ service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
|
|
1191
|
+
|
1099
|
1192
|
}
|
1100
|
1193
|
}
|
1101
|
1194
|
}
|
1102
|
1195
|
}
|
1103
|
|
-
|
1104
|
1196
|
}
|
1105
|
1197
|
}
|
1106
|
1198
|
}
|
|
@@ -1191,9 +1283,20 @@ func (c *HisApiController) CreateHisPrescription() {
|
1191
|
1283
|
for _, item := range goodList {
|
1192
|
1284
|
//回退库存
|
1193
|
1285
|
service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
|
|
1286
|
+
|
|
1287
|
+ //查询默认仓库
|
|
1288
|
+ storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.OrgId)
|
|
1289
|
+ stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, item.OrgId)
|
|
1290
|
+ var total_count int64
|
|
1291
|
+ for _, it := range stockList {
|
|
1292
|
+ total_count += it.StockCount
|
|
1293
|
+ }
|
|
1294
|
+ //基础库插入数据
|
|
1295
|
+ service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
|
1194
|
1296
|
}
|
1195
|
1297
|
//删除记录
|
1196
|
1298
|
service.DeleteAutoWarehouse(patient_id, recordDateTime)
|
|
1299
|
+
|
1197
|
1300
|
}
|
1198
|
1301
|
|
1199
|
1302
|
}
|