analysis_api_controller.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. package admin_api_controllers
  2. import (
  3. "XT_Admin_Api/models"
  4. "XT_Admin_Api/models/admin_models"
  5. "XT_Admin_Api/service"
  6. "XT_Admin_Api/utils"
  7. "time"
  8. )
  9. type AnalysisAPIController struct {
  10. AdminBaseAPIAuthController
  11. // AdminBaseAPIController
  12. }
  13. // /admin/api/org/regist [get] RegistOrg
  14. func (this *AnalysisAPIController) RegistOrg() {
  15. totalOrg, getTotalOrgErr := service.GetTotalOrgCount()
  16. if getTotalOrgErr != nil {
  17. this.ErrorLog("获取总机构数失败:%v", getTotalOrgErr)
  18. }
  19. now := time.Now()
  20. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  21. registOrgCountToday, getRegistOrgCountTodayErr := service.GetRegistedOrgCountFromDayToDay(zeroHourTimeOfToday, now)
  22. if getRegistOrgCountTodayErr != nil {
  23. this.ErrorLog("获取今日注册机构数失败:%v", getRegistOrgCountTodayErr)
  24. }
  25. monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  26. registOrgCountThisWeek, getRegistOrgCountThisWeekErr := service.GetRegistedOrgCountFromDayToDay(monday, sunday)
  27. if getRegistOrgCountThisWeekErr != nil {
  28. this.ErrorLog("获取本周注册机构数失败:%v", getRegistOrgCountThisWeekErr)
  29. }
  30. thisYear := now.Year()
  31. thisMonth := int(now.Month())
  32. beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
  33. registOrgCountThisMonth, getRegistOrgCountThisMonthErr := service.GetRegistedOrgCountFromDayToDay(beginningOfMonth, endOfMonth)
  34. if getRegistOrgCountThisMonthErr != nil {
  35. this.ErrorLog("获取本月注册机构数失败:%v", getRegistOrgCountThisMonthErr)
  36. }
  37. monthRegistOrgCounts := make([]map[string]interface{}, 0, 12)
  38. for m := 1; m < 12; m++ {
  39. if m > thisMonth {
  40. break
  41. }
  42. if m == thisMonth {
  43. monthRegistOrgCounts = append(monthRegistOrgCounts, map[string]interface{}{
  44. "month": m,
  45. "count": registOrgCountThisMonth,
  46. })
  47. } else {
  48. BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
  49. registOrgCount, getRegistOrgCountErr := service.GetRegistedOrgCountFromDayToDay(BOM, EOM)
  50. if getRegistOrgCountErr != nil {
  51. this.ErrorLog("获取%v月注册机构数失败:%v", m, getRegistOrgCountErr)
  52. }
  53. monthRegistOrgCounts = append(monthRegistOrgCounts, map[string]interface{}{
  54. "month": m,
  55. "count": registOrgCount,
  56. })
  57. }
  58. }
  59. registOrgsThisWeek, getRegistOrgThisWeekErr := service.GetRegistedOrgsFromDayToDay(monday, sunday)
  60. if getRegistOrgThisWeekErr != nil {
  61. this.ErrorLog("获取本周注册机构失败:%v", getRegistOrgThisWeekErr)
  62. registOrgsThisWeek = make([]*models.Org, 0)
  63. }
  64. registOrgsThisMonth, getRegistOrgThisMonthErr := service.GetRegistedOrgsFromDayToDay(beginningOfMonth, endOfMonth)
  65. if getRegistOrgThisMonthErr != nil {
  66. this.ErrorLog("获取本月注册机构失败:%v", getRegistOrgThisMonthErr)
  67. registOrgsThisMonth = make([]*models.Org, 0)
  68. }
  69. this.ServeSuccessJSON(map[string]interface{}{
  70. "total_org_count": totalOrg,
  71. "regist_org_count_today": registOrgCountToday,
  72. "regist_org_count_week": registOrgCountThisWeek,
  73. "regist_org_count_month": registOrgCountThisMonth,
  74. "regist_org_count_months": monthRegistOrgCounts,
  75. "regist_orgs_week": registOrgsThisWeek,
  76. "regist_orgs_month": registOrgsThisMonth,
  77. })
  78. }
  79. // /admin/api/org/active [get] ActiveOrg
  80. func (this *AnalysisAPIController) ActiveOrg() {
  81. now := time.Now()
  82. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  83. activeOrgCountToday, getActiveTodayErr := service.GetActiveOrgCountFromDayToDay(zeroHourTimeOfToday, now)
  84. if getActiveTodayErr != nil {
  85. this.ErrorLog("获取今日活跃机构数失败:%v", getActiveTodayErr)
  86. }
  87. monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  88. activeOrgCountThisWeek, getActiveOrgCountThisWeekErr := service.GetActiveOrgCountFromDayToDay(monday, sunday)
  89. if getActiveOrgCountThisWeekErr != nil {
  90. this.ErrorLog("获取本周活跃机构数失败:%v", getActiveOrgCountThisWeekErr)
  91. }
  92. thisYear := now.Year()
  93. thisMonth := int(now.Month())
  94. beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
  95. activeOrgCountThisMonth, getActiveOrgCountThisMonthErr := service.GetActiveOrgCountFromDayToDay(beginningOfMonth, endOfMonth)
  96. if getActiveOrgCountThisMonthErr != nil {
  97. this.ErrorLog("获取本月活跃机构数失败:%v", getActiveOrgCountThisMonthErr)
  98. }
  99. monthActiveOrgCounts := make([]map[string]interface{}, 0, 12)
  100. for m := 1; m < 12; m++ {
  101. if m > thisMonth {
  102. break
  103. }
  104. if m == thisMonth {
  105. monthActiveOrgCounts = append(monthActiveOrgCounts, map[string]interface{}{
  106. "month": m,
  107. "count": activeOrgCountThisMonth,
  108. })
  109. } else {
  110. BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
  111. activeOrgCount, getActiveOrgCountErr := service.GetActiveOrgCountFromDayToDay(BOM, EOM)
  112. if getActiveOrgCountErr != nil {
  113. this.ErrorLog("获取%v月活跃机构数失败:%v", m, getActiveOrgCountErr)
  114. }
  115. monthActiveOrgCounts = append(monthActiveOrgCounts, map[string]interface{}{
  116. "month": m,
  117. "count": activeOrgCount,
  118. })
  119. }
  120. }
  121. activeOrgsThisWeek, getActiveOrgThisWeekErr := service.GetActiveOrgsFromDayToDay(monday, sunday)
  122. if getActiveOrgThisWeekErr != nil {
  123. this.ErrorLog("获取本周活跃机构失败:%v", getActiveOrgThisWeekErr)
  124. activeOrgsThisWeek = make([]*service.ActiveOrgListVM, 0)
  125. }
  126. activeOrgsThisMonth, getActiveOrgThisMonthErr := service.GetActiveOrgsFromDayToDay(beginningOfMonth, endOfMonth)
  127. if getActiveOrgThisMonthErr != nil {
  128. this.ErrorLog("获取本月活跃机构失败:%v", getActiveOrgThisMonthErr)
  129. activeOrgsThisMonth = make([]*service.ActiveOrgListVM, 0)
  130. }
  131. this.ServeSuccessJSON(map[string]interface{}{
  132. "active_org_count_today": activeOrgCountToday,
  133. "active_org_count_week": activeOrgCountThisWeek,
  134. "active_org_count_month": activeOrgCountThisMonth,
  135. "active_org_count_months": monthActiveOrgCounts,
  136. "active_orgs_week": activeOrgsThisWeek,
  137. "active_orgs_month": activeOrgsThisMonth,
  138. })
  139. }
  140. // /admin/api/user/active [get] ActiveUser
  141. func (this *AnalysisAPIController) ActiveUser() {
  142. now := time.Now()
  143. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  144. activeAdminCountToday, getActiveTodayErr := service.GetActiveAdminUserCountFromDayToDay(zeroHourTimeOfToday, now)
  145. if getActiveTodayErr != nil {
  146. this.ErrorLog("获取今日活跃账户数失败:%v", getActiveTodayErr)
  147. }
  148. monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  149. activeAdminCountThisWeek, getActiveAdminCountThisWeekErr := service.GetActiveAdminUserCountFromDayToDay(monday, sunday)
  150. if getActiveAdminCountThisWeekErr != nil {
  151. this.ErrorLog("获取本周活跃账户数失败:%v", getActiveAdminCountThisWeekErr)
  152. }
  153. thisYear := now.Year()
  154. thisMonth := int(now.Month())
  155. beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
  156. activeAdminCountThisMonth, getActiveAdminCountThisMonthErr := service.GetActiveAdminUserCountFromDayToDay(beginningOfMonth, endOfMonth)
  157. if getActiveAdminCountThisMonthErr != nil {
  158. this.ErrorLog("获取本月活跃账户数失败:%v", getActiveAdminCountThisMonthErr)
  159. }
  160. monthActiveAdminCounts := make([]map[string]interface{}, 0, 12)
  161. for m := 1; m < 12; m++ {
  162. if m > thisMonth {
  163. break
  164. }
  165. if m == thisMonth {
  166. monthActiveAdminCounts = append(monthActiveAdminCounts, map[string]interface{}{
  167. "month": m,
  168. "count": activeAdminCountThisMonth,
  169. })
  170. } else {
  171. BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
  172. activeAdminCount, getActiveAdminCountErr := service.GetActiveAdminUserCountFromDayToDay(BOM, EOM)
  173. if getActiveAdminCountErr != nil {
  174. this.ErrorLog("获取%v月活跃账户数失败:%v", m, getActiveAdminCountErr)
  175. }
  176. monthActiveAdminCounts = append(monthActiveAdminCounts, map[string]interface{}{
  177. "month": m,
  178. "count": activeAdminCount,
  179. })
  180. }
  181. }
  182. activeAdminsThisWeek, getActiveAdminThisWeekErr := service.GetActiveAdminUsersFromDayToDay(monday, sunday)
  183. if getActiveAdminThisWeekErr != nil {
  184. this.ErrorLog("获取本周活跃账户失败:%v", getActiveAdminThisWeekErr)
  185. activeAdminsThisWeek = make([]*service.ActiveAdminUserListVM, 0)
  186. }
  187. activeAdminsThisMonth, getActiveAdminThisMonthErr := service.GetActiveAdminUsersFromDayToDay(beginningOfMonth, endOfMonth)
  188. if getActiveAdminThisMonthErr != nil {
  189. this.ErrorLog("获取本月活跃账户失败:%v", getActiveAdminThisMonthErr)
  190. activeAdminsThisMonth = make([]*service.ActiveAdminUserListVM, 0)
  191. }
  192. this.ServeSuccessJSON(map[string]interface{}{
  193. "active_admin_count_today": activeAdminCountToday,
  194. "active_admin_count_week": activeAdminCountThisWeek,
  195. "active_admin_count_month": activeAdminCountThisMonth,
  196. "active_admin_count_months": monthActiveAdminCounts,
  197. "active_admins_week": activeAdminsThisWeek,
  198. "active_admins_month": activeAdminsThisMonth,
  199. })
  200. }
  201. // /admin/api/org/expiring [get] ExpiringOrg
  202. func (this *AnalysisAPIController) ExpiringOrg() {
  203. now := time.Now()
  204. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  205. // endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
  206. timeAfter15Days := zeroHourTimeOfToday.AddDate(0, 0, 15)
  207. timeBefore15Days := zeroHourTimeOfToday.AddDate(0, 0, -15)
  208. countOfWillExpireOrg, getWillExpireOrgCountErr := service.GetWillExpireOrgCountFromDayToDay(zeroHourTimeOfToday, timeAfter15Days)
  209. if getWillExpireOrgCountErr != nil {
  210. this.ErrorLog("获取即将到期机构数失败:%v", getWillExpireOrgCountErr)
  211. }
  212. countOfExpiredOrg, getExpiredOrgCountErr := service.GetDidExpiredOrgCountFromDayToDay(timeBefore15Days, zeroHourTimeOfToday)
  213. if getExpiredOrgCountErr != nil {
  214. this.ErrorLog("获取刚到期机构数失败:%v", getExpiredOrgCountErr)
  215. }
  216. willExpireOrgs, getWillExpireOrgsErr := service.GetWillExpireOrgsFromDayToDay(zeroHourTimeOfToday, timeAfter15Days)
  217. if getWillExpireOrgsErr != nil {
  218. this.ErrorLog("获取即将到期机构失败:%v", getWillExpireOrgsErr)
  219. willExpireOrgs = make([]*service.ExpireOrgListVM, 0, 0)
  220. }
  221. expiredOrgs, getExpiredOrgsErr := service.GetDidExpireOrgsFromDayToDay(timeBefore15Days, zeroHourTimeOfToday)
  222. if getExpiredOrgsErr != nil {
  223. this.ErrorLog("获取已到期机构失败:%v", getExpiredOrgsErr)
  224. expiredOrgs = make([]*service.ExpireOrgListVM, 0, 0)
  225. }
  226. this.ServeSuccessJSON(map[string]interface{}{
  227. "will_expire_org_count": countOfWillExpireOrg,
  228. "did_expired_org_count": countOfExpiredOrg,
  229. "will_expire_orgs": willExpireOrgs,
  230. "did_expired_orgs": expiredOrgs,
  231. })
  232. }
  233. // /admin/api/dialysis/analysis [get] DialysisAnalysis
  234. func (this *AnalysisAPIController) DialysisAnalysis() {
  235. now := time.Now()
  236. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  237. endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
  238. timesToday, getTimesTodayErr := service.GetDialysisTimesFromDayToDay(zeroHourTimeOfToday, endTimeOfToday)
  239. if getTimesTodayErr != nil {
  240. this.ErrorLog("获取今日透析次数失败:%v", getTimesTodayErr)
  241. }
  242. monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  243. timesThisWeek, getTimesThisWeekErr := service.GetDialysisTimesFromDayToDay(monday, sunday)
  244. if getTimesThisWeekErr != nil {
  245. this.ErrorLog("获取本周透析次数失败:%v", getTimesThisWeekErr)
  246. }
  247. thisYear := now.Year()
  248. thisMonth := int(now.Month())
  249. beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
  250. timesThisMonth, getTimesThisMonthErr := service.GetDialysisTimesFromDayToDay(beginningOfMonth, endOfMonth)
  251. if getTimesThisMonthErr != nil {
  252. this.ErrorLog("获取本月透析次数失败:%v", getTimesThisMonthErr)
  253. }
  254. monthTimes := make([]map[string]interface{}, 0, 12)
  255. for m := 1; m < 12; m++ {
  256. if m > thisMonth {
  257. break
  258. }
  259. if m == thisMonth {
  260. monthTimes = append(monthTimes, map[string]interface{}{
  261. "month": m,
  262. "count": timesThisMonth,
  263. })
  264. } else {
  265. BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
  266. times, getTimesErr := service.GetDialysisTimesFromDayToDay(BOM, EOM)
  267. if getTimesErr != nil {
  268. this.ErrorLog("获取%v月透析次数失败:%v", m, getTimesErr)
  269. }
  270. monthTimes = append(monthTimes, map[string]interface{}{
  271. "month": m,
  272. "count": times,
  273. })
  274. }
  275. }
  276. this.ServeSuccessJSON(map[string]interface{}{
  277. "times_today": timesToday,
  278. "times_week": timesThisWeek,
  279. "times_month": timesThisMonth,
  280. "times_months": monthTimes,
  281. })
  282. }
  283. // /admin/api/monitor/analysis [get] MonitorAnalysis
  284. func (this *AnalysisAPIController) MonitorAnalysis() {
  285. now := time.Now()
  286. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  287. endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
  288. timesToday, getTimesTodayErr := service.GetMonitoringTimesFromDayToDay(zeroHourTimeOfToday, endTimeOfToday)
  289. if getTimesTodayErr != nil {
  290. this.ErrorLog("获取今日监控次数失败:%v", getTimesTodayErr)
  291. }
  292. monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  293. timesThisWeek, getTimesThisWeekErr := service.GetMonitoringTimesFromDayToDay(monday, sunday)
  294. if getTimesThisWeekErr != nil {
  295. this.ErrorLog("获取本周监控次数失败:%v", getTimesThisWeekErr)
  296. }
  297. thisYear := now.Year()
  298. thisMonth := int(now.Month())
  299. beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
  300. timesThisMonth, getTimesThisMonthErr := service.GetMonitoringTimesFromDayToDay(beginningOfMonth, endOfMonth)
  301. if getTimesThisMonthErr != nil {
  302. this.ErrorLog("获取本月监控次数失败:%v", getTimesThisMonthErr)
  303. }
  304. monthTimes := make([]map[string]interface{}, 0, 12)
  305. for m := 1; m < 12; m++ {
  306. if m > thisMonth {
  307. break
  308. }
  309. if m == thisMonth {
  310. monthTimes = append(monthTimes, map[string]interface{}{
  311. "month": m,
  312. "count": timesThisMonth,
  313. })
  314. } else {
  315. BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
  316. times, getTimesErr := service.GetMonitoringTimesFromDayToDay(BOM, EOM)
  317. if getTimesErr != nil {
  318. this.ErrorLog("获取%v月监控次数失败:%v", m, getTimesErr)
  319. }
  320. monthTimes = append(monthTimes, map[string]interface{}{
  321. "month": m,
  322. "count": times,
  323. })
  324. }
  325. }
  326. this.ServeSuccessJSON(map[string]interface{}{
  327. "times_today": timesToday,
  328. "times_week": timesThisWeek,
  329. "times_month": timesThisMonth,
  330. "times_months": monthTimes,
  331. })
  332. }
  333. // /admin/api/patient/analysis [get] PatientAnalysis
  334. func (this *AnalysisAPIController) PatientAnalysis() {
  335. now := time.Now()
  336. zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
  337. newCountToday, getNewCountTodayErr := service.GetNewPatientCountFromDayToDay(zeroHourTimeOfToday, now)
  338. if getNewCountTodayErr != nil {
  339. this.ErrorLog("获取今日新增病人数失败:%v", getNewCountTodayErr)
  340. }
  341. monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
  342. newCountThisWeek, getNewCountThisWeekErr := service.GetNewPatientCountFromDayToDay(monday, sunday)
  343. if getNewCountThisWeekErr != nil {
  344. this.ErrorLog("获取本周新增病人数失败:%v", getNewCountThisWeekErr)
  345. }
  346. thisYear := now.Year()
  347. thisMonth := int(now.Month())
  348. beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
  349. newCountThisMonth, getNewCountThisMonthErr := service.GetNewPatientCountFromDayToDay(beginningOfMonth, endOfMonth)
  350. if getNewCountThisMonthErr != nil {
  351. this.ErrorLog("获取本月新增病人数失败:%v", getNewCountThisMonthErr)
  352. }
  353. monthNewCounts := make([]map[string]interface{}, 0, 12)
  354. for m := 1; m < 12; m++ {
  355. if m > thisMonth {
  356. break
  357. }
  358. if m == thisMonth {
  359. monthNewCounts = append(monthNewCounts, map[string]interface{}{
  360. "month": m,
  361. "count": newCountThisMonth,
  362. })
  363. } else {
  364. BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
  365. newCount, getNewCountErr := service.GetNewPatientCountFromDayToDay(BOM, EOM)
  366. if getNewCountErr != nil {
  367. this.ErrorLog("获取%v月新增病人数失败:%v", m, getNewCountErr)
  368. }
  369. monthNewCounts = append(monthNewCounts, map[string]interface{}{
  370. "month": m,
  371. "count": newCount,
  372. })
  373. }
  374. }
  375. maleCount, femaleCount, unknowGenderCount, getGenderCountErr := service.GetPatientGenderDistribution()
  376. if getGenderCountErr != nil {
  377. this.ErrorLog("获取病人性别分布失败:%v", getGenderCountErr)
  378. }
  379. // 1乙肝 2丙肝 3艾滋病 4肺结核 5梅毒
  380. // 不写错误日志了,累了
  381. normalPCount, _ := service.GetInfectiousDiseasePatientCount(0)
  382. type1PCount, _ := service.GetInfectiousDiseasePatientCount(1)
  383. type2PCount, _ := service.GetInfectiousDiseasePatientCount(2)
  384. type3PCount, _ := service.GetInfectiousDiseasePatientCount(3)
  385. type4PCount, _ := service.GetInfectiousDiseasePatientCount(4)
  386. type5PCount, _ := service.GetInfectiousDiseasePatientCount(5)
  387. ageDistribution, getAgeDistributionErr := service.GetPatientAgeDistribution()
  388. if getAgeDistributionErr != nil {
  389. this.ErrorLog("获取病人年龄分布失败:%v", getAgeDistributionErr)
  390. ageDistribution = make([]*service.PatientAgeCountStruct, 0, 0)
  391. }
  392. this.ServeSuccessJSON(map[string]interface{}{
  393. "new_patient_count_today": newCountToday,
  394. "new_patient_count_week": newCountThisWeek,
  395. "new_patient_count_month": newCountThisMonth,
  396. "new_patient_count_months": monthNewCounts,
  397. "male_count": maleCount,
  398. "female_count": femaleCount,
  399. "total_count": maleCount + femaleCount + unknowGenderCount,
  400. "disease_type_0_count": normalPCount,
  401. "disease_type_1_count": type1PCount,
  402. "disease_type_2_count": type2PCount,
  403. "disease_type_3_count": type3PCount,
  404. "disease_type_4_count": type4PCount,
  405. "disease_type_5_count": type5PCount,
  406. "age_counts": ageDistribution,
  407. })
  408. }
  409. func (this *AnalysisAPIController) HomeStatistics() {
  410. range_data := this.GetString("range_data")
  411. range_type, _ := this.GetInt64("range_type")
  412. var rangeDate *time.Time
  413. var parseDateErr error
  414. var rangeTimeStamp int64
  415. if len(range_data) > 0 {
  416. rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
  417. if parseDateErr != nil {
  418. this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
  419. return
  420. }
  421. rangeTimeStamp = rangeDate.Unix()
  422. } else {
  423. rangeTimeStamp = 0
  424. }
  425. now := time.Now().Unix()
  426. newOrgCount, _ := service.GetRegistedOrgCount(rangeTimeStamp, now)
  427. totalOrg, _ := service.GetTotalOrgCount()
  428. activeOrgCount, _ := service.GetActiveOrgCount(rangeTimeStamp, now)
  429. totalActiveOrg, _ := service.GetActiveOrgTotalCount()
  430. activeAdminCount, _ := service.GetActiveAdminUserCount(rangeTimeStamp, now)
  431. adminTotalCount, _ := service.GetAdminUserTotalCount()
  432. patientCount, _ :=service.GetNewPatientCount(rangeTimeStamp, now)
  433. patientTotalCount, _ := service.GetPatientTotalCount()
  434. var orgRegisterStatistics []*admin_models.Statistics
  435. var newPatientStatistics []*admin_models.Statistics
  436. var orgActiveAdminStatistics []*admin_models.Statistics
  437. var orgActiveStatistics []*admin_models.Statistics
  438. switch range_type {
  439. case 3:
  440. orgRegisterStatistics, _ = service.GetWeekRegistedOrgCount()
  441. newPatientStatistics, _ = service.GetWeekNewPatientCount()
  442. orgActiveAdminStatistics, _ = service.GetWeekActiveAdminUserCount()
  443. orgActiveStatistics,_ = service.GetWeekActiveOrgCount()
  444. //newOrgCount, _ = service.GetWeekRegistedOrgTotalCount()
  445. //activeOrgCount, _ = service.GetWeekRegistedOrgTotalCount()
  446. //activeAdminCount, _ = service.GetWeekRegistedOrgTotalCount()
  447. //activeAdminCount, _ = service.GetWeekRegistedOrgTotalCount()
  448. //
  449. //
  450. break
  451. case 4:
  452. orgRegisterStatistics, _ = service.GetMonthRegistedOrgCount()
  453. newPatientStatistics, _ = service.GetMonthNewPatientCount()
  454. orgActiveAdminStatistics, _ = service.GetMonthActiveAdminUserCount()
  455. orgActiveStatistics,_ = service.GetMonthActiveOrgCount()
  456. break
  457. case 5:
  458. orgRegisterStatistics, _ = service.GetThreeMonthRegistedOrgCount()
  459. newPatientStatistics, _ = service.GetThreeMonthNewPatientCount()
  460. orgActiveAdminStatistics, _ = service.GetThreeMonthActiveAdminUserCount()
  461. orgActiveStatistics,_ = service.GetThreeMonthActiveOrgCount()
  462. break
  463. case 6:
  464. orgRegisterStatistics, _ = service.GetSixMonthRegistedOrgCount()
  465. newPatientStatistics, _ = service.GetSixMonthNewPatientCount()
  466. orgActiveAdminStatistics, _ = service.GetSixMonthActiveAdminUserCount()
  467. orgActiveStatistics,_ = service.GetSixMonthActiveOrgCount()
  468. break
  469. case 7:
  470. orgRegisterStatistics, _ = service.GetYearRegistedOrgCount()
  471. newPatientStatistics, _ = service.GetYearNewPatientCount()
  472. orgActiveAdminStatistics, _ = service.GetYearActiveAdminUserCount()
  473. orgActiveStatistics,_ = service.GetYearActiveOrgCount()
  474. break
  475. }
  476. this.ServeSuccessJSON(map[string]interface{}{
  477. "org_count": newOrgCount,
  478. "org_total_count": totalOrg,
  479. "active_org_count": activeOrgCount,
  480. "active_org_total_count": totalActiveOrg,
  481. "active_admin_count": activeAdminCount,
  482. "active_admin_total_count": adminTotalCount,
  483. "patient_count": patientCount,
  484. "patient_total_count": patientTotalCount,
  485. "org_count_list": orgRegisterStatistics,
  486. "patient_count_list": newPatientStatistics,
  487. "active_count_list": orgActiveAdminStatistics,
  488. "active_org_list": orgActiveStatistics,
  489. })
  490. }