pharmacy_controller.go 24KB

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