| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- var tcm = require('../../utils/tcm.js')
- var compliance = require('../../utils/compliance.js')
- Page({
- data: {
- currentUser: null,
- latestExam: null,
- latestExamSummary: '',
- latestExamStatusText: '',
- loadingUser: true,
- loadingLive: false
- },
- onShow: function () {
- this.loadPageData()
- },
- loadPageData: function () {
- this.loadScaleUsers()
- },
- loadScaleUsers: function () {
- var that = this
- that.setData({
- loadingUser: true
- })
- tcm.getScaleUsers().then(function (list) {
- var scaleUsers = Array.isArray(list) ? list : []
- var currentUser = null
- if (scaleUsers.length > 0) {
- currentUser = scaleUsers[0]
- for (var i = 0; i < scaleUsers.length; i++) {
- if (scaleUsers[i].isDefault === true || scaleUsers[i].isDefault === 1) {
- currentUser = scaleUsers[i]
- break
- }
- if (scaleUsers[i].active === true && !currentUser) {
- currentUser = scaleUsers[i]
- }
- }
- }
- that.setData({
- currentUser: currentUser,
- loadingUser: false
- })
- if (currentUser && currentUser.ID) {
- that.loadLatestExam(currentUser.ID)
- } else {
- that.setData({
- latestExam: null,
- latestExamSummary: '',
- latestExamStatusText: '添加成员后即可开始 AI 健康评估'
- })
- }
- }).catch(function () {
- that.setData({
- loadingUser: false,
- latestExam: null,
- latestExamSummary: '',
- latestExamStatusText: '暂未获取到康养档案'
- })
- })
- },
- loadLatestExam: function (scaleUserId) {
- var that = this
- tcm.getLatestExam(scaleUserId).then(function (data) {
- var exam = data && data.exam ? data.exam : null
- var aiSections = data && data.aiSections ? data.aiSections : {}
- that.setData({
- latestExam: exam,
- latestExamSummary: that.getLatestExamSummary(aiSections),
- latestExamStatusText: that.formatExamStatus(exam ? exam.status : '')
- })
- }).catch(function () {
- that.setData({
- latestExam: null,
- latestExamSummary: '',
- latestExamStatusText: '暂无评估报告'
- })
- })
- },
- formatExamStatus: function (status) {
- if (status === 'completed') {
- return '最新报告已生成'
- }
- if (status === 'pending' || status === 'generating') {
- return '最新报告生成中'
- }
- if (status === 'failed') {
- return '上次评估生成失败,可重新评估'
- }
- return '暂无评估报告'
- },
- getLatestExamSummary: function (aiSections) {
- if (!aiSections) {
- return ''
- }
- return compliance.sanitizeText(aiSections.summary || aiSections.general || aiSections.observation || '')
- },
- goDiagnosis: function () {
- wx.navigateTo({
- url: '/packageWellness/pages/tcm/diagnosis/diagnosis'
- })
- },
- goLatestReport: function () {
- if (!this.data.currentUser || !this.data.currentUser.ID) {
- wx.showToast({
- title: '请先添加成员',
- icon: 'none'
- })
- return
- }
- wx.navigateTo({
- url: '/packageWellness/pages/tcm/report/report?scaleUserId=' + this.data.currentUser.ID
- })
- }
- })
|