Difference between revisions of "MediaWiki:Gadget-calculator-anatomyPhysiology.js"
From WikiAnesthesia
Chris Rishel (talk | contribs) |
Chris Rishel (talk | contribs) |
||
Line 511: | Line 511: | ||
} | } | ||
} | } | ||
} ); | }, 'SimpleCalculation' ); | ||
var tableMaxWidth = 600; | var tableMaxWidth = 600; |
Revision as of 11:35, 9 August 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( { pcthct: { baseName: 'hgb', digits: 0 }, ghgbperdL: { baseName: 'hgb', digits: 1, prefixes: 'short', definition: '3 pcthct' } } ); mw.calculators.addVariables( { caseDuration: { name: 'Case duration', type: 'number', abbreviation: 'Duration', maxLength: 3, units: [ 'hr', 'min' ] }, hct: { name: 'Current hematocrit', type: 'number', abbreviation: 'Current hct', defaultValue: '45 pcthct', maxLength: 4, units: [ 'pcthct', 'ghgbperdL' ] }, minHct: { name: 'Minimum hematocrit', type: 'number', abbreviation: 'Min hct', defaultValue: '21 pcthct', maxLength: 4, units: [ 'pcthct', 'ghgbperdL' ] }, npoTime: { name: 'Time spent NPO', type: 'number', abbreviation: 'NPO time', defaultValue: '8 hr', maxLength: 2, units: [ 'hr' ] }, surgicalTrauma: { name: 'Severity of surgical trauma', type: 'string', abbreviation: 'Surgical trauma', defaultValue: 'Minimal', options: [ 'Minimal', 'Moderate', 'Severe' ] } } ); 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'; } } }, systolicBloodPressure: { name: 'Systolic blood pressure', abbreviation: 'SBP', data: { variables: { required: [ 'age' ] } }, type: 'string', references: [ 'Baby Miller 6e, ch. 16, pg. 550' ], calculate: function( data ) { var age = data.age.toNumber( 'yo' ); var systolicMin, systolicMax, diastolicMin, diastolicMax, meanMin, meanMax; if( age >= 16 ) { systolicMin = 100; systolicMax = 125; } else if( age >= 13 ) { systolicMin = 95; systolicMax = 120; } else if( age >= 9 ) { systolicMin = 90; systolicMax = 115; } else if( age >= 6 ) { systolicMin = 85; systolicMax = 105; } else if( age >= 3 ) { systolicMin = 80; systolicMax = 100; } else if( age >= 1 ) { systolicMin = 75; systolicMax = 95; } else if( age >= 6 / 12 ) { systolicMin = 70; systolicMax = 90; } else if( age >= 1 / 12 ) { systolicMin = 65; systolicMax = 85; } else { systolicMin = 60; systolicMax = 75; } } }, bmi: { name: 'Body mass index', abbreviation: 'BMI', data: { variables: { required: [ 'weight', 'height' ] } }, digits: 0, units: 'kg/m^2', formula: '<math>\\mathrm{BMI} = \\frac{\\mathrm{mass_{kg}}}{{\\mathrm{height_{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' ] } }, digits: 2, units: 'm^2', formula: '<math>\\mathrm{BSA} = \\sqrt{\\frac{\\mathrm{weight_{kg}}*\\mathrm{height_{cm}}}{3600}}</math>', link: false, references: [ 'Mosteller RD. Simplified calculation of body-surface area. N Engl J Med. 1987 Oct 22;317(17):1098. doi: 10.1056/NEJM198710223171717. PMID: 3657876.' ], calculate: function( data ) { return Math.sqrt( data.height.toNumber( 'cm' ) * data.weight.toNumber( 'kgwt' ) / 3600 ); } }, 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; } }, ettDepth: { name: 'Endotracheal tube depth', abbreviation: 'ETT depth', 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' ); var depth; if( age >= 12 ) { depth = '20+'; } else if( age >= 2 ) { // ( age / 2 ) + 12 depth = Math.round( age / 2 + 12 ); } else if( age >= 1 ) { depth = 12; } else if( age >= 0.5 ) { depth = 11; } else if( age >= 0 ) { depth = 9; } else { depth = '7-8'; } return depth + ' cm from teeth'; } }, ettSize: { name: 'Endotracheal tube size', abbreviation: 'ETT size', 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' ); var size; if( age >= 12 ) { size = '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 size = String( Math.floor( 2 * ( ( age + 16 ) / 4 ) ) / 2 ); } else if( age >= 0.5 ) { size = '3.5-4'; } else if( age >= 0 ) { size = '3-3.5'; } else { size = '2.5-3'; } return size + ' mm (ID)'; } }, 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; } }, intraopFluids: { name: 'Intraoperative fluid dosing', abbreviation: 'Intraop fluids', data: { calculations: { required: [ 'fluidMaintenanceRate' ] }, variables: { required: [ 'weight', 'npoTime', 'surgicalTrauma' ] } }, type: 'string', references: [ 'Corcoran T, Rhodes JE, Clarke S, Myles PS, Ho KM. Perioperative fluid management strategies in major surgery: a stratified meta-analysis. Anesth Analg. 2012 Mar;114(3):640-51. doi: 10.1213/ANE.0b013e318240d6eb. Epub 2012 Jan 16. PMID: 22253274.' ], calculate: function( data ) { var weight = data.weight.toNumber( 'kgwt' ); var maintenanceRate = data.fluidMaintenanceRate.toNumber( 'mL/hr' ); var npoTime = data.npoTime.toNumber( 'hr' ); var surgicalTrauma = data.surgicalTrauma; var output = ''; var npoDeficit = npoTime * maintenanceRate; var surgicalLossMin, surgicalLossMax; if( surgicalTrauma === 'Minimal' ) { surgicalLossMin = 2 * weight; surgicalLossMax = 4 * weight; } else if( surgicalTrauma === 'Moderate' ) { surgicalLossMin = 4 * weight; surgicalLossMax = 6 * weight; } else { surgicalLossMin = 6 * weight; surgicalLossMax = 8 * weight; } var firstHour = Math.round( npoDeficit / 2 ) + maintenanceRate; var nextHoursMin = Math.round( npoDeficit / 4 ) + maintenanceRate + surgicalLossMin; var nextHoursMax = Math.round( npoDeficit / 4 ) + maintenanceRate + surgicalLossMax; var remainingHoursMin = maintenanceRate + surgicalLossMin; var remainingHoursMax = maintenanceRate + surgicalLossMax; output += 'NPO deficit: ' + Math.round( npoDeficit ) + ' mL<br/>'; output += 'Surgical losses: ' + surgicalLossMin + '-' + surgicalLossMax + ' mL/hr<br/>'; output += '1st hour: ' + firstHour + ' mL<br/>'; output += '2nd hour: ' + nextHoursMin + '-' + nextHoursMax + ' mL<br/>'; output += '3rd hour: ' + nextHoursMin + '-' + nextHoursMax + ' mL<br/>'; output += '4+ hours: ' + remainingHoursMin + '-' + remainingHoursMax + ' mL<br/>'; return output; } }, lmaSize: { name: 'Laryngeal mask airway size', abbreviation: 'LMA size', data: { variables: { required: [ 'weight' ] } }, type: 'string', references: [ 'Smith\'s Anesthesia for Infants and Children. 8e. p312' ], calculate: function( data ) { var weight = data.weight.toNumber( 'kgwt' ); var size; if( weight > 100 ) { size = '6'; } else if( weight > 70 ) { size = '5'; } else if( weight > 50 ) { size = '4'; } else if( weight > 30 ) { size = '3'; } else if( weight > 20 ) { size = '2.5'; } else if( weight > 10 ) { size = '2'; } else if( weight > 5 ) { size = '1.5'; } else { size = '1'; } return size; } }, maxAbl: { name: 'Maximum allowable blood loss', abbreviation: 'Max ABL', data: { calculations: { required: [ 'ebv' ] }, variables: { required: [ 'weight', 'age', 'hct', 'minHct' ] } }, digits: 0, units: 'mL', formula: '', references: [ 'Morgan & Mikhail\'s Clinical Anesthesiology. 5e. p1168' ], calculate: function( data ) { var currentHct = data.hct.toNumber( 'pcthct' ); var minHct = data.minHct.toNumber( 'pcthct' ); if( currentHct < minHct ) { return '-'; } return data.ebv.toNumber( 'mL' ) * ( currentHct - minHct ) / currentHct; } }, minUop: { name: 'Minimum urine output', abbreviation: 'Min UOP', data: { variables: { required: [ 'weight', 'age' ], optional: [ 'caseDuration' ] } }, type: 'string', formula: '', references: [ 'Klahr S, Miller SB. Acute oliguria. N Engl J Med. 1998 Mar 5;338(10):671-5. doi: 10.1056/NEJM199803053381007. PMID: 9486997.', 'Arant BS Jr. Postnatal development of renal function during the first year of life. Pediatr Nephrol. 1987 Jul;1(3):308-13. doi: 10.1007/BF00849229. PMID: 3153294.' ], calculate: function( data ) { var weight = data.weight.toNumber( 'kgwt' ); var age = data.age.toNumber( 'yo' ); var caseDuration = data.caseDuration ? data.caseDuration.toNumber( 'hr' ) : null; var minUop; if( age > 1 ) { minUop = 0.5 * weight; } else { minUop = 1 * weight; } if( caseDuration ) { minUop = minUop * caseDuration + ' mL'; } else { minUop = minUop + ' mL/hr'; } return minUop; } } }, 'SimpleCalculation' ); var tableMaxWidth = 600; mw.calculators.addCalculators( moduleId, { anatomy: { name: 'Patient statistics', calculations: [ 'bmi', 'bsa', 'ibw', 'lbw' ], css: { 'max-width': tableMaxWidth }, table: true }, airway: { name: 'Airway management', calculations: [ 'bladeMacSize', 'bladeMillerSize', 'ettSize', 'ettDepth', 'lmaSize' ], css: { 'max-width': tableMaxWidth }, table: true }, fluidManagement: { name: 'Fluid management', calculations: [ 'fluidMaintenanceRate', 'intraopFluids', 'ebv', 'maxAbl', 'minUop' ], css: { 'max-width': tableMaxWidth }, table: true } } ); }() );