dialysis_parameter_api_controller.go 16KB

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