dialysis_parameter_api_controller.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/service"
  5. "fmt"
  6. "github.com/astaxie/beego"
  7. "github.com/jinzhu/gorm"
  8. "strings"
  9. "time"
  10. )
  11. type DialysisPrameterApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func DialysisPrameteRoutes() {
  15. beego.Router("/api/dialysis/getdialysisparameters", &DialysisPrameterApiController{}, "Get:GetDialysisParameters")
  16. beego.Router("/api/dialysis/getdialysisbatchparameters", &DialysisPrameterApiController{}, "Get:GetDialysisBatchParameters")
  17. beego.Router("/api/dialysis/getwarehouseoutlist", &DialysisPrameterApiController{}, "Get:GetWareHouseOutList")
  18. beego.Router("/api/dialysis/getallmaterial", &DialysisPrameterApiController{}, "Get:GetAllMaterial")
  19. beego.Router("/api/dialysis/getcollectlist", &DialysisPrameterApiController{}, "Get:GetCollectList")
  20. beego.Router("/api/dialysis/getbatchcollection", &DialysisPrameterApiController{}, "Get:GetBatchCollection")
  21. beego.Router("/api/dialysis/getgatherlist", &DialysisPrameterApiController{}, "Get:GetGatherList")
  22. beego.Router("/api/dialysis/getanticoagulantcount", &DialysisPrameterApiController{}, "Get:GetAnticoagulantCount")
  23. }
  24. func (this *DialysisPrameterApiController) GetDialysisParameters() {
  25. timeLayout := "2006-01-02"
  26. loc, _ := time.LoadLocation("Local")
  27. page, _ := this.GetInt64("page")
  28. limit, _ := this.GetInt64("limit")
  29. schedulType, _ := this.GetInt64("scheduleType")
  30. start_time := this.GetString("start_time")
  31. partitionType, _ := this.GetInt64("partitionType")
  32. keywords := this.GetString("keyword")
  33. adminUserInfo := this.GetAdminUserInfo()
  34. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  35. fmt.Println("scheduletype", schedulType, start_time, partitionType, keywords, theTime.Unix())
  36. if len(keywords) > 0 {
  37. dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, theTime.Unix())
  38. patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit, keywords, schedulType, partitionType)
  39. var vlist []interface{}
  40. var elist []interface{}
  41. for _, item := range patient {
  42. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  43. vlist = append(vlist, prescription)
  44. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  45. elist = append(elist, dialysis)
  46. }
  47. if err == nil {
  48. this.ServeSuccessJSON(map[string]interface{}{
  49. "schedule": dialysisSchedule,
  50. "total": total,
  51. "prescription": vlist,
  52. "dialysbefor": elist,
  53. "patient": patient,
  54. })
  55. } else {
  56. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  57. }
  58. } else {
  59. dialysisSchedule, err, total := service.GetDialysisParameter(adminUserInfo.CurrentOrgId, theTime.Unix(), schedulType, partitionType, page, limit)
  60. //查询今日排班的病人
  61. patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit, keywords, schedulType, partitionType)
  62. var vlist []interface{}
  63. var elist []interface{}
  64. for _, item := range patient {
  65. //查询当前日期的病人是否存在数据
  66. //_, errcode := service.GetToDayDialysisPrescription(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  67. //if errcode == gorm.ErrRecordNotFound {
  68. // //查询每个病人透析处方的最后一次数据
  69. // prescription, _ := service.GetLastDialysisPrescription(item.PatientId, adminUserInfo.CurrentOrgId)
  70. // vlist = append(vlist, prescription)
  71. //} else if errcode == nil {
  72. // //获取当前日期
  73. // prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  74. // vlist = append(vlist, prescription)
  75. //}
  76. //_, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  77. //if errcodes == gorm.ErrRecordNotFound {
  78. // //查询每个病人透前评估的最后一次数据
  79. // dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, adminUserInfo.CurrentOrgId)
  80. // elist = append(elist, dialysis)
  81. //} else if errcodes == nil {
  82. // dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  83. // elist = append(elist, dialysis)
  84. //}
  85. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  86. vlist = append(vlist, prescription)
  87. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  88. elist = append(elist, dialysis)
  89. }
  90. if err == nil {
  91. this.ServeSuccessJSON(map[string]interface{}{
  92. "schedule": dialysisSchedule,
  93. "total": total,
  94. "prescription": vlist,
  95. "dialysbefor": elist,
  96. "patient": patient,
  97. })
  98. } else {
  99. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  100. }
  101. }
  102. }
  103. func (this *DialysisPrameterApiController) GetDialysisBatchParameters() {
  104. timeLayout := "2006-01-02"
  105. loc, _ := time.LoadLocation("Local")
  106. adminUser := this.GetAdminUserInfo()
  107. orgId := adminUser.CurrentOrgId
  108. schIDStr := this.GetString("ids")
  109. if len(schIDStr) == 0 {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. idStrs := strings.Split(schIDStr, ",")
  114. startime := this.GetString("startime")
  115. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
  116. parameters, err := service.GetDialysisBatchParameters(idStrs, orgId)
  117. var vlist []interface{}
  118. var elist []interface{}
  119. for _, item := range parameters {
  120. //查询当前日期的病人是否存在数据
  121. _, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, theTime.Unix())
  122. if errcode == gorm.ErrRecordNotFound {
  123. //查询每个病人透析处方的最后一次数据
  124. prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
  125. vlist = append(vlist, prescription)
  126. } else if errcode == nil {
  127. //获取当前日期
  128. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, theTime.Unix())
  129. vlist = append(vlist, prescription)
  130. }
  131. _, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, orgId, theTime.Unix())
  132. if errcodes == gorm.ErrRecordNotFound {
  133. //查询每个病人透前评估的最后一次数据
  134. dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, orgId)
  135. elist = append(elist, dialysis)
  136. } else if errcodes == nil {
  137. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, orgId, theTime.Unix())
  138. elist = append(elist, dialysis)
  139. }
  140. }
  141. if err == nil {
  142. this.ServeSuccessJSON(map[string]interface{}{
  143. "schedule": parameters,
  144. "prescription": vlist,
  145. "dialysbefor": elist,
  146. })
  147. }
  148. }
  149. func (this *DialysisPrameterApiController) GetWareHouseOutList() {
  150. timeLayout := "2006-01-02"
  151. loc, _ := time.LoadLocation("Local")
  152. start_time := this.GetString("start_time")
  153. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  154. end_time := this.GetString("end_time")
  155. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  156. fmt.Println(start_time, end_time)
  157. adminUserInfo := this.GetAdminUserInfo()
  158. orgId := adminUserInfo.CurrentOrgId
  159. wareoutlist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
  160. if err == nil {
  161. this.ServeSuccessJSON(map[string]interface{}{
  162. "wareoutlist": wareoutlist,
  163. })
  164. }
  165. }
  166. func (this *DialysisPrameterApiController) GetAllMaterial() {
  167. timeLayout := "2006-01-02"
  168. loc, _ := time.LoadLocation("Local")
  169. start_time := this.GetString("startime")
  170. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  171. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  172. orgId := this.GetAdminUserInfo().CurrentOrgId
  173. material, err := service.GetAllMaterial(startime.Unix(), endtime.Unix(), orgId)
  174. if err == nil {
  175. this.ServeSuccessJSON(map[string]interface{}{
  176. "material": material,
  177. })
  178. }
  179. }
  180. func (this *DialysisPrameterApiController) GetCollectList() {
  181. timeLayout := "2006-01-02"
  182. loc, _ := time.LoadLocation("Local")
  183. limit, _ := this.GetInt64("limit")
  184. fmt.Println(limit)
  185. page, _ := this.GetInt64("page")
  186. fmt.Println("page", page)
  187. partitiontype, _ := this.GetInt64("partitionType")
  188. fmt.Println(partitiontype)
  189. scheduletype, _ := this.GetInt64("scheduleType")
  190. fmt.Println(scheduletype)
  191. start_time := this.GetString("start_time")
  192. fmt.Println(start_time)
  193. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  194. fmt.Println("startime", startime.Unix())
  195. orgId := this.GetAdminUserInfo().CurrentOrgId
  196. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  197. keyword := this.GetString("keyword")
  198. //获取透析参数数据
  199. schedule, err, _ := service.GetCollectList(limit, page, partitiontype, scheduletype, startime.Unix(), orgId, keyword)
  200. //查询今日排班的病人
  201. patient, err := service.GetDialysisTodaySchedulePatient(orgId, startime.Unix(), page, limit, keyword, scheduletype, partitiontype)
  202. var vlist []interface{}
  203. var clist []interface{}
  204. for _, item := range patient {
  205. fmt.Println("---------", item.PatientId)
  206. //查询当前日期的病人是否存在数据
  207. //_, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
  208. //if errcode == gorm.ErrRecordNotFound {
  209. // //查询每个病人透析处方的最后一次数据
  210. // prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
  211. // vlist = append(vlist, prescription)
  212. //} else if errcode == nil {
  213. // //获取当前日期
  214. // prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
  215. // vlist = append(vlist, prescription)
  216. //}
  217. //查询每个病人当前日期是否存在数据
  218. //_, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  219. //fmt.Println("errco--------------------------", errco)
  220. //if errco == gorm.ErrRecordNotFound {
  221. // reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
  222. // clist = append(clist, reduece)
  223. //} else if errco == nil {
  224. // reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  225. // clist = append(clist, reduece)
  226. //}
  227. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
  228. vlist = append(vlist, prescription)
  229. reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  230. clist = append(clist, reduece)
  231. }
  232. //获取透析耗材数据
  233. //consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  234. //if err == nil {
  235. // this.ServeSuccessJSON(map[string]interface{}{
  236. // "schedule": schedule,
  237. // "total": total,
  238. // "consumables": consumables,
  239. // "prescription": vlist,
  240. // "reducelist": clist,
  241. // })
  242. //}
  243. _, errors := service.FindStockOutByIsSys(orgId, 1, startime.Unix())
  244. goodTypes, _ := service.FindAllGoodType(orgId) //two, err, i := service.PCGetDialysisGoodsTwo(orgId, startime.Unix(), scheduletype, partitiontype, page, limit, keyword)
  245. if errors == gorm.ErrRecordNotFound {
  246. dialysisGoods, _, total := service.PCGetDialysisGoodsTwo(orgId, startime.Unix(), scheduletype, partitiontype, page, limit, keyword)
  247. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  248. goodUser, _ := service.GetLastDialysisGoodsTwo(item.PatientId, orgId, startime.Unix())
  249. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepareTwo(item.PatientId, orgId, startime.Unix())
  250. item.LastAutomaticReduceDetail = goodUser
  251. item.LastDialysisBeforePrepare = lastGoodUserDetial
  252. }
  253. this.ServeSuccessJSON(map[string]interface{}{
  254. "dialysis_goods": dialysisGoods,
  255. "good_type": goodTypes,
  256. "total": total,
  257. "schedule": schedule,
  258. //"consumables": consumables,
  259. "prescription": vlist,
  260. "reducelist": clist,
  261. })
  262. return
  263. } else if err == nil {
  264. //获取当天排班的每个患者的库存使用情况
  265. dialysisGoods, err, total := service.PCGetDialysisGoodsTwo(orgId, startime.Unix(), scheduletype, partitiontype, page, limit, keyword)
  266. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  267. goodUser, _ := service.GetLastDialysisGoodsTwo(item.PatientId, orgId, startime.Unix())
  268. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepareTwo(item.PatientId, orgId, startime.Unix())
  269. fmt.Println(goodUser)
  270. fmt.Println(lastGoodUserDetial)
  271. item.LastAutomaticReduceDetail = goodUser
  272. item.LastDialysisBeforePrepare = lastGoodUserDetial
  273. }
  274. if err == nil {
  275. this.ServeSuccessJSON(map[string]interface{}{
  276. "dialysis_goods": dialysisGoods,
  277. "good_type": goodTypes,
  278. "total": total,
  279. "schedule": schedule,
  280. //"consumables": consumables,
  281. "prescription": vlist,
  282. "reducelist": clist,
  283. })
  284. return
  285. } else {
  286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  287. return
  288. }
  289. } else if err != nil {
  290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  291. return
  292. }
  293. }
  294. func (this *DialysisPrameterApiController) GetBatchCollection() {
  295. timeLayout := "2006-01-02"
  296. loc, _ := time.LoadLocation("Local")
  297. adminUser := this.GetAdminUserInfo()
  298. orgId := adminUser.CurrentOrgId
  299. fmt.Println(orgId)
  300. start_time := this.GetString("startime")
  301. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  302. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  303. schIDStr := this.GetString("ids")
  304. //获取透析耗材数据
  305. consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  306. if len(schIDStr) == 0 {
  307. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  308. return
  309. }
  310. idStrs := strings.Split(schIDStr, ",")
  311. fmt.Println(idStrs)
  312. var vlist []interface{}
  313. var clist []interface{}
  314. schedule, err := service.GetBatchCollection(orgId, idStrs)
  315. for _, item := range schedule {
  316. //查询当前日期的病人是否存在数据
  317. _, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
  318. if errcode == gorm.ErrRecordNotFound {
  319. //查询每个病人透析处方的最后一次数据
  320. prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
  321. vlist = append(vlist, prescription)
  322. } else if errcode == nil {
  323. //获取当前日期
  324. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
  325. vlist = append(vlist, prescription)
  326. }
  327. //查询每个病人当前日期是否存在数据
  328. _, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  329. fmt.Println("errco", errco)
  330. if errco == gorm.ErrRecordNotFound {
  331. reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
  332. clist = append(clist, reduece)
  333. } else if errco == nil {
  334. reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  335. clist = append(clist, reduece)
  336. }
  337. }
  338. if err == nil {
  339. this.ServeSuccessJSON(map[string]interface{}{
  340. "schedule": schedule,
  341. "consumables": consumables,
  342. "prescripiton": vlist,
  343. "reducelist": clist,
  344. })
  345. }
  346. }
  347. func (this *DialysisPrameterApiController) GetGatherList() {
  348. timeLayout := "2006-01-02"
  349. loc, _ := time.LoadLocation("Local")
  350. adminUser := this.GetAdminUserInfo()
  351. orgId := adminUser.CurrentOrgId
  352. fmt.Println(orgId)
  353. start_time := this.GetString("start_time")
  354. end_time := this.GetString("end_time")
  355. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  356. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  357. fmt.Println("开始时间", startime)
  358. fmt.Println("结束时间", endtime)
  359. warehouselist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
  360. //获取透析耗材数据
  361. consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  362. //统计抗凝剂数据
  363. count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
  364. if err == nil {
  365. this.ServeSuccessJSON(map[string]interface{}{
  366. "warehouselist": warehouselist,
  367. "consumables": consumables,
  368. "count": count,
  369. })
  370. }
  371. }
  372. func (this *DialysisPrameterApiController) GetAnticoagulantCount() {
  373. timeLayout := "2006-01-02"
  374. loc, _ := time.LoadLocation("Local")
  375. adminUser := this.GetAdminUserInfo()
  376. orgId := adminUser.CurrentOrgId
  377. fmt.Println(orgId)
  378. start_time := this.GetString("start_time")
  379. end_time := this.GetString("end_time")
  380. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  381. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  382. fmt.Println("开始时间2222", startime)
  383. fmt.Println("结束时间3333", endtime)
  384. //统计抗凝剂数据
  385. count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
  386. if err == nil {
  387. this.ServeSuccessJSON(map[string]interface{}{
  388. "count": count,
  389. })
  390. }
  391. }