1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "sort"
- "strconv"
- "strings"
- "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/statistiscperson/list", &StatisticsApiController{}, "get:GetInsepctionList")
- beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
- beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
-
- beego.Router("/api/commonqc/statistiscall/get", &StatisticsApiController{}, "get:GetAllCommonInspectionStatistisc")
- beego.Router("/api/commonqc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonCommonInspectionStatistisc")
- beego.Router("/api/commonqc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientCommonInspectionStatistisc")
-
- //透析总量统计
- beego.Router("/api/commonqc/dialysis/total", &StatisticsApiController{}, "get:GetDialysisTotal")
- beego.Router("/api/commonqc/dialysis/detail", &StatisticsApiController{}, "get:GetDialysisTotalDetail")
- beego.Router("/api/commonqc/dialysis/detailsinfo", &StatisticsApiController{}, "get:GetDialysisTotalDetailInfo")
-
- beego.Router("/api/commonqc/anticoagulant", &StatisticsApiController{}, "get:GetAnticoagulant")
- beego.Router("/api/commonqc/anticoagulant/detail", &StatisticsApiController{}, "get:GetAnticoagulantDetail")
-
- beego.Router("/api/commonqc/dialyzer", &StatisticsApiController{}, "get:GetDialyzer")
- beego.Router("/api/commonqc/dialyzer/config", &StatisticsApiController{}, "get:GetDialyzerConfig")
- beego.Router("/api/commonqc/dialyzer/detail", &StatisticsApiController{}, "get:GetDialyzerDetail")
-
- beego.Router("/api/commonqc/dialysistreat/finish", &StatisticsApiController{}, "get:GetDialysisTreatFinsh")
- beego.Router("/api/commonqc/dialysistreat/detail", &StatisticsApiController{}, "get:GetDialysisTreatDetail")
-
- beego.Router("/api/commonqc/patinet/weight", &StatisticsApiController{}, "get:GetPatientWeight")
- beego.Router("/api/commonqc/weight/detail", &StatisticsApiController{}, "get:GetPatientWeightDetail")
- beego.Router("/api/commonqc/patinet/bp", &StatisticsApiController{}, "get:GetPatientBP")
- beego.Router("/api/commonqc/bp/detail", &StatisticsApiController{}, "get:GetPatientBPDetail")
-
- }
- func (c *StatisticsApiController) GetPatientWeight() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- statistics_type, _ := c.GetInt("statistics_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 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_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- item, _ := service.GetNewDialysisWeightChartData(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, statistics_type)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": item,
- })
- }
- func (c *StatisticsApiController) GetPatientWeightDetail() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- add_type, _ := c.GetInt64("add_type")
- dry_type, _ := c.GetInt64("dry_type")
- fmt.Println("dry_type")
- fmt.Println(dry_type)
-
- after_type, _ := c.GetInt64("after_type")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 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_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- data, total, _ := service.GetNewDialysisWeightDetailTableTen(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, dry_type, after_type, page, limit)
- fmt.Println(data)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": data,
- "total": total,
- })
- }
- func (c *StatisticsApiController) GetPatientBP() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- statistics_type, _ := c.GetInt("statistics_type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 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_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- if statistics_type == 1 {
- item, _ := service.GetNewDialysisBPDetailTableTenThree(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": item,
- })
- } else {
- item, _ := service.GetNewDialysisBPDetailTableTenFour(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": item,
- })
- }
-
- }
- func (c *StatisticsApiController) GetPatientBPDetail() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- add_type, _ := c.GetInt64("status_type")
- statistics_type, _ := c.GetInt64("statistics_type")
-
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 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_time) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- var data []service.DialysisDataThree
- var total int64
-
- if statistics_type == 1 {
- data, total, _ = service.GetNewDialysisBPDetailTableTen(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, page, limit)
-
- } else {
-
- data, total, _ = service.GetNewDialysisBPDetailTableTenOne(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, page, limit)
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": data,
- "total": total,
- })
-
- }
-
- func (c *StatisticsApiController) GetDialysisTreatFinsh() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- 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()
- }
- data, _ := service.GetDialysisCompletionRate(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
- total, _ := service.GetDialysisCompletionTotal(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "data": data,
- "total": total,
- })
- }
- func (c *StatisticsApiController) GetDialysisTreatDetail() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- mode, _ := c.GetInt64("mode")
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- 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()
- }
- data, total, _ := service.GetDialysisCompletionDetail(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, mode, limit, page)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": data,
- "total": total,
- })
- }
- func (c *StatisticsApiController) GetDialysisTotal() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- mode, _ := c.GetInt64("mode")
- origin, _ := c.GetInt64("origin")
- time_way, _ := c.GetInt64("time_way")
-
- 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 mode == 0 { //统计透析模式不限
- //获取总人数
- p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
- count_struct, _ := service.GetNewDialysisCountMode(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin, 0)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": p_total,
- "list": count_struct,
- })
- } else { //固定某个模式
- // 拆分日期范围
- dates, err := splitDateRange(start_date, end_date)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
-
- var cuss []models.CustomDialysisData
- p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
- switch time_way {
- case 1:
- // 按周统计
- weeks := groupByWeek(dates)
- fmt.Println(weeks)
- for _, week := range weeks {
- // 解析字符串时显式指定时区为 UTC
- t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[0].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
-
- // 格式化时间时将时区设置为 UTC
- //fmt.Println(t.UTC().Format("2006-01-02 15:04:05"))
-
- var cus models.CustomDialysisData
- //week_date := week[0].Format("2006-01-02") + " 00:00:00"
-
- //date, err := time.Parse("2006-01-02 15:04:05", week_date)
- //if err != nil {
- // fmt.Println("日期解析错误:", err)
- // return
- //}
-
- // 将time.Time类型转换为时间戳(秒)
- //week_start := date.Unix()
-
- // 解析字符串时显式指定时区为 UTC
- t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
-
- //week_end_date := week[len(week)-1].Format("2006-01-02") + " 00:00:00"
-
- //end_date, err := time.Parse("2006-01-02 15:04:05", week_end_date)
- //if err != nil {
- // fmt.Println("日期解析错误:", err)
- // return
- //}
- //
- //// 将time.Time类型转换为时间戳(秒)
- //week_end := end_date.Unix()
-
- counts, _ := service.GetNewDialysisCountModeTwo(t.Unix(), t2.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = strings.Split(week[0].String(), " ")[0] + "~" + strings.Split(week[len(week)-1].String(), " ")[0]
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- break
- case 2:
- startDate, err := time.Parse("2006-01-02", start_date)
- if err != nil {
- fmt.Println("Error parsing start date:", err)
- return
- }
-
- endDate, err := time.Parse("2006-01-02", end_date)
- if err != nil {
- fmt.Println("Error parsing end date:", err)
- return
- }
- dailyDates := splitByDay(startDate, endDate)
- for _, date := range dailyDates {
- //fmt.Println(date)
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(date.Unix(), date.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = date.Format("2006-01-02")
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- break
- case 3:
- // 按月统计
- months := groupByMonth(dates)
- for _, month := range months {
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(month[0].Unix(), month[len(month)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = strings.Split(month[0].String(), " ")[0] + "~" + strings.Split(month[len(month)-1].String(), " ")[0]
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
-
- //fmt.Println("Month:", month[0], "~", month[len(month)-1])
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- break
- case 4:
- // 按年统计
- years := groupByYear(dates)
- for _, year := range years {
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(year[0].Unix(), year[len(year)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = strings.Split(strings.Split(year[0].String(), " ")[0], "-")[0]
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
-
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- break
- }
- }
-
- }
- func (c *StatisticsApiController) GetDialysisTotalDetail() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- mode, _ := c.GetInt64("mode")
- origin, _ := c.GetInt64("origin")
- time_way, _ := c.GetInt64("time_way")
- //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()
- //}
- dates, err := splitDateRange(start_date, end_date)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
-
- if origin == 1 {
- switch time_way {
- case 2:
- weeks := groupByWeek(dates)
- //var uniqueFields []map[string]interface{}
- var uniqueFields []map[string]interface{}
- // 加载中国标准时间(UTC+8)
- chinaLoc, err := time.LoadLocation("Asia/Shanghai")
- if err != nil {
- fmt.Println("加载中国时区出错:", err)
- return
- }
- for _, week := range weeks {
- // 解析时间字符串并转换为中国标准时间
- t, err := time.ParseInLocation("2006-01-02 15:04:05 -0700 MST", week[0].String(), chinaLoc)
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
-
- t2, err := time.ParseInLocation("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String(), chinaLoc)
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
-
- // 获取数据
- list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
-
- var dynamicFields []map[string]interface{}
- for _, result := range list {
- nb := result["日期"].([]byte)
- name := string(nb)
-
- dynamicField := make(map[string]interface{})
- dynamicField["日期"] = name
-
- numericColumns := make(map[string]interface{})
- nonNumericColumns := make(map[string]interface{})
-
- // 分类处理列
- for columnName, columnValue := range result {
- if columnName == "日期" || columnName == "合计" {
- continue
- }
- if columnValue == nil {
- nonNumericColumns[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- nonNumericColumns[columnName] = strValue
- } else {
- if floatValue == 0 {
- nonNumericColumns[columnName] = ""
- } else {
- numericColumns[columnName] = floatValue
- }
- }
- }
-
- // 添加数值列
- for columnName, columnValue := range numericColumns {
- dynamicField[columnName] = columnValue
- }
-
- // 添加非数值列
- for columnName, columnValue := range nonNumericColumns {
- dynamicField[columnName] = columnValue
- }
-
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
-
- break
- case 1:
- startDate, err := time.Parse("2006-01-02", start_date)
- if err != nil {
- fmt.Println("Error parsing start date:", err)
- return
- }
-
- endDate, err := time.Parse("2006-01-02", end_date)
- if err != nil {
- fmt.Println("Error parsing end date:", err)
- return
- }
- dailyDates := splitByDay(startDate, endDate)
- var uniqueFields []map[string]interface{}
- for _, date := range dailyDates {
- list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- var dynamicFields []map[string]interface{}
-
- for _, result := range list {
- nb := result["日期"].([]byte)
- name := string(nb)
-
- dynamicField := make(map[string]interface{})
- dynamicField["日期"] = name
-
- numericColumns := make(map[string]interface{})
- nonNumericColumns := make(map[string]interface{})
-
- // 分类处理列
- for columnName, columnValue := range result {
- if columnName == "日期" || columnName == "合计" {
- continue
- }
- if columnValue == nil {
- nonNumericColumns[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- nonNumericColumns[columnName] = strValue
- } else {
- if floatValue == 0 {
- nonNumericColumns[columnName] = ""
- } else {
- numericColumns[columnName] = floatValue
- }
- }
- }
-
- // 添加数值列
- for columnName, columnValue := range numericColumns {
- dynamicField[columnName] = columnValue
- }
-
- // 添加非数值列
- for columnName, columnValue := range nonNumericColumns {
- dynamicField[columnName] = columnValue
- }
-
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
-
- //for _, date := range dailyDates {
- // list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- // //fmt.Println(aa)
- // var dynamicFields []map[string]interface{}
- //
- // for _, result := range list {
- // // 打印患者ID
- // nb := result["日期"].([]byte)
- // name := string(nb)
- //
- // // 创建动态字段的map
- // dynamicField := make(map[string]interface{})
- // // 将日期放在首位
- // dynamicField["日期"] = name
- //
- // // 临时存储无数值的列
- // nonNumericColumns := make(map[string]interface{})
- //
- // // 先处理包含数值的列
- // for columnName, columnValue := range result {
- // if columnName == "日期" || columnName == "合计" {
- // continue
- // }
- // if columnValue == nil {
- // nonNumericColumns[columnName] = ""
- // continue
- // }
- //
- // byteValue, ok := columnValue.([]byte)
- // if !ok {
- // fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- // continue
- // }
- //
- // strValue := string(byteValue)
- //
- // floatValue, err := strconv.ParseFloat(strValue, 64)
- // if err != nil {
- // fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- // nonNumericColumns[columnName] = strValue
- // } else {
- // if floatValue == 0 {
- // nonNumericColumns[columnName] = ""
- // } else {
- // dynamicField[columnName] = floatValue
- // }
- // }
- // }
- //
- // // 添加无数值的列
- // for columnName, columnValue := range nonNumericColumns {
- // dynamicField[columnName] = columnValue
- // }
- //
- // // 将合计放在末尾
- // hj := result["合计"].(int64)
- // dynamicField["合计"] = hj
- //
- // dynamicFields = append(dynamicFields, dynamicField)
- // }
- //
- // // 将日期放在首位
- // seen := make(map[interface{}]struct{})
- // for _, field := range dynamicFields {
- // value := field["日期"]
- // if _, ok := seen[value]; !ok {
- // seen[value] = struct{}{}
- // uniqueFields = append(uniqueFields, field)
- // }
- // }
- //}
- //for _, date := range dailyDates {
- // list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- // //fmt.Println(aa)
- // var dynamicFields []map[string]interface{}
- //
- // for _, result := range list {
- // // 打印患者ID
- // nb := result["日期"].([]byte)
- // name := string(nb)
- //
- // // 创建动态字段的map
- // dynamicField := make(map[string]interface{})
- // // 将日期放在首位
- // dynamicField["日期"] = name
- //
- // // 打印其他列的值,并添加到动态字段中
- // for columnName, columnValue := range result {
- // if columnName == "日期" {
- // continue
- // }
- // if columnName == "合计" {
- // continue
- // }
- // if columnValue == nil {
- // dynamicField[columnName] = ""
- // continue
- // }
- //
- // byteValue, ok := columnValue.([]byte)
- // if !ok {
- // fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- // continue
- // }
- //
- // strValue := string(byteValue)
- //
- // floatValue, err := strconv.ParseFloat(strValue, 64)
- // if err != nil {
- // fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- // } else {
- // if floatValue == 0 {
- // dynamicField[columnName] = ""
- // } else {
- // dynamicField[columnName] = floatValue
- // }
- // }
- // }
- //
- // // 将合计放在末尾
- // hj := result["合计"].(int64)
- // dynamicField["合计"] = hj
- //
- // dynamicFields = append(dynamicFields, dynamicField)
- // }
- //
- // // 将日期放在首位
- // seen := make(map[interface{}]struct{})
- // for _, field := range dynamicFields {
- // value := field["日期"]
- // if _, ok := seen[value]; !ok {
- // seen[value] = struct{}{}
- // uniqueFields = append(uniqueFields, field)
- // }
- // }
- //}
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
-
- break
- case 3:
- months := groupByMonth(dates)
- var uniqueFields []map[string]interface{}
- for _, month := range months {
- // 解析字符串时显式指定时区为 UTC
- t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[0].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- // 解析字符串时显式指定时区为 UTC
- t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[len(month)-1].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- //dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- //fmt.Println(aa)
- var dynamicFields []map[string]interface{}
- //var uniqueFields []map[string]interface{}
-
- for _, result := range list {
- // 打印患者ID
- nb := result["日期"].([]byte)
- name := string(nb)
-
- // 创建动态字段的map
- dynamicField := make(map[string]interface{})
- // 将日期放在首位
- dynamicField["日期"] = name
-
- // 打印其他列的值,并添加到动态字段中
- for columnName, columnValue := range result {
- if columnName == "日期" {
- continue
- }
- if columnName == "合计" {
- continue
- }
- if columnValue == nil {
- dynamicField[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
-
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- if floatValue == 0 {
- dynamicField[columnName] = ""
- } else {
- dynamicField[columnName] = floatValue
- }
- }
- }
-
- // 将合计放在末尾
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- // 将日期放在首位
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
- break
- case 4:
- years := groupByYear(dates)
- var uniqueFields []map[string]interface{}
- for _, year := range years {
- // 解析字符串时显式指定时区为 UTC
- t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[0].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- // 解析字符串时显式指定时区为 UTC
- t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[len(year)-1].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- //dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- //fmt.Println(aa)
- var dynamicFields []map[string]interface{}
- //var uniqueFields []map[string]interface{}
-
- for _, result := range list {
- // 打印患者ID
- nb := result["日期"].([]byte)
- name := string(nb)
-
- // 创建动态字段的map
- dynamicField := make(map[string]interface{})
- // 将日期放在首位
- dynamicField["日期"] = name
-
- // 打印其他列的值,并添加到动态字段中
- for columnName, columnValue := range result {
- if columnName == "日期" {
- continue
- }
- if columnName == "合计" {
- continue
- }
- if columnValue == nil {
- dynamicField[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
-
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- if floatValue == 0 {
- dynamicField[columnName] = ""
- } else {
- dynamicField[columnName] = floatValue
- }
- }
- }
-
- // 将合计放在末尾
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- // 将日期放在首位
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
- break
-
- }
-
- } else {
- switch time_way {
- case 2:
- weeks := groupByWeek(dates)
- //var uniqueFields []map[string]interface{}
- var uniqueFields []map[string]interface{}
-
- for _, week := range weeks {
- // 解析字符串时显式指定时区为 UTC
- t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[0].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- // 解析字符串时显式指定时区为 UTC
- t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- //dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetScheduleStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- //fmt.Println(aa)
- var dynamicFields []map[string]interface{}
- //var uniqueFields []map[string]interface{}
-
- for _, result := range list {
- // 打印患者ID
- nb := result["日期"].([]byte)
- name := string(nb)
-
- // 创建动态字段的map
- dynamicField := make(map[string]interface{})
- // 将日期放在首位
- dynamicField["日期"] = name
-
- // 打印其他列的值,并添加到动态字段中
- for columnName, columnValue := range result {
- if columnName == "日期" {
- continue
- }
- if columnName == "合计" {
- continue
- }
- if columnValue == nil {
- dynamicField[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
-
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- if floatValue == 0 {
- dynamicField[columnName] = ""
- } else {
- dynamicField[columnName] = floatValue
- }
- }
- }
-
- // 将合计放在末尾
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- // 将日期放在首位
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
-
- break
- case 1:
- startDate, err := time.Parse("2006-01-02", start_date)
- if err != nil {
- fmt.Println("Error parsing start date:", err)
- return
- }
-
- endDate, err := time.Parse("2006-01-02", end_date)
- if err != nil {
- fmt.Println("Error parsing end date:", err)
- return
- }
- dailyDates := splitByDay(startDate, endDate)
- var uniqueFields []map[string]interface{}
- for _, date := range dailyDates {
- list, _ := service.GetScheduleStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- //fmt.Println(aa)
- var dynamicFields []map[string]interface{}
-
- for _, result := range list {
- // 打印患者ID
- nb := result["日期"].([]byte)
- name := string(nb)
-
- // 创建动态字段的map
- dynamicField := make(map[string]interface{})
- // 将日期放在首位
- dynamicField["日期"] = name
-
- // 打印其他列的值,并添加到动态字段中
- for columnName, columnValue := range result {
- if columnName == "日期" {
- continue
- }
- if columnName == "合计" {
- continue
- }
- if columnValue == nil {
- dynamicField[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
-
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- if floatValue == 0 {
- dynamicField[columnName] = ""
- } else {
- dynamicField[columnName] = floatValue
- }
- }
- }
-
- // 将合计放在末尾
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- // 将日期放在首位
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
-
- break
- case 3:
- months := groupByMonth(dates)
- var uniqueFields []map[string]interface{}
- for _, month := range months {
- // 解析字符串时显式指定时区为 UTC
- t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[0].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- // 解析字符串时显式指定时区为 UTC
- t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[len(month)-1].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- //dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetScheduleStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- //fmt.Println(aa)
- var dynamicFields []map[string]interface{}
- //var uniqueFields []map[string]interface{}
-
- for _, result := range list {
- // 打印患者ID
- nb := result["日期"].([]byte)
- name := string(nb)
-
- // 创建动态字段的map
- dynamicField := make(map[string]interface{})
- // 将日期放在首位
- dynamicField["日期"] = name
-
- // 打印其他列的值,并添加到动态字段中
- for columnName, columnValue := range result {
- if columnName == "日期" {
- continue
- }
- if columnName == "合计" {
- continue
- }
- if columnValue == nil {
- dynamicField[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
-
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- if floatValue == 0 {
- dynamicField[columnName] = ""
- } else {
- dynamicField[columnName] = floatValue
- }
- }
- }
-
- // 将合计放在末尾
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- // 将日期放在首位
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
- break
- case 4:
- years := groupByYear(dates)
- var uniqueFields []map[string]interface{}
- for _, year := range years {
- // 解析字符串时显式指定时区为 UTC
- t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[0].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- // 解析字符串时显式指定时区为 UTC
- t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[len(year)-1].String())
- if err != nil {
- fmt.Println("解析时间出错:", err)
- return
- }
- //dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetScheduleStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
- //fmt.Println(aa)
- var dynamicFields []map[string]interface{}
- //var uniqueFields []map[string]interface{}
-
- for _, result := range list {
- // 打印患者ID
- nb := result["日期"].([]byte)
- name := string(nb)
-
- // 创建动态字段的map
- dynamicField := make(map[string]interface{})
- // 将日期放在首位
- dynamicField["日期"] = name
-
- // 打印其他列的值,并添加到动态字段中
- for columnName, columnValue := range result {
- if columnName == "日期" {
- continue
- }
- if columnName == "合计" {
- continue
- }
- if columnValue == nil {
- dynamicField[columnName] = ""
- continue
- }
-
- byteValue, ok := columnValue.([]byte)
- if !ok {
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- strValue := string(byteValue)
-
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- if floatValue == 0 {
- dynamicField[columnName] = ""
- } else {
- dynamicField[columnName] = floatValue
- }
- }
- }
-
- // 将合计放在末尾
- hj := result["合计"].(int64)
- dynamicField["合计"] = hj
-
- dynamicFields = append(dynamicFields, dynamicField)
- }
-
- // 将日期放在首位
- seen := make(map[interface{}]struct{})
- for _, field := range dynamicFields {
- value := field["日期"]
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
- break
- }
- }
- }
- func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
- date_str := c.GetString("date")
- mode, _ := c.GetInt64("mode")
- origin, _ := c.GetInt64("origin")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- time_way, _ := c.GetInt64("time_way")
- var start_date string
- var end_date string
- if time_way == 1 {
- start_date = date_str
- end_date = date_str
- } else {
- start_date = strings.Split(date_str, "~")[0]
- end_date = strings.Split(date_str, "~")[1]
- }
-
- if origin == 1 {
- qcp, total, _ := service.GetDialysisPrescriptionInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": qcp,
- "total": total,
- })
- } else {
- qcp, total, _ := service.GetScheduleInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": qcp,
- "total": total,
- })
- }
-
- }
- func (c *StatisticsApiController) GetAnticoagulant() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- 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()
- }
-
- total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err2 != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- type respData struct {
- Name string `json:"name"`
- Count int `json:"count"`
- Percentage float64 `json:"percentage"`
- }
- var respDatas []respData
- for anticoagulant, count := range anticoagulantData {
- var respData respData
- respData.Name = anticoagulant
- respData.Count = count
- respData.Percentage = float64(count) / float64(total) * 100
- respDatas = append(respDatas, respData)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "data": respDatas,
- })
-
- }
- func (c *StatisticsApiController) GetAnticoagulantDetail() {
- anticoagulant, _ := c.GetInt64("anticoagulant")
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- 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()
- }
- prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- "total": total,
- })
-
- }
-
- func (c *StatisticsApiController) GetDialyzer() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- 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()
- }
-
- total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err2 != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- DialysisIrrigation, err := service.GetDialysisIrrigationData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
-
- DialysisStrainer, err := service.GetDialysisStrainerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- type respData struct {
- Name string `json:"name"`
- Count int `json:"count"`
- Percentage float64 `json:"percentage"`
- }
- var respDatas []respData
- for _, item := range dialyzers {
- if len(item.Dialyzer) > 0 {
- var respData respData
- respData.Name = item.Dialyzer
- respData.Count = item.Count
- respData.Percentage = float64(item.Count) / float64(total) * 100
- respDatas = append(respDatas, respData)
- }
- }
- for _, item := range DialysisIrrigation {
- if len(item.Dialyzer) > 0 {
-
- var respData respData
- respData.Name = item.Dialyzer
- respData.Count = item.Count
- respData.Percentage = float64(item.Count) / float64(total) * 100
- respDatas = append(respDatas, respData)
- }
- }
-
- for _, item := range DialysisStrainer {
- fmt.Println(item.Dialyzer)
- if len(item.Dialyzer) > 0 {
- var respData respData
- respData.Name = item.Dialyzer
- respData.Count = item.Count
- respData.Percentage = float64(item.Count) / float64(total) * 100
- respDatas = append(respDatas, respData)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "data": respDatas,
- })
-
- }
- func (c *StatisticsApiController) GetDialyzerDetail() {
- dialyzer := c.GetString("dialyzer")
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- 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()
- }
- prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- "total": total,
- })
-
- }
- func (c *StatisticsApiController) GetDialyzerConfig() {
- var dialyzer []string
- dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
- for _, item := range dialyzers {
- dialyzer = append(dialyzer, item.DialysisDialyszers)
- }
- Irrigation, _ := service.GetIrrigationSummary(c.GetAdminUserInfo().CurrentOrgId)
- for _, item := range Irrigation {
- dialyzer = append(dialyzer, item.DialysisIrrigation)
- }
- DialysisStrainer, _ := service.GetDialysisStrainerSummary(c.GetAdminUserInfo().CurrentOrgId)
- for _, item := range DialysisStrainer {
- dialyzer = append(dialyzer, item.DialysisStrainer)
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "dialyzers": dialyzer,
- })
- }
-
- // 配置检验数据查询
- func (this *StatisticsApiController) GetInsepctionList() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- configurationlist, err := service.GetInsepctionConfigurationList(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configurationlist": configurationlist,
- })
- }
- func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
- 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.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- //获取数值在正常范围内的总数
- config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- max, _ := strconv.ParseFloat(config.LargeRange, 64)
- min, _ := strconv.ParseFloat(config.MinRange, 64)
-
- normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取数值异常的总数
- unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- "reference": reference,
- "config": config,
- })
-
- }
- func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- 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)
- config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
-
- //获取配置
- reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
-
- }
- func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
- 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")
- 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.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- //获取数值在正常范围内的总数
-
- config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- max, _ := strconv.ParseFloat(config.LargeRange, 64)
- min, _ := strconv.ParseFloat(config.MinRange, 64)
-
- //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
- //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
- //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
-
- switch item_type {
- case 1:
- list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- break
- case 2:
- list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- break
- case 3:
- list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- break
- }
- }
-
- 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")
-
- dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
- //fmt.Println(list)
-
- for _, result := range list {
- //fmt.Println(result)
- // 打印患者ID
- nb := result["姓名"].([]byte)
- name := string(nb)
-
- //ynamicFields := make([]map[string]interface{})
-
- //var dynamicFields DynamicData
- ynamicField := make(map[string]interface{})
- ynamicField["姓名"] = name
- // 打印其他列的值
- for columnName, columnValue := range result {
-
- // 跳过患者ID列
-
- if columnName == "姓名" {
- continue
- }
- // 检查值是否为nil
- if columnValue == nil {
- fmt.Printf("Column: %s, Value: <nil>\n", columnName)
- continue
- }
-
- // 将字节切片转换为字符串
- byteValue, ok := columnValue.([]byte)
- if !ok {
- // 如果无法转换为[]byte,输出错误信息
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- // 将字节切片转换为字符串
- strValue := string(byteValue)
-
- // 尝试将字符串转换为浮点数
- floatValue, _ := strconv.ParseFloat(strValue, 64)
- //if err != nil {
- // // 如果转换失败,输出错误信息
- // fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- //} else {
- // // 如果转换成功,输出列名和浮点数值
- // fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
- //}
- ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
- if floatValue == 0 {
- ynamicField[columnName] = ""
-
- } else {
- ynamicField[columnName] = floatValue
-
- }
- fmt.Println(ynamicField)
- dynamicFields = append(dynamicFields, ynamicField)
- }
- }
-
- seen := make(map[interface{}]struct{})
- var uniqueFields []map[string]interface{}
-
- for _, field := range dynamicFields {
- value := field["姓名"]
- // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
- //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
- //
- //var names []string
- //
- //for _, item := range list {
- // names = append(names, item.ItemName)
- //}
- //
- //names = RemoveRepeatedNameElement(names)
- //fmt.Println(names)
- //
- //var tempList []models.InspectionTen
- //list_two := RemoveRepeatedInspectPatientElement(list)
- //for _, item := range list_two {
- // var temp models.InspectionTen
- // var temptwos []models.InspectionValue
- // temp.PatientId = item.PatientId
- // temp.Name = item.Name
- // for _, subitem := range list {
- // if item.PatientId == subitem.PatientId {
- // var temptwo models.InspectionValue
- // temptwo.Name = subitem.ItemName
- // temptwo.Value = subitem.InspectValue
- // temptwos = append(temptwos, temptwo)
- // }
- // }
- // temp.Values = temptwos
- // tempList = append(tempList, temp)
- //}
- //
- //var filtered []string
- //for _, item := range names {
- // if item != "a" {
- // filtered = append(filtered, item)
- // }
- //}
- //
- //for _, item := range tempList {
- // for _, subitem := range item.Values {
- // for _, name := range filtered {
- // if subitem.Name != name {
- // filtered = append(filtered, name)
- // }
- // }
- // }
- //}
- //
- ////// 将剩余字符串填充到 Inspection 数组中
- ////for _, name := range filtered {
- //// var temptwo models.InspectionValue
- //// temptwo.Name = subitem.ItemName
- //// temptwo.Value = subitem.InspectValue
- //// temptwos = append(temptwos, temptwo)
- ////}
- //
- //for _, item := range tempList {
- // //for _, subitem := range item.Values {
- // var temptwo models.InspectionValue
- // for _, name := range filtered {
- // temptwo.Name = name
- // temptwo.Value = ""
- // }
- // item.Values = append(item.Values, temptwo)
- // //}
- // fmt.Println(item.Values)
- //}
-
- }
- 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.ItemName, 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.ItemName, 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.ItemName, 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, 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.ItemName, max, min)
- //获取数值异常的总数
- unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
- 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, patient_id, reference.ItemName)
- 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,
- })
-
- }
-
- func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
- newArr = make([]models.InspectionTenOne, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].PatientId == arr[j].PatientId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func RemoveRepeatedNameElement(arr []string) (newArr []string) {
- newArr = make([]string, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i] == arr[j] {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- // 根据指定的日期范围拆分成周、月、年
- func splitDateRange(startDate, endDate string) ([]time.Time, error) {
- startTime, err := time.Parse("2006-01-02", startDate)
- if err != nil {
- return nil, err
- }
-
- endTime, err := time.Parse("2006-01-02", endDate)
- if err != nil {
- return nil, err
- }
-
- var result []time.Time
-
- for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
- result = append(result, date)
- }
-
- return result, nil
- }
-
- // 按周统计日期
- func groupByWeek(dates []time.Time) [][]time.Time {
- var result [][]time.Time
- var currentWeek []time.Time
-
- for _, date := range dates {
- currentWeek = append(currentWeek, date)
- if date.Weekday() == time.Sunday {
- result = append(result, currentWeek)
- currentWeek = nil
- }
- }
-
- if len(currentWeek) > 0 {
- result = append(result, currentWeek)
- }
-
- return result
- }
-
- // 按月统计日期
- func groupByMonth(dates []time.Time) [][]time.Time {
- var result [][]time.Time
- var currentMonth []time.Time
- lastMonth := dates[0].Month()
-
- for _, date := range dates {
- if date.Month() != lastMonth {
- result = append(result, currentMonth)
- currentMonth = nil
- lastMonth = date.Month()
- }
- currentMonth = append(currentMonth, date)
- }
-
- if len(currentMonth) > 0 {
- result = append(result, currentMonth)
- }
-
- return result
- }
-
- // 按年统计日期
- func groupByYear(dates []time.Time) [][]time.Time {
- var result [][]time.Time
- var currentYear []time.Time
- lastYear := dates[0].Year()
-
- for _, date := range dates {
- if date.Year() != lastYear {
- result = append(result, currentYear)
- currentYear = nil
- lastYear = date.Year()
- }
- currentYear = append(currentYear, date)
- }
-
- if len(currentYear) > 0 {
- result = append(result, currentYear)
- }
-
- return result
- }
-
- // 将日期拆分为按天统计
- func splitByDay(startDate, endDate time.Time) []time.Time {
- var dates []time.Time
- for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
- dates = append(dates, d)
- }
- return dates
- }
-
- // 排序函数
- func sortFieldsByValue(field map[string]interface{}) map[string]interface{} {
- // 将键值对分成两个部分,一个有值,一个无值
- var withValue, withoutValue []string
-
- for key, value := range field {
- if key == "日期" || key == "合计" {
- continue
- }
- if value == "" {
- withoutValue = append(withoutValue, key)
- } else {
- withValue = append(withValue, key)
- }
- }
-
- // 对有值和无值部分分别排序
- sort.Strings(withValue)
- sort.Strings(withoutValue)
-
- // 创建一个新的有序map
- sortedField := make(map[string]interface{})
- sortedField["日期"] = field["日期"]
-
- for _, key := range withValue {
- sortedField[key] = field[key]
- }
- for _, key := range withoutValue {
- sortedField[key] = field[key]
- }
-
- sortedField["合计"] = field["合计"]
- return sortedField
- }
|