statistics_api_controller.go 77KB

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