statistics_api_controller.go 77KB

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