Difference between revisions of "MediaWiki:Gadget-calculator-patients-patientInput.js"

From WikiAnesthesia
(Created page with "→‎* * @author Chris Rishel: ( function() { mw.calculators.addVariables( { age: { name: 'Age', type: 'number', defaultValue:...")
 
m (Chris.Rishel moved page MediaWiki:Gadget-calculator-patientinput.js to MediaWiki:Gadget-calculator-patientInput.js without leaving a redirect)
(No difference)

Revision as of 18:04, 22 July 2021

/**
 * @author Chris Rishel
 */
( function() {
    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,
            renderUnits: function( units ) {
                return units.replace( 'wt', '' );
            },
            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 );
    }
}() );