|
@@ -0,0 +1,661 @@
|
|
1
|
+package controllers
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "XT_New/enums"
|
|
5
|
+ "XT_New/models"
|
|
6
|
+ "XT_New/service"
|
|
7
|
+ "encoding/json"
|
|
8
|
+ "fmt"
|
|
9
|
+ "github.com/astaxie/beego"
|
|
10
|
+ "github.com/jinzhu/gorm"
|
|
11
|
+ "strconv"
|
|
12
|
+ "strings"
|
|
13
|
+ "time"
|
|
14
|
+)
|
|
15
|
+
|
|
16
|
+type SelfDrugApiController struct {
|
|
17
|
+ BaseAuthAPIController
|
|
18
|
+}
|
|
19
|
+
|
|
20
|
+func SelfDrugRouters() {
|
|
21
|
+
|
|
22
|
+ beego.Router("/api/drug/getcurrentpatient", &SelfDrugApiController{}, "Get:GetCurrentPatient")
|
|
23
|
+ beego.Router("/api/drug/getalldrugname", &SelfDrugApiController{}, "Get:GetAllDrugName")
|
|
24
|
+ beego.Router("/api/drug/savedrugname", &SelfDrugApiController{}, "Get:SaveDrugName")
|
|
25
|
+ beego.Router("/api/drug/getdrugnamelist", &SelfDrugApiController{}, "Get:GetDrugNameList")
|
|
26
|
+ beego.Router("/api/drug/getrullename", &SelfDrugApiController{}, "Get:GetRulleName")
|
|
27
|
+ beego.Router("/api/drug/getunitbybaseid", &SelfDrugApiController{}, "Get:GetUnitByBaseId")
|
|
28
|
+ beego.Router("/api/drug/saverullename", &SelfDrugApiController{}, "Get:SaveRulleName")
|
|
29
|
+ beego.Router("/api/drug/editrullername", &SelfDrugApiController{}, "Get:EditRullerName")
|
|
30
|
+ beego.Router("/api/drug/updatedrullername", &SelfDrugApiController{}, "Get:UpdatedRullerName")
|
|
31
|
+ beego.Router("/api/drug/getalldrugnamelist", &SelfDrugApiController{}, "Get:GetAllDrugNameList")
|
|
32
|
+ beego.Router("/api/drug/getrulllistbydrugname", &SelfDrugApiController{}, "Get:GetRullerListByDrugName")
|
|
33
|
+ beego.Router("/api/drug/saveselfmedicines", &SelfDrugApiController{}, "Post:SaveSelfMedicines")
|
|
34
|
+ beego.Router("/api/drug/getcurrentorgallstaff", &SelfDrugApiController{}, "Get:GetCurrentOrgAllStaff")
|
|
35
|
+ beego.Router("/api/drug/savestock", &SelfDrugApiController{}, "Post:SaveStock")
|
|
36
|
+ beego.Router("/api/drug/saveoutstock", &SelfDrugApiController{}, "Post:SaveOutStock")
|
|
37
|
+ beego.Router("/api/drug/deletedrugbyid", &SelfDrugApiController{}, "Get:DeleteDrugById")
|
|
38
|
+ beego.Router("/api/drug/saveradio", &SelfDrugApiController{}, "Get:SaveRadio")
|
|
39
|
+ beego.Router("/api/drug/deletedrugstand", &SelfDrugApiController{}, "Get:DeleteDrugStand")
|
|
40
|
+ beego.Router("/api/drug/getstocklist", &SelfDrugApiController{}, "Get:GetStockList")
|
|
41
|
+ beego.Router("/api/drug/deletedrugname", &SelfDrugApiController{}, "Get:DeleteDrugName")
|
|
42
|
+ beego.Router("/api/drug/getdrugdetail", &SelfDrugApiController{}, "Get:GetDrugDetail")
|
|
43
|
+ beego.Router("/api/drug/getallpatientstocklist", &SelfDrugApiController{}, "Get:GetAllPatientStockList")
|
|
44
|
+ beego.Router("/api/drug/getdrugdatabypatientid", &SelfDrugApiController{}, "Get:GetDrugDataByPatientId")
|
|
45
|
+ beego.Router("/api/drug/getselfmedicallist", &SelfDrugApiController{}, "Get:GetSelfMedicalList")
|
|
46
|
+ beego.Router("/api/drug/getdrugdescbydrugname", &SelfDrugApiController{}, "Get:GetDrugDescByDrugName")
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+func (this *SelfDrugApiController) GetCurrentPatient() {
|
|
50
|
+
|
|
51
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
52
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
53
|
+ patient, err := service.GetCurrentPatient(orgId)
|
|
54
|
+ if err != nil {
|
|
55
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
56
|
+ return
|
|
57
|
+ }
|
|
58
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
59
|
+ "patient": patient,
|
|
60
|
+ })
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+func (this *SelfDrugApiController) GetAllDrugName() {
|
|
64
|
+
|
|
65
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
66
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
67
|
+ drugName, err := service.GetAllDrugName(orgId)
|
|
68
|
+ if err != nil {
|
|
69
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
70
|
+ return
|
|
71
|
+ }
|
|
72
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
73
|
+ "drugName": drugName,
|
|
74
|
+ })
|
|
75
|
+}
|
|
76
|
+
|
|
77
|
+func (this *SelfDrugApiController) SaveDrugName() {
|
|
78
|
+
|
|
79
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
80
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
81
|
+ drug_name := this.GetString("drug_name")
|
|
82
|
+ fmt.Println("drug_name", drug_name)
|
|
83
|
+ drugName := models.XtDrugName{
|
|
84
|
+ UserOrgId: orgId,
|
|
85
|
+ DrugName: drug_name,
|
|
86
|
+ Status: 1,
|
|
87
|
+ CreatedTime: time.Now().Unix(),
|
|
88
|
+ }
|
|
89
|
+ _, errcode := service.GetDrugName(drug_name, orgId)
|
|
90
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
91
|
+ err := service.SaveDrugName(&drugName)
|
|
92
|
+ if err != nil {
|
|
93
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
94
|
+ return
|
|
95
|
+ }
|
|
96
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
97
|
+ "drugName": drugName,
|
|
98
|
+ })
|
|
99
|
+ } else {
|
|
100
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
|
|
101
|
+ return
|
|
102
|
+ }
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+func (this *SelfDrugApiController) GetDrugNameList() {
|
|
106
|
+
|
|
107
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
108
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
109
|
+ list, err := service.GetDrugNameList(orgId)
|
|
110
|
+ if err != nil {
|
|
111
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
112
|
+ return
|
|
113
|
+ }
|
|
114
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
115
|
+ "list": list,
|
|
116
|
+ })
|
|
117
|
+}
|
|
118
|
+
|
|
119
|
+func (this *SelfDrugApiController) GetRulleName() {
|
|
120
|
+
|
|
121
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
122
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
123
|
+ name := this.GetString("name")
|
|
124
|
+ rulleName, err := service.GetRulleName(orgId, name)
|
|
125
|
+ rullerList, err := service.GetRulleList(orgId, name)
|
|
126
|
+ if err != nil {
|
|
127
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
128
|
+ return
|
|
129
|
+ }
|
|
130
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
131
|
+ "rulleName": rulleName,
|
|
132
|
+ "rullerList": rullerList,
|
|
133
|
+ })
|
|
134
|
+}
|
|
135
|
+
|
|
136
|
+func (this *SelfDrugApiController) GetUnitByBaseId() {
|
|
137
|
+
|
|
138
|
+ id, _ := this.GetInt64("id")
|
|
139
|
+ baseList, err := service.GetUnitByBaseId(id)
|
|
140
|
+ if err != nil {
|
|
141
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
142
|
+ return
|
|
143
|
+ }
|
|
144
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
145
|
+ "baseList": baseList,
|
|
146
|
+ })
|
|
147
|
+}
|
|
148
|
+
|
|
149
|
+func (this *SelfDrugApiController) SaveRulleName() {
|
|
150
|
+ drug_name := this.GetString("drug_name")
|
|
151
|
+ drug_spec := this.GetString("drug_spec")
|
|
152
|
+ drug_stock_limit := this.GetString("drug_stock_limit")
|
|
153
|
+ drug_name_id, _ := this.GetInt64("drug_name_id")
|
|
154
|
+ price, _ := this.GetInt64("price")
|
|
155
|
+ prices := strconv.FormatInt(price, 10)
|
|
156
|
+ durg_price, _ := strconv.ParseFloat(prices, 64)
|
|
157
|
+ unit := this.GetString("unit")
|
|
158
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
159
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
160
|
+ fmt.Println(drug_name, drug_stock_limit, unit, price, drug_spec, orgId)
|
|
161
|
+ drugSpecName := models.XtStandName{
|
|
162
|
+ DrugName: drug_name,
|
|
163
|
+ DrugSpec: drug_spec,
|
|
164
|
+ DrugStockLimit: drug_stock_limit,
|
|
165
|
+ DrugNameId: drug_name_id,
|
|
166
|
+ Price: durg_price,
|
|
167
|
+ MinUnit: unit,
|
|
168
|
+ UserOrgId: orgId,
|
|
169
|
+ Status: 1,
|
|
170
|
+ CreatedTime: time.Now().Unix(),
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+ err := service.SaveRulleName(&drugSpecName)
|
|
174
|
+ if err != nil {
|
|
175
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
176
|
+ return
|
|
177
|
+ }
|
|
178
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
179
|
+ "RullerName": drugSpecName,
|
|
180
|
+ })
|
|
181
|
+}
|
|
182
|
+
|
|
183
|
+func (this *SelfDrugApiController) EditRullerName() {
|
|
184
|
+
|
|
185
|
+ id, _ := this.GetInt64("id")
|
|
186
|
+ rullerDetail, err := service.GetRullerNameDetail(id)
|
|
187
|
+ if err != nil {
|
|
188
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
189
|
+ return
|
|
190
|
+ }
|
|
191
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
192
|
+ "rullerDetail": rullerDetail,
|
|
193
|
+ })
|
|
194
|
+}
|
|
195
|
+
|
|
196
|
+func (this *SelfDrugApiController) UpdatedRullerName() {
|
|
197
|
+
|
|
198
|
+ id, _ := this.GetInt64("id")
|
|
199
|
+ drug_name := this.GetString("drug_name")
|
|
200
|
+ drug_stock_limit := this.GetString("drug_stock_limit")
|
|
201
|
+ price, _ := this.GetInt64("price")
|
|
202
|
+ prices := strconv.FormatInt(price, 10)
|
|
203
|
+ durg_price, _ := strconv.ParseFloat(prices, 64)
|
|
204
|
+
|
|
205
|
+ drug_spec := this.GetString("drug_spec")
|
|
206
|
+ unit := this.GetString("unit")
|
|
207
|
+ drug_name_id, _ := this.GetInt64("drug_name_id")
|
|
208
|
+ RullerName := models.XtStandName{
|
|
209
|
+ DrugName: drug_name,
|
|
210
|
+ DrugStockLimit: drug_stock_limit,
|
|
211
|
+ Price: durg_price,
|
|
212
|
+ DrugSpec: drug_spec,
|
|
213
|
+ MinUnit: unit,
|
|
214
|
+ DrugNameId: drug_name_id,
|
|
215
|
+ }
|
|
216
|
+
|
|
217
|
+ err := service.UpdatedRullerName(id, &RullerName)
|
|
218
|
+ if err != nil {
|
|
219
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
220
|
+ return
|
|
221
|
+ }
|
|
222
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
223
|
+ "RullerName": RullerName,
|
|
224
|
+ })
|
|
225
|
+}
|
|
226
|
+
|
|
227
|
+func (this *SelfDrugApiController) GetAllDrugNameList() {
|
|
228
|
+
|
|
229
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
230
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
231
|
+ rullerName, err := service.GetAllDrugNameList(orgId)
|
|
232
|
+
|
|
233
|
+ if err != nil {
|
|
234
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
235
|
+ return
|
|
236
|
+ }
|
|
237
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
238
|
+ "rullerName": rullerName,
|
|
239
|
+ })
|
|
240
|
+}
|
|
241
|
+
|
|
242
|
+func (this *SelfDrugApiController) GetRullerListByDrugName() {
|
|
243
|
+
|
|
244
|
+ drug_name := this.GetString("drug_name")
|
|
245
|
+ fmt.Println(drug_name)
|
|
246
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
247
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
248
|
+ fmt.Println("orgid", orgId)
|
|
249
|
+ drugName, err := service.GetRullerListByDrugName(drug_name, orgId)
|
|
250
|
+ if err != nil {
|
|
251
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
252
|
+ return
|
|
253
|
+ }
|
|
254
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
255
|
+ "drugName": drugName,
|
|
256
|
+ })
|
|
257
|
+}
|
|
258
|
+
|
|
259
|
+func (this *SelfDrugApiController) SaveSelfMedicines() {
|
|
260
|
+
|
|
261
|
+ dataBody := make(map[string]interface{}, 0)
|
|
262
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
263
|
+ fmt.Println(err)
|
|
264
|
+ patient_id := int64(dataBody["patient_id"].(float64))
|
|
265
|
+ medicineData, _ := dataBody["medicineData"].([]interface{})
|
|
266
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
267
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
268
|
+ for _, item := range medicineData {
|
|
269
|
+ items := item.(map[string]interface{})
|
|
270
|
+ drug_name := items["drug_name"].(string)
|
|
271
|
+ id := int64(items["id"].(float64))
|
|
272
|
+ drug_spec := items["drug_spec"].(string)
|
|
273
|
+ min_unit := items["min_unit"].(string)
|
|
274
|
+ medical := models.XtSelfMedical{
|
|
275
|
+ DrugName: drug_name,
|
|
276
|
+ DrugNameId: id,
|
|
277
|
+ DrugSpec: drug_spec,
|
|
278
|
+ CreatedTime: time.Now().Unix(),
|
|
279
|
+ Status: 1,
|
|
280
|
+ UserOrgId: orgId,
|
|
281
|
+ PatientId: patient_id,
|
|
282
|
+ MinUnit: min_unit,
|
|
283
|
+ }
|
|
284
|
+ //查询同个病人同个药品同个规格是否已存在
|
|
285
|
+ _, errcode := service.GetSelfMedicalByDrugName(drug_name, drug_spec, patient_id)
|
|
286
|
+
|
|
287
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
288
|
+ err := service.CreateSelfMedical(&medical)
|
|
289
|
+ fmt.Println(err)
|
|
290
|
+ } else if errcode == nil {
|
|
291
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
|
|
292
|
+ return
|
|
293
|
+ }
|
|
294
|
+
|
|
295
|
+ }
|
|
296
|
+ returnData := make(map[string]interface{}, 0)
|
|
297
|
+ returnData["msg"] = "ok"
|
|
298
|
+ this.ServeSuccessJSON(returnData)
|
|
299
|
+ return
|
|
300
|
+}
|
|
301
|
+
|
|
302
|
+func (this *SelfDrugApiController) GetCurrentOrgAllStaff() {
|
|
303
|
+
|
|
304
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
305
|
+ orgid := adminUserInfo.CurrentOrgId
|
|
306
|
+ //fmt.Println(orgid)
|
|
307
|
+ appId := adminUserInfo.CurrentAppId
|
|
308
|
+ staff, err := service.GetCurrentOrgAllStaff(orgid, appId)
|
|
309
|
+ if err != nil {
|
|
310
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
311
|
+ return
|
|
312
|
+ }
|
|
313
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
314
|
+ "staff": staff,
|
|
315
|
+ })
|
|
316
|
+}
|
|
317
|
+
|
|
318
|
+func (this *SelfDrugApiController) SaveStock() {
|
|
319
|
+
|
|
320
|
+ timeLayout := "2006-01-02"
|
|
321
|
+ loc, _ := time.LoadLocation("Local")
|
|
322
|
+ start_time := this.GetString("start_time")
|
|
323
|
+ fmt.Println("start_time", start_time)
|
|
324
|
+ admin_user_id, _ := this.GetInt64("admin_user_id")
|
|
325
|
+ fmt.Println("admin_user_id", admin_user_id)
|
|
326
|
+ patient_id, _ := this.GetInt64("patient_id")
|
|
327
|
+ dataBody := make(map[string]interface{}, 0)
|
|
328
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
329
|
+ fmt.Println(err)
|
|
330
|
+ stocks, _ := dataBody["stocks"].([]interface{})
|
|
331
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
332
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
333
|
+ for _, item := range stocks {
|
|
334
|
+ items := item.(map[string]interface{})
|
|
335
|
+ drug_name := items["drug_name"].(string)
|
|
336
|
+ fmt.Println("drug_name", drug_name)
|
|
337
|
+ drug_name_id := int64(items["drug_name_id"].(float64))
|
|
338
|
+ fmt.Println("parient_id", drug_name_id)
|
|
339
|
+ drug_spec := items["drug_spec"].(string)
|
|
340
|
+ store_number := items["store_number"].(string)
|
|
341
|
+ fmt.Println("store_number", store_number)
|
|
342
|
+ storeNumber, _ := strconv.ParseInt(store_number, 10, 64)
|
|
343
|
+ remarks := items["remarks"].(string)
|
|
344
|
+ min_unit := items["min_unit"].(string)
|
|
345
|
+ medic_id := int64(items["id"].(float64))
|
|
346
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
347
|
+ timeArr := strings.Split(timeStr, "-")
|
|
348
|
+ total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
|
|
349
|
+
|
|
350
|
+ total = total + 1
|
|
351
|
+ warehousing_in_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
|
352
|
+ number, _ := strconv.ParseInt(warehousing_in_order, 10, 64)
|
|
353
|
+ number = number + total
|
|
354
|
+ warehousing_in_order = "RKD" + strconv.FormatInt(number, 10)
|
|
355
|
+
|
|
356
|
+ theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
357
|
+ stock := models.XtSelfStock{
|
|
358
|
+ DrugName: drug_name,
|
|
359
|
+ DrugNameId: drug_name_id,
|
|
360
|
+ DrugSpec: drug_spec,
|
|
361
|
+ StoreNumber: storeNumber,
|
|
362
|
+ Remarks: remarks,
|
|
363
|
+ AdminUserId: admin_user_id,
|
|
364
|
+ StorckTime: theTime.Unix(),
|
|
365
|
+ CreatedTime: time.Now().Unix(),
|
|
366
|
+ Status: 1,
|
|
367
|
+ UserOrgId: orgId,
|
|
368
|
+ StockInNumber: warehousing_in_order,
|
|
369
|
+ PatientId: patient_id,
|
|
370
|
+ MinUnit: min_unit,
|
|
371
|
+ StorageMode: 1,
|
|
372
|
+ MedicId: medic_id,
|
|
373
|
+ }
|
|
374
|
+ err := service.CreateStock(&stock)
|
|
375
|
+ fmt.Println("err", err)
|
|
376
|
+ }
|
|
377
|
+ returnData := make(map[string]interface{}, 0)
|
|
378
|
+ returnData["msg"] = "ok"
|
|
379
|
+ this.ServeSuccessJSON(returnData)
|
|
380
|
+ return
|
|
381
|
+}
|
|
382
|
+
|
|
383
|
+func (this *SelfDrugApiController) SaveOutStock() {
|
|
384
|
+
|
|
385
|
+ timeLayout := "2006-01-02"
|
|
386
|
+ loc, _ := time.LoadLocation("Local")
|
|
387
|
+ start_time := this.GetString("start_time")
|
|
388
|
+ admin_user_id, _ := this.GetInt64("admin_user_id")
|
|
389
|
+ patient_id, _ := this.GetInt64("patient_id")
|
|
390
|
+ dataBody := make(map[string]interface{}, 0)
|
|
391
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
392
|
+ fmt.Println(err)
|
|
393
|
+ outStocks, _ := dataBody["outStocks"].([]interface{})
|
|
394
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
395
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
396
|
+
|
|
397
|
+ for _, item := range outStocks {
|
|
398
|
+ items := item.(map[string]interface{})
|
|
399
|
+ drug_name := items["drug_name"].(string)
|
|
400
|
+ drug_name_id := int64(items["drug_name_id"].(float64))
|
|
401
|
+ drug_spec := items["drug_spec"].(string)
|
|
402
|
+ outstore_number := items["outstore_number"].(string)
|
|
403
|
+ outStoreNumber, _ := strconv.ParseInt(outstore_number, 10, 64)
|
|
404
|
+ remarks := items["remarks"].(string)
|
|
405
|
+ medic_id := int64(items["id"].(float64))
|
|
406
|
+ timeStr := time.Now().Format("2006-01-02")
|
|
407
|
+ timeArr := strings.Split(timeStr, "-")
|
|
408
|
+ total, _ := service.FindAllWarehouseOut(adminUserInfo.CurrentOrgId)
|
|
409
|
+
|
|
410
|
+ total = total + 1
|
|
411
|
+ warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
|
|
412
|
+ number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
|
|
413
|
+ number = number + total
|
|
414
|
+ warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
|
|
415
|
+ fmt.Println(remarks)
|
|
416
|
+ fmt.Println(items)
|
|
417
|
+ theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
418
|
+ stock := models.XtSelfOutStock{
|
|
419
|
+ DrugName: drug_name,
|
|
420
|
+ DrugNameId: drug_name_id,
|
|
421
|
+ DrugSpec: drug_spec,
|
|
422
|
+ OutstoreNumber: outStoreNumber,
|
|
423
|
+ Remarks: remarks,
|
|
424
|
+ AdminUserId: admin_user_id,
|
|
425
|
+ StorckTime: theTime.Unix(),
|
|
426
|
+ CreatedTime: time.Now().Unix(),
|
|
427
|
+ Status: 1,
|
|
428
|
+ UserOrgId: orgId,
|
|
429
|
+ StockOutNumber: warehousing_out_order,
|
|
430
|
+ PatientId: patient_id,
|
|
431
|
+ ExitMode: 1,
|
|
432
|
+ MedicId: medic_id,
|
|
433
|
+ }
|
|
434
|
+ err := service.CreateOutStock(&stock)
|
|
435
|
+ fmt.Println("err", err)
|
|
436
|
+ }
|
|
437
|
+ returnData := make(map[string]interface{}, 0)
|
|
438
|
+ returnData["msg"] = "ok"
|
|
439
|
+ this.ServeSuccessJSON(returnData)
|
|
440
|
+ return
|
|
441
|
+}
|
|
442
|
+
|
|
443
|
+func (this *SelfDrugApiController) DeleteDrugById() {
|
|
444
|
+ id, _ := this.GetInt64("id")
|
|
445
|
+ drug_name := this.GetString("drug_name")
|
|
446
|
+ fmt.Println("drug_name", drug_name)
|
|
447
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
448
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
449
|
+
|
|
450
|
+ _, errcode := service.GetStandDrugByDrugName(drug_name, orgId)
|
|
451
|
+ fmt.Println("errcode", errcode)
|
|
452
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
453
|
+ service.DeleteDrugName(id)
|
|
454
|
+ returnData := make(map[string]interface{}, 0)
|
|
455
|
+ returnData["msg"] = "ok"
|
|
456
|
+ this.ServeSuccessJSON(returnData)
|
|
457
|
+ } else if errcode == nil {
|
|
458
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
|
|
459
|
+ return
|
|
460
|
+ }
|
|
461
|
+}
|
|
462
|
+
|
|
463
|
+func (this *SelfDrugApiController) SaveRadio() {
|
|
464
|
+
|
|
465
|
+ radio, _ := this.GetInt64("radio")
|
|
466
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
467
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
468
|
+ drugSet := models.XtDrugSet{
|
|
469
|
+ DrugStart: radio,
|
|
470
|
+ UserOrgId: orgId,
|
|
471
|
+ Status: 1,
|
|
472
|
+ CreatedTime: time.Now().Unix(),
|
|
473
|
+ }
|
|
474
|
+ _, errcode := service.GetDrugSetByUserOrgId(orgId)
|
|
475
|
+ if errcode == gorm.ErrRecordNotFound {
|
|
476
|
+ err := service.SaveRadio(&drugSet)
|
|
477
|
+ if err != nil {
|
|
478
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
479
|
+ return
|
|
480
|
+ }
|
|
481
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
482
|
+ "drugSet": drugSet,
|
|
483
|
+ })
|
|
484
|
+ } else if errcode == nil {
|
|
485
|
+ err := service.UpdateDrugSet(&drugSet, orgId)
|
|
486
|
+ if err != nil {
|
|
487
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
488
|
+ return
|
|
489
|
+ }
|
|
490
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
491
|
+ "drugSet": drugSet,
|
|
492
|
+ })
|
|
493
|
+ }
|
|
494
|
+
|
|
495
|
+}
|
|
496
|
+
|
|
497
|
+func (this *SelfDrugApiController) DeleteDrugStand() {
|
|
498
|
+
|
|
499
|
+ id, _ := this.GetInt64("id")
|
|
500
|
+ err := service.DeleteDrugStand(id)
|
|
501
|
+ fmt.Println(err)
|
|
502
|
+ returnData := make(map[string]interface{}, 0)
|
|
503
|
+ returnData["msg"] = "ok"
|
|
504
|
+ this.ServeSuccessJSON(returnData)
|
|
505
|
+}
|
|
506
|
+
|
|
507
|
+func (this *SelfDrugApiController) GetStockList() {
|
|
508
|
+
|
|
509
|
+ patientid, _ := this.GetInt64("id")
|
|
510
|
+ start_time := this.GetString("start_time")
|
|
511
|
+ fmt.Println("开始时间", start_time)
|
|
512
|
+ timeLayout := "2006-01-02"
|
|
513
|
+ loc, _ := time.LoadLocation("Local")
|
|
514
|
+ theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
515
|
+ startimeUnix := theTime.Unix()
|
|
516
|
+ keyword := this.GetString("keyword")
|
|
517
|
+ fmt.Println("keyword", keyword)
|
|
518
|
+ //统计总数量
|
|
519
|
+ stocklist, err := service.GetStockList(patientid, startimeUnix, keyword)
|
|
520
|
+
|
|
521
|
+ //统计出库数量
|
|
522
|
+ outStocklist, err := service.GetOutStockList(patientid, startimeUnix, keyword)
|
|
523
|
+ if err != nil {
|
|
524
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
525
|
+ return
|
|
526
|
+ }
|
|
527
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
528
|
+ "stocklist": stocklist,
|
|
529
|
+ "outStocklist": outStocklist,
|
|
530
|
+ })
|
|
531
|
+}
|
|
532
|
+
|
|
533
|
+func (this *SelfDrugApiController) DeleteDrugName() {
|
|
534
|
+
|
|
535
|
+ drug_name := this.GetString("drugname")
|
|
536
|
+ patient_id, _ := this.GetInt64("patientid")
|
|
537
|
+
|
|
538
|
+ //查询该药品是否出库
|
|
539
|
+ stocklist, _ := service.GetStockOutDetail(drug_name, patient_id)
|
|
540
|
+ if len(stocklist) == 0 {
|
|
541
|
+ //删除该药品
|
|
542
|
+ service.DeleteDrugStockNumber(drug_name, patient_id)
|
|
543
|
+ returnData := make(map[string]interface{}, 0)
|
|
544
|
+ returnData["msg"] = "ok"
|
|
545
|
+ this.ServeSuccessJSON(returnData)
|
|
546
|
+ } else {
|
|
547
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
|
|
548
|
+ return
|
|
549
|
+ }
|
|
550
|
+}
|
|
551
|
+
|
|
552
|
+func (this *SelfDrugApiController) GetDrugDetail() {
|
|
553
|
+
|
|
554
|
+ timeLayout := "2006-01-02"
|
|
555
|
+ loc, _ := time.LoadLocation("Local")
|
|
556
|
+ drug_name := this.GetString("drug_name")
|
|
557
|
+ drug_spec := this.GetString("drug_spec")
|
|
558
|
+ start_time := this.GetString("start_time")
|
|
559
|
+ startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
560
|
+ end_time := this.GetString("end_time")
|
|
561
|
+ endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
|
|
562
|
+ patient_id, _ := this.GetInt64("patient_id")
|
|
563
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
564
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
565
|
+ //查询入库明细
|
|
566
|
+ stockDetail, err := service.GetStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
|
|
567
|
+
|
|
568
|
+ //查询出库明细
|
|
569
|
+ outStockDetail, err := service.GetOutStockDetail(drug_name, drug_spec, startTime.Unix(), endTime.Unix(), patient_id, orgId)
|
|
570
|
+ if err != nil {
|
|
571
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
572
|
+ return
|
|
573
|
+ }
|
|
574
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
575
|
+ "stockDetail": stockDetail,
|
|
576
|
+ "outStockDetail": outStockDetail,
|
|
577
|
+ })
|
|
578
|
+}
|
|
579
|
+
|
|
580
|
+func (this *SelfDrugApiController) GetAllPatientStockList() {
|
|
581
|
+
|
|
582
|
+ timeLayout := "2006-01-02"
|
|
583
|
+ loc, _ := time.LoadLocation("Local")
|
|
584
|
+ drug_name := this.GetString("drug_name")
|
|
585
|
+ drug_spec := this.GetString("drug_spec")
|
|
586
|
+ start_time := this.GetString("start_time")
|
|
587
|
+ theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
588
|
+ startUnix := theTime.Unix()
|
|
589
|
+ end_time := this.GetString("end_time")
|
|
590
|
+ endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
|
|
591
|
+ endTimeUnix := endTimes.Unix()
|
|
592
|
+ keywords := this.GetString("search_input")
|
|
593
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
594
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
595
|
+
|
|
596
|
+ //入库
|
|
597
|
+ stocklist, err := service.GetAllPatientStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
|
|
598
|
+
|
|
599
|
+ //出库
|
|
600
|
+ outStockList, err := service.GetAllPatientOutStockList(drug_name, drug_spec, startUnix, endTimeUnix, keywords, orgId)
|
|
601
|
+ if err != nil {
|
|
602
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
603
|
+ return
|
|
604
|
+ }
|
|
605
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
606
|
+ "stocklist": stocklist,
|
|
607
|
+ "outStockList": outStockList,
|
|
608
|
+ })
|
|
609
|
+}
|
|
610
|
+
|
|
611
|
+func (this *SelfDrugApiController) GetDrugDataByPatientId() {
|
|
612
|
+
|
|
613
|
+ patient_id, _ := this.GetInt64("patient_id")
|
|
614
|
+ fmt.Println("patient_id", patient_id)
|
|
615
|
+ medicalList, err := service.GetDrugDataByPatientId(patient_id)
|
|
616
|
+ if err != nil {
|
|
617
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
618
|
+ return
|
|
619
|
+ }
|
|
620
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
621
|
+ "medicalList": medicalList,
|
|
622
|
+ })
|
|
623
|
+}
|
|
624
|
+
|
|
625
|
+func (this *SelfDrugApiController) GetSelfMedicalList() {
|
|
626
|
+
|
|
627
|
+ patient_id, _ := this.GetInt64("patient_id")
|
|
628
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
629
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
630
|
+ //查询该机构是否开启自备药
|
|
631
|
+ medical, _ := service.GetSetSelfMedical(orgId)
|
|
632
|
+ //开启
|
|
633
|
+ if medical.DrugStart == 1 {
|
|
634
|
+ list, err := service.GetSelfMedicalList(patient_id)
|
|
635
|
+ if err != nil {
|
|
636
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
637
|
+ return
|
|
638
|
+ }
|
|
639
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
640
|
+ "medicalList": list,
|
|
641
|
+ })
|
|
642
|
+ }
|
|
643
|
+}
|
|
644
|
+
|
|
645
|
+func (this *SelfDrugApiController) GetDrugDescByDrugName() {
|
|
646
|
+
|
|
647
|
+ drug_name := this.GetString("drug_name")
|
|
648
|
+ fmt.Println("drug_name", drug_name)
|
|
649
|
+ patient_id, _ := this.GetInt64("patient_id")
|
|
650
|
+ fmt.Println("patient_id", patient_id)
|
|
651
|
+ adminUserInfo := this.GetAdminUserInfo()
|
|
652
|
+ orgId := adminUserInfo.CurrentOrgId
|
|
653
|
+ drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
|
|
654
|
+ if err != nil {
|
|
655
|
+ this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
|
|
656
|
+ return
|
|
657
|
+ }
|
|
658
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
659
|
+ "drugspec": drugspec,
|
|
660
|
+ })
|
|
661
|
+}
|