statistics_api_controller.go 68KB

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