@automate-medical/gli2012
Version:
Continuous prediction equations for spirometric indices
40 lines (39 loc) • 1.69 kB
JavaScript
export function GLIFunction(coefficients, lookups, age, sex, height, ethnicity, measured) {
const c = coefficients[sex];
const AfrAm = ethnicity === "AfrAm" ? 1 : 0;
const NEAsia = ethnicity === "NEAsia" ? 1 : 0;
const SEAsia = ethnicity === "SEAsia" ? 1 : 0;
const Other = ethnicity === "Other" ? 1 : 0;
const Lspline = lookups[sex][findIndex(age)][0]; // @TODO implements lookup for 3-95 vs. second method
const Mspline = lookups[sex][findIndex(age)][1];
const Sspline = lookups[sex][findIndex(age)][2];
const L = c['q0'] + c['q1'] * Math.log(age) + Lspline;
const M = Math.exp(c['a0'] + c['a1'] * Math.log(height) + c['a2'] * Math.log(age) + c['a3'] * AfrAm + c['a4'] * NEAsia + c['a5'] * SEAsia + c['a6'] * Other + Mspline);
const S = Math.exp(c['p0'] + c['p1'] * Math.log(age) + c['p2'] * AfrAm + c['p3'] * NEAsia + c['p4'] * SEAsia + c['p5'] * Other + Sspline);
const LLN = Math.exp(Math.log(M) + Math.log(1 - 1.645 * L * S) / L);
const percent = (measured / M) * 100;
const zscore = (Math.pow((measured / M), L) - 1) / (L * S);
return {
L,
M,
S,
LLN,
percent,
zscore
};
}
// @TODO is there a way to avoid this duplication so the runtime has access?
export const sexes = ["Male", "Female"];
export const ethnicities = ["Caucasian", "AfrAm", "NEAsia", "SEAsia", "Other"];
export function findIndex(age) {
if (age % 0.25 === 0) {
// @TODO is there a way to prove that this is going to be a lookup-able value?
// @ts-ignore
return age;
}
else {
// @TODO same thing
// @ts-ignore
return age - (age % 0.25);
}
}