pharmacy_controller.go 25KB

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