package controllers import ( "XT_New/enums" "XT_New/service" "XT_New/utils" "fmt" "github.com/astaxie/beego" "strconv" "time" ) type StatisticsApiController struct { BaseAuthAPIController } func StatisticsApiRegistRouters() { beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics") beego.Router("/api/qc/statistiscall/get", &StatisticsApiController{}, "get:GetAllInspectionStatistisc") beego.Router("/api/qc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonInspectionStatistisc") beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc") //beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc") //beego.Router("/api/qc/statistiscperson/export", &StatisticsApiController{}, "get:ExportPersonInspectionStatistisc") } func (c *StatisticsApiController) GetPatientInspectionStatistisc() { start_date := c.GetString("start_date") end_date := c.GetString("end_date") project_id, _ := c.GetInt64("project_id") item_id, _ := c.GetInt64("item_id") item_type, _ := c.GetInt64("item_type") //order_type, _ := c.GetInt64("order_type") keyword := c.GetString("keyword") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") var startTime int64 if len(start_date) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc) fmt.Println("err-----------", err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startTime = theTime.Unix() } var endTime int64 if len(end_date) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } //获取配置 reference, _ := service.GetInspectionReferenceThree(project_id, item_id) //获取数值在正常范围内的总数 max, _ := strconv.ParseFloat(reference.RangeMax, 64) min, _ := strconv.ParseFloat(reference.RangeMin, 64) switch item_type { case 0: break case 1: list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword) c.ServeSuccessJSON(map[string]interface{}{ "list": list, "reference": reference, }) break case 2: list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword) c.ServeSuccessJSON(map[string]interface{}{ "list": list, "reference": reference, }) break case 3: list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword) c.ServeSuccessJSON(map[string]interface{}{ "list": list, "reference": reference, }) break } } func (c *StatisticsApiController) GetAllInspectionStatistisc() { start_date := c.GetString("start_date") end_date := c.GetString("end_date") project_id, _ := c.GetInt64("project_id") item_id, _ := c.GetInt64("item_id") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") var startTime int64 if len(start_date) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc) fmt.Println("err-----------", err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startTime = theTime.Unix() } var endTime int64 if len(end_date) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } //患者总数 patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId) //获取配置 reference, _ := service.GetInspectionReferenceThree(project_id, item_id) //获取数值在正常范围内的总数 max, _ := strconv.ParseFloat(reference.RangeMax, 64) min, _ := strconv.ParseFloat(reference.RangeMin, 64) normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min) //获取数值异常的总数 unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min) //获取没有检查的患者总数 noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID) c.ServeSuccessJSON(map[string]interface{}{ "patient_count": patientCount, "normal_total": normalTotal, "unusual_total": unusualTotal, "no_check_total": noCheckTotal, "reference": reference, }) } func (c *StatisticsApiController) GetPersonInspectionStatistisc() { start_date := c.GetString("start_time") end_date := c.GetString("end_time") project_id, _ := c.GetInt64("project_id") item_id, _ := c.GetInt64("item_id") patient_id, _ := c.GetInt64("patient_id") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") var startTime int64 if len(start_date) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc) fmt.Println("err-----------", err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startTime = theTime.Unix() } var endTime int64 if len(end_date) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id) //获取配置 reference, _ := service.GetInspectionReferenceThree(project_id, item_id) //获取数值在正常范围内的总数 inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id) c.ServeSuccessJSON(map[string]interface{}{ "patient": patient, "reference": reference, "inspections": inspections, }) } func (c *StatisticsApiController) GetStatistics() { adminUserInfo := c.GetAdminUserInfo() // thisTime := time.Now() year, month, day := time.Now().Date() todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local) startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local) endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local) todayWeek := int(todayTime.Weekday()) if todayWeek == 0 { todayWeek = 7 } weekEnd := 7 - todayWeek weekStart := weekEnd - 6 // endDay := todayTime.AddDate(0, 0, weekEnd) startDay := todayTime.AddDate(0, 0, weekStart) //患者总数 patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId) //今日透析 todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix()) //本周透析 weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix()) //传染病 diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId) //性别分布 genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId) //年龄分布 ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId) //透析模式 modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix()) c.ServeSuccessJSON(map[string]interface{}{ "patient_count": patientCount, "today_dialysis_count": todayDialysisCount, "week_daylysis_count": weekDaylysisCount, "disease_counts": diseaseCounts, "gender_counts": genderCounts, "age_counts": ageCounts, "mode_counts": modeCounts, }) }