statistics_api_controller.go 78KB

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