Difference between revisions of "MediaWiki:Gadget-calculator-bodyComposition.js"
From WikiAnesthesia
Chris Rishel (talk | contribs) |
Chris Rishel (talk | contribs) (Changed gender label to sex) |
||
(One intermediate revision by the same user not shown) | |||
Line 31: | Line 31: | ||
baseWeight = 50; | baseWeight = 50; | ||
} else { | } else { | ||
throw new Error( 'Invalid | throw new Error( 'Invalid sex "' + data.gender + '"' ); | ||
} | } | ||
Line 58: | Line 58: | ||
return 9270 * data.weight.toNumber( 'kgwt' ) / ( 6680 + 216 * data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ) ); | return 9270 * data.weight.toNumber( 'kgwt' ) / ( 6680 + 216 * data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ) ); | ||
} else { | } else { | ||
throw new Error( 'Invalid | throw new Error( 'Invalid sex "' + data.gender + '"' ); | ||
} | } | ||
} | } |
Latest revision as of 21:27, 11 July 2022
/** * @author Chris Rishel */ ( function() { mw.calculators.addCalculations( { ibw: { name: 'Ideal body weight', abbreviation: 'IBW', data: { variables: { required: [ 'height', 'gender' ] } }, units: 'kgwt', link: 'https://en.wikipedia.org/wiki/Human_body_weight#Ideal_body_weight', description: 'Ideal body weight may only be applied to persons 152 cm (60 inches) or taller', formula: '<math>\\mathrm{IBW} = \\begin{cases}45.5 + 2.3 * (\\mathrm{height_{in}} - 60) & \\text{if female} \\\\50 + 2.3 * (\\mathrm{height_{in}} - 60) & \\text{if male}\\end{cases}</math>', references: [ 'Devine BJ. Gentamicin therapy. Drug Intell Clin Pharm. 1974;8:650–655.' ], calculate: function( data ) { if( data.height.toNumber( 'cm' ) < 152 ) { throw new Error( 'Ideal body weight may only be applied to persons 152 cm (60 inches) or taller' ); } var baseWeight; if( data.gender === 'F' ) { baseWeight = 45.5; } else if( data.gender === 'M' ) { baseWeight = 50; } else { throw new Error( 'Invalid sex "' + data.gender + '"' ); } // baseWeight + 2.3 kg for every inch over 5 feet return baseWeight + 2.3 * ( data.height.toNumber( 'in' ) - 60 ); } }, lbw: { name: 'Lean body weight', abbreviation: 'LBW', data: { variables: { required: [ 'weight', 'height', 'gender' ] } }, units: 'kgwt', link: 'https://en.wikipedia.org/wiki/Lean_body_mass', formula: '<math>\\mathrm{LBW} = \\begin{cases} \\frac{9270 * \\mathrm{weight_{kg}}}{8780+(244*\\mathrm{BMI})} & \\text{if female} \\\\\\\\ \\frac{9270 * \\mathrm{weight_{kg}}}{6680+(216*\\mathrm{BMI})} & \\text{if male} \\end{cases}</math>', references: [ 'Janmahasatian S, Duffull SB, Ash S, Ward LC, Byrne NM, Green B. Quantification of lean bodyweight. Clin Pharmacokinet. 2005; 44(10): 1051-65.' ], calculate: function( data ) { if( data.gender === 'F' ) { return 9270 * data.weight.toNumber( 'kgwt' ) / ( 8780 + 244 * data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ) ); } else if( data.gender === 'M' ) { return 9270 * data.weight.toNumber( 'kgwt' ) / ( 6680 + 216 * data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ) ); } else { throw new Error( 'Invalid sex "' + data.gender + '"' ); } } }, tbw: { name: 'Total body weight', abbreviation: 'TBW', data: { variables: { required: [ 'weight' ] } }, units: 'kgwt', calculate: function( data ) { return data.weight.toNumber( 'kgwt' ); } }, bmi: { name: 'Body mass index', abbreviation: 'BMI', data: { variables: { required: [ 'weight', 'height' ] } }, digits: 0, units: 'kg/m^2', formula: '<math>\\mathrm{BMI} = \\frac{\\mathrm{mass_{kg}}}{{(\\mathrm{height_{m}}})^2}</math>', link: '[[Body mass index]]', references: [], calculate: function( data ) { return data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ); } }, bsa: { name: 'Body surface area', abbreviation: 'BSA', data: { variables: { required: [ 'weight', 'height' ] } }, digits: 2, units: 'm^2', formula: '<math>\\mathrm{BSA} = \\sqrt{\\frac{\\mathrm{weight_{kg}}*\\mathrm{height_{cm}}}{3600}}</math>', link: false, references: [ 'Mosteller RD. Simplified calculation of body-surface area. N Engl J Med. 1987 Oct 22;317(17):1098. doi: 10.1056/NEJM198710223171717. PMID: 3657876.' ], calculate: function( data ) { return Math.sqrt( data.height.toNumber( 'cm' ) * data.weight.toNumber( 'kgwt' ) / 3600 ); } } } ); }() );