Browse Source

库存流水展示

XMLWAN 2 years ago
parent
commit
c96853361a

+ 194 - 1
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 {}" {

+ 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())

+ 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://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"},
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"},

+ 81 - 14
service/pharmacy_service.go View File

@@ -46,11 +46,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
46 46
 	var tmp []*models.TmpTTT
47 47
 	if is_medicine == 0 {
48 48
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
49
-			"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 "+
50 50
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
51 51
 			"union "+
52 52
 			"select distinct patient_id from xt_doctor_advice where "+
53
-			"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 "+
54 54
 			"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) ",
55 55
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
56 56
 		if err != nil {
@@ -58,11 +58,11 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
58 58
 		}
59 59
 	} else {
60 60
 		err = XTReadDB().Raw("select distinct patient_id from his_doctor_advice_info where "+
61
-			"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 "+
62 62
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) "+
63 63
 			"union "+
64 64
 			"select distinct patient_id from xt_doctor_advice where "+
65
-			"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 "+
66 66
 			"drug_id in (select id from xt_base_drug where org_id = ? and status = 1) ",
67 67
 			stime, etime, orgid, orgid, stime, etime, orgid, orgid).Scan(&tmp).Error
68 68
 		if err != nil {
@@ -74,6 +74,52 @@ func GetTodayPharmacy(stime, etime, orgid, is_medicine int64) (num int, err erro
74 74
 
75 75
 }
76 76
 
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
+
77 123
 // (改)
78 124
 func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list []*models.TmpPatient, err error) {
79 125
 	InitDrugidIsNil(orgid, stime, etime)
@@ -84,22 +130,22 @@ func GetTodayDrug(stime, etime, orgid, is_medicine int64, keyword string) (list
84 130
 		if keyword != "" {
85 131
 			keyword = "%" + keyword + "%"
86 132
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
87
-				"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 "+
88 134
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
89 135
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
90 136
 				"union "+
91 137
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
92
-				"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 "+
93 139
 				"patient_id in (select id from xt_patients where user_org_id = ? and name like ? or dialysis_no like ?) and "+
94 140
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc ",
95 141
 				stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid, stime, etime, orgid, is_medicine, orgid, keyword, keyword, orgid).Scan(&tmp).Error
96 142
 		} else {
97 143
 			err = XTReadDB().Raw("select a.* from(select distinct patient_id,dispensing_time from his_doctor_advice_info where "+
98
-				"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 "+
99 145
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1) "+
100 146
 				"union "+
101 147
 				"select distinct patient_id,dispensing_time from xt_doctor_advice where "+
102
-				"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 "+
103 149
 				"drug_id in (select id from xt_base_drug where org_id = ? and is_pharmacy = 1))a order by dispensing_time desc",
104 150
 				stime, etime, orgid, is_medicine, orgid, stime, etime, orgid, is_medicine, orgid).Scan(&tmp).Error
105 151
 		}
@@ -172,13 +218,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
172 218
 	var tmp []*models.HisDoctorAdviceInfoL
173 219
 	if is_medicine == 0 {
174 220
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
175
-			"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
176 222
 		if err != nil {
177 223
 			return pp, err
178 224
 		}
179 225
 	} else {
180 226
 		err = XTReadDB().Model(&models.HisDoctorAdviceInfoL{}).Where(
181
-			"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
182 228
 		if err != nil {
183 229
 			return pp, err
184 230
 		}
@@ -201,13 +247,13 @@ func GetPatientMedication(orgid, patient_id, stime, etime, is_medicine int64) (p
201 247
 	var tmp_advice []*models.XtDoctorAdviceL
202 248
 	if is_medicine == 0 {
203 249
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
204
-			"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
205 251
 		if err != nil {
206 252
 			return pp, err
207 253
 		}
208 254
 	} else {
209 255
 		err = XTReadDB().Model(&models.XtDoctorAdviceL{}).Where(
210
-			"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
211 257
 		if err != nil {
212 258
 			return pp, err
213 259
 		}
@@ -580,7 +626,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
580 626
 	time_now := time.Now().Unix()
581 627
 	var hids []*models.TmpID
582 628
 	var xids []*models.TmpID
583
-	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 <= ? "+
584 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
585 631
 	if err != nil {
586 632
 		return
@@ -629,7 +675,7 @@ func DispensingMedicine(orgid, patient_id, stime, etime, creater int64) (err err
629 675
 		return err1
630 676
 	}
631 677
 
632
-	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 "+
678
+	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 "+
633 679
 		"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
634 680
 	if err != nil {
635 681
 		return
@@ -1911,3 +1957,24 @@ func GetAllValidDeviceZones02(orgID int64) ([]*models.DeviceZone, error) {
1911 1957
 	}
1912 1958
 	return zones, nil
1913 1959
 }
1960
+
1961
+func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
1962
+
1963
+	db := XTReadDB().Model(&advice).Where("status= 1")
1964
+
1965
+	if orgid > 0 {
1966
+		db = db.Where("user_org_id = ?", orgid)
1967
+	}
1968
+	if patient_id > 0 {
1969
+		db = db.Where("patient_id = ?", patient_id)
1970
+	}
1971
+	if stime > 0 {
1972
+		db = db.Where("advice_date >=?", stime)
1973
+	}
1974
+	if etime > 0 {
1975
+		db = db.Where("advice_date<=?", etime)
1976
+	}
1977
+	err = db.Find(&advice).Error
1978
+
1979
+	return advice, err
1980
+}