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

From WikiAnesthesia
 
(10 intermediate revisions by the same user not shown)
Line 3: Line 3:
  */
  */
( function() {
( function() {
    // Units for age (37 weeks = birth)
     mw.calculators.renderPatientInput = function() {
     mw.calculators.addUnits( {
         if( mw.calculators.getOptionValue( 'patientinputinline' ) ) {
         wk: {
             return;
            baseName: 'age',
            definition: '0.01923 year',
            offset: -37
        },
        mo: {
            baseName: 'age',
            definition: '1 month'
        },
        yr: {
             baseName: 'age',
            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( {
         var containerId = 'calculator-patients-patientInput';
         gwt: {
            baseName: 'weight',
            prefixes: 'short'
        },
        lbwt: {
            baseName: 'weight',
            definition: '453.59237 gwt'
        }
    } );


    mw.calculators.addVariables( {
        if( !$( '#' + containerId ).length ) {
        age: {
             var inputs = [
            name: 'Age',
                 'weight',
            type: 'number',
                 'height',
            defaultValue: '40 yr',
                 'age',
            maxLength: 3,
                 'gender'
            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';
            var $container = $( '<div>', {
                id: containerId
            } );


    if( !$( '#' + containerId ).length ) {
            $container.addClass( 'container border-bottom px-0 py-1' );
        var $container = $( '<div>', {
            id: containerId
        } );


        $container.addClass( 'container border-bottom px-0 py-1' );
            $container.append( mw.calculators.createInputGroup( inputs, true, inputs.length ) );


        var $containerRow = $( '<div>', {
             $container.appendTo( $( '#contentHeader' ) );
             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 );
    mw.hook( 'calculators.initialized' ).add( mw.calculators.renderPatientInput );
    }
}() );
}() );

Latest revision as of 21:59, 29 March 2022

/**
 * @author Chris Rishel
 */
( function() {
    mw.calculators.renderPatientInput = function() {
        if( mw.calculators.getOptionValue( 'patientinputinline' ) ) {
            return;
        }

        var containerId = 'calculator-patients-patientInput';

        if( !$( '#' + containerId ).length ) {
            var inputs = [
                'weight',
                'height',
                'age',
                'gender'
            ];

            var $container = $( '<div>', {
                id: containerId
            } );

            $container.addClass( 'container border-bottom px-0 py-1' );

            $container.append( mw.calculators.createInputGroup( inputs, true, inputs.length ) );

            $container.appendTo( $( '#contentHeader' ) );
        }
    };

    mw.hook( 'calculators.initialized' ).add( mw.calculators.renderPatientInput );
}() );