pharmacy_controller.go 24KB

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