statistics_api_controller.go 67KB

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