pharmacy_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "math"
  10. "strconv"
  11. "time"
  12. )
  13. type PharmacyController struct {
  14. BaseAuthAPIController
  15. }
  16. func PharmacyApiRegistRouters() {
  17. beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
  18. beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber") //查询今天的待发药,已发药人数(
  19. beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug") //获取当天待发药的所有患者(
  20. beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug") //获取当天已发药的所有患者(
  21. beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent") //获取当天该患者的所有信息(
  22. beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine") //患者发药按钮点击(
  23. beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal") //退药按钮点击
  24. beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails") //获取发药明细的患者列表(
  25. beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails") //发药明细-详情(
  26. beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine") //获取当天已发药的药品(
  27. beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine") //获取当天待发药的药品(
  28. beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
  29. beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture") //药品发药按钮点击(
  30. beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName") //获取当前登录账号的名字(
  31. beego.Router("/api/pharmacy/getpartitionlist", &PharmacyController{}, "get:GetPartitionList") //获取当前机构的分区列表
  32. beego.Router("/api/pharmacy/routeofadministration", &PharmacyController{}, "get:RouteOfAdministration") //获取当前机构的给药途径
  33. }
  34. //测试
  35. func (this *PharmacyController) Tlili() {
  36. var err error
  37. defer func() {
  38. if rec := recover(); rec != nil {
  39. err = fmt.Errorf("程序异常:%v", rec)
  40. }
  41. if err != nil {
  42. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  43. }
  44. }()
  45. var list2 []*models.ReplacementDrugs
  46. list2, err = service.ReplacementDrugs(9675, false)
  47. if err != nil {
  48. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  49. return
  50. }
  51. this.ServeSuccessJSON(map[string]interface{}{
  52. "list": list2,
  53. })
  54. return
  55. }
  56. func (this *PharmacyController) GetCurrentName() {
  57. create := this.GetAdminUserInfo().AdminUser.Id
  58. this.ServeSuccessJSON(map[string]interface{}{
  59. "list": create,
  60. })
  61. return
  62. }
  63. //查询今天的待发药,已发药人数
  64. func (this *PharmacyController) TodayNumber() {
  65. var err error
  66. defer func() {
  67. if rec := recover(); rec != nil {
  68. err = fmt.Errorf("程序异常:%v", rec)
  69. }
  70. if err != nil {
  71. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  72. }
  73. }()
  74. orgid := this.GetAdminUserInfo().CurrentOrgId
  75. times := this.GetString("time", "")
  76. timeLayout := "2006-01-02"
  77. loc, _ := time.LoadLocation("Local")
  78. var stime, etime int64
  79. if times == "" {
  80. stime, etime = service.GetNowTime()
  81. } else {
  82. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  83. stime = stmp.Unix()
  84. etime = stime + 86399
  85. }
  86. if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
  87. //查询表里当天的数据
  88. var wtotal int
  89. wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
  90. if err != nil {
  91. utils.ErrorLog(err.Error())
  92. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  93. return
  94. }
  95. var itotal int
  96. itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
  97. if err != nil {
  98. utils.ErrorLog(err.Error())
  99. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. this.ServeSuccessJSON(map[string]interface{}{
  103. "wtotal": wtotal,
  104. "itotal": itotal,
  105. })
  106. return
  107. }
  108. if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
  109. var wtotal int
  110. var itotal int
  111. //查找出库数量
  112. wtotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 1)
  113. itotal, _ = service.GetTodayAdviceCount(stime, etime, orgid, 0)
  114. this.ServeSuccessJSON(map[string]interface{}{
  115. "wtotal": wtotal,
  116. "itotal": itotal,
  117. })
  118. return
  119. }
  120. }
  121. func (this *PharmacyController) IssuedDrug() {
  122. var err error
  123. defer func() {
  124. if rec := recover(); rec != nil {
  125. err = fmt.Errorf("程序异常:%v", rec)
  126. }
  127. if err != nil {
  128. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  129. }
  130. }()
  131. keyword := this.GetString("keyword", "")
  132. times := this.GetString("time", "")
  133. orgid := this.GetAdminUserInfo().CurrentOrgId
  134. shift, err := this.GetInt64("shift", 0) //班次
  135. if err != nil {
  136. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  137. return
  138. }
  139. partition, err := this.GetInt64("partition", 0) //分区
  140. if err != nil {
  141. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. timeLayout := "2006-01-02"
  145. loc, _ := time.LoadLocation("Local")
  146. var stime, etime int64
  147. if times == "" {
  148. stime, etime = service.GetNowTime()
  149. } else {
  150. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  151. stime = stmp.Unix()
  152. etime = stime + 86399
  153. }
  154. if orgid == 10164 || orgid == 3877 || orgid == 10188 || orgid == 10217 || orgid == 9671 {
  155. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1)
  156. fmt.Println("list23323232323232", list)
  157. var flist []models.TmpPatientOne
  158. if len(list) > 0 {
  159. for _, item := range list {
  160. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  161. flist = append(flist, patientlist)
  162. }
  163. }
  164. this.ServeSuccessJSON(map[string]interface{}{
  165. "list": flist,
  166. })
  167. }
  168. if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 {
  169. //查询表里当天的数据
  170. var flist []*models.TmpPatient
  171. flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  172. if err != nil {
  173. utils.ErrorLog(err.Error())
  174. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  175. return
  176. }
  177. listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  178. if err != nil {
  179. utils.ErrorLog(err.Error())
  180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  181. return
  182. }
  183. this.ServeSuccessJSON(map[string]interface{}{
  184. "list": listt,
  185. })
  186. return
  187. }
  188. }
  189. func (this *PharmacyController) WaitingDrug() {
  190. var err error
  191. defer func() {
  192. if rec := recover(); rec != nil {
  193. err = fmt.Errorf("程序异常:%v", rec)
  194. }
  195. if err != nil {
  196. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  197. }
  198. }()
  199. keyword := this.GetString("keyword", "")
  200. times := this.GetString("time", "")
  201. shift, err := this.GetInt64("shift", 0) //班次
  202. if err != nil {
  203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  204. return
  205. }
  206. partition, err := this.GetInt64("partition", 0) //分区
  207. if err != nil {
  208. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. orgid := this.GetAdminUserInfo().CurrentOrgId
  212. timeLayout := "2006-01-02"
  213. loc, _ := time.LoadLocation("Local")
  214. var stime, etime int64
  215. if times == "" {
  216. stime, etime = service.GetNowTime()
  217. } else {
  218. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  219. stime = stmp.Unix()
  220. etime = stime + 86399
  221. }
  222. if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
  223. //查询表里当天的数据
  224. var flist []*models.TmpPatient
  225. flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
  226. if err != nil {
  227. utils.ErrorLog(err.Error())
  228. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  229. return
  230. }
  231. listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  232. if err != nil {
  233. utils.ErrorLog(err.Error())
  234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  235. return
  236. }
  237. this.ServeSuccessJSON(map[string]interface{}{
  238. "list": listt,
  239. })
  240. return
  241. }
  242. //当天已发药的人数
  243. if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
  244. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0)
  245. var flist []models.TmpPatientOne
  246. if len(list) > 0 {
  247. for _, item := range list {
  248. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  249. flist = append(flist, patientlist)
  250. }
  251. }
  252. this.ServeSuccessJSON(map[string]interface{}{
  253. "list": flist,
  254. })
  255. return
  256. }
  257. }
  258. //
  259. func (this *PharmacyController) GetPharmacyContent() {
  260. var err error
  261. defer func() {
  262. if rec := recover(); rec != nil {
  263. err = fmt.Errorf("程序异常:%v", rec)
  264. }
  265. if err != nil {
  266. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  267. }
  268. }()
  269. patient_id, _ := this.GetInt64("patient_id", 0)
  270. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  271. times := this.GetString("time", "")
  272. orgid := this.GetAdminUserInfo().CurrentOrgId
  273. timeLayout := "2006-01-02"
  274. loc, _ := time.LoadLocation("Local")
  275. var stime, etime int64
  276. if times == "" {
  277. stime, etime = service.GetNowTime()
  278. } else {
  279. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  280. stime = stmp.Unix()
  281. etime = stime + 86399
  282. }
  283. var list []*models.PharmacyContent
  284. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  285. if err != nil {
  286. utils.ErrorLog(err.Error())
  287. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  288. return
  289. }
  290. return_value := make(map[string]interface{})
  291. return_value["list"] = list
  292. //if is_medicine == 1{发药时间先不展示
  293. // return_value["time"] = time
  294. //}
  295. this.ServeSuccessJSON(return_value)
  296. return
  297. }
  298. //发药按钮点击
  299. func (this *PharmacyController) DispensingMedicine() {
  300. var err error
  301. defer func() {
  302. if rec := recover(); rec != nil {
  303. err = fmt.Errorf("程序异常:%v", rec)
  304. }
  305. if err != nil {
  306. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  307. }
  308. }()
  309. patient_id, _ := this.GetInt64("patient_id", 0)
  310. times := this.GetString("time", "")
  311. orgid := this.GetAdminUserInfo().CurrentOrgId
  312. creater := this.GetAdminUserInfo().AdminUser.Id
  313. timeLayout := "2006-01-02"
  314. loc, _ := time.LoadLocation("Local")
  315. var stime, etime int64
  316. if times == "" {
  317. stime, etime = service.GetNowTime()
  318. } else {
  319. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  320. stime = stmp.Unix()
  321. etime = stime + 86399
  322. }
  323. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  324. if len(advicelist) > 0 {
  325. var total int64
  326. var prescribing_number_total int64
  327. for _, item := range advicelist {
  328. houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
  329. //查询该药品是否有库存
  330. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  331. //查询改药品信息
  332. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  333. //判断单位是否相等
  334. if medical.MaxUnit == item.PrescribingNumberUnit {
  335. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  336. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  337. //转化为最小单位
  338. total = list.Count*medical.MinNumber + list.StockMinNumber
  339. prescribing_number_total = count * medical.MinNumber
  340. }
  341. if medical.MinUnit == item.PrescribingNumberUnit {
  342. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  343. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  344. total = list.Count*medical.MinNumber + list.StockMinNumber
  345. prescribing_number_total = count
  346. }
  347. if medical.IsUse != 1 {
  348. //如果出库数量大于库存数量
  349. if prescribing_number_total > total {
  350. err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
  351. if err != nil {
  352. utils.ErrorLog(err.Error())
  353. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  354. return
  355. }
  356. }
  357. }
  358. }
  359. }
  360. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  361. if err != nil {
  362. utils.ErrorLog(err.Error())
  363. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  364. return
  365. }
  366. this.ServeSuccessJSON(map[string]interface{}{
  367. "list": "操作成功",
  368. })
  369. return
  370. }
  371. //退药按钮点击
  372. func (this *PharmacyController) DrugWithdrawal() {
  373. var err error
  374. defer func() {
  375. if rec := recover(); rec != nil {
  376. err = fmt.Errorf("程序异常:%v", rec)
  377. }
  378. if err != nil {
  379. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  380. }
  381. }()
  382. patient_id, _ := this.GetInt64("patient_id", 0)
  383. times := this.GetString("time", "")
  384. orgid := this.GetAdminUserInfo().CurrentOrgId
  385. creater := this.GetAdminUserInfo().AdminUser.Id
  386. timeLayout := "2006-01-02"
  387. loc, _ := time.LoadLocation("Local")
  388. var stime, etime int64
  389. if times == "" {
  390. stime, etime = service.GetNowTime()
  391. } else {
  392. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  393. stime = stmp.Unix()
  394. etime = stime + 86399
  395. }
  396. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  397. if err != nil {
  398. utils.ErrorLog(err.Error())
  399. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  400. return
  401. }
  402. this.ServeSuccessJSON(map[string]interface{}{
  403. "list": "操作成功",
  404. })
  405. return
  406. }
  407. //发药明细列表
  408. func (this *PharmacyController) DispensingDetails() {
  409. var err error
  410. defer func() {
  411. if rec := recover(); rec != nil {
  412. err = fmt.Errorf("程序异常:%v", rec)
  413. }
  414. if err != nil {
  415. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  416. }
  417. }()
  418. keyword := this.GetString("keyword", "") //患者名称
  419. start_time := this.GetString("start_time", "") //开始时间
  420. end_time := this.GetString("end_time", "") //结束时间
  421. page, _ := this.GetInt64("page", 1) //页码
  422. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  423. orgid := this.GetAdminUserInfo().CurrentOrgId
  424. timeLayout := "2006-01-02"
  425. loc, _ := time.LoadLocation("Local")
  426. var stime, etime int64
  427. if start_time == "" {
  428. stime = 1
  429. } else {
  430. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  431. stime = stmp.Unix()
  432. }
  433. if end_time == "" {
  434. _, etime = service.GetNowTime()
  435. } else {
  436. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  437. etime = etmp.Unix()
  438. }
  439. var dislist []*models.DispensingList
  440. var total int64
  441. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  442. if err != nil {
  443. utils.ErrorLog(err.Error())
  444. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  445. return
  446. }
  447. this.ServeSuccessJSON(map[string]interface{}{
  448. "list": dislist,
  449. "total": total,
  450. })
  451. return
  452. }
  453. //处方详情
  454. func (this *PharmacyController) PrescriptionDetails() {
  455. var err error
  456. defer func() {
  457. if rec := recover(); rec != nil {
  458. err = fmt.Errorf("程序异常:%v", rec)
  459. }
  460. if err != nil {
  461. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  462. }
  463. }()
  464. //患者姓名
  465. patient_id, _ := this.GetInt64("patient_id", 0)
  466. //发药时间
  467. record_date, _ := this.GetInt64("record_date", 0)
  468. orgid := this.GetAdminUserInfo().CurrentOrgId
  469. if record_date == 0 || patient_id == 0 {
  470. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  471. return
  472. }
  473. var list []*models.PrescripDetails
  474. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  475. if err != nil {
  476. utils.ErrorLog(err.Error())
  477. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  478. return
  479. }
  480. this.ServeSuccessJSON(map[string]interface{}{
  481. "list": list,
  482. })
  483. return
  484. }
  485. //已发药品的信息
  486. func (this *PharmacyController) DispenseMedicine() {
  487. var err error
  488. defer func() {
  489. if rec := recover(); rec != nil {
  490. err = fmt.Errorf("程序异常:%v", rec)
  491. }
  492. if err != nil {
  493. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  494. }
  495. }()
  496. keyword := this.GetString("keyword", "")
  497. times := this.GetString("time", "")
  498. orgid := this.GetAdminUserInfo().CurrentOrgId
  499. timeLayout := "2006-01-02"
  500. loc, _ := time.LoadLocation("Local")
  501. deliveryway := this.GetString("deliveryway", "")
  502. var stime, etime int64
  503. if times == "" {
  504. stime, etime = service.GetNowTime()
  505. } else {
  506. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  507. stime = stmp.Unix()
  508. etime = stime + 86399
  509. }
  510. //查询表里当天的数据
  511. var flist []*models.ListOfDrugs
  512. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  513. if err != nil {
  514. utils.ErrorLog(err.Error())
  515. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  516. return
  517. }
  518. llist, err := service.Administration(deliveryway, orgid, flist)
  519. if err != nil {
  520. utils.ErrorLog(err.Error())
  521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  522. return
  523. }
  524. this.ServeSuccessJSON(map[string]interface{}{
  525. "list": llist,
  526. })
  527. return
  528. }
  529. //待发药的药品信息
  530. func (this *PharmacyController) WaitingMedicine() {
  531. var err error
  532. defer func() {
  533. if rec := recover(); rec != nil {
  534. err = fmt.Errorf("程序异常:%v", rec)
  535. }
  536. if err != nil {
  537. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  538. }
  539. }()
  540. keyword := this.GetString("keyword", "")
  541. times := this.GetString("time", "")
  542. orgid := this.GetAdminUserInfo().CurrentOrgId
  543. timeLayout := "2006-01-02"
  544. loc, _ := time.LoadLocation("Local")
  545. deliveryway := this.GetString("deliveryway", "")
  546. var stime, etime int64
  547. if times == "" {
  548. stime, etime = service.GetNowTime()
  549. } else {
  550. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  551. stime = stmp.Unix()
  552. etime = stime + 86399
  553. }
  554. //查询表里当天的数据
  555. var flist []*models.ListOfDrugs
  556. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  557. if err != nil {
  558. utils.ErrorLog(err.Error())
  559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  560. return
  561. }
  562. llist, err := service.Administration(deliveryway, orgid, flist)
  563. if err != nil {
  564. utils.ErrorLog(err.Error())
  565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  566. return
  567. }
  568. this.ServeSuccessJSON(map[string]interface{}{
  569. "list": llist,
  570. })
  571. return
  572. }
  573. //获取药品的所有患者信息
  574. func (this *PharmacyController) GetPatientsWithDrugs() {
  575. var err error
  576. defer func() {
  577. if rec := recover(); rec != nil {
  578. err = fmt.Errorf("程序异常:%v", rec)
  579. }
  580. if err != nil {
  581. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  582. }
  583. }()
  584. drug_id, _ := this.GetInt64("drug_id", 0)
  585. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  586. times := this.GetString("time", "")
  587. orgid := this.GetAdminUserInfo().CurrentOrgId
  588. deliveryway := this.GetString("deliveryway", "")
  589. if deliveryway == "" {
  590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  591. return
  592. }
  593. shift, err := this.GetInt64("shift", 0) //班次
  594. if err != nil {
  595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  596. return
  597. }
  598. partition, err := this.GetInt64("partition", 0) //分区
  599. if err != nil {
  600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  601. return
  602. }
  603. timeLayout := "2006-01-02"
  604. loc, _ := time.LoadLocation("Local")
  605. var stime, etime int64
  606. if times == "" {
  607. stime, etime = service.GetNowTime()
  608. } else {
  609. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  610. stime = stmp.Unix()
  611. etime = stime + 86399
  612. }
  613. var list []*models.PatientInformation
  614. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  615. if err != nil {
  616. utils.ErrorLog(err.Error())
  617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  618. return
  619. }
  620. listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
  621. if err != nil {
  622. utils.ErrorLog(err.Error())
  623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  624. return
  625. }
  626. total, err := service.CalculateTheTotalAmount(listll, drug_id)
  627. if err != nil {
  628. utils.ErrorLog(err.Error())
  629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  630. return
  631. }
  632. this.ServeSuccessJSON(map[string]interface{}{
  633. "list": listll,
  634. "total": total,
  635. })
  636. return
  637. }
  638. //药品管理发药按钮点击
  639. func (this *PharmacyController) MedicineDeparture() {
  640. var err error
  641. defer func() {
  642. if rec := recover(); rec != nil {
  643. err = fmt.Errorf("程序异常:%v", rec)
  644. }
  645. if err != nil {
  646. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  647. }
  648. }()
  649. creater, _ := this.GetInt64("creater", 0) //领药人
  650. ids := this.GetString("ids", "") //发药的数据
  651. orgid := this.GetAdminUserInfo().CurrentOrgId
  652. if ids == "" {
  653. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  654. return
  655. }
  656. err = service.MedicineDeparture(ids, creater, orgid)
  657. if err != nil {
  658. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  659. return
  660. }
  661. this.ServeSuccessJSON(map[string]interface{}{
  662. "list": "修改成功",
  663. })
  664. return
  665. }
  666. func (this *PharmacyController) GetPartitionList() {
  667. var err error
  668. defer func() {
  669. if rec := recover(); rec != nil {
  670. err = fmt.Errorf("程序异常:%v", rec)
  671. }
  672. if err != nil {
  673. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  674. }
  675. }()
  676. orgid := this.GetAdminUserInfo().CurrentOrgId
  677. tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
  678. list, err := service.GetAllValidDeviceZones02(orgid)
  679. if err != nil {
  680. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  681. return
  682. }
  683. this.ServeSuccessJSON(map[string]interface{}{
  684. "list": append(tmp, list...),
  685. })
  686. return
  687. }
  688. func (this *PharmacyController) RouteOfAdministration() {
  689. var err error
  690. defer func() {
  691. if rec := recover(); rec != nil {
  692. err = fmt.Errorf("程序异常:%v", rec)
  693. }
  694. if err != nil {
  695. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  696. }
  697. }()
  698. orgid := this.GetAdminUserInfo().CurrentOrgId
  699. tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
  700. list, _, err := service.GetDrugWayDics(orgid)
  701. if err != nil {
  702. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  703. return
  704. }
  705. this.ServeSuccessJSON(map[string]interface{}{
  706. "list": append(tmp, list...),
  707. })
  708. return
  709. }