statistics_api_controller.go 74KB

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