12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414 |
- 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")
- 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.GetNewDialysisWeightDetailTableTen(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, dry_type, after_type, page, limit, keyword)
- 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
- }
|