Difference between revisions of "MediaWiki:Gadget-calculator-patients-patientInput.js"
From WikiAnesthesia
Chris Rishel (talk | contribs) |
Chris Rishel (talk | contribs) |
||
| Line 6: | Line 6: | ||
mw.calculators.addUnits( { | mw.calculators.addUnits( { | ||
wk: { | wk: { | ||
definition: '0.01923 year', | definition: '0.01923 year', | ||
offset: -37 | offset: -37 | ||
}, | }, | ||
mo: { | mo: { | ||
definition: '1 month' | definition: '1 month' | ||
}, | }, | ||
yr: { | yr: { | ||
definition: '1 year', | definition: '1 year', | ||
aliases: [ 'yo' ] | aliases: [ 'yo' ] | ||
} | } | ||
} ); | } ); | ||
// Units for weight | // Units for weight | ||
// Body weight needs to be treated as a different fundamental unit type from mass (otherwise it would cancel out | // Body weight needs to be treated as a different fundamental unit type from mass (otherwise it would cancel out | ||
| Line 35: | Line 32: | ||
mw.calculators.addUnits( { | mw.calculators.addUnits( { | ||
gwt: { | gwt: { | ||
baseName: ' | baseName: 'WEIGHT', | ||
prefixes: 'short' | prefixes: 'short' | ||
}, | }, | ||
lbwt: { | lbwt: { | ||
baseName: ' | baseName: 'WEIGHT', | ||
definition: '453.59237 gwt' | definition: '453.59237 gwt' | ||
} | } | ||
Revision as of 10:17, 28 July 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',
abbreviation: 'Ht',
defaultValue: '175 cm',
maxLength: 3,
units: [
'cm',
'm',
'in',
'ft'
]
},
weight: {
name: 'Weight',
type: 'number',
abbreviation: 'Wt',
defaultValue: '75 kgwt',
maxLength: 3,
units: [
'kgwt',
'lbwt',
'gwt'
]
}
} );
var containerId = 'calculator-patientInput';
if( !$( '#' + containerId ).length ) {
var $container = $( '<div>', {
id: containerId
} );
$container.addClass( 'container border-bottom px-0 py-1' );
var $containerRow = $( '<div>', {
class: 'form-row align-items-center'
} );
var inputOptions = {
size: 'compact'
};
$containerRow.append( mw.calculators.getVariable( 'weight' ).createInput( inputOptions ) );
$containerRow.append( mw.calculators.getVariable( 'height' ).createInput( inputOptions ) );
$containerRow.append( mw.calculators.getVariable( 'age' ).createInput( inputOptions ) );
$containerRow.append( mw.calculators.getVariable( 'gender' ).createInput( inputOptions ) );
$container.appendTo( $( '#contentHeader' ) );
$container.append( $containerRow );
}
}() );