common_api_controller.go 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/controllers"
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/jinzhu/gorm"
  11. "strconv"
  12. "time"
  13. )
  14. type CommonApiController struct {
  15. controllers.BaseAuthAPIController
  16. }
  17. func (this *CommonApiController) GetInspectionMajor() {
  18. major, err := service.GetInspectionMajor(0)
  19. if err != nil {
  20. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  21. return
  22. }
  23. this.ServeSuccessJSON(map[string]interface{}{
  24. "inspection": major,
  25. })
  26. }
  27. func (this *CommonApiController) GetInspectionMinor() {
  28. id, _ := this.GetInt64("id")
  29. minor, err := service.GetInspectionMinor(id)
  30. if err != nil {
  31. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  32. return
  33. }
  34. this.ServeSuccessJSON(map[string]interface{}{
  35. "inspection": minor,
  36. })
  37. }
  38. func (this *CommonApiController) GetInspectionRange() {
  39. id, _ := this.GetInt64("id")
  40. fmt.Println("id", id)
  41. inspectionRange, err := service.GetInspectionRange(id)
  42. if err != nil {
  43. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  44. return
  45. }
  46. this.ServeSuccessJSON(map[string]interface{}{
  47. "inspectionRange": inspectionRange,
  48. })
  49. }
  50. func (this *CommonApiController) SaveConfiguration() {
  51. adminInfo := this.GetAdminUserInfo()
  52. orgid := adminInfo.CurrentOrgId
  53. dataBody := make(map[string]interface{}, 0)
  54. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  55. fmt.Println("err", err)
  56. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  57. fmt.Println("大项", inspectionmajor)
  58. inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
  59. fmt.Println("小项", inspectionMinor)
  60. minrange := dataBody["min_range"].(string)
  61. fmt.Println("minragne", minrange)
  62. largerange := dataBody["large_range"].(string)
  63. fmt.Println("largerange", largerange)
  64. sort := dataBody["sort"].(string)
  65. sorts, err := strconv.ParseInt(sort, 10, 64)
  66. fmt.Println("sort", sort)
  67. _, errcode := service.GetConfigurationById(inspectionmajor, inspectionMinor, orgid)
  68. if errcode == gorm.ErrRecordNotFound {
  69. standard := models.XtQualityControlStandard{
  70. InspectionMajor: inspectionmajor,
  71. InspectionMinor: inspectionMinor,
  72. MinRange: minrange,
  73. LargeRange: largerange,
  74. Sort: sorts,
  75. UserOrgId: orgid,
  76. Status: 1,
  77. CreatedTime: time.Now().Unix(),
  78. }
  79. fmt.Println(standard)
  80. err = service.SaveInspection(&standard)
  81. if err != nil {
  82. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  83. return
  84. }
  85. this.ServeSuccessJSON(map[string]interface{}{
  86. "standard": standard,
  87. })
  88. } else if errcode == nil {
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. return
  91. }
  92. }
  93. func (this *CommonApiController) GetConfigurationlist() {
  94. limit, _ := this.GetInt64("limit")
  95. page, _ := this.GetInt64("page")
  96. adminUser := this.GetAdminUserInfo()
  97. orgid := adminUser.CurrentOrgId
  98. configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page)
  99. if err != nil {
  100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  101. return
  102. }
  103. this.ServeSuccessJSON(map[string]interface{}{
  104. "configurationlist": configurationlist,
  105. "total": total,
  106. })
  107. }
  108. func (this *CommonApiController) GetConfigurationDetail() {
  109. id, _ := this.GetInt64("id")
  110. fmt.Println("id是", id)
  111. detail, err := service.GetConfigurationDetail(id)
  112. if err != nil {
  113. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  114. return
  115. }
  116. this.ServeSuccessJSON(map[string]interface{}{
  117. "configurationdetail": detail,
  118. })
  119. }
  120. func (this *CommonApiController) GetAllInspectionminor() {
  121. minor, err := service.GetAllInspectionMinor(0)
  122. if err != nil {
  123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. this.ServeSuccessJSON(map[string]interface{}{
  127. "minor": minor,
  128. })
  129. }
  130. func (this *CommonApiController) UpdateConfiguration() {
  131. id, _ := this.GetInt64("id")
  132. fmt.Println("id", id)
  133. dataBody := make(map[string]interface{}, 0)
  134. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  135. fmt.Println("err", err)
  136. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  137. fmt.Println("大项", inspectionmajor)
  138. inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
  139. fmt.Println("小项", inspectionMinor)
  140. minrange := dataBody["min_range"].(string)
  141. fmt.Println("minragne", minrange)
  142. largerange := dataBody["large_range"].(string)
  143. fmt.Println("largerange", largerange)
  144. sort := int64(dataBody["sort"].(float64))
  145. fmt.Println("排序", sort)
  146. adminInfo := this.GetAdminUserInfo()
  147. orgId := adminInfo.CurrentOrgId
  148. configuration, err := service.GetConfigurationByIdTwo(inspectionmajor, inspectionMinor, orgId)
  149. fmt.Println("err", err)
  150. if configuration.ID > 0 && configuration.ID != id {
  151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  152. return
  153. }
  154. standard := models.XtQualityControlStandard{
  155. InspectionMajor: inspectionmajor,
  156. InspectionMinor: inspectionMinor,
  157. MinRange: minrange,
  158. LargeRange: largerange,
  159. Sort: sort,
  160. }
  161. err = service.UpdarteConfiguration(&standard, id)
  162. if err != nil {
  163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  164. return
  165. }
  166. this.ServeSuccessJSON(map[string]interface{}{
  167. "standard": standard,
  168. })
  169. }
  170. func (this *CommonApiController) DeleteConfiguration() {
  171. id, _ := this.GetInt64("id")
  172. err := service.DeleteConfiguration(id)
  173. if err != nil {
  174. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  175. return
  176. }
  177. returnData := make(map[string]interface{}, 0)
  178. returnData["msg"] = "ok"
  179. this.ServeSuccessJSON(returnData)
  180. return
  181. }
  182. func (this *CommonApiController) GetAllInspectiondata() {
  183. adminUser := this.GetAdminUserInfo()
  184. orgid := adminUser.CurrentOrgId
  185. //查询该机构是否有数据
  186. _, errcode := service.GetAllInspectionData(orgid)
  187. if errcode == gorm.ErrRecordNotFound {
  188. inspection, err := service.GetAllInspectiondatatwo(0)
  189. if err != nil {
  190. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  191. return
  192. }
  193. this.ServeSuccessJSON(map[string]interface{}{
  194. "inspection": inspection,
  195. })
  196. } else if errcode == nil {
  197. inspection, err := service.GetAllInspectiondatatwo(orgid)
  198. if err != nil {
  199. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  200. return
  201. }
  202. this.ServeSuccessJSON(map[string]interface{}{
  203. "inspection": inspection,
  204. })
  205. }
  206. }
  207. func (this *CommonApiController) SaveCheckConfiguration() {
  208. dataBody := make(map[string]interface{}, 0)
  209. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  210. fmt.Println("err", err)
  211. adminUser := this.GetAdminUserInfo()
  212. orgid := adminUser.CurrentOrgId
  213. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  214. fmt.Println("大项", inspectionmajor)
  215. frequency := dataBody["frequency"].(string)
  216. fmt.Println("凭次", frequency)
  217. sort := dataBody["sort"].(string)
  218. sorts, err := strconv.ParseInt(sort, 10, 64)
  219. fmt.Println("sort", sort)
  220. _, errcode := service.GetInspectionMajorById(inspectionmajor, orgid)
  221. if errcode == gorm.ErrRecordNotFound {
  222. configuration := models.XtCheckConfiguration{
  223. InspectionMajor: inspectionmajor,
  224. InspectionFrequency: frequency,
  225. Sort: sorts,
  226. UserOrgId: orgid,
  227. Status: 1,
  228. CreatedTime: time.Now().Unix(),
  229. }
  230. err := service.CreateCheckConfiguration(&configuration)
  231. if err != nil {
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  233. return
  234. }
  235. this.ServeSuccessJSON(map[string]interface{}{
  236. "configuration": configuration,
  237. })
  238. } else if errcode == nil {
  239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  240. return
  241. }
  242. }
  243. func (this *CommonApiController) GetAllCheckList() {
  244. adminUser := this.GetAdminUserInfo()
  245. orgid := adminUser.CurrentOrgId
  246. fmt.Println("org", orgid)
  247. page, _ := this.GetInt64("page")
  248. limit, _ := this.GetInt64("limit")
  249. checkList, total, err := service.GetAllCheckList(orgid, page, limit)
  250. if err != nil {
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  252. return
  253. }
  254. this.ServeSuccessJSON(map[string]interface{}{
  255. "checklist": checkList,
  256. "total": total,
  257. })
  258. }
  259. func (this *CommonApiController) GetCheckdetail() {
  260. id, _ := this.GetInt64("id")
  261. detail, err := service.GetCheckDetail(id)
  262. if err != nil {
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  264. return
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "checkdetail": detail,
  268. })
  269. }
  270. func (this *CommonApiController) UpdateCheck() {
  271. id, _ := this.GetInt64("id")
  272. fmt.Println(id)
  273. dataBody := make(map[string]interface{}, 0)
  274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  275. fmt.Println(err)
  276. inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
  277. fmt.Println("大项", inspectionmajor)
  278. frequency := dataBody["frequency"].(string)
  279. fmt.Println("凭次", frequency)
  280. sort := int64(dataBody["sort"].(float64))
  281. fmt.Println("sort", sort)
  282. adminInfo := this.GetAdminUserInfo()
  283. orgId := adminInfo.CurrentOrgId
  284. Inspection, err := service.GetInspectionMajorByIdTwo(inspectionmajor, orgId)
  285. if Inspection.ID > 0 && Inspection.ID != id {
  286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  287. return
  288. }
  289. configuration := models.XtCheckConfiguration{
  290. InspectionMajor: inspectionmajor,
  291. InspectionFrequency: frequency,
  292. Sort: sort,
  293. }
  294. err = service.UpdateCheck(&configuration, id)
  295. if err != nil {
  296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  297. return
  298. }
  299. this.ServeSuccessJSON(map[string]interface{}{
  300. "configuration": configuration,
  301. })
  302. }
  303. func (this *CommonApiController) DeleteCheck() {
  304. id, _ := this.GetInt64("id")
  305. err := service.DeleteCheck(id)
  306. if err != nil {
  307. this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
  308. return
  309. }
  310. returnData := make(map[string]interface{}, 0)
  311. returnData["msg"] = "ok"
  312. this.ServeSuccessJSON(returnData)
  313. return
  314. }
  315. func (this *CommonApiController) GetDialysisModeType() {
  316. timeLayout := "2006-01-02"
  317. loc, _ := time.LoadLocation("Local")
  318. startime := this.GetString("startime")
  319. endtime := this.GetString("endtime")
  320. fmt.Println("endtime", endtime)
  321. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", startime+" 00:00:00", loc)
  322. startimes := startTimes.Unix()
  323. // fmt.Println("startime",startimes)
  324. endtimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", endtime+" 00:00:00", loc)
  325. endtimeData := endtimes.Unix()
  326. // fmt.Println("结束日期",endtimeData)
  327. adminUser := this.GetAdminUserInfo()
  328. orgid := adminUser.CurrentOrgId
  329. //统计透析总量
  330. _, total, _ := service.GetDialysiTotal(startimes, endtimeData, orgid)
  331. modeType, err := service.GetDialysisCountMode(startimes, endtimeData, orgid)
  332. if err != nil {
  333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  334. return
  335. }
  336. this.ServeSuccessJSON(map[string]interface{}{
  337. "total": total,
  338. "modetype": modeType,
  339. })
  340. }
  341. func (this *CommonApiController) GetTotalLapseCount() {
  342. adminUser := this.GetAdminUserInfo()
  343. orgid := adminUser.CurrentOrgId
  344. startime, _ := this.GetInt64("startime")
  345. fmt.Println("startime", startime)
  346. endtime, _ := this.GetInt64("endtime")
  347. fmt.Println("endtime", endtime)
  348. //统计一个月内转出的病人
  349. //patients, total, err := service.GetTotalRollOut(startime, endtime, orgid)
  350. //统计该机构的转出人数
  351. patients, total, err := service.GetTotalRollOutPatients(orgid)
  352. //统计总共病人
  353. // _, count, _ := service.GetPatientTotalCountTwo(orgid, startime, endtime)
  354. count := service.GetPatientTotalCount(orgid)
  355. if err != nil {
  356. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  357. return
  358. }
  359. this.ServeSuccessJSON(map[string]interface{}{
  360. "patients": patients,
  361. "total": total,
  362. "count": count,
  363. })
  364. }
  365. func (this *CommonApiController) GetTotalSexCount() {
  366. adminUser := this.GetAdminUserInfo()
  367. orgid := adminUser.CurrentOrgId
  368. fmt.Println("orgid", orgid)
  369. startime, _ := this.GetInt64("startime")
  370. fmt.Println("开始时间", startime)
  371. endtime, _ := this.GetInt64("endtime")
  372. fmt.Println("结束时间", endtime)
  373. total := service.GetPatientTotalCount(orgid)
  374. _, totalSex, err := service.GetManPatientTotal(orgid)
  375. if err != nil {
  376. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  377. return
  378. }
  379. this.ServeSuccessJSON(map[string]interface{}{
  380. "total": total,
  381. "totalSex": totalSex,
  382. })
  383. }
  384. func (this *CommonApiController) GetTotalInfectiouscount() {
  385. adminUser := this.GetAdminUserInfo()
  386. orgid := adminUser.CurrentOrgId
  387. fmt.Println("orgid", orgid)
  388. startime, _ := this.GetInt64("startime")
  389. fmt.Println("开始时间", startime)
  390. endtime, _ := this.GetInt64("endtime")
  391. fmt.Println("结束时间", endtime)
  392. //统计透析总人数
  393. total := service.GetPatientTotalCount(orgid)
  394. //统计透析人数传染病所占比例
  395. count, err := service.GetPatientInfectiousCount(orgid)
  396. //统计其他
  397. _, otherTotal, err := service.GetPatientOtherInfectious(orgid)
  398. if err != nil {
  399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  400. return
  401. }
  402. this.ServeSuccessJSON(map[string]interface{}{
  403. "total": total,
  404. "count": count,
  405. "otherTotal": otherTotal,
  406. })
  407. }
  408. func (this *CommonApiController) GetTotalAgeCount() {
  409. adminUser := this.GetAdminUserInfo()
  410. orgid := adminUser.CurrentOrgId
  411. fmt.Println("orgid", orgid)
  412. startime, _ := this.GetInt64("startime")
  413. fmt.Println("开始时间", startime)
  414. endtime, _ := this.GetInt64("endtime")
  415. fmt.Println("结束时间", endtime)
  416. //统计透析总人数
  417. total := service.GetPatientTotalCount(orgid)
  418. agecount, err := service.GetTotalAgeCount(orgid)
  419. //two, err := service.GetTotalAgeCountTwo(orgid, startime, endtime)
  420. if err != nil {
  421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  422. return
  423. }
  424. this.ServeSuccessJSON(map[string]interface{}{
  425. "total": total,
  426. "ageCount": agecount,
  427. })
  428. }
  429. func (this *CommonApiController) GetTotalDialysisCount() {
  430. adminUser := this.GetAdminUserInfo()
  431. orgid := adminUser.CurrentOrgId
  432. fmt.Println("org", orgid)
  433. startime, _ := this.GetInt64("startime")
  434. fmt.Println(startime)
  435. endtime, _ := this.GetInt64("endtime")
  436. fmt.Println(endtime)
  437. recordDateStr := time.Now().Format("2006-01-02")
  438. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  439. fmt.Println("parseDateErr", parseDateErr)
  440. nowtime := recordDate.Unix()
  441. //统计透析总人数
  442. total := service.GetPatientTotalCount(orgid)
  443. fmt.Println("total", total)
  444. //获取该机构下的所有病人数据
  445. patients, err := service.GetTotalDialysisAgeCount(orgid)
  446. fmt.Println("patients", patients)
  447. //统计透年龄
  448. dataage, _ := service.GetDialysisAgeData(orgid)
  449. if err != nil {
  450. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  451. return
  452. }
  453. this.ServeSuccessJSON(map[string]interface{}{
  454. "total": total,
  455. "patients": patients,
  456. "nowtime": nowtime,
  457. "dataage": dataage,
  458. })
  459. }
  460. func (this *CommonApiController) GetCurentOrgPatients() {
  461. adminUser := this.GetAdminUserInfo()
  462. orgid := adminUser.CurrentOrgId
  463. patients, err := service.GetCurentOrgPatients(orgid)
  464. if err != nil {
  465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  466. return
  467. }
  468. this.ServeSuccessJSON(map[string]interface{}{
  469. "patients": patients,
  470. })
  471. }
  472. func (this *CommonApiController) GetDialysislist() {
  473. startime := this.GetString("startime")
  474. fmt.Println("startime", startime)
  475. endtime := this.GetString("endtime")
  476. fmt.Println("enditme", endtime)
  477. startDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", startime)
  478. fmt.Println("parseDateErr", parseDateErr)
  479. statime := startDate.Unix()
  480. fmt.Println("开始时间", statime)
  481. endDate, _ := utils.ParseTimeStringToTime("2006-01-02", endtime)
  482. entime := endDate.Unix()
  483. fmt.Println("开始时间", statime)
  484. page, _ := this.GetInt64("page")
  485. fmt.Println("page", page)
  486. limit, _ := this.GetInt64("limit")
  487. fmt.Println("limit", limit)
  488. adminUser := this.GetAdminUserInfo()
  489. orgId := adminUser.CurrentOrgId
  490. dialysislist, total, err := service.GetDialysisList(statime, entime, page, limit, orgId)
  491. fmt.Println("err", err)
  492. if err != nil {
  493. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  494. return
  495. }
  496. this.ServeSuccessJSON(map[string]interface{}{
  497. "dialysislist": dialysislist,
  498. "total": total,
  499. })
  500. }
  501. func (this *CommonApiController) GetLastSort() {
  502. adminUser := this.GetAdminUserInfo()
  503. orgid := adminUser.CurrentOrgId
  504. standard, err := service.GetLastSort(orgid)
  505. if err != nil {
  506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  507. return
  508. }
  509. this.ServeSuccessJSON(map[string]interface{}{
  510. "standard": standard,
  511. })
  512. }
  513. func (this *CommonApiController) GetLastCheckList() {
  514. adminUser := this.GetAdminUserInfo()
  515. orgid := adminUser.CurrentOrgId
  516. checkList, err := service.GetLastCheckList(orgid)
  517. if err != nil {
  518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  519. return
  520. }
  521. this.ServeSuccessJSON(map[string]interface{}{
  522. "checkList": checkList,
  523. })
  524. }