statistics_api_controller.go 74KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "sort"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type StatisticsApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func StatisticsApiRegistRouters() {
  18. beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics")
  19. beego.Router("/api/qc/statistiscall/get", &StatisticsApiController{}, "get:GetAllInspectionStatistisc")
  20. beego.Router("/api/qc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonInspectionStatistisc")
  21. beego.Router("/api/qc/statistiscperson/list", &StatisticsApiController{}, "get:GetInsepctionList")
  22. beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
  23. beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
  24. beego.Router("/api/commonqc/statistiscall/get", &StatisticsApiController{}, "get:GetAllCommonInspectionStatistisc")
  25. beego.Router("/api/commonqc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonCommonInspectionStatistisc")
  26. beego.Router("/api/commonqc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientCommonInspectionStatistisc")
  27. //透析总量统计
  28. beego.Router("/api/commonqc/dialysis/total", &StatisticsApiController{}, "get:GetDialysisTotal")
  29. beego.Router("/api/commonqc/dialysis/detail", &StatisticsApiController{}, "get:GetDialysisTotalDetail")
  30. beego.Router("/api/commonqc/dialysis/detailsinfo", &StatisticsApiController{}, "get:GetDialysisTotalDetailInfo")
  31. beego.Router("/api/commonqc/anticoagulant", &StatisticsApiController{}, "get:GetAnticoagulant")
  32. beego.Router("/api/commonqc/anticoagulant/detail", &StatisticsApiController{}, "get:GetAnticoagulantDetail")
  33. beego.Router("/api/commonqc/dialyzer", &StatisticsApiController{}, "get:GetDialyzer")
  34. beego.Router("/api/commonqc/dialyzer/config", &StatisticsApiController{}, "get:GetDialyzerConfig")
  35. beego.Router("/api/commonqc/dialyzer/detail", &StatisticsApiController{}, "get:GetDialyzerDetail")
  36. beego.Router("/api/commonqc/dialysistreat/finish", &StatisticsApiController{}, "get:GetDialysisTreatFinsh")
  37. beego.Router("/api/commonqc/dialysistreat/detail", &StatisticsApiController{}, "get:GetDialysisTreatDetail")
  38. beego.Router("/api/commonqc/patinet/weight", &StatisticsApiController{}, "get:GetPatientWeight")
  39. beego.Router("/api/commonqc/dryweight/detail", &StatisticsApiController{}, "get:GetPatientDryWeightDetail")
  40. beego.Router("/api/commonqc/weight/detail", &StatisticsApiController{}, "get:GetPatientWeightDetail")
  41. beego.Router("/api/commonqc/patinet/bp", &StatisticsApiController{}, "get:GetPatientBP")
  42. beego.Router("/api/commonqc/bp/detail", &StatisticsApiController{}, "get:GetPatientBPDetail")
  43. }
  44. func (c *StatisticsApiController) GetPatientWeight() {
  45. start_time := c.GetString("start_time")
  46. end_time := c.GetString("end_time")
  47. statistics_type, _ := c.GetInt("statistics_type")
  48. timeLayout := "2006-01-02"
  49. loc, _ := time.LoadLocation("Local")
  50. var startTime int64
  51. if len(start_time) > 0 {
  52. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  53. fmt.Println("err-----------", err)
  54. if err != nil {
  55. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  56. return
  57. }
  58. startTime = theTime.Unix()
  59. }
  60. var endTime int64
  61. if len(end_time) > 0 {
  62. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  63. if err != nil {
  64. utils.ErrorLog(err.Error())
  65. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. endTime = theTime.Unix()
  69. }
  70. item, _ := service.GetNewDialysisWeightChartData(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, statistics_type)
  71. c.ServeSuccessJSON(map[string]interface{}{
  72. "list": item,
  73. })
  74. }
  75. func (c *StatisticsApiController) GetPatientDryWeightDetail() {
  76. start_time := c.GetString("start_time")
  77. end_time := c.GetString("end_time")
  78. dry_type, _ := c.GetInt64("dry_type")
  79. page, _ := c.GetInt64("page")
  80. limit, _ := c.GetInt64("limit")
  81. timeLayout := "2006-01-02"
  82. loc, _ := time.LoadLocation("Local")
  83. var startTime int64
  84. if len(start_time) > 0 {
  85. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  86. fmt.Println("err-----------", err)
  87. if err != nil {
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  89. return
  90. }
  91. startTime = theTime.Unix()
  92. }
  93. var endTime int64
  94. if len(end_time) > 0 {
  95. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  96. if err != nil {
  97. utils.ErrorLog(err.Error())
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. endTime = theTime.Unix()
  102. }
  103. data, total, _ := service.GetNewDialysisWeightDetailTableTenSix(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, dry_type, page, limit)
  104. fmt.Println(data)
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "list": data,
  107. "total": total,
  108. })
  109. }
  110. func (c *StatisticsApiController) GetPatientWeightDetail() {
  111. start_time := c.GetString("start_time")
  112. end_time := c.GetString("end_time")
  113. add_type, _ := c.GetInt64("add_type")
  114. dry_type, _ := c.GetInt64("dry_type")
  115. item_type, _ := c.GetInt64("item_type")
  116. after_type, _ := c.GetInt64("after_type")
  117. page, _ := c.GetInt64("page")
  118. limit, _ := c.GetInt64("limit")
  119. keyword := c.GetString("keyword")
  120. timeLayout := "2006-01-02"
  121. loc, _ := time.LoadLocation("Local")
  122. var startTime int64
  123. if len(start_time) > 0 {
  124. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  125. fmt.Println("err-----------", err)
  126. if err != nil {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  128. return
  129. }
  130. startTime = theTime.Unix()
  131. }
  132. var endTime int64
  133. if len(end_time) > 0 {
  134. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  135. if err != nil {
  136. utils.ErrorLog(err.Error())
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. endTime = theTime.Unix()
  141. }
  142. data, total, _ := service.GetNewDialysisWeightDetailTableTenT(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, dry_type, after_type, page, limit, keyword, item_type)
  143. fmt.Println(data)
  144. c.ServeSuccessJSON(map[string]interface{}{
  145. "list": data,
  146. "total": total,
  147. })
  148. }
  149. func (c *StatisticsApiController) GetPatientBP() {
  150. start_time := c.GetString("start_time")
  151. end_time := c.GetString("end_time")
  152. statistics_type, _ := c.GetInt("statistics_type")
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. var startTime int64
  156. if len(start_time) > 0 {
  157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  158. fmt.Println("err-----------", err)
  159. if err != nil {
  160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  161. return
  162. }
  163. startTime = theTime.Unix()
  164. }
  165. var endTime int64
  166. if len(end_time) > 0 {
  167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  168. if err != nil {
  169. utils.ErrorLog(err.Error())
  170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  171. return
  172. }
  173. endTime = theTime.Unix()
  174. }
  175. if statistics_type == 1 {
  176. item, _ := service.GetNewDialysisBPDetailTableTenThree(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
  177. c.ServeSuccessJSON(map[string]interface{}{
  178. "list": item,
  179. })
  180. } else {
  181. item, _ := service.GetNewDialysisBPDetailTableTenFour(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
  182. c.ServeSuccessJSON(map[string]interface{}{
  183. "list": item,
  184. })
  185. }
  186. }
  187. func (c *StatisticsApiController) GetPatientBPDetail() {
  188. start_time := c.GetString("start_time")
  189. end_time := c.GetString("end_time")
  190. add_type, _ := c.GetInt64("status_type")
  191. statistics_type, _ := c.GetInt64("statistics_type")
  192. page, _ := c.GetInt64("page")
  193. limit, _ := c.GetInt64("limit")
  194. timeLayout := "2006-01-02"
  195. loc, _ := time.LoadLocation("Local")
  196. var startTime int64
  197. if len(start_time) > 0 {
  198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  199. fmt.Println("err-----------", err)
  200. if err != nil {
  201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  202. return
  203. }
  204. startTime = theTime.Unix()
  205. }
  206. var endTime int64
  207. if len(end_time) > 0 {
  208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  209. if err != nil {
  210. utils.ErrorLog(err.Error())
  211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  212. return
  213. }
  214. endTime = theTime.Unix()
  215. }
  216. var data []service.DialysisDataThree
  217. var total int64
  218. if statistics_type == 1 {
  219. data, total, _ = service.GetNewDialysisBPDetailTableTen(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, page, limit)
  220. } else {
  221. data, total, _ = service.GetNewDialysisBPDetailTableTenOne(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, add_type, page, limit)
  222. }
  223. c.ServeSuccessJSON(map[string]interface{}{
  224. "list": data,
  225. "total": total,
  226. })
  227. }
  228. func (c *StatisticsApiController) GetDialysisTreatFinsh() {
  229. start_date := c.GetString("start_date")
  230. end_date := c.GetString("end_date")
  231. timeLayout := "2006-01-02"
  232. loc, _ := time.LoadLocation("Local")
  233. var startTime int64
  234. if len(start_date) > 0 {
  235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  236. fmt.Println("err-----------", err)
  237. if err != nil {
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  239. return
  240. }
  241. startTime = theTime.Unix()
  242. }
  243. var endTime int64
  244. if len(end_date) > 0 {
  245. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  246. if err != nil {
  247. utils.ErrorLog(err.Error())
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. return
  250. }
  251. endTime = theTime.Unix()
  252. }
  253. data, _ := service.GetDialysisCompletionRate(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
  254. total, _ := service.GetDialysisCompletionTotal(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
  255. c.ServeSuccessJSON(map[string]interface{}{
  256. "data": data,
  257. "total": total,
  258. })
  259. }
  260. func (c *StatisticsApiController) GetDialysisTreatDetail() {
  261. start_date := c.GetString("start_date")
  262. end_date := c.GetString("end_date")
  263. mode, _ := c.GetInt64("mode")
  264. page, _ := c.GetInt64("page", 0)
  265. limit, _ := c.GetInt64("limit", 0)
  266. if page <= 0 {
  267. page = 1
  268. }
  269. if limit <= 0 {
  270. limit = 10
  271. }
  272. timeLayout := "2006-01-02"
  273. loc, _ := time.LoadLocation("Local")
  274. var startTime int64
  275. if len(start_date) > 0 {
  276. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  277. fmt.Println("err-----------", err)
  278. if err != nil {
  279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  280. return
  281. }
  282. startTime = theTime.Unix()
  283. }
  284. var endTime int64
  285. if len(end_date) > 0 {
  286. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  287. if err != nil {
  288. utils.ErrorLog(err.Error())
  289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  290. return
  291. }
  292. endTime = theTime.Unix()
  293. }
  294. data, total, _ := service.GetDialysisCompletionDetail(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, mode, limit, page)
  295. c.ServeSuccessJSON(map[string]interface{}{
  296. "list": data,
  297. "total": total,
  298. })
  299. }
  300. func (c *StatisticsApiController) GetDialysisTotal() {
  301. start_date := c.GetString("start_date")
  302. end_date := c.GetString("end_date")
  303. mode, _ := c.GetInt64("mode")
  304. origin, _ := c.GetInt64("origin")
  305. time_way, _ := c.GetInt64("time_way")
  306. timeLayout := "2006-01-02"
  307. loc, _ := time.LoadLocation("Local")
  308. var startTime int64
  309. if len(start_date) > 0 {
  310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  311. fmt.Println("err-----------", err)
  312. if err != nil {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  314. return
  315. }
  316. startTime = theTime.Unix()
  317. }
  318. var endTime int64
  319. if len(end_date) > 0 {
  320. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  321. if err != nil {
  322. utils.ErrorLog(err.Error())
  323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  324. return
  325. }
  326. endTime = theTime.Unix()
  327. }
  328. if mode == 0 { //统计透析模式不限
  329. //获取总人数
  330. p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
  331. count_struct, _ := service.GetNewDialysisCountMode(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin, 0)
  332. c.ServeSuccessJSON(map[string]interface{}{
  333. "patient_count": p_total,
  334. "list": count_struct,
  335. })
  336. } else { //固定某个模式
  337. // 拆分日期范围
  338. dates, err := splitDateRange(start_date, end_date)
  339. if err != nil {
  340. fmt.Println("Error:", err)
  341. return
  342. }
  343. var cuss []models.CustomDialysisData
  344. p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
  345. switch time_way {
  346. case 1:
  347. // 按周统计
  348. weeks := groupByWeek(dates)
  349. fmt.Println(weeks)
  350. for _, week := range weeks {
  351. // 解析字符串时显式指定时区为 UTC
  352. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[0].String())
  353. if err != nil {
  354. fmt.Println("解析时间出错:", err)
  355. return
  356. }
  357. // 格式化时间时将时区设置为 UTC
  358. //fmt.Println(t.UTC().Format("2006-01-02 15:04:05"))
  359. var cus models.CustomDialysisData
  360. //week_date := week[0].Format("2006-01-02") + " 00:00:00"
  361. //date, err := time.Parse("2006-01-02 15:04:05", week_date)
  362. //if err != nil {
  363. // fmt.Println("日期解析错误:", err)
  364. // return
  365. //}
  366. // 将time.Time类型转换为时间戳(秒)
  367. //week_start := date.Unix()
  368. // 解析字符串时显式指定时区为 UTC
  369. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String())
  370. if err != nil {
  371. fmt.Println("解析时间出错:", err)
  372. return
  373. }
  374. //week_end_date := week[len(week)-1].Format("2006-01-02") + " 00:00:00"
  375. //end_date, err := time.Parse("2006-01-02 15:04:05", week_end_date)
  376. //if err != nil {
  377. // fmt.Println("日期解析错误:", err)
  378. // return
  379. //}
  380. //
  381. //// 将time.Time类型转换为时间戳(秒)
  382. //week_end := end_date.Unix()
  383. counts, _ := service.GetNewDialysisCountModeTwo(t.Unix(), t2.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  384. cus.Date = strings.Split(week[0].String(), " ")[0] + "~" + strings.Split(week[len(week)-1].String(), " ")[0]
  385. cus.Count = counts.Count
  386. cus.Total = p_total
  387. cuss = append(cuss, cus)
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "list": cuss,
  391. })
  392. break
  393. case 2:
  394. startDate, err := time.Parse("2006-01-02", start_date)
  395. if err != nil {
  396. fmt.Println("Error parsing start date:", err)
  397. return
  398. }
  399. endDate, err := time.Parse("2006-01-02", end_date)
  400. if err != nil {
  401. fmt.Println("Error parsing end date:", err)
  402. return
  403. }
  404. dailyDates := splitByDay(startDate, endDate)
  405. for _, date := range dailyDates {
  406. //fmt.Println(date)
  407. var cus models.CustomDialysisData
  408. counts, _ := service.GetNewDialysisCountModeTwo(date.Unix(), date.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  409. cus.Date = date.Format("2006-01-02")
  410. cus.Count = counts.Count
  411. cus.Total = p_total
  412. cuss = append(cuss, cus)
  413. }
  414. c.ServeSuccessJSON(map[string]interface{}{
  415. "list": cuss,
  416. })
  417. break
  418. case 3:
  419. // 按月统计
  420. months := groupByMonth(dates)
  421. for _, month := range months {
  422. var cus models.CustomDialysisData
  423. counts, _ := service.GetNewDialysisCountModeTwo(month[0].Unix(), month[len(month)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  424. cus.Date = strings.Split(month[0].String(), " ")[0] + "~" + strings.Split(month[len(month)-1].String(), " ")[0]
  425. cus.Count = counts.Count
  426. cus.Total = p_total
  427. cuss = append(cuss, cus)
  428. //fmt.Println("Month:", month[0], "~", month[len(month)-1])
  429. }
  430. c.ServeSuccessJSON(map[string]interface{}{
  431. "list": cuss,
  432. })
  433. break
  434. case 4:
  435. // 按年统计
  436. years := groupByYear(dates)
  437. for _, year := range years {
  438. var cus models.CustomDialysisData
  439. counts, _ := service.GetNewDialysisCountModeTwo(year[0].Unix(), year[len(year)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  440. cus.Date = strings.Split(strings.Split(year[0].String(), " ")[0], "-")[0]
  441. cus.Count = counts.Count
  442. cus.Total = p_total
  443. cuss = append(cuss, cus)
  444. }
  445. c.ServeSuccessJSON(map[string]interface{}{
  446. "list": cuss,
  447. })
  448. break
  449. }
  450. }
  451. }
  452. func (c *StatisticsApiController) GetDialysisTotalDetail() {
  453. start_date := c.GetString("start_date")
  454. end_date := c.GetString("end_date")
  455. mode, _ := c.GetInt64("mode")
  456. origin, _ := c.GetInt64("origin")
  457. time_way, _ := c.GetInt64("time_way")
  458. //timeLayout := "2006-01-02"
  459. //loc, _ := time.LoadLocation("Local")
  460. //var startTime int64
  461. //if len(start_date) > 0 {
  462. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  463. // fmt.Println("err-----------", err)
  464. // if err != nil {
  465. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  466. // return
  467. // }
  468. // //startTime = theTime.Unix()
  469. //}
  470. //var endTime int64
  471. //if len(end_date) > 0 {
  472. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  473. // if err != nil {
  474. // utils.ErrorLog(err.Error())
  475. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  476. // return
  477. // }
  478. // //endTime = theTime.Unix()
  479. //}
  480. dates, err := splitDateRange(start_date, end_date)
  481. if err != nil {
  482. fmt.Println("Error:", err)
  483. return
  484. }
  485. if origin == 1 {
  486. switch time_way {
  487. case 2:
  488. weeks := groupByWeek(dates)
  489. //var uniqueFields []map[string]interface{}
  490. var uniqueFields []map[string]interface{}
  491. // 加载中国标准时间(UTC+8)
  492. chinaLoc, err := time.LoadLocation("Asia/Shanghai")
  493. if err != nil {
  494. fmt.Println("加载中国时区出错:", err)
  495. return
  496. }
  497. for _, week := range weeks {
  498. // 解析时间字符串并转换为中国标准时间
  499. t, err := time.ParseInLocation("2006-01-02 15:04:05 -0700 MST", week[0].String(), chinaLoc)
  500. if err != nil {
  501. fmt.Println("解析时间出错:", err)
  502. return
  503. }
  504. t2, err := time.ParseInLocation("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String(), chinaLoc)
  505. if err != nil {
  506. fmt.Println("解析时间出错:", err)
  507. return
  508. }
  509. // 获取数据
  510. list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  511. var dynamicFields []map[string]interface{}
  512. for _, result := range list {
  513. nb := result["日期"].([]byte)
  514. name := string(nb)
  515. dynamicField := make(map[string]interface{})
  516. dynamicField["日期"] = name
  517. numericColumns := make(map[string]interface{})
  518. nonNumericColumns := make(map[string]interface{})
  519. // 分类处理列
  520. for columnName, columnValue := range result {
  521. if columnName == "日期" || columnName == "合计" {
  522. continue
  523. }
  524. if columnValue == nil {
  525. nonNumericColumns[columnName] = ""
  526. continue
  527. }
  528. byteValue, ok := columnValue.([]byte)
  529. if !ok {
  530. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  531. continue
  532. }
  533. strValue := string(byteValue)
  534. floatValue, err := strconv.ParseFloat(strValue, 64)
  535. if err != nil {
  536. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  537. nonNumericColumns[columnName] = strValue
  538. } else {
  539. if floatValue == 0 {
  540. nonNumericColumns[columnName] = ""
  541. } else {
  542. numericColumns[columnName] = floatValue
  543. }
  544. }
  545. }
  546. // 添加数值列
  547. for columnName, columnValue := range numericColumns {
  548. dynamicField[columnName] = columnValue
  549. }
  550. // 添加非数值列
  551. for columnName, columnValue := range nonNumericColumns {
  552. dynamicField[columnName] = columnValue
  553. }
  554. hj := result["合计"].(int64)
  555. dynamicField["合计"] = hj
  556. dynamicFields = append(dynamicFields, dynamicField)
  557. }
  558. seen := make(map[interface{}]struct{})
  559. for _, field := range dynamicFields {
  560. value := field["日期"]
  561. if _, ok := seen[value]; !ok {
  562. seen[value] = struct{}{}
  563. uniqueFields = append(uniqueFields, field)
  564. }
  565. }
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "list": uniqueFields,
  569. })
  570. break
  571. case 1:
  572. startDate, err := time.Parse("2006-01-02", start_date)
  573. if err != nil {
  574. fmt.Println("Error parsing start date:", err)
  575. return
  576. }
  577. endDate, err := time.Parse("2006-01-02", end_date)
  578. if err != nil {
  579. fmt.Println("Error parsing end date:", err)
  580. return
  581. }
  582. dailyDates := splitByDay(startDate, endDate)
  583. var uniqueFields []map[string]interface{}
  584. for _, date := range dailyDates {
  585. list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  586. var dynamicFields []map[string]interface{}
  587. for _, result := range list {
  588. nb := result["日期"].([]byte)
  589. name := string(nb)
  590. dynamicField := make(map[string]interface{})
  591. dynamicField["日期"] = name
  592. numericColumns := make(map[string]interface{})
  593. nonNumericColumns := make(map[string]interface{})
  594. // 分类处理列
  595. for columnName, columnValue := range result {
  596. if columnName == "日期" || columnName == "合计" {
  597. continue
  598. }
  599. if columnValue == nil {
  600. nonNumericColumns[columnName] = ""
  601. continue
  602. }
  603. byteValue, ok := columnValue.([]byte)
  604. if !ok {
  605. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  606. continue
  607. }
  608. strValue := string(byteValue)
  609. floatValue, err := strconv.ParseFloat(strValue, 64)
  610. if err != nil {
  611. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  612. nonNumericColumns[columnName] = strValue
  613. } else {
  614. if floatValue == 0 {
  615. nonNumericColumns[columnName] = ""
  616. } else {
  617. numericColumns[columnName] = floatValue
  618. }
  619. }
  620. }
  621. // 添加数值列
  622. for columnName, columnValue := range numericColumns {
  623. dynamicField[columnName] = columnValue
  624. }
  625. // 添加非数值列
  626. for columnName, columnValue := range nonNumericColumns {
  627. dynamicField[columnName] = columnValue
  628. }
  629. hj := result["合计"].(int64)
  630. dynamicField["合计"] = hj
  631. dynamicFields = append(dynamicFields, dynamicField)
  632. }
  633. seen := make(map[interface{}]struct{})
  634. for _, field := range dynamicFields {
  635. value := field["日期"]
  636. if _, ok := seen[value]; !ok {
  637. seen[value] = struct{}{}
  638. uniqueFields = append(uniqueFields, field)
  639. }
  640. }
  641. }
  642. //for _, date := range dailyDates {
  643. // list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  644. // //fmt.Println(aa)
  645. // var dynamicFields []map[string]interface{}
  646. //
  647. // for _, result := range list {
  648. // // 打印患者ID
  649. // nb := result["日期"].([]byte)
  650. // name := string(nb)
  651. //
  652. // // 创建动态字段的map
  653. // dynamicField := make(map[string]interface{})
  654. // // 将日期放在首位
  655. // dynamicField["日期"] = name
  656. //
  657. // // 临时存储无数值的列
  658. // nonNumericColumns := make(map[string]interface{})
  659. //
  660. // // 先处理包含数值的列
  661. // for columnName, columnValue := range result {
  662. // if columnName == "日期" || columnName == "合计" {
  663. // continue
  664. // }
  665. // if columnValue == nil {
  666. // nonNumericColumns[columnName] = ""
  667. // continue
  668. // }
  669. //
  670. // byteValue, ok := columnValue.([]byte)
  671. // if !ok {
  672. // fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  673. // continue
  674. // }
  675. //
  676. // strValue := string(byteValue)
  677. //
  678. // floatValue, err := strconv.ParseFloat(strValue, 64)
  679. // if err != nil {
  680. // fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  681. // nonNumericColumns[columnName] = strValue
  682. // } else {
  683. // if floatValue == 0 {
  684. // nonNumericColumns[columnName] = ""
  685. // } else {
  686. // dynamicField[columnName] = floatValue
  687. // }
  688. // }
  689. // }
  690. //
  691. // // 添加无数值的列
  692. // for columnName, columnValue := range nonNumericColumns {
  693. // dynamicField[columnName] = columnValue
  694. // }
  695. //
  696. // // 将合计放在末尾
  697. // hj := result["合计"].(int64)
  698. // dynamicField["合计"] = hj
  699. //
  700. // dynamicFields = append(dynamicFields, dynamicField)
  701. // }
  702. //
  703. // // 将日期放在首位
  704. // seen := make(map[interface{}]struct{})
  705. // for _, field := range dynamicFields {
  706. // value := field["日期"]
  707. // if _, ok := seen[value]; !ok {
  708. // seen[value] = struct{}{}
  709. // uniqueFields = append(uniqueFields, field)
  710. // }
  711. // }
  712. //}
  713. //for _, date := range dailyDates {
  714. // list, _ := service.GetDialysisStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  715. // //fmt.Println(aa)
  716. // var dynamicFields []map[string]interface{}
  717. //
  718. // for _, result := range list {
  719. // // 打印患者ID
  720. // nb := result["日期"].([]byte)
  721. // name := string(nb)
  722. //
  723. // // 创建动态字段的map
  724. // dynamicField := make(map[string]interface{})
  725. // // 将日期放在首位
  726. // dynamicField["日期"] = name
  727. //
  728. // // 打印其他列的值,并添加到动态字段中
  729. // for columnName, columnValue := range result {
  730. // if columnName == "日期" {
  731. // continue
  732. // }
  733. // if columnName == "合计" {
  734. // continue
  735. // }
  736. // if columnValue == nil {
  737. // dynamicField[columnName] = ""
  738. // continue
  739. // }
  740. //
  741. // byteValue, ok := columnValue.([]byte)
  742. // if !ok {
  743. // fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  744. // continue
  745. // }
  746. //
  747. // strValue := string(byteValue)
  748. //
  749. // floatValue, err := strconv.ParseFloat(strValue, 64)
  750. // if err != nil {
  751. // fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  752. // } else {
  753. // if floatValue == 0 {
  754. // dynamicField[columnName] = ""
  755. // } else {
  756. // dynamicField[columnName] = floatValue
  757. // }
  758. // }
  759. // }
  760. //
  761. // // 将合计放在末尾
  762. // hj := result["合计"].(int64)
  763. // dynamicField["合计"] = hj
  764. //
  765. // dynamicFields = append(dynamicFields, dynamicField)
  766. // }
  767. //
  768. // // 将日期放在首位
  769. // seen := make(map[interface{}]struct{})
  770. // for _, field := range dynamicFields {
  771. // value := field["日期"]
  772. // if _, ok := seen[value]; !ok {
  773. // seen[value] = struct{}{}
  774. // uniqueFields = append(uniqueFields, field)
  775. // }
  776. // }
  777. //}
  778. c.ServeSuccessJSON(map[string]interface{}{
  779. "list": uniqueFields,
  780. })
  781. break
  782. case 3:
  783. months := groupByMonth(dates)
  784. var uniqueFields []map[string]interface{}
  785. for _, month := range months {
  786. // 解析字符串时显式指定时区为 UTC
  787. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[0].String())
  788. if err != nil {
  789. fmt.Println("解析时间出错:", err)
  790. return
  791. }
  792. // 解析字符串时显式指定时区为 UTC
  793. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[len(month)-1].String())
  794. if err != nil {
  795. fmt.Println("解析时间出错:", err)
  796. return
  797. }
  798. //dynamicFields := make([]map[string]interface{}, 0)
  799. list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  800. //fmt.Println(aa)
  801. var dynamicFields []map[string]interface{}
  802. //var uniqueFields []map[string]interface{}
  803. for _, result := range list {
  804. // 打印患者ID
  805. nb := result["日期"].([]byte)
  806. name := string(nb)
  807. // 创建动态字段的map
  808. dynamicField := make(map[string]interface{})
  809. // 将日期放在首位
  810. dynamicField["日期"] = name
  811. // 打印其他列的值,并添加到动态字段中
  812. for columnName, columnValue := range result {
  813. if columnName == "日期" {
  814. continue
  815. }
  816. if columnName == "合计" {
  817. continue
  818. }
  819. if columnValue == nil {
  820. dynamicField[columnName] = ""
  821. continue
  822. }
  823. byteValue, ok := columnValue.([]byte)
  824. if !ok {
  825. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  826. continue
  827. }
  828. strValue := string(byteValue)
  829. floatValue, err := strconv.ParseFloat(strValue, 64)
  830. if err != nil {
  831. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  832. } else {
  833. if floatValue == 0 {
  834. dynamicField[columnName] = ""
  835. } else {
  836. dynamicField[columnName] = floatValue
  837. }
  838. }
  839. }
  840. // 将合计放在末尾
  841. hj := result["合计"].(int64)
  842. dynamicField["合计"] = hj
  843. dynamicFields = append(dynamicFields, dynamicField)
  844. }
  845. // 将日期放在首位
  846. seen := make(map[interface{}]struct{})
  847. for _, field := range dynamicFields {
  848. value := field["日期"]
  849. if _, ok := seen[value]; !ok {
  850. seen[value] = struct{}{}
  851. uniqueFields = append(uniqueFields, field)
  852. }
  853. }
  854. }
  855. c.ServeSuccessJSON(map[string]interface{}{
  856. "list": uniqueFields,
  857. })
  858. break
  859. case 4:
  860. years := groupByYear(dates)
  861. var uniqueFields []map[string]interface{}
  862. for _, year := range years {
  863. // 解析字符串时显式指定时区为 UTC
  864. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[0].String())
  865. if err != nil {
  866. fmt.Println("解析时间出错:", err)
  867. return
  868. }
  869. // 解析字符串时显式指定时区为 UTC
  870. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[len(year)-1].String())
  871. if err != nil {
  872. fmt.Println("解析时间出错:", err)
  873. return
  874. }
  875. //dynamicFields := make([]map[string]interface{}, 0)
  876. list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  877. //fmt.Println(aa)
  878. var dynamicFields []map[string]interface{}
  879. //var uniqueFields []map[string]interface{}
  880. for _, result := range list {
  881. // 打印患者ID
  882. nb := result["日期"].([]byte)
  883. name := string(nb)
  884. // 创建动态字段的map
  885. dynamicField := make(map[string]interface{})
  886. // 将日期放在首位
  887. dynamicField["日期"] = name
  888. // 打印其他列的值,并添加到动态字段中
  889. for columnName, columnValue := range result {
  890. if columnName == "日期" {
  891. continue
  892. }
  893. if columnName == "合计" {
  894. continue
  895. }
  896. if columnValue == nil {
  897. dynamicField[columnName] = ""
  898. continue
  899. }
  900. byteValue, ok := columnValue.([]byte)
  901. if !ok {
  902. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  903. continue
  904. }
  905. strValue := string(byteValue)
  906. floatValue, err := strconv.ParseFloat(strValue, 64)
  907. if err != nil {
  908. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  909. } else {
  910. if floatValue == 0 {
  911. dynamicField[columnName] = ""
  912. } else {
  913. dynamicField[columnName] = floatValue
  914. }
  915. }
  916. }
  917. // 将合计放在末尾
  918. hj := result["合计"].(int64)
  919. dynamicField["合计"] = hj
  920. dynamicFields = append(dynamicFields, dynamicField)
  921. }
  922. // 将日期放在首位
  923. seen := make(map[interface{}]struct{})
  924. for _, field := range dynamicFields {
  925. value := field["日期"]
  926. if _, ok := seen[value]; !ok {
  927. seen[value] = struct{}{}
  928. uniqueFields = append(uniqueFields, field)
  929. }
  930. }
  931. }
  932. c.ServeSuccessJSON(map[string]interface{}{
  933. "list": uniqueFields,
  934. })
  935. break
  936. }
  937. } else {
  938. switch time_way {
  939. case 2:
  940. weeks := groupByWeek(dates)
  941. //var uniqueFields []map[string]interface{}
  942. var uniqueFields []map[string]interface{}
  943. for _, week := range weeks {
  944. // 解析字符串时显式指定时区为 UTC
  945. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[0].String())
  946. if err != nil {
  947. fmt.Println("解析时间出错:", err)
  948. return
  949. }
  950. // 解析字符串时显式指定时区为 UTC
  951. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String())
  952. if err != nil {
  953. fmt.Println("解析时间出错:", err)
  954. return
  955. }
  956. //dynamicFields := make([]map[string]interface{}, 0)
  957. list, _ := service.GetScheduleStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  958. //fmt.Println(aa)
  959. var dynamicFields []map[string]interface{}
  960. //var uniqueFields []map[string]interface{}
  961. for _, result := range list {
  962. // 打印患者ID
  963. nb := result["日期"].([]byte)
  964. name := string(nb)
  965. // 创建动态字段的map
  966. dynamicField := make(map[string]interface{})
  967. // 将日期放在首位
  968. dynamicField["日期"] = name
  969. // 打印其他列的值,并添加到动态字段中
  970. for columnName, columnValue := range result {
  971. if columnName == "日期" {
  972. continue
  973. }
  974. if columnName == "合计" {
  975. continue
  976. }
  977. if columnValue == nil {
  978. dynamicField[columnName] = ""
  979. continue
  980. }
  981. byteValue, ok := columnValue.([]byte)
  982. if !ok {
  983. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  984. continue
  985. }
  986. strValue := string(byteValue)
  987. floatValue, err := strconv.ParseFloat(strValue, 64)
  988. if err != nil {
  989. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  990. } else {
  991. if floatValue == 0 {
  992. dynamicField[columnName] = ""
  993. } else {
  994. dynamicField[columnName] = floatValue
  995. }
  996. }
  997. }
  998. // 将合计放在末尾
  999. hj := result["合计"].(int64)
  1000. dynamicField["合计"] = hj
  1001. dynamicFields = append(dynamicFields, dynamicField)
  1002. }
  1003. // 将日期放在首位
  1004. seen := make(map[interface{}]struct{})
  1005. for _, field := range dynamicFields {
  1006. value := field["日期"]
  1007. if _, ok := seen[value]; !ok {
  1008. seen[value] = struct{}{}
  1009. uniqueFields = append(uniqueFields, field)
  1010. }
  1011. }
  1012. }
  1013. c.ServeSuccessJSON(map[string]interface{}{
  1014. "list": uniqueFields,
  1015. })
  1016. break
  1017. case 1:
  1018. startDate, err := time.Parse("2006-01-02", start_date)
  1019. if err != nil {
  1020. fmt.Println("Error parsing start date:", err)
  1021. return
  1022. }
  1023. endDate, err := time.Parse("2006-01-02", end_date)
  1024. if err != nil {
  1025. fmt.Println("Error parsing end date:", err)
  1026. return
  1027. }
  1028. dailyDates := splitByDay(startDate, endDate)
  1029. var uniqueFields []map[string]interface{}
  1030. for _, date := range dailyDates {
  1031. list, _ := service.GetScheduleStats(date.Unix(), date.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  1032. //fmt.Println(aa)
  1033. var dynamicFields []map[string]interface{}
  1034. for _, result := range list {
  1035. // 打印患者ID
  1036. nb := result["日期"].([]byte)
  1037. name := string(nb)
  1038. // 创建动态字段的map
  1039. dynamicField := make(map[string]interface{})
  1040. // 将日期放在首位
  1041. dynamicField["日期"] = name
  1042. // 打印其他列的值,并添加到动态字段中
  1043. for columnName, columnValue := range result {
  1044. if columnName == "日期" {
  1045. continue
  1046. }
  1047. if columnName == "合计" {
  1048. continue
  1049. }
  1050. if columnValue == nil {
  1051. dynamicField[columnName] = ""
  1052. continue
  1053. }
  1054. byteValue, ok := columnValue.([]byte)
  1055. if !ok {
  1056. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  1057. continue
  1058. }
  1059. strValue := string(byteValue)
  1060. floatValue, err := strconv.ParseFloat(strValue, 64)
  1061. if err != nil {
  1062. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  1063. } else {
  1064. if floatValue == 0 {
  1065. dynamicField[columnName] = ""
  1066. } else {
  1067. dynamicField[columnName] = floatValue
  1068. }
  1069. }
  1070. }
  1071. // 将合计放在末尾
  1072. hj := result["合计"].(int64)
  1073. dynamicField["合计"] = hj
  1074. dynamicFields = append(dynamicFields, dynamicField)
  1075. }
  1076. // 将日期放在首位
  1077. seen := make(map[interface{}]struct{})
  1078. for _, field := range dynamicFields {
  1079. value := field["日期"]
  1080. if _, ok := seen[value]; !ok {
  1081. seen[value] = struct{}{}
  1082. uniqueFields = append(uniqueFields, field)
  1083. }
  1084. }
  1085. }
  1086. c.ServeSuccessJSON(map[string]interface{}{
  1087. "list": uniqueFields,
  1088. })
  1089. break
  1090. case 3:
  1091. months := groupByMonth(dates)
  1092. var uniqueFields []map[string]interface{}
  1093. for _, month := range months {
  1094. // 解析字符串时显式指定时区为 UTC
  1095. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[0].String())
  1096. if err != nil {
  1097. fmt.Println("解析时间出错:", err)
  1098. return
  1099. }
  1100. // 解析字符串时显式指定时区为 UTC
  1101. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", month[len(month)-1].String())
  1102. if err != nil {
  1103. fmt.Println("解析时间出错:", err)
  1104. return
  1105. }
  1106. //dynamicFields := make([]map[string]interface{}, 0)
  1107. list, _ := service.GetScheduleStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  1108. //fmt.Println(aa)
  1109. var dynamicFields []map[string]interface{}
  1110. //var uniqueFields []map[string]interface{}
  1111. for _, result := range list {
  1112. // 打印患者ID
  1113. nb := result["日期"].([]byte)
  1114. name := string(nb)
  1115. // 创建动态字段的map
  1116. dynamicField := make(map[string]interface{})
  1117. // 将日期放在首位
  1118. dynamicField["日期"] = name
  1119. // 打印其他列的值,并添加到动态字段中
  1120. for columnName, columnValue := range result {
  1121. if columnName == "日期" {
  1122. continue
  1123. }
  1124. if columnName == "合计" {
  1125. continue
  1126. }
  1127. if columnValue == nil {
  1128. dynamicField[columnName] = ""
  1129. continue
  1130. }
  1131. byteValue, ok := columnValue.([]byte)
  1132. if !ok {
  1133. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  1134. continue
  1135. }
  1136. strValue := string(byteValue)
  1137. floatValue, err := strconv.ParseFloat(strValue, 64)
  1138. if err != nil {
  1139. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  1140. } else {
  1141. if floatValue == 0 {
  1142. dynamicField[columnName] = ""
  1143. } else {
  1144. dynamicField[columnName] = floatValue
  1145. }
  1146. }
  1147. }
  1148. // 将合计放在末尾
  1149. hj := result["合计"].(int64)
  1150. dynamicField["合计"] = hj
  1151. dynamicFields = append(dynamicFields, dynamicField)
  1152. }
  1153. // 将日期放在首位
  1154. seen := make(map[interface{}]struct{})
  1155. for _, field := range dynamicFields {
  1156. value := field["日期"]
  1157. if _, ok := seen[value]; !ok {
  1158. seen[value] = struct{}{}
  1159. uniqueFields = append(uniqueFields, field)
  1160. }
  1161. }
  1162. }
  1163. c.ServeSuccessJSON(map[string]interface{}{
  1164. "list": uniqueFields,
  1165. })
  1166. break
  1167. case 4:
  1168. years := groupByYear(dates)
  1169. var uniqueFields []map[string]interface{}
  1170. for _, year := range years {
  1171. // 解析字符串时显式指定时区为 UTC
  1172. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[0].String())
  1173. if err != nil {
  1174. fmt.Println("解析时间出错:", err)
  1175. return
  1176. }
  1177. // 解析字符串时显式指定时区为 UTC
  1178. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", year[len(year)-1].String())
  1179. if err != nil {
  1180. fmt.Println("解析时间出错:", err)
  1181. return
  1182. }
  1183. //dynamicFields := make([]map[string]interface{}, 0)
  1184. list, _ := service.GetScheduleStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  1185. //fmt.Println(aa)
  1186. var dynamicFields []map[string]interface{}
  1187. //var uniqueFields []map[string]interface{}
  1188. for _, result := range list {
  1189. // 打印患者ID
  1190. nb := result["日期"].([]byte)
  1191. name := string(nb)
  1192. // 创建动态字段的map
  1193. dynamicField := make(map[string]interface{})
  1194. // 将日期放在首位
  1195. dynamicField["日期"] = name
  1196. // 打印其他列的值,并添加到动态字段中
  1197. for columnName, columnValue := range result {
  1198. if columnName == "日期" {
  1199. continue
  1200. }
  1201. if columnName == "合计" {
  1202. continue
  1203. }
  1204. if columnValue == nil {
  1205. dynamicField[columnName] = ""
  1206. continue
  1207. }
  1208. byteValue, ok := columnValue.([]byte)
  1209. if !ok {
  1210. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  1211. continue
  1212. }
  1213. strValue := string(byteValue)
  1214. floatValue, err := strconv.ParseFloat(strValue, 64)
  1215. if err != nil {
  1216. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  1217. } else {
  1218. if floatValue == 0 {
  1219. dynamicField[columnName] = ""
  1220. } else {
  1221. dynamicField[columnName] = floatValue
  1222. }
  1223. }
  1224. }
  1225. // 将合计放在末尾
  1226. hj := result["合计"].(int64)
  1227. dynamicField["合计"] = hj
  1228. dynamicFields = append(dynamicFields, dynamicField)
  1229. }
  1230. // 将日期放在首位
  1231. seen := make(map[interface{}]struct{})
  1232. for _, field := range dynamicFields {
  1233. value := field["日期"]
  1234. if _, ok := seen[value]; !ok {
  1235. seen[value] = struct{}{}
  1236. uniqueFields = append(uniqueFields, field)
  1237. }
  1238. }
  1239. }
  1240. c.ServeSuccessJSON(map[string]interface{}{
  1241. "list": uniqueFields,
  1242. })
  1243. break
  1244. }
  1245. }
  1246. }
  1247. func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
  1248. date_str := c.GetString("date")
  1249. mode, _ := c.GetInt64("mode")
  1250. origin, _ := c.GetInt64("origin")
  1251. page, _ := c.GetInt64("page")
  1252. limit, _ := c.GetInt64("limit")
  1253. time_way, _ := c.GetInt64("time_way")
  1254. var start_date string
  1255. var end_date string
  1256. if time_way == 1 {
  1257. start_date = date_str
  1258. end_date = date_str
  1259. } else {
  1260. start_date = strings.Split(date_str, "~")[0]
  1261. end_date = strings.Split(date_str, "~")[1]
  1262. }
  1263. if origin == 1 {
  1264. qcp, total, _ := service.GetDialysisPrescriptionInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  1265. c.ServeSuccessJSON(map[string]interface{}{
  1266. "list": qcp,
  1267. "total": total,
  1268. })
  1269. } else {
  1270. qcp, total, _ := service.GetScheduleInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  1271. c.ServeSuccessJSON(map[string]interface{}{
  1272. "list": qcp,
  1273. "total": total,
  1274. })
  1275. }
  1276. }
  1277. func (c *StatisticsApiController) GetAnticoagulant() {
  1278. start_date := c.GetString("start_date")
  1279. end_date := c.GetString("end_date")
  1280. timeLayout := "2006-01-02"
  1281. loc, _ := time.LoadLocation("Local")
  1282. var startTime int64
  1283. if len(start_date) > 0 {
  1284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1285. fmt.Println("err-----------", err)
  1286. if err != nil {
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1288. return
  1289. }
  1290. startTime = theTime.Unix()
  1291. }
  1292. var endTime int64
  1293. if len(end_date) > 0 {
  1294. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1295. if err != nil {
  1296. utils.ErrorLog(err.Error())
  1297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1298. return
  1299. }
  1300. endTime = theTime.Unix()
  1301. }
  1302. total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1303. if err2 != nil {
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1305. return
  1306. }
  1307. anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1308. if err != nil {
  1309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1310. return
  1311. }
  1312. type respData struct {
  1313. Name string `json:"name"`
  1314. Count int `json:"count"`
  1315. Percentage float64 `json:"percentage"`
  1316. }
  1317. var respDatas []respData
  1318. for anticoagulant, count := range anticoagulantData {
  1319. var respData respData
  1320. respData.Name = anticoagulant
  1321. respData.Count = count
  1322. respData.Percentage = float64(count) / float64(total) * 100
  1323. respDatas = append(respDatas, respData)
  1324. }
  1325. c.ServeSuccessJSON(map[string]interface{}{
  1326. "data": respDatas,
  1327. })
  1328. }
  1329. func (c *StatisticsApiController) GetAnticoagulantDetail() {
  1330. anticoagulant, _ := c.GetInt64("anticoagulant")
  1331. start_date := c.GetString("start_date")
  1332. end_date := c.GetString("end_date")
  1333. timeLayout := "2006-01-02"
  1334. page, _ := c.GetInt64("page", 0)
  1335. limit, _ := c.GetInt64("limit", 0)
  1336. if page <= 0 {
  1337. page = 1
  1338. }
  1339. if limit <= 0 {
  1340. limit = 10
  1341. }
  1342. loc, _ := time.LoadLocation("Local")
  1343. var startTime int64
  1344. if len(start_date) > 0 {
  1345. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1346. fmt.Println("err-----------", err)
  1347. if err != nil {
  1348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1349. return
  1350. }
  1351. startTime = theTime.Unix()
  1352. }
  1353. var endTime int64
  1354. if len(end_date) > 0 {
  1355. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1356. if err != nil {
  1357. utils.ErrorLog(err.Error())
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. endTime = theTime.Unix()
  1362. }
  1363. prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
  1364. c.ServeSuccessJSON(map[string]interface{}{
  1365. "prescriptions": prescriptions,
  1366. "total": total,
  1367. })
  1368. }
  1369. func (c *StatisticsApiController) GetDialyzer() {
  1370. start_date := c.GetString("start_date")
  1371. end_date := c.GetString("end_date")
  1372. timeLayout := "2006-01-02"
  1373. loc, _ := time.LoadLocation("Local")
  1374. var startTime int64
  1375. if len(start_date) > 0 {
  1376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1377. fmt.Println("err-----------", err)
  1378. if err != nil {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1380. return
  1381. }
  1382. startTime = theTime.Unix()
  1383. }
  1384. var endTime int64
  1385. if len(end_date) > 0 {
  1386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1387. if err != nil {
  1388. utils.ErrorLog(err.Error())
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1390. return
  1391. }
  1392. endTime = theTime.Unix()
  1393. }
  1394. total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1395. if err2 != nil {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1397. return
  1398. }
  1399. dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1400. DialysisIrrigation, err := service.GetDialysisIrrigationData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1401. DialysisStrainer, err := service.GetDialysisStrainerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1402. if err != nil {
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1404. return
  1405. }
  1406. type respData struct {
  1407. Name string `json:"name"`
  1408. Count int `json:"count"`
  1409. Percentage float64 `json:"percentage"`
  1410. }
  1411. var respDatas []respData
  1412. for _, item := range dialyzers {
  1413. if len(item.Dialyzer) > 0 {
  1414. var respData respData
  1415. respData.Name = item.Dialyzer
  1416. respData.Count = item.Count
  1417. respData.Percentage = float64(item.Count) / float64(total) * 100
  1418. respDatas = append(respDatas, respData)
  1419. }
  1420. }
  1421. for _, item := range DialysisIrrigation {
  1422. if len(item.Dialyzer) > 0 {
  1423. var respData respData
  1424. respData.Name = item.Dialyzer
  1425. respData.Count = item.Count
  1426. respData.Percentage = float64(item.Count) / float64(total) * 100
  1427. respDatas = append(respDatas, respData)
  1428. }
  1429. }
  1430. for _, item := range DialysisStrainer {
  1431. fmt.Println(item.Dialyzer)
  1432. if len(item.Dialyzer) > 0 {
  1433. var respData respData
  1434. respData.Name = item.Dialyzer
  1435. respData.Count = item.Count
  1436. respData.Percentage = float64(item.Count) / float64(total) * 100
  1437. respDatas = append(respDatas, respData)
  1438. }
  1439. }
  1440. c.ServeSuccessJSON(map[string]interface{}{
  1441. "data": respDatas,
  1442. })
  1443. }
  1444. func (c *StatisticsApiController) GetDialyzerDetail() {
  1445. dialyzer := c.GetString("dialyzer")
  1446. start_date := c.GetString("start_date")
  1447. end_date := c.GetString("end_date")
  1448. timeLayout := "2006-01-02"
  1449. page, _ := c.GetInt64("page", 0)
  1450. limit, _ := c.GetInt64("limit", 0)
  1451. if page <= 0 {
  1452. page = 1
  1453. }
  1454. if limit <= 0 {
  1455. limit = 10
  1456. }
  1457. loc, _ := time.LoadLocation("Local")
  1458. var startTime int64
  1459. if len(start_date) > 0 {
  1460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1461. fmt.Println("err-----------", err)
  1462. if err != nil {
  1463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1464. return
  1465. }
  1466. startTime = theTime.Unix()
  1467. }
  1468. var endTime int64
  1469. if len(end_date) > 0 {
  1470. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1471. if err != nil {
  1472. utils.ErrorLog(err.Error())
  1473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1474. return
  1475. }
  1476. endTime = theTime.Unix()
  1477. }
  1478. prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
  1479. c.ServeSuccessJSON(map[string]interface{}{
  1480. "prescriptions": prescriptions,
  1481. "total": total,
  1482. })
  1483. }
  1484. func (c *StatisticsApiController) GetDialyzerConfig() {
  1485. var dialyzer []string
  1486. dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
  1487. for _, item := range dialyzers {
  1488. dialyzer = append(dialyzer, item.DialysisDialyszers)
  1489. }
  1490. Irrigation, _ := service.GetIrrigationSummary(c.GetAdminUserInfo().CurrentOrgId)
  1491. for _, item := range Irrigation {
  1492. dialyzer = append(dialyzer, item.DialysisIrrigation)
  1493. }
  1494. DialysisStrainer, _ := service.GetDialysisStrainerSummary(c.GetAdminUserInfo().CurrentOrgId)
  1495. for _, item := range DialysisStrainer {
  1496. dialyzer = append(dialyzer, item.DialysisStrainer)
  1497. }
  1498. c.ServeSuccessJSON(map[string]interface{}{
  1499. "dialyzers": dialyzer,
  1500. })
  1501. }
  1502. // 配置检验数据查询
  1503. func (this *StatisticsApiController) GetInsepctionList() {
  1504. adminUser := this.GetAdminUserInfo()
  1505. orgid := adminUser.CurrentOrgId
  1506. configurationlist, err := service.GetInsepctionConfigurationList(orgid)
  1507. if err != nil {
  1508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1509. return
  1510. }
  1511. this.ServeSuccessJSON(map[string]interface{}{
  1512. "configurationlist": configurationlist,
  1513. })
  1514. }
  1515. func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
  1516. start_date := c.GetString("start_date")
  1517. end_date := c.GetString("end_date")
  1518. project_id, _ := c.GetInt64("project_id")
  1519. item_id, _ := c.GetInt64("item_id")
  1520. timeLayout := "2006-01-02"
  1521. loc, _ := time.LoadLocation("Local")
  1522. var startTime int64
  1523. if len(start_date) > 0 {
  1524. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1525. fmt.Println("err-----------", err)
  1526. if err != nil {
  1527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1528. return
  1529. }
  1530. startTime = theTime.Unix()
  1531. }
  1532. var endTime int64
  1533. if len(end_date) > 0 {
  1534. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1535. if err != nil {
  1536. utils.ErrorLog(err.Error())
  1537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1538. return
  1539. }
  1540. endTime = theTime.Unix()
  1541. }
  1542. //患者总数
  1543. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  1544. //获取配置
  1545. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1546. //获取数值在正常范围内的总数
  1547. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1548. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  1549. min, _ := strconv.ParseFloat(config.MinRange, 64)
  1550. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1551. //获取数值异常的总数
  1552. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1553. //获取没有检查的患者总数
  1554. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  1555. c.ServeSuccessJSON(map[string]interface{}{
  1556. "patient_count": patientCount,
  1557. "normal_total": normalTotal,
  1558. "unusual_total": unusualTotal,
  1559. "no_check_total": noCheckTotal,
  1560. "reference": reference,
  1561. "config": config,
  1562. })
  1563. }
  1564. func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
  1565. start_date := c.GetString("start_date")
  1566. end_date := c.GetString("end_date")
  1567. project_id, _ := c.GetInt64("project_id")
  1568. item_id, _ := c.GetInt64("item_id")
  1569. patient_id, _ := c.GetInt64("patient_id")
  1570. timeLayout := "2006-01-02"
  1571. loc, _ := time.LoadLocation("Local")
  1572. var startTime int64
  1573. if len(start_date) > 0 {
  1574. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1575. fmt.Println("err-----------", err)
  1576. if err != nil {
  1577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1578. return
  1579. }
  1580. startTime = theTime.Unix()
  1581. }
  1582. var endTime int64
  1583. if len(end_date) > 0 {
  1584. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1585. if err != nil {
  1586. utils.ErrorLog(err.Error())
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. endTime = theTime.Unix()
  1591. }
  1592. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1593. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1594. //获取配置
  1595. reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
  1596. //获取数值在正常范围内的总数
  1597. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  1598. c.ServeSuccessJSON(map[string]interface{}{
  1599. "patient": patient,
  1600. "reference": reference,
  1601. "inspections": inspections,
  1602. })
  1603. }
  1604. func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
  1605. start_date := c.GetString("start_date")
  1606. end_date := c.GetString("end_date")
  1607. project_id, _ := c.GetInt64("project_id")
  1608. item_id, _ := c.GetInt64("item_id")
  1609. item_type, _ := c.GetInt64("item_type")
  1610. keyword := c.GetString("keyword")
  1611. timeLayout := "2006-01-02"
  1612. loc, _ := time.LoadLocation("Local")
  1613. var startTime int64
  1614. if len(start_date) > 0 {
  1615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1616. fmt.Println("err-----------", err)
  1617. if err != nil {
  1618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1619. return
  1620. }
  1621. startTime = theTime.Unix()
  1622. }
  1623. var endTime int64
  1624. if len(end_date) > 0 {
  1625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1626. if err != nil {
  1627. utils.ErrorLog(err.Error())
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1629. return
  1630. }
  1631. endTime = theTime.Unix()
  1632. }
  1633. //获取配置
  1634. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1635. //获取数值在正常范围内的总数
  1636. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1637. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  1638. min, _ := strconv.ParseFloat(config.MinRange, 64)
  1639. //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  1640. //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  1641. //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1642. switch item_type {
  1643. case 1:
  1644. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "list": list,
  1647. "reference": reference,
  1648. })
  1649. break
  1650. case 2:
  1651. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  1652. c.ServeSuccessJSON(map[string]interface{}{
  1653. "list": list,
  1654. "reference": reference,
  1655. })
  1656. break
  1657. case 3:
  1658. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1659. c.ServeSuccessJSON(map[string]interface{}{
  1660. "list": list,
  1661. "reference": reference,
  1662. })
  1663. break
  1664. }
  1665. }
  1666. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  1667. //start_date := c.GetString("start_date")
  1668. end_date := c.GetString("end_date")
  1669. //keyword := c.GetString("keyword")
  1670. //timeLayout := "2006-01-02"
  1671. //loc, _ := time.LoadLocation("Local")
  1672. dynamicFields := make([]map[string]interface{}, 0)
  1673. list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
  1674. //fmt.Println(list)
  1675. for _, result := range list {
  1676. //fmt.Println(result)
  1677. // 打印患者ID
  1678. nb := result["姓名"].([]byte)
  1679. name := string(nb)
  1680. //ynamicFields := make([]map[string]interface{})
  1681. //var dynamicFields DynamicData
  1682. ynamicField := make(map[string]interface{})
  1683. ynamicField["姓名"] = name
  1684. // 打印其他列的值
  1685. for columnName, columnValue := range result {
  1686. // 跳过患者ID列
  1687. if columnName == "姓名" {
  1688. continue
  1689. }
  1690. // 检查值是否为nil
  1691. if columnValue == nil {
  1692. fmt.Printf("Column: %s, Value: <nil>\n", columnName)
  1693. continue
  1694. }
  1695. // 将字节切片转换为字符串
  1696. byteValue, ok := columnValue.([]byte)
  1697. if !ok {
  1698. // 如果无法转换为[]byte,输出错误信息
  1699. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  1700. continue
  1701. }
  1702. // 将字节切片转换为字符串
  1703. strValue := string(byteValue)
  1704. // 尝试将字符串转换为浮点数
  1705. floatValue, _ := strconv.ParseFloat(strValue, 64)
  1706. //if err != nil {
  1707. // // 如果转换失败,输出错误信息
  1708. // fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  1709. //} else {
  1710. // // 如果转换成功,输出列名和浮点数值
  1711. // fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
  1712. //}
  1713. ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
  1714. if floatValue == 0 {
  1715. ynamicField[columnName] = ""
  1716. } else {
  1717. ynamicField[columnName] = floatValue
  1718. }
  1719. fmt.Println(ynamicField)
  1720. dynamicFields = append(dynamicFields, ynamicField)
  1721. }
  1722. }
  1723. seen := make(map[interface{}]struct{})
  1724. var uniqueFields []map[string]interface{}
  1725. for _, field := range dynamicFields {
  1726. value := field["姓名"]
  1727. // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
  1728. if _, ok := seen[value]; !ok {
  1729. seen[value] = struct{}{}
  1730. uniqueFields = append(uniqueFields, field)
  1731. }
  1732. }
  1733. c.ServeSuccessJSON(map[string]interface{}{
  1734. "list": uniqueFields,
  1735. })
  1736. //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  1737. //
  1738. //var names []string
  1739. //
  1740. //for _, item := range list {
  1741. // names = append(names, item.ItemName)
  1742. //}
  1743. //
  1744. //names = RemoveRepeatedNameElement(names)
  1745. //fmt.Println(names)
  1746. //
  1747. //var tempList []models.InspectionTen
  1748. //list_two := RemoveRepeatedInspectPatientElement(list)
  1749. //for _, item := range list_two {
  1750. // var temp models.InspectionTen
  1751. // var temptwos []models.InspectionValue
  1752. // temp.PatientId = item.PatientId
  1753. // temp.Name = item.Name
  1754. // for _, subitem := range list {
  1755. // if item.PatientId == subitem.PatientId {
  1756. // var temptwo models.InspectionValue
  1757. // temptwo.Name = subitem.ItemName
  1758. // temptwo.Value = subitem.InspectValue
  1759. // temptwos = append(temptwos, temptwo)
  1760. // }
  1761. // }
  1762. // temp.Values = temptwos
  1763. // tempList = append(tempList, temp)
  1764. //}
  1765. //
  1766. //var filtered []string
  1767. //for _, item := range names {
  1768. // if item != "a" {
  1769. // filtered = append(filtered, item)
  1770. // }
  1771. //}
  1772. //
  1773. //for _, item := range tempList {
  1774. // for _, subitem := range item.Values {
  1775. // for _, name := range filtered {
  1776. // if subitem.Name != name {
  1777. // filtered = append(filtered, name)
  1778. // }
  1779. // }
  1780. // }
  1781. //}
  1782. //
  1783. ////// 将剩余字符串填充到 Inspection 数组中
  1784. ////for _, name := range filtered {
  1785. //// var temptwo models.InspectionValue
  1786. //// temptwo.Name = subitem.ItemName
  1787. //// temptwo.Value = subitem.InspectValue
  1788. //// temptwos = append(temptwos, temptwo)
  1789. ////}
  1790. //
  1791. //for _, item := range tempList {
  1792. // //for _, subitem := range item.Values {
  1793. // var temptwo models.InspectionValue
  1794. // for _, name := range filtered {
  1795. // temptwo.Name = name
  1796. // temptwo.Value = ""
  1797. // }
  1798. // item.Values = append(item.Values, temptwo)
  1799. // //}
  1800. // fmt.Println(item.Values)
  1801. //}
  1802. }
  1803. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  1804. start_date := c.GetString("start_date")
  1805. end_date := c.GetString("end_date")
  1806. project_id, _ := c.GetInt64("project_id")
  1807. item_id, _ := c.GetInt64("item_id")
  1808. item_type, _ := c.GetInt64("item_type")
  1809. //order_type, _ := c.GetInt64("order_type")
  1810. keyword := c.GetString("keyword")
  1811. s_type, _ := c.GetInt64("type")
  1812. timeLayout := "2006-01-02"
  1813. loc, _ := time.LoadLocation("Local")
  1814. var startTime int64
  1815. if len(start_date) > 0 {
  1816. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1817. fmt.Println("err-----------", err)
  1818. if err != nil {
  1819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1820. return
  1821. }
  1822. startTime = theTime.Unix()
  1823. }
  1824. var endTime int64
  1825. if len(end_date) > 0 {
  1826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1827. if err != nil {
  1828. utils.ErrorLog(err.Error())
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1830. return
  1831. }
  1832. endTime = theTime.Unix()
  1833. }
  1834. //获取配置
  1835. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  1836. //获取数值在正常范围内的总数
  1837. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  1838. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  1839. switch item_type {
  1840. case 0:
  1841. break
  1842. case 1:
  1843. if s_type == 2 { //KTV
  1844. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  1845. c.ServeSuccessJSON(map[string]interface{}{
  1846. "list": list,
  1847. })
  1848. } else if s_type == 3 { //URR
  1849. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  1850. c.ServeSuccessJSON(map[string]interface{}{
  1851. "list": list,
  1852. })
  1853. } else {
  1854. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1855. c.ServeSuccessJSON(map[string]interface{}{
  1856. "list": list,
  1857. "reference": reference,
  1858. })
  1859. }
  1860. break
  1861. case 2:
  1862. if s_type == 2 { //KTV
  1863. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  1864. c.ServeSuccessJSON(map[string]interface{}{
  1865. "list": list,
  1866. })
  1867. } else if s_type == 3 { //URR
  1868. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  1869. c.ServeSuccessJSON(map[string]interface{}{
  1870. "list": list,
  1871. })
  1872. } else {
  1873. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  1874. c.ServeSuccessJSON(map[string]interface{}{
  1875. "list": list,
  1876. "reference": reference,
  1877. })
  1878. }
  1879. break
  1880. case 3:
  1881. if s_type == 2 { //KTV
  1882. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  1883. c.ServeSuccessJSON(map[string]interface{}{
  1884. "list": list,
  1885. })
  1886. } else if s_type == 3 { //URR
  1887. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  1888. c.ServeSuccessJSON(map[string]interface{}{
  1889. "list": list,
  1890. })
  1891. } else {
  1892. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1893. c.ServeSuccessJSON(map[string]interface{}{
  1894. "list": list,
  1895. "reference": reference,
  1896. })
  1897. }
  1898. break
  1899. }
  1900. }
  1901. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  1902. start_date := c.GetString("start_date")
  1903. end_date := c.GetString("end_date")
  1904. project_id, _ := c.GetInt64("project_id")
  1905. item_id, _ := c.GetInt64("item_id")
  1906. s_type, _ := c.GetInt64("type")
  1907. timeLayout := "2006-01-02"
  1908. loc, _ := time.LoadLocation("Local")
  1909. var startTime int64
  1910. if len(start_date) > 0 {
  1911. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1912. fmt.Println("err-----------", err)
  1913. if err != nil {
  1914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1915. return
  1916. }
  1917. startTime = theTime.Unix()
  1918. }
  1919. var endTime int64
  1920. if len(end_date) > 0 {
  1921. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1922. if err != nil {
  1923. utils.ErrorLog(err.Error())
  1924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1925. return
  1926. }
  1927. endTime = theTime.Unix()
  1928. }
  1929. //患者总数
  1930. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  1931. //获取配置
  1932. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  1933. //获取数值在正常范围内的总数
  1934. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  1935. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  1936. if s_type == 2 {
  1937. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  1938. //获取数值异常的总数
  1939. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  1940. //获取没有检查的患者总数
  1941. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  1942. c.ServeSuccessJSON(map[string]interface{}{
  1943. "patient_count": patientCount,
  1944. "normal_total": normalTotal,
  1945. "unusual_total": unusualTotal,
  1946. "no_check_total": noCheckTotal,
  1947. })
  1948. } else if s_type == 3 {
  1949. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  1950. //获取数值异常的总数
  1951. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  1952. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  1953. //获取没有检查的患者总数
  1954. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  1955. c.ServeSuccessJSON(map[string]interface{}{
  1956. "patient_count": patientCount,
  1957. "normal_total": normalTotal,
  1958. "unusual_total": unusualTotal,
  1959. "no_check_total": noCheckTotal,
  1960. })
  1961. } else {
  1962. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1963. //获取数值异常的总数
  1964. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1965. //获取没有检查的患者总数
  1966. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  1967. c.ServeSuccessJSON(map[string]interface{}{
  1968. "patient_count": patientCount,
  1969. "normal_total": normalTotal,
  1970. "unusual_total": unusualTotal,
  1971. "no_check_total": noCheckTotal,
  1972. "reference": reference,
  1973. })
  1974. }
  1975. }
  1976. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  1977. start_date := c.GetString("start_time")
  1978. end_date := c.GetString("end_time")
  1979. project_id, _ := c.GetInt64("project_id")
  1980. item_id, _ := c.GetInt64("item_id")
  1981. patient_id, _ := c.GetInt64("patient_id")
  1982. s_type, _ := c.GetInt64("type")
  1983. timeLayout := "2006-01-02"
  1984. loc, _ := time.LoadLocation("Local")
  1985. var startTime int64
  1986. if len(start_date) > 0 {
  1987. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1988. fmt.Println("err-----------", err)
  1989. if err != nil {
  1990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1991. return
  1992. }
  1993. startTime = theTime.Unix()
  1994. }
  1995. var endTime int64
  1996. if len(end_date) > 0 {
  1997. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1998. if err != nil {
  1999. utils.ErrorLog(err.Error())
  2000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2001. return
  2002. }
  2003. endTime = theTime.Unix()
  2004. }
  2005. if s_type == 2 {
  2006. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  2007. //获取配置
  2008. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  2009. //获取数值在正常范围内的总数
  2010. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  2011. c.ServeSuccessJSON(map[string]interface{}{
  2012. "patient": patient,
  2013. "reference": reference,
  2014. "inspections": inspections,
  2015. })
  2016. } else if s_type == 3 {
  2017. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  2018. //获取配置
  2019. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  2020. //获取数值在正常范围内的总数
  2021. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  2022. c.ServeSuccessJSON(map[string]interface{}{
  2023. "patient": patient,
  2024. "reference": reference,
  2025. "inspections": inspections,
  2026. })
  2027. } else {
  2028. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  2029. //获取配置
  2030. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  2031. //获取数值在正常范围内的总数
  2032. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  2033. c.ServeSuccessJSON(map[string]interface{}{
  2034. "patient": patient,
  2035. "reference": reference,
  2036. "inspections": inspections,
  2037. })
  2038. }
  2039. }
  2040. func (c *StatisticsApiController) GetStatistics() {
  2041. adminUserInfo := c.GetAdminUserInfo()
  2042. // thisTime := time.Now()
  2043. year, month, day := time.Now().Date()
  2044. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2045. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  2046. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  2047. todayWeek := int(todayTime.Weekday())
  2048. if todayWeek == 0 {
  2049. todayWeek = 7
  2050. }
  2051. weekEnd := 7 - todayWeek
  2052. weekStart := weekEnd - 6
  2053. // endDay := todayTime.AddDate(0, 0, weekEnd)
  2054. startDay := todayTime.AddDate(0, 0, weekStart)
  2055. //患者总数
  2056. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  2057. //今日透析
  2058. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  2059. //本周透析
  2060. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  2061. //传染病
  2062. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  2063. //性别分布
  2064. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  2065. //年龄分布
  2066. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  2067. //透析模式
  2068. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  2069. c.ServeSuccessJSON(map[string]interface{}{
  2070. "patient_count": patientCount,
  2071. "today_dialysis_count": todayDialysisCount,
  2072. "week_daylysis_count": weekDaylysisCount,
  2073. "disease_counts": diseaseCounts,
  2074. "gender_counts": genderCounts,
  2075. "age_counts": ageCounts,
  2076. "mode_counts": modeCounts,
  2077. })
  2078. }
  2079. func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
  2080. newArr = make([]models.InspectionTenOne, 0)
  2081. for i := 0; i < len(arr); i++ {
  2082. repeat := false
  2083. for j := i + 1; j < len(arr); j++ {
  2084. if arr[i].PatientId == arr[j].PatientId {
  2085. repeat = true
  2086. break
  2087. }
  2088. }
  2089. if !repeat {
  2090. newArr = append(newArr, arr[i])
  2091. }
  2092. }
  2093. return
  2094. }
  2095. func RemoveRepeatedNameElement(arr []string) (newArr []string) {
  2096. newArr = make([]string, 0)
  2097. for i := 0; i < len(arr); i++ {
  2098. repeat := false
  2099. for j := i + 1; j < len(arr); j++ {
  2100. if arr[i] == arr[j] {
  2101. repeat = true
  2102. break
  2103. }
  2104. }
  2105. if !repeat {
  2106. newArr = append(newArr, arr[i])
  2107. }
  2108. }
  2109. return
  2110. }
  2111. // 根据指定的日期范围拆分成周、月、年
  2112. func splitDateRange(startDate, endDate string) ([]time.Time, error) {
  2113. startTime, err := time.Parse("2006-01-02", startDate)
  2114. if err != nil {
  2115. return nil, err
  2116. }
  2117. endTime, err := time.Parse("2006-01-02", endDate)
  2118. if err != nil {
  2119. return nil, err
  2120. }
  2121. var result []time.Time
  2122. for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
  2123. result = append(result, date)
  2124. }
  2125. return result, nil
  2126. }
  2127. // 按周统计日期
  2128. func groupByWeek(dates []time.Time) [][]time.Time {
  2129. var result [][]time.Time
  2130. var currentWeek []time.Time
  2131. for _, date := range dates {
  2132. currentWeek = append(currentWeek, date)
  2133. if date.Weekday() == time.Sunday {
  2134. result = append(result, currentWeek)
  2135. currentWeek = nil
  2136. }
  2137. }
  2138. if len(currentWeek) > 0 {
  2139. result = append(result, currentWeek)
  2140. }
  2141. return result
  2142. }
  2143. // 按月统计日期
  2144. func groupByMonth(dates []time.Time) [][]time.Time {
  2145. var result [][]time.Time
  2146. var currentMonth []time.Time
  2147. lastMonth := dates[0].Month()
  2148. for _, date := range dates {
  2149. if date.Month() != lastMonth {
  2150. result = append(result, currentMonth)
  2151. currentMonth = nil
  2152. lastMonth = date.Month()
  2153. }
  2154. currentMonth = append(currentMonth, date)
  2155. }
  2156. if len(currentMonth) > 0 {
  2157. result = append(result, currentMonth)
  2158. }
  2159. return result
  2160. }
  2161. // 按年统计日期
  2162. func groupByYear(dates []time.Time) [][]time.Time {
  2163. var result [][]time.Time
  2164. var currentYear []time.Time
  2165. lastYear := dates[0].Year()
  2166. for _, date := range dates {
  2167. if date.Year() != lastYear {
  2168. result = append(result, currentYear)
  2169. currentYear = nil
  2170. lastYear = date.Year()
  2171. }
  2172. currentYear = append(currentYear, date)
  2173. }
  2174. if len(currentYear) > 0 {
  2175. result = append(result, currentYear)
  2176. }
  2177. return result
  2178. }
  2179. // 将日期拆分为按天统计
  2180. func splitByDay(startDate, endDate time.Time) []time.Time {
  2181. var dates []time.Time
  2182. for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
  2183. dates = append(dates, d)
  2184. }
  2185. return dates
  2186. }
  2187. // 排序函数
  2188. func sortFieldsByValue(field map[string]interface{}) map[string]interface{} {
  2189. // 将键值对分成两个部分,一个有值,一个无值
  2190. var withValue, withoutValue []string
  2191. for key, value := range field {
  2192. if key == "日期" || key == "合计" {
  2193. continue
  2194. }
  2195. if value == "" {
  2196. withoutValue = append(withoutValue, key)
  2197. } else {
  2198. withValue = append(withValue, key)
  2199. }
  2200. }
  2201. // 对有值和无值部分分别排序
  2202. sort.Strings(withValue)
  2203. sort.Strings(withoutValue)
  2204. // 创建一个新的有序map
  2205. sortedField := make(map[string]interface{})
  2206. sortedField["日期"] = field["日期"]
  2207. for _, key := range withValue {
  2208. sortedField[key] = field[key]
  2209. }
  2210. for _, key := range withoutValue {
  2211. sortedField[key] = field[key]
  2212. }
  2213. sortedField["合计"] = field["合计"]
  2214. return sortedField
  2215. }