Difference between revisions of "MediaWiki:Gadget-calculator-drugs-core.js"
From WikiAnesthesia
Chris Rishel (talk | contribs) (Created page with "→* * @author Chris Rishel: ( function() { mw.calculators.drugColors = {}; mw.calculators.addDrugColors = function( drugColorData ) { var drugColors = mw....") |
Chris Rishel (talk | contribs) |
||
| Line 3: | Line 3: | ||
*/ | */ | ||
( function() { | ( function() { | ||
/** | |||
* DrugColor | |||
*/ | |||
mw.calculators.drugColors = {}; | mw.calculators.drugColors = {}; | ||
| Line 10: | Line 14: | ||
for( var drugColorId in drugColors ) { | for( var drugColorId in drugColors ) { | ||
mw.calculators.drugColors[ drugColorId ] = drugColors[ drugColorId ]; | mw.calculators.drugColors[ drugColorId ] = drugColors[ drugColorId ]; | ||
} | |||
}; | |||
mw.calculators.getDrugColor = function( drugColorId ) { | |||
if( mw.calculators.drugColors.hasOwnProperty( drugColorId ) ) { | |||
return mw.calculators.drugColors[ drugColorId ]; | |||
} else { | |||
return null; | |||
} | } | ||
}; | }; | ||
| Line 25: | Line 37: | ||
], | ], | ||
optional: [ | optional: [ | ||
'parentColor', | |||
'primaryColor', | |||
'highlightColor', | 'highlightColor', | ||
'striped' | 'striped' | ||
] | ] | ||
| Line 32: | Line 45: | ||
mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues ); | mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues ); | ||
} | |||
if( !this.primaryColor && !this.parentColor ) { | |||
throw new Error( 'Drug color "' + this.id + '" must define either a primary color or a parent color.' ); | |||
} | |||
}; | |||
mw.calculators.objectClasses.DrugColor.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype ); | mw.calculators.objectClasses.DrugColor.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype ); | ||
mw.calculators.objectClasses.DrugColor.getParentDrugColor = function() { | |||
if( !this.parentColor ) { | |||
return null; | |||
} | |||
var parentDrugColor = mw.calculators.getDrugColor( this.parentColor ); | |||
if( !parentDrugColor ) { | |||
throw new Error( 'Parent drug color "' + this.parentColor + '" not found for drug color "' + this.id + '"' ); | |||
} | |||
return parentDrugColor; | |||
}; | |||
mw.calculators.objectClasses.DrugColor.getHighlightColor = function() { | |||
if( this.highlightColor ) { | |||
return this.highlightColor; | |||
} else if( this.parentColor ) { | |||
return this.getParentDrugColor().getHighlightColor(); | |||
} | |||
}; | |||
mw.calculators.objectClasses.DrugColor.getPrimaryColor = function() { | |||
if( this.primaryColor ) { | |||
return this.primaryColor; | |||
} else if( this.parentColor ) { | |||
return this.getParentDrugColor().getPrimaryColor(); | |||
} | |||
}; | |||
mw.calculators.objectClasses.DrugColor.isStriped = function() { | |||
if( this.striped !== null ) { | |||
return this.striped; | |||
} else if( this.parentColor ) { | |||
return this.getParentDrugColor().isStriped(); | |||
} | |||
}; | |||
/** | |||
* DrugPopulation | |||
*/ | |||
mw.calculators.drugPopulations = {}; | |||
mw.calculators.addDrugPopulations = function( drugPopulationData ) { | |||
var drugPopulations = mw.calculators.createCalculatorObjects( 'DrugPopulation', drugPopulationData ); | |||
for( var drugPopulationId in drugPopulations ) { | |||
mw.calculators.drugPopulations[ drugPopulationId ] = drugPopulations[ drugPopulationId ]; | |||
} | |||
}; | |||
mw.calculators.getDrugPopulation = function( drugPopulationId ) { | |||
if( mw.calculators.drugPopulations.hasOwnProperty( drugPopulationId ) ) { | |||
return mw.calculators.drugPopulations[ drugPopulationId ]; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* Class DrugPopulation | |||
* @param {Object} propertyValues | |||
* @returns {mw.calculators.objectClasses.DrugPopulation} | |||
* @constructor | |||
*/ | |||
mw.calculators.objectClasses.DrugPopulation = function( propertyValues ) { | |||
var properties = { | |||
required: [ | |||
'id', | |||
'name' | |||
], | |||
optional: [ | |||
'abbreviation', | |||
'variables' | |||
] | |||
}; | |||
mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues ); | |||
if( this.variables ) { | |||
for( var variableId in this.variables ) { | |||
if( !mw.calculators.getVariable( variableId ) ) { | |||
throw new Error( 'DrugPopulation variable "' + variableId + '" not defined' ); | |||
} | |||
} | |||
} | |||
}; | |||
mw.calculators.objectClasses.DrugPopulation.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype ); | |||
/** | |||
* DrugIndication | |||
*/ | |||
mw.calculators.drugIndications = {}; | |||
mw.calculators.addDrugIndications = function( drugIndicationData ) { | |||
var drugIndications = mw.calculators.createCalculatorObjects( 'DrugIndication', drugIndicationData ); | |||
for( var drugIndicationId in drugIndications ) { | |||
mw.calculators.drugPopulations[ drugIndicationId ] = drugIndications[ drugIndicationId ]; | |||
} | |||
}; | |||
mw.calculators.getDrugIndication = function( drugIndicationId ) { | |||
if( mw.calculators.drugIndications.hasOwnProperty( drugIndicationId ) ) { | |||
return mw.calculators.drugIndications[ drugIndicationId ]; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* Class DrugIndication | |||
* @param {Object} propertyValues | |||
* @returns {mw.calculators.objectClasses.DrugIndication} | |||
* @constructor | |||
*/ | |||
mw.calculators.objectClasses.DrugIndication = function( propertyValues ) { | |||
var properties = { | |||
required: [ | |||
'id', | |||
'name' | |||
], | |||
optional: [ | |||
'abbreviation' | |||
] | |||
}; | |||
mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues ); | |||
}; | |||
mw.calculators.objectClasses.DrugIndication.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype ); | |||
/** | |||
* Drug data | |||
*/ | |||
mw.calculators.addDrugColors( { | mw.calculators.addDrugColors( { | ||
anticholinergic: { | |||
primaryColor: '#00ac8c' | |||
}, | |||
benzodiazepine: { | |||
primaryColor: '#ff6c2f' | |||
}, | |||
benzodiazepineReversal: { | |||
parentColor: 'benzodiazepine', | |||
striped: true | |||
}, | |||
cardiovascularAgonist: { | |||
primaryColor: '#ba93df' | |||
}, | |||
cardiovascularAntagonist: { | |||
parentColor: 'cardiovascularAgonist', | |||
striped: true | |||
}, | |||
default: { | |||
primaryColor: '#fff' | |||
}, | |||
desflurane: { | |||
primaryColor: '#0ab8fd' | |||
}, | |||
enflurane: { | |||
primaryColor: '#f58733' | |||
}, | |||
epinephrine: { | |||
parentColor: 'cardiovascularAntagonist', | |||
highlightColor: '#000' | |||
}, | |||
halothane: { | |||
primaryColor: '#b20107' | |||
}, | |||
isoflurane: { | |||
primaryColor: '#ca7fc0' | |||
}, | |||
localAnesthetic: { | |||
primaryColor: '#dad9d6' | |||
}, | |||
neuromuscularBlocker: { | |||
primaryColor: '#fe5442' | |||
}, | |||
neuromuscularBlockerReversal: { | |||
parentColor: 'neuromuscularBlocker', | |||
striped: true | |||
}, | |||
nitrousOxide: { | |||
primaryColor: '#2d549f' | |||
}, | |||
opioid: { | |||
primaryColor: '#6cd1ef' | |||
}, | |||
opioidReversal: { | |||
parentColor: 'opioid', | |||
striped: true | |||
}, | |||
sedativeHypnotic: { | sedativeHypnotic: { | ||
primaryColor: '#ffe800' | primaryColor: '#ffe800' | ||
}, | |||
sevoflurane: { | |||
primaryColor: '#f8da00' | |||
}, | |||
succinylcholine: { | |||
parentColor: 'neuromuscularBlocker', | |||
highlightColor: '#000' | |||
} | } | ||
} ); | } ); | ||
mw.calculators.addDrugPopulations( { | |||
general: { | |||
name: 'General', | |||
abbreviation: 'Gen.' | |||
}, | |||
neonatal: { | |||
name: 'Neonatal', | |||
abbreviation: 'Neo.', | |||
variables: { | |||
age: { | |||
max: '0 yo' | |||
} | |||
} | |||
}, | |||
pediatric: { | |||
name: 'Pediatric', | |||
abbreviation: 'Ped.', | |||
variables: { | |||
age: { | |||
min: '0 yo', | |||
max: '17.9 yo' | |||
} | |||
} | |||
}, | |||
elderly: { | |||
name: 'Elderly', | |||
abbreviation: 'Eld.', | |||
variables: { | |||
age: { | |||
min: '65 yo' | |||
} | |||
} | |||
} | |||
} ); | |||
/** | |||
* DrugIndications | |||
*/ | |||
mw.calculators.addDrugIndications( { | |||
generalAnesthesia: { | |||
name: 'General anesthesia', | |||
abbreviation: 'GA' | |||
} | |||
} ); | |||
/** | |||
* Drug | |||
*/ | |||
var drugs = { | var drugs = { | ||
cefazolin: { | |||
name: 'Cefazolin', | |||
dosages: { | |||
} | |||
}, | |||
propofol: { | propofol: { | ||
color: 'sedativeHypnotic', | color: 'sedativeHypnotic', | ||
| Line 53: | Line 340: | ||
}; | }; | ||
/** | |||
* DrugDosage | |||
* | |||
* Structure is: | |||
* | |||
* drugId: { | |||
* indicationId: { | |||
* doseId: { | |||
* | |||
* } | |||
* } | |||
* } | |||
*/ | |||
var drugDosages = { | |||
cefazolin: { | |||
abxProphylaxis: { | |||
general: { | |||
population: 'general', | |||
dose: '2 g' | |||
}, | |||
general120kg: { | |||
population: { | |||
id: 'general', | |||
variables: { | |||
weight: { | |||
min: '120 kg' | |||
} | |||
} | |||
}, | |||
dose: '3 g' | |||
}, | |||
pediatric: { | |||
dose: { | |||
absoluteMax: '2 g', | |||
dose: '30 mg/kg' | |||
} | |||
}, | |||
pediatric120kg: { | |||
population: { | |||
id: 'pediatric', | |||
variables: { | |||
weight: { | |||
min: '120 kg' | |||
} | |||
} | |||
}, | |||
dose: { | |||
dose: '3 g' | |||
} | |||
} | |||
} | |||
}, | |||
propofol: { | |||
generalAnesthesia: { | |||
general: { | |||
population: 'general', | |||
dose: [ | |||
{ | |||
name: 'Induction', | |||
min: '1 mg/kg', | |||
max: '2.5 mg/kg', | |||
weightCalculation: 'lbw' | |||
}, { | |||
name: 'Maintenance', | |||
min: '100 mcg/kg/min', | |||
max: '200 mcg/kg/min', | |||
weightCalculation: 'tbw' | |||
} | |||
], | |||
route: 'IV' | |||
}, | |||
pediatric: { | |||
population: { | |||
id: 'pediatric', | |||
variables: { | |||
age: { | |||
min: '3 yo', | |||
max: '16 yo' | |||
} | |||
} | |||
}, | |||
dose: [ | |||
{ | |||
name: 'Induction', | |||
min: '2.5 mg/kg', | |||
max: '3.5 mg/kg', | |||
weightCalculation: 'lbw' | |||
}, { | |||
name: 'Maintenance', | |||
min: '125 mcg/kg/min', | |||
max: '300 mcg/kg/min', | |||
weightCalculation: 'tbw' | |||
} | |||
], | |||
route: 'IV' | |||
}, | |||
elderly: { | |||
population: 'elderly', | |||
dose: [ | |||
{ | |||
name: 'Induction', | |||
min: '1 mg/kg', | |||
max: '1.5 mg/kg', | |||
weightCalculation: 'lbw' | |||
}, { | |||
name: 'Maintenance', | |||
min: '50 mcg/kg/min', | |||
max: '100 mcg/kg/min', | |||
weightCalculation: 'tbw' | |||
} | |||
] | |||
} | |||
}, | |||
mac: { | |||
general: { | |||
} | |||
} | |||
} | |||
}; | |||
}() ); | }() ); | ||
Revision as of 13:25, 7 August 2021
/**
* @author Chris Rishel
*/
( function() {
/**
* DrugColor
*/
mw.calculators.drugColors = {};
mw.calculators.addDrugColors = function( drugColorData ) {
var drugColors = mw.calculators.createCalculatorObjects( 'DrugColor', drugColorData );
for( var drugColorId in drugColors ) {
mw.calculators.drugColors[ drugColorId ] = drugColors[ drugColorId ];
}
};
mw.calculators.getDrugColor = function( drugColorId ) {
if( mw.calculators.drugColors.hasOwnProperty( drugColorId ) ) {
return mw.calculators.drugColors[ drugColorId ];
} else {
return null;
}
};
/**
* Class DrugColor
* @param {Object} propertyValues
* @returns {mw.calculators.objectClasses.DrugColor}
* @constructor
*/
mw.calculators.objectClasses.DrugColor = function( propertyValues ) {
var properties = {
required: [
'id'
],
optional: [
'parentColor',
'primaryColor',
'highlightColor',
'striped'
]
};
mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues );
if( !this.primaryColor && !this.parentColor ) {
throw new Error( 'Drug color "' + this.id + '" must define either a primary color or a parent color.' );
}
};
mw.calculators.objectClasses.DrugColor.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype );
mw.calculators.objectClasses.DrugColor.getParentDrugColor = function() {
if( !this.parentColor ) {
return null;
}
var parentDrugColor = mw.calculators.getDrugColor( this.parentColor );
if( !parentDrugColor ) {
throw new Error( 'Parent drug color "' + this.parentColor + '" not found for drug color "' + this.id + '"' );
}
return parentDrugColor;
};
mw.calculators.objectClasses.DrugColor.getHighlightColor = function() {
if( this.highlightColor ) {
return this.highlightColor;
} else if( this.parentColor ) {
return this.getParentDrugColor().getHighlightColor();
}
};
mw.calculators.objectClasses.DrugColor.getPrimaryColor = function() {
if( this.primaryColor ) {
return this.primaryColor;
} else if( this.parentColor ) {
return this.getParentDrugColor().getPrimaryColor();
}
};
mw.calculators.objectClasses.DrugColor.isStriped = function() {
if( this.striped !== null ) {
return this.striped;
} else if( this.parentColor ) {
return this.getParentDrugColor().isStriped();
}
};
/**
* DrugPopulation
*/
mw.calculators.drugPopulations = {};
mw.calculators.addDrugPopulations = function( drugPopulationData ) {
var drugPopulations = mw.calculators.createCalculatorObjects( 'DrugPopulation', drugPopulationData );
for( var drugPopulationId in drugPopulations ) {
mw.calculators.drugPopulations[ drugPopulationId ] = drugPopulations[ drugPopulationId ];
}
};
mw.calculators.getDrugPopulation = function( drugPopulationId ) {
if( mw.calculators.drugPopulations.hasOwnProperty( drugPopulationId ) ) {
return mw.calculators.drugPopulations[ drugPopulationId ];
} else {
return null;
}
};
/**
* Class DrugPopulation
* @param {Object} propertyValues
* @returns {mw.calculators.objectClasses.DrugPopulation}
* @constructor
*/
mw.calculators.objectClasses.DrugPopulation = function( propertyValues ) {
var properties = {
required: [
'id',
'name'
],
optional: [
'abbreviation',
'variables'
]
};
mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues );
if( this.variables ) {
for( var variableId in this.variables ) {
if( !mw.calculators.getVariable( variableId ) ) {
throw new Error( 'DrugPopulation variable "' + variableId + '" not defined' );
}
}
}
};
mw.calculators.objectClasses.DrugPopulation.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype );
/**
* DrugIndication
*/
mw.calculators.drugIndications = {};
mw.calculators.addDrugIndications = function( drugIndicationData ) {
var drugIndications = mw.calculators.createCalculatorObjects( 'DrugIndication', drugIndicationData );
for( var drugIndicationId in drugIndications ) {
mw.calculators.drugPopulations[ drugIndicationId ] = drugIndications[ drugIndicationId ];
}
};
mw.calculators.getDrugIndication = function( drugIndicationId ) {
if( mw.calculators.drugIndications.hasOwnProperty( drugIndicationId ) ) {
return mw.calculators.drugIndications[ drugIndicationId ];
} else {
return null;
}
};
/**
* Class DrugIndication
* @param {Object} propertyValues
* @returns {mw.calculators.objectClasses.DrugIndication}
* @constructor
*/
mw.calculators.objectClasses.DrugIndication = function( propertyValues ) {
var properties = {
required: [
'id',
'name'
],
optional: [
'abbreviation'
]
};
mw.calculators.objectClasses.CalculatorObject.call( this, properties, propertyValues );
};
mw.calculators.objectClasses.DrugIndication.prototype = Object.create( mw.calculators.objectClasses.CalculatorObject.prototype );
/**
* Drug data
*/
mw.calculators.addDrugColors( {
anticholinergic: {
primaryColor: '#00ac8c'
},
benzodiazepine: {
primaryColor: '#ff6c2f'
},
benzodiazepineReversal: {
parentColor: 'benzodiazepine',
striped: true
},
cardiovascularAgonist: {
primaryColor: '#ba93df'
},
cardiovascularAntagonist: {
parentColor: 'cardiovascularAgonist',
striped: true
},
default: {
primaryColor: '#fff'
},
desflurane: {
primaryColor: '#0ab8fd'
},
enflurane: {
primaryColor: '#f58733'
},
epinephrine: {
parentColor: 'cardiovascularAntagonist',
highlightColor: '#000'
},
halothane: {
primaryColor: '#b20107'
},
isoflurane: {
primaryColor: '#ca7fc0'
},
localAnesthetic: {
primaryColor: '#dad9d6'
},
neuromuscularBlocker: {
primaryColor: '#fe5442'
},
neuromuscularBlockerReversal: {
parentColor: 'neuromuscularBlocker',
striped: true
},
nitrousOxide: {
primaryColor: '#2d549f'
},
opioid: {
primaryColor: '#6cd1ef'
},
opioidReversal: {
parentColor: 'opioid',
striped: true
},
sedativeHypnotic: {
primaryColor: '#ffe800'
},
sevoflurane: {
primaryColor: '#f8da00'
},
succinylcholine: {
parentColor: 'neuromuscularBlocker',
highlightColor: '#000'
}
} );
mw.calculators.addDrugPopulations( {
general: {
name: 'General',
abbreviation: 'Gen.'
},
neonatal: {
name: 'Neonatal',
abbreviation: 'Neo.',
variables: {
age: {
max: '0 yo'
}
}
},
pediatric: {
name: 'Pediatric',
abbreviation: 'Ped.',
variables: {
age: {
min: '0 yo',
max: '17.9 yo'
}
}
},
elderly: {
name: 'Elderly',
abbreviation: 'Eld.',
variables: {
age: {
min: '65 yo'
}
}
}
} );
/**
* DrugIndications
*/
mw.calculators.addDrugIndications( {
generalAnesthesia: {
name: 'General anesthesia',
abbreviation: 'GA'
}
} );
/**
* Drug
*/
var drugs = {
cefazolin: {
name: 'Cefazolin',
dosages: {
}
},
propofol: {
color: 'sedativeHypnotic',
name: 'Propofol',
preparations: [
'10 mg/mL'
]
}
};
/**
* DrugDosage
*
* Structure is:
*
* drugId: {
* indicationId: {
* doseId: {
*
* }
* }
* }
*/
var drugDosages = {
cefazolin: {
abxProphylaxis: {
general: {
population: 'general',
dose: '2 g'
},
general120kg: {
population: {
id: 'general',
variables: {
weight: {
min: '120 kg'
}
}
},
dose: '3 g'
},
pediatric: {
dose: {
absoluteMax: '2 g',
dose: '30 mg/kg'
}
},
pediatric120kg: {
population: {
id: 'pediatric',
variables: {
weight: {
min: '120 kg'
}
}
},
dose: {
dose: '3 g'
}
}
}
},
propofol: {
generalAnesthesia: {
general: {
population: 'general',
dose: [
{
name: 'Induction',
min: '1 mg/kg',
max: '2.5 mg/kg',
weightCalculation: 'lbw'
}, {
name: 'Maintenance',
min: '100 mcg/kg/min',
max: '200 mcg/kg/min',
weightCalculation: 'tbw'
}
],
route: 'IV'
},
pediatric: {
population: {
id: 'pediatric',
variables: {
age: {
min: '3 yo',
max: '16 yo'
}
}
},
dose: [
{
name: 'Induction',
min: '2.5 mg/kg',
max: '3.5 mg/kg',
weightCalculation: 'lbw'
}, {
name: 'Maintenance',
min: '125 mcg/kg/min',
max: '300 mcg/kg/min',
weightCalculation: 'tbw'
}
],
route: 'IV'
},
elderly: {
population: 'elderly',
dose: [
{
name: 'Induction',
min: '1 mg/kg',
max: '1.5 mg/kg',
weightCalculation: 'lbw'
}, {
name: 'Maintenance',
min: '50 mcg/kg/min',
max: '100 mcg/kg/min',
weightCalculation: 'tbw'
}
]
}
},
mac: {
general: {
}
}
}
};
}() );