pharmacy_controller.go 25KB

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