pharmacy_controller.go 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "github.com/astaxie/beego"
  8. "time"
  9. )
  10. type PharmacyController struct {
  11. BaseAuthAPIController
  12. }
  13. func PharmacyApiRegistRouters() {
  14. beego.Router("/api/pharmacy/ceshili", &PharmacyController{}, "get:Tlili")
  15. beego.Router("/api/pharmacy/todaynumber", &PharmacyController{}, "get:TodayNumber") //查询今天的待发药,已发药人数(
  16. beego.Router("/api/pharmacy/waitingdrug", &PharmacyController{}, "get:WaitingDrug") //获取当天待发药的所有患者(
  17. beego.Router("/api/pharmacy/issueddrugs", &PharmacyController{}, "get:IssuedDrug") //获取当天已发药的所有患者(
  18. beego.Router("/api/pharmacy/getpharmacycontent", &PharmacyController{}, "get:GetPharmacyContent") //获取当天该患者的所有信息(
  19. beego.Router("/api/pharmacy/dispensingmedicine", &PharmacyController{}, "get:DispensingMedicine") //患者发药按钮点击(
  20. beego.Router("/api/pharmacy/drugwithdrawal", &PharmacyController{}, "get:DrugWithdrawal") //退药按钮点击
  21. beego.Router("/api/pharmacy/dispensingdetails", &PharmacyController{}, "get:DispensingDetails") //获取发药明细的患者列表(
  22. beego.Router("/api/pharmacy/prescriptiondetails", &PharmacyController{}, "get:PrescriptionDetails") //发药明细-详情(
  23. beego.Router("/api/pharmacy/dispensemedicine", &PharmacyController{}, "get:DispenseMedicine") //获取当天已发药的药品(
  24. beego.Router("/api/pharmacy/waitingmedicine", &PharmacyController{}, "get:WaitingMedicine") //获取当天待发药的药品(
  25. beego.Router("/api/pharmacy/getpatientswithdrugs", &PharmacyController{}, "get:GetPatientsWithDrugs") //获取当天该药品的所有患者(
  26. beego.Router("/api/pharmacy/medicinedeparture", &PharmacyController{}, "get:MedicineDeparture") //药品发药按钮点击(
  27. beego.Router("/api/pharmacy/getcurrentname", &PharmacyController{}, "get:GetCurrentName") //获取当前登录账号的名字(
  28. }
  29. func (this *PharmacyController) Tlili() {
  30. times := this.GetString("time", "")
  31. timeLayout := "2006-01-02"
  32. loc, _ := time.LoadLocation("Local")
  33. var stime, etime int64
  34. if times == "" {
  35. stime, etime = service.GetNowTime()
  36. } else {
  37. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  38. stime = stmp.Unix()
  39. etime = stime + 86399
  40. }
  41. orgid := this.GetAdminUserInfo().CurrentOrgId
  42. service.InitDrugidIsNil(orgid, stime, etime)
  43. this.ServeSuccessJSON(map[string]interface{}{
  44. "list": "err",
  45. })
  46. return
  47. }
  48. func (this *PharmacyController) GetCurrentName() {
  49. create := this.GetAdminUserInfo().AdminUser.Id
  50. this.ServeSuccessJSON(map[string]interface{}{
  51. "list": create,
  52. })
  53. return
  54. }
  55. //查询今天的待发药,已发药人数
  56. func (this *PharmacyController) TodayNumber() {
  57. var err error
  58. defer func() {
  59. if err != nil {
  60. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  61. }
  62. }()
  63. orgid := this.GetAdminUserInfo().CurrentOrgId
  64. times := this.GetString("time", "")
  65. timeLayout := "2006-01-02"
  66. loc, _ := time.LoadLocation("Local")
  67. var stime, etime int64
  68. if times == "" {
  69. stime, etime = service.GetNowTime()
  70. } else {
  71. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  72. stime = stmp.Unix()
  73. etime = stime + 86399
  74. }
  75. //查询表里当天的数据
  76. var wtotal int
  77. wtotal, err = service.GetTodayPharmacy(stime, etime, orgid, 1)
  78. if err != nil {
  79. utils.ErrorLog(err.Error())
  80. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  81. return
  82. }
  83. var itotal int
  84. itotal, err = service.GetTodayPharmacy(stime, etime, orgid, 0)
  85. if err != nil {
  86. utils.ErrorLog(err.Error())
  87. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  88. return
  89. }
  90. this.ServeSuccessJSON(map[string]interface{}{
  91. "wtotal": wtotal,
  92. "itotal": itotal,
  93. })
  94. return
  95. }
  96. func (this *PharmacyController) IssuedDrug() {
  97. var err error
  98. defer func() {
  99. if err != nil {
  100. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  101. }
  102. }()
  103. keyword := this.GetString("keyword", "")
  104. times := this.GetString("time", "")
  105. orgid := this.GetAdminUserInfo().CurrentOrgId
  106. timeLayout := "2006-01-02"
  107. loc, _ := time.LoadLocation("Local")
  108. var stime, etime int64
  109. if times == "" {
  110. stime, etime = service.GetNowTime()
  111. } else {
  112. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  113. stime = stmp.Unix()
  114. etime = stime + 86399
  115. }
  116. //查询表里当天的数据
  117. var flist []*models.TmpPatient
  118. flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  119. if err != nil {
  120. utils.ErrorLog(err.Error())
  121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  122. return
  123. }
  124. this.ServeSuccessJSON(map[string]interface{}{
  125. "list": flist,
  126. })
  127. return
  128. }
  129. func (this *PharmacyController) WaitingDrug() {
  130. var err error
  131. defer func() {
  132. if err != nil {
  133. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  134. }
  135. }()
  136. keyword := this.GetString("keyword", "")
  137. times := this.GetString("time", "")
  138. orgid := this.GetAdminUserInfo().CurrentOrgId
  139. timeLayout := "2006-01-02"
  140. loc, _ := time.LoadLocation("Local")
  141. var stime, etime int64
  142. if times == "" {
  143. stime, etime = service.GetNowTime()
  144. } else {
  145. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  146. stime = stmp.Unix()
  147. etime = stime + 86399
  148. }
  149. //查询表里当天的数据
  150. var flist []*models.TmpPatient
  151. flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
  152. if err != nil {
  153. utils.ErrorLog(err.Error())
  154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. this.ServeSuccessJSON(map[string]interface{}{
  158. "list": flist,
  159. })
  160. return
  161. }
  162. //
  163. func (this *PharmacyController) GetPharmacyContent() {
  164. var err error
  165. defer func() {
  166. if err != nil {
  167. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  168. }
  169. }()
  170. patient_id, _ := this.GetInt64("patient_id", 0)
  171. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  172. times := this.GetString("time", "")
  173. orgid := this.GetAdminUserInfo().CurrentOrgId
  174. timeLayout := "2006-01-02"
  175. loc, _ := time.LoadLocation("Local")
  176. var stime, etime int64
  177. if times == "" {
  178. stime, etime = service.GetNowTime()
  179. } else {
  180. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  181. stime = stmp.Unix()
  182. etime = stime + 86399
  183. }
  184. var list []*models.PharmacyContent
  185. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  186. if err != nil {
  187. utils.ErrorLog(err.Error())
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. return_value := make(map[string]interface{})
  192. return_value["list"] = list
  193. //if is_medicine == 1{发药时间先不展示
  194. // return_value["time"] = time
  195. //}
  196. this.ServeSuccessJSON(return_value)
  197. return
  198. }
  199. //发药按钮点击
  200. func (this *PharmacyController) DispensingMedicine() {
  201. var err error
  202. defer func() {
  203. if err != nil {
  204. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  205. }
  206. }()
  207. patient_id, _ := this.GetInt64("patient_id", 0)
  208. times := this.GetString("time", "")
  209. orgid := this.GetAdminUserInfo().CurrentOrgId
  210. creater := this.GetAdminUserInfo().AdminUser.Id
  211. timeLayout := "2006-01-02"
  212. loc, _ := time.LoadLocation("Local")
  213. var stime, etime int64
  214. if times == "" {
  215. stime, etime = service.GetNowTime()
  216. } else {
  217. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  218. stime = stmp.Unix()
  219. etime = stime + 86399
  220. }
  221. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  222. if err != nil {
  223. utils.ErrorLog(err.Error())
  224. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  225. return
  226. }
  227. this.ServeSuccessJSON(map[string]interface{}{
  228. "list": "操作成功",
  229. })
  230. return
  231. }
  232. //退药按钮点击
  233. func (this *PharmacyController) DrugWithdrawal() {
  234. var err error
  235. defer func() {
  236. if err != nil {
  237. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  238. }
  239. }()
  240. patient_id, _ := this.GetInt64("patient_id", 0)
  241. times := this.GetString("time", "")
  242. orgid := this.GetAdminUserInfo().CurrentOrgId
  243. creater := this.GetAdminUserInfo().AdminUser.Id
  244. timeLayout := "2006-01-02"
  245. loc, _ := time.LoadLocation("Local")
  246. var stime, etime int64
  247. if times == "" {
  248. stime, etime = service.GetNowTime()
  249. } else {
  250. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  251. stime = stmp.Unix()
  252. etime = stime + 86399
  253. }
  254. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  255. if err != nil {
  256. utils.ErrorLog(err.Error())
  257. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  258. return
  259. }
  260. this.ServeSuccessJSON(map[string]interface{}{
  261. "list": "操作成功",
  262. })
  263. return
  264. }
  265. //发药明细列表
  266. func (this *PharmacyController) DispensingDetails() {
  267. var err error
  268. defer func() {
  269. if err != nil {
  270. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  271. }
  272. }()
  273. keyword := this.GetString("keyword", "") //患者名称
  274. start_time := this.GetString("start_time", "") //开始时间
  275. end_time := this.GetString("end_time", "") //结束时间
  276. page, _ := this.GetInt64("page", 1) //页码
  277. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  278. orgid := this.GetAdminUserInfo().CurrentOrgId
  279. timeLayout := "2006-01-02"
  280. loc, _ := time.LoadLocation("Local")
  281. var stime, etime int64
  282. if start_time == "" {
  283. stime = 1
  284. } else {
  285. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  286. stime = stmp.Unix()
  287. }
  288. if end_time == "" {
  289. _, etime = service.GetNowTime()
  290. } else {
  291. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  292. etime = etmp.Unix()
  293. }
  294. var dislist []*models.DispensingList
  295. var total int64
  296. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  297. if err != nil {
  298. utils.ErrorLog(err.Error())
  299. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  300. return
  301. }
  302. this.ServeSuccessJSON(map[string]interface{}{
  303. "list": dislist,
  304. "total": total,
  305. })
  306. return
  307. }
  308. //处方详情
  309. func (this *PharmacyController) PrescriptionDetails() {
  310. var err error
  311. defer func() {
  312. if err != nil {
  313. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  314. }
  315. }()
  316. //患者姓名
  317. patient_id, _ := this.GetInt64("patient_id", 0)
  318. //发药时间
  319. record_date, _ := this.GetInt64("record_date", 0)
  320. orgid := this.GetAdminUserInfo().CurrentOrgId
  321. if record_date == 0 || patient_id == 0 {
  322. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  323. return
  324. }
  325. var list []*models.PrescripDetails
  326. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  327. if err != nil {
  328. utils.ErrorLog(err.Error())
  329. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  330. return
  331. }
  332. this.ServeSuccessJSON(map[string]interface{}{
  333. "list": list,
  334. })
  335. return
  336. }
  337. //已发药品的信息
  338. func (this *PharmacyController) DispenseMedicine() {
  339. var err error
  340. defer func() {
  341. if err != nil {
  342. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  343. }
  344. }()
  345. keyword := this.GetString("keyword", "")
  346. times := this.GetString("time", "")
  347. orgid := this.GetAdminUserInfo().CurrentOrgId
  348. timeLayout := "2006-01-02"
  349. loc, _ := time.LoadLocation("Local")
  350. var stime, etime int64
  351. if times == "" {
  352. stime, etime = service.GetNowTime()
  353. } else {
  354. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  355. stime = stmp.Unix()
  356. etime = stime + 86399
  357. }
  358. //查询表里当天的数据
  359. var flist []*models.ListOfDrugs
  360. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  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": flist,
  368. })
  369. return
  370. }
  371. //待发药的药品信息
  372. func (this *PharmacyController) WaitingMedicine() {
  373. var err error
  374. defer func() {
  375. if err != nil {
  376. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  377. }
  378. }()
  379. keyword := this.GetString("keyword", "")
  380. times := this.GetString("time", "")
  381. orgid := this.GetAdminUserInfo().CurrentOrgId
  382. timeLayout := "2006-01-02"
  383. loc, _ := time.LoadLocation("Local")
  384. var stime, etime int64
  385. if times == "" {
  386. stime, etime = service.GetNowTime()
  387. } else {
  388. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  389. stime = stmp.Unix()
  390. etime = stime + 86399
  391. }
  392. //查询表里当天的数据
  393. var flist []*models.ListOfDrugs
  394. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  395. if err != nil {
  396. utils.ErrorLog(err.Error())
  397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  398. return
  399. }
  400. this.ServeSuccessJSON(map[string]interface{}{
  401. "list": flist,
  402. })
  403. return
  404. }
  405. //获取药品的所有患者信息
  406. func (this *PharmacyController) GetPatientsWithDrugs() {
  407. var err error
  408. defer func() {
  409. if err != nil {
  410. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  411. }
  412. }()
  413. drug_id, _ := this.GetInt64("drug_id", 0)
  414. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  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. var list []*models.PatientInformation
  428. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  429. if err != nil {
  430. utils.ErrorLog(err.Error())
  431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  432. return
  433. }
  434. this.ServeSuccessJSON(map[string]interface{}{
  435. "list": list,
  436. })
  437. return
  438. }
  439. //药品管理发药按钮点击
  440. func (this *PharmacyController) MedicineDeparture() {
  441. var err error
  442. defer func() {
  443. if err != nil {
  444. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  445. }
  446. }()
  447. creater, _ := this.GetInt64("creater", 0) //领药人
  448. ids := this.GetString("ids", "") //发药的数据
  449. orgid := this.GetAdminUserInfo().CurrentOrgId
  450. if ids == "" {
  451. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  452. return
  453. }
  454. err = service.MedicineDeparture(ids, creater, orgid)
  455. if err != nil {
  456. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  457. return
  458. }
  459. this.ServeSuccessJSON(map[string]interface{}{
  460. "list": "修改成功",
  461. })
  462. return
  463. }