statistics_api_controller.go 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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, c.GetAdminUserInfo().CurrentOrgId)
  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.ItemName, max, min)
  74. //获取数值异常的总数
  75. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  76. //获取没有检查的患者总数
  77. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  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. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  117. //获取配置
  118. reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
  119. //获取数值在正常范围内的总数
  120. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "patient": patient,
  123. "reference": reference,
  124. "inspections": inspections,
  125. })
  126. }
  127. func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
  128. start_date := c.GetString("start_date")
  129. end_date := c.GetString("end_date")
  130. project_id, _ := c.GetInt64("project_id")
  131. item_id, _ := c.GetInt64("item_id")
  132. item_type, _ := c.GetInt64("item_type")
  133. keyword := c.GetString("keyword")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. var startTime int64
  137. if len(start_date) > 0 {
  138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  139. fmt.Println("err-----------", err)
  140. if err != nil {
  141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  142. return
  143. }
  144. startTime = theTime.Unix()
  145. }
  146. var endTime int64
  147. if len(end_date) > 0 {
  148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  149. if err != nil {
  150. utils.ErrorLog(err.Error())
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. endTime = theTime.Unix()
  155. }
  156. //获取配置
  157. reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  158. //获取数值在正常范围内的总数
  159. config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  160. max, _ := strconv.ParseFloat(config.LargeRange, 64)
  161. min, _ := strconv.ParseFloat(config.MinRange, 64)
  162. //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  163. //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  164. //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
  165. switch item_type {
  166. case 1:
  167. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  168. c.ServeSuccessJSON(map[string]interface{}{
  169. "list": list,
  170. "reference": reference,
  171. })
  172. break
  173. case 2:
  174. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  175. c.ServeSuccessJSON(map[string]interface{}{
  176. "list": list,
  177. "reference": reference,
  178. })
  179. break
  180. case 3:
  181. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  182. c.ServeSuccessJSON(map[string]interface{}{
  183. "list": list,
  184. "reference": reference,
  185. })
  186. break
  187. }
  188. }
  189. func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
  190. start_date := c.GetString("start_date")
  191. end_date := c.GetString("end_date")
  192. keyword := c.GetString("keyword")
  193. timeLayout := "2006-01-02"
  194. loc, _ := time.LoadLocation("Local")
  195. var startTime int64
  196. if len(start_date) > 0 {
  197. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  198. if err != nil {
  199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  200. return
  201. }
  202. startTime = theTime.Unix()
  203. }
  204. var endTime int64
  205. if len(end_date) > 0 {
  206. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  207. if err != nil {
  208. utils.ErrorLog(err.Error())
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. endTime = theTime.Unix()
  213. }
  214. list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
  215. c.ServeSuccessJSON(map[string]interface{}{
  216. "list": list,
  217. })
  218. }
  219. func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
  220. start_date := c.GetString("start_date")
  221. end_date := c.GetString("end_date")
  222. project_id, _ := c.GetInt64("project_id")
  223. item_id, _ := c.GetInt64("item_id")
  224. item_type, _ := c.GetInt64("item_type")
  225. //order_type, _ := c.GetInt64("order_type")
  226. keyword := c.GetString("keyword")
  227. s_type, _ := c.GetInt64("type")
  228. timeLayout := "2006-01-02"
  229. loc, _ := time.LoadLocation("Local")
  230. var startTime int64
  231. if len(start_date) > 0 {
  232. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  233. fmt.Println("err-----------", err)
  234. if err != nil {
  235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  236. return
  237. }
  238. startTime = theTime.Unix()
  239. }
  240. var endTime int64
  241. if len(end_date) > 0 {
  242. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  243. if err != nil {
  244. utils.ErrorLog(err.Error())
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. endTime = theTime.Unix()
  249. }
  250. //获取配置
  251. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  252. //获取数值在正常范围内的总数
  253. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  254. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  255. switch item_type {
  256. case 0:
  257. break
  258. case 1:
  259. if s_type == 2 { //KTV
  260. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  261. c.ServeSuccessJSON(map[string]interface{}{
  262. "list": list,
  263. })
  264. } else if s_type == 3 { //URR
  265. list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  266. c.ServeSuccessJSON(map[string]interface{}{
  267. "list": list,
  268. })
  269. } else {
  270. list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  271. c.ServeSuccessJSON(map[string]interface{}{
  272. "list": list,
  273. "reference": reference,
  274. })
  275. }
  276. break
  277. case 2:
  278. if s_type == 2 { //KTV
  279. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
  280. c.ServeSuccessJSON(map[string]interface{}{
  281. "list": list,
  282. })
  283. } else if s_type == 3 { //URR
  284. list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
  285. c.ServeSuccessJSON(map[string]interface{}{
  286. "list": list,
  287. })
  288. } else {
  289. list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
  290. c.ServeSuccessJSON(map[string]interface{}{
  291. "list": list,
  292. "reference": reference,
  293. })
  294. }
  295. break
  296. case 3:
  297. if s_type == 2 { //KTV
  298. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
  299. c.ServeSuccessJSON(map[string]interface{}{
  300. "list": list,
  301. })
  302. } else if s_type == 3 { //URR
  303. list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
  304. c.ServeSuccessJSON(map[string]interface{}{
  305. "list": list,
  306. })
  307. } else {
  308. list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
  309. c.ServeSuccessJSON(map[string]interface{}{
  310. "list": list,
  311. "reference": reference,
  312. })
  313. }
  314. break
  315. }
  316. }
  317. func (c *StatisticsApiController) GetAllInspectionStatistisc() {
  318. start_date := c.GetString("start_date")
  319. end_date := c.GetString("end_date")
  320. project_id, _ := c.GetInt64("project_id")
  321. item_id, _ := c.GetInt64("item_id")
  322. s_type, _ := c.GetInt64("type")
  323. timeLayout := "2006-01-02"
  324. loc, _ := time.LoadLocation("Local")
  325. var startTime int64
  326. if len(start_date) > 0 {
  327. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  328. fmt.Println("err-----------", err)
  329. if err != nil {
  330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  331. return
  332. }
  333. startTime = theTime.Unix()
  334. }
  335. var endTime int64
  336. if len(end_date) > 0 {
  337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  338. if err != nil {
  339. utils.ErrorLog(err.Error())
  340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  341. return
  342. }
  343. endTime = theTime.Unix()
  344. }
  345. //患者总数
  346. patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
  347. //获取配置
  348. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  349. //获取数值在正常范围内的总数
  350. max, _ := strconv.ParseFloat(reference.RangeMax, 64)
  351. min, _ := strconv.ParseFloat(reference.RangeMin, 64)
  352. if s_type == 2 {
  353. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  354. //获取数值异常的总数
  355. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
  356. //获取没有检查的患者总数
  357. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
  358. c.ServeSuccessJSON(map[string]interface{}{
  359. "patient_count": patientCount,
  360. "normal_total": normalTotal,
  361. "unusual_total": unusualTotal,
  362. "no_check_total": noCheckTotal,
  363. })
  364. } else if s_type == 3 {
  365. normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  366. //获取数值异常的总数
  367. //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
  368. unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
  369. //获取没有检查的患者总数
  370. noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
  371. c.ServeSuccessJSON(map[string]interface{}{
  372. "patient_count": patientCount,
  373. "normal_total": normalTotal,
  374. "unusual_total": unusualTotal,
  375. "no_check_total": noCheckTotal,
  376. })
  377. } else {
  378. normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  379. //获取数值异常的总数
  380. unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
  381. //获取没有检查的患者总数
  382. noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
  383. c.ServeSuccessJSON(map[string]interface{}{
  384. "patient_count": patientCount,
  385. "normal_total": normalTotal,
  386. "unusual_total": unusualTotal,
  387. "no_check_total": noCheckTotal,
  388. "reference": reference,
  389. })
  390. }
  391. }
  392. func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
  393. start_date := c.GetString("start_time")
  394. end_date := c.GetString("end_time")
  395. project_id, _ := c.GetInt64("project_id")
  396. item_id, _ := c.GetInt64("item_id")
  397. patient_id, _ := c.GetInt64("patient_id")
  398. s_type, _ := c.GetInt64("type")
  399. timeLayout := "2006-01-02"
  400. loc, _ := time.LoadLocation("Local")
  401. var startTime int64
  402. if len(start_date) > 0 {
  403. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
  404. fmt.Println("err-----------", err)
  405. if err != nil {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  407. return
  408. }
  409. startTime = theTime.Unix()
  410. }
  411. var endTime int64
  412. if len(end_date) > 0 {
  413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
  414. if err != nil {
  415. utils.ErrorLog(err.Error())
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. endTime = theTime.Unix()
  420. }
  421. if s_type == 2 {
  422. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  423. //获取配置
  424. reference, _ := service.GetInspectionReferenceThree(1014, 10950)
  425. //获取数值在正常范围内的总数
  426. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
  427. c.ServeSuccessJSON(map[string]interface{}{
  428. "patient": patient,
  429. "reference": reference,
  430. "inspections": inspections,
  431. })
  432. } else if s_type == 3 {
  433. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  434. //获取配置
  435. reference, _ := service.GetInspectionReferenceThree(1014, 10951)
  436. //获取数值在正常范围内的总数
  437. inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
  438. c.ServeSuccessJSON(map[string]interface{}{
  439. "patient": patient,
  440. "reference": reference,
  441. "inspections": inspections,
  442. })
  443. } else {
  444. patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  445. //获取配置
  446. reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
  447. //获取数值在正常范围内的总数
  448. inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
  449. c.ServeSuccessJSON(map[string]interface{}{
  450. "patient": patient,
  451. "reference": reference,
  452. "inspections": inspections,
  453. })
  454. }
  455. }
  456. func (c *StatisticsApiController) GetStatistics() {
  457. adminUserInfo := c.GetAdminUserInfo()
  458. // thisTime := time.Now()
  459. year, month, day := time.Now().Date()
  460. todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  461. startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
  462. endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
  463. todayWeek := int(todayTime.Weekday())
  464. if todayWeek == 0 {
  465. todayWeek = 7
  466. }
  467. weekEnd := 7 - todayWeek
  468. weekStart := weekEnd - 6
  469. // endDay := todayTime.AddDate(0, 0, weekEnd)
  470. startDay := todayTime.AddDate(0, 0, weekStart)
  471. //患者总数
  472. patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  473. //今日透析
  474. todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
  475. //本周透析
  476. weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
  477. //传染病
  478. diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
  479. //性别分布
  480. genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
  481. //年龄分布
  482. ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
  483. //透析模式
  484. modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
  485. c.ServeSuccessJSON(map[string]interface{}{
  486. "patient_count": patientCount,
  487. "today_dialysis_count": todayDialysisCount,
  488. "week_daylysis_count": weekDaylysisCount,
  489. "disease_counts": diseaseCounts,
  490. "gender_counts": genderCounts,
  491. "age_counts": ageCounts,
  492. "mode_counts": modeCounts,
  493. })
  494. }