statistics_api_controller.go 68KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  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. for _, week := range weeks {
  303. // 解析字符串时显式指定时区为 UTC
  304. t, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[0].String())
  305. if err != nil {
  306. fmt.Println("解析时间出错:", err)
  307. return
  308. }
  309. // 解析字符串时显式指定时区为 UTC
  310. t2, err := time.Parse("2006-01-02 15:04:05 -0700 MST", week[len(week)-1].String())
  311. if err != nil {
  312. fmt.Println("解析时间出错:", err)
  313. return
  314. }
  315. //dynamicFields := make([]map[string]interface{}, 0)
  316. list, _ := service.GetDialysisStats(t.Unix(), t2.Unix(), mode, c.GetAdminUserInfo().CurrentOrgId, time_way)
  317. //fmt.Println(aa)
  318. var dynamicFields []map[string]interface{}
  319. //var uniqueFields []map[string]interface{}
  320. for _, result := range list {
  321. nb := result["日期"].([]byte)
  322. name := string(nb)
  323. dynamicField := make(map[string]interface{})
  324. dynamicField["日期"] = name
  325. numericColumns := make(map[string]interface{})
  326. nonNumericColumns := make(map[string]interface{})
  327. // 分类处理列
  328. for columnName, columnValue := range result {
  329. if columnName == "日期" || columnName == "合计" {
  330. continue
  331. }
  332. if columnValue == nil {
  333. nonNumericColumns[columnName] = ""
  334. continue
  335. }
  336. byteValue, ok := columnValue.([]byte)
  337. if !ok {
  338. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  339. continue
  340. }
  341. strValue := string(byteValue)
  342. floatValue, err := strconv.ParseFloat(strValue, 64)
  343. if err != nil {
  344. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  345. nonNumericColumns[columnName] = strValue
  346. } else {
  347. if floatValue == 0 {
  348. nonNumericColumns[columnName] = ""
  349. } else {
  350. numericColumns[columnName] = floatValue
  351. }
  352. }
  353. }
  354. // 添加数值列
  355. for columnName, columnValue := range numericColumns {
  356. dynamicField[columnName] = columnValue
  357. }
  358. // 添加非数值列
  359. for columnName, columnValue := range nonNumericColumns {
  360. dynamicField[columnName] = columnValue
  361. }
  362. hj := result["合计"].(int64)
  363. dynamicField["合计"] = hj
  364. dynamicFields = append(dynamicFields, dynamicField)
  365. }
  366. seen := make(map[interface{}]struct{})
  367. for _, field := range dynamicFields {
  368. value := field["日期"]
  369. if _, ok := seen[value]; !ok {
  370. seen[value] = struct{}{}
  371. uniqueFields = append(uniqueFields, field)
  372. //// 对字段进行排序,有值的排在前面
  373. //sortedField := sortFieldsByValue(field)
  374. //uniqueFields = append(uniqueFields, sortedField)
  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. }