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

From WikiAnesthesia
Line 40: Line 40:
         }
         }
     } );
     } );


     mw.calculators.addCalculations( {
     mw.calculators.addCalculations( {
         bladeMacSize: {
         bladeMacSize: {
            name: 'Laryngoscope blade size (MAC)',
             abbreviation: 'Blade (MAC)',
             abbreviation: 'Blade (MAC)',
             name: 'Laryngoscope blade size (MAC)',
             data: {
                variables: {
                    required: [ 'age' ]
                }
            },
            type: 'string',
             references: [
             references: [
                 'Smith\'s Anesthesia for Infants and Children. 8e. p356'
                 'Smith\'s Anesthesia for Infants and Children. 8e. p356'
             ],
             ],
            type: 'string',
            variables: {
                required: [ 'age' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 var age = data.age.toNumber( 'yo' );
                 var age = data.age.toNumber( 'yo' );
Line 67: Line 71:
         },
         },
         bladeMillerSize: {
         bladeMillerSize: {
            name: 'Laryngoscope blade size (Miller)',
             abbreviation: 'Blade (Miller)',
             abbreviation: 'Blade (Miller)',
             name: 'Laryngoscope blade size (Miller)',
             data: {
                variables: {
                    required: [ 'age' ]
                }
            },
            type: 'string',
             references: [
             references: [
                 'Smith\'s Anesthesia for Infants and Children. 8e. p356'
                 'Smith\'s Anesthesia for Infants and Children. 8e. p356'
             ],
             ],
            type: 'string',
            variables: {
                required: [ 'age' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 var age = data.age.toNumber( 'yo' );
                 var age = data.age.toNumber( 'yo' );
Line 91: Line 97:
         },
         },
         bmi: {
         bmi: {
            name: 'Body mass index',
             abbreviation: 'BMI',
             abbreviation: 'BMI',
            data: {
                variables: {
                    required: [ 'weight', 'height' ]
                }
            },
             digits: 0,
             digits: 0,
            units: 'kg/m^2',
             formula: '<math>\\mathrm{BMI} = \\frac{\\text{mass}_\\text{kg}}{{\\text{height}_\\text{m}}^2}</math>',
             formula: '<math>\\mathrm{BMI} = \\frac{\\text{mass}_\\text{kg}}{{\\text{height}_\\text{m}}^2}</math>',
             link: '[[Body mass index]]',
             link: '[[Body mass index]]',
            name: 'Body mass index',
             references: [],
             references: [],
            units: 'kg/m^2',
            variables: {
                required: [ 'weight', 'height' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 return data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 );
                 return data.weight.toNumber( 'kgwt' ) / Math.pow( data.height.toNumber( 'm' ), 2 );
Line 106: Line 114:
         },
         },
         bsa: {
         bsa: {
            name: 'Body surface area',
             abbreviation: 'BSA',
             abbreviation: 'BSA',
            data: {
                variables: {
                    required: [ 'weight', 'height' ]
                }
            },
             formula: '<math>\\mathrm{BSA} = 0.007184 \\times W^{0.425} \\times H^{0.725}</math>',
             formula: '<math>\\mathrm{BSA} = 0.007184 \\times W^{0.425} \\times H^{0.725}</math>',
             link: false,
             link: false,
            name: 'Body surface area',
             references: [
             references: [
                 'Verbraecken, J; Van de Heyning P; De Backer W; Van Gaal L (Apr 2006). "Body surface area in normal-weight, overweight, and obese adults. A comparison study". Metabolism: Clinical and Experimental. 55 (4): 515–24. doi:10.1016/j.metabol.2005.11.004. PMID 16546483'
                 'Verbraecken, J; Van de Heyning P; De Backer W; Van Gaal L (Apr 2006). "Body surface area in normal-weight, overweight, and obese adults. A comparison study". Metabolism: Clinical and Experimental. 55 (4): 515–24. doi:10.1016/j.metabol.2005.11.004. PMID 16546483'
             ],
             ],
            variables: {
                required: [ 'weight', 'height' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 return Math.pow( data.weight.toNumber( 'kgwt' ), 0.425 ) * Math.pow( data.height.toNumber( 'cm' ), 0.725 );
                 return Math.pow( data.weight.toNumber( 'kgwt' ), 0.425 ) * Math.pow( data.height.toNumber( 'cm' ), 0.725 );
Line 121: Line 131:
         },
         },
         ebv: {
         ebv: {
            name: 'Estimated blood volume',
             abbreviation: 'EBV',
             abbreviation: 'EBV',
            data: {
                variables: {
                    required: [ 'weight', 'age' ]
                }
            },
             digits: 0,
             digits: 0,
            units: 'mL',
             formula: '',
             formula: '',
            link: false,
            name: 'Estimated blood volume',
             references: [
             references: [
                 'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168'
                 'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168'
             ],
             ],
            units: 'mL',
            variables: {
                required: [ 'weight', 'age' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 var weight = data.weight.toNumber( 'kgwt' );
                 var weight = data.weight.toNumber( 'kgwt' );
Line 157: Line 168:
         },
         },
         ettSize: {
         ettSize: {
            name: 'Endotracheal tube size',
             abbreviation: 'ETT size',
             abbreviation: 'ETT size',
             name: 'Endotracheal tube size',
             data: {
                variables: {
                    required: [ 'age' ],
                    optional: [ 'height' ]
                }
            },
            type: 'string',
             references: [
             references: [
                 'Smith\'s Anesthesia for Infants and Children. 8e. p356'
                 'Smith\'s Anesthesia for Infants and Children. 8e. p356'
             ],
             ],
            type: 'string',
            variables: {
                required: [ 'age' ],
                optional: [ 'height' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 var age = data.age.toNumber( 'yo' );
                 var age = data.age.toNumber( 'yo' );
Line 186: Line 199:
         },
         },
         fluidMaintenanceRate: {
         fluidMaintenanceRate: {
            name: 'Fluid maintenance rate',
             abbreviation: 'Fluid maint.',
             abbreviation: 'Fluid maint.',
            data: {
                variables: {
                    required: [ 'weight' ]
                }
            },
             digits: 0,
             digits: 0,
            units: 'mL/hr',
             formula: '',
             formula: '',
            name: 'Fluid maintenance rate',
             references: [
             references: [
                 'Miller\'s Anesthesia 7e, section IV, pg. 1728'
                 'Miller\'s Anesthesia 7e, section IV, pg. 1728'
             ],
             ],
            units: 'mL/hr',
            variables: {
                required: [ 'weight' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 var weight = data.weight.toNumber( 'kgwt' );
                 var weight = data.weight.toNumber( 'kgwt' );
Line 215: Line 230:
         },
         },
         ibw: {
         ibw: {
            name: 'Ideal body weight',
             abbreviation: 'IBW',
             abbreviation: 'IBW',
            data: {
                variables: {
                    required: [ 'height', 'gender' ]
                }
            },
            units: 'kg',
             link: 'https://en.wikipedia.org/wiki/Human_body_weight#Ideal_body_weight',
             link: 'https://en.wikipedia.org/wiki/Human_body_weight#Ideal_body_weight',
            name: 'Ideal body weight',
             references: [
             references: [
                 'Devine BJ. Gentamicin therapy. Drug Intell Clin Pharm. 1974;8:650–655.'
                 'Devine BJ. Gentamicin therapy. Drug Intell Clin Pharm. 1974;8:650–655.'
             ],
             ],
            units: 'kg',
            variables: {
                required: [ 'height', 'gender' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 if( data.height.toNumber( 'cm' ) < 152 ) {
                 if( data.height.toNumber( 'cm' ) < 152 ) {
Line 237: Line 254:
         },
         },
         lbw: {
         lbw: {
            name: 'Lean body weight',
             abbreviation: 'LBW',
             abbreviation: 'LBW',
            data: {
                variables: {
                    required: [ 'gender', 'height', 'weight' ]
                }
            },
            units: 'kg',
             link: 'https://en.wikipedia.org/wiki/Lean_body_mass',
             link: 'https://en.wikipedia.org/wiki/Lean_body_mass',
            name: 'Lean body weight',
             references: [
             references: [
                 'Janmahasatian S, Duffull SB, Ash S, Ward LC, Byrne NM, Green B. Quantification of lean bodyweight. Clin Pharmacokinet. 2005; 44(10): 1051-65.'
                 'Janmahasatian S, Duffull SB, Ash S, Ward LC, Byrne NM, Green B. Quantification of lean bodyweight. Clin Pharmacokinet. 2005; 44(10): 1051-65.'
             ],
             ],
            units: 'kg',
            variables: {
                required: [ 'gender', 'height', 'weight' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 if( data.gender === 'F' ) {
                 if( data.gender === 'F' ) {
Line 256: Line 275:
         },
         },
         maxAbl: {
         maxAbl: {
            name: 'Maximum allowable blood loss',
             abbreviation: 'Max ABL',
             abbreviation: 'Max ABL',
            data: {
                calculations: {
                    required: [ 'ebv' ]
                },
                variables: {
                    required: [ 'weight', 'age' ]
                }
            },
            units: 'mL',
             formula: '',
             formula: '',
            link: false,
            name: 'Maximum allowable blood loss',
             references: [
             references: [
                 'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168'
                 'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168'
             ],
             ],
            units: 'mL',
            variables: {
                required: [ 'weight', 'age' ]
            },
             calculate: function( data ) {
             calculate: function( data ) {
                 var weight = data.weight.toNumber( 'kgwt' );
                 console.log(data);
                var age = data.age.toNumber( 'yo' );
 
                var ebvPerKg;
 
                if( age >= 1 ) {
                    if( data.gender === 'F' ) {
                        ebvPerKg = 65;
                    } else {
                        ebvPerKg = 75;
                    }
                } else if( age >= 1/12 ) {
                    ebvPerKg = 80;
                } else if( age >= 0 ) {
                    ebvPerKg = 85;
                } else {
                    ebvPerKg = 95;
                }
 
                return weight * ebvPerKg;
             }
             }
         }
         }
Line 324: Line 328:
             calculations: [
             calculations: [
                 'ebv',
                 'ebv',
                 'fluidMaintenanceRate'
                 'fluidMaintenanceRate',
                'maxAbl'
             ],
             ],
             css: {
             css: {

Revision as of 13:32, 29 July 2021

( function() {
    var moduleId = 'patientStats';

    mw.calculators.addUnitsBases( {
        hgb: {
            toString: function( units ) {
                units = units.replace( 'hgbperdL', '/dL' );
                units = units.replace( 'pcthct', '%' );

                return units;
            }
        }
    } );

    mw.calculators.addUnits( {
        ghgbperdL: {
            baseName: 'hgb',
            prefixes: 'short'
        },
        pcthct: {
            baseName: 'hgb',
            definition: '3 ghgbperdL'
        }
    } );

    mw.calculators.addVariables( {
        hct: {
            name: 'Current hematocrit / hemoglobin',
            type: 'number',
            abbreviation: 'Hct/hgb',
            defaultValue: '45',
            maxLength: 4
        },
        minHct: {
            name: 'Minimum allowable hematocrit/hemoglobin',
            type: 'number',
            abbreviation: 'Min hct/hgb',
            defaultValue: '21',
            maxLength: 4
        }
    } );



    mw.calculators.addCalculations( {
        bladeMacSize: {
            name: 'Laryngoscope blade size (MAC)',
            abbreviation: 'Blade (MAC)',
            data: {
                variables: {
                    required: [ 'age' ]
                }
            },
            type: 'string',
            references: [
                'Smith\'s Anesthesia for Infants and Children. 8e. p356'
            ],
            calculate: function( data ) {
                var age = data.age.toNumber( 'yo' );

                if( age >= 6 ) {
                    return '3';
                } else if( age >= 1 ) {
                    // ( age + 16 ) / 4
                    // To nicely display in increments of 0.5, double the calculation, round (floor), then divide by 2
                    return '2';
                } else {
                    return '-';
                }
            }
        },
        bladeMillerSize: {
            name: 'Laryngoscope blade size (Miller)',
            abbreviation: 'Blade (Miller)',
            data: {
                variables: {
                    required: [ 'age' ]
                }
            },
            type: 'string',
            references: [
                'Smith\'s Anesthesia for Infants and Children. 8e. p356'
            ],
            calculate: function( data ) {
                var age = data.age.toNumber( 'yo' );

                if( age >= 2 ) {
                    return '2';
                } else if( age >= 1 / 12 ) {
                    return '1';
                } else if( age >= 0 ) {
                    return '0-1';
                } else {
                    return '0';
                }
            }
        },
        bmi: {
            name: 'Body mass index',
            abbreviation: 'BMI',
            data: {
                variables: {
                    required: [ 'weight', 'height' ]
                }
            },
            digits: 0,
            units: 'kg/m^2',
            formula: '<math>\\mathrm{BMI} = \\frac{\\text{mass}_\\text{kg}}{{\\text{height}_\\text{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' ]
                }
            },
            formula: '<math>\\mathrm{BSA} = 0.007184 \\times W^{0.425} \\times H^{0.725}</math>',
            link: false,
            references: [
                'Verbraecken, J; Van de Heyning P; De Backer W; Van Gaal L (Apr 2006). "Body surface area in normal-weight, overweight, and obese adults. A comparison study". Metabolism: Clinical and Experimental. 55 (4): 515–24. doi:10.1016/j.metabol.2005.11.004. PMID 16546483'
            ],
            calculate: function( data ) {
                return Math.pow( data.weight.toNumber( 'kgwt' ), 0.425 ) * Math.pow( data.height.toNumber( 'cm' ), 0.725 );
            }
        },
        ebv: {
            name: 'Estimated blood volume',
            abbreviation: 'EBV',
            data: {
                variables: {
                    required: [ 'weight', 'age' ]
                }
            },
            digits: 0,
            units: 'mL',
            formula: '',
            references: [
                'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168'
            ],
            calculate: function( data ) {
                var weight = data.weight.toNumber( 'kgwt' );
                var age = data.age.toNumber( 'yo' );

                var ebvPerKg;

                if( age >= 1 ) {
                    if( data.gender === 'F' ) {
                        ebvPerKg = 65;
                    } else {
                        ebvPerKg = 75;
                    }
                } else if( age >= 1/12 ) {
                    ebvPerKg = 80;
                } else if( age >= 0 ) {
                    ebvPerKg = 85;
                } else {
                    ebvPerKg = 95;
                }

                return weight * ebvPerKg;
            }
        },
        ettSize: {
            name: 'Endotracheal tube size',
            abbreviation: 'ETT size',
            data: {
                variables: {
                    required: [ 'age' ],
                    optional: [ 'height' ]
                }
            },
            type: 'string',
            references: [
                'Smith\'s Anesthesia for Infants and Children. 8e. p356'
            ],
            calculate: function( data ) {
                var age = data.age.toNumber( 'yo' );

                if( age >= 12 ) {
                    return '6+';
                } else if( age >= 1 ) {
                    // ( age + 16 ) / 4
                    // To nicely display in increments of 0.5, double the calculation, round (floor), then divide by 2
                    return String( Math.floor( 2 * ( ( age + 16 ) / 4 ) ) / 2 );
                } else if (age >= 0.5 ) {
                    return '3.5-4';
                } else if( age >= 0 ) {
                    return '3-3.5';
                } else {
                    return '2.5-3';
                }
            }
        },
        fluidMaintenanceRate: {
            name: 'Fluid maintenance rate',
            abbreviation: 'Fluid maint.',
            data: {
                variables: {
                    required: [ 'weight' ]
                }
            },
            digits: 0,
            units: 'mL/hr',
            formula: '',
            references: [
                'Miller\'s Anesthesia 7e, section IV, pg. 1728'
            ],
            calculate: function( data ) {
                var weight = data.weight.toNumber( 'kgwt' );

                // Uses 4-2-1 rule
                var maintenanceRate = 4 * Math.min( weight, 10 );

                if( weight > 10 ) {
                    maintenanceRate += 2 * Math.min( weight - 10, 10 );
                }

                if( weight > 20) {
                    maintenanceRate += weight - 20;
                }

                return maintenanceRate;
            }
        },
        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 ) );
                }
            }
        },
        maxAbl: {
            name: 'Maximum allowable blood loss',
            abbreviation: 'Max ABL',
            data: {
                calculations: {
                    required: [ 'ebv' ]
                },
                variables: {
                    required: [ 'weight', 'age' ]
                }
            },
            units: 'mL',
            formula: '',
            references: [
                'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168'
            ],
            calculate: function( data ) {
                console.log(data);
            }
        }
    } );

    var tableMaxWidth = 600;

    mw.calculators.addCalculators( moduleId, {
        anatomy: {
            name: 'Patient statistics',
            calculations: [
                'bmi',
                'bsa',
                'ibw',
                'lbw'
            ],
            css: {
                'max-width': tableMaxWidth
            },
            table: true
        },
        equipment: {
            name: 'Equipment',
            calculations: [
                'bladeMacSize',
                'bladeMillerSize',
                'ettSize'
            ],
            css: {
                'max-width': tableMaxWidth
            },
            table: true
        },
        fluidManagement: {
            name: 'Fluid management',
            calculations: [
                'ebv',
                'fluidMaintenanceRate',
                'maxAbl'
            ],
            css: {
                'max-width': tableMaxWidth
            },
            table: true
        }
    } );
}() );