pharmacy_controller.go 25KB

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