123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- 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")
-
- beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
-
- }
-
- func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- 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)
- 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()
- }
- list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- 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")
- s_type, _ := c.GetInt64("type")
-
- 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:
- if s_type == 2 { //KTV
- list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else if s_type == 3 { //URR
- list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else {
-
- 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:
- if s_type == 2 { //KTV
- list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else if s_type == 3 { //URR
- list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else {
-
- 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:
- if s_type == 2 { //KTV
- list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else if s_type == 3 { //URR
- list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else {
- 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")
-
- s_type, _ := c.GetInt64("type")
-
- 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)
-
- if s_type == 2 {
- normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
- //获取数值异常的总数
- //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
- unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
-
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- })
-
- } else if s_type == 3 {
-
- normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
- //获取数值异常的总数
- //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
- unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
-
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- })
-
- } else {
-
- 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")
- s_type, _ := c.GetInt64("type")
-
- 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()
- }
-
- if s_type == 2 {
- patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(1014, 10950)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
-
- } else if s_type == 3 {
- patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(1014, 10951)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
-
- } else {
- 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,
- })
-
- }
|