/** * Program: models_30DayMortality.js.js * @date 10/20/2022 * @author Stephan K Eisenbarth * Organization: VA CART * 30-Day Mortality: Colin O'Donnell * Description: JavaScript file containing the function calls for 30-Day Mortality */ //<30DAYMORTALITYCODE> /** * @author Stephan K Eisenbarth * @date 11/21/2019 * Description: Processes the 30 Day Mortality Risk After PCI form * @param parFormID String containing the 30 Day Mortality form's ID * @return outArr String array containing the values of successfully processing the 30 Day Mortality After PCI Risk model */ function processForm_30DayMortalityRiskPCI (parFormID) { var outArr = null; var errMess = null; var errTitle = "30 Day Mortality Afer PCI - "; var x = getElemInput (parFormID, "ageFld"); if (checkVal_Age (25, 99) == true) { x = getElemInput (parFormID, "heightFld"); if (isEmpty (x.value) == true || x.value == "null") { errMess = errTitle + "Height (in inches) text field cannot be empty"; } else { if (checkVal_Height () == true) { var heightVal = parseInt (x.value); x = getElemInput (parFormID, "weightLbsFld"); if (isEmpty(x.value) == true) { errMess = errTitle + "Weight (in pounds) text field cannot be empty"; } else { if (checkVal_Weight () == true) { var weightVal = parseFloat (x.value); x = getElemInput (parFormID, "statusMenu"); if (isEmpty(x.value) == true || x.value == "NULL") { errMess = errTitle + "PCI Status menu cannot be empty"; } else { x = getElemInput (parFormID, "indicaMenu"); if (isEmpty(x.value) == true || x.value == "NULL") { errMess = errTitle + "Indication menu cannot be empty"; } else { x = getElemInput (parFormID, "HgBFld"); if (isEmpty(x.value) == true) { errMess = errTitle + "Hemoglobin value cannot be empty"; } else { if (checkVal_Hemoglobin () == true) { x = getElemInput (parFormID, "inrFld"); if (isEmpty(x.value) == true) { errMess = errTitle + "INR (Standardized Prothrombin Time) value cannot be empty"; } else { if (checkVal_INR () == true) { x = getElemInput (parFormID, "syntaxScoreFld"); if (isDouble (x.value) == false) { errMess = errTitle + "Syntax score field must be a decimal"; } else { // Fields filled out so run 30 Day Mortality After PCI calculation outArr = calc30MortalityRisk (parFormID); } } } } } } } } } } } } else { errMess = errTitle + "Age invalid, must be between 25 and 99"; } if (errMess != null) { alert (errMess); if (currModel != "mortality_Area") { changeModel ("mortalityBtn"); } if (x != null) { getElementFromCurrModel(x.id).focus (); } } return outArr; } /** * @author Stephan K Eisenbarth * @date 3/14/2018 * Description: Show the final results tables * @param parFormID String containing the 30 Day Mortality form's ID * @param tmpArr String array containing the RISK30DayMort Percentage, Lower Limit Confidence Interval Percentage, then the Upper Limit Confidence Interval Percentage */ function showResults_30DayMortality (parFormID, tmpArr) { if (tmpArr != null && tmpArr.length==3) { var str = "

VA Mortality Model

" + "
" + "
" + "This risk estimate may be used to inform discussions of the risk/benefit of a PCI. Any clinical decisions related to the need for or against any medical procedure are at the discretion of the treating provider." + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "30 Day Mortality After PCI Risk:" + "" + "" + tmpArr[0].toFixed(1) + "% (95% CI: " + tmpArr [1].toFixed(1) + ", " + tmpArr [2].toFixed(1) + ")" + "
" + "Based on a single model of all patients undergoing PCI, patients with similar characteristics would have a " + tmpArr[0].toFixed(1) + "% risk of mortality within 30 days after PCI." + "" + "
" + "

VA National Average:

" + "
" + "

1.7%

" + "
" + "
" + "
" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; // PCI status if (getElemInput (parFormID, "statusMenu").value == "elective") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "statusMenu").value == "emergent") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "statusMenu").value == "salvage") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "statusMenu").value == "urgent") { str += "" + "" + "" + ""; } // Indication if (getElemInput (parFormID, "indicaMenu").value == "Stable Angina") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "indicaMenu").value == "Unstable Angina") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "indicaMenu").value == "STEMI") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "indicaMenu").value == "NSTEMI") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "indicaMenu").value == "Chest Pain") { str += "" + "" + "" + ""; } else if (getElemInput (parFormID, "indicaMenu").value == "Other") { str += "" + "" + "" + ""; } if (getElemInput (parFormID, "CGS").checked == true) { str += "" + "" + "" + ""; } if (getElemInput (parFormID, "PriorCABG").checked == true) { str += "" + "" + "" + ""; } if (getElemInput (parFormID, "CKD").checked == true) { str += "" + "" + "" + ""; } str += "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "Metric" + "" + "Value" + "
" + "Age" + "" + getElemInput (parFormID, "ageFld").value + "
" + "Estimated BMI" + "
    " + "
  • " + "Height: " + getElemInput (parFormID, "heightFld").value + " (inches)" + "
  • " + "
  • " + "Weight: " + getElemInput (parFormID, "weightLbsFld").value + " (pounds)" + "
  • " + "
" + "
" + (parseFloat (getElemInput (parFormID, "bmiFld").value)).toFixed (2) + "
" + "Elective PCI" + "" + "Yes" + "
" + "Emergent PCI" + "" + "Yes" + "
" + "Salvage" + "" + "Yes" + "
" + "Urgent" + "" + "Yes" + "
" + "Stable Angina" + "" + "Yes" + "
" + "Unstable Angina" + "" + "Yes" + "
" + "STEMI" + "" + "Yes" + "
" + "NSTEMI" + "" + "Yes" + "
" + "Chest Pain" + "" + "Yes" + "
" + "Other Indication" + "" + "Yes" + "
" + "Cardiogenic Shock" + "" + "Yes" + "
" + "Prior CABG" + "" + "Yes" + "
" + "CKD" + "" + "Yes" + "
" + "Hemoglobin" + "" + getElemInput (parFormID, "HgBFld").value + " (g/dl)" + "
" + "VA Syntax Score" + "" + getElemInput (parFormID, "syntaxScoreFld").value + "
" + "INR" + "" + getElemInput (parFormID, "inrFld").value + "
" + "
"; document.getElementById ("resultsArea_mortalityArea").innerHTML = str; } } /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CALCULATION INFORMATION +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /** * @author Stephan K Eisenbarth * @date 3/14/2018 * Description: returns an array containing the covariate human readable names * @return varNameArr String array containing the covariate human readable names */ function get30DayMortVariableNamesArr () { var varNameArr = ["EMERGENT", "cardiogenicshock","SYNTAX","HgB","chf","AGE","URGENT","SALVAGE","priorcabg","INR","copd","stemi","PriorValvDz","bmi","AFIB","CKD"]; return varNameArr; } /** * @author Stephan K Eisenbarth * @date 11/21/2019 * Description: Calculates the associated 30 Day Mortality After PCI percentrage value based on the form's values * @param parFormID String containing the 30 Day Mortality form's ID */ function calc30MortalityRisk (parFormID) { var resultsArr = null; var covarArr = [17]; // Array of the initial covariate values var index = 0; // int index used to track the current place within the covariate value array var ok = true; // Whether form was properly filled out covarArr [index ++] = 1 // Intercept value is always 1 var EMERG = 0; if (getElemInput (parFormID, "statusMenu").value == "emergent") { EMERG = 1; } covarArr [index ++] = EMERG; var CGS = 0; if (getElemInput (parFormID, "CGS").checked) { CGS = 1; } covarArr [index ++] = CGS; var SYNTAX = getElemInput (parFormID, "syntaxScoreFld").value if (parseFloat (SYNTAX) < 0.1) { SYNTAX = 0.5; } // covarArr [index ++] = SYNTAX; covarArr [index ++] = Math.log (SYNTAX); covarArr [index ++] = getElemInput (parFormID, "HgBFld").value; var chf = 0; if (getElemInput (parFormID, "CHF").checked) { chf = 1; } covarArr [index ++] = chf; covarArr [index ++] = getElemInput (parFormID, "ageFld").value; var URGENT = 0; if (getElemInput (parFormID, "statusMenu").value == "urgent") { URGENT = 1; } covarArr [index ++] = URGENT; var SALV = 0; if (getElemInput (parFormID, "statusMenu").value == "salvage") { SALV = 1; } covarArr [index ++] = SALV; var PriorCABG = 0; if (getElemInput (parFormID, "PriorCABG").checked) { PriorCABG = 1; } covarArr [index ++] = PriorCABG; var INR = 0.0; var x = getElemInput (parFormID, "inrFld"); if (x.value == null || x.value == "" || x.value == " ") { ok = false; alert ("INR (Standardized Prothrombin Time) value cannot be empty"); x.focus (); } else { INR = Math.log (parseFloat (getElemInput (parFormID, "inrFld").value)); } covarArr [index ++] = INR; var COPD = 0; if (getElemInput (parFormID, "COPD").checked) { COPD = 1; } covarArr [index ++] = COPD; var STEMI = 0; if (getElemInput (parFormID, "indicaMenu").value == "STEMI") { STEMI = 1; } covarArr [index ++] = STEMI; var PriorValvDz = 0; if (getElemInput (parFormID, "PriorValvDz").checked) { PriorValvDz = 1; } covarArr [index ++] = PriorValvDz; var HEIGHT = 0; HEIGHT = parseInt (getElemInput (parFormID, "heightFld").value); var BMI = getBMI (HEIGHT, parseInt(getElemInput (parFormID, "weightLbsFld").value)); if (BMI < 1) { ok = false; } covarArr [index ++] = BMI; getElemInput (parFormID, "bmiFld").value = BMI; var AFIB = 0; if (getElemInput (parFormID, "AFIB").checked) { AFIB = 1; } covarArr [index ++] = AFIB; var CKD = 0; if (getElemInput (parFormID, "CKD").checked) { CKD = 1; } covarArr [index ++] = CKD; if (ok == true) { resultsArr = get30DayMortalityRisk (covarArr); showResults_30DayMortality (parFormID, resultsArr); } return resultsArr; } /** * @author Stephan K Eisenbarth * @date 11/21/2019 * Description: Calculates the associated In-Hospital percentrage value * @param tmpCovarArr Array containing the int covariate modified values * @return risk30DayMortArr Array containing the Risk percentage, the Lower Limit and Upper Limit confidence intervals */ function get30DayMortalityRisk (tmpCovarArr) { var risk30DayMortArr = null; var varNameArr = get30DayMortVariableNamesArr (); var final30DayMortRisk = 0.0; var RISK30DayMort = 0.0; if (tmpCovarArr != null && tmpCovarArr.length > 0) { // Values do exist within the tmpCovarArr object // Array of the covariate modifiers // Modifier Value Assocaited Covariate var modCovarArr = [-5.5744060, // Intercept 1.9830162, // EMERGENT 2.0604840, // cardiogenicshock 0.6292261, // SYNTAX -0.2056896, // HgB 0.7165258, // chf 0.0319361, // AGE 0.7322692, // URGENT 2.5334458, // SALVAGE -0.5033531, // priorcabg 1.0715679, // INR 0.2734635, // copd 0.5435716, // stemi 0.3574776, // PriorValvDz -0.0331556, // bmi 0.2593935, // AFIB 0.3072406]; // CKD // Generate CALC value by modify each covariate then adding everything together var LP = 0.0; for (var i = 0; i < tmpCovarArr.length; i++) { LP += (parseFloat(modCovarArr [i]) * parseFloat(tmpCovarArr [i])); } // Get the probability var PROB = 0.0; PROB = (Math.pow (e, LP))/(1+(Math.pow (e, LP))); // Generate the risk percentage RISK30DayMort = 100 * PROB; // 2D Array of matrix (17x17) var matrix30Day = [ [0.2508312877,-0.0075319030,-0.0038082270,-0.0089227782,-0.0051296024,-0.0043000240,-0.0014932555,-0.0060114413,-0.0077968444, 0.0058316116,-0.0047312317,-0.0040864333,-0.0021724849, 0.0010483725,-0.0017200834, 0.0039958725,-0.0033695522], [-0.0075319030, 0.0193159335,-0.0047161272,-0.0005679924, 0.0001627260, 0.0006010655, 0.0000089135, 0.0052787598, 0.0126205083, 0.0005063573,-0.0001272507, 0.0001912794,-0.0120022361, 0.0003920865, 0.0000370550, 0.0002787508, 0.0002385066], [-0.0038082270,-0.0047161272, 0.0254988566,-0.0007181110, 0.0001762079,-0.0005481192, 0.0000423522,-0.0007287159,-0.0123584985, 0.0006444121,-0.0001524343, 0.0004439154, 0.0020843730, 0.0001145666,-0.0000047098, 0.0000355221, 0.0004573884,], [-0.0089227782,-0.0005679924,-0.0007181110, 0.0040998465, 0.0000433327,-0.0003606234,-0.0000256077,-0.0001149486,-0.0010584190,-0.0028727275, 0.0000110397, 0.0002147557,-0.0001105941, 0.0002114086, 0.0000116275, 0.0001704055,-0.0000447175], [-0.0051296024, 0.0001627260, 0.0001762079, 0.0000433327, 0.0003692127, 0.0002318476, 0.0000076952, 0.0001164725, 0.0003427178,-0.0000260376, 0.0002056272, 0.0000701995,-0.0000840480, 0.0000823928,-0.0000146467,-0.0000220216, 0.0004078742], [-0.0043000240, 0.0006010655,-0.0005481192,-0.0003606234, 0.0002318476, 0.0082774482, 0.0000047441,-0.0002348116, 0.0003703500,-0.0006468753,-0.0009839217,-0.0010477334, 0.0010279072,-0.0011480946,-0.0000260442,-0.0013946618,-0.0014010936], [-0.0014932555, 0.0000089135, 0.0000423522,-0.0000256077, 0.0000076952, 0.0000047441, 0.0000185920,-0.0000038374, 0.0000194738, 0.0000143896, 0.0000102330, 0.0000043051, 0.0000106657,-0.0000565697, 0.0000060393,-0.0000622002,-0.0000354251], [-0.0060114413, 0.0052787598,-0.0007287159,-0.0001149486, 0.0001164725,-0.0002348116,-0.0000038374, 0.0088290998, 0.0055780479, 0.0000020360,-0.0001026661,-0.0001269158,-0.0006628358, 0.0001795067, 0.0000232918, 0.0000102575,-0.0002400025], [-0.0077968444, 0.0126205083,-0.0123584985,-0.0010584190, 0.0003427178, 0.0003703500, 0.0000194738, 0.0055780479, 0.1225188258, 0.0000339686,-0.0009166130,-0.0004523261,-0.0087823477, 0.0006456227, 0.0000133364, 0.0003659940, 0.0001279918], [0.0058316116, 0.0005063573, 0.0006444121,-0.0028727275,-0.0000260376,-0.0006468753, 0.0000143896, 0.0000020360, 0.0000339686, 0.0097350553,-0.0003363408,-0.0001325663, 0.0011091128,-0.0006924250,-0.0000486178,-0.0004977272,-0.0001441798], [-0.0047312317,-0.0001272507,-0.0001524343, 0.0000110397, 0.0002056272,-0.0009839217, 0.0000102330,-0.0001026661,-0.0009166130,-0.0003363408, 0.0254945917, 0.0001660285, 0.0001078789,-0.0003833700,-0.0000191652,-0.0050745725,-0.0001026580], [-0.0040864333, 0.0001912794, 0.0004439154, 0.0002147557, 0.0000701995,-0.0010477334, 0.0000043051,-0.0001269158,-0.0004523261,-0.0001325663, 0.0001660285, 0.0071905149, 0.0002587888,-0.0001317563, 0.0000235517,-0.0007043624,-0.0001519582], [-0.0021724849,-0.0120022361, 0.0020843730,-0.0001105941,-0.0000840480, 0.0010279072, 0.0000106657,-0.0006628358,-0.0087823477, 0.0011091128, 0.0001078789, 0.0002587888, 0.0185165843, 0.0003660535, 0.0000347932, 0.0003182781, 0.0001688450], [0.0010483725, 0.0003920865, 0.0001145666, 0.0002114086, 0.0000823928,-0.0011480946,-0.0000565697, 0.0001795067, 0.0006456227,-0.0006924250,-0.0003833700,-0.0001317563, 0.0003660535, 0.0112159717, 0.0000142816,-0.0009900867,-0.0002818043], [-0.0017200834, 0.0000370550,-0.0000047098, 0.0000116275,-0.0000146467,-0.0000260442, 0.0000060393, 0.0000232918, 0.0000133364,-0.0000486178,-0.0000191652, 0.0000235517, 0.0000347932, 0.0000142816, 0.0000509628,-0.0000153374,-0.0000416001], [0.0039958725, 0.0002787508, 0.0000355221, 0.0001704055,-0.0000220216,-0.0013946618,-0.0000622002, 0.0000102575, 0.0003659940,-0.0004977272,-0.0050745725,-0.0007043624, 0.0003182781,-0.0009900867,-0.0000153374, 0.0098669971,-0.0000279872], [-0.0033695522, 0.0002385066, 0.0004573884,-0.0000447175, 0.0004078742,-0.0014010936,-0.0000354251,-0.0002400025, 0.0001279918,-0.0001441798,-0.0001026580,-0.0001519581, 0.0001688450,-0.0002818043,-0.0000416001,-0.0000279872, 0.0074813546] ]; var outArr = new Array (tmpCovarArr.length); // Perform martix multiplication outArr = runMatrixMultiplication (tmpCovarArr, matrix30Day); var final30DayMortRisk = 0; // Transpose the covariate array (tmpCovarArr) and perform matirx multiplication with the above matrix (outArr) to get final result for (var i = 0; i < outArr.length; i++) { final30DayMortRisk += (parseFloat(outArr [i]) * parseFloat(tmpCovarArr [i])); } } var standardError = Math.sqrt (final30DayMortRisk); var lcl = getLowerConfidenceLevel (LP, standardError); var ucl = getUpperConfidenceLevel (LP, standardError); risk30DayMortArr = [RISK30DayMort, lcl*100, ucl*100]; return risk30DayMortArr; } // End of setBleedingRisk_PTS function /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TESTING +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /** * @author Stephan K Eisenbarth * @date 4/30/2018 * Description: Function runs series of test data (NO GUI) */ function runTestData_30DayMortalityAfterPCI () { var varNameArr = get30DayMortVariableNamesArr (); var testArr = [[1, 0, 0, 3.0910425, 13.1, 1, 66.266405, 0, 0, 0, 0.33647224, 0, 0, 1, 21.2, 0, 0]]; var tmpStr = ""; var tmpResArr = null; for (var i = 0; i < testArr.length; i++) { console.log ("Test #" + i); tmpStr += "

Test #" + i + "

" + "\n"; for (var x = 0; x < testArr[i].length - 1; x++) { tmpStr += "\n" + "\n" + "\n" + "\n"; } tmpResArr = get30DayMortalityRisk (testArr [i]); tmpStr += "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + "" + varNameArr [x] + "\n" + "\n" + testArr [i][x + 1] + "
\n" + "PROB\n" + "\n" + (tmpResArr [0]/100) + "\n" + "
\n" + "LL\n" + "\n" + (tmpResArr [1]/100) + "\n" + "
\n" + "UL\n" + "\n" + (tmpResArr [2]/100) + "\n" + "
\n" + "
\n"; console.log ("____________________________________"); } document.getElementById ("resultsArea_mortalityArea").innerHTML = tmpStr; }