pharmacy_controller.go 25KB

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