wellness.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. var tcm = require('../../utils/tcm.js')
  2. var compliance = require('../../utils/compliance.js')
  3. Page({
  4. data: {
  5. currentUser: null,
  6. latestExam: null,
  7. latestExamSummary: '',
  8. latestExamStatusText: '',
  9. loadingUser: true,
  10. loadingLive: false
  11. },
  12. onShow: function () {
  13. this.loadPageData()
  14. },
  15. loadPageData: function () {
  16. this.loadScaleUsers()
  17. },
  18. loadScaleUsers: function () {
  19. var that = this
  20. that.setData({
  21. loadingUser: true
  22. })
  23. tcm.getScaleUsers().then(function (list) {
  24. var scaleUsers = Array.isArray(list) ? list : []
  25. var currentUser = null
  26. if (scaleUsers.length > 0) {
  27. currentUser = scaleUsers[0]
  28. for (var i = 0; i < scaleUsers.length; i++) {
  29. if (scaleUsers[i].isDefault === true || scaleUsers[i].isDefault === 1) {
  30. currentUser = scaleUsers[i]
  31. break
  32. }
  33. if (scaleUsers[i].active === true && !currentUser) {
  34. currentUser = scaleUsers[i]
  35. }
  36. }
  37. }
  38. that.setData({
  39. currentUser: currentUser,
  40. loadingUser: false
  41. })
  42. if (currentUser && currentUser.ID) {
  43. that.loadLatestExam(currentUser.ID)
  44. } else {
  45. that.setData({
  46. latestExam: null,
  47. latestExamSummary: '',
  48. latestExamStatusText: '添加成员后即可开始 AI 健康评估'
  49. })
  50. }
  51. }).catch(function () {
  52. that.setData({
  53. loadingUser: false,
  54. latestExam: null,
  55. latestExamSummary: '',
  56. latestExamStatusText: '暂未获取到康养档案'
  57. })
  58. })
  59. },
  60. loadLatestExam: function (scaleUserId) {
  61. var that = this
  62. tcm.getLatestExam(scaleUserId).then(function (data) {
  63. var exam = data && data.exam ? data.exam : null
  64. var aiSections = data && data.aiSections ? data.aiSections : {}
  65. that.setData({
  66. latestExam: exam,
  67. latestExamSummary: that.getLatestExamSummary(aiSections),
  68. latestExamStatusText: that.formatExamStatus(exam ? exam.status : '')
  69. })
  70. }).catch(function () {
  71. that.setData({
  72. latestExam: null,
  73. latestExamSummary: '',
  74. latestExamStatusText: '暂无评估报告'
  75. })
  76. })
  77. },
  78. formatExamStatus: function (status) {
  79. if (status === 'completed') {
  80. return '最新报告已生成'
  81. }
  82. if (status === 'pending' || status === 'generating') {
  83. return '最新报告生成中'
  84. }
  85. if (status === 'failed') {
  86. return '上次评估生成失败,可重新评估'
  87. }
  88. return '暂无评估报告'
  89. },
  90. getLatestExamSummary: function (aiSections) {
  91. if (!aiSections) {
  92. return ''
  93. }
  94. return compliance.sanitizeText(aiSections.summary || aiSections.general || aiSections.observation || '')
  95. },
  96. goDiagnosis: function () {
  97. wx.navigateTo({
  98. url: '/packageWellness/pages/tcm/diagnosis/diagnosis'
  99. })
  100. },
  101. goLatestReport: function () {
  102. if (!this.data.currentUser || !this.data.currentUser.ID) {
  103. wx.showToast({
  104. title: '请先添加成员',
  105. icon: 'none'
  106. })
  107. return
  108. }
  109. wx.navigateTo({
  110. url: '/packageWellness/pages/tcm/report/report?scaleUserId=' + this.data.currentUser.ID
  111. })
  112. }
  113. })