123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451 |
- 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/dryweight/detail", &StatisticsApiController{}, "get:GetPatientDryWeightDetail")
-
- 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) GetPatientDryWeightDetail() {
- start_time := c.GetString("start_time")
- end_time := c.GetString("end_time")
- dry_type, _ := c.GetInt64("dry_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.GetNewDialysisWeightDetailTableTenSix(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, dry_type, page, limit)
- fmt.Println(data)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": data,
- "total": total,
- })
- }
-
- 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")
- item_type, _ := c.GetInt64("item_type")
- after_type, _ := c.GetInt64("after_type")
- page, _ := c.GetInt64("page")
- limit, _ := c.GetInt64("limit")
- keyword := c.GetString("keyword")
-
- 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.GetNewDialysisWeightDetailTableTenT(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, dry_type, after_type, page, limit, keyword, item_type)
- 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
- }
|