下载地址: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 = `
${data.hospital}
门(急)诊病历
姓名: ${data.patientName}
性别: ${data.patientGender}
年龄: ${data.patientAge}
病历号/ID: ${data.patientId}
科室: ${data.department}
医师: ${data.doctor}
就诊日期: ${data.visitDate}
出院日期: ${data.dischargeDate}
初步诊断
${data.diagnosis}
主诉
${data.symptoms}
体格检查
${data.physicalExam}
实验室检查
${data.labResults}
治疗方案
${data.treatmentPlan}
`;
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();});