statistics_api_controller.go 73KB

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