statistics_api_controller.go 61KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  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/detailsinfo", &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. date_str := c.GetString("data")
  915. mode, _ := c.GetInt64("mode")
  916. origin, _ := c.GetInt64("origin")
  917. page, _ := c.GetInt64("page")
  918. limit, _ := c.GetInt64("limit")
  919. start_date := strings.Split(date_str, "~")[0]
  920. end_date := strings.Split(date_str, "~")[1]
  921. if origin == 1 {
  922. qcp, total, _ := service.GetDialysisPrescriptionInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  923. c.ServeSuccessJSON(map[string]interface{}{
  924. "list": qcp,
  925. "total": total,
  926. })
  927. } else {
  928. qcp, total, _ := service.GetScheduleInfo(start_date, end_date, mode, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  929. c.ServeSuccessJSON(map[string]interface{}{
  930. "list": qcp,
  931. "total": total,
  932. })
  933. }
  934. }
  935. func (c *StatisticsApiController) GetAnticoagulant() {
  936. start_date := c.GetString("start_date")
  937. end_date := c.GetString("end_date")
  938. timeLayout := "2006-01-02"
  939. loc, _ := time.LoadLocation("Local")
  940. var startTime int64
  941. if len(start_date) > 0 {
  942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  943. fmt.Println("err-----------", err)
  944. if err != nil {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  946. return
  947. }
  948. startTime = theTime.Unix()
  949. }
  950. var endTime int64
  951. if len(end_date) > 0 {
  952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  953. if err != nil {
  954. utils.ErrorLog(err.Error())
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. endTime = theTime.Unix()
  959. }
  960. total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  961. if err2 != nil {
  962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  963. return
  964. }
  965. anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  966. if err != nil {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  968. return
  969. }
  970. type respData struct {
  971. Name string `json:"name"`
  972. Count int `json:"count"`
  973. Percentage float64 `json:"percentage"`
  974. }
  975. var respDatas []respData
  976. for anticoagulant, count := range anticoagulantData {
  977. var respData respData
  978. respData.Name = anticoagulant
  979. respData.Count = count
  980. respData.Percentage = float64(count) / float64(total) * 100
  981. respDatas = append(respDatas, respData)
  982. }
  983. c.ServeSuccessJSON(map[string]interface{}{
  984. "data": respDatas,
  985. })
  986. }
  987. func (c *StatisticsApiController) GetAnticoagulantDetail() {
  988. anticoagulant, _ := c.GetInt64("anticoagulant")
  989. start_date := c.GetString("start_date")
  990. end_date := c.GetString("end_date")
  991. timeLayout := "2006-01-02"
  992. page, _ := c.GetInt64("page", 0)
  993. limit, _ := c.GetInt64("limit", 0)
  994. if page <= 0 {
  995. page = 1
  996. }
  997. if limit <= 0 {
  998. limit = 10
  999. }
  1000. loc, _ := time.LoadLocation("Local")
  1001. var startTime int64
  1002. if len(start_date) > 0 {
  1003. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1004. fmt.Println("err-----------", err)
  1005. if err != nil {
  1006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1007. return
  1008. }
  1009. startTime = theTime.Unix()
  1010. }
  1011. var endTime int64
  1012. if len(end_date) > 0 {
  1013. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1014. if err != nil {
  1015. utils.ErrorLog(err.Error())
  1016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1017. return
  1018. }
  1019. endTime = theTime.Unix()
  1020. }
  1021. prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
  1022. c.ServeSuccessJSON(map[string]interface{}{
  1023. "prescriptions": prescriptions,
  1024. "total": total,
  1025. })
  1026. }
  1027. func (c *StatisticsApiController) GetDialyzer() {
  1028. start_date := c.GetString("start_date")
  1029. end_date := c.GetString("end_date")
  1030. timeLayout := "2006-01-02"
  1031. loc, _ := time.LoadLocation("Local")
  1032. var startTime int64
  1033. if len(start_date) > 0 {
  1034. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1035. fmt.Println("err-----------", err)
  1036. if err != nil {
  1037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1038. return
  1039. }
  1040. startTime = theTime.Unix()
  1041. }
  1042. var endTime int64
  1043. if len(end_date) > 0 {
  1044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1045. if err != nil {
  1046. utils.ErrorLog(err.Error())
  1047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1048. return
  1049. }
  1050. endTime = theTime.Unix()
  1051. }
  1052. total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1053. if err2 != nil {
  1054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1055. return
  1056. }
  1057. dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  1058. if err != nil {
  1059. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1060. return
  1061. }
  1062. type respData struct {
  1063. Name string `json:"name"`
  1064. Count int `json:"count"`
  1065. Percentage float64 `json:"percentage"`
  1066. }
  1067. var respDatas []respData
  1068. for _, item := range dialyzers {
  1069. var respData respData
  1070. respData.Name = item.Dialyzer
  1071. respData.Count = item.Count
  1072. respData.Percentage = float64(item.Count) / float64(total) * 100
  1073. respDatas = append(respDatas, respData)
  1074. }
  1075. c.ServeSuccessJSON(map[string]interface{}{
  1076. "data": respDatas,
  1077. })
  1078. }
  1079. func (c *StatisticsApiController) GetDialyzerDetail() {
  1080. dialyzer := c.GetString("dialyzer")
  1081. start_date := c.GetString("start_date")
  1082. end_date := c.GetString("end_date")
  1083. timeLayout := "2006-01-02"
  1084. page, _ := c.GetInt64("page", 0)
  1085. limit, _ := c.GetInt64("limit", 0)
  1086. if page <= 0 {
  1087. page = 1
  1088. }
  1089. if limit <= 0 {
  1090. limit = 10
  1091. }
  1092. loc, _ := time.LoadLocation("Local")
  1093. var startTime int64
  1094. if len(start_date) > 0 {
  1095. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1096. fmt.Println("err-----------", err)
  1097. if err != nil {
  1098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1099. return
  1100. }
  1101. startTime = theTime.Unix()
  1102. }
  1103. var endTime int64
  1104. if len(end_date) > 0 {
  1105. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1106. if err != nil {
  1107. utils.ErrorLog(err.Error())
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1109. return
  1110. }
  1111. endTime = theTime.Unix()
  1112. }
  1113. prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
  1114. c.ServeSuccessJSON(map[string]interface{}{
  1115. "prescriptions": prescriptions,
  1116. "total": total,
  1117. })
  1118. }
  1119. func (c *StatisticsApiController) GetDialyzerConfig() {
  1120. dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
  1121. //Irrigation, _ := service.GetIrrigationSummary(c.GetAdminUserInfo().CurrentOrgId)
  1122. //dialyzers = append(dialyzers, Irrigation...)
  1123. c.ServeSuccessJSON(map[string]interface{}{
  1124. "dialyzers": dialyzers,
  1125. })
  1126. }
  1127. // 配置检验数据查询
  1128. func (this *StatisticsApiController) GetInsepctionList() {
  1129. adminUser := this.GetAdminUserInfo()
  1130. orgid := adminUser.CurrentOrgId
  1131. configurationlist, err := service.GetInsepctionConfigurationList(orgid)
  1132. if err != nil {
  1133. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1134. return
  1135. }
  1136. this.ServeSuccessJSON(map[string]interface{}{
  1137. "configurationlist": configurationlist,
  1138. })
  1139. }
  1140. func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
  1141. start_date := c.GetString("start_date")
  1142. end_date := c.GetString("end_date")
  1143. project_id, _ := c.GetInt64("project_id")
  1144. item_id, _ := c.GetInt64("item_id")
  1145. timeLayout := "2006-01-02"
  1146. loc, _ := time.LoadLocation("Local")
  1147. var startTime int64
  1148. if len(start_date) > 0 {
  1149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1150. fmt.Println("err-----------", err)
  1151. if err != nil {
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1153. return
  1154. }
  1155. startTime = theTime.Unix()
  1156. }
  1157. var endTime int64
  1158. if len(end_date) > 0 {
  1159. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1160. if err != nil {
  1161. utils.ErrorLog(err.Error())
  1162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1163. return
  1164. }
  1165. endTime = theTime.Unix()
  1166. }
  1167. //患者总数
  1168. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  1169. //获取配置
  1170. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1171. //获取数值在正常范围内的总数
  1172. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1173. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  1174. min, _ := strconv.ParseFloat(config.MinRange, 64)
  1175. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1176. //获取数值异常的总数
  1177. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1178. //获取没有检查的患者总数
  1179. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  1180. c.ServeSuccessJSON(map[string]interface{}{
  1181. "patient_count": patientCount,
  1182. "normal_total": normalTotal,
  1183. "unusual_total": unusualTotal,
  1184. "no_check_total": noCheckTotal,
  1185. "reference": reference,
  1186. "config": config,
  1187. })
  1188. }
  1189. func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
  1190. start_date := c.GetString("start_date")
  1191. end_date := c.GetString("end_date")
  1192. project_id, _ := c.GetInt64("project_id")
  1193. item_id, _ := c.GetInt64("item_id")
  1194. patient_id, _ := c.GetInt64("patient_id")
  1195. timeLayout := "2006-01-02"
  1196. loc, _ := time.LoadLocation("Local")
  1197. var startTime int64
  1198. if len(start_date) > 0 {
  1199. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1200. fmt.Println("err-----------", err)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. startTime = theTime.Unix()
  1206. }
  1207. var endTime int64
  1208. if len(end_date) > 0 {
  1209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1210. if err != nil {
  1211. utils.ErrorLog(err.Error())
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1213. return
  1214. }
  1215. endTime = theTime.Unix()
  1216. }
  1217. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1218. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1219. //获取配置
  1220. reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
  1221. //获取数值在正常范围内的总数
  1222. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "patient": patient,
  1225. "reference": reference,
  1226. "inspections": inspections,
  1227. })
  1228. }
  1229. func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
  1230. start_date := c.GetString("start_date")
  1231. end_date := c.GetString("end_date")
  1232. project_id, _ := c.GetInt64("project_id")
  1233. item_id, _ := c.GetInt64("item_id")
  1234. item_type, _ := c.GetInt64("item_type")
  1235. keyword := c.GetString("keyword")
  1236. timeLayout := "2006-01-02"
  1237. loc, _ := time.LoadLocation("Local")
  1238. var startTime int64
  1239. if len(start_date) > 0 {
  1240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1241. fmt.Println("err-----------", err)
  1242. if err != nil {
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1244. return
  1245. }
  1246. startTime = theTime.Unix()
  1247. }
  1248. var endTime int64
  1249. if len(end_date) > 0 {
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1251. if err != nil {
  1252. utils.ErrorLog(err.Error())
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. endTime = theTime.Unix()
  1257. }
  1258. //获取配置
  1259. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1260. //获取数值在正常范围内的总数
  1261. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1262. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  1263. min, _ := strconv.ParseFloat(config.MinRange, 64)
  1264. //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  1265. //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  1266. //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  1267. switch item_type {
  1268. case 1:
  1269. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1270. c.ServeSuccessJSON(map[string]interface{}{
  1271. "list": list,
  1272. "reference": reference,
  1273. })
  1274. break
  1275. case 2:
  1276. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  1277. c.ServeSuccessJSON(map[string]interface{}{
  1278. "list": list,
  1279. "reference": reference,
  1280. })
  1281. break
  1282. case 3:
  1283. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1284. c.ServeSuccessJSON(map[string]interface{}{
  1285. "list": list,
  1286. "reference": reference,
  1287. })
  1288. break
  1289. }
  1290. }
  1291. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  1292. //start_date := c.GetString("start_date")
  1293. end_date := c.GetString("end_date")
  1294. //keyword := c.GetString("keyword")
  1295. //timeLayout := "2006-01-02"
  1296. //loc, _ := time.LoadLocation("Local")
  1297. dynamicFields := make([]map[string]interface{}, 0)
  1298. list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
  1299. //fmt.Println(list)
  1300. for _, result := range list {
  1301. //fmt.Println(result)
  1302. // 打印患者ID
  1303. nb := result["姓名"].([]byte)
  1304. name := string(nb)
  1305. //ynamicFields := make([]map[string]interface{})
  1306. //var dynamicFields DynamicData
  1307. ynamicField := make(map[string]interface{})
  1308. ynamicField["姓名"] = name
  1309. // 打印其他列的值
  1310. for columnName, columnValue := range result {
  1311. fmt.Println("000000")
  1312. fmt.Println(columnName)
  1313. fmt.Println("000000")
  1314. // 跳过患者ID列
  1315. if columnName == "姓名" {
  1316. continue
  1317. }
  1318. // 检查值是否为nil
  1319. if columnValue == nil {
  1320. fmt.Printf("Column: %s, Value: <nil>\n", columnName)
  1321. continue
  1322. }
  1323. // 将字节切片转换为字符串
  1324. byteValue, ok := columnValue.([]byte)
  1325. if !ok {
  1326. // 如果无法转换为[]byte,输出错误信息
  1327. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  1328. continue
  1329. }
  1330. // 将字节切片转换为字符串
  1331. strValue := string(byteValue)
  1332. // 尝试将字符串转换为浮点数
  1333. floatValue, err := strconv.ParseFloat(strValue, 64)
  1334. if err != nil {
  1335. // 如果转换失败,输出错误信息
  1336. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  1337. } else {
  1338. // 如果转换成功,输出列名和浮点数值
  1339. fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
  1340. }
  1341. ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
  1342. if floatValue == 0 {
  1343. ynamicField[columnName] = ""
  1344. } else {
  1345. ynamicField[columnName] = floatValue
  1346. }
  1347. fmt.Println(ynamicField)
  1348. dynamicFields = append(dynamicFields, ynamicField)
  1349. }
  1350. }
  1351. seen := make(map[interface{}]struct{})
  1352. var uniqueFields []map[string]interface{}
  1353. for _, field := range dynamicFields {
  1354. value := field["姓名"]
  1355. // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
  1356. if _, ok := seen[value]; !ok {
  1357. seen[value] = struct{}{}
  1358. uniqueFields = append(uniqueFields, field)
  1359. }
  1360. }
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "list": uniqueFields,
  1363. })
  1364. //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  1365. //
  1366. //var names []string
  1367. //
  1368. //for _, item := range list {
  1369. // names = append(names, item.ItemName)
  1370. //}
  1371. //
  1372. //names = RemoveRepeatedNameElement(names)
  1373. //fmt.Println(names)
  1374. //
  1375. //var tempList []models.InspectionTen
  1376. //list_two := RemoveRepeatedInspectPatientElement(list)
  1377. //for _, item := range list_two {
  1378. // var temp models.InspectionTen
  1379. // var temptwos []models.InspectionValue
  1380. // temp.PatientId = item.PatientId
  1381. // temp.Name = item.Name
  1382. // for _, subitem := range list {
  1383. // if item.PatientId == subitem.PatientId {
  1384. // var temptwo models.InspectionValue
  1385. // temptwo.Name = subitem.ItemName
  1386. // temptwo.Value = subitem.InspectValue
  1387. // temptwos = append(temptwos, temptwo)
  1388. // }
  1389. // }
  1390. // temp.Values = temptwos
  1391. // tempList = append(tempList, temp)
  1392. //}
  1393. //
  1394. //var filtered []string
  1395. //for _, item := range names {
  1396. // if item != "a" {
  1397. // filtered = append(filtered, item)
  1398. // }
  1399. //}
  1400. //
  1401. //for _, item := range tempList {
  1402. // for _, subitem := range item.Values {
  1403. // for _, name := range filtered {
  1404. // if subitem.Name != name {
  1405. // filtered = append(filtered, name)
  1406. // }
  1407. // }
  1408. // }
  1409. //}
  1410. //
  1411. ////// 将剩余字符串填充到 Inspection 数组中
  1412. ////for _, name := range filtered {
  1413. //// var temptwo models.InspectionValue
  1414. //// temptwo.Name = subitem.ItemName
  1415. //// temptwo.Value = subitem.InspectValue
  1416. //// temptwos = append(temptwos, temptwo)
  1417. ////}
  1418. //
  1419. //for _, item := range tempList {
  1420. // //for _, subitem := range item.Values {
  1421. // var temptwo models.InspectionValue
  1422. // for _, name := range filtered {
  1423. // temptwo.Name = name
  1424. // temptwo.Value = ""
  1425. // }
  1426. // item.Values = append(item.Values, temptwo)
  1427. // //}
  1428. // fmt.Println(item.Values)
  1429. //}
  1430. }
  1431. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  1432. start_date := c.GetString("start_date")
  1433. end_date := c.GetString("end_date")
  1434. project_id, _ := c.GetInt64("project_id")
  1435. item_id, _ := c.GetInt64("item_id")
  1436. item_type, _ := c.GetInt64("item_type")
  1437. //order_type, _ := c.GetInt64("order_type")
  1438. keyword := c.GetString("keyword")
  1439. s_type, _ := c.GetInt64("type")
  1440. timeLayout := "2006-01-02"
  1441. loc, _ := time.LoadLocation("Local")
  1442. var startTime int64
  1443. if len(start_date) > 0 {
  1444. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1445. fmt.Println("err-----------", err)
  1446. if err != nil {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. startTime = theTime.Unix()
  1451. }
  1452. var endTime int64
  1453. if len(end_date) > 0 {
  1454. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1455. if err != nil {
  1456. utils.ErrorLog(err.Error())
  1457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1458. return
  1459. }
  1460. endTime = theTime.Unix()
  1461. }
  1462. //获取配置
  1463. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  1464. //获取数值在正常范围内的总数
  1465. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  1466. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  1467. switch item_type {
  1468. case 0:
  1469. break
  1470. case 1:
  1471. if s_type == 2 { //KTV
  1472. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "list": list,
  1475. })
  1476. } else if s_type == 3 { //URR
  1477. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  1478. c.ServeSuccessJSON(map[string]interface{}{
  1479. "list": list,
  1480. })
  1481. } else {
  1482. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1483. c.ServeSuccessJSON(map[string]interface{}{
  1484. "list": list,
  1485. "reference": reference,
  1486. })
  1487. }
  1488. break
  1489. case 2:
  1490. if s_type == 2 { //KTV
  1491. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  1492. c.ServeSuccessJSON(map[string]interface{}{
  1493. "list": list,
  1494. })
  1495. } else if s_type == 3 { //URR
  1496. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  1497. c.ServeSuccessJSON(map[string]interface{}{
  1498. "list": list,
  1499. })
  1500. } else {
  1501. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "list": list,
  1504. "reference": reference,
  1505. })
  1506. }
  1507. break
  1508. case 3:
  1509. if s_type == 2 { //KTV
  1510. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  1511. c.ServeSuccessJSON(map[string]interface{}{
  1512. "list": list,
  1513. })
  1514. } else if s_type == 3 { //URR
  1515. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  1516. c.ServeSuccessJSON(map[string]interface{}{
  1517. "list": list,
  1518. })
  1519. } else {
  1520. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "list": list,
  1523. "reference": reference,
  1524. })
  1525. }
  1526. break
  1527. }
  1528. }
  1529. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  1530. start_date := c.GetString("start_date")
  1531. end_date := c.GetString("end_date")
  1532. project_id, _ := c.GetInt64("project_id")
  1533. item_id, _ := c.GetInt64("item_id")
  1534. s_type, _ := c.GetInt64("type")
  1535. timeLayout := "2006-01-02"
  1536. loc, _ := time.LoadLocation("Local")
  1537. var startTime int64
  1538. if len(start_date) > 0 {
  1539. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1540. fmt.Println("err-----------", err)
  1541. if err != nil {
  1542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1543. return
  1544. }
  1545. startTime = theTime.Unix()
  1546. }
  1547. var endTime int64
  1548. if len(end_date) > 0 {
  1549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1550. if err != nil {
  1551. utils.ErrorLog(err.Error())
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1553. return
  1554. }
  1555. endTime = theTime.Unix()
  1556. }
  1557. //患者总数
  1558. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  1559. //获取配置
  1560. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  1561. //获取数值在正常范围内的总数
  1562. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  1563. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  1564. if s_type == 2 {
  1565. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  1566. //获取数值异常的总数
  1567. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  1568. //获取没有检查的患者总数
  1569. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  1570. c.ServeSuccessJSON(map[string]interface{}{
  1571. "patient_count": patientCount,
  1572. "normal_total": normalTotal,
  1573. "unusual_total": unusualTotal,
  1574. "no_check_total": noCheckTotal,
  1575. })
  1576. } else if s_type == 3 {
  1577. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  1578. //获取数值异常的总数
  1579. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  1580. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  1581. //获取没有检查的患者总数
  1582. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  1583. c.ServeSuccessJSON(map[string]interface{}{
  1584. "patient_count": patientCount,
  1585. "normal_total": normalTotal,
  1586. "unusual_total": unusualTotal,
  1587. "no_check_total": noCheckTotal,
  1588. })
  1589. } else {
  1590. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1591. //获取数值异常的总数
  1592. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  1593. //获取没有检查的患者总数
  1594. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  1595. c.ServeSuccessJSON(map[string]interface{}{
  1596. "patient_count": patientCount,
  1597. "normal_total": normalTotal,
  1598. "unusual_total": unusualTotal,
  1599. "no_check_total": noCheckTotal,
  1600. "reference": reference,
  1601. })
  1602. }
  1603. }
  1604. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  1605. start_date := c.GetString("start_time")
  1606. end_date := c.GetString("end_time")
  1607. project_id, _ := c.GetInt64("project_id")
  1608. item_id, _ := c.GetInt64("item_id")
  1609. patient_id, _ := c.GetInt64("patient_id")
  1610. s_type, _ := c.GetInt64("type")
  1611. timeLayout := "2006-01-02"
  1612. loc, _ := time.LoadLocation("Local")
  1613. var startTime int64
  1614. if len(start_date) > 0 {
  1615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  1616. fmt.Println("err-----------", err)
  1617. if err != nil {
  1618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1619. return
  1620. }
  1621. startTime = theTime.Unix()
  1622. }
  1623. var endTime int64
  1624. if len(end_date) > 0 {
  1625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  1626. if err != nil {
  1627. utils.ErrorLog(err.Error())
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1629. return
  1630. }
  1631. endTime = theTime.Unix()
  1632. }
  1633. if s_type == 2 {
  1634. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1635. //获取配置
  1636. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  1637. //获取数值在正常范围内的总数
  1638. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  1639. c.ServeSuccessJSON(map[string]interface{}{
  1640. "patient": patient,
  1641. "reference": reference,
  1642. "inspections": inspections,
  1643. })
  1644. } else if s_type == 3 {
  1645. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1646. //获取配置
  1647. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  1648. //获取数值在正常范围内的总数
  1649. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  1650. c.ServeSuccessJSON(map[string]interface{}{
  1651. "patient": patient,
  1652. "reference": reference,
  1653. "inspections": inspections,
  1654. })
  1655. } else {
  1656. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  1657. //获取配置
  1658. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  1659. //获取数值在正常范围内的总数
  1660. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  1661. c.ServeSuccessJSON(map[string]interface{}{
  1662. "patient": patient,
  1663. "reference": reference,
  1664. "inspections": inspections,
  1665. })
  1666. }
  1667. }
  1668. func (c *StatisticsApiController) GetStatistics() {
  1669. adminUserInfo := c.GetAdminUserInfo()
  1670. // thisTime := time.Now()
  1671. year, month, day := time.Now().Date()
  1672. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1673. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  1674. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  1675. todayWeek := int(todayTime.Weekday())
  1676. if todayWeek == 0 {
  1677. todayWeek = 7
  1678. }
  1679. weekEnd := 7 - todayWeek
  1680. weekStart := weekEnd - 6
  1681. // endDay := todayTime.AddDate(0, 0, weekEnd)
  1682. startDay := todayTime.AddDate(0, 0, weekStart)
  1683. //患者总数
  1684. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  1685. //今日透析
  1686. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  1687. //本周透析
  1688. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  1689. //传染病
  1690. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  1691. //性别分布
  1692. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  1693. //年龄分布
  1694. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  1695. //透析模式
  1696. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  1697. c.ServeSuccessJSON(map[string]interface{}{
  1698. "patient_count": patientCount,
  1699. "today_dialysis_count": todayDialysisCount,
  1700. "week_daylysis_count": weekDaylysisCount,
  1701. "disease_counts": diseaseCounts,
  1702. "gender_counts": genderCounts,
  1703. "age_counts": ageCounts,
  1704. "mode_counts": modeCounts,
  1705. })
  1706. }
  1707. func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
  1708. newArr = make([]models.InspectionTenOne, 0)
  1709. for i := 0; i < len(arr); i++ {
  1710. repeat := false
  1711. for j := i + 1; j < len(arr); j++ {
  1712. if arr[i].PatientId == arr[j].PatientId {
  1713. repeat = true
  1714. break
  1715. }
  1716. }
  1717. if !repeat {
  1718. newArr = append(newArr, arr[i])
  1719. }
  1720. }
  1721. return
  1722. }
  1723. func RemoveRepeatedNameElement(arr []string) (newArr []string) {
  1724. newArr = make([]string, 0)
  1725. for i := 0; i < len(arr); i++ {
  1726. repeat := false
  1727. for j := i + 1; j < len(arr); j++ {
  1728. if arr[i] == arr[j] {
  1729. repeat = true
  1730. break
  1731. }
  1732. }
  1733. if !repeat {
  1734. newArr = append(newArr, arr[i])
  1735. }
  1736. }
  1737. return
  1738. }
  1739. // 根据指定的日期范围拆分成周、月、年
  1740. func splitDateRange(startDate, endDate string) ([]time.Time, error) {
  1741. startTime, err := time.Parse("2006-01-02", startDate)
  1742. if err != nil {
  1743. return nil, err
  1744. }
  1745. endTime, err := time.Parse("2006-01-02", endDate)
  1746. if err != nil {
  1747. return nil, err
  1748. }
  1749. var result []time.Time
  1750. for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
  1751. result = append(result, date)
  1752. }
  1753. return result, nil
  1754. }
  1755. // 按周统计日期
  1756. func groupByWeek(dates []time.Time) [][]time.Time {
  1757. var result [][]time.Time
  1758. var currentWeek []time.Time
  1759. for _, date := range dates {
  1760. currentWeek = append(currentWeek, date)
  1761. if date.Weekday() == time.Sunday {
  1762. result = append(result, currentWeek)
  1763. currentWeek = nil
  1764. }
  1765. }
  1766. if len(currentWeek) > 0 {
  1767. result = append(result, currentWeek)
  1768. }
  1769. return result
  1770. }
  1771. // 按月统计日期
  1772. func groupByMonth(dates []time.Time) [][]time.Time {
  1773. var result [][]time.Time
  1774. var currentMonth []time.Time
  1775. lastMonth := dates[0].Month()
  1776. for _, date := range dates {
  1777. if date.Month() != lastMonth {
  1778. result = append(result, currentMonth)
  1779. currentMonth = nil
  1780. lastMonth = date.Month()
  1781. }
  1782. currentMonth = append(currentMonth, date)
  1783. }
  1784. if len(currentMonth) > 0 {
  1785. result = append(result, currentMonth)
  1786. }
  1787. return result
  1788. }
  1789. // 按年统计日期
  1790. func groupByYear(dates []time.Time) [][]time.Time {
  1791. var result [][]time.Time
  1792. var currentYear []time.Time
  1793. lastYear := dates[0].Year()
  1794. for _, date := range dates {
  1795. if date.Year() != lastYear {
  1796. result = append(result, currentYear)
  1797. currentYear = nil
  1798. lastYear = date.Year()
  1799. }
  1800. currentYear = append(currentYear, date)
  1801. }
  1802. if len(currentYear) > 0 {
  1803. result = append(result, currentYear)
  1804. }
  1805. return result
  1806. }
  1807. // 将日期拆分为按天统计
  1808. func splitByDay(startDate, endDate time.Time) []time.Time {
  1809. var dates []time.Time
  1810. for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
  1811. dates = append(dates, d)
  1812. }
  1813. return dates
  1814. }