analysis_api_controller.go 21KB

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