dialysis_parameter_api_controller.go 17KB

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