statistics_api_controller.go 7.9KB

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