statistics_api_controller.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "fmt"
  7. "github.com/astaxie/beego"
  8. "strconv"
  9. "time"
  10. )
  11. type StatisticsApiController struct {
  12. BaseAuthAPIController
  13. }
  14. func StatisticsApiRegistRouters() {
  15. beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics")
  16. beego.Router("/api/qc/statistiscall/get", &StatisticsApiController{}, "get:GetAllInspectionStatistisc")
  17. beego.Router("/api/qc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonInspectionStatistisc")
  18. beego.Router("/api/qc/statistiscperson/list", &StatisticsApiController{}, "get:GetInsepctionList")
  19. beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
  20. beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
  21. beego.Router("/api/commonqc/statistiscall/get", &StatisticsApiController{}, "get:GetAllCommonInspectionStatistisc")
  22. beego.Router("/api/commonqc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonCommonInspectionStatistisc")
  23. beego.Router("/api/commonqc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientCommonInspectionStatistisc")
  24. }
  25. // 配置检验数据查询
  26. func (this *StatisticsApiController) GetInsepctionList() {
  27. adminUser := this.GetAdminUserInfo()
  28. orgid := adminUser.CurrentOrgId
  29. configurationlist, err := service.GetInsepctionConfigurationList(orgid)
  30. if err != nil {
  31. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  32. return
  33. }
  34. this.ServeSuccessJSON(map[string]interface{}{
  35. "configurationlist": configurationlist,
  36. })
  37. }
  38. func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
  39. start_date := c.GetString("start_date")
  40. end_date := c.GetString("end_date")
  41. project_id, _ := c.GetInt64("project_id")
  42. item_id, _ := c.GetInt64("item_id")
  43. timeLayout := "2006-01-02"
  44. loc, _ := time.LoadLocation("Local")
  45. var startTime int64
  46. if len(start_date) > 0 {
  47. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  48. fmt.Println("err-----------", err)
  49. if err != nil {
  50. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  51. return
  52. }
  53. startTime = theTime.Unix()
  54. }
  55. var endTime int64
  56. if len(end_date) > 0 {
  57. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  58. if err != nil {
  59. utils.ErrorLog(err.Error())
  60. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  61. return
  62. }
  63. endTime = theTime.Unix()
  64. }
  65. //患者总数
  66. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  67. //获取配置
  68. reference, _ := service.GetInspectionReferenceFour(project_id, item_id)
  69. //获取数值在正常范围内的总数
  70. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  71. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  72. min, _ := strconv.ParseFloat(config.MinRange, 64)
  73. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  74. //获取数值异常的总数
  75. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  76. //获取没有检查的患者总数
  77. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
  78. c.ServeSuccessJSON(map[string]interface{}{
  79. "patient_count": patientCount,
  80. "normal_total": normalTotal,
  81. "unusual_total": unusualTotal,
  82. "no_check_total": noCheckTotal,
  83. "reference": reference,
  84. "config": config,
  85. })
  86. }
  87. func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
  88. start_date := c.GetString("start_time")
  89. end_date := c.GetString("end_time")
  90. project_id, _ := c.GetInt64("project_id")
  91. item_id, _ := c.GetInt64("item_id")
  92. patient_id, _ := c.GetInt64("patient_id")
  93. timeLayout := "2006-01-02"
  94. loc, _ := time.LoadLocation("Local")
  95. var startTime int64
  96. if len(start_date) > 0 {
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  98. fmt.Println("err-----------", err)
  99. if err != nil {
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. startTime = theTime.Unix()
  104. }
  105. var endTime int64
  106. if len(end_date) > 0 {
  107. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  108. if err != nil {
  109. utils.ErrorLog(err.Error())
  110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. endTime = theTime.Unix()
  114. }
  115. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  116. //获取配置
  117. reference, _ := service.GetInspectionReferenceFour(project_id, item_id)
  118. //获取数值在正常范围内的总数
  119. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "patient": patient,
  122. "reference": reference,
  123. "inspections": inspections,
  124. })
  125. }
  126. func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
  127. start_date := c.GetString("start_date")
  128. end_date := c.GetString("end_date")
  129. project_id, _ := c.GetInt64("project_id")
  130. item_id, _ := c.GetInt64("item_id")
  131. item_type, _ := c.GetInt64("item_type")
  132. keyword := c.GetString("keyword")
  133. timeLayout := "2006-01-02"
  134. loc, _ := time.LoadLocation("Local")
  135. var startTime int64
  136. if len(start_date) > 0 {
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  138. fmt.Println("err-----------", err)
  139. if err != nil {
  140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. return
  142. }
  143. startTime = theTime.Unix()
  144. }
  145. var endTime int64
  146. if len(end_date) > 0 {
  147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  148. if err != nil {
  149. utils.ErrorLog(err.Error())
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  151. return
  152. }
  153. endTime = theTime.Unix()
  154. }
  155. //获取配置
  156. reference, _ := service.GetInspectionReferenceFour(project_id, item_id)
  157. //获取数值在正常范围内的总数
  158. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  159. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  160. min, _ := strconv.ParseFloat(config.MinRange, 64)
  161. //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  162. //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  163. switch item_type {
  164. case 1:
  165. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "list": list,
  168. "reference": reference,
  169. })
  170. break
  171. case 2:
  172. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
  173. c.ServeSuccessJSON(map[string]interface{}{
  174. "list": list,
  175. "reference": reference,
  176. })
  177. break
  178. case 3:
  179. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  180. c.ServeSuccessJSON(map[string]interface{}{
  181. "list": list,
  182. "reference": reference,
  183. })
  184. break
  185. }
  186. }
  187. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  188. start_date := c.GetString("start_date")
  189. end_date := c.GetString("end_date")
  190. keyword := c.GetString("keyword")
  191. timeLayout := "2006-01-02"
  192. loc, _ := time.LoadLocation("Local")
  193. var startTime int64
  194. if len(start_date) > 0 {
  195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  196. if err != nil {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. startTime = theTime.Unix()
  201. }
  202. var endTime int64
  203. if len(end_date) > 0 {
  204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  205. if err != nil {
  206. utils.ErrorLog(err.Error())
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. endTime = theTime.Unix()
  211. }
  212. list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  213. c.ServeSuccessJSON(map[string]interface{}{
  214. "list": list,
  215. })
  216. }
  217. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  218. start_date := c.GetString("start_date")
  219. end_date := c.GetString("end_date")
  220. project_id, _ := c.GetInt64("project_id")
  221. item_id, _ := c.GetInt64("item_id")
  222. item_type, _ := c.GetInt64("item_type")
  223. //order_type, _ := c.GetInt64("order_type")
  224. keyword := c.GetString("keyword")
  225. s_type, _ := c.GetInt64("type")
  226. timeLayout := "2006-01-02"
  227. loc, _ := time.LoadLocation("Local")
  228. var startTime int64
  229. if len(start_date) > 0 {
  230. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  231. fmt.Println("err-----------", err)
  232. if err != nil {
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  234. return
  235. }
  236. startTime = theTime.Unix()
  237. }
  238. var endTime int64
  239. if len(end_date) > 0 {
  240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  241. if err != nil {
  242. utils.ErrorLog(err.Error())
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  244. return
  245. }
  246. endTime = theTime.Unix()
  247. }
  248. //获取配置
  249. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  250. //获取数值在正常范围内的总数
  251. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  252. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  253. switch item_type {
  254. case 0:
  255. break
  256. case 1:
  257. if s_type == 2 { //KTV
  258. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  259. c.ServeSuccessJSON(map[string]interface{}{
  260. "list": list,
  261. })
  262. } else if s_type == 3 { //URR
  263. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  264. c.ServeSuccessJSON(map[string]interface{}{
  265. "list": list,
  266. })
  267. } else {
  268. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  269. c.ServeSuccessJSON(map[string]interface{}{
  270. "list": list,
  271. "reference": reference,
  272. })
  273. }
  274. break
  275. case 2:
  276. if s_type == 2 { //KTV
  277. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  278. c.ServeSuccessJSON(map[string]interface{}{
  279. "list": list,
  280. })
  281. } else if s_type == 3 { //URR
  282. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  283. c.ServeSuccessJSON(map[string]interface{}{
  284. "list": list,
  285. })
  286. } else {
  287. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, keyword)
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": list,
  290. "reference": reference,
  291. })
  292. }
  293. break
  294. case 3:
  295. if s_type == 2 { //KTV
  296. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": list,
  299. })
  300. } else if s_type == 3 { //URR
  301. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  302. c.ServeSuccessJSON(map[string]interface{}{
  303. "list": list,
  304. })
  305. } else {
  306. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min, keyword)
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": list,
  309. "reference": reference,
  310. })
  311. }
  312. break
  313. }
  314. }
  315. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  316. start_date := c.GetString("start_date")
  317. end_date := c.GetString("end_date")
  318. project_id, _ := c.GetInt64("project_id")
  319. item_id, _ := c.GetInt64("item_id")
  320. s_type, _ := c.GetInt64("type")
  321. timeLayout := "2006-01-02"
  322. loc, _ := time.LoadLocation("Local")
  323. var startTime int64
  324. if len(start_date) > 0 {
  325. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  326. fmt.Println("err-----------", err)
  327. if err != nil {
  328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  329. return
  330. }
  331. startTime = theTime.Unix()
  332. }
  333. var endTime int64
  334. if len(end_date) > 0 {
  335. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  336. if err != nil {
  337. utils.ErrorLog(err.Error())
  338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  339. return
  340. }
  341. endTime = theTime.Unix()
  342. }
  343. //患者总数
  344. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  345. //获取配置
  346. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  347. //获取数值在正常范围内的总数
  348. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  349. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  350. if s_type == 2 {
  351. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  352. //获取数值异常的总数
  353. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  354. //获取没有检查的患者总数
  355. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  356. c.ServeSuccessJSON(map[string]interface{}{
  357. "patient_count": patientCount,
  358. "normal_total": normalTotal,
  359. "unusual_total": unusualTotal,
  360. "no_check_total": noCheckTotal,
  361. })
  362. } else if s_type == 3 {
  363. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  364. //获取数值异常的总数
  365. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  366. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  367. //获取没有检查的患者总数
  368. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  369. c.ServeSuccessJSON(map[string]interface{}{
  370. "patient_count": patientCount,
  371. "normal_total": normalTotal,
  372. "unusual_total": unusualTotal,
  373. "no_check_total": noCheckTotal,
  374. })
  375. } else {
  376. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  377. //获取数值异常的总数
  378. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID, max, min)
  379. //获取没有检查的患者总数
  380. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.ID)
  381. c.ServeSuccessJSON(map[string]interface{}{
  382. "patient_count": patientCount,
  383. "normal_total": normalTotal,
  384. "unusual_total": unusualTotal,
  385. "no_check_total": noCheckTotal,
  386. "reference": reference,
  387. })
  388. }
  389. }
  390. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  391. start_date := c.GetString("start_time")
  392. end_date := c.GetString("end_time")
  393. project_id, _ := c.GetInt64("project_id")
  394. item_id, _ := c.GetInt64("item_id")
  395. patient_id, _ := c.GetInt64("patient_id")
  396. s_type, _ := c.GetInt64("type")
  397. timeLayout := "2006-01-02"
  398. loc, _ := time.LoadLocation("Local")
  399. var startTime int64
  400. if len(start_date) > 0 {
  401. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  402. fmt.Println("err-----------", err)
  403. if err != nil {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  405. return
  406. }
  407. startTime = theTime.Unix()
  408. }
  409. var endTime int64
  410. if len(end_date) > 0 {
  411. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  412. if err != nil {
  413. utils.ErrorLog(err.Error())
  414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  415. return
  416. }
  417. endTime = theTime.Unix()
  418. }
  419. if s_type == 2 {
  420. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  421. //获取配置
  422. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  423. //获取数值在正常范围内的总数
  424. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  425. c.ServeSuccessJSON(map[string]interface{}{
  426. "patient": patient,
  427. "reference": reference,
  428. "inspections": inspections,
  429. })
  430. } else if s_type == 3 {
  431. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  432. //获取配置
  433. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  434. //获取数值在正常范围内的总数
  435. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  436. c.ServeSuccessJSON(map[string]interface{}{
  437. "patient": patient,
  438. "reference": reference,
  439. "inspections": inspections,
  440. })
  441. } else {
  442. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  443. //获取配置
  444. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  445. //获取数值在正常范围内的总数
  446. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.SystemProjectId, reference.SysItemId, patient_id)
  447. c.ServeSuccessJSON(map[string]interface{}{
  448. "patient": patient,
  449. "reference": reference,
  450. "inspections": inspections,
  451. })
  452. }
  453. }
  454. func (c *StatisticsApiController) GetStatistics() {
  455. adminUserInfo := c.GetAdminUserInfo()
  456. // thisTime := time.Now()
  457. year, month, day := time.Now().Date()
  458. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  459. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  460. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  461. todayWeek := int(todayTime.Weekday())
  462. if todayWeek == 0 {
  463. todayWeek = 7
  464. }
  465. weekEnd := 7 - todayWeek
  466. weekStart := weekEnd - 6
  467. // endDay := todayTime.AddDate(0, 0, weekEnd)
  468. startDay := todayTime.AddDate(0, 0, weekStart)
  469. //患者总数
  470. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  471. //今日透析
  472. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  473. //本周透析
  474. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  475. //传染病
  476. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  477. //性别分布
  478. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  479. //年龄分布
  480. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  481. //透析模式
  482. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  483. c.ServeSuccessJSON(map[string]interface{}{
  484. "patient_count": patientCount,
  485. "today_dialysis_count": todayDialysisCount,
  486. "week_daylysis_count": weekDaylysisCount,
  487. "disease_counts": diseaseCounts,
  488. "gender_counts": genderCounts,
  489. "age_counts": ageCounts,
  490. "mode_counts": modeCounts,
  491. })
  492. }