|
@@ -77,6 +77,11 @@ class TcmExam < ActiveRecord::Base
|
|
|
parsed_ai_summary["advice"] || "-"
|
|
parsed_ai_summary["advice"] || "-"
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ # 虚拟方法:望诊记录
|
|
|
|
|
+ def observation_section
|
|
|
|
|
+ parsed_ai_summary["observation"] || "-"
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
# 格式化内容,处理换行和 markdown 格式
|
|
# 格式化内容,处理换行和 markdown 格式
|
|
|
def format_content(content)
|
|
def format_content(content)
|
|
|
return "-" if content.blank?
|
|
return "-" if content.blank?
|
|
@@ -89,6 +94,51 @@ class TcmExam < ActiveRecord::Base
|
|
|
formatted
|
|
formatted
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+ # 格式化调养与建议的嵌套 JSON 结构
|
|
|
|
|
+ def format_advice(advice)
|
|
|
|
|
+ return "-" if advice.blank?
|
|
|
|
|
+
|
|
|
|
|
+ # 如果是字符串,尝试解析为 JSON
|
|
|
|
|
+ if advice.is_a?(String)
|
|
|
|
|
+ begin
|
|
|
|
|
+ advice = JSON.parse(advice)
|
|
|
|
|
+ rescue
|
|
|
|
|
+ return format_content(advice)
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ # 如果不是 Hash,直接格式化
|
|
|
|
|
+ return format_content(advice.to_s) unless advice.is_a?(Hash)
|
|
|
|
|
+
|
|
|
|
|
+ # 定义分类标签和图标
|
|
|
|
|
+ category_info = {
|
|
|
|
|
+ '饮食' => { icon: '🍵', color: '#059669' },
|
|
|
|
|
+ '运动' => { icon: '🏃', color: '#2563eb' },
|
|
|
|
|
+ '作息' => { icon: '🌙', color: '#7c3aed' },
|
|
|
|
|
+ '情志' => { icon: '💆', color: '#db2777' }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ html = ''
|
|
|
|
|
+ advice.each do |category, items|
|
|
|
|
|
+ info = category_info[category] || { icon: '📌', color: '#6b7280' }
|
|
|
|
|
+ html += %Q{<div style="margin-bottom: 16px;">}
|
|
|
|
|
+ html += %Q{<div style="font-weight: 600; color: #{info[:color]}; margin-bottom: 8px; font-size: 15px;">#{info[:icon]} #{category}</div>}
|
|
|
|
|
+ html += %Q{<ul style="margin: 0; padding-left: 20px; list-style-type: disc;">}
|
|
|
|
|
+
|
|
|
|
|
+ if items.is_a?(Array)
|
|
|
|
|
+ items.each do |item|
|
|
|
|
|
+ html += %Q{<li style="margin-bottom: 6px; line-height: 1.6;">#{format_content(item)}</li>}
|
|
|
|
|
+ end
|
|
|
|
|
+ else
|
|
|
|
|
+ html += %Q{<li style="margin-bottom: 6px; line-height: 1.6;">#{format_content(items)}</li>}
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ html += '</ul></div>'
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ html
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
rails_admin do
|
|
rails_admin do
|
|
|
navigation_label '中医诊疗记录'
|
|
navigation_label '中医诊疗记录'
|
|
|
parent ScaleDevice
|
|
parent ScaleDevice
|
|
@@ -217,8 +267,8 @@ class TcmExam < ActiveRecord::Base
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- # 望诊与闻诊
|
|
|
|
|
- field :extra_note do
|
|
|
|
|
|
|
+ # 望诊与闻诊 - 使用虚拟字段确保显示
|
|
|
|
|
+ field :observation_section do
|
|
|
label '叁 · 望诊与闻诊'
|
|
label '叁 · 望诊与闻诊'
|
|
|
pretty_value do
|
|
pretty_value do
|
|
|
exam = bindings[:object]
|
|
exam = bindings[:object]
|
|
@@ -239,14 +289,16 @@ class TcmExam < ActiveRecord::Base
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- # 调养与建议
|
|
|
|
|
- field :advice_section, :string do
|
|
|
|
|
|
|
+ # 调养与建议 - 格式化嵌套 JSON
|
|
|
|
|
+ field :advice_section do
|
|
|
label '伍 · 调养与建议'
|
|
label '伍 · 调养与建议'
|
|
|
pretty_value do
|
|
pretty_value do
|
|
|
exam = bindings[:object]
|
|
exam = bindings[:object]
|
|
|
summary = exam.parsed_ai_summary
|
|
summary = exam.parsed_ai_summary
|
|
|
- content = summary['advice'] || '-'
|
|
|
|
|
- %Q{<div style="background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 10px; padding: 14px; margin: 10px 0; line-height: 1.7;">#{exam.format_content(content)}</div>}.html_safe
|
|
|
|
|
|
|
+ advice = summary['advice']
|
|
|
|
|
+ return "-" if advice.blank?
|
|
|
|
|
+ formatted = exam.format_advice(advice)
|
|
|
|
|
+ %Q{<div style="background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 10px; padding: 14px; margin: 10px 0; line-height: 1.7;">#{formatted}</div>}.html_safe
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|