patient-mini/test_parser.js
@zuopngfei 746614c2cc dsdd
2025-08-04 18:11:46 +08:00

85 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 简单的B超报告解析测试
const testText = `上海复旦大学儿科医院
阴道屈笼中儿童 B秒
肝肋下: 32mm
肝剑突下: 42mm
肝回声
门静脉流速: 15.5cm/s
肝回声
肝性性形影像像最大数字: 10.5ka
肝回声
肝性性形影像像中测数字: 25.5ka
门静脉主干内径: 4.5mm
门静脉主干内径: 6.5mm
胆囊大小: 15.5mm×5.5mm
胆囊大小: 21mm×11mm
膀肋下: 未触及
膀总管: 显示不清
膀性声像:`;
// 解析函数(简化版本)
function parseBUltraReport(text) {
if (!text) return [];
const result = [];
const lines = text.split(/[\n\r]+/);
lines.forEach(line => {
line = line.trim();
if (!line) return;
// 匹配 "名称: 数值" 格式,提取数值部分(不包含单位)
const colonMatch = line.match(/^([^:]+)[:]\s*(.+)$/);
if (colonMatch) {
const name = colonMatch[1].trim();
let value = colonMatch[2].trim();
// 提取数值部分,去除单位
const numberMatch = value.match(/^(\d+(?:\.\d+)?)/);
if (numberMatch) {
value = numberMatch[1];
}
if (name && value) {
result.push({ name, value });
}
return;
}
// 匹配包含数值的项目(如 "肝肋下: 32mm"),只提取数值
const valueMatch = line.match(/([^0-9]+?)(\d+(?:\.\d+)?)/);
if (valueMatch) {
const name = valueMatch[1].trim();
const value = valueMatch[2].trim();
if (name && value) {
result.push({ name, value });
}
return;
}
// 处理特殊格式,如 "未触及"、"显示不清" 等
const specialMatch = line.match(/^([^:]+)[:]\s*(未触及|显示不清|.+)$/);
if (specialMatch) {
const name = specialMatch[1].trim();
const value = specialMatch[2].trim();
if (name && value) {
result.push({ name, value });
}
}
});
return result;
}
// 执行解析
const result = parseBUltraReport(testText);
// 输出结果
console.log('解析结果value不包含单位:');
console.log(JSON.stringify(result, null, 2));
// 验证结果
console.log('\n验证结果:');
result.forEach((item, index) => {
console.log(`${index + 1}. ${item.name}: ${item.value}`);
});