statistics_api_controller.go 60KB

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