dialysis_parameter_api_controller.go 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package new_mobile_api_controllers
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/service"
  6. "fmt"
  7. "github.com/jinzhu/gorm"
  8. "time"
  9. )
  10. type DialysisParamerterApiController struct {
  11. mobile_api_controllers.MobileBaseAPIAuthController
  12. }
  13. func (this *DialysisParamerterApiController) GetAllMobileZon() {
  14. adminUserInfo := this.GetMobileAdminUserInfo()
  15. orgid := adminUserInfo.Org.Id
  16. err, zone := service.GetAllDeviceZone(orgid)
  17. if err == nil {
  18. this.ServeSuccessJSON(map[string]interface{}{
  19. "zone": zone,
  20. })
  21. }
  22. }
  23. func (this *DialysisParamerterApiController) GetMobileDialysisParameters() {
  24. timeLayout := "2006-01-02"
  25. loc, _ := time.LoadLocation("Local")
  26. adminUserInfo := this.GetMobileAdminUserInfo()
  27. orgid := adminUserInfo.Org.Id
  28. fmt.Println(orgid)
  29. keywords := this.GetString("keyword")
  30. start_time := this.GetString("start_time")
  31. fmt.Println("start_time", start_time)
  32. limit, _ := this.GetInt64("limit")
  33. fmt.Println(limit)
  34. page, _ := this.GetInt64("page")
  35. fmt.Println(page)
  36. partitionType, _ := this.GetInt64("partitionType")
  37. fmt.Println("partiontype", partitionType)
  38. scheduleType, _ := this.GetInt64("scheduleType")
  39. fmt.Println(scheduleType)
  40. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  41. if len(keywords) > 0 {
  42. //dialysisSchedule, err, total := service.GetDialysisParametersByKeyword(orgid, keywords, scheduleType, partitionType, page, limit, theTime.Unix())
  43. //查询今日排班的病人
  44. patient, err := service.GetDialysisTodaySchedulePatient(orgid, theTime.Unix(), page, limit, keywords, scheduleType, partitionType)
  45. var vlist []interface{}
  46. var elist []interface{}
  47. for _, item := range patient {
  48. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgid, theTime.Unix())
  49. vlist = append(vlist, prescription)
  50. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, orgid, theTime.Unix())
  51. elist = append(elist, dialysis)
  52. if err == nil {
  53. this.ServeSuccessJSON(map[string]interface{}{
  54. //"schedule": dialysisSchedule,
  55. //"total": total,
  56. "prescription": vlist,
  57. "dialysbefor": elist,
  58. "patient": patient,
  59. })
  60. } else {
  61. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  62. }
  63. }
  64. } else {
  65. dialysisSchedule, err, total := service.GetDialysisParameter(orgid, theTime.Unix(), scheduleType, partitionType, page, limit)
  66. //查询今日排班的病人
  67. patient, err := service.GetDialysisTodaySchedulePatient(orgid, theTime.Unix(), page, limit, keywords, scheduleType, partitionType)
  68. var vlist []interface{}
  69. var elist []interface{}
  70. for _, item := range patient {
  71. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgid, theTime.Unix())
  72. vlist = append(vlist, prescription)
  73. dialysis, _ := service.GetAssessmentBeforDialysisByStartime(item.PatientId, orgid, theTime.Unix())
  74. elist = append(elist, dialysis)
  75. }
  76. if err == nil {
  77. this.ServeSuccessJSON(map[string]interface{}{
  78. "schedule": dialysisSchedule,
  79. "total": total,
  80. "prescription": vlist,
  81. "dialysbefor": elist,
  82. "patient": patient,
  83. })
  84. } else {
  85. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  86. }
  87. }
  88. }
  89. func (this *DialysisParamerterApiController) GetMobileWareHouseOutList() {
  90. timeLayout := "2006-01-02"
  91. loc, _ := time.LoadLocation("Local")
  92. start_time := this.GetString("start_time")
  93. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  94. end_time := this.GetString("end_time")
  95. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  96. fmt.Println(start_time, end_time)
  97. orgId := this.GetMobileAdminUserInfo().Org.Id
  98. wareoutlist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
  99. count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
  100. if err == nil {
  101. this.ServeSuccessJSON(map[string]interface{}{
  102. "wareoutlist": wareoutlist,
  103. "count": count,
  104. })
  105. }
  106. }
  107. func (this *DialysisParamerterApiController) GetAllMobileMaterial() {
  108. timeLayout := "2006-01-02"
  109. loc, _ := time.LoadLocation("Local")
  110. start_time := this.GetString("startime")
  111. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  112. fmt.Println("开始时间", startime)
  113. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 23:59:59", loc)
  114. fmt.Println("结束时间", endtime)
  115. adminUserInfo := this.GetMobileAdminUserInfo()
  116. orgId := adminUserInfo.Org.Id
  117. material, err := service.GetAllMaterial(startime.Unix(), endtime.Unix(), orgId)
  118. if err == nil {
  119. this.ServeSuccessJSON(map[string]interface{}{
  120. "material": material,
  121. })
  122. }
  123. }
  124. func (this *DialysisParamerterApiController) GetMobileCollectList() {
  125. timeLayout := "2006-01-02"
  126. loc, _ := time.LoadLocation("Local")
  127. limit, _ := this.GetInt64("limit")
  128. fmt.Println(limit)
  129. page, _ := this.GetInt64("page")
  130. fmt.Println("page", page)
  131. partitiontype, _ := this.GetInt64("partitionType")
  132. fmt.Println(partitiontype)
  133. scheduletype, _ := this.GetInt64("scheduleType")
  134. fmt.Println(scheduletype)
  135. start_time := this.GetString("start_time")
  136. fmt.Println(start_time)
  137. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  138. orgId := this.GetMobileAdminUserInfo().Org.Id
  139. keyword := this.GetString("keyword")
  140. //获取透析参数数据
  141. //schedule, err, _ := service.GetCollectList(limit, page, partitiontype, scheduletype, startime.Unix(), orgId, keyword)
  142. //查询今日排班的病人
  143. patient, err := service.GetDialysisTodaySchedulePatient(orgId, startime.Unix(), page, limit, keyword, scheduletype, partitiontype)
  144. var vlist []interface{}
  145. var clist []interface{}
  146. for _, item := range patient {
  147. prescription, _ := service.GetDialysisPrescriptionList(item.PatientId, orgId, startime.Unix())
  148. vlist = append(vlist, prescription)
  149. }
  150. _, errors := service.FindStockOutByIsSys(orgId, 1, startime.Unix())
  151. goodTypes, _ := service.FindAllGoodType(orgId) //two, err, i := service.PCGetDialysisGoodsTwo(orgId, startime.Unix(), scheduletype, partitiontype, page, limit, keyword)
  152. if errors == gorm.ErrRecordNotFound {
  153. dialysisGoods, _, total := service.PCGetDialysisGoodsTwo(orgId, startime.Unix(), scheduletype, partitiontype, page, limit, keyword)
  154. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  155. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, orgId, startime.Unix())
  156. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, orgId, startime.Unix())
  157. item.LastAutomaticReduceDetail = goodUser
  158. item.LastDialysisBeforePrepare = lastGoodUserDetial
  159. }
  160. this.ServeSuccessJSON(map[string]interface{}{
  161. "dialysis_goods": dialysisGoods,
  162. "good_type": goodTypes,
  163. "total": total,
  164. //"schedule": schedule,
  165. "prescription": vlist,
  166. "patient": patient,
  167. })
  168. return
  169. } else if err == nil {
  170. //获取当天排班的每个患者的库存使用情况
  171. dialysisGoods, err, total := service.PCGetDialysisGoodsTwo(orgId, startime.Unix(), scheduletype, partitiontype, page, limit, keyword)
  172. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  173. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, orgId, startime.Unix())
  174. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, orgId, startime.Unix())
  175. fmt.Println(goodUser)
  176. fmt.Println(lastGoodUserDetial)
  177. item.LastAutomaticReduceDetail = goodUser
  178. item.LastDialysisBeforePrepare = lastGoodUserDetial
  179. }
  180. if err == nil {
  181. this.ServeSuccessJSON(map[string]interface{}{
  182. "dialysis_goods": dialysisGoods,
  183. "good_type": goodTypes,
  184. "total": total,
  185. //"schedule": schedule,
  186. //"consumables": consumables,
  187. "prescription": vlist,
  188. "reducelist": clist,
  189. })
  190. return
  191. } else {
  192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  193. return
  194. }
  195. } else if err != nil {
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  197. return
  198. }
  199. //if err == nil {
  200. // this.ServeSuccessJSON(map[string]interface{}{
  201. // "schedule": schedule,
  202. // "total": total,
  203. // "consumables": consumables,
  204. // "prescription": vlist,
  205. // "reducelist": clist,
  206. // })
  207. //}
  208. }
  209. func (this *DialysisParamerterApiController) GetMobileGatherList() {
  210. timeLayout := "2006-01-02"
  211. loc, _ := time.LoadLocation("Local")
  212. start_time := this.GetString("start_time")
  213. end_time := this.GetString("end_time")
  214. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  215. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  216. adminUserInfo := this.GetMobileAdminUserInfo()
  217. orgId := adminUserInfo.Org.Id
  218. fmt.Println("开始时间", startime)
  219. fmt.Println("结束时间", endtime)
  220. warehouselist, err := service.GetWareHouseOutList(startime.Unix(), endtime.Unix(), orgId)
  221. //获取透析耗材数据
  222. consumables, err := service.GetDialysisConsumables(startime.Unix(), endtime.Unix(), orgId)
  223. //统计抗凝剂数据
  224. count, err := service.GetAnticoagulantCount(startime.Unix(), endtime.Unix(), orgId)
  225. if err == nil {
  226. this.ServeSuccessJSON(map[string]interface{}{
  227. "warehouselist": warehouselist,
  228. "consumables": consumables,
  229. "count": count,
  230. })
  231. }
  232. }