2baf29b3ae
Deliver encrypted health zone, observation API, baseline maturity pipeline, page-data bindings, and H5/WeChat channel integration for health P0. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
import { parseChineseInteger } from './health-chinese-numerals.mjs';
|
||
|
||
const BP_PAIR = /(\d{2,3})\s*[//]\s*(\d{2,3})/;
|
||
const BP_ALT = /高压\s*(\d{2,3}).{0,8}低压\s*(\d{2,3})/;
|
||
const BP_CN = /(?:血压|收缩压|高压)?\s*([零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖]{1,8})\s*(?:[//比]|和|跟)\s*([零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖]{1,6})/;
|
||
const BP_CN_ALT = /高压\s*([零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖]{1,8})\s*低压\s*([零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖]{1,6})/;
|
||
|
||
export function extractBloodPressurePair(text) {
|
||
const raw = String(text ?? '').trim();
|
||
if (!raw) return null;
|
||
|
||
const direct = raw.match(BP_PAIR);
|
||
if (direct) {
|
||
return { systolic: Number(direct[1]), diastolic: Number(direct[2]), source: 'numeric' };
|
||
}
|
||
|
||
const alt = raw.match(BP_ALT);
|
||
if (alt) {
|
||
return { systolic: Number(alt[1]), diastolic: Number(alt[2]), source: 'alt_label' };
|
||
}
|
||
|
||
const cn = raw.match(BP_CN);
|
||
if (cn) {
|
||
const systolic = parseChineseInteger(cn[1]);
|
||
const diastolic = parseChineseInteger(cn[2]);
|
||
if (systolic != null && diastolic != null) {
|
||
return { systolic, diastolic, source: 'chinese' };
|
||
}
|
||
}
|
||
|
||
const cnAlt = raw.match(BP_CN_ALT);
|
||
if (cnAlt) {
|
||
const systolic = parseChineseInteger(cnAlt[1]);
|
||
const diastolic = parseChineseInteger(cnAlt[2]);
|
||
if (systolic != null && diastolic != null) {
|
||
return { systolic, diastolic, source: 'chinese_alt' };
|
||
}
|
||
}
|
||
|
||
if (/血压/.test(raw) && /\d{2,3}/.test(raw)) {
|
||
const nums = [...raw.matchAll(/\d{2,3}/g)].map((m) => Number(m[0]));
|
||
if (nums.length >= 2) {
|
||
return { systolic: nums[0], diastolic: nums[1], source: 'numeric_loose' };
|
||
}
|
||
}
|
||
|
||
return null;
|
||
}
|