MediaWiki:Gadget-calculator-respiratory.js

From WikiAnesthesia

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
( function() {
    mw.calculators.addUnitsBases( {
        o2: {
            toString: function( units ) {
                units = units.replace( /\s?pcto2/, '%' );

                return units;
            }
        }
    } );

    mw.calculators.addUnits( {
        breaths: {
            baseName: 'breaths'
        },
        pcto2: {
            baseName: 'o2'
        }
    } );

    mw.calculators.addVariables( {
        fiO2: {
            name: 'FiO<sub>2</sub>',
            type: 'number',
            abbreviation: 'FiO<sub>2</sub>',
            minValue: '10 pcto2',
            maxValue: '100 pcto2',
            defaultValue: '21 pcto2',
            maxLength: 3,
            units: [
                'pcto2'
            ]
        },
        paCO2: {
            name: 'PaCO<sub>2</sub>',
            type: 'number',
            abbreviation: 'PaCO<sub>2</sub>',
            minValue: '20 mmHg',
            defaultValue: '40 mmHg',
            maxLength: 3,
            units: [
                'mmHg'
            ]
        },
        paO2: {
            name: 'PaO<sub>2</sub>',
            type: 'number',
            abbreviation: 'PaO<sub>2</sub>',
            minValue: '25 mmHg',
            defaultValue: '100 mmHg',
            maxLength: 3,
            units: [
                'mmHg'
            ]
        },
        pAtm: {
            name: 'Atmospheric pressure',
            type: 'number',
            abbreviation: 'P<sub>atm</sub>',
            minValue: '0 mmHg',
            defaultValue: '760 mmHg',
            maxLength: 4,
            units: [
                'mmHg'
            ]
        },
        raceSpirometry: {
            name: 'Race',
            type: 'string',
            abbreviation: 'Race',
            defaultValue: 'unknown',
            options: {
                unknown: 'Unknown',
                black: 'Black',
                caucasian: 'Caucasian',
                mexican: 'Mexican-American'
            }
        },
        respiratoryRate: {
            name: 'Respiratory rate',
            type: 'number',
            abbreviation: 'RR',
            minValue: '1 breaths/min',
            maxValue: '50 breaths/min',
            defaultValue: '12 breaths/min',
            maxLength: 2,
            units: [
                'breaths/min'
            ]
        },
        tidalVolume: {
            name: 'Tidal volume',
            type: 'number',
            abbreviation: 'TV',
            minValue: '10 mL',
            maxValue: '2500 mL',
            defaultValue: '500 mL',
            maxLength: 4,
            units: [
                'mL'
            ]
        },
        weightBasedTidalVolumePerKgMin: {
            name: 'Minimum tidal volume',
            type: 'number',
            abbreviation: 'Min TV',
            minValue: '3 mL/kgwt',
            maxValue: '12 mL/kgwt',
            defaultValue: '6 mL/kgwt',
            maxLength: 2,
            units: [
                'mL/kgwt'
            ]
        },
        weightBasedTidalVolumePerKgMax: {
            name: 'Maximum tidal volume',
            type: 'number',
            abbreviation: 'Max TV',
            minValue: '3 mL/kgwt',
            maxValue: '12 mL/kgwt',
            defaultValue: '8 mL/kgwt',
            maxLength: 2,
            units: [
                'mL/kgwt'
            ]
        }
    } );

    // Force re-render of ibw.
    // This is necessary to remove the additional inputs for patient variables
    // from the calculation which are now provided by the patient input toolbar.
    mw.calculators.calculations.ibw.render();

    mw.calculators.addCalculations( {
        paO2Predicted: {
            name: 'PaO<sub>2</sub> (predicted)',
            abbreviation: 'PaO<sub>2</sub> pred.',
            data: {
                variables: {
                    required: [ 'pAtm', 'fiO2', 'paCO2' ]
                }
            },
            units: 'mmHg',
            formula: '<math>P_{aO_2Predicted} = FiO_2*(P_{atm}-P_{H_{2}O})-\\frac{P_{aCO_2}}{R}</math>',
            references: [
                'McFarlane MJ, Imperiale TF. Use of the alveolar-arterial oxygen gradient in the diagnosis of pulmonary embolism. Am J Med. 1994 Jan;96(1):57-62. doi: 10.1016/0002-9343(94)90116-3. PMID: 8304364.'
            ],
            searchData: 'PaO2',
            calculate: function( data ) {
                var fiO2 = data.fiO2.toNumber( 'pcto2' ) / 100;
                var pAtm = data.pAtm.toNumber( 'mmHg' );
                var pH2O = 47; // mmHg
                var paCO2 = data.paCO2.toNumber( 'mmHg' );
                var r = 0.8;

                return fiO2 * ( pAtm - pH2O ) - paCO2 / r;
            }
        },
        aaGradientO2: {
            name: 'A-a O<sub>2</sub> gradient',
            abbreviation: 'A-a O<sub>2</sub>',
            data: {
                calculations: {
                    required: [ 'paO2Predicted' ]
                },
                variables: {
                    required: [ 'paO2' ]
                }
            },
            units: 'mmHg',
            formula: '<math>\\text{A-a gradient}_{\\mathrm{O}_2} = P_{aO_2Predicted}-P_{aO_2} </math>',
            references: [
                'McFarlane MJ, Imperiale TF. Use of the alveolar-arterial oxygen gradient in the diagnosis of pulmonary embolism. Am J Med. 1994 Jan;96(1):57-62. doi: 10.1016/0002-9343(94)90116-3. PMID: 8304364.'
            ],
            searchData: 'Aa gradient',
            calculate: function( data ) {
                var paO2Predicted = data.paO2Predicted.toNumber( 'mmHg' );
                var paO2 = data.paO2.toNumber( 'mmHg' );

                return math.round( paO2Predicted - paO2 );
            }
        },
        aaGradientO2Predicted: {
            name: 'A-a O<sub>2</sub> gradient (predicted)',
            abbreviation: 'A-a O<sub>2</sub> pred.',
            data: {
                variables: {
                    required: [ 'age' ]
                }
            },
            units: 'mmHg',
            formula: '<math>\\text{Predicted A-a gradient}_{\\mathrm{O}_2} = \\frac{(\\mathrm{age_{yr} + 10)}}{4}</math>',
            references: [
                'Hantzidiamantis PJ, Amaro E. Physiology, Alveolar to Arterial Oxygen Gradient. 2021 Feb 22. In: StatPearls [Internet]. Treasure Island (FL): StatPearls Publishing; 2021 Jan–. PMID: 31424737.'
            ],
            searchData: 'Aa gradient',
            calculate: function( data ) {
                var age = data.age.toNumber( 'yr' );

                return ( age + 10 ) / 4;
            }
        },
        rapidShallowBreathingIndex: {
            name: 'Rapid shallow breathing index',
            abbreviation: 'RSBI',
            data: {
                variables: {
                    required: [ 'respiratoryRate', 'tidalVolume' ]
                }
            },
            units: 'breaths/min/L',
            formula: '<math>\\text{RSBI}= \\frac{\\text{Respiratory rate}}{\\text{Tidal volume}}</math>',
            description: '<ul><li>RSBI < 105: Successful extubation likely</li><li>RSBI > 105: Likely to fail extubation</li>',
            references: [
                'Yang KL, Tobin MJ. A prospective study of indexes predicting the outcome of trials of weaning from mechanical ventilation. N Engl J Med. 1991 May 23;324(21):1445-50. doi: 10.1056/NEJM199105233242101. PMID: 2023603.'
            ],
            searchData: 'Extubation',
            calculate: function( data ) {
                var respiratoryRate = data.respiratoryRate.toNumber( 'breaths/min' );
                var tidalVolume = data.tidalVolume.toNumber( 'L' );

                return math.round( respiratoryRate / tidalVolume );
            }
        },
        weightBasedTidalVolume: {
            name: 'Weight-based tidal volume',
            abbreviation: 'Weight-based TV',
            data: {
                calculations: {
                    required: [ 'ibw' ]
                },
                variables: {
                    required: [ 'weightBasedTidalVolumePerKgMin', 'weightBasedTidalVolumePerKgMax' ]
                }
            },
            searchData: 'Low tidal volume',
            type: 'string',
            description: '<ul><li>Calculated using ideal body weight</li><li>Low tidal volume uses 6-8 mL/kg<sup>1</sup><ul><li>Current evidence does not show benefit of intraoperative low tidal volumes for patients without pulmonary injury<sup>2</sup></li></ul></li>',
            references: [
                'Acute Respiratory Distress Syndrome Network, Brower RG, Matthay MA, Morris A, Schoenfeld D, Thompson BT, Wheeler A. Ventilation with lower tidal volumes as compared with traditional tidal volumes for acute lung injury and the acute respiratory distress syndrome. N Engl J Med. 2000 May 4;342(18):1301-8. doi: 10.1056/NEJM200005043421801. PMID: 10793162.',
                'Karalapillai D, Weinberg L, Peyton P, Ellard L, Hu R, Pearce B, Tan CO, Story D, O\'Donnell M, Hamilton P, Oughton C, Galtieri J, Wilson A, Serpa Neto A, Eastwood G, Bellomo R, Jones DA. Effect of Intraoperative Low Tidal Volume vs Conventional Tidal Volume on Postoperative Pulmonary Complications in Patients Undergoing Major Surgery: A Randomized Clinical Trial. JAMA. 2020 Sep 1;324(9):848-858. doi: 10.1001/jama.2020.12866. PMID: 32870298; PMCID: PMC7489812.'
            ],
            calculate: function( data ) {
                var ibw = data.ibw.toNumber( 'kgwt' );
                var weightBasedTidalVolumePerKgMin = data.weightBasedTidalVolumePerKgMin.toNumber( 'mL/kgwt' );
                var weightBasedTidalVolumePerKgMax = data.weightBasedTidalVolumePerKgMax.toNumber( 'mL/kgwt' );

                return math.round( weightBasedTidalVolumePerKgMin * ibw ) + '-' + math.round( weightBasedTidalVolumePerKgMax * ibw ) + ' mL';
            }
        }
    } );
}() );