statistics_api_controller.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
  22. }
  23. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  24. start_date := c.GetString("start_date")
  25. end_date := c.GetString("end_date")
  26. keyword := c.GetString("keyword")
  27. timeLayout := "2006-01-02"
  28. loc, _ := time.LoadLocation("Local")
  29. var startTime int64
  30. if len(start_date) > 0 {
  31. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  32. if err != nil {
  33. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  34. return
  35. }
  36. startTime = theTime.Unix()
  37. }
  38. var endTime int64
  39. if len(end_date) > 0 {
  40. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  41. if err != nil {
  42. utils.ErrorLog(err.Error())
  43. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  44. return
  45. }
  46. endTime = theTime.Unix()
  47. }
  48. list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "list": list,
  51. })
  52. }
  53. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  54. start_date := c.GetString("start_date")
  55. end_date := c.GetString("end_date")
  56. project_id, _ := c.GetInt64("project_id")
  57. item_id, _ := c.GetInt64("item_id")
  58. item_type, _ := c.GetInt64("item_type")
  59. //order_type, _ := c.GetInt64("order_type")
  60. keyword := c.GetString("keyword")
  61. s_type, _ := c.GetInt64("type")
  62. timeLayout := "2006-01-02"
  63. loc, _ := time.LoadLocation("Local")
  64. var startTime int64
  65. if len(start_date) > 0 {
  66. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  67. fmt.Println("err-----------", err)
  68. if err != nil {
  69. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  70. return
  71. }
  72. startTime = theTime.Unix()
  73. }
  74. var endTime int64
  75. if len(end_date) > 0 {
  76. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  77. if err != nil {
  78. utils.ErrorLog(err.Error())
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  80. return
  81. }
  82. endTime = theTime.Unix()
  83. }
  84. //获取配置
  85. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  86. //获取数值在正常范围内的总数
  87. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  88. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  89. switch item_type {
  90. case 0:
  91. break
  92. case 1:
  93. if s_type == 2 { //KTV
  94. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  95. c.ServeSuccessJSON(map[string]interface{}{
  96. "list": list,
  97. })
  98. } else if s_type == 3 { //URR
  99. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  100. c.ServeSuccessJSON(map[string]interface{}{
  101. "list": list,
  102. })
  103. } else {
  104. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "list": list,
  107. "reference": reference,
  108. })
  109. }
  110. break
  111. case 2:
  112. if s_type == 2 { //KTV
  113. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "list": list,
  116. })
  117. } else if s_type == 3 { //URR
  118. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  119. c.ServeSuccessJSON(map[string]interface{}{
  120. "list": list,
  121. })
  122. } else {
  123. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
  124. c.ServeSuccessJSON(map[string]interface{}{
  125. "list": list,
  126. "reference": reference,
  127. })
  128. }
  129. break
  130. case 3:
  131. if s_type == 2 { //KTV
  132. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  133. c.ServeSuccessJSON(map[string]interface{}{
  134. "list": list,
  135. })
  136. } else if s_type == 3 { //URR
  137. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  138. c.ServeSuccessJSON(map[string]interface{}{
  139. "list": list,
  140. })
  141. } else {
  142. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  143. c.ServeSuccessJSON(map[string]interface{}{
  144. "list": list,
  145. "reference": reference,
  146. })
  147. }
  148. break
  149. }
  150. }
  151. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  152. start_date := c.GetString("start_date")
  153. end_date := c.GetString("end_date")
  154. project_id, _ := c.GetInt64("project_id")
  155. item_id, _ := c.GetInt64("item_id")
  156. s_type, _ := c.GetInt64("type")
  157. timeLayout := "2006-01-02"
  158. loc, _ := time.LoadLocation("Local")
  159. var startTime int64
  160. if len(start_date) > 0 {
  161. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  162. fmt.Println("err-----------", err)
  163. if err != nil {
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  165. return
  166. }
  167. startTime = theTime.Unix()
  168. }
  169. var endTime int64
  170. if len(end_date) > 0 {
  171. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  172. if err != nil {
  173. utils.ErrorLog(err.Error())
  174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  175. return
  176. }
  177. endTime = theTime.Unix()
  178. }
  179. //患者总数
  180. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  181. //获取配置
  182. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  183. //获取数值在正常范围内的总数
  184. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  185. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  186. if s_type == 2 {
  187. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  188. //获取数值异常的总数
  189. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  190. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  191. //获取没有检查的患者总数
  192. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  193. c.ServeSuccessJSON(map[string]interface{}{
  194. "patient_count": patientCount,
  195. "normal_total": normalTotal,
  196. "unusual_total": unusualTotal,
  197. "no_check_total": noCheckTotal,
  198. })
  199. } else if s_type == 3 {
  200. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  201. //获取数值异常的总数
  202. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  203. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  204. //获取没有检查的患者总数
  205. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  206. c.ServeSuccessJSON(map[string]interface{}{
  207. "patient_count": patientCount,
  208. "normal_total": normalTotal,
  209. "unusual_total": unusualTotal,
  210. "no_check_total": noCheckTotal,
  211. })
  212. } else {
  213. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  214. //获取数值异常的总数
  215. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  216. //获取没有检查的患者总数
  217. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "patient_count": patientCount,
  220. "normal_total": normalTotal,
  221. "unusual_total": unusualTotal,
  222. "no_check_total": noCheckTotal,
  223. "reference": reference,
  224. })
  225. }
  226. }
  227. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  228. start_date := c.GetString("start_time")
  229. end_date := c.GetString("end_time")
  230. project_id, _ := c.GetInt64("project_id")
  231. item_id, _ := c.GetInt64("item_id")
  232. patient_id, _ := c.GetInt64("patient_id")
  233. s_type, _ := c.GetInt64("type")
  234. timeLayout := "2006-01-02"
  235. loc, _ := time.LoadLocation("Local")
  236. var startTime int64
  237. if len(start_date) > 0 {
  238. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  239. fmt.Println("err-----------", err)
  240. if err != nil {
  241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  242. return
  243. }
  244. startTime = theTime.Unix()
  245. }
  246. var endTime int64
  247. if len(end_date) > 0 {
  248. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  249. if err != nil {
  250. utils.ErrorLog(err.Error())
  251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  252. return
  253. }
  254. endTime = theTime.Unix()
  255. }
  256. if s_type == 2 {
  257. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  258. //获取配置
  259. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  260. //获取数值在正常范围内的总数
  261. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  262. c.ServeSuccessJSON(map[string]interface{}{
  263. "patient": patient,
  264. "reference": reference,
  265. "inspections": inspections,
  266. })
  267. } else if s_type == 3 {
  268. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  269. //获取配置
  270. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  271. //获取数值在正常范围内的总数
  272. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  273. c.ServeSuccessJSON(map[string]interface{}{
  274. "patient": patient,
  275. "reference": reference,
  276. "inspections": inspections,
  277. })
  278. } else {
  279. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  280. //获取配置
  281. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  282. //获取数值在正常范围内的总数
  283. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
  284. c.ServeSuccessJSON(map[string]interface{}{
  285. "patient": patient,
  286. "reference": reference,
  287. "inspections": inspections,
  288. })
  289. }
  290. }
  291. func (c *StatisticsApiController) GetStatistics() {
  292. adminUserInfo := c.GetAdminUserInfo()
  293. // thisTime := time.Now()
  294. year, month, day := time.Now().Date()
  295. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  296. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  297. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  298. todayWeek := int(todayTime.Weekday())
  299. if todayWeek == 0 {
  300. todayWeek = 7
  301. }
  302. weekEnd := 7 - todayWeek
  303. weekStart := weekEnd - 6
  304. // endDay := todayTime.AddDate(0, 0, weekEnd)
  305. startDay := todayTime.AddDate(0, 0, weekStart)
  306. //患者总数
  307. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  308. //今日透析
  309. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  310. //本周透析
  311. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  312. //传染病
  313. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  314. //性别分布
  315. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  316. //年龄分布
  317. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  318. //透析模式
  319. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  320. c.ServeSuccessJSON(map[string]interface{}{
  321. "patient_count": patientCount,
  322. "today_dialysis_count": todayDialysisCount,
  323. "week_daylysis_count": weekDaylysisCount,
  324. "disease_counts": diseaseCounts,
  325. "gender_counts": genderCounts,
  326. "age_counts": ageCounts,
  327. "mode_counts": modeCounts,
  328. })
  329. }