statistics_api_controller.go 40KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type StatisticsApiController struct {
  14. BaseAuthAPIController
  15. }
  16. func StatisticsApiRegistRouters() {
  17. beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics")
  18. beego.Router("/api/qc/statistiscall/get", &StatisticsApiController{}, "get:GetAllInspectionStatistisc")
  19. beego.Router("/api/qc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonInspectionStatistisc")
  20. beego.Router("/api/qc/statistiscperson/list", &StatisticsApiController{}, "get:GetInsepctionList")
  21. beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
  22. beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
  23. beego.Router("/api/commonqc/statistiscall/get", &StatisticsApiController{}, "get:GetAllCommonInspectionStatistisc")
  24. beego.Router("/api/commonqc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonCommonInspectionStatistisc")
  25. beego.Router("/api/commonqc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientCommonInspectionStatistisc")
  26. //透析总量统计
  27. beego.Router("/api/commonqc/dialysis/total", &StatisticsApiController{}, "get:GetDialysisTotal")
  28. beego.Router("/api/commonqc/dialysis/detail", &StatisticsApiController{}, "get:GetDialysisTotalDetail")
  29. beego.Router("/api/commonqc/dialysis/details", &StatisticsApiController{}, "get:GetDialysisTotalDetailInfo")
  30. beego.Router("/api/commonqc/anticoagulant", &StatisticsApiController{}, "get:GetAnticoagulant")
  31. beego.Router("/api/commonqc/anticoagulant/detail", &StatisticsApiController{}, "get:GetAnticoagulantDetail")
  32. beego.Router("/api/commonqc/dialyzer", &StatisticsApiController{}, "get:GetDialyzer")
  33. beego.Router("/api/commonqc/dialyzer/config", &StatisticsApiController{}, "get:GetDialyzerConfig")
  34. beego.Router("/api/commonqc/dialyzer/detail", &StatisticsApiController{}, "get:GetDialyzerDetail")
  35. beego.Router("/api/commonqc/dialysistreat/finish", &StatisticsApiController{}, "get:GetDialysisTreatFinsh")
  36. beego.Router("/api/commonqc/dialysistreat/detail", &StatisticsApiController{}, "get:GetDialysisTreatDetail")
  37. }
  38. func (c *StatisticsApiController) GetDialysisTreatFinsh() {
  39. start_date := c.GetString("start_date")
  40. end_date := c.GetString("end_date")
  41. timeLayout := "2006-01-02"
  42. loc, _ := time.LoadLocation("Local")
  43. var startTime int64
  44. if len(start_date) > 0 {
  45. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  46. fmt.Println("err-----------", err)
  47. if err != nil {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. startTime = theTime.Unix()
  52. }
  53. var endTime int64
  54. if len(end_date) > 0 {
  55. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  56. if err != nil {
  57. utils.ErrorLog(err.Error())
  58. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  59. return
  60. }
  61. endTime = theTime.Unix()
  62. }
  63. data, _ := service.GetDialysisCompletionRate(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
  64. total, _ := service.GetDialysisCompletionTotal(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
  65. c.ServeSuccessJSON(map[string]interface{}{
  66. "data": data,
  67. "total": total,
  68. })
  69. }
  70. func (c *StatisticsApiController) GetDialysisTreatDetail() {
  71. start_date := c.GetString("start_date")
  72. end_date := c.GetString("end_date")
  73. mode, _ := c.GetInt64("mode")
  74. page, _ := c.GetInt64("page", 0)
  75. limit, _ := c.GetInt64("limit", 0)
  76. if page <= 0 {
  77. page = 1
  78. }
  79. if limit <= 0 {
  80. limit = 10
  81. }
  82. timeLayout := "2006-01-02"
  83. loc, _ := time.LoadLocation("Local")
  84. var startTime int64
  85. if len(start_date) > 0 {
  86. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  87. fmt.Println("err-----------", err)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  90. return
  91. }
  92. startTime = theTime.Unix()
  93. }
  94. var endTime int64
  95. if len(end_date) > 0 {
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  97. if err != nil {
  98. utils.ErrorLog(err.Error())
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. endTime = theTime.Unix()
  103. }
  104. data, total, _ := service.GetDialysisCompletionDetail(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, mode, limit, page)
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "list": data,
  107. "total": total,
  108. })
  109. }
  110. func (c *StatisticsApiController) GetDialysisTotal() {
  111. start_date := c.GetString("start_date")
  112. end_date := c.GetString("end_date")
  113. mode, _ := c.GetInt64("mode")
  114. origin, _ := c.GetInt64("origin")
  115. time_way, _ := c.GetInt64("time_way")
  116. timeLayout := "2006-01-02"
  117. loc, _ := time.LoadLocation("Local")
  118. var startTime int64
  119. if len(start_date) > 0 {
  120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  121. fmt.Println("err-----------", err)
  122. if err != nil {
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  124. return
  125. }
  126. startTime = theTime.Unix()
  127. }
  128. var endTime int64
  129. if len(end_date) > 0 {
  130. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  131. if err != nil {
  132. utils.ErrorLog(err.Error())
  133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  134. return
  135. }
  136. endTime = theTime.Unix()
  137. }
  138. if mode == 0 { //统计透析模式不限
  139. //获取总人数
  140. p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
  141. count_struct, _ := service.GetNewDialysisCountMode(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin, 0)
  142. c.ServeSuccessJSON(map[string]interface{}{
  143. "patient_count": p_total,
  144. "list": count_struct,
  145. })
  146. } else { //固定某个模式
  147. // 拆分日期范围
  148. dates, err := splitDateRange(start_date, end_date)
  149. if err != nil {
  150. fmt.Println("Error:", err)
  151. return
  152. }
  153. var cuss []models.CustomDialysisData
  154. p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
  155. switch time_way {
  156. case 1:
  157. // 按周统计
  158. weeks := groupByWeek(dates)
  159. for _, week := range weeks {
  160. var cus models.CustomDialysisData
  161. counts, _ := service.GetNewDialysisCountModeTwo(week[0].Unix(), week[len(week)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  162. cus.Date = strings.Split(week[0].String(), " ")[0] + "~" + strings.Split(week[len(week)-1].String(), " ")[0]
  163. cus.Count = counts.Count
  164. cus.Total = p_total
  165. cuss = append(cuss, cus)
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "list": cuss,
  168. })
  169. }
  170. break
  171. case 2:
  172. startDate, err := time.Parse("2006-01-02", start_date)
  173. if err != nil {
  174. fmt.Println("Error parsing start date:", err)
  175. return
  176. }
  177. endDate, err := time.Parse("2006-01-02", end_date)
  178. if err != nil {
  179. fmt.Println("Error parsing end date:", err)
  180. return
  181. }
  182. dailyDates := splitByDay(startDate, endDate)
  183. for _, date := range dailyDates {
  184. //fmt.Println(date)
  185. var cus models.CustomDialysisData
  186. counts, _ := service.GetNewDialysisCountModeTwo(date.Unix(), date.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  187. cus.Date = date.Format("2006-01-02")
  188. cus.Count = counts.Count
  189. cus.Total = p_total
  190. cuss = append(cuss, cus)
  191. c.ServeSuccessJSON(map[string]interface{}{
  192. "list": cuss,
  193. })
  194. }
  195. break
  196. case 3:
  197. // 按月统计
  198. months := groupByMonth(dates)
  199. for _, month := range months {
  200. var cus models.CustomDialysisData
  201. counts, _ := service.GetNewDialysisCountModeTwo(month[0].Unix(), month[len(month)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  202. cus.Date = strings.Split(month[0].String(), " ")[0] + "~" + strings.Split(month[len(month)-1].String(), " ")[0]
  203. cus.Count = counts.Count
  204. cus.Total = p_total
  205. cuss = append(cuss, cus)
  206. c.ServeSuccessJSON(map[string]interface{}{
  207. "list": cuss,
  208. })
  209. //fmt.Println("Month:", month[0], "~", month[len(month)-1])
  210. }
  211. break
  212. case 4:
  213. // 按年统计
  214. years := groupByYear(dates)
  215. for _, year := range years {
  216. var cus models.CustomDialysisData
  217. counts, _ := service.GetNewDialysisCountModeTwo(year[0].Unix(), year[len(year)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
  218. cus.Date = strings.Split(year[0].String(), " ")[0] + "~" + strings.Split(year[len(year)-1].String(), " ")[0]
  219. cus.Count = counts.Count
  220. cus.Total = p_total
  221. cuss = append(cuss, cus)
  222. c.ServeSuccessJSON(map[string]interface{}{
  223. "list": cuss,
  224. })
  225. }
  226. break
  227. }
  228. }
  229. }
  230. func (c *StatisticsApiController) GetDialysisTotalDetail() {
  231. start_date := c.GetString("start_date")
  232. end_date := c.GetString("end_date")
  233. mode, _ := c.GetInt64("mode")
  234. origin, _ := c.GetInt64("origin")
  235. time_way, _ := c.GetInt64("time_way")
  236. timeLayout := "2006-01-02"
  237. loc, _ := time.LoadLocation("Local")
  238. var startTime int64
  239. if len(start_date) > 0 {
  240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  241. fmt.Println("err-----------", err)
  242. if err != nil {
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  244. return
  245. }
  246. startTime = theTime.Unix()
  247. }
  248. var endTime int64
  249. if len(end_date) > 0 {
  250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  251. if err != nil {
  252. utils.ErrorLog(err.Error())
  253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  254. return
  255. }
  256. endTime = theTime.Unix()
  257. }
  258. if origin == 1 {
  259. data, _ := service.GetDialysisStats(startTime, endTime, time_way, mode)
  260. c.ServeSuccessJSON(map[string]interface{}{
  261. "data": data,
  262. })
  263. } else {
  264. data, _ := service.GetScheduleStats(startTime, endTime, time_way, mode)
  265. c.ServeSuccessJSON(map[string]interface{}{
  266. "data": data,
  267. })
  268. }
  269. }
  270. func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
  271. }
  272. func (c *StatisticsApiController) GetAnticoagulant() {
  273. start_date := c.GetString("start_date")
  274. end_date := c.GetString("end_date")
  275. timeLayout := "2006-01-02"
  276. loc, _ := time.LoadLocation("Local")
  277. var startTime int64
  278. if len(start_date) > 0 {
  279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  280. fmt.Println("err-----------", err)
  281. if err != nil {
  282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  283. return
  284. }
  285. startTime = theTime.Unix()
  286. }
  287. var endTime int64
  288. if len(end_date) > 0 {
  289. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  290. if err != nil {
  291. utils.ErrorLog(err.Error())
  292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  293. return
  294. }
  295. endTime = theTime.Unix()
  296. }
  297. total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  298. if err2 != nil {
  299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  300. return
  301. }
  302. anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  303. if err != nil {
  304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  305. return
  306. }
  307. type respData struct {
  308. Name string `json:"name"`
  309. Count int `json:"count"`
  310. Percentage float64 `json:"percentage"`
  311. }
  312. var respDatas []respData
  313. for anticoagulant, count := range anticoagulantData {
  314. var respData respData
  315. respData.Name = anticoagulant
  316. respData.Count = count
  317. respData.Percentage = float64(count) / float64(total) * 100
  318. respDatas = append(respDatas, respData)
  319. }
  320. c.ServeSuccessJSON(map[string]interface{}{
  321. "data": respDatas,
  322. })
  323. }
  324. func (c *StatisticsApiController) GetAnticoagulantDetail() {
  325. anticoagulant, _ := c.GetInt64("anticoagulant")
  326. start_date := c.GetString("start_date")
  327. end_date := c.GetString("end_date")
  328. timeLayout := "2006-01-02"
  329. page, _ := c.GetInt64("page", 0)
  330. limit, _ := c.GetInt64("limit", 0)
  331. if page <= 0 {
  332. page = 1
  333. }
  334. if limit <= 0 {
  335. limit = 10
  336. }
  337. loc, _ := time.LoadLocation("Local")
  338. var startTime int64
  339. if len(start_date) > 0 {
  340. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  341. fmt.Println("err-----------", err)
  342. if err != nil {
  343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  344. return
  345. }
  346. startTime = theTime.Unix()
  347. }
  348. var endTime int64
  349. if len(end_date) > 0 {
  350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  351. if err != nil {
  352. utils.ErrorLog(err.Error())
  353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  354. return
  355. }
  356. endTime = theTime.Unix()
  357. }
  358. prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
  359. c.ServeSuccessJSON(map[string]interface{}{
  360. "prescriptions": prescriptions,
  361. "total": total,
  362. })
  363. }
  364. func (c *StatisticsApiController) GetDialyzer() {
  365. start_date := c.GetString("start_date")
  366. end_date := c.GetString("end_date")
  367. timeLayout := "2006-01-02"
  368. loc, _ := time.LoadLocation("Local")
  369. var startTime int64
  370. if len(start_date) > 0 {
  371. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  372. fmt.Println("err-----------", err)
  373. if err != nil {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. startTime = theTime.Unix()
  378. }
  379. var endTime int64
  380. if len(end_date) > 0 {
  381. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  382. if err != nil {
  383. utils.ErrorLog(err.Error())
  384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  385. return
  386. }
  387. endTime = theTime.Unix()
  388. }
  389. total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  390. if err2 != nil {
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  392. return
  393. }
  394. dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
  395. if err != nil {
  396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  397. return
  398. }
  399. type respData struct {
  400. Name string `json:"name"`
  401. Count int `json:"count"`
  402. Percentage float64 `json:"percentage"`
  403. }
  404. var respDatas []respData
  405. for _, item := range dialyzers {
  406. var respData respData
  407. respData.Name = item.Dialyzer
  408. respData.Count = item.Count
  409. respData.Percentage = float64(item.Count) / float64(total) * 100
  410. respDatas = append(respDatas, respData)
  411. }
  412. c.ServeSuccessJSON(map[string]interface{}{
  413. "data": respDatas,
  414. })
  415. }
  416. func (c *StatisticsApiController) GetDialyzerDetail() {
  417. dialyzer := c.GetString("Dialyzer")
  418. start_date := c.GetString("start_date")
  419. end_date := c.GetString("end_date")
  420. timeLayout := "2006-01-02"
  421. page, _ := c.GetInt64("page", 0)
  422. limit, _ := c.GetInt64("limit", 0)
  423. if page <= 0 {
  424. page = 1
  425. }
  426. if limit <= 0 {
  427. limit = 10
  428. }
  429. loc, _ := time.LoadLocation("Local")
  430. var startTime int64
  431. if len(start_date) > 0 {
  432. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  433. fmt.Println("err-----------", err)
  434. if err != nil {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. startTime = theTime.Unix()
  439. }
  440. var endTime int64
  441. if len(end_date) > 0 {
  442. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  443. if err != nil {
  444. utils.ErrorLog(err.Error())
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. endTime = theTime.Unix()
  449. }
  450. prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
  451. c.ServeSuccessJSON(map[string]interface{}{
  452. "prescriptions": prescriptions,
  453. "total": total,
  454. })
  455. }
  456. func (c *StatisticsApiController) GetDialyzerConfig() {
  457. dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
  458. c.ServeSuccessJSON(map[string]interface{}{
  459. "dialyzers": dialyzers,
  460. })
  461. }
  462. // 配置检验数据查询
  463. func (this *StatisticsApiController) GetInsepctionList() {
  464. adminUser := this.GetAdminUserInfo()
  465. orgid := adminUser.CurrentOrgId
  466. configurationlist, err := service.GetInsepctionConfigurationList(orgid)
  467. if err != nil {
  468. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  469. return
  470. }
  471. this.ServeSuccessJSON(map[string]interface{}{
  472. "configurationlist": configurationlist,
  473. })
  474. }
  475. func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
  476. start_date := c.GetString("start_date")
  477. end_date := c.GetString("end_date")
  478. project_id, _ := c.GetInt64("project_id")
  479. item_id, _ := c.GetInt64("item_id")
  480. timeLayout := "2006-01-02"
  481. loc, _ := time.LoadLocation("Local")
  482. var startTime int64
  483. if len(start_date) > 0 {
  484. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  485. fmt.Println("err-----------", err)
  486. if err != nil {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  488. return
  489. }
  490. startTime = theTime.Unix()
  491. }
  492. var endTime int64
  493. if len(end_date) > 0 {
  494. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  495. if err != nil {
  496. utils.ErrorLog(err.Error())
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  498. return
  499. }
  500. endTime = theTime.Unix()
  501. }
  502. //患者总数
  503. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  504. //获取配置
  505. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  506. //获取数值在正常范围内的总数
  507. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  508. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  509. min, _ := strconv.ParseFloat(config.MinRange, 64)
  510. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  511. //获取数值异常的总数
  512. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  513. //获取没有检查的患者总数
  514. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  515. c.ServeSuccessJSON(map[string]interface{}{
  516. "patient_count": patientCount,
  517. "normal_total": normalTotal,
  518. "unusual_total": unusualTotal,
  519. "no_check_total": noCheckTotal,
  520. "reference": reference,
  521. "config": config,
  522. })
  523. }
  524. func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
  525. start_date := c.GetString("start_time")
  526. end_date := c.GetString("end_time")
  527. project_id, _ := c.GetInt64("project_id")
  528. item_id, _ := c.GetInt64("item_id")
  529. patient_id, _ := c.GetInt64("patient_id")
  530. timeLayout := "2006-01-02"
  531. loc, _ := time.LoadLocation("Local")
  532. var startTime int64
  533. if len(start_date) > 0 {
  534. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  535. fmt.Println("err-----------", err)
  536. if err != nil {
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  538. return
  539. }
  540. startTime = theTime.Unix()
  541. }
  542. var endTime int64
  543. if len(end_date) > 0 {
  544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  545. if err != nil {
  546. utils.ErrorLog(err.Error())
  547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  548. return
  549. }
  550. endTime = theTime.Unix()
  551. }
  552. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  553. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  554. //获取配置
  555. reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
  556. //获取数值在正常范围内的总数
  557. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "patient": patient,
  560. "reference": reference,
  561. "inspections": inspections,
  562. })
  563. }
  564. func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
  565. start_date := c.GetString("start_date")
  566. end_date := c.GetString("end_date")
  567. project_id, _ := c.GetInt64("project_id")
  568. item_id, _ := c.GetInt64("item_id")
  569. item_type, _ := c.GetInt64("item_type")
  570. keyword := c.GetString("keyword")
  571. timeLayout := "2006-01-02"
  572. loc, _ := time.LoadLocation("Local")
  573. var startTime int64
  574. if len(start_date) > 0 {
  575. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  576. fmt.Println("err-----------", err)
  577. if err != nil {
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  579. return
  580. }
  581. startTime = theTime.Unix()
  582. }
  583. var endTime int64
  584. if len(end_date) > 0 {
  585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  586. if err != nil {
  587. utils.ErrorLog(err.Error())
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. endTime = theTime.Unix()
  592. }
  593. //获取配置
  594. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  595. //获取数值在正常范围内的总数
  596. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  597. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  598. min, _ := strconv.ParseFloat(config.MinRange, 64)
  599. //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  600. //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  601. //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  602. switch item_type {
  603. case 1:
  604. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  605. c.ServeSuccessJSON(map[string]interface{}{
  606. "list": list,
  607. "reference": reference,
  608. })
  609. break
  610. case 2:
  611. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  612. c.ServeSuccessJSON(map[string]interface{}{
  613. "list": list,
  614. "reference": reference,
  615. })
  616. break
  617. case 3:
  618. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  619. c.ServeSuccessJSON(map[string]interface{}{
  620. "list": list,
  621. "reference": reference,
  622. })
  623. break
  624. }
  625. }
  626. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  627. //start_date := c.GetString("start_date")
  628. end_date := c.GetString("end_date")
  629. //keyword := c.GetString("keyword")
  630. //timeLayout := "2006-01-02"
  631. //loc, _ := time.LoadLocation("Local")
  632. dynamicFields := make([]map[string]interface{}, 0)
  633. list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
  634. fmt.Println(list)
  635. for _, result := range list {
  636. fmt.Println(result)
  637. // 打印患者ID
  638. nb := result["姓名"].([]byte)
  639. name := string(nb)
  640. //ynamicFields := make([]map[string]interface{})
  641. //var dynamicFields DynamicData
  642. ynamicField := make(map[string]interface{})
  643. ynamicField["姓名"] = name
  644. // 打印其他列的值
  645. for columnName, columnValue := range result {
  646. // 跳过患者ID列
  647. if columnName == "姓名" {
  648. continue
  649. }
  650. // 检查值是否为nil
  651. if columnValue == nil {
  652. fmt.Printf("Column: %s, Value: <nil>\n", columnName)
  653. continue
  654. }
  655. // 将字节切片转换为字符串
  656. byteValue, ok := columnValue.([]byte)
  657. if !ok {
  658. // 如果无法转换为[]byte,输出错误信息
  659. fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
  660. continue
  661. }
  662. // 将字节切片转换为字符串
  663. strValue := string(byteValue)
  664. // 尝试将字符串转换为浮点数
  665. floatValue, err := strconv.ParseFloat(strValue, 64)
  666. if err != nil {
  667. // 如果转换失败,输出错误信息
  668. fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
  669. } else {
  670. // 如果转换成功,输出列名和浮点数值
  671. fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
  672. }
  673. ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
  674. ynamicField[columnName] = floatValue
  675. dynamicFields = append(dynamicFields, ynamicField)
  676. }
  677. }
  678. seen := make(map[interface{}]struct{})
  679. var uniqueFields []map[string]interface{}
  680. for _, field := range dynamicFields {
  681. value := field["姓名"]
  682. // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
  683. if _, ok := seen[value]; !ok {
  684. seen[value] = struct{}{}
  685. uniqueFields = append(uniqueFields, field)
  686. }
  687. }
  688. c.ServeSuccessJSON(map[string]interface{}{
  689. "list": uniqueFields,
  690. })
  691. //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  692. //
  693. //var names []string
  694. //
  695. //for _, item := range list {
  696. // names = append(names, item.ItemName)
  697. //}
  698. //
  699. //names = RemoveRepeatedNameElement(names)
  700. //fmt.Println(names)
  701. //
  702. //var tempList []models.InspectionTen
  703. //list_two := RemoveRepeatedInspectPatientElement(list)
  704. //for _, item := range list_two {
  705. // var temp models.InspectionTen
  706. // var temptwos []models.InspectionValue
  707. // temp.PatientId = item.PatientId
  708. // temp.Name = item.Name
  709. // for _, subitem := range list {
  710. // if item.PatientId == subitem.PatientId {
  711. // var temptwo models.InspectionValue
  712. // temptwo.Name = subitem.ItemName
  713. // temptwo.Value = subitem.InspectValue
  714. // temptwos = append(temptwos, temptwo)
  715. // }
  716. // }
  717. // temp.Values = temptwos
  718. // tempList = append(tempList, temp)
  719. //}
  720. //
  721. //var filtered []string
  722. //for _, item := range names {
  723. // if item != "a" {
  724. // filtered = append(filtered, item)
  725. // }
  726. //}
  727. //
  728. //for _, item := range tempList {
  729. // for _, subitem := range item.Values {
  730. // for _, name := range filtered {
  731. // if subitem.Name != name {
  732. // filtered = append(filtered, name)
  733. // }
  734. // }
  735. // }
  736. //}
  737. //
  738. ////// 将剩余字符串填充到 Inspection 数组中
  739. ////for _, name := range filtered {
  740. //// var temptwo models.InspectionValue
  741. //// temptwo.Name = subitem.ItemName
  742. //// temptwo.Value = subitem.InspectValue
  743. //// temptwos = append(temptwos, temptwo)
  744. ////}
  745. //
  746. //for _, item := range tempList {
  747. // //for _, subitem := range item.Values {
  748. // var temptwo models.InspectionValue
  749. // for _, name := range filtered {
  750. // temptwo.Name = name
  751. // temptwo.Value = ""
  752. // }
  753. // item.Values = append(item.Values, temptwo)
  754. // //}
  755. // fmt.Println(item.Values)
  756. //}
  757. }
  758. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  759. start_date := c.GetString("start_date")
  760. end_date := c.GetString("end_date")
  761. project_id, _ := c.GetInt64("project_id")
  762. item_id, _ := c.GetInt64("item_id")
  763. item_type, _ := c.GetInt64("item_type")
  764. //order_type, _ := c.GetInt64("order_type")
  765. keyword := c.GetString("keyword")
  766. s_type, _ := c.GetInt64("type")
  767. timeLayout := "2006-01-02"
  768. loc, _ := time.LoadLocation("Local")
  769. var startTime int64
  770. if len(start_date) > 0 {
  771. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  772. fmt.Println("err-----------", err)
  773. if err != nil {
  774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  775. return
  776. }
  777. startTime = theTime.Unix()
  778. }
  779. var endTime int64
  780. if len(end_date) > 0 {
  781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  782. if err != nil {
  783. utils.ErrorLog(err.Error())
  784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  785. return
  786. }
  787. endTime = theTime.Unix()
  788. }
  789. //获取配置
  790. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  791. //获取数值在正常范围内的总数
  792. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  793. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  794. switch item_type {
  795. case 0:
  796. break
  797. case 1:
  798. if s_type == 2 { //KTV
  799. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  800. c.ServeSuccessJSON(map[string]interface{}{
  801. "list": list,
  802. })
  803. } else if s_type == 3 { //URR
  804. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  805. c.ServeSuccessJSON(map[string]interface{}{
  806. "list": list,
  807. })
  808. } else {
  809. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": list,
  812. "reference": reference,
  813. })
  814. }
  815. break
  816. case 2:
  817. if s_type == 2 { //KTV
  818. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  819. c.ServeSuccessJSON(map[string]interface{}{
  820. "list": list,
  821. })
  822. } else if s_type == 3 { //URR
  823. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  824. c.ServeSuccessJSON(map[string]interface{}{
  825. "list": list,
  826. })
  827. } else {
  828. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  829. c.ServeSuccessJSON(map[string]interface{}{
  830. "list": list,
  831. "reference": reference,
  832. })
  833. }
  834. break
  835. case 3:
  836. if s_type == 2 { //KTV
  837. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  838. c.ServeSuccessJSON(map[string]interface{}{
  839. "list": list,
  840. })
  841. } else if s_type == 3 { //URR
  842. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  843. c.ServeSuccessJSON(map[string]interface{}{
  844. "list": list,
  845. })
  846. } else {
  847. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  848. c.ServeSuccessJSON(map[string]interface{}{
  849. "list": list,
  850. "reference": reference,
  851. })
  852. }
  853. break
  854. }
  855. }
  856. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  857. start_date := c.GetString("start_date")
  858. end_date := c.GetString("end_date")
  859. project_id, _ := c.GetInt64("project_id")
  860. item_id, _ := c.GetInt64("item_id")
  861. s_type, _ := c.GetInt64("type")
  862. timeLayout := "2006-01-02"
  863. loc, _ := time.LoadLocation("Local")
  864. var startTime int64
  865. if len(start_date) > 0 {
  866. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  867. fmt.Println("err-----------", err)
  868. if err != nil {
  869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  870. return
  871. }
  872. startTime = theTime.Unix()
  873. }
  874. var endTime int64
  875. if len(end_date) > 0 {
  876. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  877. if err != nil {
  878. utils.ErrorLog(err.Error())
  879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  880. return
  881. }
  882. endTime = theTime.Unix()
  883. }
  884. //患者总数
  885. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  886. //获取配置
  887. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  888. //获取数值在正常范围内的总数
  889. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  890. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  891. if s_type == 2 {
  892. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  893. //获取数值异常的总数
  894. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  895. //获取没有检查的患者总数
  896. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  897. c.ServeSuccessJSON(map[string]interface{}{
  898. "patient_count": patientCount,
  899. "normal_total": normalTotal,
  900. "unusual_total": unusualTotal,
  901. "no_check_total": noCheckTotal,
  902. })
  903. } else if s_type == 3 {
  904. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  905. //获取数值异常的总数
  906. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  907. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  908. //获取没有检查的患者总数
  909. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  910. c.ServeSuccessJSON(map[string]interface{}{
  911. "patient_count": patientCount,
  912. "normal_total": normalTotal,
  913. "unusual_total": unusualTotal,
  914. "no_check_total": noCheckTotal,
  915. })
  916. } else {
  917. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  918. //获取数值异常的总数
  919. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  920. //获取没有检查的患者总数
  921. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  922. c.ServeSuccessJSON(map[string]interface{}{
  923. "patient_count": patientCount,
  924. "normal_total": normalTotal,
  925. "unusual_total": unusualTotal,
  926. "no_check_total": noCheckTotal,
  927. "reference": reference,
  928. })
  929. }
  930. }
  931. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  932. start_date := c.GetString("start_time")
  933. end_date := c.GetString("end_time")
  934. project_id, _ := c.GetInt64("project_id")
  935. item_id, _ := c.GetInt64("item_id")
  936. patient_id, _ := c.GetInt64("patient_id")
  937. s_type, _ := c.GetInt64("type")
  938. timeLayout := "2006-01-02"
  939. loc, _ := time.LoadLocation("Local")
  940. var startTime int64
  941. if len(start_date) > 0 {
  942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  943. fmt.Println("err-----------", err)
  944. if err != nil {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  946. return
  947. }
  948. startTime = theTime.Unix()
  949. }
  950. var endTime int64
  951. if len(end_date) > 0 {
  952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  953. if err != nil {
  954. utils.ErrorLog(err.Error())
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. endTime = theTime.Unix()
  959. }
  960. if s_type == 2 {
  961. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  962. //获取配置
  963. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  964. //获取数值在正常范围内的总数
  965. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  966. c.ServeSuccessJSON(map[string]interface{}{
  967. "patient": patient,
  968. "reference": reference,
  969. "inspections": inspections,
  970. })
  971. } else if s_type == 3 {
  972. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  973. //获取配置
  974. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  975. //获取数值在正常范围内的总数
  976. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  977. c.ServeSuccessJSON(map[string]interface{}{
  978. "patient": patient,
  979. "reference": reference,
  980. "inspections": inspections,
  981. })
  982. } else {
  983. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  984. //获取配置
  985. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  986. //获取数值在正常范围内的总数
  987. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "patient": patient,
  990. "reference": reference,
  991. "inspections": inspections,
  992. })
  993. }
  994. }
  995. func (c *StatisticsApiController) GetStatistics() {
  996. adminUserInfo := c.GetAdminUserInfo()
  997. // thisTime := time.Now()
  998. year, month, day := time.Now().Date()
  999. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1000. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  1001. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  1002. todayWeek := int(todayTime.Weekday())
  1003. if todayWeek == 0 {
  1004. todayWeek = 7
  1005. }
  1006. weekEnd := 7 - todayWeek
  1007. weekStart := weekEnd - 6
  1008. // endDay := todayTime.AddDate(0, 0, weekEnd)
  1009. startDay := todayTime.AddDate(0, 0, weekStart)
  1010. //患者总数
  1011. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  1012. //今日透析
  1013. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  1014. //本周透析
  1015. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  1016. //传染病
  1017. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  1018. //性别分布
  1019. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  1020. //年龄分布
  1021. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  1022. //透析模式
  1023. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  1024. c.ServeSuccessJSON(map[string]interface{}{
  1025. "patient_count": patientCount,
  1026. "today_dialysis_count": todayDialysisCount,
  1027. "week_daylysis_count": weekDaylysisCount,
  1028. "disease_counts": diseaseCounts,
  1029. "gender_counts": genderCounts,
  1030. "age_counts": ageCounts,
  1031. "mode_counts": modeCounts,
  1032. })
  1033. }
  1034. func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
  1035. newArr = make([]models.InspectionTenOne, 0)
  1036. for i := 0; i < len(arr); i++ {
  1037. repeat := false
  1038. for j := i + 1; j < len(arr); j++ {
  1039. if arr[i].PatientId == arr[j].PatientId {
  1040. repeat = true
  1041. break
  1042. }
  1043. }
  1044. if !repeat {
  1045. newArr = append(newArr, arr[i])
  1046. }
  1047. }
  1048. return
  1049. }
  1050. func RemoveRepeatedNameElement(arr []string) (newArr []string) {
  1051. newArr = make([]string, 0)
  1052. for i := 0; i < len(arr); i++ {
  1053. repeat := false
  1054. for j := i + 1; j < len(arr); j++ {
  1055. if arr[i] == arr[j] {
  1056. repeat = true
  1057. break
  1058. }
  1059. }
  1060. if !repeat {
  1061. newArr = append(newArr, arr[i])
  1062. }
  1063. }
  1064. return
  1065. }
  1066. // 根据指定的日期范围拆分成周、月、年
  1067. func splitDateRange(startDate, endDate string) ([]time.Time, error) {
  1068. startTime, err := time.Parse("2006-01-02", startDate)
  1069. if err != nil {
  1070. return nil, err
  1071. }
  1072. endTime, err := time.Parse("2006-01-02", endDate)
  1073. if err != nil {
  1074. return nil, err
  1075. }
  1076. var result []time.Time
  1077. for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
  1078. result = append(result, date)
  1079. }
  1080. return result, nil
  1081. }
  1082. // 按周统计日期
  1083. func groupByWeek(dates []time.Time) [][]time.Time {
  1084. var result [][]time.Time
  1085. var currentWeek []time.Time
  1086. for _, date := range dates {
  1087. currentWeek = append(currentWeek, date)
  1088. if date.Weekday() == time.Sunday {
  1089. result = append(result, currentWeek)
  1090. currentWeek = nil
  1091. }
  1092. }
  1093. if len(currentWeek) > 0 {
  1094. result = append(result, currentWeek)
  1095. }
  1096. return result
  1097. }
  1098. // 按月统计日期
  1099. func groupByMonth(dates []time.Time) [][]time.Time {
  1100. var result [][]time.Time
  1101. var currentMonth []time.Time
  1102. lastMonth := dates[0].Month()
  1103. for _, date := range dates {
  1104. if date.Month() != lastMonth {
  1105. result = append(result, currentMonth)
  1106. currentMonth = nil
  1107. lastMonth = date.Month()
  1108. }
  1109. currentMonth = append(currentMonth, date)
  1110. }
  1111. if len(currentMonth) > 0 {
  1112. result = append(result, currentMonth)
  1113. }
  1114. return result
  1115. }
  1116. // 按年统计日期
  1117. func groupByYear(dates []time.Time) [][]time.Time {
  1118. var result [][]time.Time
  1119. var currentYear []time.Time
  1120. lastYear := dates[0].Year()
  1121. for _, date := range dates {
  1122. if date.Year() != lastYear {
  1123. result = append(result, currentYear)
  1124. currentYear = nil
  1125. lastYear = date.Year()
  1126. }
  1127. currentYear = append(currentYear, date)
  1128. }
  1129. if len(currentYear) > 0 {
  1130. result = append(result, currentYear)
  1131. }
  1132. return result
  1133. }
  1134. // 将日期拆分为按天统计
  1135. func splitByDay(startDate, endDate time.Time) []time.Time {
  1136. var dates []time.Time
  1137. for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
  1138. dates = append(dates, d)
  1139. }
  1140. return dates
  1141. }