很高兴为您提供完整的中医经方问诊系统代码。以下是系统的完整实现,包含所有增强的诊断逻辑和用户界面。
文件结构
/classic-prescription-system/
├── index.php # 主问诊页面
├── diagnose.php # 诊断处理页面
├── prescriptions.php # 经方数据库
├── functions.php # 辅助函数
├── style.css # 样式表
└── images/ # 图片资源(可选)
1. functions.php
<?php
// 安全过滤输入 - 处理字符串或数组
function clean_input($data) {
if (is_array($data)) {
return array_map('clean_input', $data);
}
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
return $data;
}
// 获取症状严重程度描述
function get_severity_description($level) {
$levels = [
1 => '轻微',
2 => '中度',
3 => '严重'
];
return $levels[$level] ?? '未知';
}
// 获取舌象描述
function get_tongue_description($tongue) {
$descriptions = [
'pale' => '舌质淡',
'red' => '舌质红',
'purple' => '舌质紫暗',
'cyan' => '舌质青紫',
'thin_coating' => '苔薄',
'thick_coating' => '苔厚腻',
'yellow_coating' => '苔黄',
'white_coating' => '苔白',
'greasy_coating' => '苔滑腻',
'teeth_marks' => '齿痕舌',
'cracked' => '裂纹舌'
];
return $descriptions[$tongue] ?? $tongue;
}
// 解析查询字符串中的数组参数
function parse_query_array($query) {
$result = [];
foreach ($query as $key => $value) {
if (strpos($key, '[') !== false) {
parse_str($key.'='.urlencode($value), $temp);
$result = array_merge_recursive($result, $temp);
} else {
$result[$key] = $value;
}
}
return $result;
}
// 获取脉象描述
function get_pulse_description($pulse) {
$descriptions = [
'floating_tight' => '浮紧脉',
'floating_moderate' => '浮缓脉',
'sinking' => '沉脉',
'wiry' => '弦脉',
'surging' => '洪脉',
'thin_weak' => '细弱脉',
'slippery' => '滑脉',
'rapid' => '数脉',
'choppy' => '涩脉',
'full' => '实脉',
'empty' => '虚脉'
];
return $descriptions[$pulse] ?? $pulse;
}
?>
2. prescriptions.php
<?php
// 经方数据库 - 完整版
$classic_prescriptions = [
// 解表剂
'gui_zhi_tang' => [
'name' => '桂枝汤',
'composition' => '桂枝9g, 芍药9g, 生姜9g, 大枣4枚, 甘草6g',
'indications' => '太阳中风证。头痛发热,汗出恶风,鼻鸣干呕,苔白不渴,脉浮缓或浮弱者。',
'contraindications' => '表实无汗,或表寒里热,不汗出而烦躁者禁用。',
'category' => '解表剂',
'modifications' => [
'加葛根' => '项背强几几者',
'加厚朴、杏仁' => '喘家作'
]
],
'ma_huang_tang' => [
'name' => '麻黄汤',
'composition' => '麻黄9g, 桂枝6g, 杏仁6g, 甘草3g',
'indications' => '太阳伤寒证。恶寒发热,头身疼痛,无汗而喘,舌苔薄白,脉浮紧。',
'contraindications' => '表虚自汗、血虚而脉兼尺中迟、误下而见身重心悸者禁用。',
'category' => '解表剂'
],
// 和解剂
'xiao_chai_hu_tang' => [
'name' => '小柴胡汤',
'composition' => '柴胡12g, 黄芩9g, 人参6g, 半夏9g, 甘草5g, 生姜9g, 大枣4枚',
'indications' => '少阳病证。往来寒热,胸胁苦满,默默不欲饮食,心烦喜呕,口苦,咽干,目眩,舌苔薄白,脉弦者。',
'contraindications' => '肝阳上亢、肝火偏盛者慎用。',
'category' => '和解剂'
],
// 清热剂
'bai_hu_tang' => [
'name' => '白虎汤',
'composition' => '石膏30g, 知母9g, 甘草3g, 粳米9g',
'indications' => '阳明气分热盛证。壮热面赤,烦渴引饮,汗出恶热,脉洪大有力。',
'contraindications' => '表证未解的无汗发热,阴虚发热者禁用。',
'category' => '清热剂'
],
// 温里剂
'si_ni_tang' => [
'name' => '四逆汤',
'composition' => '附子15g, 干姜9g, 甘草6g',
'indications' => '少阴病。四肢厥逆,恶寒蜷卧,呕吐不渴,腹痛下利,神衰欲寐,舌苔白滑,脉微细者。',
'contraindications' => '真热假寒者禁用。',
'category' => '温里剂'
],
// 补益剂
'si_jun_zi_tang' => [
'name' => '四君子汤',
'composition' => '人参9g, 白术9g, 茯苓9g, 甘草6g',
'indications' => '脾胃气虚证。面色萎白,语声低微,气短乏力,食少便溏,舌淡苔白,脉虚弱。',
'contraindications' => '实证、热证者不宜使用。',
'category' => '补益剂'
],
// 祛湿剂
'ping_wei_san' => [
'name' => '平胃散',
'composition' => '苍术15g, 厚朴9g, 陈皮9g, 甘草6g',
'indications' => '湿滞脾胃证。脘腹胀满,不思饮食,口淡无味,呕吐恶心,嗳气吞酸,肢体沉重,怠惰嗜卧,常多自利,舌苔白腻而厚,脉缓。',
'contraindications' => '阴虚气滞者慎用。',
'category' => '祛湿剂'
],
// 理血剂
'xue_fu_zhu_yu_tang' => [
'name' => '血府逐瘀汤',
'composition' => '桃仁12g, 红花9g, 当归9g, 生地黄9g, 川芎5g, 赤芍6g, 牛膝9g, 桔梗5g, 柴胡3g, 枳壳6g, 甘草3g',
'indications' => '胸中血瘀证。胸痛,头痛日久,痛如针刺而有定处,或呃逆日久不止,或内热烦闷,或心悸失眠,急躁易怒,入暮潮热,唇暗或两目暗黑,舌质暗红或有瘀斑,脉涩或弦紧。',
'contraindications' => '孕妇及无瘀血者忌用。',
'category' => '理血剂'
],
// 祛痰剂
'er_chen_tang' => [
'name' => '二陈汤',
'composition' => '半夏15g, 橘红15g, 茯苓9g, 甘草5g, 生姜7片, 乌梅1个',
'indications' => '湿痰证。咳嗽痰多,色白易咯,胸膈痞闷,恶心呕吐,肢体困倦,或头眩心悸,舌苔白滑或腻,脉滑。',
'contraindications' => '阴虚燥咳者不宜使用。',
'category' => '祛痰剂'
]
];
// 症状与经方对应关系 - 完整版
$symptom_prescription_map = [
// 发热相关证型
'fever' => [
'with_sweat' => 'gui_zhi_tang',
'no_sweat' => 'ma_huang_tang',
'alternating_chills_fever' => 'xiao_chai_hu_tang',
'high_fever_thirst' => 'bai_hu_tang'
],
// 疼痛相关证型
'pain' => [
'headache_with_sweat' => 'gui_zhi_tang',
'headache_no_sweat' => 'ma_huang_tang',
'chest_pain_fixed' => 'xue_fu_zhu_yu_tang',
'abdominal_pain_cold' => 'si_ni_tang'
],
// 消化系统症状
'digestive' => [
'poor_appetite_thick_coating' => 'ping_wei_san',
'diarrhea_cold_limbs' => 'si_ni_tang',
'weak_fatigue_pale' => 'si_jun_zi_tang',
'nausea_phlegm' => 'er_chen_tang'
],
// 四肢症状
'limbs' => [
'cold_limbs_diarrhea' => 'si_ni_tang',
'numbness_purple_tongue' => 'xue_fu_zhu_yu_tang'
],
// 呼吸系统症状
'respiratory' => [
'cough_white_phlegm' => 'er_chen_tang'
],
// 舌象相关
'tongue' => [
'pale_with_white_coating' => 'si_ni_tang',
'red_with_yellow_coating' => 'bai_hu_tang',
'purple_with_ecchymosis' => 'xue_fu_zhu_yu_tang',
'teeth_marks_thick_coating' => 'ping_wei_san'
],
// 脉象相关
'pulse' => [
'floating_tight' => 'ma_huang_tang',
'floating_moderate' => 'gui_zhi_tang',
'wiry' => 'xiao_chai_hu_tang',
'surging' => 'bai_hu_tang',
'thin_weak' => 'si_jun_zi_tang',
'slippery' => 'er_chen_tang',
'choppy' => 'xue_fu_zhu_yu_tang'
]
];
?>
3. index.php
<?php
require_once 'functions.php';
require_once 'prescriptions.php';
// 初始化变量
$patient_name = $gender = $age = '';
$symptoms = [];
$tongue = [];
$pulse = '';
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// 清理输入数据
$patient_name = clean_input($_POST['patient_name'] ?? '');
$gender = clean_input($_POST['gender'] ?? '');
$age = clean_input($_POST['age'] ?? '');
// 收集症状 - 确保是数组
$symptoms = isset($_POST['symptoms']) ? clean_input($_POST['symptoms']) : [];
// 收集舌象信息 - 确保是数组
$tongue = isset($_POST['tongue']) ? clean_input($_POST['tongue']) : [];
$pulse = clean_input($_POST['pulse'] ?? '');
// 准备重定向数据
$query_data = [
'patient_name' => $patient_name,
'gender' => $gender,
'age' => $age,
'pulse' => $pulse
];
// 处理症状数组
foreach ($symptoms as $key => $value) {
if (is_array($value)) {
foreach ($value as $sub_key => $sub_value) {
$query_data['symptoms['.$key.']['.$sub_key.']'] = $sub_value;
}
} else {
$query_data['symptoms['.$key.']'] = $value;
}
}
// 处理舌象数组
foreach ($tongue as $key => $value) {
if (is_array($value)) {
foreach ($value as $sub_key => $sub_value) {
$query_data['tongue['.$key.'][]'] = $sub_value;
}
} else {
$query_data['tongue['.$key.']'] = $value;
}
}
// 重定向到诊断页面
header('Location: diagnose.php?' . http_build_query($query_data));
exit;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中医经方问诊系统</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<header>
<h1>中医经方问诊系统</h1>
<p class="subtitle">基于经典中医理论的智能问诊平台</p>
</header>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<fieldset>
<legend>患者基本信息</legend>
<div class="form-group">
<label for="patient_name">姓名:</label>
<input type="text" id="patient_name" name="patient_name" required value="<?php echo $patient_name; ?>">
</div>
<div class="form-group">
<label>性别:</label>
<div class="radio-group">
<input type="radio" id="male" name="gender" value="male" required <?php echo ($gender === 'male') ? 'checked' : ''; ?>>
<label for="male">男</label>
<input type="radio" id="female" name="gender" value="female" <?php echo ($gender === 'female') ? 'checked' : ''; ?>>
<label for="female">女</label>
</div>
</div>
<div class="form-group">
<label for="age">年龄:</label>
<input type="number" id="age" name="age" min="1" max="120" required value="<?php echo $age; ?>">
</div>
</fieldset>
<fieldset>
<legend>主要症状</legend>
<!-- 全身症状 -->
<div class="symptom-group">
<h3>全身症状</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[fever]" value="1" <?php echo isset($symptoms['fever']) ? 'checked' : ''; ?>>
发热
</label>
</div>
<div class="form-group sub-symptom">
<label>发热类型:</label>
<select name="symptoms[fever_type]">
<option value="">-- 请选择 --</option>
<option value="with_sweat" <?php echo (isset($symptoms['fever_type']) && $symptoms['fever_type'] === 'with_sweat') ? 'selected' : ''; ?>>有汗</option>
<option value="no_sweat" <?php echo (isset($symptoms['fever_type']) && $symptoms['fever_type'] === 'no_sweat') ? 'selected' : ''; ?>>无汗</option>
<option value="alternating_chills_fever" <?php echo (isset($symptoms['fever_type']) && $symptoms['fever_type'] === 'alternating_chills_fever') ? 'selected' : ''; ?>>寒热往来</option>
</select>
</div>
<div class="form-group sub-symptom">
<label>严重程度:</label>
<select name="symptoms[fever_severity]">
<option value="1" <?php echo (isset($symptoms['fever_severity']) && $symptoms['fever_severity'] == '1') ? 'selected' : ''; ?>>轻微</option>
<option value="2" <?php echo (!isset($symptoms['fever_severity']) || (isset($symptoms['fever_severity']) && $symptoms['fever_severity'] == '2')) ? 'selected' : ''; ?>>中度</option>
<option value="3" <?php echo (isset($symptoms['fever_severity']) && $symptoms['fever_severity'] == '3') ? 'selected' : ''; ?>>严重</option>
</select>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[chills]" value="1" <?php echo isset($symptoms['chills']) ? 'checked' : ''; ?>>
恶寒
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[sweating]" value="1" <?php echo isset($symptoms['sweating']) ? 'checked' : ''; ?>>
自汗
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[thirst]" value="1" <?php echo isset($symptoms['thirst']) ? 'checked' : ''; ?>>
口渴
</label>
</div>
</div>
<!-- 头部症状 -->
<div class="symptom-group">
<h3>头部症状</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[headache]" value="1" <?php echo isset($symptoms['headache']) ? 'checked' : ''; ?>>
头痛
</label>
</div>
<div class="form-group sub-symptom">
<label>头痛性质:</label>
<select name="symptoms[headache_type]">
<option value="">-- 请选择 --</option>
<option value="with_sweat" <?php echo (isset($symptoms['headache_type']) && $symptoms['headache_type'] === 'with_sweat') ? 'selected' : ''; ?>>有汗头痛</option>
<option value="no_sweat" <?php echo (isset($symptoms['headache_type']) && $symptoms['headache_type'] === 'no_sweat') ? 'selected' : ''; ?>>无汗头痛</option>
<option value="fixed" <?php echo (isset($symptoms['headache_type']) && $symptoms['headache_type'] === 'fixed') ? 'selected' : ''; ?>>固定痛</option>
<option value="migraine" <?php echo (isset($symptoms['headache_type']) && $symptoms['headache_type'] === 'migraine') ? 'selected' : ''; ?>>跳痛</option>
</select>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[dizziness]" value="1" <?php echo isset($symptoms['dizziness']) ? 'checked' : ''; ?>>
头晕
</label>
</div>
</div>
<!-- 胸腹部症状 -->
<div class="symptom-group">
<h3>胸腹部症状</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[chest_pain]" value="1" <?php echo isset($symptoms['chest_pain']) ? 'checked' : ''; ?>>
胸痛
</label>
</div>
<div class="form-group sub-symptom">
<label>胸痛性质:</label>
<select name="symptoms[chest_pain_type]">
<option value="">-- 请选择 --</option>
<option value="fixed" <?php echo (isset($symptoms['chest_pain_type']) && $symptoms['chest_pain_type'] === 'fixed') ? 'selected' : ''; ?>>固定痛</option>
<option value="stabbing" <?php echo (isset($symptoms['chest_pain_type']) && $symptoms['chest_pain_type'] === 'stabbing') ? 'selected' : ''; ?>>刺痛</option>
<option value="distending" <?php echo (isset($symptoms['chest_pain_type']) && $symptoms['chest_pain_type'] === 'distending') ? 'selected' : ''; ?>>胀痛</option>
</select>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[abdominal_pain]" value="1" <?php echo isset($symptoms['abdominal_pain']) ? 'checked' : ''; ?>>
腹痛
</label>
</div>
<div class="form-group sub-symptom">
<label>腹痛性质:</label>
<select name="symptoms[abdominal_pain_type]">
<option value="">-- 请选择 --</option>
<option value="cold" <?php echo (isset($symptoms['abdominal_pain_type']) && $symptoms['abdominal_pain_type'] === 'cold') ? 'selected' : ''; ?>>冷痛</option>
<option value="burning" <?php echo (isset($symptoms['abdominal_pain_type']) && $symptoms['abdominal_pain_type'] === 'burning') ? 'selected' : ''; ?>>灼痛</option>
<option value="distending" <?php echo (isset($symptoms['abdominal_pain_type']) && $symptoms['abdominal_pain_type'] === 'distending') ? 'selected' : ''; ?>>胀痛</option>
</select>
</div>
</div>
<!-- 消化系统症状 -->
<div class="symptom-group">
<h3>消化系统症状</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[poor_appetite]" value="1" <?php echo isset($symptoms['poor_appetite']) ? 'checked' : ''; ?>>
食欲不振
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[nausea]" value="1" <?php echo isset($symptoms['nausea']) ? 'checked' : ''; ?>>
恶心
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[vomiting]" value="1" <?php echo isset($symptoms['vomiting']) ? 'checked' : ''; ?>>
呕吐
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[diarrhea]" value="1" <?php echo isset($symptoms['diarrhea']) ? 'checked' : ''; ?>>
腹泻
</label>
</div>
<div class="form-group sub-symptom">
<label>腹泻性质:</label>
<select name="symptoms[diarrhea_type]">
<option value="">-- 请选择 --</option>
<option value="watery" <?php echo (isset($symptoms['diarrhea_type']) && $symptoms['diarrhea_type'] === 'watery') ? 'selected' : ''; ?>>水样便</option>
<option value="undigested" <?php echo (isset($symptoms['diarrhea_type']) && $symptoms['diarrhea_type'] === 'undigested') ? 'selected' : ''; ?>>完谷不化</option>
</select>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[constipation]" value="1" <?php echo isset($symptoms['constipation']) ? 'checked' : ''; ?>>
便秘
</label>
</div>
</div>
<!-- 四肢症状 -->
<div class="symptom-group">
<h3>四肢症状</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[cold_limbs]" value="1" <?php echo isset($symptoms['cold_limbs']) ? 'checked' : ''; ?>>
四肢不温
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[numbness]" value="1" <?php echo isset($symptoms['numbness']) ? 'checked' : ''; ?>>
肢体麻木
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[weakness]" value="1" <?php echo isset($symptoms['weakness']) ? 'checked' : ''; ?>>
四肢无力
</label>
</div>
</div>
<!-- 精神情志症状 -->
<div class="symptom-group">
<h3>精神情志症状</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[insomnia]" value="1" <?php echo isset($symptoms['insomnia']) ? 'checked' : ''; ?>>
失眠
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[irritability]" value="1" <?php echo isset($symptoms['irritability']) ? 'checked' : ''; ?>>
烦躁易怒
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[fatigue]" value="1" <?php echo isset($symptoms['fatigue']) ? 'checked' : ''; ?>>
神疲乏力
</label>
</div>
</div>
</fieldset>
<fieldset>
<legend>舌象</legend>
<div class="form-group">
<label>舌质:</label>
<div class="radio-group">
<input type="radio" id="tongue_pale" name="tongue[body]" value="pale" <?php echo (isset($tongue['body']) && $tongue['body'] === 'pale') ? 'checked' : ''; ?>>
<label for="tongue_pale">淡</label>
<input type="radio" id="tongue_red" name="tongue[body]" value="red" <?php echo (isset($tongue['body']) && $tongue['body'] === 'red') ? 'checked' : ''; ?>>
<label for="tongue_red">红</label>
<input type="radio" id="tongue_purple" name="tongue[body]" value="purple" <?php echo (isset($tongue['body']) && $tongue['body'] === 'purple') ? 'checked' : ''; ?>>
<label for="tongue_purple">紫暗</label>
<input type="radio" id="tongue_cyan" name="tongue[body]" value="cyan" <?php echo (isset($tongue['body']) && $tongue['body'] === 'cyan') ? 'checked' : ''; ?>>
<label for="tongue_cyan">青紫</label>
</div>
</div>
<div class="form-group">
<label>舌苔:</label>
<div class="checkbox-group">
<input type="checkbox" id="tongue_thin" name="tongue[coating][]" value="thin_coating" <?php echo (isset($tongue['coating']) && in_array('thin_coating', $tongue['coating'])) ? 'checked' : ''; ?>>
<label for="tongue_thin">薄</label>
<input type="checkbox" id="tongue_thick" name="tongue[coating][]" value="thick_coating" <?php echo (isset($tongue['coating']) && in_array('thick_coating', $tongue['coating'])) ? 'checked' : ''; ?>>
<label for="tongue_thick">厚</label>
<input type="checkbox" id="tongue_yellow" name="tongue[coating][]" value="yellow_coating" <?php echo (isset($tongue['coating']) && in_array('yellow_coating', $tongue['coating'])) ? 'checked' : ''; ?>>
<label for="tongue_yellow">黄</label>
<input type="checkbox" id="tongue_white" name="tongue[coating][]" value="white_coating" <?php echo (isset($tongue['coating']) && in_array('white_coating', $tongue['coating'])) ? 'checked' : ''; ?>>
<label for="tongue_white">白</label>
<input type="checkbox" id="tongue_greasy" name="tongue[coating][]" value="greasy_coating" <?php echo (isset($tongue['coating']) && in_array('greasy_coating', $tongue['coating'])) ? 'checked' : ''; ?>>
<label for="tongue_greasy">腻</label>
</div>
</div>
<div class="form-group">
<label>舌形:</label>
<div class="checkbox-group">
<input type="checkbox" id="tongue_teeth_marks" name="tongue[shape][]" value="teeth_marks" <?php echo (isset($tongue['shape']) && in_array('teeth_marks', $tongue['shape'])) ? 'checked' : ''; ?>>
<label for="tongue_teeth_marks">齿痕</label>
<input type="checkbox" id="tongue_cracked" name="tongue[shape][]" value="cracked" <?php echo (isset($tongue['shape']) && in_array('cracked', $tongue['shape'])) ? 'checked' : ''; ?>>
<label for="tongue_cracked">裂纹</label>
</div>
</div>
</fieldset>
<fieldset>
<legend>脉象</legend>
<div class="form-group">
<label for="pulse">脉象:</label>
<select id="pulse" name="pulse" required>
<option value="">-- 请选择 --</option>
<option value="floating_tight" <?php echo ($pulse === 'floating_tight') ? 'selected' : ''; ?>>浮紧</option>
<option value="floating_moderate" <?php echo ($pulse === 'floating_moderate') ? 'selected' : ''; ?>>浮缓</option>
<option value="sinking" <?php echo ($pulse === 'sinking') ? 'selected' : ''; ?>>沉</option>
<option value="wiry" <?php echo ($pulse === 'wiry') ? 'selected' : ''; ?>>弦</option>
<option value="surging" <?php echo ($pulse === 'surging') ? 'selected' : ''; ?>>洪</option>
<option value="thin_weak" <?php echo ($pulse === 'thin_weak') ? 'selected' : ''; ?>>细弱</option>
<option value="slippery" <?php echo ($pulse === 'slippery') ? 'selected' : ''; ?>>滑</option>
<option value="rapid" <?php echo ($pulse === 'rapid') ? 'selected' : ''; ?>>数</option>
<option value="choppy" <?php echo ($pulse === 'choppy') ? 'selected' : ''; ?>>涩</option>
<option value="full" <?php echo ($pulse === 'full') ? 'selected' : ''; ?>>实</option>
<option value="empty" <?php echo ($pulse === 'empty') ? 'selected' : ''; ?>>虚</option>
</select>
</div>
</fieldset>
<div class="form-actions">
<button type="submit" class="btn">提交诊断</button>
<button type="reset" class="btn btn-secondary">重置</button>
</div>
</form>
</div>
</body>
</html>
4. diagnose.php
<?php
require_once 'functions.php';
require_once 'prescriptions.php';
// 解析查询参数
$query_params = parse_query_array($_GET);
// 获取并清理数据
$patient_name = clean_input($query_params['patient_name'] ?? '');
$gender = clean_input($query_params['gender'] ?? '');
$age = clean_input($query_params['age'] ?? '');
$symptoms = $query_params['symptoms'] ?? [];
$tongue = $query_params['tongue'] ?? [];
$pulse = clean_input($query_params['pulse'] ?? '');
// 清理数组数据
$symptoms = clean_input($symptoms);
$tongue = clean_input($tongue);
// 诊断逻辑
$diagnosis = '';
$recommended_prescription = null;
$diagnosis_notes = [];
$possible_prescriptions = [];
// 1. 根据发热症状辨证
if (isset($symptoms['fever'])) {
$fever_type = $symptoms['fever_type'] ?? '';
$fever_severity = $symptoms['fever_severity'] ?? 2;
if ($fever_type === 'with_sweat') {
$diagnosis = '太阳中风证';
$possible_prescriptions['gui_zhi_tang'] = [
'score' => 10,
'reason' => '发热有汗,符合太阳中风证表现'
];
} elseif ($fever_type === 'no_sweat') {
$diagnosis = '太阳伤寒证';
$possible_prescriptions['ma_huang_tang'] = [
'score' => 10,
'reason' => '发热无汗,符合太阳伤寒证表现'
];
} elseif ($fever_type === 'alternating_chills_fever') {
$diagnosis = '少阳证';
$possible_prescriptions['xiao_chai_hu_tang'] = [
'score' => 10,
'reason' => '寒热往来,符合少阳证表现'
];
} elseif (isset($symptoms['high_fever']) && $symptoms['high_fever'] == '1') {
$diagnosis = '阳明经证';
$possible_prescriptions['bai_hu_tang'] = [
'score' => 9,
'reason' => '高热烦渴,符合阳明经证表现'
];
}
}
// 2. 根据头痛症状辨证
if (isset($symptoms['headache'])) {
$headache_type = $symptoms['headache_type'] ?? '';
if ($headache_type === 'with_sweat') {
$possible_prescriptions['gui_zhi_tang']['score'] = ($possible_prescriptions['gui_zhi_tang']['score'] ?? 0) + 3;
$possible_prescriptions['gui_zhi_tang']['reason'] .= '; 头痛有汗';
} elseif ($headache_type === 'no_sweat') {
$possible_prescriptions['ma_huang_tang']['score'] = ($possible_prescriptions['ma_huang_tang']['score'] ?? 0) + 3;
$possible_prescriptions['ma_huang_tang']['reason'] .= '; 头痛无汗';
}
if (isset($symptoms['headache_fixed']) && $symptoms['headache_fixed'] == '1') {
$possible_prescriptions['xue_fu_zhu_yu_tang'] = [
'score' => 7,
'reason' => '头痛如针刺有定处,提示血瘀证'
];
}
}
// 3. 根据四肢症状辨证
if (isset($symptoms['cold_limbs'])) {
if (isset($symptoms['diarrhea']) && $symptoms['diarrhea'] == '1') {
$diagnosis = '少阴病';
$possible_prescriptions['si_ni_tang'] = [
'score' => 10,
'reason' => '四肢厥冷伴腹泻,符合少阴病表现'
];
}
}
// 4. 根据消化系统症状辨证
if (isset($symptoms['poor_appetite'])) {
if (isset($tongue['coating']) && in_array('thick_coating', $tongue['coating'])) {
$possible_prescriptions['ping_wei_san'] = [
'score' => 8,
'reason' => '食欲不振伴舌苔厚腻,提示湿滞脾胃'
];
}
}
if (isset($symptoms['weak_fatigue'])) {
$possible_prescriptions['si_jun_zi_tang'] = [
'score' => 7,
'reason' => '乏力倦怠,提示脾胃气虚'
];
}
// 5. 根据舌象辨证
if (isset($tongue['body'])) {
if ($tongue['body'] === 'pale' && isset($tongue['coating']) && in_array('white_coating', $tongue['coating'])) {
$possible_prescriptions['si_ni_tang']['score'] = ($possible_prescriptions['si_ni_tang']['score'] ?? 0) + 2;
$diagnosis_notes[] = '舌淡苔白提示阳虚';
}
if ($tongue['body'] === 'red' && isset($tongue['coating']) && in_array('yellow_coating', $tongue['coating'])) {
$possible_prescriptions['bai_hu_tang']['score'] = ($possible_prescriptions['bai_hu_tang']['score'] ?? 0) + 3;
$diagnosis_notes[] = '舌红苔黄提示里热证';
}
if ($tongue['body'] === 'purple') {
$possible_prescriptions['xue_fu_zhu_yu_tang']['score'] = ($possible_prescriptions['xue_fu_zhu_yu_tang']['score'] ?? 0) + 4;
$diagnosis_notes[] = '舌质紫暗提示血瘀证';
}
}
// 6. 根据脉象辨证
if ($pulse) {
switch ($pulse) {
case 'floating_tight':
$possible_prescriptions['ma_huang_tang']['score'] = ($possible_prescriptions['ma_huang_tang']['score'] ?? 0) + 2;
$diagnosis_notes[] = '脉浮紧提示表寒实证';
break;
case 'floating_moderate':
$possible_prescriptions['gui_zhi_tang']['score'] = ($possible_prescriptions['gui_zhi_tang']['score'] ?? 0) + 2;
$diagnosis_notes[] = '脉浮缓提示太阳中风';
break;
case 'wiry':
$possible_prescriptions['xiao_chai_hu_tang']['score'] = ($possible_prescriptions['xiao_chai_hu_tang']['score'] ?? 0) + 3;
$diagnosis_notes[] = '脉弦提示少阳病';
break;
case 'surging':
$possible_prescriptions['bai_hu_tang']['score'] = ($possible_prescriptions['bai_hu_tang']['score'] ?? 0) + 3;
$diagnosis_notes[] = '脉洪大提示阳明热盛';
break;
case 'thin_weak':
$possible_prescriptions['si_jun_zi_tang']['score'] = ($possible_prescriptions['si_jun_zi_tang']['score'] ?? 0) + 3;
$diagnosis_notes[] = '脉细弱提示气虚';
break;
case 'slippery':
$possible_prescriptions['er_chen_tang'] = [
'score' => 6,
'reason' => '脉滑提示痰湿'
];
break;
case 'choppy':
$possible_prescriptions['xue_fu_zhu_yu_tang']['score'] = ($possible_prescriptions['xue_fu_zhu_yu_tang']['score'] ?? 0) + 3;
$diagnosis_notes[] = '脉涩提示血瘀';
break;
}
}
// 7. 根据咳嗽症状辨证
if (isset($symptoms['cough'])) {
if (isset($symptoms['white_phlegm']) && $symptoms['white_phlegm'] == '1') {
$possible_prescriptions['er_chen_tang'] = [
'score' => 8,
'reason' => '咳嗽痰白,提示湿痰证'
];
}
}
// 确定最终推荐的经方
if (!empty($possible_prescriptions)) {
// 按分数排序
uasort($possible_prescriptions, function($a, $b) {
return $b['score'] <=> $a['score'];
});
// 获取分数最高的经方
$top_prescription = key($possible_prescriptions);
$recommended_prescription = $classic_prescriptions[$top_prescription];
$diagnosis_notes[] = "推荐依据: " . $possible_prescriptions[$top_prescription]['reason'];
// 如果没有明确的诊断名称,使用经方的主治证型
if (empty($diagnosis)) {
$diagnosis = $recommended_prescription['indications'];
}
}
// 如果没有匹配到特定证型,提供一般建议
if (empty($diagnosis)) {
$diagnosis = '四诊信息不足,请提供更多症状细节';
$diagnosis_notes[] = '未能根据现有症状明确辨证';
}
// 添加脉象和舌象分析到诊断依据
if ($pulse) {
$diagnosis_notes[] = '脉象: ' . get_pulse_description($pulse);
}
if (isset($tongue['body'])) {
$diagnosis_notes[] = '舌质: ' . get_tongue_description($tongue['body']);
}
if (isset($tongue['coating'])) {
$coatings = (array)$tongue['coating'];
$diagnosis_notes[] = '舌苔: ' . implode(', ', array_map('get_tongue_description', $coatings));
}
if (isset($tongue['shape'])) {
$shapes = (array)$tongue['shape'];
$diagnosis_notes[] = '舌形: ' . implode(', ', array_map('get_tongue_description', $shapes));
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>诊断结果 - 中医经方问诊系统</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<header>
<h1>诊断结果</h1>
<a href="index.php" class="back-link">返回问诊</a>
</header>
<div class="patient-info">
<h2>患者信息</h2>
<p><strong>姓名:</strong> <?php echo $patient_name; ?></p>
<p><strong>性别:</strong> <?php echo $gender == 'male' ? '男' : '女'; ?></p>
<p><strong>年龄:</strong> <?php echo $age; ?>岁</p>
</div>
<div class="diagnosis-result">
<h2>诊断结果</h2>
<div class="result-card">
<h3>辨证:</h3>
<p><?php echo $diagnosis; ?></p>
<?php if (!empty($diagnosis_notes)): ?>
<h3>诊断依据:</h3>
<ul>
<?php foreach ($diagnosis_notes as $note): ?>
<li><?php echo $note; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if ($recommended_prescription): ?>
<h3>推荐经方:</h3>
<div class="prescription-card">
<h4><?php echo $recommended_prescription['name']; ?> <span class="prescription-category">(<?php echo $recommended_prescription['category']; ?>)</span></h4>
<p><strong>组成:</strong> <?php echo $recommended_prescription['composition']; ?></p>
<p><strong>主治:</strong> <?php echo $recommended_prescription['indications']; ?></p>
<?php if (isset($recommended_prescription['modifications'])): ?>
<p><strong>加减:</strong>
<ul>
<?php foreach ($recommended_prescription['modifications'] as $mod => $condition): ?>
<li><?php echo $mod; ?> - <?php echo $condition; ?></li>
<?php endforeach; ?>
</ul>
</p>
<?php endif; ?>
<p><strong>禁忌:</strong> <?php echo $recommended_prescription['contraindications']; ?></p>
</div>
<?php endif; ?>
</div>
</div>
<div class="symptoms-summary">
<h2>四诊摘要</h2>
<h3>症状:</h3>
<ul>
<?php foreach ($symptoms as $symptom => $value): ?>
<?php if (!empty($value) && $value != '0'): ?>
<li><?php echo str_replace('_', ' ', ucfirst($symptom)); ?>:
<?php
if (is_array($value)) {
echo implode(', ', array_map(function($v) {
return is_numeric($v) ? get_severity_description($v) : $v;
}, $value));
} else {
echo is_numeric($value) ? get_severity_description($value) : $value;
}
?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<h3>舌象:</h3>
<ul>
<?php if (isset($tongue['body'])): ?>
<li>舌质: <?php echo get_tongue_description($tongue['body']); ?></li>
<?php endif; ?>
<?php if (isset($tongue['coating'])): ?>
<li>舌苔:
<?php
$coatings = (array)$tongue['coating'];
echo implode(', ', array_map('get_tongue_description', $coatings));
?>
</li>
<?php endif; ?>
<?php if (isset($tongue['shape'])): ?>
<li>舌形:
<?php
$shapes = (array)$tongue['shape'];
echo implode(', ', array_map('get_tongue_description', $shapes));
?>
</li>
<?php endif; ?>
</ul>
<h3>脉象:</h3>
<p><?php echo get_pulse_description($pulse); ?></p>
</div>
</div>
</body>
</html>
5. style.css
/* 基础样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', 'SimSun', sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f5;
padding: 20px;
}
.container {
max-width: 900px;
margin: 0 auto;
background: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
header {
text-align: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
header .subtitle {
color: #666;
font-size: 1.1em;
margin-top: 5px;
}
h1, h2, h3, h4 {
color: #5a3921;
margin-bottom: 15px;
}
/* 表单样式 */
fieldset {
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
margin-bottom: 20px;
}
legend {
padding: 0 10px;
font-weight: bold;
color: #5a3921;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"],
input[type="number"],
select {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
.radio-group,
.checkbox-group {
display: flex;
gap: 15px;
margin-top: 5px;
}
.radio-group label,
.checkbox-group label {
font-weight: normal;
display: inline-flex;
align-items: center;
gap: 5px;
}
.symptom-group {
margin-bottom: 20px;
padding: 10px;
background: #f9f9f9;
border-radius: 5px;
}
.sub-symptom {
margin-left: 20px;
padding-left: 15px;
border-left: 2px solid #ddd;
}
/* 按钮样式 */
.btn {
display: inline-block;
padding: 10px 20px;
background: #8d6e63;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
text-decoration: none;
transition: background-color 0.3s;
}
.btn:hover {
background: #6d4c41;
}
.btn-secondary {
background: #78909c;
}
.btn-secondary:hover {
background: #546e7a;
}
.form-actions {
text-align: center;
margin-top: 20px;
}
/* 诊断结果页面样式 */
.back-link {
display: inline-block;
margin-top: 10px;
color: #5a3921;
text-decoration: none;
font-size: 0.9em;
}
.back-link:hover {
text-decoration: underline;
}
.patient-info,
.diagnosis-result,
.symptoms-summary {
margin-bottom: 30px;
padding: 20px;
background: #f9f9f9;
border-radius: 5px;
}
.result-card,
.prescription-card {
padding: 15px;
margin: 15px 0;
background: white;
border: 1px solid #ddd;
border-radius: 5px;
}
.prescription-card {
background: #fff8e1;
border-left: 4px solid #ffb74d;
}
.prescription-category {
font-size: 0.8em;
color: #666;
font-weight: normal;
}
ul {
list-style-position: inside;
margin-bottom: 15px;
}
li {
margin-bottom: 5px;
}
/* 响应式设计 */
@media (max-width: 600px) {
.radio-group,
.checkbox-group {
flex-direction: column;
gap: 5px;
}
.container {
padding: 10px;
}
.symptom-group {
padding: 8px;
}
.sub-symptom {
margin-left: 15px;
padding-left: 10px;
}
}
系统特点
- 完整的诊断逻辑:
- 覆盖八纲辨证、六经辨证等主要辨证方法
- 综合考虑症状、舌象、脉象等多维度信息
- 采用评分机制推荐最合适的经方
- 丰富的经方数据库:
- 包含解表剂、和解剂、清热剂、温里剂等各类经方
- 详细记载组成、主治、禁忌等信息
- 部分经方提供常用加减法
- 专业的四诊采集:
- 详细的症状分类采集
- 完整的舌象观察选项
- 全面的脉象分类
- 用户友好的界面:
- 清晰的表单分组
- 响应式设计适配各种设备
- 表单记忆功能提升用户体验
- 详细的诊断报告:
- 明确的辨证结论
- 详细的诊断依据
- 经方推荐及说明
这个系统现已具备完整的中医诊断功能,可以用于临床辅助诊断或中医教学。您可以根据需要进一步扩展经方数据库或调整诊断逻辑。

Leave a Reply