下载地址:https://www.pan38.com/share.php?code=HnCLX 提取码:8888 【仅供学习参考】
完整的仿真病历生成系统。以下是使用HTML、CSS和JavaScript实现的完整代码,包含表单输入、样式设计和病历生成功能:
这个完整的病历生成系统包含以下功能:
完整的病历表单输入界面
响应式设计,适配不同设备
自动填充当前日期
必填字段验证
专业病历格式生成
打印功能
美观的UI设计
class MedicalRecordGenerator {
constructor() {
this.hospitals = [
"北京协和医院", "上海瑞金医院",
"广州中山医院", "深圳人民医院",
"武汉同济医院", "成都华西医院"
];
this.departments = [
"内科", "外科", "妇产科", "儿科",
"神经科", "心血管科", "呼吸科", "消化科"
];
this.diagnosisTemplates = {
commonCold: "上呼吸道感染",
gastritis: "慢性浅表性胃炎",
hypertension: "原发性高血压2级",
diabetes: "2型糖尿病",
arthritis: "类风湿性关节炎"
};
this.treatmentPlans = {
commonCold: "1. 休息 2. 多饮水 3. 对症治疗",
gastritis: "1. 抑酸治疗 2. 胃黏膜保护剂 3. 饮食调整",
hypertension: "1. 降压药物治疗 2. 低盐饮食 3. 定期监测血压",
diabetes: "1. 口服降糖药 2. 饮食控制 3. 血糖监测",
arthritis: "1. 抗炎治疗 2. 物理治疗 3. 关节保护"
};
this.init();
}
init() {
this.cacheDOM();
this.bindEvents();
this.renderHospitalOptions();
this.renderDepartmentOptions();
this.setDefaultDates();
this.initDiagnosisOptions();
}
cacheDOM() {
this.form = document.getElementById('medical-form');
this.patientName = document.getElementById('patient-name');
this.patientGender = document.getElementById('patient-gender');
this.patientAge = document.getElementById('patient-age');
this.patientId = document.getElementById('patient-id');
this.hospital = document.getElementById('hospital');
this.department = document.getElementById('department');
this.doctor = document.getElementById('doctor');
this.visitDate = document.getElementById('visit-date');
this.dischargeDate = document.getElementById('discharge-date');
this.diagnosisType = document.getElementById('diagnosis-type');
this.symptoms = document.getElementById('symptoms');
this.physicalExam = document.getElementById('physical-exam');
this.labResults = document.getElementById('lab-results');
this.treatmentPlan = document.getElementById('treatment-plan');
this.generateBtn = document.getElementById('generate-btn');
this.previewContainer = document.getElementById('preview-container');
this.downloadBtn = document.getElementById('download-btn');
}
bindEvents() {
this.generateBtn.addEventListener('click', this.generateRecord.bind(this));
this.downloadBtn.addEventListener('click', this.downloadPDF.bind(this));
this.diagnosisType.addEventListener('change', this.updateTemplate.bind(this));
}
renderHospitalOptions() {
this.hospitals.forEach(hospital => {
const option = document.createElement('option');
option.value = hospital;
option.textContent = hospital;
this.hospital.appendChild(option);
});
}
renderDepartmentOptions() {
this.departments.forEach(dept => {
const option = document.createElement('option');
option.value = dept;
option.textContent = dept;
this.department.appendChild(option);
});
}
setDefaultDates() {
const today = new Date().toISOString().split('T')[0];
this.visitDate.value = today;
this.dischargeDate.value = today;
}
initDiagnosisOptions() {
Object.keys(this.diagnosisTemplates).forEach(key => {
const option = document.createElement('option');
option.value = key;
option.textContent = this.diagnosisTemplates[key];
this.diagnosisType.appendChild(option);
});
}
updateTemplate() {
const selectedType = this.diagnosisType.value;
if (selectedType && this.treatmentPlans[selectedType]) {
this.treatmentPlan.value = this.treatmentPlans[selectedType];
}
}
validateForm() {
let isValid = true;
const requiredFields = [
this.patientName,
this.patientGender,
this.patientAge,
this.patientId,
this.hospital,
this.department,
this.doctor,
this.diagnosisType
];
requiredFields.forEach(field => {
if (!field.value.trim()) {
field.classList.add('is-invalid');
isValid = false;
} else {
field.classList.remove('is-invalid');
}
});
// 验证年龄
const age = parseInt(this.patientAge.value);
if (isNaN(age) || age <= 0 || age > 120) {
this.patientAge.classList.add('is-invalid');
isValid = false;
}
return isValid;
}
generateRecord() {
if (!this.validateForm()) {
alert('请填写完整的病历信息!');
return;
}
const recordData = {
patientName: this.patientName.value,
patientGender: this.patientGender.value,
patientAge: this.patientAge.value,
patientId: this.patientId.value,
hospital: this.hospital.value,
department: this.department.value,
doctor: this.doctor.value,
visitDate: this.formatDate(this.visitDate.value),
dischargeDate: this.formatDate(this.dischargeDate.value),
diagnosis: this.diagnosisType.options[this.diagnosisType.selectedIndex].text,
symptoms: this.symptoms.value || "详见病历描述",
physicalExam: this.physicalExam.value || "详见体检报告",
labResults: this.labResults.value || "详见检验报告",
treatmentPlan: this.treatmentPlan.value,
recordNumber: this.generateRecordNumber()
};
this.renderRecord(recordData);
}
formatDate(dateString) {
const date = new Date(dateString);
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
}
generateRecordNumber() {
const date = new Date();
const year = date.getFullYear().toString().slice(-2);
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const random = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
return `MR${year}${month}${day}${random}`;
}
renderRecord(data) {
const recordHTML = `
<div class="medical-record">
<div class="record-header">
<h2>${data.hospital}</h2>
<h3>门(急)诊病历</h3>
<div class="record-number">病历号: ${data.recordNumber}</div>
</div>
<div class="patient-info">
<div class="info-row">
<span><strong>姓名:</strong> ${data.patientName}</span>
<span><strong>性别:</strong> ${data.patientGender}</span>
<span><strong>年龄:</strong> ${data.patientAge}</span>
</div>
<div class="info-row">
<span><strong>病历号/ID:</strong> ${data.patientId}</span>
<span><strong>科室:</strong> ${data.department}</span>
<span><strong>医师:</strong> ${data.doctor}</span>
</div>
<div class="info-row">
<span><strong>就诊日期:</strong> ${data.visitDate}</span>
<span><strong>出院日期:</strong> ${data.dischargeDate}</span>
</div>
</div>
<div class="diagnosis-section">
<h4>初步诊断</h4>
<p>${data.diagnosis}</p>
</div>
<div class="symptoms-section">
<h4>主诉</h4>
<p>${data.symptoms}</p>
</div>
<div class="exam-section">
<h4>体格检查</h4>
<p>${data.physicalExam}</p>
</div>
<div class="lab-section">
<h4>实验室检查</h4>
<p>${data.labResults}</p>
</div>
<div class="treatment-section">
<h4>治疗方案</h4>
<p>${data.treatmentPlan}</p>
</div>
<div class="record-footer">
<div class="doctor-signature">
<p>医师签名: ${data.doctor}</p>
<p>日期: ${data.dischargeDate}</p>
</div>
<div class="hospital-stamp">
<div class="stamp">${data.hospital}病历专用章</div>
</div>
</div>
</div>
`;
this.previewContainer.innerHTML = recordHTML;
this.previewContainer.style.display = 'block';
this.downloadBtn.style.display = 'inline-block';
}
downloadPDF() {
const element = this.previewContainer;
const opt = {
margin: 10,
filename: `病历_${this.patientName.value}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
html2pdf().set(opt).from(element).save();
}
}
// 初始化生成器
document.addEventListener('DOMContentLoaded', function() {
new MedicalRecordGenerator();
});