Improved measurement parsing

This commit is contained in:
Jiang Yio 2025-01-05 21:52:42 -05:00
parent 5d2a8f464f
commit 18d6b6f19c
2 changed files with 31 additions and 14 deletions

View File

@ -49,13 +49,14 @@
function vitals_normalize(rs) { function vitals_normalize(rs) {
return rs.map(function(x) { return rs.map(function(x) {
var comment = x.comment && x.comment.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ');
var res = { var res = {
time: x.datetime, time: x.datetime,
name: x.name, name: x.name,
unit: x.unit, unit: x.unit,
value: x.value, value: x.value,
flag: x.flag, flag: x.flag,
comment: x.user comment: comment ? x.user + ' • ' + comment : x.user
}; };
return vitals_mapping[x.name] ? Object.assign(res, vitals_mapping[x.name]) : res; return vitals_mapping[x.name] ? Object.assign(res, vitals_mapping[x.name]) : res;
}); });

View File

@ -195,20 +195,36 @@ export function measurement_parse(data) {
res.name = row.substring(idx + 3, idx = row.indexOf(': ', idx)); res.name = row.substring(idx + 3, idx = row.indexOf(': ', idx));
value = row.substring(idx + 4, idx = row.indexOf(' _', idx)); value = row.substring(idx + 4, idx = row.indexOf(' _', idx));
res.user = row.substring(idx + 2); res.user = row.substring(idx + 2);
m = value.match(/^(?:(.*?)(?: (\S+))?)(\*)?(?: \((?:(.*?)(?: (\S+))?)\))?\s*$/); if(m = value.match(/(?:^(?<value>[\d\.\/%]+)(?: (?<unit>\w+) \((?<value2>[\d\.\/%]+) (?<unit2>\w+)\))?(?<flag>\*)? (?: (?<comment>.*))?$)|(?:^(?<value3>[\d\.\/%]+)(?<flag3>\*)?\s*(?<comment3>.*)$)/)) {
res.value = m[4] ? m[4] : m[1]; if(m.groups.value2) {
res.unit = m[4] ? m[5] : m[2]; res.value = m.groups.value2;
res.flag = m[3]; res.unit = m.groups.unit2;
res.value_american = m[4] ? m[1] : m[4]; res.value_american = m.groups.value;
res.unit_american = m[4] ? m[2] : m[5]; res.unit_american = m.groups.unit;
if(res.value.charAt(res.value.length - 1) == '%') { res.flag = m.groups.flag;
res.unit = '%'; res.comment = m.groups.comment;
res.value = res.value.substring(0, res.value.length - 1); } else if(m.groups.value) {
res.value = m.groups.value;
res.unit = m.groups.unit;
res.flag = m.groups.flag;
res.comment = m.groups.comment;
} else if(m.groups.value3) {
res.value = m.groups.value3;
res.flag = m.groups.flag3;
res.comment = m.groups.comment3;
} else res.comment = value;
if(res.comment) res.comment = res.comment.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ');
} }
if(res.name == 'B/P') { if(res.value) {
var bpsplit = res.value.split('/'); if(res.value.charAt(res.value.length - 1) == '%') {
extras.push({...res, name: 'SBP', range: '90 - 120', unit: 'mmHg', value: bpsplit[0] }); res.unit = '%';
extras.push({...res, name: 'DBP', range: '60 - 80', unit: 'mmHg', value: bpsplit[1] }); res.value = res.value.substring(0, res.value.length - 1);
}
if(res.name == 'B/P') {
var bpsplit = res.value.split('/');
extras.push({...res, name: 'SBP', range: '90 - 120', unit: 'mmHg', value: bpsplit[0] });
extras.push({...res, name: 'DBP', range: '60 - 80', unit: 'mmHg', value: bpsplit[1] });
}
} }
return res; return res;
} }