dialysis_parameter_api_controller.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. }
  23. func (this *DialysisPrameterApiController) GetDialysisParameters() {
  24. timeLayout := "2006-01-02"
  25. loc, _ := time.LoadLocation("Local")
  26. page, _ := this.GetInt64("page")
  27. limit, _ := this.GetInt64("limit")
  28. schedulType, _ := this.GetInt64("scheduleType")
  29. start_time := this.GetString("start_time")
  30. partitionType, _ := this.GetInt64("partitionType")
  31. keywords := this.GetString("keyword")
  32. adminUserInfo := this.GetAdminUserInfo()
  33. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  34. fmt.Println("scheduletype", schedulType, start_time, partitionType, keywords, theTime.Unix())
  35. if len(keywords) > 0 {
  36. dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, theTime.Unix())
  37. if err == nil {
  38. this.ServeSuccessJSON(map[string]interface{}{
  39. "schedule": dialysisSchedule,
  40. "total": total,
  41. })
  42. } else {
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  44. }
  45. } else {
  46. dialysisSchedule, err, total := service.GetDialysisParameter(adminUserInfo.CurrentOrgId, theTime.Unix(), schedulType, partitionType, page, limit)
  47. //查询今日排班的病人
  48. patient, err := service.GetDialysisTodaySchedulePatient(adminUserInfo.CurrentOrgId, theTime.Unix(), page, limit)
  49. var vlist []interface{}
  50. var elist []interface{}
  51. for _, item := range patient {
  52. //查询当前日期的病人是否存在数据
  53. _, errcode := service.GetToDayDialysisPrescription(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  54. if errcode == gorm.ErrRecordNotFound {
  55. //查询每个病人透析处方的最后一次数据
  56. prescription, _ := service.GetLastDialysisPrescription(item.PatientId, adminUserInfo.CurrentOrgId)
  57. vlist = append(vlist, prescription)
  58. } else if errcode == nil {
  59. //获取当前日期
  60. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  61. vlist = append(vlist, prescription)
  62. }
  63. _, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  64. if errcodes == gorm.ErrRecordNotFound {
  65. //查询每个病人透前评估的最后一次数据
  66. dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, adminUserInfo.CurrentOrgId)
  67. elist = append(elist, dialysis)
  68. } else if errcodes == nil {
  69. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, adminUserInfo.CurrentOrgId, theTime.Unix())
  70. elist = append(elist, dialysis)
  71. }
  72. }
  73. if err == nil {
  74. this.ServeSuccessJSON(map[string]interface{}{
  75. "schedule": dialysisSchedule,
  76. "total": total,
  77. "prescription": vlist,
  78. "dialysbefor": elist,
  79. })
  80. } else {
  81. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  82. }
  83. }
  84. }
  85. func (this *DialysisPrameterApiController) GetDialysisBatchParameters() {
  86. timeLayout := "2006-01-02"
  87. loc, _ := time.LoadLocation("Local")
  88. adminUser := this.GetAdminUserInfo()
  89. orgId := adminUser.CurrentOrgId
  90. schIDStr := this.GetString("ids")
  91. if len(schIDStr) == 0 {
  92. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  93. return
  94. }
  95. idStrs := strings.Split(schIDStr, ",")
  96. startime := this.GetString("startime")
  97. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
  98. parameters, err := service.GetDialysisBatchParameters(idStrs, orgId)
  99. var vlist []interface{}
  100. var elist []interface{}
  101. for _, item := range parameters {
  102. //查询当前日期的病人是否存在数据
  103. _, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, theTime.Unix())
  104. if errcode == gorm.ErrRecordNotFound {
  105. //查询每个病人透析处方的最后一次数据
  106. prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
  107. vlist = append(vlist, prescription)
  108. } else if errcode == nil {
  109. //获取当前日期
  110. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, theTime.Unix())
  111. vlist = append(vlist, prescription)
  112. }
  113. _, errcodes := service.GetTodayAssessmentBeforDialysis(item.PatientId, orgId, theTime.Unix())
  114. if errcodes == gorm.ErrRecordNotFound {
  115. //查询每个病人透前评估的最后一次数据
  116. dialysis, _ := service.GetLastAssessmentBeforDialysis(item.PatientId, orgId)
  117. elist = append(elist, dialysis)
  118. } else if errcodes == nil {
  119. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, orgId, theTime.Unix())
  120. elist = append(elist, dialysis)
  121. }
  122. }
  123. if err == nil {
  124. this.ServeSuccessJSON(map[string]interface{}{
  125. "schedule": parameters,
  126. "prescription": vlist,
  127. "dialysbefor": elist,
  128. })
  129. }
  130. }
  131. func (this *DialysisPrameterApiController) GetWareHouseOutList() {
  132. timeLayout := "2006-01-02"
  133. loc, _ := time.LoadLocation("Local")
  134. start_time := this.GetString("start_time")
  135. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  136. end_time := this.GetString("end_time")
  137. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  138. fmt.Println(start_time, end_time)
  139. adminUserInfo := this.GetAdminUserInfo()
  140. orgId := adminUserInfo.CurrentOrgId
  141. wareoutlist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
  142. if err == nil {
  143. this.ServeSuccessJSON(map[string]interface{}{
  144. "wareoutlist": wareoutlist,
  145. })
  146. }
  147. }
  148. func (this *DialysisPrameterApiController) GetAllMaterial() {
  149. timeLayout := "2006-01-02"
  150. loc, _ := time.LoadLocation("Local")
  151. start_time := this.GetString("startime")
  152. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  153. fmt.Println("开始时间", startime)
  154. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  155. fmt.Println("结束时间", endtime)
  156. orgId := this.GetAdminUserInfo().CurrentOrgId
  157. material, err := service.GetAllMaterial(startime.Unix(), endtime.Unix(), orgId)
  158. if err == nil {
  159. this.ServeSuccessJSON(map[string]interface{}{
  160. "material": material,
  161. })
  162. }
  163. }
  164. func (this *DialysisPrameterApiController) GetCollectList() {
  165. timeLayout := "2006-01-02"
  166. loc, _ := time.LoadLocation("Local")
  167. limit, _ := this.GetInt64("limit")
  168. fmt.Println(limit)
  169. page, _ := this.GetInt64("page")
  170. fmt.Println("page", page)
  171. partitiontype, _ := this.GetInt64("partitionType")
  172. fmt.Println(partitiontype)
  173. scheduletype, _ := this.GetInt64("scheduleType")
  174. fmt.Println(scheduletype)
  175. start_time := this.GetString("start_time")
  176. fmt.Println(start_time)
  177. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  178. orgId := this.GetAdminUserInfo().CurrentOrgId
  179. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  180. keyword := this.GetString("keyword")
  181. //获取透析参数数据
  182. schedule, err, total := service.GetCollectList(limit, page, partitiontype, scheduletype, startime.Unix(), orgId, keyword)
  183. //查询今日排班的病人
  184. patient, err := service.GetDialysisTodaySchedulePatient(orgId, startime.Unix(), page, limit)
  185. var vlist []interface{}
  186. var clist []interface{}
  187. for _, item := range patient {
  188. fmt.Println("---------", item.PatientId)
  189. //查询当前日期的病人是否存在数据
  190. _, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
  191. if errcode == gorm.ErrRecordNotFound {
  192. //查询每个病人透析处方的最后一次数据
  193. prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
  194. vlist = append(vlist, prescription)
  195. } else if errcode == nil {
  196. //获取当前日期
  197. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
  198. vlist = append(vlist, prescription)
  199. }
  200. //查询每个病人当前日期是否存在数据
  201. _, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  202. fmt.Println("errco--------------------------", errco)
  203. if errco == gorm.ErrRecordNotFound {
  204. reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
  205. clist = append(clist, reduece)
  206. } else if errco == nil {
  207. reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  208. clist = append(clist, reduece)
  209. }
  210. }
  211. //获取透析耗材数据
  212. consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  213. if err == nil {
  214. this.ServeSuccessJSON(map[string]interface{}{
  215. "schedule": schedule,
  216. "total": total,
  217. "consumables": consumables,
  218. "prescription": vlist,
  219. "reducelist": clist,
  220. })
  221. }
  222. }
  223. func (this *DialysisPrameterApiController) GetBatchCollection() {
  224. timeLayout := "2006-01-02"
  225. loc, _ := time.LoadLocation("Local")
  226. adminUser := this.GetAdminUserInfo()
  227. orgId := adminUser.CurrentOrgId
  228. fmt.Println(orgId)
  229. start_time := this.GetString("startime")
  230. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  231. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  232. schIDStr := this.GetString("ids")
  233. //获取透析耗材数据
  234. consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  235. if len(schIDStr) == 0 {
  236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  237. return
  238. }
  239. idStrs := strings.Split(schIDStr, ",")
  240. fmt.Println(idStrs)
  241. var vlist []interface{}
  242. var clist []interface{}
  243. schedule, err := service.GetBatchCollection(orgId, idStrs)
  244. for _, item := range schedule {
  245. //查询当前日期的病人是否存在数据
  246. _, errcode := service.GetToDayDialysisPrescription(item.PatientId, orgId, startime.Unix())
  247. if errcode == gorm.ErrRecordNotFound {
  248. //查询每个病人透析处方的最后一次数据
  249. prescription, _ := service.GetLastDialysisPrescription(item.PatientId, orgId)
  250. vlist = append(vlist, prescription)
  251. } else if errcode == nil {
  252. //获取当前日期
  253. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
  254. vlist = append(vlist, prescription)
  255. }
  256. //查询每个病人当前日期是否存在数据
  257. _, errco := service.GetAotoMaticReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  258. fmt.Println("errco", errco)
  259. if errco == gorm.ErrRecordNotFound {
  260. reduece, _ := service.GetMaticReduece(item.PatientId, orgId)
  261. clist = append(clist, reduece)
  262. } else if errco == nil {
  263. reduece, _ := service.GetMaticeReduceByPatientId(item.PatientId, orgId, startime.Unix(), endtime.Unix())
  264. clist = append(clist, reduece)
  265. }
  266. }
  267. if err == nil {
  268. this.ServeSuccessJSON(map[string]interface{}{
  269. "schedule": schedule,
  270. "consumables": consumables,
  271. "prescripiton": vlist,
  272. "reducelist": clist,
  273. })
  274. }
  275. }
  276. func (this *DialysisPrameterApiController) GetGatherList() {
  277. timeLayout := "2006-01-02"
  278. loc, _ := time.LoadLocation("Local")
  279. adminUser := this.GetAdminUserInfo()
  280. orgId := adminUser.CurrentOrgId
  281. fmt.Println(orgId)
  282. start_time := this.GetString("start_time")
  283. end_time := this.GetString("end_time")
  284. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  285. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  286. fmt.Println("开始时间", startime)
  287. fmt.Println("结束时间", endtime)
  288. warehouselist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
  289. //获取透析耗材数据
  290. consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  291. //统计抗凝剂数据
  292. count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
  293. if err == nil {
  294. this.ServeSuccessJSON(map[string]interface{}{
  295. "warehouselist": warehouselist,
  296. "consumables": consumables,
  297. "count": count,
  298. })
  299. }
  300. }