pharmacy_controller.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. func (this *PharmacyController) Tlili() {
  33. var err error
  34. defer func() {
  35. if rec := recover(); rec != nil {
  36. err = fmt.Errorf("程序异常:%v", rec)
  37. }
  38. if err != nil {
  39. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  40. }
  41. }()
  42. var list2 []*models.ReplacementDrugs
  43. list2, err = service.ReplacementDrugs(9675, false)
  44. if err != nil {
  45. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  46. return
  47. }
  48. this.ServeSuccessJSON(map[string]interface{}{
  49. "list": list2,
  50. })
  51. return
  52. }
  53. func (this *PharmacyController) GetCurrentName() {
  54. create := this.GetAdminUserInfo().AdminUser.Id
  55. this.ServeSuccessJSON(map[string]interface{}{
  56. "list": create,
  57. })
  58. return
  59. }
  60. //查询今天的待发药,已发药人数
  61. func (this *PharmacyController) TodayNumber() {
  62. var err error
  63. defer func() {
  64. if rec := recover(); rec != nil {
  65. err = fmt.Errorf("程序异常:%v", rec)
  66. }
  67. if err != nil {
  68. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  69. }
  70. }()
  71. orgid := this.GetAdminUserInfo().CurrentOrgId
  72. times := this.GetString("time", "")
  73. timeLayout := "2006-01-02"
  74. loc, _ := time.LoadLocation("Local")
  75. var stime, etime int64
  76. if times == "" {
  77. stime, etime = service.GetNowTime()
  78. } else {
  79. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  80. stime = stmp.Unix()
  81. etime = stime + 86399
  82. }
  83. //查询表里当天的数据
  84. var wtotal int
  85. wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
  86. if err != nil {
  87. utils.ErrorLog(err.Error())
  88. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  89. return
  90. }
  91. var itotal int
  92. itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
  93. if err != nil {
  94. utils.ErrorLog(err.Error())
  95. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  96. return
  97. }
  98. this.ServeSuccessJSON(map[string]interface{}{
  99. "wtotal": wtotal,
  100. "itotal": itotal,
  101. })
  102. return
  103. }
  104. func (this *PharmacyController) IssuedDrug() {
  105. var err error
  106. defer func() {
  107. if rec := recover(); rec != nil {
  108. err = fmt.Errorf("程序异常:%v", rec)
  109. }
  110. if err != nil {
  111. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  112. }
  113. }()
  114. keyword := this.GetString("keyword", "")
  115. times := this.GetString("time", "")
  116. orgid := this.GetAdminUserInfo().CurrentOrgId
  117. timeLayout := "2006-01-02"
  118. loc, _ := time.LoadLocation("Local")
  119. var stime, etime int64
  120. if times == "" {
  121. stime, etime = service.GetNowTime()
  122. } else {
  123. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  124. stime = stmp.Unix()
  125. etime = stime + 86399
  126. }
  127. //查询表里当天的数据
  128. var flist []*models.TmpPatient
  129. flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  130. if err != nil {
  131. utils.ErrorLog(err.Error())
  132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  133. return
  134. }
  135. this.ServeSuccessJSON(map[string]interface{}{
  136. "list": flist,
  137. })
  138. return
  139. }
  140. func (this *PharmacyController) WaitingDrug() {
  141. var err error
  142. defer func() {
  143. if rec := recover(); rec != nil {
  144. err = fmt.Errorf("程序异常:%v", rec)
  145. }
  146. if err != nil {
  147. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  148. }
  149. }()
  150. keyword := this.GetString("keyword", "")
  151. times := this.GetString("time", "")
  152. orgid := this.GetAdminUserInfo().CurrentOrgId
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. var stime, etime int64
  156. if times == "" {
  157. stime, etime = service.GetNowTime()
  158. } else {
  159. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  160. stime = stmp.Unix()
  161. etime = stime + 86399
  162. }
  163. //查询表里当天的数据
  164. var flist []*models.TmpPatient
  165. flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
  166. if err != nil {
  167. utils.ErrorLog(err.Error())
  168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  169. return
  170. }
  171. this.ServeSuccessJSON(map[string]interface{}{
  172. "list": flist,
  173. })
  174. return
  175. }
  176. //
  177. func (this *PharmacyController) GetPharmacyContent() {
  178. var err error
  179. defer func() {
  180. if rec := recover(); rec != nil {
  181. err = fmt.Errorf("程序异常:%v", rec)
  182. }
  183. if err != nil {
  184. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  185. }
  186. }()
  187. patient_id, _ := this.GetInt64("patient_id", 0)
  188. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  189. times := this.GetString("time", "")
  190. orgid := this.GetAdminUserInfo().CurrentOrgId
  191. timeLayout := "2006-01-02"
  192. loc, _ := time.LoadLocation("Local")
  193. var stime, etime int64
  194. if times == "" {
  195. stime, etime = service.GetNowTime()
  196. } else {
  197. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  198. stime = stmp.Unix()
  199. etime = stime + 86399
  200. }
  201. var list []*models.PharmacyContent
  202. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  203. if err != nil {
  204. utils.ErrorLog(err.Error())
  205. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  206. return
  207. }
  208. return_value := make(map[string]interface{})
  209. return_value["list"] = list
  210. //if is_medicine == 1{发药时间先不展示
  211. // return_value["time"] = time
  212. //}
  213. this.ServeSuccessJSON(return_value)
  214. return
  215. }
  216. //发药按钮点击
  217. func (this *PharmacyController) DispensingMedicine() {
  218. var err error
  219. defer func() {
  220. if rec := recover(); rec != nil {
  221. err = fmt.Errorf("程序异常:%v", rec)
  222. }
  223. if err != nil {
  224. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  225. }
  226. }()
  227. patient_id, _ := this.GetInt64("patient_id", 0)
  228. times := this.GetString("time", "")
  229. orgid := this.GetAdminUserInfo().CurrentOrgId
  230. creater := this.GetAdminUserInfo().AdminUser.Id
  231. timeLayout := "2006-01-02"
  232. loc, _ := time.LoadLocation("Local")
  233. var stime, etime int64
  234. if times == "" {
  235. stime, etime = service.GetNowTime()
  236. } else {
  237. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  238. stime = stmp.Unix()
  239. etime = stime + 86399
  240. }
  241. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  242. if err != nil {
  243. utils.ErrorLog(err.Error())
  244. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  245. return
  246. }
  247. this.ServeSuccessJSON(map[string]interface{}{
  248. "list": "操作成功",
  249. })
  250. return
  251. }
  252. //退药按钮点击
  253. func (this *PharmacyController) DrugWithdrawal() {
  254. var err error
  255. defer func() {
  256. if rec := recover(); rec != nil {
  257. err = fmt.Errorf("程序异常:%v", rec)
  258. }
  259. if err != nil {
  260. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  261. }
  262. }()
  263. patient_id, _ := this.GetInt64("patient_id", 0)
  264. times := this.GetString("time", "")
  265. orgid := this.GetAdminUserInfo().CurrentOrgId
  266. creater := this.GetAdminUserInfo().AdminUser.Id
  267. timeLayout := "2006-01-02"
  268. loc, _ := time.LoadLocation("Local")
  269. var stime, etime int64
  270. if times == "" {
  271. stime, etime = service.GetNowTime()
  272. } else {
  273. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  274. stime = stmp.Unix()
  275. etime = stime + 86399
  276. }
  277. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  278. if err != nil {
  279. utils.ErrorLog(err.Error())
  280. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  281. return
  282. }
  283. this.ServeSuccessJSON(map[string]interface{}{
  284. "list": "操作成功",
  285. })
  286. return
  287. }
  288. //发药明细列表
  289. func (this *PharmacyController) DispensingDetails() {
  290. var err error
  291. defer func() {
  292. if rec := recover(); rec != nil {
  293. err = fmt.Errorf("程序异常:%v", rec)
  294. }
  295. if err != nil {
  296. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  297. }
  298. }()
  299. keyword := this.GetString("keyword", "") //患者名称
  300. start_time := this.GetString("start_time", "") //开始时间
  301. end_time := this.GetString("end_time", "") //结束时间
  302. page, _ := this.GetInt64("page", 1) //页码
  303. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  304. orgid := this.GetAdminUserInfo().CurrentOrgId
  305. timeLayout := "2006-01-02"
  306. loc, _ := time.LoadLocation("Local")
  307. var stime, etime int64
  308. if start_time == "" {
  309. stime = 1
  310. } else {
  311. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  312. stime = stmp.Unix()
  313. }
  314. if end_time == "" {
  315. _, etime = service.GetNowTime()
  316. } else {
  317. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  318. etime = etmp.Unix()
  319. }
  320. var dislist []*models.DispensingList
  321. var total int64
  322. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  323. if err != nil {
  324. utils.ErrorLog(err.Error())
  325. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  326. return
  327. }
  328. this.ServeSuccessJSON(map[string]interface{}{
  329. "list": dislist,
  330. "total": total,
  331. })
  332. return
  333. }
  334. //处方详情
  335. func (this *PharmacyController) PrescriptionDetails() {
  336. var err error
  337. defer func() {
  338. if rec := recover(); rec != nil {
  339. err = fmt.Errorf("程序异常:%v", rec)
  340. }
  341. if err != nil {
  342. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  343. }
  344. }()
  345. //患者姓名
  346. patient_id, _ := this.GetInt64("patient_id", 0)
  347. //发药时间
  348. record_date, _ := this.GetInt64("record_date", 0)
  349. orgid := this.GetAdminUserInfo().CurrentOrgId
  350. if record_date == 0 || patient_id == 0 {
  351. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  352. return
  353. }
  354. var list []*models.PrescripDetails
  355. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  356. if err != nil {
  357. utils.ErrorLog(err.Error())
  358. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  359. return
  360. }
  361. this.ServeSuccessJSON(map[string]interface{}{
  362. "list": list,
  363. })
  364. return
  365. }
  366. //已发药品的信息
  367. func (this *PharmacyController) DispenseMedicine() {
  368. var err error
  369. defer func() {
  370. if rec := recover(); rec != nil {
  371. err = fmt.Errorf("程序异常:%v", rec)
  372. }
  373. if err != nil {
  374. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  375. }
  376. }()
  377. keyword := this.GetString("keyword", "")
  378. times := this.GetString("time", "")
  379. orgid := this.GetAdminUserInfo().CurrentOrgId
  380. timeLayout := "2006-01-02"
  381. loc, _ := time.LoadLocation("Local")
  382. var stime, etime int64
  383. if times == "" {
  384. stime, etime = service.GetNowTime()
  385. } else {
  386. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  387. stime = stmp.Unix()
  388. etime = stime + 86399
  389. }
  390. //查询表里当天的数据
  391. var flist []*models.ListOfDrugs
  392. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  393. if err != nil {
  394. utils.ErrorLog(err.Error())
  395. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  396. return
  397. }
  398. this.ServeSuccessJSON(map[string]interface{}{
  399. "list": flist,
  400. })
  401. return
  402. }
  403. //待发药的药品信息
  404. func (this *PharmacyController) WaitingMedicine() {
  405. var err error
  406. defer func() {
  407. if rec := recover(); rec != nil {
  408. err = fmt.Errorf("程序异常:%v", rec)
  409. }
  410. if err != nil {
  411. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  412. }
  413. }()
  414. keyword := this.GetString("keyword", "")
  415. times := this.GetString("time", "")
  416. orgid := this.GetAdminUserInfo().CurrentOrgId
  417. timeLayout := "2006-01-02"
  418. loc, _ := time.LoadLocation("Local")
  419. var stime, etime int64
  420. if times == "" {
  421. stime, etime = service.GetNowTime()
  422. } else {
  423. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  424. stime = stmp.Unix()
  425. etime = stime + 86399
  426. }
  427. //查询表里当天的数据
  428. var flist []*models.ListOfDrugs
  429. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  430. if err != nil {
  431. utils.ErrorLog(err.Error())
  432. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  433. return
  434. }
  435. this.ServeSuccessJSON(map[string]interface{}{
  436. "list": flist,
  437. })
  438. return
  439. }
  440. //获取药品的所有患者信息
  441. func (this *PharmacyController) GetPatientsWithDrugs() {
  442. var err error
  443. defer func() {
  444. if rec := recover(); rec != nil {
  445. err = fmt.Errorf("程序异常:%v", rec)
  446. }
  447. if err != nil {
  448. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  449. }
  450. }()
  451. drug_id, _ := this.GetInt64("drug_id", 0)
  452. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  453. times := this.GetString("time", "")
  454. orgid := this.GetAdminUserInfo().CurrentOrgId
  455. timeLayout := "2006-01-02"
  456. loc, _ := time.LoadLocation("Local")
  457. var stime, etime int64
  458. if times == "" {
  459. stime, etime = service.GetNowTime()
  460. } else {
  461. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  462. stime = stmp.Unix()
  463. etime = stime + 86399
  464. }
  465. var list []*models.PatientInformation
  466. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  467. if err != nil {
  468. utils.ErrorLog(err.Error())
  469. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  470. return
  471. }
  472. this.ServeSuccessJSON(map[string]interface{}{
  473. "list": list,
  474. })
  475. return
  476. }
  477. //药品管理发药按钮点击
  478. func (this *PharmacyController) MedicineDeparture() {
  479. var err error
  480. defer func() {
  481. if rec := recover(); rec != nil {
  482. err = fmt.Errorf("程序异常:%v", rec)
  483. }
  484. if err != nil {
  485. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  486. }
  487. }()
  488. creater, _ := this.GetInt64("creater", 0) //领药人
  489. ids := this.GetString("ids", "") //发药的数据
  490. orgid := this.GetAdminUserInfo().CurrentOrgId
  491. if ids == "" {
  492. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  493. return
  494. }
  495. err = service.MedicineDeparture(ids, creater, orgid)
  496. if err != nil {
  497. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  498. return
  499. }
  500. this.ServeSuccessJSON(map[string]interface{}{
  501. "list": "修改成功",
  502. })
  503. return
  504. }
  505. func (this *PharmacyController) GetPartitionList() {
  506. var err error
  507. defer func() {
  508. if rec := recover(); rec != nil {
  509. err = fmt.Errorf("程序异常:%v", rec)
  510. }
  511. if err != nil {
  512. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  513. }
  514. }()
  515. orgid := this.GetAdminUserInfo().CurrentOrgId
  516. list, err := service.GetAllValidDeviceZones(orgid)
  517. if err != nil {
  518. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  519. return
  520. }
  521. this.ServeSuccessJSON(map[string]interface{}{
  522. "list": list,
  523. })
  524. return
  525. }
  526. func (this *PharmacyController) RouteOfAdministration() {
  527. var err error
  528. defer func() {
  529. if rec := recover(); rec != nil {
  530. err = fmt.Errorf("程序异常:%v", rec)
  531. }
  532. if err != nil {
  533. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  534. }
  535. }()
  536. orgid := this.GetAdminUserInfo().CurrentOrgId
  537. list, _, err := service.GetDrugWayDics(orgid)
  538. if err != nil {
  539. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  540. return
  541. }
  542. this.ServeSuccessJSON(map[string]interface{}{
  543. "list": list,
  544. })
  545. return
  546. }