statistics_api_controller.go 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "strconv"
  9. "time"
  10. )
  11. type StatisticsApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func StatisticsApiRegistRouters() {
  15. beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics")
  16. beego.Router("/api/qc/statistiscall/get", &StatisticsApiController{}, "get:GetAllInspectionStatistisc")
  17. beego.Router("/api/qc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonInspectionStatistisc")
  18. beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
  19. //beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
  20. //beego.Router("/api/qc/statistiscperson/export", &StatisticsApiController{}, "get:ExportPersonInspectionStatistisc")
  21. }
  22. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  23. start_date := c.GetString("start_date")
  24. end_date := c.GetString("end_date")
  25. project_id, _ := c.GetInt64("project_id")
  26. item_id, _ := c.GetInt64("item_id")
  27. item_type, _ := c.GetInt64("item_type")
  28. //order_type, _ := c.GetInt64("order_type")
  29. keyword := c.GetString("keyword")
  30. timeLayout := "2006-01-02"
  31. loc, _ := time.LoadLocation("Local")
  32. var startTime int64
  33. if len(start_date) > 0 {
  34. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  35. fmt.Println("err-----------", err)
  36. if err != nil {
  37. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  38. return
  39. }
  40. startTime = theTime.Unix()
  41. }
  42. var endTime int64
  43. if len(end_date) > 0 {
  44. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  45. if err != nil {
  46. utils.ErrorLog(err.Error())
  47. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  48. return
  49. }
  50. endTime = theTime.Unix()
  51. }
  52. //获取配置
  53. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  54. //获取数值在正常范围内的总数
  55. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  56. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  57. switch item_type {
  58. case 0:
  59. break
  60. case 1:
  61. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  62. c.ServeSuccessJSON(map[string]interface{}{
  63. "list": list,
  64. "reference": reference,
  65. })
  66. break
  67. case 2:
  68. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
  69. c.ServeSuccessJSON(map[string]interface{}{
  70. "list": list,
  71. "reference": reference,
  72. })
  73. break
  74. case 3:
  75. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  76. c.ServeSuccessJSON(map[string]interface{}{
  77. "list": list,
  78. "reference": reference,
  79. })
  80. break
  81. }
  82. }
  83. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  84. start_date := c.GetString("start_date")
  85. end_date := c.GetString("end_date")
  86. project_id, _ := c.GetInt64("project_id")
  87. item_id, _ := c.GetInt64("item_id")
  88. timeLayout := "2006-01-02"
  89. loc, _ := time.LoadLocation("Local")
  90. var startTime int64
  91. if len(start_date) > 0 {
  92. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  93. fmt.Println("err-----------", err)
  94. if err != nil {
  95. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  96. return
  97. }
  98. startTime = theTime.Unix()
  99. }
  100. var endTime int64
  101. if len(end_date) > 0 {
  102. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  103. if err != nil {
  104. utils.ErrorLog(err.Error())
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. endTime = theTime.Unix()
  109. }
  110. //患者总数
  111. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  112. //获取配置
  113. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  114. //获取数值在正常范围内的总数
  115. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  116. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  117. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  118. //获取数值异常的总数
  119. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  120. //获取没有检查的患者总数
  121. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "patient_count": patientCount,
  124. "normal_total": normalTotal,
  125. "unusual_total": unusualTotal,
  126. "no_check_total": noCheckTotal,
  127. "reference": reference,
  128. })
  129. }
  130. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  131. start_date := c.GetString("start_time")
  132. end_date := c.GetString("end_time")
  133. project_id, _ := c.GetInt64("project_id")
  134. item_id, _ := c.GetInt64("item_id")
  135. patient_id, _ := c.GetInt64("patient_id")
  136. timeLayout := "2006-01-02"
  137. loc, _ := time.LoadLocation("Local")
  138. var startTime int64
  139. if len(start_date) > 0 {
  140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  141. fmt.Println("err-----------", err)
  142. if err != nil {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. startTime = theTime.Unix()
  147. }
  148. var endTime int64
  149. if len(end_date) > 0 {
  150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  151. if err != nil {
  152. utils.ErrorLog(err.Error())
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. endTime = theTime.Unix()
  157. }
  158. patient, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  159. //获取配置
  160. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  161. //获取数值在正常范围内的总数
  162. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
  163. c.ServeSuccessJSON(map[string]interface{}{
  164. "patient": patient,
  165. "reference": reference,
  166. "inspections": inspections,
  167. })
  168. }
  169. func (c *StatisticsApiController) GetStatistics() {
  170. adminUserInfo := c.GetAdminUserInfo()
  171. // thisTime := time.Now()
  172. year, month, day := time.Now().Date()
  173. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  174. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  175. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  176. todayWeek := int(todayTime.Weekday())
  177. if todayWeek == 0 {
  178. todayWeek = 7
  179. }
  180. weekEnd := 7 - todayWeek
  181. weekStart := weekEnd - 6
  182. // endDay := todayTime.AddDate(0, 0, weekEnd)
  183. startDay := todayTime.AddDate(0, 0, weekStart)
  184. //患者总数
  185. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  186. //今日透析
  187. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  188. //本周透析
  189. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  190. //传染病
  191. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  192. //性别分布
  193. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  194. //年龄分布
  195. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  196. //透析模式
  197. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "patient_count": patientCount,
  200. "today_dialysis_count": todayDialysisCount,
  201. "week_daylysis_count": weekDaylysisCount,
  202. "disease_counts": diseaseCounts,
  203. "gender_counts": genderCounts,
  204. "age_counts": ageCounts,
  205. "mode_counts": modeCounts,
  206. })
  207. }