Difference between revisions of "MediaWiki:Gadget-calculator-patients-core.js"
From WikiAnesthesia
Chris Rishel (talk | contribs) (Created page with "→* * @author Chris Rishel: ( function() { // Units for age (37 weeks = birth) mw.calculators.addUnits( { wk: { definition: '0.01923 year',...") |
Chris Rishel (talk | contribs) |
||
Line 84: | Line 84: | ||
'gwt' | 'gwt' | ||
] | ] | ||
} | |||
} ); | |||
mw.calculators.addCalculations( { | |||
ibw: { | |||
name: 'Ideal body weight', | |||
abbreviation: 'IBW', | |||
data: { | |||
variables: { | |||
required: [ 'height', 'gender' ] | |||
} | |||
}, | |||
units: 'kg', | |||
link: 'https://en.wikipedia.org/wiki/Human_body_weight#Ideal_body_weight', | |||
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 = data.gender === 'F' ? 45.5 : 50; | |||
// 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: [ 'gender', 'height', 'weight' ] | |||
} | |||
}, | |||
units: 'kg', | |||
link: 'https://en.wikipedia.org/wiki/Lean_body_mass', | |||
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 { | |||
return 9270 * data.weight.toNumber( 'kgwt' ) / ( 6680 + 216 * data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ) ); | |||
} | |||
} | |||
} | } | ||
} ); | } ); | ||
}() ); | }() ); |
Revision as of 14:23, 8 August 2021
/** * @author Chris Rishel */ ( function() { // Units for age (37 weeks = birth) mw.calculators.addUnits( { wk: { definition: '0.01923 year', offset: -37 }, mo: { definition: '1 month' }, yr: { definition: '1 year', aliases: [ 'yo' ] } } ); // Units for weight // Body weight needs to be treated as a different fundamental unit type from mass (otherwise it would cancel out // doing stoichiometry calculations. // Gram-weight, which uses short SI prefixes (e.g. 1 kgwt = 1000 gwt) mw.calculators.addUnitsBases( { weight: { toString: function( units ) { return units.replace( 'wt', '' ); } } } ); mw.calculators.addUnits( { gwt: { baseName: 'weight', prefixes: 'short' }, lbwt: { baseName: 'weight', definition: '453.59237 gwt' } } ); mw.calculators.addVariables( { age: { name: 'Age', type: 'number', defaultValue: '40 yr', maxLength: 3, units: [ 'yr', 'mo', 'wk' ] }, gender: { name: 'Gender', type: 'string', defaultValue: 'F', options: [ 'F', 'M' ] }, height: { name: 'Height', type: 'number', defaultValue: '175 cm', maxLength: 3, units: [ 'cm', 'm', 'in', 'ft' ] }, weight: { name: 'Weight', type: 'number', defaultValue: '75 kgwt', maxLength: 3, units: [ 'kgwt', 'lbwt', 'gwt' ] } } ); mw.calculators.addCalculations( { ibw: { name: 'Ideal body weight', abbreviation: 'IBW', data: { variables: { required: [ 'height', 'gender' ] } }, units: 'kg', link: 'https://en.wikipedia.org/wiki/Human_body_weight#Ideal_body_weight', 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 = data.gender === 'F' ? 45.5 : 50; // 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: [ 'gender', 'height', 'weight' ] } }, units: 'kg', link: 'https://en.wikipedia.org/wiki/Lean_body_mass', 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 { return 9270 * data.weight.toNumber( 'kgwt' ) / ( 6680 + 216 * data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 ) ); } } } } ); }() );