下面是一个基于中医经方理论构建的简易问诊系统,使用纯PHP开发,不依赖Bootstrap或jQuery,仅使用原生HTML、CSS和PHP。
系统架构
/classic-prescription-system/
├── index.php # 主问诊页面
├── diagnose.php # 诊断处理页面
├── prescriptions.php # 经方数据库
├── functions.php # 辅助函数
├── style.css # 样式表
└── images/ # 图片资源
完整代码实现
1. functions.php – 辅助函数
<?php
// 安全过滤输入
function clean_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// 获取症状严重程度描述
function get_severity_description($level) {
$levels = [
1 => '轻微',
2 => '中度',
3 => '严重'
];
return $levels[$level] ?? '未知';
}
// 获取舌象描述
function get_tongue_description($tongue) {
$descriptions = [
'pale' => '舌质淡',
'red' => '舌质红',
'purple' => '舌质紫暗',
'thin_coating' => '苔薄',
'thick_coating' => '苔厚腻',
'yellow_coating' => '苔黄',
'white_coating' => '苔白'
];
return $descriptions[$tongue] ?? $tongue;
}
?>
2. prescriptions.php – 经方数据库
<?php
// 经方数据库
$classic_prescriptions = [
'gui_zhi_tang' => [
'name' => '桂枝汤',
'composition' => '桂枝9g, 芍药9g, 生姜9g, 大枣4枚, 甘草6g',
'indications' => '太阳中风证。头痛发热,汗出恶风,鼻鸣干呕,苔白不渴,脉浮缓或浮弱者。',
'contraindications' => '表实无汗,或表寒里热,不汗出而烦躁者禁用。'
],
'ma_huang_tang' => [
'name' => '麻黄汤',
'composition' => '麻黄9g, 桂枝6g, 杏仁6g, 甘草3g',
'indications' => '太阳伤寒证。恶寒发热,头身疼痛,无汗而喘,舌苔薄白,脉浮紧。',
'contraindications' => '表虚自汗、血虚而脉兼尺中迟、误下而见身重心悸者禁用。'
],
'xiao_chai_hu_tang' => [
'name' => '小柴胡汤',
'composition' => '柴胡12g, 黄芩9g, 人参6g, 半夏9g, 甘草5g, 生姜9g, 大枣4枚',
'indications' => '少阳病证。往来寒热,胸胁苦满,默默不欲饮食,心烦喜呕,口苦,咽干,目眩,舌苔薄白,脉弦者。',
'contraindications' => '肝阳上亢、肝火偏盛者慎用。'
],
// 可继续添加更多经方...
];
// 症状与经方对应关系
$symptom_prescription_map = [
'fever' => [
'with_sweat' => 'gui_zhi_tang',
'no_sweat' => 'ma_huang_tang',
'alternating_chills_fever' => 'xiao_chai_hu_tang'
],
'headache' => [
'with_sweat' => 'gui_zhi_tang',
'no_sweat' => 'ma_huang_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']);
// 收集症状
if (isset($_POST['symptoms'])) {
foreach ($_POST['symptoms'] as $symptom => $value) {
$symptoms[$symptom] = clean_input($value);
}
}
// 收集舌象信息
if (isset($_POST['tongue'])) {
foreach ($_POST['tongue'] as $tongue_feature => $value) {
$tongue[$tongue_feature] = clean_input($value);
}
}
$pulse = clean_input($_POST['pulse']);
// 重定向到诊断页面
header('Location: diagnose.php?' . http_build_query([
'patient_name' => $patient_name,
'gender' => $gender,
'age' => $age,
'symptoms' => $symptoms,
'tongue' => $tongue,
'pulse' => $pulse
]));
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>
</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>
</div>
<div class="form-group">
<label>性别:</label>
<div class="radio-group">
<input type="radio" id="male" name="gender" value="male" required>
<label for="male">男</label>
<input type="radio" id="female" name="gender" value="female">
<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>
</div>
</fieldset>
<fieldset>
<legend>主要症状</legend>
<div class="symptom-group">
<h3>发热</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[fever]" value="1">
有发热
</label>
</div>
<div class="form-group sub-symptom">
<label>伴随症状:</label>
<select name="symptoms[fever_type]">
<option value="">-- 请选择 --</option>
<option value="with_sweat">有汗</option>
<option value="no_sweat">无汗</option>
<option value="alternating_chills_fever">寒热往来</option>
</select>
</div>
<div class="form-group sub-symptom">
<label>严重程度:</label>
<select name="symptoms[fever_severity]">
<option value="1">轻微</option>
<option value="2" selected>中度</option>
<option value="3">严重</option>
</select>
</div>
</div>
<div class="symptom-group">
<h3>头痛</h3>
<div class="form-group">
<label>
<input type="checkbox" name="symptoms[headache]" value="1">
有头痛
</label>
</div>
<div class="form-group sub-symptom">
<label>伴随症状:</label>
<select name="symptoms[headache_type]">
<option value="">-- 请选择 --</option>
<option value="with_sweat">有汗</option>
<option value="no_sweat">无汗</option>
</select>
</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">
<label for="tongue_pale">淡</label>
<input type="radio" id="tongue_red" name="tongue[body]" value="red">
<label for="tongue_red">红</label>
<input type="radio" id="tongue_purple" name="tongue[body]" value="purple">
<label for="tongue_purple">紫暗</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">
<label for="tongue_thin">薄</label>
<input type="checkbox" id="tongue_thick" name="tongue[coating][]" value="thick_coating">
<label for="tongue_thick">厚腻</label>
<input type="checkbox" id="tongue_yellow" name="tongue[coating][]" value="yellow_coating">
<label for="tongue_yellow">黄</label>
<input type="checkbox" id="tongue_white" name="tongue[coating][]" value="white_coating">
<label for="tongue_white">白</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">浮</option>
<option value="sinking">沉</option>
<option value="slow">迟</option>
<option value="rapid">数</option>
<option value="slippery">滑</option>
<option value="wiry">弦</option>
<option value="fine">细</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';
// 获取问诊数据
$patient_name = clean_input($_GET['patient_name'] ?? '');
$gender = clean_input($_GET['gender'] ?? '');
$age = clean_input($_GET['age'] ?? '');
$symptoms = $_GET['symptoms'] ?? [];
$tongue = $_GET['tongue'] ?? [];
$pulse = clean_input($_GET['pulse'] ?? '');
// 诊断逻辑
$diagnosis = '';
$recommended_prescription = null;
// 简单诊断逻辑示例
if (isset($symptoms['fever']) && $symptoms['fever'] == '1') {
if (isset($symptoms['fever_type'])) {
switch ($symptoms['fever_type']) {
case 'with_sweat':
$diagnosis = '太阳中风证';
$recommended_prescription = $classic_prescriptions['gui_zhi_tang'];
break;
case 'no_sweat':
$diagnosis = '太阳伤寒证';
$recommended_prescription = $classic_prescriptions['ma_huang_tang'];
break;
case 'alternating_chills_fever':
$diagnosis = '少阳证';
$recommended_prescription = $classic_prescriptions['xiao_chai_hu_tang'];
break;
}
}
}
// 如果没有匹配到特定证型,提供一般建议
if (empty($diagnosis)) {
$diagnosis = '四诊信息不足,请提供更多症状细节';
}
?>
<!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 ($recommended_prescription): ?>
<h3>推荐经方:</h3>
<div class="prescription-card">
<h4><?php echo $recommended_prescription['name']; ?></h4>
<p><strong>组成:</strong> <?php echo $recommended_prescription['composition']; ?></p>
<p><strong>主治:</strong> <?php echo $recommended_prescription['indications']; ?></p>
<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)): ?>
<li><?php echo ucfirst(str_replace('_', ' ', $symptom)); ?>:
<?php echo is_array($value) ? implode(', ', $value) : $value; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<h3>舌象:</h3>
<ul>
<?php foreach ($tongue as $feature => $value): ?>
<li><?php echo get_tongue_description($feature)); ?>: <?php echo $value; ?></li>
<?php endforeach; ?>
</ul>
<h3>脉象:</h3>
<p><?php echo $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;
}
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;
}
.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;
}
.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;
}
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;
}
}
系统功能说明
- 患者信息收集:
- 基本信息(姓名、性别、年龄)
- 主要症状(发热、头痛等,可扩展)
- 舌象(舌质、舌苔)
- 脉象
- 诊断逻辑:
- 根据症状组合匹配中医证型
- 推荐相应的经典方剂
- 显示方剂组成、主治和禁忌
- 结果展示:
- 辨证结论
- 推荐经方详情
- 四诊摘要回顾
扩展建议
- 增加更多症状和经方:
- 在prescriptions.php中添加更多经方
- 扩展symptom_prescription_map映射关系
- 增强诊断逻辑:
- 实现更复杂的辨证算法
- 添加体质辨识功能
- 数据持久化:
- 添加MySQL数据库存储病历
- 实现病历查询功能
- 安全性增强:
- 添加用户认证
- 加强输入验证
这个系统完全使用原生PHP实现,不依赖任何前端框架,保持了简洁性和可维护性,同时遵循了中医经方辨证的基本原则。

Leave a Reply