statistics_api_controller.go 41KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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. if origin == 1 {
  291. data, _ := service.GetDialysisStats(startTime, endTime, time_way, mode)
  292. c.ServeSuccessJSON(map[string]interface{}{
  293. "data": data,
  294. })
  295. } else {
  296. data, _ := service.GetScheduleStats(startTime, endTime, time_way, mode)
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "data": data,
  299. })
  300. }
  301. }
  302. func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
  303. }
  304. func (c *StatisticsApiController) GetAnticoagulant() {
  305. start_date := c.GetString("start_date")
  306. end_date := c.GetString("end_date")
  307. timeLayout := "2006-01-02"
  308. loc, _ := time.LoadLocation("Local")
  309. var startTime int64
  310. if len(start_date) > 0 {
  311. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  312. fmt.Println("err-----------", err)
  313. if err != nil {
  314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  315. return
  316. }
  317. startTime = theTime.Unix()
  318. }
  319. var endTime int64
  320. if len(end_date) > 0 {
  321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  322. if err != nil {
  323. utils.ErrorLog(err.Error())
  324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  325. return
  326. }
  327. endTime = theTime.Unix()
  328. }
  329. total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  330. if err2 != nil {
  331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  332. return
  333. }
  334. anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  335. if err != nil {
  336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  337. return
  338. }
  339. type respData struct {
  340. Name string `json:"name"`
  341. Count int `json:"count"`
  342. Percentage float64 `json:"percentage"`
  343. }
  344. var respDatas []respData
  345. for anticoagulant, count := range anticoagulantData {
  346. var respData respData
  347. respData.Name = anticoagulant
  348. respData.Count = count
  349. respData.Percentage = float64(count) / float64(total) * 100
  350. respDatas = append(respDatas, respData)
  351. }
  352. c.ServeSuccessJSON(map[string]interface{}{
  353. "data": respDatas,
  354. })
  355. }
  356. func (c *StatisticsApiController) GetAnticoagulantDetail() {
  357. anticoagulant, _ := c.GetInt64("anticoagulant")
  358. start_date := c.GetString("start_date")
  359. end_date := c.GetString("end_date")
  360. timeLayout := "2006-01-02"
  361. page, _ := c.GetInt64("page", 0)
  362. limit, _ := c.GetInt64("limit", 0)
  363. if page <= 0 {
  364. page = 1
  365. }
  366. if limit <= 0 {
  367. limit = 10
  368. }
  369. loc, _ := time.LoadLocation("Local")
  370. var startTime int64
  371. if len(start_date) > 0 {
  372. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  373. fmt.Println("err-----------", err)
  374. if err != nil {
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. startTime = theTime.Unix()
  379. }
  380. var endTime int64
  381. if len(end_date) > 0 {
  382. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  383. if err != nil {
  384. utils.ErrorLog(err.Error())
  385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  386. return
  387. }
  388. endTime = theTime.Unix()
  389. }
  390. prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "prescriptions": prescriptions,
  393. "total": total,
  394. })
  395. }
  396. func (c *StatisticsApiController) GetDialyzer() {
  397. start_date := c.GetString("start_date")
  398. end_date := c.GetString("end_date")
  399. timeLayout := "2006-01-02"
  400. loc, _ := time.LoadLocation("Local")
  401. var startTime int64
  402. if len(start_date) > 0 {
  403. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  404. fmt.Println("err-----------", err)
  405. if err != nil {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  407. return
  408. }
  409. startTime = theTime.Unix()
  410. }
  411. var endTime int64
  412. if len(end_date) > 0 {
  413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  414. if err != nil {
  415. utils.ErrorLog(err.Error())
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. endTime = theTime.Unix()
  420. }
  421. total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  422. if err2 != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  424. return
  425. }
  426. dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  427. if err != nil {
  428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  429. return
  430. }
  431. type respData struct {
  432. Name string `json:"name"`
  433. Count int `json:"count"`
  434. Percentage float64 `json:"percentage"`
  435. }
  436. var respDatas []respData
  437. for _, item := range dialyzers {
  438. var respData respData
  439. respData.Name = item.Dialyzer
  440. respData.Count = item.Count
  441. respData.Percentage = float64(item.Count) / float64(total) * 100
  442. respDatas = append(respDatas, respData)
  443. }
  444. c.ServeSuccessJSON(map[string]interface{}{
  445. "data": respDatas,
  446. })
  447. }
  448. func (c *StatisticsApiController) GetDialyzerDetail() {
  449. dialyzer := c.GetString("dialyzer")
  450. start_date := c.GetString("start_date")
  451. end_date := c.GetString("end_date")
  452. timeLayout := "2006-01-02"
  453. page, _ := c.GetInt64("page", 0)
  454. limit, _ := c.GetInt64("limit", 0)
  455. if page <= 0 {
  456. page = 1
  457. }
  458. if limit <= 0 {
  459. limit = 10
  460. }
  461. loc, _ := time.LoadLocation("Local")
  462. var startTime int64
  463. if len(start_date) > 0 {
  464. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  465. fmt.Println("err-----------", err)
  466. if err != nil {
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. startTime = theTime.Unix()
  471. }
  472. var endTime int64
  473. if len(end_date) > 0 {
  474. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  475. if err != nil {
  476. utils.ErrorLog(err.Error())
  477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  478. return
  479. }
  480. endTime = theTime.Unix()
  481. }
  482. prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
  483. c.ServeSuccessJSON(map[string]interface{}{
  484. "prescriptions": prescriptions,
  485. "total": total,
  486. })
  487. }
  488. func (c *StatisticsApiController) GetDialyzerConfig() {
  489. dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
  490. c.ServeSuccessJSON(map[string]interface{}{
  491. "dialyzers": dialyzers,
  492. })
  493. }
  494. // 配置检验数据查询
  495. func (this *StatisticsApiController) GetInsepctionList() {
  496. adminUser := this.GetAdminUserInfo()
  497. orgid := adminUser.CurrentOrgId
  498. configurationlist, err := service.GetInsepctionConfigurationList(orgid)
  499. if err != nil {
  500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  501. return
  502. }
  503. this.ServeSuccessJSON(map[string]interface{}{
  504. "configurationlist": configurationlist,
  505. })
  506. }
  507. func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
  508. start_date := c.GetString("start_date")
  509. end_date := c.GetString("end_date")
  510. project_id, _ := c.GetInt64("project_id")
  511. item_id, _ := c.GetInt64("item_id")
  512. timeLayout := "2006-01-02"
  513. loc, _ := time.LoadLocation("Local")
  514. var startTime int64
  515. if len(start_date) > 0 {
  516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  517. fmt.Println("err-----------", err)
  518. if err != nil {
  519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  520. return
  521. }
  522. startTime = theTime.Unix()
  523. }
  524. var endTime int64
  525. if len(end_date) > 0 {
  526. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  527. if err != nil {
  528. utils.ErrorLog(err.Error())
  529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  530. return
  531. }
  532. endTime = theTime.Unix()
  533. }
  534. //患者总数
  535. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  536. //获取配置
  537. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  538. //获取数值在正常范围内的总数
  539. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  540. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  541. min, _ := strconv.ParseFloat(config.MinRange, 64)
  542. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  543. //获取数值异常的总数
  544. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  545. //获取没有检查的患者总数
  546. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  547. c.ServeSuccessJSON(map[string]interface{}{
  548. "patient_count": patientCount,
  549. "normal_total": normalTotal,
  550. "unusual_total": unusualTotal,
  551. "no_check_total": noCheckTotal,
  552. "reference": reference,
  553. "config": config,
  554. })
  555. }
  556. func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
  557. start_date := c.GetString("start_time")
  558. end_date := c.GetString("end_time")
  559. project_id, _ := c.GetInt64("project_id")
  560. item_id, _ := c.GetInt64("item_id")
  561. patient_id, _ := c.GetInt64("patient_id")
  562. timeLayout := "2006-01-02"
  563. loc, _ := time.LoadLocation("Local")
  564. var startTime int64
  565. if len(start_date) > 0 {
  566. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  567. fmt.Println("err-----------", err)
  568. if err != nil {
  569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  570. return
  571. }
  572. startTime = theTime.Unix()
  573. }
  574. var endTime int64
  575. if len(end_date) > 0 {
  576. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  577. if err != nil {
  578. utils.ErrorLog(err.Error())
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  580. return
  581. }
  582. endTime = theTime.Unix()
  583. }
  584. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  585. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  586. //获取配置
  587. reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
  588. //获取数值在正常范围内的总数
  589. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  590. c.ServeSuccessJSON(map[string]interface{}{
  591. "patient": patient,
  592. "reference": reference,
  593. "inspections": inspections,
  594. })
  595. }
  596. func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
  597. start_date := c.GetString("start_date")
  598. end_date := c.GetString("end_date")
  599. project_id, _ := c.GetInt64("project_id")
  600. item_id, _ := c.GetInt64("item_id")
  601. item_type, _ := c.GetInt64("item_type")
  602. keyword := c.GetString("keyword")
  603. timeLayout := "2006-01-02"
  604. loc, _ := time.LoadLocation("Local")
  605. var startTime int64
  606. if len(start_date) > 0 {
  607. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  608. fmt.Println("err-----------", err)
  609. if err != nil {
  610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  611. return
  612. }
  613. startTime = theTime.Unix()
  614. }
  615. var endTime int64
  616. if len(end_date) > 0 {
  617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  618. if err != nil {
  619. utils.ErrorLog(err.Error())
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  621. return
  622. }
  623. endTime = theTime.Unix()
  624. }
  625. //获取配置
  626. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  627. //获取数值在正常范围内的总数
  628. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  629. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  630. min, _ := strconv.ParseFloat(config.MinRange, 64)
  631. //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  632. //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  633. //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  634. switch item_type {
  635. case 1:
  636. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  637. c.ServeSuccessJSON(map[string]interface{}{
  638. "list": list,
  639. "reference": reference,
  640. })
  641. break
  642. case 2:
  643. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  644. c.ServeSuccessJSON(map[string]interface{}{
  645. "list": list,
  646. "reference": reference,
  647. })
  648. break
  649. case 3:
  650. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  651. c.ServeSuccessJSON(map[string]interface{}{
  652. "list": list,
  653. "reference": reference,
  654. })
  655. break
  656. }
  657. }
  658. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  659. //start_date := c.GetString("start_date")
  660. end_date := c.GetString("end_date")
  661. //keyword := c.GetString("keyword")
  662. //timeLayout := "2006-01-02"
  663. //loc, _ := time.LoadLocation("Local")
  664. dynamicFields := make([]map[string]interface{}, 0)
  665. list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
  666. //fmt.Println(list)
  667. for _, result := range list {
  668. //fmt.Println(result)
  669. // 打印患者ID
  670. nb := result["姓名"].([]byte)
  671. name := string(nb)
  672. //ynamicFields := make([]map[string]interface{})
  673. //var dynamicFields DynamicData
  674. ynamicField := make(map[string]interface{})
  675. ynamicField["姓名"] = name
  676. // 打印其他列的值
  677. for columnName, columnValue := range result {
  678. fmt.Println("000000")
  679. fmt.Println(columnName)
  680. fmt.Println("000000")
  681. // 跳过患者ID列
  682. if columnName == "姓名" {
  683. continue
  684. }
  685. // 检查值是否为nil
  686. if columnValue == nil {
  687. fmt.Printf("Column: %s, Value: <nil>\n", columnName)
  688. continue
  689. }
  690. // 将字节切片转换为字符串
  691. byteValue, ok := columnValue.([]byte)
  692. if !ok {
  693. // 如果无法转换为[]byte,输出错误信息
  694. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  695. continue
  696. }
  697. // 将字节切片转换为字符串
  698. strValue := string(byteValue)
  699. // 尝试将字符串转换为浮点数
  700. floatValue, err := strconv.ParseFloat(strValue, 64)
  701. if err != nil {
  702. // 如果转换失败,输出错误信息
  703. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  704. } else {
  705. // 如果转换成功,输出列名和浮点数值
  706. fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
  707. }
  708. ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
  709. if floatValue == 0 {
  710. ynamicField[columnName] = ""
  711. } else {
  712. ynamicField[columnName] = floatValue
  713. }
  714. fmt.Println(ynamicField)
  715. dynamicFields = append(dynamicFields, ynamicField)
  716. }
  717. }
  718. seen := make(map[interface{}]struct{})
  719. var uniqueFields []map[string]interface{}
  720. for _, field := range dynamicFields {
  721. value := field["姓名"]
  722. // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
  723. if _, ok := seen[value]; !ok {
  724. seen[value] = struct{}{}
  725. uniqueFields = append(uniqueFields, field)
  726. }
  727. }
  728. c.ServeSuccessJSON(map[string]interface{}{
  729. "list": uniqueFields,
  730. })
  731. //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  732. //
  733. //var names []string
  734. //
  735. //for _, item := range list {
  736. // names = append(names, item.ItemName)
  737. //}
  738. //
  739. //names = RemoveRepeatedNameElement(names)
  740. //fmt.Println(names)
  741. //
  742. //var tempList []models.InspectionTen
  743. //list_two := RemoveRepeatedInspectPatientElement(list)
  744. //for _, item := range list_two {
  745. // var temp models.InspectionTen
  746. // var temptwos []models.InspectionValue
  747. // temp.PatientId = item.PatientId
  748. // temp.Name = item.Name
  749. // for _, subitem := range list {
  750. // if item.PatientId == subitem.PatientId {
  751. // var temptwo models.InspectionValue
  752. // temptwo.Name = subitem.ItemName
  753. // temptwo.Value = subitem.InspectValue
  754. // temptwos = append(temptwos, temptwo)
  755. // }
  756. // }
  757. // temp.Values = temptwos
  758. // tempList = append(tempList, temp)
  759. //}
  760. //
  761. //var filtered []string
  762. //for _, item := range names {
  763. // if item != "a" {
  764. // filtered = append(filtered, item)
  765. // }
  766. //}
  767. //
  768. //for _, item := range tempList {
  769. // for _, subitem := range item.Values {
  770. // for _, name := range filtered {
  771. // if subitem.Name != name {
  772. // filtered = append(filtered, name)
  773. // }
  774. // }
  775. // }
  776. //}
  777. //
  778. ////// 将剩余字符串填充到 Inspection 数组中
  779. ////for _, name := range filtered {
  780. //// var temptwo models.InspectionValue
  781. //// temptwo.Name = subitem.ItemName
  782. //// temptwo.Value = subitem.InspectValue
  783. //// temptwos = append(temptwos, temptwo)
  784. ////}
  785. //
  786. //for _, item := range tempList {
  787. // //for _, subitem := range item.Values {
  788. // var temptwo models.InspectionValue
  789. // for _, name := range filtered {
  790. // temptwo.Name = name
  791. // temptwo.Value = ""
  792. // }
  793. // item.Values = append(item.Values, temptwo)
  794. // //}
  795. // fmt.Println(item.Values)
  796. //}
  797. }
  798. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  799. start_date := c.GetString("start_date")
  800. end_date := c.GetString("end_date")
  801. project_id, _ := c.GetInt64("project_id")
  802. item_id, _ := c.GetInt64("item_id")
  803. item_type, _ := c.GetInt64("item_type")
  804. //order_type, _ := c.GetInt64("order_type")
  805. keyword := c.GetString("keyword")
  806. s_type, _ := c.GetInt64("type")
  807. timeLayout := "2006-01-02"
  808. loc, _ := time.LoadLocation("Local")
  809. var startTime int64
  810. if len(start_date) > 0 {
  811. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  812. fmt.Println("err-----------", err)
  813. if err != nil {
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  815. return
  816. }
  817. startTime = theTime.Unix()
  818. }
  819. var endTime int64
  820. if len(end_date) > 0 {
  821. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  822. if err != nil {
  823. utils.ErrorLog(err.Error())
  824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  825. return
  826. }
  827. endTime = theTime.Unix()
  828. }
  829. //获取配置
  830. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  831. //获取数值在正常范围内的总数
  832. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  833. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  834. switch item_type {
  835. case 0:
  836. break
  837. case 1:
  838. if s_type == 2 { //KTV
  839. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  840. c.ServeSuccessJSON(map[string]interface{}{
  841. "list": list,
  842. })
  843. } else if s_type == 3 { //URR
  844. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  845. c.ServeSuccessJSON(map[string]interface{}{
  846. "list": list,
  847. })
  848. } else {
  849. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "list": list,
  852. "reference": reference,
  853. })
  854. }
  855. break
  856. case 2:
  857. if s_type == 2 { //KTV
  858. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  859. c.ServeSuccessJSON(map[string]interface{}{
  860. "list": list,
  861. })
  862. } else if s_type == 3 { //URR
  863. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  864. c.ServeSuccessJSON(map[string]interface{}{
  865. "list": list,
  866. })
  867. } else {
  868. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  869. c.ServeSuccessJSON(map[string]interface{}{
  870. "list": list,
  871. "reference": reference,
  872. })
  873. }
  874. break
  875. case 3:
  876. if s_type == 2 { //KTV
  877. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  878. c.ServeSuccessJSON(map[string]interface{}{
  879. "list": list,
  880. })
  881. } else if s_type == 3 { //URR
  882. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  883. c.ServeSuccessJSON(map[string]interface{}{
  884. "list": list,
  885. })
  886. } else {
  887. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  888. c.ServeSuccessJSON(map[string]interface{}{
  889. "list": list,
  890. "reference": reference,
  891. })
  892. }
  893. break
  894. }
  895. }
  896. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  897. start_date := c.GetString("start_date")
  898. end_date := c.GetString("end_date")
  899. project_id, _ := c.GetInt64("project_id")
  900. item_id, _ := c.GetInt64("item_id")
  901. s_type, _ := c.GetInt64("type")
  902. timeLayout := "2006-01-02"
  903. loc, _ := time.LoadLocation("Local")
  904. var startTime int64
  905. if len(start_date) > 0 {
  906. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  907. fmt.Println("err-----------", err)
  908. if err != nil {
  909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  910. return
  911. }
  912. startTime = theTime.Unix()
  913. }
  914. var endTime int64
  915. if len(end_date) > 0 {
  916. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  917. if err != nil {
  918. utils.ErrorLog(err.Error())
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. endTime = theTime.Unix()
  923. }
  924. //患者总数
  925. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  926. //获取配置
  927. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  928. //获取数值在正常范围内的总数
  929. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  930. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  931. if s_type == 2 {
  932. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  933. //获取数值异常的总数
  934. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  935. //获取没有检查的患者总数
  936. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  937. c.ServeSuccessJSON(map[string]interface{}{
  938. "patient_count": patientCount,
  939. "normal_total": normalTotal,
  940. "unusual_total": unusualTotal,
  941. "no_check_total": noCheckTotal,
  942. })
  943. } else if s_type == 3 {
  944. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  945. //获取数值异常的总数
  946. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  947. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  948. //获取没有检查的患者总数
  949. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  950. c.ServeSuccessJSON(map[string]interface{}{
  951. "patient_count": patientCount,
  952. "normal_total": normalTotal,
  953. "unusual_total": unusualTotal,
  954. "no_check_total": noCheckTotal,
  955. })
  956. } else {
  957. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  958. //获取数值异常的总数
  959. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  960. //获取没有检查的患者总数
  961. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  962. c.ServeSuccessJSON(map[string]interface{}{
  963. "patient_count": patientCount,
  964. "normal_total": normalTotal,
  965. "unusual_total": unusualTotal,
  966. "no_check_total": noCheckTotal,
  967. "reference": reference,
  968. })
  969. }
  970. }
  971. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  972. start_date := c.GetString("start_time")
  973. end_date := c.GetString("end_time")
  974. project_id, _ := c.GetInt64("project_id")
  975. item_id, _ := c.GetInt64("item_id")
  976. patient_id, _ := c.GetInt64("patient_id")
  977. s_type, _ := c.GetInt64("type")
  978. timeLayout := "2006-01-02"
  979. loc, _ := time.LoadLocation("Local")
  980. var startTime int64
  981. if len(start_date) > 0 {
  982. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  983. fmt.Println("err-----------", err)
  984. if err != nil {
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  986. return
  987. }
  988. startTime = theTime.Unix()
  989. }
  990. var endTime int64
  991. if len(end_date) > 0 {
  992. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  993. if err != nil {
  994. utils.ErrorLog(err.Error())
  995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  996. return
  997. }
  998. endTime = theTime.Unix()
  999. }
  1000. if s_type == 2 {
  1001. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1002. //获取配置
  1003. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  1004. //获取数值在正常范围内的总数
  1005. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  1006. c.ServeSuccessJSON(map[string]interface{}{
  1007. "patient": patient,
  1008. "reference": reference,
  1009. "inspections": inspections,
  1010. })
  1011. } else if s_type == 3 {
  1012. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1013. //获取配置
  1014. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  1015. //获取数值在正常范围内的总数
  1016. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  1017. c.ServeSuccessJSON(map[string]interface{}{
  1018. "patient": patient,
  1019. "reference": reference,
  1020. "inspections": inspections,
  1021. })
  1022. } else {
  1023. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1024. //获取配置
  1025. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  1026. //获取数值在正常范围内的总数
  1027. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  1028. c.ServeSuccessJSON(map[string]interface{}{
  1029. "patient": patient,
  1030. "reference": reference,
  1031. "inspections": inspections,
  1032. })
  1033. }
  1034. }
  1035. func (c *StatisticsApiController) GetStatistics() {
  1036. adminUserInfo := c.GetAdminUserInfo()
  1037. // thisTime := time.Now()
  1038. year, month, day := time.Now().Date()
  1039. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1040. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  1041. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  1042. todayWeek := int(todayTime.Weekday())
  1043. if todayWeek == 0 {
  1044. todayWeek = 7
  1045. }
  1046. weekEnd := 7 - todayWeek
  1047. weekStart := weekEnd - 6
  1048. // endDay := todayTime.AddDate(0, 0, weekEnd)
  1049. startDay := todayTime.AddDate(0, 0, weekStart)
  1050. //患者总数
  1051. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  1052. //今日透析
  1053. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  1054. //本周透析
  1055. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  1056. //传染病
  1057. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  1058. //性别分布
  1059. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  1060. //年龄分布
  1061. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  1062. //透析模式
  1063. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  1064. c.ServeSuccessJSON(map[string]interface{}{
  1065. "patient_count": patientCount,
  1066. "today_dialysis_count": todayDialysisCount,
  1067. "week_daylysis_count": weekDaylysisCount,
  1068. "disease_counts": diseaseCounts,
  1069. "gender_counts": genderCounts,
  1070. "age_counts": ageCounts,
  1071. "mode_counts": modeCounts,
  1072. })
  1073. }
  1074. func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
  1075. newArr = make([]models.InspectionTenOne, 0)
  1076. for i := 0; i < len(arr); i++ {
  1077. repeat := false
  1078. for j := i + 1; j < len(arr); j++ {
  1079. if arr[i].PatientId == arr[j].PatientId {
  1080. repeat = true
  1081. break
  1082. }
  1083. }
  1084. if !repeat {
  1085. newArr = append(newArr, arr[i])
  1086. }
  1087. }
  1088. return
  1089. }
  1090. func RemoveRepeatedNameElement(arr []string) (newArr []string) {
  1091. newArr = make([]string, 0)
  1092. for i := 0; i < len(arr); i++ {
  1093. repeat := false
  1094. for j := i + 1; j < len(arr); j++ {
  1095. if arr[i] == arr[j] {
  1096. repeat = true
  1097. break
  1098. }
  1099. }
  1100. if !repeat {
  1101. newArr = append(newArr, arr[i])
  1102. }
  1103. }
  1104. return
  1105. }
  1106. // 根据指定的日期范围拆分成周、月、年
  1107. func splitDateRange(startDate, endDate string) ([]time.Time, error) {
  1108. startTime, err := time.Parse("2006-01-02", startDate)
  1109. if err != nil {
  1110. return nil, err
  1111. }
  1112. endTime, err := time.Parse("2006-01-02", endDate)
  1113. if err != nil {
  1114. return nil, err
  1115. }
  1116. var result []time.Time
  1117. for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
  1118. result = append(result, date)
  1119. }
  1120. return result, nil
  1121. }
  1122. // 按周统计日期
  1123. func groupByWeek(dates []time.Time) [][]time.Time {
  1124. var result [][]time.Time
  1125. var currentWeek []time.Time
  1126. for _, date := range dates {
  1127. currentWeek = append(currentWeek, date)
  1128. if date.Weekday() == time.Sunday {
  1129. result = append(result, currentWeek)
  1130. currentWeek = nil
  1131. }
  1132. }
  1133. if len(currentWeek) > 0 {
  1134. result = append(result, currentWeek)
  1135. }
  1136. return result
  1137. }
  1138. // 按月统计日期
  1139. func groupByMonth(dates []time.Time) [][]time.Time {
  1140. var result [][]time.Time
  1141. var currentMonth []time.Time
  1142. lastMonth := dates[0].Month()
  1143. for _, date := range dates {
  1144. if date.Month() != lastMonth {
  1145. result = append(result, currentMonth)
  1146. currentMonth = nil
  1147. lastMonth = date.Month()
  1148. }
  1149. currentMonth = append(currentMonth, date)
  1150. }
  1151. if len(currentMonth) > 0 {
  1152. result = append(result, currentMonth)
  1153. }
  1154. return result
  1155. }
  1156. // 按年统计日期
  1157. func groupByYear(dates []time.Time) [][]time.Time {
  1158. var result [][]time.Time
  1159. var currentYear []time.Time
  1160. lastYear := dates[0].Year()
  1161. for _, date := range dates {
  1162. if date.Year() != lastYear {
  1163. result = append(result, currentYear)
  1164. currentYear = nil
  1165. lastYear = date.Year()
  1166. }
  1167. currentYear = append(currentYear, date)
  1168. }
  1169. if len(currentYear) > 0 {
  1170. result = append(result, currentYear)
  1171. }
  1172. return result
  1173. }
  1174. // 将日期拆分为按天统计
  1175. func splitByDay(startDate, endDate time.Time) []time.Time {
  1176. var dates []time.Time
  1177. for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
  1178. dates = append(dates, d)
  1179. }
  1180. return dates
  1181. }