pharmacy_controller.go 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. //获取排班班次
  156. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
  157. var ids []int64
  158. for _, item := range schedule {
  159. ids = append(ids, item.PatientId)
  160. }
  161. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 1, ids)
  162. fmt.Println("list23323232323232", list)
  163. var flist []models.TmpPatientOne
  164. if len(list) > 0 {
  165. for _, item := range list {
  166. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  167. flist = append(flist, patientlist)
  168. }
  169. }
  170. this.ServeSuccessJSON(map[string]interface{}{
  171. "list": flist,
  172. })
  173. }
  174. if orgid != 10164 && orgid == 3877 && orgid != 10188 && orgid != 10217 && orgid != 9671 {
  175. //查询表里当天的数据
  176. var flist []*models.TmpPatient
  177. flist, err = service.GetTodayDrug(stime, etime, orgid, 1, keyword)
  178. if err != nil {
  179. utils.ErrorLog(err.Error())
  180. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  181. return
  182. }
  183. listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  184. if err != nil {
  185. utils.ErrorLog(err.Error())
  186. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  187. return
  188. }
  189. this.ServeSuccessJSON(map[string]interface{}{
  190. "list": listt,
  191. })
  192. return
  193. }
  194. }
  195. func (this *PharmacyController) WaitingDrug() {
  196. var err error
  197. defer func() {
  198. if rec := recover(); rec != nil {
  199. err = fmt.Errorf("程序异常:%v", rec)
  200. }
  201. if err != nil {
  202. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  203. }
  204. }()
  205. keyword := this.GetString("keyword", "")
  206. times := this.GetString("time", "")
  207. shift, err := this.GetInt64("shift", 0) //班次
  208. if err != nil {
  209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. partition, err := this.GetInt64("partition", 0) //分区
  213. if err != nil {
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  215. return
  216. }
  217. orgid := this.GetAdminUserInfo().CurrentOrgId
  218. timeLayout := "2006-01-02"
  219. loc, _ := time.LoadLocation("Local")
  220. var stime, etime int64
  221. if times == "" {
  222. stime, etime = service.GetNowTime()
  223. } else {
  224. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  225. stime = stmp.Unix()
  226. etime = stime + 86399
  227. }
  228. if orgid != 9671 && orgid != 10188 && orgid != 10217 && orgid != 3877 && orgid != 10164 {
  229. //查询表里当天的数据
  230. var flist []*models.TmpPatient
  231. flist, err = service.GetTodayDrug(stime, etime, orgid, 0, keyword)
  232. if err != nil {
  233. utils.ErrorLog(err.Error())
  234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  235. return
  236. }
  237. listt, err := service.PartitionAndLayout(stime, etime, orgid, shift, partition, flist)
  238. if err != nil {
  239. utils.ErrorLog(err.Error())
  240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  241. return
  242. }
  243. this.ServeSuccessJSON(map[string]interface{}{
  244. "list": listt,
  245. })
  246. return
  247. }
  248. //当天已发药的人数
  249. if orgid == 9671 || orgid == 10188 || orgid == 10217 || orgid == 3877 || orgid == 10164 {
  250. //获取排班班次
  251. schedule, _ := service.GetSchedulePatientId(stime, etime, orgid, shift, partition)
  252. fmt.Println("schedule--------", schedule)
  253. var ids []int64
  254. for _, item := range schedule {
  255. ids = append(ids, item.PatientId)
  256. }
  257. list, _ := service.GetTodayAdviceCountOne(stime, etime, orgid, 0, ids)
  258. var flist []models.TmpPatientOne
  259. if len(list) > 0 {
  260. for _, item := range list {
  261. patientlist, _ := service.GetPatientByAdviceId(item.PatientId)
  262. flist = append(flist, patientlist)
  263. }
  264. }
  265. this.ServeSuccessJSON(map[string]interface{}{
  266. "list": flist,
  267. })
  268. return
  269. }
  270. }
  271. func (this *PharmacyController) GetPharmacyContent() {
  272. var err error
  273. defer func() {
  274. if rec := recover(); rec != nil {
  275. err = fmt.Errorf("程序异常:%v", rec)
  276. }
  277. if err != nil {
  278. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  279. }
  280. }()
  281. patient_id, _ := this.GetInt64("patient_id", 0)
  282. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  283. times := this.GetString("time", "")
  284. orgid := this.GetAdminUserInfo().CurrentOrgId
  285. timeLayout := "2006-01-02"
  286. loc, _ := time.LoadLocation("Local")
  287. var stime, etime int64
  288. if times == "" {
  289. stime, etime = service.GetNowTime()
  290. } else {
  291. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  292. stime = stmp.Unix()
  293. etime = stime + 86399
  294. }
  295. var list []*models.PharmacyContent
  296. list, err = service.GetPatientMedication(orgid, patient_id, stime, etime, is_medicine)
  297. if err != nil {
  298. utils.ErrorLog(err.Error())
  299. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  300. return
  301. }
  302. return_value := make(map[string]interface{})
  303. return_value["list"] = list
  304. //if is_medicine == 1{发药时间先不展示
  305. // return_value["time"] = time
  306. //}
  307. this.ServeSuccessJSON(return_value)
  308. return
  309. }
  310. // 发药按钮点击
  311. func (this *PharmacyController) DispensingMedicine() {
  312. var err error
  313. defer func() {
  314. if rec := recover(); rec != nil {
  315. err = fmt.Errorf("程序异常:%v", rec)
  316. }
  317. if err != nil {
  318. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  319. }
  320. }()
  321. patient_id, _ := this.GetInt64("patient_id", 0)
  322. times := this.GetString("time", "")
  323. orgid := this.GetAdminUserInfo().CurrentOrgId
  324. creater := this.GetAdminUserInfo().AdminUser.Id
  325. timeLayout := "2006-01-02"
  326. loc, _ := time.LoadLocation("Local")
  327. var stime, etime int64
  328. if times == "" {
  329. stime, etime = service.GetNowTime()
  330. } else {
  331. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  332. stime = stmp.Unix()
  333. etime = stime + 86399
  334. }
  335. advicelist, _ := service.FindeHisAdviceDocAdvice(orgid, patient_id, stime, etime)
  336. if len(advicelist) > 0 {
  337. var total int64
  338. var prescribing_number_total int64
  339. for _, item := range advicelist {
  340. houseConfig, _ := service.GetAllStoreHouseConfig(orgid)
  341. //查询该药品是否有库存
  342. list, _ := service.GetDrugTotalCountTwenty(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  343. //查询改药品信息
  344. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  345. //判断单位是否相等
  346. if medical.MaxUnit == item.PrescribingNumberUnit {
  347. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  348. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  349. //转化为最小单位
  350. total = list.Count*medical.MinNumber + list.StockMinNumber
  351. prescribing_number_total = count * medical.MinNumber
  352. }
  353. if medical.MinUnit == item.PrescribingNumberUnit {
  354. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  355. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  356. total = list.Count*medical.MinNumber + list.StockMinNumber
  357. prescribing_number_total = count
  358. }
  359. if medical.IsUse != 1 {
  360. //如果出库数量大于库存数量
  361. if prescribing_number_total > total {
  362. err := fmt.Errorf(service.FindDrugsName(item.DrugId) + "库存不足")
  363. if err != nil {
  364. utils.ErrorLog(err.Error())
  365. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  366. return
  367. }
  368. }
  369. }
  370. }
  371. }
  372. err = service.DispensingMedicine(orgid, patient_id, stime, etime, creater)
  373. if err != nil {
  374. utils.ErrorLog(err.Error())
  375. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  376. return
  377. }
  378. this.ServeSuccessJSON(map[string]interface{}{
  379. "list": "操作成功",
  380. })
  381. return
  382. }
  383. // 退药按钮点击
  384. func (this *PharmacyController) DrugWithdrawal() {
  385. var err error
  386. defer func() {
  387. if rec := recover(); rec != nil {
  388. err = fmt.Errorf("程序异常:%v", rec)
  389. }
  390. if err != nil {
  391. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  392. }
  393. }()
  394. patient_id, _ := this.GetInt64("patient_id", 0)
  395. times := this.GetString("time", "")
  396. orgid := this.GetAdminUserInfo().CurrentOrgId
  397. creater := this.GetAdminUserInfo().AdminUser.Id
  398. timeLayout := "2006-01-02"
  399. loc, _ := time.LoadLocation("Local")
  400. var stime, etime int64
  401. if times == "" {
  402. stime, etime = service.GetNowTime()
  403. } else {
  404. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  405. stime = stmp.Unix()
  406. etime = stime + 86399
  407. }
  408. err = service.DrugWithdrawal(orgid, patient_id, stime, etime, creater)
  409. if err != nil {
  410. utils.ErrorLog(err.Error())
  411. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  412. return
  413. }
  414. this.ServeSuccessJSON(map[string]interface{}{
  415. "list": "操作成功",
  416. })
  417. return
  418. }
  419. // 发药明细列表
  420. func (this *PharmacyController) DispensingDetails() {
  421. var err error
  422. defer func() {
  423. if rec := recover(); rec != nil {
  424. err = fmt.Errorf("程序异常:%v", rec)
  425. }
  426. if err != nil {
  427. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  428. }
  429. }()
  430. keyword := this.GetString("keyword", "") //患者名称
  431. start_time := this.GetString("start_time", "") //开始时间
  432. end_time := this.GetString("end_time", "") //结束时间
  433. page, _ := this.GetInt64("page", 1) //页码
  434. limit, _ := this.GetInt64("limit", 10) //每一页查出来的条数
  435. orgid := this.GetAdminUserInfo().CurrentOrgId
  436. timeLayout := "2006-01-02"
  437. loc, _ := time.LoadLocation("Local")
  438. var stime, etime int64
  439. if start_time == "" {
  440. stime = 1
  441. } else {
  442. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  443. stime = stmp.Unix()
  444. }
  445. if end_time == "" {
  446. _, etime = service.GetNowTime()
  447. } else {
  448. etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  449. etime = etmp.Unix()
  450. }
  451. var dislist []*models.DispensingList
  452. var total int64
  453. dislist, total, err = service.DispensingDetailsList(stime, etime, orgid, page, limit, keyword)
  454. if err != nil {
  455. utils.ErrorLog(err.Error())
  456. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  457. return
  458. }
  459. this.ServeSuccessJSON(map[string]interface{}{
  460. "list": dislist,
  461. "total": total,
  462. })
  463. return
  464. }
  465. // 处方详情
  466. func (this *PharmacyController) PrescriptionDetails() {
  467. var err error
  468. defer func() {
  469. if rec := recover(); rec != nil {
  470. err = fmt.Errorf("程序异常:%v", rec)
  471. }
  472. if err != nil {
  473. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  474. }
  475. }()
  476. //患者姓名
  477. patient_id, _ := this.GetInt64("patient_id", 0)
  478. //发药时间
  479. record_date, _ := this.GetInt64("record_date", 0)
  480. orgid := this.GetAdminUserInfo().CurrentOrgId
  481. if record_date == 0 || patient_id == 0 {
  482. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  483. return
  484. }
  485. var list []*models.PrescripDetails
  486. list, err = service.PrescriptionDetails(patient_id, record_date, orgid)
  487. if err != nil {
  488. utils.ErrorLog(err.Error())
  489. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  490. return
  491. }
  492. this.ServeSuccessJSON(map[string]interface{}{
  493. "list": list,
  494. })
  495. return
  496. }
  497. // 已发药品的信息
  498. func (this *PharmacyController) DispenseMedicine() {
  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. keyword := this.GetString("keyword", "")
  509. times := this.GetString("time", "")
  510. orgid := this.GetAdminUserInfo().CurrentOrgId
  511. timeLayout := "2006-01-02"
  512. loc, _ := time.LoadLocation("Local")
  513. deliveryway := this.GetString("deliveryway", "")
  514. var stime, etime int64
  515. if times == "" {
  516. stime, etime = service.GetNowTime()
  517. } else {
  518. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  519. stime = stmp.Unix()
  520. etime = stime + 86399
  521. }
  522. //查询表里当天的数据
  523. var flist []*models.ListOfDrugs
  524. flist, err = service.GetTodayMedicine(stime, etime, orgid, 1, keyword)
  525. if err != nil {
  526. utils.ErrorLog(err.Error())
  527. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  528. return
  529. }
  530. llist, err := service.Administration(deliveryway, orgid, flist)
  531. if err != nil {
  532. utils.ErrorLog(err.Error())
  533. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  534. return
  535. }
  536. this.ServeSuccessJSON(map[string]interface{}{
  537. "list": llist,
  538. })
  539. return
  540. }
  541. // 待发药的药品信息
  542. func (this *PharmacyController) WaitingMedicine() {
  543. var err error
  544. defer func() {
  545. if rec := recover(); rec != nil {
  546. err = fmt.Errorf("程序异常:%v", rec)
  547. }
  548. if err != nil {
  549. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  550. }
  551. }()
  552. keyword := this.GetString("keyword", "")
  553. times := this.GetString("time", "")
  554. orgid := this.GetAdminUserInfo().CurrentOrgId
  555. timeLayout := "2006-01-02"
  556. loc, _ := time.LoadLocation("Local")
  557. deliveryway := this.GetString("deliveryway", "")
  558. var stime, etime int64
  559. if times == "" {
  560. stime, etime = service.GetNowTime()
  561. } else {
  562. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  563. stime = stmp.Unix()
  564. etime = stime + 86399
  565. }
  566. //查询表里当天的数据
  567. var flist []*models.ListOfDrugs
  568. flist, err = service.GetTodayMedicine(stime, etime, orgid, 0, keyword)
  569. if err != nil {
  570. utils.ErrorLog(err.Error())
  571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  572. return
  573. }
  574. llist, err := service.Administration(deliveryway, orgid, flist)
  575. if err != nil {
  576. utils.ErrorLog(err.Error())
  577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  578. return
  579. }
  580. this.ServeSuccessJSON(map[string]interface{}{
  581. "list": llist,
  582. })
  583. return
  584. }
  585. // 获取药品的所有患者信息
  586. func (this *PharmacyController) GetPatientsWithDrugs() {
  587. var err error
  588. defer func() {
  589. if rec := recover(); rec != nil {
  590. err = fmt.Errorf("程序异常:%v", rec)
  591. }
  592. if err != nil {
  593. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  594. }
  595. }()
  596. drug_id, _ := this.GetInt64("drug_id", 0)
  597. is_medicine, _ := this.GetInt64("is_medicine", 0) //0:待发药,1:已发药
  598. times := this.GetString("time", "")
  599. orgid := this.GetAdminUserInfo().CurrentOrgId
  600. deliveryway := this.GetString("deliveryway", "")
  601. if deliveryway == "" {
  602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  603. return
  604. }
  605. shift, err := this.GetInt64("shift", 0) //班次
  606. if err != nil {
  607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  608. return
  609. }
  610. partition, err := this.GetInt64("partition", 0) //分区
  611. if err != nil {
  612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  613. return
  614. }
  615. timeLayout := "2006-01-02"
  616. loc, _ := time.LoadLocation("Local")
  617. var stime, etime int64
  618. if times == "" {
  619. stime, etime = service.GetNowTime()
  620. } else {
  621. stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", times+" 00:00:00", loc)
  622. stime = stmp.Unix()
  623. etime = stime + 86399
  624. }
  625. var list []*models.PatientInformation
  626. list, err = service.FindMedicationList(orgid, drug_id, stime, etime, is_medicine)
  627. if err != nil {
  628. utils.ErrorLog(err.Error())
  629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  630. return
  631. }
  632. listll, err := service.PartitionAndLayoutDrug(deliveryway, stime, etime, orgid, shift, partition, list)
  633. if err != nil {
  634. utils.ErrorLog(err.Error())
  635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  636. return
  637. }
  638. total, err := service.CalculateTheTotalAmount(listll, drug_id)
  639. if err != nil {
  640. utils.ErrorLog(err.Error())
  641. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  642. return
  643. }
  644. this.ServeSuccessJSON(map[string]interface{}{
  645. "list": listll,
  646. "total": total,
  647. })
  648. return
  649. }
  650. // 药品管理发药按钮点击
  651. func (this *PharmacyController) MedicineDeparture() {
  652. var err error
  653. defer func() {
  654. if rec := recover(); rec != nil {
  655. err = fmt.Errorf("程序异常:%v", rec)
  656. }
  657. if err != nil {
  658. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  659. }
  660. }()
  661. creater, _ := this.GetInt64("creater", 0) //领药人
  662. ids := this.GetString("ids", "") //发药的数据
  663. orgid := this.GetAdminUserInfo().CurrentOrgId
  664. if ids == "" {
  665. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数不足")
  666. return
  667. }
  668. err = service.MedicineDeparture(ids, creater, orgid)
  669. if err != nil {
  670. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  671. return
  672. }
  673. this.ServeSuccessJSON(map[string]interface{}{
  674. "list": "修改成功",
  675. })
  676. return
  677. }
  678. func (this *PharmacyController) GetPartitionList() {
  679. var err error
  680. defer func() {
  681. if rec := recover(); rec != nil {
  682. err = fmt.Errorf("程序异常:%v", rec)
  683. }
  684. if err != nil {
  685. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  686. }
  687. }()
  688. orgid := this.GetAdminUserInfo().CurrentOrgId
  689. tmp := []*models.DeviceZone{{ID: 0, Name: "全部分区"}}
  690. list, err := service.GetAllValidDeviceZones02(orgid)
  691. if err != nil {
  692. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  693. return
  694. }
  695. this.ServeSuccessJSON(map[string]interface{}{
  696. "list": append(tmp, list...),
  697. })
  698. return
  699. }
  700. func (this *PharmacyController) RouteOfAdministration() {
  701. var err error
  702. defer func() {
  703. if rec := recover(); rec != nil {
  704. err = fmt.Errorf("程序异常:%v", rec)
  705. }
  706. if err != nil {
  707. service.SaveErrs(this.GetAdminUserInfo().CurrentOrgId, this.Ctx.Input, err)
  708. }
  709. }()
  710. orgid := this.GetAdminUserInfo().CurrentOrgId
  711. tmp := []*models.DrugwayDic{{ID: 0, Name: "全部"}}
  712. list, _, err := service.GetDrugWayDics(orgid)
  713. if err != nil {
  714. this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  715. return
  716. }
  717. this.ServeSuccessJSON(map[string]interface{}{
  718. "list": append(tmp, list...),
  719. })
  720. return
  721. }