pharmacy_controller.go 20KB

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