pharmacy_controller.go 24KB

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