dialysis_parameter_api_controller.go 16KB

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