123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- package admin_api_controllers
-
- import (
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "time"
- )
-
- type AnalysisAPIController struct {
- AdminBaseAPIAuthController
- // AdminBaseAPIController
- }
-
- // /admin/api/org/regist [get] RegistOrg
- func (this *AnalysisAPIController) RegistOrg() {
- totalOrg, getTotalOrgErr := service.GetTotalOrgCount()
- if getTotalOrgErr != nil {
- this.ErrorLog("获取总机构数失败:%v", getTotalOrgErr)
- }
-
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- registOrgCountToday, getRegistOrgCountTodayErr := service.GetRegistedOrgCountFromDayToDay(zeroHourTimeOfToday, now)
- if getRegistOrgCountTodayErr != nil {
- this.ErrorLog("获取今日注册机构数失败:%v", getRegistOrgCountTodayErr)
- }
-
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- registOrgCountThisWeek, getRegistOrgCountThisWeekErr := service.GetRegistedOrgCountFromDayToDay(monday, sunday)
- if getRegistOrgCountThisWeekErr != nil {
- this.ErrorLog("获取本周注册机构数失败:%v", getRegistOrgCountThisWeekErr)
- }
-
- thisYear := now.Year()
- thisMonth := int(now.Month())
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
- registOrgCountThisMonth, getRegistOrgCountThisMonthErr := service.GetRegistedOrgCountFromDayToDay(beginningOfMonth, endOfMonth)
- if getRegistOrgCountThisMonthErr != nil {
- this.ErrorLog("获取本月注册机构数失败:%v", getRegistOrgCountThisMonthErr)
- }
-
- monthRegistOrgCounts := make([]map[string]interface{}, 0, 12)
- for m := 1; m < 12; m++ {
- if m > thisMonth {
- break
- }
- if m == thisMonth {
- monthRegistOrgCounts = append(monthRegistOrgCounts, map[string]interface{}{
- "month": m,
- "count": registOrgCountThisMonth,
- })
-
- } else {
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
- registOrgCount, getRegistOrgCountErr := service.GetRegistedOrgCountFromDayToDay(BOM, EOM)
- if getRegistOrgCountErr != nil {
- this.ErrorLog("获取%v月注册机构数失败:%v", m, getRegistOrgCountErr)
- }
- monthRegistOrgCounts = append(monthRegistOrgCounts, map[string]interface{}{
- "month": m,
- "count": registOrgCount,
- })
- }
- }
-
- registOrgsThisWeek, getRegistOrgThisWeekErr := service.GetRegistedOrgsFromDayToDay(monday, sunday)
- if getRegistOrgThisWeekErr != nil {
- this.ErrorLog("获取本周注册机构失败:%v", getRegistOrgThisWeekErr)
- registOrgsThisWeek = make([]*models.Org, 0)
- }
-
- registOrgsThisMonth, getRegistOrgThisMonthErr := service.GetRegistedOrgsFromDayToDay(beginningOfMonth, endOfMonth)
- if getRegistOrgThisMonthErr != nil {
- this.ErrorLog("获取本月注册机构失败:%v", getRegistOrgThisMonthErr)
- registOrgsThisMonth = make([]*models.Org, 0)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "total_org_count": totalOrg,
- "regist_org_count_today": registOrgCountToday,
- "regist_org_count_week": registOrgCountThisWeek,
- "regist_org_count_month": registOrgCountThisMonth,
- "regist_org_count_months": monthRegistOrgCounts,
- "regist_orgs_week": registOrgsThisWeek,
- "regist_orgs_month": registOrgsThisMonth,
- })
- }
-
- // /admin/api/org/active [get] ActiveOrg
- func (this *AnalysisAPIController) ActiveOrg() {
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- activeOrgCountToday, getActiveTodayErr := service.GetActiveOrgCountFromDayToDay(zeroHourTimeOfToday, now)
- if getActiveTodayErr != nil {
- this.ErrorLog("获取今日活跃机构数失败:%v", getActiveTodayErr)
- }
-
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- activeOrgCountThisWeek, getActiveOrgCountThisWeekErr := service.GetActiveOrgCountFromDayToDay(monday, sunday)
- if getActiveOrgCountThisWeekErr != nil {
- this.ErrorLog("获取本周活跃机构数失败:%v", getActiveOrgCountThisWeekErr)
- }
-
- thisYear := now.Year()
- thisMonth := int(now.Month())
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
- activeOrgCountThisMonth, getActiveOrgCountThisMonthErr := service.GetActiveOrgCountFromDayToDay(beginningOfMonth, endOfMonth)
- if getActiveOrgCountThisMonthErr != nil {
- this.ErrorLog("获取本月活跃机构数失败:%v", getActiveOrgCountThisMonthErr)
- }
-
- monthActiveOrgCounts := make([]map[string]interface{}, 0, 12)
- for m := 1; m < 12; m++ {
- if m > thisMonth {
- break
- }
- if m == thisMonth {
- monthActiveOrgCounts = append(monthActiveOrgCounts, map[string]interface{}{
- "month": m,
- "count": activeOrgCountThisMonth,
- })
-
- } else {
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
- activeOrgCount, getActiveOrgCountErr := service.GetActiveOrgCountFromDayToDay(BOM, EOM)
- if getActiveOrgCountErr != nil {
- this.ErrorLog("获取%v月活跃机构数失败:%v", m, getActiveOrgCountErr)
- }
- monthActiveOrgCounts = append(monthActiveOrgCounts, map[string]interface{}{
- "month": m,
- "count": activeOrgCount,
- })
- }
- }
-
- activeOrgsThisWeek, getActiveOrgThisWeekErr := service.GetActiveOrgsFromDayToDay(monday, sunday)
- if getActiveOrgThisWeekErr != nil {
- this.ErrorLog("获取本周活跃机构失败:%v", getActiveOrgThisWeekErr)
- activeOrgsThisWeek = make([]*service.ActiveOrgListVM, 0)
- }
-
- activeOrgsThisMonth, getActiveOrgThisMonthErr := service.GetActiveOrgsFromDayToDay(beginningOfMonth, endOfMonth)
- if getActiveOrgThisMonthErr != nil {
- this.ErrorLog("获取本月活跃机构失败:%v", getActiveOrgThisMonthErr)
- activeOrgsThisMonth = make([]*service.ActiveOrgListVM, 0)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "active_org_count_today": activeOrgCountToday,
- "active_org_count_week": activeOrgCountThisWeek,
- "active_org_count_month": activeOrgCountThisMonth,
- "active_org_count_months": monthActiveOrgCounts,
- "active_orgs_week": activeOrgsThisWeek,
- "active_orgs_month": activeOrgsThisMonth,
- })
- }
-
- // /admin/api/user/active [get] ActiveUser
- func (this *AnalysisAPIController) ActiveUser() {
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- activeAdminCountToday, getActiveTodayErr := service.GetActiveAdminUserCountFromDayToDay(zeroHourTimeOfToday, now)
- if getActiveTodayErr != nil {
- this.ErrorLog("获取今日活跃账户数失败:%v", getActiveTodayErr)
- }
-
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- activeAdminCountThisWeek, getActiveAdminCountThisWeekErr := service.GetActiveAdminUserCountFromDayToDay(monday, sunday)
- if getActiveAdminCountThisWeekErr != nil {
- this.ErrorLog("获取本周活跃账户数失败:%v", getActiveAdminCountThisWeekErr)
- }
-
- thisYear := now.Year()
- thisMonth := int(now.Month())
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
- activeAdminCountThisMonth, getActiveAdminCountThisMonthErr := service.GetActiveAdminUserCountFromDayToDay(beginningOfMonth, endOfMonth)
- if getActiveAdminCountThisMonthErr != nil {
- this.ErrorLog("获取本月活跃账户数失败:%v", getActiveAdminCountThisMonthErr)
- }
-
- monthActiveAdminCounts := make([]map[string]interface{}, 0, 12)
- for m := 1; m < 12; m++ {
- if m > thisMonth {
- break
- }
- if m == thisMonth {
- monthActiveAdminCounts = append(monthActiveAdminCounts, map[string]interface{}{
- "month": m,
- "count": activeAdminCountThisMonth,
- })
-
- } else {
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
- activeAdminCount, getActiveAdminCountErr := service.GetActiveAdminUserCountFromDayToDay(BOM, EOM)
- if getActiveAdminCountErr != nil {
- this.ErrorLog("获取%v月活跃账户数失败:%v", m, getActiveAdminCountErr)
- }
- monthActiveAdminCounts = append(monthActiveAdminCounts, map[string]interface{}{
- "month": m,
- "count": activeAdminCount,
- })
- }
- }
-
- activeAdminsThisWeek, getActiveAdminThisWeekErr := service.GetActiveAdminUsersFromDayToDay(monday, sunday)
- if getActiveAdminThisWeekErr != nil {
- this.ErrorLog("获取本周活跃账户失败:%v", getActiveAdminThisWeekErr)
- activeAdminsThisWeek = make([]*service.ActiveAdminUserListVM, 0)
- }
-
- activeAdminsThisMonth, getActiveAdminThisMonthErr := service.GetActiveAdminUsersFromDayToDay(beginningOfMonth, endOfMonth)
- if getActiveAdminThisMonthErr != nil {
- this.ErrorLog("获取本月活跃账户失败:%v", getActiveAdminThisMonthErr)
- activeAdminsThisMonth = make([]*service.ActiveAdminUserListVM, 0)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "active_admin_count_today": activeAdminCountToday,
- "active_admin_count_week": activeAdminCountThisWeek,
- "active_admin_count_month": activeAdminCountThisMonth,
- "active_admin_count_months": monthActiveAdminCounts,
- "active_admins_week": activeAdminsThisWeek,
- "active_admins_month": activeAdminsThisMonth,
- })
- }
-
- // /admin/api/org/expiring [get] ExpiringOrg
- func (this *AnalysisAPIController) ExpiringOrg() {
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- // endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
- timeAfter15Days := zeroHourTimeOfToday.AddDate(0, 0, 15)
- timeBefore15Days := zeroHourTimeOfToday.AddDate(0, 0, -15)
-
- countOfWillExpireOrg, getWillExpireOrgCountErr := service.GetWillExpireOrgCountFromDayToDay(zeroHourTimeOfToday, timeAfter15Days)
- if getWillExpireOrgCountErr != nil {
- this.ErrorLog("获取即将到期机构数失败:%v", getWillExpireOrgCountErr)
- }
-
- countOfExpiredOrg, getExpiredOrgCountErr := service.GetDidExpiredOrgCountFromDayToDay(timeBefore15Days, zeroHourTimeOfToday)
- if getExpiredOrgCountErr != nil {
- this.ErrorLog("获取刚到期机构数失败:%v", getExpiredOrgCountErr)
- }
-
- willExpireOrgs, getWillExpireOrgsErr := service.GetWillExpireOrgsFromDayToDay(zeroHourTimeOfToday, timeAfter15Days)
- if getWillExpireOrgsErr != nil {
- this.ErrorLog("获取即将到期机构失败:%v", getWillExpireOrgsErr)
- willExpireOrgs = make([]*service.ExpireOrgListVM, 0, 0)
- }
-
- expiredOrgs, getExpiredOrgsErr := service.GetDidExpireOrgsFromDayToDay(timeBefore15Days, zeroHourTimeOfToday)
- if getExpiredOrgsErr != nil {
- this.ErrorLog("获取已到期机构失败:%v", getExpiredOrgsErr)
- expiredOrgs = make([]*service.ExpireOrgListVM, 0, 0)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "will_expire_org_count": countOfWillExpireOrg,
- "did_expired_org_count": countOfExpiredOrg,
- "will_expire_orgs": willExpireOrgs,
- "did_expired_orgs": expiredOrgs,
- })
- }
-
- // /admin/api/dialysis/analysis [get] DialysisAnalysis
- func (this *AnalysisAPIController) DialysisAnalysis() {
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
-
- timesToday, getTimesTodayErr := service.GetDialysisTimesFromDayToDay(zeroHourTimeOfToday, endTimeOfToday)
- if getTimesTodayErr != nil {
- this.ErrorLog("获取今日透析次数失败:%v", getTimesTodayErr)
- }
-
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- timesThisWeek, getTimesThisWeekErr := service.GetDialysisTimesFromDayToDay(monday, sunday)
- if getTimesThisWeekErr != nil {
- this.ErrorLog("获取本周透析次数失败:%v", getTimesThisWeekErr)
- }
-
- thisYear := now.Year()
- thisMonth := int(now.Month())
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
- timesThisMonth, getTimesThisMonthErr := service.GetDialysisTimesFromDayToDay(beginningOfMonth, endOfMonth)
- if getTimesThisMonthErr != nil {
- this.ErrorLog("获取本月透析次数失败:%v", getTimesThisMonthErr)
- }
-
- monthTimes := make([]map[string]interface{}, 0, 12)
- for m := 1; m < 12; m++ {
- if m > thisMonth {
- break
- }
- if m == thisMonth {
- monthTimes = append(monthTimes, map[string]interface{}{
- "month": m,
- "count": timesThisMonth,
- })
-
- } else {
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
- times, getTimesErr := service.GetDialysisTimesFromDayToDay(BOM, EOM)
- if getTimesErr != nil {
- this.ErrorLog("获取%v月透析次数失败:%v", m, getTimesErr)
- }
- monthTimes = append(monthTimes, map[string]interface{}{
- "month": m,
- "count": times,
- })
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "times_today": timesToday,
- "times_week": timesThisWeek,
- "times_month": timesThisMonth,
- "times_months": monthTimes,
- })
- }
-
- // /admin/api/monitor/analysis [get] MonitorAnalysis
- func (this *AnalysisAPIController) MonitorAnalysis() {
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
-
- timesToday, getTimesTodayErr := service.GetMonitoringTimesFromDayToDay(zeroHourTimeOfToday, endTimeOfToday)
- if getTimesTodayErr != nil {
- this.ErrorLog("获取今日监控次数失败:%v", getTimesTodayErr)
- }
-
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- timesThisWeek, getTimesThisWeekErr := service.GetMonitoringTimesFromDayToDay(monday, sunday)
- if getTimesThisWeekErr != nil {
- this.ErrorLog("获取本周监控次数失败:%v", getTimesThisWeekErr)
- }
-
- thisYear := now.Year()
- thisMonth := int(now.Month())
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
- timesThisMonth, getTimesThisMonthErr := service.GetMonitoringTimesFromDayToDay(beginningOfMonth, endOfMonth)
- if getTimesThisMonthErr != nil {
- this.ErrorLog("获取本月监控次数失败:%v", getTimesThisMonthErr)
- }
-
- monthTimes := make([]map[string]interface{}, 0, 12)
- for m := 1; m < 12; m++ {
- if m > thisMonth {
- break
- }
- if m == thisMonth {
- monthTimes = append(monthTimes, map[string]interface{}{
- "month": m,
- "count": timesThisMonth,
- })
-
- } else {
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
- times, getTimesErr := service.GetMonitoringTimesFromDayToDay(BOM, EOM)
- if getTimesErr != nil {
- this.ErrorLog("获取%v月监控次数失败:%v", m, getTimesErr)
- }
- monthTimes = append(monthTimes, map[string]interface{}{
- "month": m,
- "count": times,
- })
- }
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "times_today": timesToday,
- "times_week": timesThisWeek,
- "times_month": timesThisMonth,
- "times_months": monthTimes,
- })
- }
-
- // /admin/api/patient/analysis [get] PatientAnalysis
- func (this *AnalysisAPIController) PatientAnalysis() {
- now := time.Now()
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
- newCountToday, getNewCountTodayErr := service.GetNewPatientCountFromDayToDay(zeroHourTimeOfToday, now)
- if getNewCountTodayErr != nil {
- this.ErrorLog("获取今日新增病人数失败:%v", getNewCountTodayErr)
- }
-
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- newCountThisWeek, getNewCountThisWeekErr := service.GetNewPatientCountFromDayToDay(monday, sunday)
- if getNewCountThisWeekErr != nil {
- this.ErrorLog("获取本周新增病人数失败:%v", getNewCountThisWeekErr)
- }
-
- thisYear := now.Year()
- thisMonth := int(now.Month())
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
- newCountThisMonth, getNewCountThisMonthErr := service.GetNewPatientCountFromDayToDay(beginningOfMonth, endOfMonth)
- if getNewCountThisMonthErr != nil {
- this.ErrorLog("获取本月新增病人数失败:%v", getNewCountThisMonthErr)
- }
-
- monthNewCounts := make([]map[string]interface{}, 0, 12)
- for m := 1; m < 12; m++ {
- if m > thisMonth {
- break
- }
- if m == thisMonth {
- monthNewCounts = append(monthNewCounts, map[string]interface{}{
- "month": m,
- "count": newCountThisMonth,
- })
-
- } else {
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
- newCount, getNewCountErr := service.GetNewPatientCountFromDayToDay(BOM, EOM)
- if getNewCountErr != nil {
- this.ErrorLog("获取%v月新增病人数失败:%v", m, getNewCountErr)
- }
- monthNewCounts = append(monthNewCounts, map[string]interface{}{
- "month": m,
- "count": newCount,
- })
- }
- }
-
- maleCount, femaleCount, unknowGenderCount, getGenderCountErr := service.GetPatientGenderDistribution()
- if getGenderCountErr != nil {
- this.ErrorLog("获取病人性别分布失败:%v", getGenderCountErr)
- }
-
- // 1乙肝 2丙肝 3艾滋病 4肺结核 5梅毒
- // 不写错误日志了,累了
- normalPCount, _ := service.GetInfectiousDiseasePatientCount(0)
- type1PCount, _ := service.GetInfectiousDiseasePatientCount(1)
- type2PCount, _ := service.GetInfectiousDiseasePatientCount(2)
- type3PCount, _ := service.GetInfectiousDiseasePatientCount(3)
- type4PCount, _ := service.GetInfectiousDiseasePatientCount(4)
- type5PCount, _ := service.GetInfectiousDiseasePatientCount(5)
-
- ageDistribution, getAgeDistributionErr := service.GetPatientAgeDistribution()
- if getAgeDistributionErr != nil {
- this.ErrorLog("获取病人年龄分布失败:%v", getAgeDistributionErr)
- ageDistribution = make([]*service.PatientAgeCountStruct, 0, 0)
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "new_patient_count_today": newCountToday,
- "new_patient_count_week": newCountThisWeek,
- "new_patient_count_month": newCountThisMonth,
- "new_patient_count_months": monthNewCounts,
-
- "male_count": maleCount,
- "female_count": femaleCount,
- "total_count": maleCount + femaleCount + unknowGenderCount,
-
- "disease_type_0_count": normalPCount,
- "disease_type_1_count": type1PCount,
- "disease_type_2_count": type2PCount,
- "disease_type_3_count": type3PCount,
- "disease_type_4_count": type4PCount,
- "disease_type_5_count": type5PCount,
-
- "age_counts": ageDistribution,
- })
- }
|