//////////////////////////////////////////////////////////////////////////////// // // Copyright (c) 2013-2017 Dawson Dean // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //////////////////////////////////////////////////////////////////////////////// // // MedNote_InitQuantState() // MedNote_InitOneQuantValueField(valueNameStr) // MedNote_ReInitializeQuantState() // // MedNote_ParseOneSCMLine(lineArray, lineNum) // MedNote_SaveValueFromOneSCMString(lineArray, lineNum, valueNameStr, str, startIndex) // MedNote_SetValueNumber(valueNameStr, intVal) // MedNote_SetValueNumberWithComment(valueNameStr, intVal, strVal) // MedNote_SetValueString(valueNameStr, strVal) // // MedNote_CalculateAllValues() // // MedNote_ImportSCMLabs(lineArray) // MedNote_ImportCPRSLabs(lineArray) // // ComputeRiskOfESRD() // AddTermToESRDRiskScore(labelStr, coefficient, xBar, xVal) // SaveValueFromOneString(lineArray, lineNum, valueNameStr, str, startIndex) // ReadNumberFromStr(str, startIndex) // ParseOneCPRSLine(lineArray, lineNum) // ParseUserInputs() // GetLabValue(valueNameStr) // GetLabValueStringForPlan(valueNameStr) // NBQuant_ToggleBooleanButton(valueNameStr) // //////////////////////////////////////////////////////////////////////////////// ///////////////////////// // Laboratory Values and Derived Scores var g_LabValueArray = []; var g_AllLabValuesDeclaration = { ////////////////// // BMP "Sodium" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputNa"}, "Potassium" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputK"}, "Chloride" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCl"}, "HCO3" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputHCO3"}, "BUN" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputBUN"}, "Creatinine" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCr"}, "Glucose" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputGlc"}, "ReportedGFR" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputGFR"}, "ReportedAfricanGFR" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputGFRAfrican"}, ////////////////// // LFT "ALT" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputALT"}, "AST" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputAST"}, "ALP" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputALP"}, "TBili" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputTbili"}, "TProtein" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputTProt"}, "Albumin" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputAlbumin"}, "INR" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputINR"}, "PT" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPT"}, "UricAcid" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUrate"}, ////////////////// // Urine "UrineUrea" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUUN"}, "UrineSodium" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUNa"}, "UrineCreatinine" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUrineCr"}, // mg/dL "UrinePotassium" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUK"}, "UrineChloride" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUCl"}, "UrineProtein" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUProt"}, "UrineAlbumin" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUrineAlb"}, // mcg/dL "UrineOsm" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUOsm"}, "UrineVolume" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUrineVolume"}, "UrineCalcium" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUCa"}, "UrinePhos" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUPhos"}, "UrineUrate" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUUrate"}, "UrineMag" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputUMag"}, ////////////////// // Vitals "Age" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputAge"}, "WeightInKg" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputWt"}, "HeightInCm" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputHt"}, "SystolicBP" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputSBP"}, "DiastolicBP" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputDBP"}, "HR" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputHR"}, ////////////////// // MBD "Calcium" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCa"}, "Phos" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPhos"}, "Mag" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputMag"}, "VitD" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputVitD"}, "PTH" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPTH"}, ////////////////// // Dialysis "PreBUN" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPreBUN"}, "PostBUN" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPostBUN"}, "HDTimeInMin" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputHDTime"}, "PreHDWeightInKg" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPreWeight"}, "PostHDWeightInKg" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputPostWeight"}, "FilterSelect" : { "userInput" : "1", "inputType" : "enum", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "FilterSelect"}, "BloodFlowSelect" : { "userInput" : "1", "inputType" : "enum", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "BloodFlowSelect"}, "HDFreqSelect" : { "userInput" : "1", "inputType" : "enum", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "HDFrequencySelect"}, ////////////////// // ABG "pH" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputABGpH"}, "PaCO2" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputABGPaCO2"}, "PaO2" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputABGPaO2"}, ////////////////// // CBC "WBC" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCBCWBC"}, "CBCHgb" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCBCHgb"}, "Platelet" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCBCPlt"}, ////////////////// // Markers "CystatinC" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputCystatinC"}, "HgbA1c" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputA1c"}, "Osmolality" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputOsm"}, ////////////////// // Lipids "LDL" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputLDL"}, "HDL" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputHDL"}, "TChol" : { "userInput" : "1", "inputType" : "text", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "InputTChol"}, ////////////////// // Patient Questionaire // // Additionally, boolean outputs have these additional fields: // "boolResultHTMLElementID" // "boolResultHTMLElement" // "outputOnStr" // "outputOffStr" // "drawColorsInRedGreen" // "IsMale" : { "userInput" : "1", "inputType" : "bool", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "sexOption", "boolResultHTMLElementID" : "SexBoolOutput", "boolResultHTMLElement" : null, "outputOnStr" : "Male", "outputOffStr" : "Female", "drawColorsInRedGreen" : "1" }, "IsCaucasian" : { "userInput" : "1", "inputType" : "bool", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "RaceOption", "boolResultHTMLElementID" : "RaceBoolOutput", "boolResultHTMLElement" : null, "outputOnStr" : "Caucasian", "outputOffStr" : "Other", "drawColorsInRedGreen" : "1" }, "OnHTNMeds" : { "userInput" : "1", "inputType" : "bool", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "HTNOption", "boolResultHTMLElementID" : "OnHTNMedsBoolOutput", "boolResultHTMLElement" : null, "outputOnStr" : "YES", "outputOffStr" : "NO", "drawColorsInRedGreen" : "1" }, "IsDiabetic" : { "userInput" : "1", "inputType" : "bool", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "DMOption", "boolResultHTMLElementID" : "DiabeticBoolOutput", "boolResultHTMLElement" : null, "outputOnStr" : "YES", "outputOffStr" : "NO", "drawColorsInRedGreen" : "1" }, "IsSmoker" : { "userInput" : "1", "inputType" : "bool", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "SmokerOption", "boolResultHTMLElementID" : "SmokingBoolOutput", "boolResultHTMLElement" : null, "outputOnStr" : "YES", "outputOffStr" : "NO", "drawColorsInRedGreen" : "1" }, "IsOnDialysis" : { "userInput" : "1", "inputType" : "bool", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "OnDialysisOption", "boolResultHTMLElementID" : "OnDialysisOptionOutput", "boolResultHTMLElement" : null, "outputOnStr" : "YES", "outputOffStr" : "NO", "drawColorsInRedGreen" : "1" }, "AscitesSelect" : { "userInput" : "1", "inputType" : "enum", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "AscitesSelect"}, "EncephalopathySelect" : { "userInput" : "1", "inputType" : "enum", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "EncephalopathySelect"}, //////////////////////////////////// // Output values // These have ADDITIONAL values, which are only used for the output values. // "outputPrefixStr" // "outputSuffixStr" // "CreatinineClearance" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultCrCl", "outputPrefixStr" : "CreatinineClearance: ", "outputSuffixStr" : null}, "FENa" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultFENa", "outputPrefixStr" : "FENa: ", "outputSuffixStr" : null}, "FEUrea" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultFEUrea", "outputPrefixStr" : "FEUrea: ", "outputSuffixStr" : null}, "FEPhos" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultFEPhos", "outputPrefixStr" : "FE-Phos: ", "outputSuffixStr" : null}, "FECalcium" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultFECalcium", "outputPrefixStr" : "FE-Calcium: ", "outputSuffixStr" : null}, "FEUrate" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultFEUrate", "outputPrefixStr" : "FE-Urate: ", "outputSuffixStr" : null}, "GFR" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ResultGFR", "outputPrefixStr" : "GFR: ", "outputSuffixStr" : null}, "AnionGap" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "AnionGap", "outputPrefixStr" : "AnionGap: ", "outputSuffixStr" : null}, "UrineAnionGap" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "UrineAnionGap", "outputPrefixStr" : "UrineAnionGap: ", "outputSuffixStr" : null}, "AdjustedAnionGap" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "AdjustedAnionGap", "outputPrefixStr" : "Adjusted AnionGap: ", "outputSuffixStr" : null}, "AdjustedNa" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "AdjustedNa", "outputPrefixStr" : "AdjustedNa: ", "outputSuffixStr" : null}, "AdjustedCa" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "AdjustedCa", "outputPrefixStr" : "AdjustedCa: ", "outputSuffixStr" : null}, "Est2YearESRDRisk" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "TwoYrESRDRisk", "outputPrefixStr" : "Risk of ESRD in 2 years: ", "outputSuffixStr" : "%"}, "Est5YearESRDRisk" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "FiveYrESRDRisk", "outputPrefixStr" : "Risk of ESRD in 5 years: ", "outputSuffixStr" : "%"}, "UreaReductionRatio" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "UreaReductionRatio", "outputPrefixStr" : "Urea Reduction Ratio: ", "outputSuffixStr" : "%"}, "EstimatedKtV" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "EstimatedKtV", "outputPrefixStr" : "Estimated Kt/V: ", "outputSuffixStr" : null}, "SingleCompartmentKtV" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "SingleCompartmentKtV", "outputPrefixStr" : "Single Compartment Kt/V: ", "outputSuffixStr" : null}, "EquilibratedKtV" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "EquilibratedKtV", "outputPrefixStr" : "Equilibrated Kt/V: ", "outputSuffixStr" : null}, "StandardKtV" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "StandardKtV", "outputPrefixStr" : "Standard Kt/V: ", "outputSuffixStr" : null}, "ChildPugh" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ChildPughOutput", "outputPrefixStr" : "Child-Pugh: ", "outputSuffixStr" : "(*)"}, "DiscriminantFunction" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "DiscriminantFunctionOutput", "outputPrefixStr" : "Maddreys Discriminant: ", "outputSuffixStr" : ""}, "MELD" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "MELDOutput", "outputPrefixStr" : "MELD: ", "outputSuffixStr" : null}, "FreeWaterDeficit" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "FreeWaterDeficitStrOutput", "outputPrefixStr" : "Free Water Deficit: ", "outputSuffixStr" : " liters"}, "ElectrolyteFreeWaterClearance" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ElectrolyteFreeWaterClearanceStrOutput", "outputPrefixStr" : "Electrolyte-Free Water Clearance: ", "outputSuffixStr" : " liters"}, "TransTubularKGradient" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "TransTubularKGradientOutput", "outputPrefixStr" : "TransTubular K Gradient: ", "outputSuffixStr" : null}, "ComputedSerumOsm" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "ComputedSerumOsm", "outputPrefixStr" : "ComputedSerumOsm: ", "outputSuffixStr" : null}, "FraminghamOutput" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "FraminghamOutput", "outputPrefixStr" : "Framingham risk: ", "outputSuffixStr" : "% (*)"}, "AaGradientOutput" : { "userInput" : "0", "inputType" : "none", "htmlElement" : null, "intVal" : -1, "strVal" : "x", "htmlElementID" : "AaGradientOutput", "outputPrefixStr" : "AaGradient: ", "outputSuffixStr" : ""} }; // g_AllLabValuesDeclaration ////////////////////////////////////////// // Private Temporary Globals // Globals, these just allow ComputeRiskOfESRD() to return two separate values. var g_2YearESRDRisk = -1; var g_5YearESRDRisk = -1; var g_SumofBetaXBar = 0; var g_SumofBetaX = 0; var g_TotalDelta = 0; //////////////////////////////////// var g_F160Info = {id:"F-160", name:"Fresenius Optiflux-160NR", UreaCl:["194", "266", "308", ""]}; var g_F180Info = {id:"F-180", name:"Fresenius Optiflux-180NR", UreaCl:["196", "274", "323", ""]}; var g_F200Info = {id:"F-200", name:"Fresenius Optiflux-200NR", UreaCl:["197", "277", "330", ""]}; var g_Exceltra170Info = {id:"Exceltra-170", name:"Baxter Exceltra-170", UreaCl:["196", "260", "310", "341"]}; var g_Exceltra190Info = {id:"Exceltra-190", name:"Baxter Exceltra-190", UreaCl:["197", "273", "323", "354"]}; var g_Exceltra210Info = {id:"Exceltra-210", name:"Baxter Exceltra-210", UreaCl:["199", "287", "350", "384"]}; var g_RevaclearInfo = {id:"Revaclear", name:"Baxter Revaclear", UreaCl:["196", "271", "321", "353"]}; var g_RevaclearMaxInfo = {id:"Revaclear-MAX", name:"Baxter Revaclear-MAX", UreaCl:["198", "282", "339", "376"]}; var g_BloodFlowList = ["300", "350", "400", "450", "500"]; var g_hisHer = "his"; var g_CapHisHer = "His"; var g_himHer = "him"; var g_CapHimHer = "His"; var g_heShe = "he"; var g_CapHeShe = "He"; // This tells us whether any data has been entered. We do not derive values if nothing is in the system var g_LabDataAvailable = false; //////////////////////////////////////////////////////////////////////////////// // // [MedNote_InitQuantState] // // This is called by the browser to initialize the entire UI. //////////////////////////////////////////////////////////////////////////////// function MedNote_InitQuantState() { //LogEvent("MedNote_InitQuantState"); MedNote_InitOneQuantValueField("Sodium"); MedNote_InitOneQuantValueField("Potassium"); MedNote_InitOneQuantValueField("Chloride"); MedNote_InitOneQuantValueField("HCO3"); MedNote_InitOneQuantValueField("BUN"); MedNote_InitOneQuantValueField("Creatinine"); MedNote_InitOneQuantValueField("Glucose"); MedNote_InitOneQuantValueField("ReportedGFR"); MedNote_InitOneQuantValueField("ReportedAfricanGFR"); MedNote_InitOneQuantValueField("ALT"); MedNote_InitOneQuantValueField("AST"); MedNote_InitOneQuantValueField("ALP"); MedNote_InitOneQuantValueField("TBili"); MedNote_InitOneQuantValueField("TProtein"); MedNote_InitOneQuantValueField("Albumin"); MedNote_InitOneQuantValueField("INR"); MedNote_InitOneQuantValueField("PT"); MedNote_InitOneQuantValueField("UricAcid"); ////////////////// // Urine MedNote_InitOneQuantValueField("UrineUrea"); MedNote_InitOneQuantValueField("UrineSodium"); MedNote_InitOneQuantValueField("UrineCreatinine"); // mg/dL MedNote_InitOneQuantValueField("UrinePotassium"); MedNote_InitOneQuantValueField("UrineChloride"); MedNote_InitOneQuantValueField("UrineProtein"); MedNote_InitOneQuantValueField("UrineAlbumin"); // mcg/dL MedNote_InitOneQuantValueField("UrineOsm"); MedNote_InitOneQuantValueField("UrineVolume"); // L/day MedNote_InitOneQuantValueField("UrineCalcium"); MedNote_InitOneQuantValueField("UrinePhos"); MedNote_InitOneQuantValueField("UrineUrate"); ////////////////// // Vitals MedNote_InitOneQuantValueField("Age"); MedNote_InitOneQuantValueField("WeightInKg"); MedNote_InitOneQuantValueField("HeightInCm"); MedNote_InitOneQuantValueField("SystolicBP"); MedNote_InitOneQuantValueField("DiastolicBP"); MedNote_InitOneQuantValueField("HR"); ////////////////// // MBD MedNote_InitOneQuantValueField("Calcium"); MedNote_InitOneQuantValueField("Phos"); MedNote_InitOneQuantValueField("VitD"); MedNote_InitOneQuantValueField("PTH"); ////////////////// // Dialysis MedNote_InitOneQuantValueField("PreBUN"); MedNote_InitOneQuantValueField("PostBUN"); MedNote_InitOneQuantValueField("HDTimeInMin"); MedNote_InitOneQuantValueField("PreHDWeightInKg"); MedNote_InitOneQuantValueField("PostHDWeightInKg"); MedNote_InitOneQuantValueField("FilterSelect"); MedNote_InitOneQuantValueField("BloodFlowSelect"); MedNote_InitOneQuantValueField("HDFreqSelect"); ////////////////// // ABG MedNote_InitOneQuantValueField("pH"); MedNote_InitOneQuantValueField("PaCO2"); MedNote_InitOneQuantValueField("PaO2"); ////////////////// // CBC MedNote_InitOneQuantValueField("WBC"); MedNote_InitOneQuantValueField("CBCHgb"); MedNote_InitOneQuantValueField("Platelet"); ////////////////// // Markers MedNote_InitOneQuantValueField("CystatinC"); MedNote_InitOneQuantValueField("HgbA1c"); ////////////////// // Lipids MedNote_InitOneQuantValueField("LDL"); MedNote_InitOneQuantValueField("HDL"); MedNote_InitOneQuantValueField("TChol"); ////////////////// // Patient Questionaire MedNote_InitOneQuantValueField("IsMale"); MedNote_InitOneQuantValueField("IsCaucasian"); MedNote_InitOneQuantValueField("OnHTNMeds"); MedNote_InitOneQuantValueField("IsDiabetic"); MedNote_InitOneQuantValueField("IsSmoker"); MedNote_InitOneQuantValueField("IsOnDialysis"); MedNote_InitOneQuantValueField("AscitesSelect"); MedNote_InitOneQuantValueField("EncephalopathySelect"); //////////////////////////////////// // Output values that may be used for other equations. MedNote_InitOneQuantValueField("CreatinineClearance"); MedNote_InitOneQuantValueField("FENa"); MedNote_InitOneQuantValueField("FEUrea"); MedNote_InitOneQuantValueField("GFR"); MedNote_InitOneQuantValueField("AnionGap"); MedNote_InitOneQuantValueField("UrineAnionGap"); MedNote_InitOneQuantValueField("AdjustedAnionGap"); MedNote_InitOneQuantValueField("AdjustedNa"); MedNote_InitOneQuantValueField("AdjustedCa"); MedNote_InitOneQuantValueField("Est2YearESRDRisk"); MedNote_InitOneQuantValueField("Est5YearESRDRisk"); MedNote_InitOneQuantValueField("UreaReductionRatio"); MedNote_InitOneQuantValueField("EstimatedKtV"); MedNote_InitOneQuantValueField("SingleCompartmentKtV"); MedNote_InitOneQuantValueField("EquilibratedKtV"); MedNote_InitOneQuantValueField("StandardKtV"); MedNote_InitOneQuantValueField("ChildPugh"); MedNote_InitOneQuantValueField("DiscriminantFunction"); MedNote_InitOneQuantValueField("MELD"); MedNote_InitOneQuantValueField("FreeWaterDeficit"); MedNote_InitOneQuantValueField("ElectrolyteFreeWaterClearance"); MedNote_InitOneQuantValueField("TransTubularKGradient"); MedNote_InitOneQuantValueField("ComputedSerumOsm"); MedNote_InitOneQuantValueField("FraminghamOutput"); MedNote_InitOneQuantValueField("AaGradientOutput"); //LogEvent("MedNote_InitQuantState. Finished MedNote_InitOneQuantValueField"); // Debnug code. Verify that we got the right values. //LogEvent("MedNote_InitQuantState. g_LabValueArray.length=" + g_LabValueArray.length); if (0) { var index; var intVal = 3.14; for (index = 0; index < g_LabValueArray.length; index++) { var valueEntry = g_LabValueArray[index]; // LogEvent("Check Value " + index + ", name=" + valueEntry.valueName + ", elementID=" + valueEntry.htmlElementID + ", userInput=" + valueEntry.userInput); if ((valueEntry.userInput == "1") && (valueEntry.inputType == "text") && (valueEntry.htmlElement)) { valueEntry.htmlElement.value = intVal.toString(); } intVal += 1.0; } } g_LabDataAvailable = false; } // MedNote_InitQuantState //////////////////////////////////////////////////////////////////////////////// // // [MedNote_InitOneQuantValueField] // //////////////////////////////////////////////////////////////////////////////// function MedNote_InitOneQuantValueField(valueNameStr) { //LogEvent("MedNote_InitOneQuantValueField. valueNameStr= " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; var resultTextStr = ""; if (valueEntry.userInput == "1") { valueEntry.intVal = -1; if ((valueEntry.inputType == "text") || (valueEntry.inputType == "enum") || (valueEntry.inputType == "bool")) { valueEntry.htmlElement = document.getElementById(valueEntry.htmlElementID); } if ((valueEntry.htmlElement) && (valueEntry.inputType == "bool")) { //LogEvent("MedNote_InitOneQuantValueField. bool value. valueEntry.htmlElementID=" + valueEntry.htmlElementID); var currentStr = valueEntry.htmlElement.getAttribute('boolVal'); if (!currentStr) { currentStr = "ON"; valueEntry.htmlElement.setAttribute('boolVal', currentStr); } if (currentStr.toUpperCase() == "ON") { valueEntry.intVal = 1; } else { valueEntry.intVal = 0; } valueEntry.boolResultHTMLElement = document.getElementById(valueEntry.boolResultHTMLElementID); if (valueEntry.boolResultHTMLElement) { if (valueEntry.intVal) { resultTextStr = valueEntry.outputOnStr; if (valueEntry.drawColorsInRedGreen) { valueEntry.boolResultHTMLElement.style="background-color:#00FF00;" } } else { resultTextStr = valueEntry.outputOffStr; if (valueEntry.drawColorsInRedGreen) { valueEntry.boolResultHTMLElement.style="background-color:#FF0000;" } } Util_RemoveAllChildNodes(valueEntry.boolResultHTMLElement); var textNode = document.createTextNode(resultTextStr); valueEntry.boolResultHTMLElement.appendChild(textNode); } // if (valueEntry.boolResultHTMLElement) } // if ((valueEntry.htmlElement) && (valueEntry.inputType == "bool")) } else { // if (valueEntry.userInput != "1") { valueEntry.intVal = -1; valueEntry.strVal = "xxxxx"; valueEntry.htmlElement = document.getElementById(valueEntry.htmlElementID); } // Save the name, so if we access this value by index we can also know its name valueEntry.valueName = valueNameStr; // I seem to need an array that is accessed by index in addition to the associative-array that is accessed by name. // There must be a way, but for now I do not know how to enumerate the named elements of an associative array using an integer index. g_LabValueArray.push(valueEntry); } // MedNote_InitOneQuantValueField //////////////////////////////////////////////////////////////////////////////// // // [MedNote_ReInitializeQuantState] // //////////////////////////////////////////////////////////////////////////////// function MedNote_ReInitializeQuantState() { var index; for (index = 0; index < g_LabValueArray.length; index++) { var valueEntry = g_LabValueArray[index]; if (!valueEntry) { continue; } valueEntry.intVal = -1; valueEntry.strVal = ""; if (valueEntry.userInput == "1") { if ((valueEntry.inputType == "text") && (valueEntry.htmlElement)) { valueEntry.htmlElement.value = valueEntry.strVal; } if (valueEntry.inputType == "bool") { valueEntry.strVal = "false"; } } else { // if (valueEntry.userInput != "1") { if (valueEntry.htmlElement) { Util_RemoveAllChildNodes(valueEntry.htmlElement); } } } g_LabDataAvailable = false; } // MedNote_ReInitializeQuantState //////////////////////////////////////////////////////////////////////////////// // // [MedNote_CalculateAllValues] // //////////////////////////////////////////////////////////////////////////////// function MedNote_CalculateAllValues() { //LogEvent("MedNote_CalculateAllValues"); var fShowValues = false; var creatinine = GetLabValue("Creatinine"); var sodium = GetLabValue("Sodium"); var albumin = GetLabValue("Albumin"); var patientAge = GetLabValue("Age"); var systolicBP = GetLabValue("SystolicBP"); var serumHDL = GetLabValue("HDL"); var totalChol = GetLabValue("TChol"); var fAddFootNote = false; // If no data has been entered, then do nothing. // This is more than a performance helper. If data is available, then // generate hints/errors when required data is still missing. if (!g_LabDataAvailable) { //LogEvent("MedNote_CalculateAllValues. Nothing to do. g_LabDataAvailable=" + g_LabDataAvailable); return; } ParseUserInputs(); g_2YearESRDRisk = -1; g_5YearESRDRisk = -1; g_ComputedResultsDivElement.style.display = "None"; // Total Body Water is used by several values, so let's compute it once now. // There are some many ways to estimate this. // // Watson: // Male TBW = 2.447 - (0.09156 x age) + (0.1074 x height) + (0.3362 x weight) // Female TBW = -2.097 + (0.1069 x height) + (0.2466 x weight) // Watson PE, Watson ID, Batt RD. Total body water volumes for adult males and females estimated from simple anthropometric measurements. Am J Clin Nutr 33:27-39, 1980. // // Hume-Weyers: // Male TBW = (0.194786 x height) + (0.296785 x weight) - 14.012934 // Female TBW = (0.34454 x height) + (0.183809 x weight) - 35.270121 // Hume R, Weyers E. Relationship between total body water and surface area in normal and obese subjects. J Clin Pathol 24:234-238, 1971. // // Chertow's Bioelectrical Impedance: // TBW = ht x (0.0186104 x wt + 0.12703384) + wt x (0.11262857 x male + 0.00104135 x age - 0.00067247 x wt - 0.04012056) - age x (0.03486146 x male + 0.07493713) - male x 1.01767992 + diabetes x 0.57894981 // Chertow GM, Lowrie EG, Lew NL, Lazarus JM. Development of a population-specific regression equation to estimate total body water in hemodialysis patients. Kid Int 51:1578-1582, 1997. // // I use a much simpler method, which scales mass. But, the scale can vary depending on sex and age // Children: 0.6 // Adult men: 0.6 // Adult women: 0.5 // Geriatric (?age) men: 0.5 // Geriatric (age?) women: 0.45 var EstimatedTotalBodyWater = -1; if (GetLabValue("WeightInKg") > 0) { EstimatedTotalBodyWater = 0.6 * GetLabValue("WeightInKg"); } /////////////////////////////////////////// // Adjust Na for Glucose - do this BEFORE computing the anion gap. if ((sodium > 0) && (GetLabValue("Glucose") > 0)) { var adjustedNa = sodium + (2.4 * ((GetLabValue("Glucose") - 100) / 100)); // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. adjustedNa = Math.round((adjustedNa + 0.00001) * 100) / 100; var deltaNa = adjustedNa - sodium; if ((deltaNa > 4) || (deltaNa < -4)) { MedNote_SetValueNumber("AdjustedNa", adjustedNa); //?????<> This is technically correct, but nobody will believe me. //sodium = adjustedNa; fShowValues = true; } } /////////////////////////////////////////// // Anion Gap if ((sodium > 0) && (GetLabValue("Chloride") > 0) && (GetLabValue("HCO3") > 0)) { var anionGap = sodium - (GetLabValue("Chloride") + GetLabValue("HCO3")); var adjustedAnionGap = anionGap; if ((albumin > 0) && (albumin < 4)) { adjustedAnionGap = anionGap + (2.5 * (4.0 - albumin)); } // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. anionGap = Math.round((anionGap + 0.00001) * 100) / 100; adjustedAnionGap = Math.round((adjustedAnionGap + 0.00001) * 100) / 100; MedNote_SetValueNumber("AnionGap", anionGap); MedNote_SetValueNumber("AdjustedAnionGap", adjustedAnionGap); fShowValues = true; } /////////////////////////////////////////// // Urine Anion Gap if ((GetLabValue("UrineSodium") > 0) && (GetLabValue("UrinePotassium") > 0) && (GetLabValue("UrineChloride") > 0)) { var g_UrineAnionGap = (GetLabValue("UrineSodium") + GetLabValue("UrinePotassium")) - GetLabValue("UrineChloride"); // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. g_UrineAnionGap = Math.round((g_UrineAnionGap + 0.00001) * 100) / 100; MedNote_SetValueNumber("UrineAnionGap", g_UrineAnionGap); fShowValues = true; } /////////////////////////////////////////// // GFR var estimatedGFR = 175; // If there is a GFR from the EMR, then use that. // It saves a lot of hassles with Pharmacy. if ((GetLabValue("ReportedGFR") > 0) && (GetLabValue("IsCaucasian"))) { estimatedGFR = GetLabValue("ReportedGFR"); MedNote_SetValueNumberWithComment("GFR", estimatedGFR, "(from EMR)"); } else if ((GetLabValue("ReportedAfricanGFR") > 0) && (!GetLabValue("IsCaucasian"))) { estimatedGFR = GetLabValue("ReportedAfricanGFR"); MedNote_SetValueNumberWithComment("GFR", estimatedGFR, "(from EMR)"); // Otherwise, see what is missing: } else if ((creatinine < 0) || (patientAge < 0)) { var missingDataStr = "GFR: missing "; var fAddedFields = 0; if (creatinine < 0) { missingDataStr = missingDataStr + "Creatinine"; fAddedFields = 1; } if (patientAge < 0) { if (fAddedFields) { missingDataStr = missingDataStr + ", "; } missingDataStr = missingDataStr + "Age"; fAddedFields = 1; } MedNote_SetValueString("GFR", missingDataStr); // Otherwise, compute the real value. } else { var scaler; estimatedGFR = 175; scaler = Math.pow(creatinine, -1.154); estimatedGFR = estimatedGFR * scaler; scaler = Math.pow(patientAge, -0.203); estimatedGFR = estimatedGFR * scaler; if (!GetLabValue("IsMale") ) { estimatedGFR = estimatedGFR * 0.742; } if (!GetLabValue("IsCaucasian")) { estimatedGFR = estimatedGFR * 1.212; } estimatedGFR = Math.round((estimatedGFR + 0.00001) * 100) / 100; MedNote_SetValueNumber("GFR", estimatedGFR); } fShowValues = true; /////////////////////////////////////////// // Creatinine Clearance // This may seem odd, but it's still used for a lot of drug dosing. if ((patientAge > 0) && (GetLabValue("WeightInKg") > 0) && (creatinine > 0)) { var creatinineClearance = ((140 - patientAge) * GetLabValue("WeightInKg")) / (72 * creatinine); if (!GetLabValue("IsMale") ) { creatinineClearance = creatinineClearance * 0.85; } creatinineClearance = Math.round((creatinineClearance + 0.00001) * 100) / 100; MedNote_SetValueNumber("CreatinineClearance", creatinineClearance); fShowValues = true; // If the Cr Clearance is below 60, then the patient may have CKD. if ((creatinineClearance > 0) && (creatinineClearance < 60)) { CKDPlanButtonState = 1; } } // Creatinine Clearance /////////////////////////////////////////// // Adjust Calcium for Albumin if ((GetLabValue("Calcium") > 0) && (albumin > 0) && (albumin < 4)) { var adjustedCa = GetLabValue("Calcium") + (0.8 * (4.0 - albumin)); // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. adjustedCa = Math.round((adjustedCa + 0.00001) * 100) / 100; var deltaNCa = adjustedCa - GetLabValue("Calcium"); if ((deltaNCa > 1) || (deltaNCa < -1)) { MedNote_SetValueNumber("AdjustedCa", adjustedCa); fShowValues = true; } } /////////////////////////////////////////// // Framingham if ((patientAge > 0) && (serumHDL > 0) && (totalChol > 0) && (systolicBP > 0)) { var score = 0; var risk = 0; var resultStr = ""; ////////////////// MALE if (GetLabValue("IsMale") ) { //////////////////// // Age if ((patientAge >= 35) && (patientAge <= 39)) { score += 2; } else if ((patientAge >= 40) && (patientAge <= 44)) { score += 5; } else if ((patientAge >= 45) && (patientAge <= 49)) { score += 6; } else if ((patientAge >= 50) && (patientAge <= 54)) { score += 8; } else if ((patientAge >= 55) && (patientAge <= 59)) { score += 10; } else if ((patientAge >= 60) && (patientAge <= 64)) { score += 11; } else if ((patientAge >= 65) && (patientAge <= 69)) { score += 12; } else if ((patientAge >= 70) && (patientAge <= 74)) { score += 14; } else if (patientAge >= 75) { score += 15; } //////////////////// // HDL if (serumHDL >= 60) { score = score - 2; } else if ((serumHDL >= 50) && (serumHDL <= 59)) { score = score - 1; } else if ((serumHDL >= 35) && (serumHDL <= 44)) { score += 1; } else if (serumHDL < 35) { score += 2; } //////////////////// // Total Cholesterol if ((totalChol >= 160) && (totalChol <= 199)) { score += 1; } else if ((totalChol >= 200) && (totalChol <= 239)) { score += 2; } else if ((totalChol >= 240) && (totalChol <= 279)) { score += 3; } else if (totalChol >= 280) { score += 4; } //////////////////// // SBP Untreated if (!GetLabValue("OnHTNMeds")) { if ((systolicBP <= 120)) { score = score - 2; } else if ((systolicBP >= 130) && (systolicBP <= 139)) { score += 1; } else if ((systolicBP >= 140) && (systolicBP <= 159)) { score += 2; } else if (systolicBP >= 160) { score += 3; } } // if (!GetLabValue("OnHTNMeds")) else { // SBP Treated if ((systolicBP >= 120) && (systolicBP <= 129)) { score += 2; } else if ((systolicBP >= 130) && (systolicBP <= 139)) { score += 3; } else if ((systolicBP >= 140) && (systolicBP <= 159)) { score += 4; } else if (systolicBP >= 160) { score += 5; } } // if (GetLabValue("OnHTNMeds")) //////////////////// // Diabetic and Smoking if (GetLabValue("IsDiabetic")) { score += 3; } if (GetLabValue("IsSmoker")) { score += 4; } if (score <= -3) { risk = 0; } else if (score == -2) { risk = 1.1; } else if (score == -1) { risk = 1.4; } else if (score == 0) { risk = 1.6; } else if (score == 1) { risk = 1.9; } else if (score == 2) { risk = 2.3; } else if (score == 3) { risk = 2.8; } else if (score == 4) { risk = 3.3; } else if (score == 5) { risk = 3.9; } else if (score == 6) { risk = 4.7; } else if (score == 7) { risk = 5.6; } else if (score == 8) { risk = 6.7; } else if (score == 9) { risk = 7.9; } else if (score == 10) { risk = 9.4; } else if (score == 11) { risk = 11.2; } else if (score == 12) { risk = 13.2; } else if (score == 13) { risk = 15.6; } else if (score == 14) { risk = 18.4; } else if (score == 15) { risk = 21.6; } else if (score == 16) { risk = 25.3; } else if (score == 17) { risk = 29.4; } else if (score >= 18) { risk = 30; } ////////////////// FEMALE } else { //////////////////// // Age if ((patientAge >= 35) && (patientAge <= 39)) { score += 2; } else if ((patientAge >= 40) && (patientAge <= 44)) { score += 4; } else if ((patientAge >= 45) && (patientAge <= 49)) { score += 5; } else if ((patientAge >= 50) && (patientAge <= 54)) { score += 7; } else if ((patientAge >= 55) && (patientAge <= 59)) { score += 8; } else if ((patientAge >= 60) && (patientAge <= 64)) { score += 9; } else if ((patientAge >= 65) && (patientAge <= 69)) { score += 10; } else if ((patientAge >= 70) && (patientAge <= 74)) { score += 11; } else if (patientAge >= 75) { score += 12; } //////////////////// // HDL if (serumHDL >= 60) { score = score - 2; } else if ((serumHDL >= 50) && (serumHDL <= 59)) { score = score - 1; } else if ((serumHDL >= 35) && (serumHDL <= 44)) { score += 1; } else if (serumHDL < 35) { score += 2; } //////////////////// // Total Cholesterol if ((totalChol >= 160) && (totalChol <= 199)) { score += 1; } else if ((totalChol >= 200) && (totalChol <= 239)) { score += 3; } else if ((totalChol >= 240) && (totalChol <= 279)) { score += 4; } else if (totalChol >= 280) { score += 5; } //////////////////// // SBP Untreated if (!GetLabValue("OnHTNMeds")) { if ((systolicBP <= 120)) { score = score - 3; } else if ((systolicBP >= 130) && (systolicBP <= 139)) { score += 1; } else if ((systolicBP >= 140) && (systolicBP <= 149)) { score += 2; } else if ((systolicBP >= 150) && (systolicBP <= 159)) { score += 4; } else if (systolicBP >= 160) { score += 5; } } // if (!GetLabValue("OnHTNMeds")) //////////////////// // SBP Treated if (GetLabValue("OnHTNMeds")) { if ((systolicBP <= 120)) { score = score - 1; } else if ((systolicBP >= 120) && (systolicBP <= 129)) { score += 2; } else if ((systolicBP >= 130) && (systolicBP <= 139)) { score += 3; } else if ((systolicBP >= 140) && (systolicBP <= 149)) { score += 5; } else if ((systolicBP >= 150) && (systolicBP <= 159)) { score += 6; } else if (systolicBP >= 160) { score += 7; } } // if (GetLabValue("OnHTNMeds")) //////////////////// // Diabetic and Smoking if (GetLabValue("IsDiabetic")) { score += 4; } if (GetLabValue("IsSmoker")) { score += 3; } if (score <= -2) { risk = 0; } else if (score == -1) { risk = 1.0; } else if (score == 0) { risk = 1.2; } else if (score == 1) { risk = 1.5; } else if (score == 2) { risk = 1.7; } else if (score == 3) { risk = 2.0; } else if (score == 4) { risk = 2.4; } else if (score == 5) { risk = 2.8; } else if (score == 6) { risk = 3.3; } else if (score == 7) { risk = 3.9; } else if (score == 8) { risk = 4.5; } else if (score == 9) { risk = 5.3; } else if (score == 10) { risk = 6.3; } else if (score == 11) { risk = 7.3; } else if (score == 12) { risk = 8.6; } else if (score == 13) { risk = 10.0; } else if (score == 14) { risk = 11.7; } else if (score == 15) { risk = 13.7; } else if (score == 16) { risk = 15.9; } else if (score == 17) { risk = 18.5; } else if (score == 18) { risk = 21.5; } else if (score == 19) { risk = 24.8; } else if (score == 20) { risk = 28.5; } else if (score >= 21) { risk = 30; } } MedNote_SetValueNumber("FraminghamOutput", risk); fShowValues = true; fAddFootNote = true; } /////////////////////////////////////////// // ESRD Risk if ((GetLabValue("GFR") > 0) || (GetLabValue("ReportedGFR") > 0) || (GetLabValue("ReportedAfricanGFR"))) { // This seems to use the reported Calcium, not the value corrected by albumin. if ((GetLabValue("UrineCreatinine") > 0) && (GetLabValue("UrineAlbumin") > 0) && (patientAge > 0) && (GetLabValue("Calcium") > 0) && (GetLabValue("Phos") > 0) && (albumin > 0) && (GetLabValue("HCO3") > 0)) { ComputeRiskOfESRD(); MedNote_SetValueNumber("Est2YearESRDRisk", g_2YearESRDRisk); MedNote_SetValueNumber("Est5YearESRDRisk", g_5YearESRDRisk); fShowValues = true; } } /////////////////////////////////////////// // Urea Reduction Ratio if ((GetLabValue("PreBUN") > 0) && (GetLabValue("PostBUN") > 0)) { // URR is usually measured only once every 12 to 14 treatments, which is once a month // Target *average* URR over 65% var ureaReductionRatio = ((GetLabValue("PreBUN") - GetLabValue("PostBUN")) / GetLabValue("PreBUN")) * 100; // Round it to 1 decomal places. We add 0.00001 to work around a Javascript bug. ureaReductionRatio = Math.round((ureaReductionRatio + 0.00001) * 10) / 10; MedNote_SetValueNumber("UreaReductionRatio", ureaReductionRatio); } /////////////////////////////////////////// // Kt/v if ((GetLabValue("PreBUN") > 0) && (GetLabValue("PostBUN") > 0) && (GetLabValue("PostHDWeightInKg") > 0) && (GetLabValue("PreHDWeightInKg") > 0) && (GetLabValue("HDTimeInMin") > 0)) { var MinutesInWeek = 10080; var UFInKg = GetLabValue("PreHDWeightInKg") - GetLabValue("PostHDWeightInKg"); var treatmentsPerWeek = 3; var theoreticalKtV = -1; var singleCompartmentKtV = -1; var equilibratedKtV; var standardKtV; // Single Pool Kt/V // See Daugirdas JT, "Second generation logarithmic estimates of single-pool variable volume Kt/V: an analysis of error", J Am Soc Nephrol. 1993 Nov;4(5):1205-13. // http://www.ncbi.nlm.nih.gov/pubmed/8305648 singleCompartmentKtV = - Math.log((GetLabValue("PostBUN") / GetLabValue("PreBUN")) - (0.008 * (GetLabValue("HDTimeInMin") / 60))) + ((4 - (3.5 * (GetLabValue("PostBUN") / GetLabValue("PreBUN")))) * (UFInKg / GetLabValue("PostHDWeightInKg"))); // Equilibrated Kt/V // See Leypoldt equation for Equilibrated Double Pool // http://onlinelibrary.wiley.com/doi/10.1111/j.1525-139X.2006.00132.x/full var equilibratedKtV = (0.924 * singleCompartmentKtV) - (0.395 * (singleCompartmentKtV / (GetLabValue("HDTimeInMin") / 60))) + 0.056; if (equilibratedKtV > singleCompartmentKtV) { equilibratedKtV = singleCompartmentKtV; } // Standard Kt/V // See Leypoldt equation for Standard (stdKt/V) //var standardKtV = (MinutesInWeek * (1 - Math.exp(-equilibratedKtV)) / GetLabValue("HDTimeInMin")) / (((1 - Math.exp(-equilibratedKtV)) /singleCompartmentKtV) + (MinutesInWeek / (treatmentsPerWeek * GetLabValue("HDTimeInMin")) -1)); var standardKtV = (MinutesInWeek * (1-Math.exp(- equilibratedKtV)) / GetLabValue("HDTimeInMin")) / (((1 - Math.exp(- equilibratedKtV)) / singleCompartmentKtV) + (MinutesInWeek / (treatmentsPerWeek * GetLabValue("HDTimeInMin")) - 1)); // Theoretical Kt/v, assuming a perfect filter that does not get clogged as the session goes on, and // also no urea rebound from extravascular space if ((GetLabValue('FilterSelect') > -1) && (GetLabValue('BloodFlowSelect') > -1)) { var bloodFlowIndex = GetLabValue('BloodFlowSelect'); var bloodFlowStr = g_BloodFlowList[bloodFlowIndex]; var bloodFlow = parseInt(bloodFlowStr); var clearance = 0; var filterName = GetLabValueStringForPlan('FilterSelect'); if (filterName == "F-160") { var clearanceArray = g_F160Info.UreaCl; clearance = g_F160Info.UreaCl[bloodFlowIndex]; } else if (filterName == "F-180") { clearance = g_F180Info.UreaCl[bloodFlowIndex]; } else if (filterName == "F-200") { clearance = g_F200Info.UreaCl[bloodFlowIndex]; } else if (filterName == "Exceltra-170") { clearance = g_Exceltra170Info.UreaCl[bloodFlowIndex]; } else if (filterName == "Exceltra-190") { clearance = g_Exceltra190Info.UreaCl[bloodFlowIndex]; } else if (filterName == "Exceltra-210") { clearance = g_Exceltra210Info.UreaCl[bloodFlowIndex]; } else if (filterName == "Revaclear") { clearance = g_RevaclearInfo.UreaCl[bloodFlowIndex]; } else if (filterName == "Revaclear-MAX") { clearance = g_RevaclearMaxInfo.UreaCl[bloodFlowIndex]; } theoreticalKtV = (clearance * GetLabValue("HDTimeInMin")) / EstimatedTotalBodyWater; } // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. standardKtV = Math.round((standardKtV + 0.00001) * 100) / 100; equilibratedKtV = Math.round((equilibratedKtV + 0.00001) * 100) / 100; singleCompartmentKtV = Math.round((singleCompartmentKtV + 0.00001) * 100) / 100; theoreticalKtV = Math.round((theoreticalKtV + 0.00001) * 100) / 100; MedNote_SetValueNumber("StandardKtV", standardKtV); MedNote_SetValueNumber("EquilibratedKtV", equilibratedKtV); MedNote_SetValueNumber("SingleCompartmentKtV", singleCompartmentKtV); MedNote_SetValueNumber("EstimatedKtV", theoreticalKtV); fShowValues = true; } /////////////////////////////////////////// if ((sodium > 0) && (GetLabValue("Glucose") > 0) && (GetLabValue("BUN") > 0)) { var serumOsm = (2 * sodium) + (GetLabValue("Glucose") / 18) + (GetLabValue("BUN") / 2.8); serumOsm = Math.round((serumOsm + 0.00001) * 10) / 10; MedNote_SetValueNumber("ComputedSerumOsm", serumOsm); fShowValues = true; } /////////////////////////////////////////// // MELD // // There may be better scores. See: // // Ming Jiang, Fei Liu, Wu-Jun Xiong, Lan Zhong, and Xi-Mei Chen // "Comparison of four models for end-stage liver disease in evaluating the prognosis of cirrhosis" // World J Gastroenterol. 2008 Nov 14; 14(42): 6546–6550. // https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2773344/ if ((GetLabValue("INR") > 0) && (creatinine > 0) && (GetLabValue("TBili") > 0)) { var meldScore = 10 * ((0.957 * Math.log(creatinine)) + (0.378 * Math.log(GetLabValue("TBili"))) + (1.12 * Math.log(GetLabValue("INR"))) + 0.643); meldScore = Math.round(meldScore); MedNote_SetValueNumber("MELD", meldScore); fShowValues = true; } /////////////////////////////////////////// // // Maddrey Discriminant Function // // Maddrey WC, Boitnott JK, Bedine MS, Weber FL, Mezey E, White RI (1978). // "Corticosteroid therapy of alcoholic hepatitis" // Gastroenterology 75 (2): 193–9. PMID 352788 // // Soultati AS, et. al. // Predicting utility of a model for end stage liver disease in alcoholic liver disease // World J Gastroenterol 2006 July 07;12(25):4020-4025 if ((GetLabValue("PT") > 0) && (creatinine > 0) && (GetLabValue("TBili") > 0)) { // The reference range for prothrombin time is 9.5-13.5 seconds. var ReferencePT = 11.5; var discriminantFunction = (4.6 * (GetLabValue("PT") - ReferencePT)) + GetLabValue("TBili"); discriminantFunction = Math.round(discriminantFunction); MedNote_SetValueNumber("DiscriminantFunction", discriminantFunction); fShowValues = true; } /////////////////////////////////////////// // Child-Pugh // // François Durand, Dominique Valla // Assessment of the prognosis of cirrhosis: Child–Pugh versus MELD // Journal of hepatology April 2005 Volume 42, Issue 1, Supplement, Pages S100–S107 if ((albumin > 0) && (GetLabValue("TBili") > 0) && (GetLabValue("INR") > 0)) { var score = 0; var tBili = GetLabValue("TBili"); if (tBili < 2) { score += 1; } else if (tBili <= 3) { score += 2; } else { score += 3; } if (albumin > 3.5) { score += 1; } else if (albumin >= 2.8) { score += 2; } else { score += 3; } var INR = GetLabValue("INR"); if (INR < 1.7) { score += 1; } else if (INR <= 2.2) { score += 2; } else { score += 3; } var ascites = GetLabValue("AscitesSelect"); if (ascites == 0) { // absent score += 1; } else if (ascites == 2) { // Slight score += 2; } else { score += 3; } var encephalopathy = GetLabValue("EncephalopathySelect"); if (encephalopathy == 1) { // None score += 1; } else if (encephalopathy == 2) { // Grade 1-2 score += 2; } else { score += 3; } score = Math.round(score); var className = "(Class A)"; if ((score >= 7) && (score <= 9)) { className = "(Class B)"; } else if ((score >= 10)) { className = "(Class C)"; } MedNote_SetValueNumberWithComment("ChildPugh", score, className); fAddFootNote = true; fShowValues = true; } /////////////////////////////////////////// // Aa Gradient // // Normal gradient is < 10. A high Aa gradient means impaired diffusion or VQ mismatch due to shunting. // This assumes 100% humidity at sea level and a respiratory quotient of 0.8 if ((GetLabValue("PaO2") > 0) && (GetLabValue("PaCO2") > 0)) { var FiO2 = 0.21; var PAO2 = (FiO2 * (760 - 47)) - (GetLabValue("PaCO2") / 0.8); var AaGradient = PAO2 - GetLabValue("PaO2"); AaGradient = Math.round(AaGradient); MedNote_SetValueNumber("AaGradientOutput", AaGradient); fShowValues = true; } /////////////////////////////////////////// // Free Water Deficit if (sodium > 0) { var freeWaterDeficit = EstimatedTotalBodyWater * ((sodium / 140) - 1); // This is in liters, so round to the nearest 10th freeWaterDeficit = Math.round((freeWaterDeficit + 0.00001) * 10) / 10; MedNote_SetValueNumber("FreeWaterDeficit", freeWaterDeficit); fShowValues = true; } /////////////////////////////////////////// // Electrolyte-Free Water Clearance // // See Minhtri K. Nguyen and Ira Kurtz, // "Derivation of a new formula for calculating urinary electrolyte-free water clearance based on the Edelman equation" // Am J Physiol Renal Physiol 288: F1–F7, 2005; // http://ajprenal.physiology.org/content/ajprenal/288/1/F1.full.pdf if ((sodium > 0) && (GetLabValue("UrineSodium") > 0) && (GetLabValue("UrinePotassium") > 0) && (GetLabValue("UrineVolume") > 0)) { var urineLyteConcentration = GetLabValue("UrineSodium") + GetLabValue("UrinePotassium"); var fractionOfUrineThatIsIsoOsmolar = urineLyteConcentration / sodium; var fractionOfUrineThatIsIsPureWater = 1 - fractionOfUrineThatIsIsoOsmolar; var volumeOfUrineThatIsIsPureWater = fractionOfUrineThatIsIsPureWater * GetLabValue("UrineVolume"); // This is in liters, so round to the nearest 10th volumeOfUrineThatIsIsPureWater = Math.round((volumeOfUrineThatIsIsPureWater + 0.00001) * 10) / 10; MedNote_SetValueNumber("ElectrolyteFreeWaterClearance", volumeOfUrineThatIsIsPureWater); } /////////////////////////////////////////// // Trans-Tubular Potassium Gradient if ((sodium > 0) && (GetLabValue("Glucose") > 0) && (GetLabValue("BUN") > 0) && (GetLabValue("Potassium") > 0) && (GetLabValue("UrinePotassium") > 0) && (GetLabValue("UrineOsm") > 0)) { var serumOsm = GetLabValue("Osmolality"); if (serumOsm < 0) { serumOsm = (2 * sodium) + (GetLabValue("Glucose") / 18) + (GetLabValue("BUN") / 2.8); } var transTubularKGradient = ((GetLabValue("UrinePotassium") / (GetLabValue("Potassium"))) / (GetLabValue("UrineOsm") / serumOsm)); transTubularKGradient = Math.round((transTubularKGradient + 0.00001) * 10) / 10; MedNote_SetValueNumber("TransTubularKGradient", transTubularKGradient); fShowValues = true; } /////////////////////////////////////////// // FENa - Fractional Excretion Sodium if ((GetLabValue("UrineSodium") > 0) && (sodium > 0) && (GetLabValue("UrineCreatinine") > 0) && (creatinine > 0)) { var FENa = (GetLabValue("UrineSodium") / sodium) / (GetLabValue("UrineCreatinine") / creatinine); // Convert to a percentage FENa = FENa * 100; // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. FENa = Math.round((FENa + 0.00001) * 100) / 100; MedNote_SetValueNumber("FENa", FENa); fShowValues = true; } /////////////////////////////////////////// // FEUrea - Fractional Excretion Urea if ((GetLabValue("UrineUrea") > 0) && (GetLabValue("BUN") > 0) && (GetLabValue("UrineCreatinine") > 0) && (creatinine > 0)) { var FEUrea = (GetLabValue("UrineUrea") / GetLabValue("BUN")) / (GetLabValue("UrineCreatinine") / creatinine); // Convert to a percentage FEUrea = FEUrea * 100; // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. FEUrea = Math.round((FEUrea + 0.00001) * 100) / 100; MedNote_SetValueNumber("FEUrea", FEUrea); } /////////////////////////////////////////// // Fractional Excretion Phos if ((GetLabValue("UrinePhos") > 0) && (GetLabValue("Phos") > 0) && (GetLabValue("UrineCreatinine") > 0) && (creatinine > 0)) { var FEPhos = (GetLabValue("UrinePhos") / GetLabValue("Phos")) / (GetLabValue("UrineCreatinine") / creatinine); // Convert to a percentage FEPhos = FEPhos * 100; // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. FEPhos = Math.round((FEPhos + 0.00001) * 100) / 100; MedNote_SetValueNumber("FEPhos", FEPhos); } /////////////////////////////////////////// // Fractional Excretion Calcium if ((GetLabValue("UrineCalcium") > 0) && (GetLabValue("Calcium") > 0) && (GetLabValue("UrineCreatinine") > 0) && (creatinine > 0)) { var FECalcium = (GetLabValue("UrineCalcium") / GetLabValue("Calcium")) / (GetLabValue("UrineCreatinine") / creatinine); // Convert to a percentage FECalcium = FECalcium * 100; // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. FECalcium = Math.round((FECalcium + 0.00001) * 100) / 100; MedNote_SetValueNumber("FECalcium", FECalcium); } /////////////////////////////////////////// // Fractional Excretion Urate if ((GetLabValue("UrineUrate") > 0) && (GetLabValue("UricAcid") > 0) && (GetLabValue("UrineCreatinine") > 0) && (creatinine > 0)) { var FEUrate = (GetLabValue("UrineUrate") / GetLabValue("UricAcid")) / (GetLabValue("UrineCreatinine") / creatinine); // Convert to a percentage FEUrate = FEUrate * 100; // Round it to 2 decomal places. We add 0.00001 to work around a Javascript bug. FEUrate = Math.round((FEUrate + 0.00001) * 100) / 100; MedNote_SetValueNumber("FEUrate", FEUrate); } if (fAddFootNote) { var footnoteHtmlElement = document.getElementById("CalcOutputFootNotes"); if (footnoteHtmlElement) { Util_RemoveAllChildNodes(footnoteHtmlElement); var textNode = document.createTextNode("(*) means this value requires that you also set manually entered options or values in the calculator"); footnoteHtmlElement.appendChild(textNode); } } //LogEvent("Got to end of MedNote_CalculateAllValues. fShowValues=" + fShowValues); if (fShowValues) { //LogEvent("Got to end of MedNote_CalculateAllValues. g_ComputedResultsDivElement=" + g_ComputedResultsDivElement); g_ComputedResultsDivElement.style.display = "inline"; } if (GetLabValue("IsMale")) { g_hisHer = "his"; g_CapHisHer = "His"; g_himHer = "him"; g_CapHimHer = "His"; g_heShe = "he"; g_CapHeShe = "He"; } else { g_hisHer = "her"; g_CapHisHer = "Her"; g_himHer = "her"; g_CapHimHer = "Her"; g_heShe = "she"; g_CapHeShe = "She"; } } // MedNote_CalculateAllValues //////////////////////////////////////////////////////////////////////////////// // // [ComputeRiskOfESRD] // // Based on retrospective studies. See: // Tangri N, Stevens LA, Griffith J, et al. "A predictive model for progression of chronic kidney disease to kidney failure" JAMA. 2011;305(15) // Tangri N, Grams ME, Levey AS et al, "Multinational Assessment of Accuracy of Equations for Predicting Risk of Kidney Failure: A Meta-analysis", JAMA. 2016;315(2):1-11 // // Some handy websites for checking my implementation. // https://qxmd.com/calculate/calculator_125/kidney-failure-risk-equation-8-variable // http://kidneyfailurerisk.com/ // http://kidneyfailurerisk.com/assets/js/kidney-app.js //////////////////////////////////////////////////////////////////////////////// function ComputeRiskOfESRD() { //LogEvent("ComputeRiskOfESRD"); var estimatedGFR = 0; var maleValue; var baselineChanceOfHealthy; var riskExponent; var chanceHealthy; var albumin = GetLabValue("Albumin"); var patientAge = GetLabValue("Age"); g_2YearESRDRisk = -1; g_5YearESRDRisk = -1; if (GetLabValue("GFR") > 0) { estimatedGFR = GetLabValue("GFR"); } else if ((GetLabValue("IsCaucasian")) && (GetLabValue("ReportedGFR") > 0)) { estimatedGFR = GetLabValue("ReportedGFR"); } else if ((!GetLabValue("IsCaucasian")) && (GetLabValue("ReportedAfricanGFR") > 0)) { estimatedGFR = GetLabValue("ReportedAfricanGFR"); } var urineAlbCrRatio = GetLabValue("UrineAlbumin") / GetLabValue("UrineCreatinine"); // mg/g //LogEvent("urineAlbCrRatio=" + urineAlbCrRatio); var lnUrineAlbCrRatio = Math.log(urineAlbCrRatio); if (GetLabValue("IsMale") ) { maleValue = 1; } else { maleValue = 0; } //////////////////////////////////////////// // Calculate the Two-year risk. There are several formulae: // // 8-Variable - North America - Two-year Risk. // 1 – 0.9757 ^ exp (-0.1992 × (age/10 – 7.036) + 0.1602 × (male – 0.5642) – 0.4919 × (eGFR/5 – 7.222) // + 0.3364 × (logACR – 5.137) – 0.3441 × (albumin – 3.997) + 0.2604 × (phosphorous – 3.916) // – 0.07354 × (bicarbonate – 25.57) – 0.2228 × (calcium – 9.355)) // // 8-Variable - Global Two-year Risk // 1 – 0.9629 ^ exp (-0.1848 × (age/10 – 7.036) + 0.2906 × (male – 0.5642) – 0.4156 × (eGFR/5 – 7.222) // + 0.3480 × (logACR – 5.137) – 0.3569 × (albumin – 3.997) + 0.1582 × (phosphorous – 3.916) // – 0.01199 × (bicarbonate – 25.57) – 0.1581 × (calcium – 9.355)) // // Four-Variable - North America - Two-year Risk. // 1 – 0.9751 ^ exp (-0.2201 × (age/10 – 7.036) + 0.2467 × (male – 0.5642) – 0.5567 × (eGFR/5 – 7.222) + 0.4510 × (logACR – 5.137)) // // Four-Variable - Global - Two-year Risk // 1 – 0.9676 ^ exp (-0.2245 × (age/10 – 7.036) + 0.3212 × (male – 0.5642) – 0.4553 × (eGFR/5 – 7.222) + 0.4469 × (logACR – 5.137)) g_SumofBetaXBar = 0; g_SumofBetaX = 0; g_TotalDelta = 0; // If we have values for albumin, phosphorous, bicarbonate, and calcium then we can compute the 8-variable form. if ((albumin > 0) && (GetLabValue("Phos") > 0) && (GetLabValue("HCO3") > 0) && (GetLabValue("Calcium") > 0)) { AddTermToESRDRiskScore("GFR", -0.4919, 7.222, estimatedGFR / 5); AddTermToESRDRiskScore("Sex", 0.1602, 0.5642, maleValue); AddTermToESRDRiskScore("Urine Albumin/Cr Ratio", 0.3364, 5.137, lnUrineAlbCrRatio); AddTermToESRDRiskScore("Age", -0.1992, 7.036, patientAge / 10); AddTermToESRDRiskScore("Albumin", -0.3441, 3.997, albumin); AddTermToESRDRiskScore("Phos", 0.2604, 3.916, GetLabValue("Phos")); AddTermToESRDRiskScore("Bicarb", -0.07354, 25.57, GetLabValue("HCO3")); AddTermToESRDRiskScore("Calcium", -0.2228, 9.355, GetLabValue("Calcium")); // Thie is the empirically observed baseline survival rate in the data sets. // Note, that in these patients, there is a baseline chance of needing ESRD (around 2.5%) since this survival rate is less than 1.0. baselineChanceOfHealthy = 0.9757; } // Compute the Eight-variable form. else { AddTermToESRDRiskScore("Age", -0.2201, 7.036, patientAge / 10); AddTermToESRDRiskScore("Sex", 0.2467, 0.5642, maleValue); AddTermToESRDRiskScore("GFR", -0.5567, 7.222, estimatedGFR / 5); AddTermToESRDRiskScore("Urine Albumin/Cr Ratio", 0.4510, 5.137, lnUrineAlbCrRatio); // Thie is the empirically observed baseline survival rate in the data sets. // Note, that in these patients, there is a baseline chance of needing ESRD (around 2.5%) since this survival rate is less than 1.0. baselineChanceOfHealthy = 0.9751; } // Compute the Two-variable form // First get e**sum, which is the exponent we will use to compute the the chance of survival. riskExponent = Math.exp(g_TotalDelta); // Now, compute the survival probability. This is the chance of NOT being ESRD. chanceHealthy = Math.pow(baselineChanceOfHealthy, riskExponent); //LogEvent("chanceHealthy=" + chanceHealthy); // The risk of ESRD is 100% - chance of avoiding ESRD g_2YearESRDRisk = (1.0 - chanceHealthy); g_2YearESRDRisk = parseInt(g_2YearESRDRisk * 1000); g_2YearESRDRisk = parseFloat(g_2YearESRDRisk / 10); //LogEvent("2 year risk of ESRD=" + g_2YearESRDRisk); //////////////////////////////////////////// // Calculate the Five-year risk. There are several formulae: // // 8-Variable - North America - Five-year Risk. // 1 – 0.9096 ^ exp (-0.1992 × (age/10 – 7.036) + 0.1602 × (male – 0.5642) – 0.4919 × (eGFR/5 – 7.222) // + 0.3364 × (logACR – 5.137) – 0.3441 × (albumin – 3.997) + 0.2604 × (phosphorous – 3.916) // – 0.07354 × (bicarbonate – 25.57) – 0.2228 × (calcium – 9.355)) // // 8-Variable - Global Five-year Risk // 1 – 0.8636 ^ exp (-0.1848 × (age/10 – 7.036) + 0.2906 × (male – 0.5642) – 0.4156 × (eGFR/5 – 7.222) // + 0.3480 × (logACR – 5.137) – 0.3569 × (albumin – 3.997) + 0.1582 × (phosphorous – 3.916) // – 0.01199 × (bicarbonate – 25.57) – 0.1581 × (calcium – 9.355)) // // Four-Variable - North America - Five-year Risk. // 1 – 0.8996 ^ exp (-0.2201 × (age/10 – 7.036) + 0.2467 × (male – 0.5642) – 0.5567 × (eGFR/5 – 7.222) + 0.4510 × (logACR – 5.137)) // // Four-Variable - Global - Five-year Risk // 1 – 0.8762 ^ exp (-0.2245 × (age/10 – 7.036) + 0.3212 × (male – 0.5642) – 0.4553 × (eGFR/5 – 7.222) + 0.4469 × (logACR – 5.137)) g_SumofBetaXBar = 0; g_SumofBetaX = 0; g_TotalDelta = 0; // If we have values for albumin, phosphorous, bicarbonate, and calcium then we can compute the 8-variable form. if ((albumin > 0) && (GetLabValue("Phos") > 0) && (GetLabValue("HCO3") > 0) && (GetLabValue("Calcium") > 0)) { AddTermToESRDRiskScore("GFR", -0.4919, 7.222, estimatedGFR / 5); AddTermToESRDRiskScore("Sex", 0.1602, 0.5642, maleValue); AddTermToESRDRiskScore("Urine Albumin/Cr Ratio", 0.3364, 5.137, lnUrineAlbCrRatio); AddTermToESRDRiskScore("Age", -0.1992, 7.036, patientAge / 10); AddTermToESRDRiskScore("Albumin", -0.3441, 3.997, albumin); AddTermToESRDRiskScore("Phos", 0.2604, 3.916, GetLabValue("Phos")); AddTermToESRDRiskScore("Bicarb", -0.07354, 25.57, GetLabValue("HCO3")); AddTermToESRDRiskScore("Calcium", -0.2228, 9.355, GetLabValue("Calcium")); // Thie is the empirically observed baseline survival rate in the data sets. // Note, that in these patients, there is a baseline chance of needing ESRD (around 9%) since this survival rate is less than 1.0. baselineChanceOfHealthy = 0.9096; } // Compute the Eight-variable form. else { AddTermToESRDRiskScore("GFR", -0.5567, 7.222, estimatedGFR / 5); AddTermToESRDRiskScore("Sex", 0.2467, 0.5642, maleValue); AddTermToESRDRiskScore("Urine Albumin/Cr Ratio", 0.4510, 5.137, lnUrineAlbCrRatio); AddTermToESRDRiskScore("Age", -0.2201, 7.036, patientAge / 10); // Thie is the empirically observed baseline survival rate in the data sets. // Note, that in these patients, there is a baseline chance of needing ESRD (around 9%) since this survival rate is less than 1.0. baselineChanceOfHealthy = 0.8996; } // Compute the Two-variable form // First get e**sum, which is the exponent we will use to compute the the chance of survival. riskExponent = Math.exp(g_TotalDelta); // Now, compute the survival probability. This is the chance of NOT being ESRD. chanceHealthy = Math.pow(baselineChanceOfHealthy, riskExponent); //LogEvent("chanceHealthy=" + chanceHealthy); // The risk of ESRD is 100% - chance of avoiding ESRD g_5YearESRDRisk = (1.0 - chanceHealthy); g_5YearESRDRisk = parseInt(g_5YearESRDRisk * 1000); g_5YearESRDRisk = parseFloat(g_5YearESRDRisk / 10); //LogEvent("5 year risk of ESRD =" + g_5YearESRDRisk); } // ComputeRiskOfESRD //////////////////////////////////////////////////////////////////////////////// // // [AddTermToESRDRiskScore] // Called by ComputeRiskOfESRD for computing ESRD risk. //////////////////////////////////////////////////////////////////////////////// function AddTermToESRDRiskScore(labelStr, coefficient, xBar, xVal) { var betaXbar; var betaX; betaXbar = coefficient * xBar; betaX = coefficient * xVal; //LogEvent(labelStr + ": xVal=" + xVal + ", coefficient=" + coefficient + ", xBar=" + xBar); //LogEvent("________________betaXbar=" + betaXbar + ", betaX=" + betaX); g_SumofBetaX = g_SumofBetaX + betaX; g_SumofBetaXBar = g_SumofBetaXBar + betaXbar; var currentDelta = coefficient * (xVal - xBar); g_TotalDelta = g_TotalDelta + currentDelta; } // AddTermToESRDRiskScore //////////////////////////////////////////////////////////////////////////////// // // [SaveValueFromOneString] // // This is used by the import functions, so it reads a value from a text string // that was imported from another EMR system. //////////////////////////////////////////////////////////////////////////////// function SaveValueFromOneString(lineArray, lineNum, valueNameStr, str, startIndex) { //LogEvent("SaveValueFromOneString. lineNum=" + lineNum + ", str=" + str); var totalNumberStr = ""; var startLineNum = lineNum; while (true) { totalNumberStr = ReadNumberFromStr(str, startIndex); if (totalNumberStr != "") { //LogEvent("SaveValueFromOneString. totalNumberStr=" + totalNumberStr); //LogEvent("SaveValueFromOneString. htmlElement=" + htmlElement); //LogEvent("SaveValueFromOneString. htmlElement.value=" + htmlElement.value); MedNote_SetValueNumber(valueNameStr, intVal); return(lineNum); } // if (totalNumberStr != "") lineNum += 1; if (lineNum >= lineArray.length) { return(lineNum); } str = lineArray[lineNum]; } // while (true) } // SaveValueFromOneString //////////////////////////////////////////////////////////////////////////////// // // [ReadNumberFromStr] // // This is used by the import functions, so it reads a value from a text string // that was imported from another EMR system. //////////////////////////////////////////////////////////////////////////////// function ReadNumberFromStr(str, startIndex) { //LogEvent("ReadNumberFromStr. startIndex=" + startIndex + ", Str=" + str); var index; var currentChar; var charArray; var tempCharStr; var currentCharAsNumber; var totalNumberStr = ""; var charCode; // Remove the prefix. This saves time, but it also avoids confusion over names that contain // numbers, like "CO2" str = str.substring(startIndex, 200); //LogEvent("ReadNumberFromStr. modified split Str=" + str); charArray = str.split(''); // Skip ahead to the first number character. for (index = 0; index < charArray.length; index++) { currentChar = charArray[index]; //LogEvent("ReadNumberFromStr. currentChar=" + currentChar); tempCharStr = "" + currentChar; //LogEvent("ReadNumberFromStr. tempCharStr=" + tempCharStr); currentCharAsNumber = parseInt(tempCharStr); //LogEvent("ReadNumberFromStr. currentCharAsNumber=" + currentCharAsNumber); if (!isNaN(currentCharAsNumber)) { //LogEvent("ReadNumberFromStr. Found a Number! currentCharAsNumber=" + currentCharAsNumber); break; } } // Read all of the number chars for (index = index; index < charArray.length; index++) { currentChar = charArray[index]; //LogEvent("ReadNumberFromStr. currentChar=" + currentChar); tempCharStr = "" + currentChar; charCode = tempCharStr.charCodeAt(0); //LogEvent("ReadNumberFromStr. charCode=" + charCode); if (((charCode >= 48) && (charCode <= 57)) || (charCode == 46)) { //LogEvent("ReadNumberFromStr. Add one number to the str. tempCharStr=" + tempCharStr); totalNumberStr = totalNumberStr + tempCharStr; } else { break; } } //LogEvent("ReadNumberFromStr. totalNumberStr=" + totalNumberStr); return(totalNumberStr); } // ReadNumberFromStr //////////////////////////////////////////////////////////////////////////////// // // [MedNote_ImportSCMLabs] // //////////////////////////////////////////////////////////////////////////////// function MedNote_ImportSCMLabs(lineArray) { //LogEvent("MedNote_ImportSCMLabs"); var index = 0; for (index = 0; index < lineArray.length; index++) { MedNote_ParseOneSCMLine(lineArray, index); } } // MedNote_ImportSCMLabs //////////////////////////////////////////////////////////////////////////////// // // [MedNote_ParseOneSCMLine] // //////////////////////////////////////////////////////////////////////////////// function MedNote_ParseOneSCMLine(lineArray, lineNum) { //LogEvent("MedNote_ParseOneSCMLine. lineNum=" + lineNum); var index; var str; if (lineNum < 0) { LogEvent("MedNote_ParseOneSCMLine. Invalid lineNum=" + lineNum); return; } str = lineArray[lineNum]; //LogEvent("MedNote_ParseOneSCMLine. str=" + str); ////////////////// // Urine // Do this FIRST, because other names are prefixes of these names, so we could accidentally // mistake "PROTEIN URINE" for "PROTEIN" index = str.indexOf("Sodium, Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineSodium", str, index); return; } index = str.indexOf("Phosphorus, Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrinePhos", str, index); return; } index = str.indexOf("Calcium, Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineCalcium", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineOsm", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineUrate", str, index); return; } index = str.indexOf("Magnesium,Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineMag", str, index); return; } index = str.indexOf("Potassium,Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrinePotassium", str, index); return; } index = str.indexOf("Chloride, Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineChloride", str, index); return; } index = str.indexOf("Urea Nitrogen,Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineUrea", str, index); return; } index = str.indexOf("Creatinine, Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineCreatinine", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { // This is mg/L lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineAlbumin", str, index); return; } index = str.indexOf("Protein, Urine Random"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineProtein", str, index); return; } index = str.indexOf("Osmolality, Urine"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UrineOsm", str, index); return; } ///////////////////////// // BMP index = str.indexOf("Sodium Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Sodium", str, index); return; } index = str.indexOf("Sodium, syringe"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Sodium", str, index); return; } index = str.indexOf("Potassium Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Potassium", str, index); return; } index = str.indexOf("Potassium, Syringe"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Potassium", str, index); return; } index = str.indexOf("Chloride Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Chloride", str, index); return; } index = str.indexOf("Chloride, Syringe"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Chloride", str, index); return; } index = str.indexOf("CO2"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "HCO3", str, index + 4); return; } index = str.indexOf("Bicarbonate, Venous"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "HCO3", str, index + 4); return; } index = str.indexOf("Urea Nitrogen, Blood"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "BUN", str, index); return; } index = str.indexOf("Creatinine Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Creatinine", str, index); return; } index = str.indexOf("Glucose Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Glucose", str, index); return; } index = str.indexOf("Glucose, Syringe"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Glucose", str, index); return; } index = str.indexOf("GFR, est. if Afr/Am"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "ReportedAfricanGFR", str, index); return; } index = str.indexOf("GFR, est"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "ReportedGFR", str, index); return; } ///////////////////////// // LFT index = str.indexOf("Alanine Aminotransferase"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "ALT", str, index); return; } index = str.indexOf("AST"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "AST", str, index); return; } index = str.indexOf("Alkaline Phosphatase"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "ALP", str, index); return; } index = str.indexOf("Bilirubin,Total"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "TBili", str, index); return; } index = str.indexOf("Total Protein"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "TProtein", str, index); return; } index = str.indexOf("Albumin Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Albumin", str, index); return; } index = str.indexOf("INR"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "INR", str, index); return; } index = str.indexOf("Prothrombin Time (PT1)"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "PT", str, index); return; } ////////////////// // MBD index = str.indexOf("Calcium, Total"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Calcium", str, index); return; } index = str.indexOf("Phosphorus"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Phos", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "VitD", str, index); return; } index = str.indexOf("PTH Intact Total"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "PTH", str, index); return; } index = str.indexOf("Magnesium Level"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Mag", str, index); return; } index = str.indexOf("Uric Acid"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "UricAcid", str, index); return; } index = str.indexOf("Osmolality, Plasma"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Osmolality", str, index); return; } ////////////////// // CBC index = str.indexOf("Platelet Count"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "Platelet", str, index); return; } index = str.indexOf("WBC Count"); if (index >= 0) { } else if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "WBC", str, index); return; } index = str.indexOf("Total Hemoglobin, syringe"); if (index >= 0) { //LogEvent("Try to read Hgb. str=" + str); lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "CBCHgb", str, index); return; } index = str.indexOf("Hemoglobin"); if (index >= 0) { //LogEvent("Try to read Hgb. str=" + str); lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "CBCHgb", str, index); return; } ////////////////// // ABG index = str.indexOf("pH, Venous"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "pH", str, index); return; } index = str.indexOf("PCO2, Venous"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "PaCO2", str, index); return; } index = str.indexOf("PO2, Venous"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "PaO2", str, index); return; } ////////////////// // Vitals index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "WeightInKg", str, index); // Convert lbs to kg var valueEntry = g_AllLabValuesDeclaration['WeightInKg']; if (valueEntry) { valueEntry.intVal = valueEntry.intVal / 2.20462; } return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "WeightInKg", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "SystolicBP", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "DiastolicBP", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "HR", str, index); return; } // <> Need These // "Age" "HeightInCm" // "PreBUN" "PostBUN" "HDTimeInMin" "PreHDWeightInKg" "PostHDWeightInKg" "FilterSelect" "BloodFlowSelect" "HDFreqSelect" "CystatinC" "IsMale" "IsCaucasian" "OnHTNMeds" "IsDiabetic" "IsSmoker" ////////////////// // Lipids index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "LDL", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "LDL", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "HDL", str, index); return; } index = str.indexOf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); if (index >= 0) { lineNum = MedNote_SaveValueFromOneSCMString(lineArray, lineNum, "TChol", str, index); return; } } // MedNote_ParseOneSCMLine //////////////////////////////////////////////////////////////////////////////// // // [MedNote_SaveValueFromOneSCMString] // // This is used by the import functions, so it reads a value from a text string // that was imported from another EMR system. //////////////////////////////////////////////////////////////////////////////// function MedNote_SaveValueFromOneSCMString(lineArray, lineNum, valueNameStr, str, startIndex) { //LogEvent("MedNote_SaveValueFromOneSCMString. lineNum=" + lineNum + ", str=" + str + ", startIndex=" + startIndex); var wordArray; var currentWord; var currentWordAsNumber; var index; // Remove the prefix. This saves time, but it also avoids confusion over names that contain // numbers, like "CO2" str = str.substring(startIndex, 200); //LogEvent("MedNote_SaveValueFromOneSCMString. modified split Str=" + str); wordArray = str.split(" "); for (index = 0; index < wordArray.length; index++) { currentWord = wordArray[index]; //LogEvent("MedNote_SaveValueFromOneSCMString. currentWord=[" + currentWord + "]"); // Skip whitespace. if ((currentWord == "") || (currentWord == " ")) { continue; } currentWordAsNumber = parseFloat(currentWord); //LogEvent("MedNote_SaveValueFromOneSCMString. currentWordAsNumber=" + currentWordAsNumber); if (!isNaN(currentWordAsNumber)) { //LogEvent("MedNote_SaveValueFromOneSCMString. Found a Number! currentWordAsNumber=" + currentWordAsNumber); // Only write a number once. This will use the first value which is the most recent. var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if ((valueEntry) && (-1 == valueEntry.intVal)) { //LogEvent("Write one lab value. valueNameStr=" + valueNameStr); MedNote_SetValueNumber(valueNameStr, currentWordAsNumber); } else { //LogEvent("Don't clobber one lab value. valueNameStr=" + valueNameStr); } break; } } // for () return(lineNum); } // MedNote_SaveValueFromOneSCMString //////////////////////////////////////////////////////////////////////////////// // // [MedNote_ImportCPRSLabs] // //////////////////////////////////////////////////////////////////////////////// function MedNote_ImportCPRSLabs(lineArray) { //LogEvent("MedNote_ImportCPRSLabs"); var index = 0; while (index < lineArray.length) { index = ParseOneCPRSLine(lineArray, index); //LogEvent("MedNote_ImportCPRSLabs. Line " + index); } } // MedNote_ImportCPRSLabs //////////////////////////////////////////////////////////////////////////////// // // [ParseOneCPRSLine] // //////////////////////////////////////////////////////////////////////////////// function ParseOneCPRSLine(lineArray, lineNum) { //LogEvent("ParseOneCPRSLine. lineNum=" + lineNum); var index; var index2; var index3; var str = lineArray[lineNum]; //LogEvent("ParseOneCPRSLine. str=" + str); ////////////////// // Urine // Do this FIRST, because other names are prefixes of these names, so we could accidentally // mistake "PROTEIN URINE" for "PROTEIN" index = str.indexOf("SODIUM URINE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineSodium", str, index); return(lineNum + 1); } index = str.indexOf("POTASSIUM URINE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrinePotassium", str, index); return(lineNum + 1); } index = str.indexOf("CHLORIDE URINE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineChloride", str, index); return(lineNum + 1); } index = str.indexOf("Urea Nit Ur Qn"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineUrea", str, index); return(lineNum + 1); } index = str.indexOf("URINE CREATININE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineCreatinine", str, index); return(lineNum + 1); } index = str.indexOf("MICROALBUMIN"); if (index == 0) { // This is mg/L lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineAlbumin", str, index); return(lineNum + 1); } index = str.indexOf("PROTEIN URINE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineProtein", str, index); return(lineNum + 1); } index = str.indexOf("OSMOLALITY URINE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "UrineOsm", str, index); return(lineNum + 1); } ///////////////////////// // BMP index = str.indexOf("SODIUM"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Sodium", str, index); return(lineNum + 1); } index = str.indexOf("POTASSIUM"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Potassium", str, index); return(lineNum + 1); } index = str.indexOf("CHLORIDE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Chloride", str, index); return(lineNum + 1); } index = str.indexOf("CO2"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "HCO3", str, index + 4); return(lineNum + 1); } index = str.indexOf("UREA NITROGEN"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "BUN", str, index); return(lineNum + 1); } index = str.indexOf("CREATININE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Creatinine", str, index); return(lineNum + 1); } index = str.indexOf("GLUCOSE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Glucose", str, index); return(lineNum + 1); } index = str.indexOf("eGFR"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "ReportedGFR", str, index); return(lineNum + 1); } index = str.indexOf("xxxx"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "ReportedAfricanGFR", str, index); return(lineNum + 1); } // We can also get values from a blood gas. //HCO3-(c) 28.1 H mmol/L 22 - 26 [583] //HEMOGLOBIN, TOTAL (B-GAS) 8.8 L G/DL 14 - 18 [583] //SODIUM (B-GAS) 133 L mmol/L 135 - 145 [583] //POTASSIUM (B-GAS) 5.4 mmol/L 3.5 - 5.5 [583] //CHLORIDE (B-GAS) 109 H mmol/L 98 - 107 [583] //GLUCOSE (B-GAS) 158 H mg/dL 65 - 110 [583] //IONIZED CALCIUM 4.13 L mg/dL 4.50 - 5.30 [583] ///////////////////////// // LFT index = str.indexOf("SGPT"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "ALT", str, index); return(lineNum + 1); } index = str.indexOf("SGOT"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "AST", str, index); return(lineNum + 1); } index = str.indexOf("ALKALINE PHOSPHATASE"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "ALP", str, index); return(lineNum + 1); } index = str.indexOf("TOT. BILIRUBIN"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "TBili", str, index); return(lineNum + 1); } index = str.indexOf("PROTEIN,TOTAL"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "TProtein", str, index); return(lineNum + 1); } index = str.indexOf("ALBUMIN"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Albumin", str, index); return(lineNum + 1); } index = str.indexOf("INR"); if (index >= 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "INR", str, index); return(lineNum + 1); } index = str.indexOf("PT"); if (index >= 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "PT", str, index); return(lineNum + 1); } ////////////////// // MBD index = str.indexOf("CALCIUM"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Calcium", str, index); return(lineNum + 1); } index = str.indexOf("PO4"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Phos", str, index); return(lineNum + 1); } index = str.indexOf("VITAMIN D, TOTAL"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "VitD", str, index); return(lineNum + 1); } index = str.indexOf("PTH (INTACT)"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "PTH", str, index); return(lineNum + 1); } ////////////////// // CBC index = str.indexOf("PLT"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "Platelet", str, index); return(lineNum + 1); } index = str.indexOf("WBC "); index2 = str.indexOf("WBC:UA"); index3 = str.indexOf("WBC Esterase"); if ((index2 >= 0) || (index3 >= 0)) { } else if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "WBC", str, index); return(lineNum + 1); } index = str.indexOf("HEMOGLOBIN A1C"); index2 = str.indexOf("HGB UA"); index3 = str.indexOf("HGB"); if (index == 0) { //LogEvent("Try to read A1c. str=" + str); lineNum = SaveValueFromOneString(lineArray, lineNum, "HgbA1c", str, index + 7); return(lineNum + 1); } else if (index2 >= 0) { //LogEvent("Try to read Hgb UA. str=" + str); } else if (index3 >= 0) { //LogEvent("Try to read Hgb. str=" + str); lineNum = SaveValueFromOneString(lineArray, lineNum, "CBCHgb", str, index3); return(lineNum + 1); } ////////////////// // ABG index = str.indexOf("PH (B-GAS)"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "pH", str, index); return(lineNum + 1); } index = str.indexOf("PCO2"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "PaCO2", str, index); return(lineNum + 1); } index = str.indexOf("PO2"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "PaO2", str, index); return(lineNum + 1); } ////////////////// // Vitals index = str.indexOf("Weight Lbs"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "WeightInKg", str, index); // Convert lbs to kg var valueEntry = g_AllLabValuesDeclaration['WeightInKg']; if (valueEntry) { valueEntry.intVal = valueEntry.intVal / 2.20462; } return(lineNum + 1); } index = str.indexOf("Weight Metric"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "WeightInKg", str, index); return(lineNum + 1); } index = str.indexOf("BP Sys"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "SystolicBP", str, index); return(lineNum + 1); } index = str.indexOf("BP Dias"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "DiastolicBP", str, index); return(lineNum + 1); } index = str.indexOf("Pulse"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "HR", str, index); return(lineNum + 1); } // <> Need These // "Age" "HeightInCm" // "PreBUN" "PostBUN" "HDTimeInMin" "PreHDWeightInKg" "PostHDWeightInKg" "FilterSelect" "BloodFlowSelect" "HDFreqSelect" "CystatinC" "IsMale" "IsCaucasian" "OnHTNMeds" "IsDiabetic" "IsSmoker" ////////////////// // Lipids index = str.indexOf("LDL CHOLESTEROL"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "LDL", str, index); return(lineNum + 1); } index = str.indexOf("QUANTITATIVE LDL"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "LDL", str, index); return(lineNum + 1); } index = str.indexOf("HDL CHOLESTEROL"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "HDL", str, index); return(lineNum + 1); } index = str.indexOf("CHOLESTEROL,TOTAL"); if (index == 0) { lineNum = SaveValueFromOneString(lineArray, lineNum, "TChol", str, index); return(lineNum + 1); } // Resume parsing on the next line. //LogEvent("ParseOneCPRSLine. Didnt recognize the line. lineNum=" + lineNum); return(lineNum + 1); } // ParseOneCPRSLine //////////////////////////////////////////////////////////////////////////////// // // [ParseUserInputs] // //////////////////////////////////////////////////////////////////////////////// function ParseUserInputs() { var index; var inputText; for (index = 0; index < g_LabValueArray.length; index++) { var valueEntry = g_LabValueArray[index]; if (valueEntry.userInput == "1") { valueEntry.intVal = -1; valueEntry.strVal = ""; if ((valueEntry.inputType == "text") && (valueEntry.htmlElement)) { inputText = valueEntry.htmlElement.value; if (inputText != "") { var valueNum = parseFloat(inputText); valueEntry.intVal = valueNum; valueEntry.strVal = inputText; } } else if ((valueEntry.inputType == "enum") && (valueEntry.htmlElement)) { valueEntry.strVal = valueEntry.htmlElement.value; valueEntry.intVal = valueEntry.htmlElement.selectedIndex; } else if ((valueEntry.inputType == "bool") && (valueEntry.htmlElement)) { var currentStr = valueEntry.htmlElement.getAttribute('boolVal'); if (!currentStr) { currentStr = "ON"; valueEntry.htmlElement.setAttribute('boolVal', currentStr); } if (currentStr.toUpperCase() == "ON") { valueEntry.intVal = 1; } else { valueEntry.intVal = 0; } } // if ((valueEntry.htmlElement) && (valueEntry.inputType == "bool")) // We parse the inputs immediately before generating the outputs. So, clear any outputs. } else { // if (valueEntry.userInput != "1") { valueEntry.intVal = -1; valueEntry.strVal = ""; if (valueEntry.htmlElement) { Util_RemoveAllChildNodes(valueEntry.htmlElement); } } } } // ParseUserInputs //////////////////////////////////////////////////////////////////////////////// // // [MedNote_SetValueNumber] // //////////////////////////////////////////////////////////////////////////////// function MedNote_SetValueNumber(valueNameStr, intVal) { var outputStr = ""; var textNode; //LogEvent("MedNote_SetValueNumber. valueNameStr= " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if (!valueEntry) { LogEvent("!!!!BUG!!!!!! MedNote_SetValueNumber. NULL valueEntry. valueNameStr= " + valueNameStr); return; } if (valueEntry.userInput == "1") { valueEntry.intVal = intVal; if (valueEntry.htmlElement) { /////////////////////////////// if (valueEntry.inputType == "text") { // If we are initializing, then set the input or output to an empty string. if (intVal == -1) { valueEntry.strVal = ""; // Otherwise, we are settiung it to a valid value. } else { valueEntry.intVal = Math.round(intVal * 10) / 10; valueEntry.strVal = intVal.toString(); } valueEntry.htmlElement.value = valueEntry.strVal; } /////////////////////////////// if (valueEntry.inputType == "bool") { var resultTextStr; if (valueEntry.intVal) { valueEntry.strVal = "ON"; } else { valueEntry.strVal = "OFF"; } valueEntry.htmlElement.setAttribute('boolVal', currentStr); if (valueEntry.boolResultHTMLElement) { if (valueEntry.intVal) { resultTextStr = valueEntry.outputOnStr; if (valueEntry.drawColorsInRedGreen) { valueEntry.boolResultHTMLElement.style="background-color:#00FF00;" } } else { resultTextStr = valueEntry.outputOffStr; if (valueEntry.drawColorsInRedGreen) { valueEntry.boolResultHTMLElement.style="background-color:#FF0000;" } } Util_RemoveAllChildNodes(valueEntry.boolResultHTMLElement); var textNode = document.createTextNode(resultTextStr); valueEntry.boolResultHTMLElement.appendChild(textNode); } // if (valueEntry.boolResultHTMLElement) } /////////////////////////////// if (valueEntry.inputType == "enum") { if (intVal == -1) { valueEntry.htmlElement.selectedIndex = 0; // Otherwise, we are setting it to a valid value. } else { valueEntry.htmlElement.selectedIndex = intVal; } // For enums, the intVal is the index, and the strVal is the selected text. valueEntry.strVal = valueEntry.htmlElement.options[intVal].value; } } // if (valueEntry.htmlElement) } else { // if (valueEntry.userInput != "1") valueEntry.intVal = Math.round(intVal * 10) / 10; // If we are initializing, then set the input or output to an empty string. if (intVal == -1) { valueEntry.strVal = ""; // Otherwise, we are settiung it to a valid value. } else { valueEntry.strVal = valueEntry.strVal + valueEntry.intVal.toString(); outputStr = ""; if (valueEntry.outputPrefixStr) { outputStr = outputStr + valueEntry.outputPrefixStr; } outputStr = outputStr + valueEntry.strVal; if (valueEntry.outputSuffixStr) { outputStr = outputStr + valueEntry.outputSuffixStr; } } if (valueEntry.htmlElement) { Util_RemoveAllChildNodes(valueEntry.htmlElement); textNode = document.createTextNode(outputStr); valueEntry.htmlElement.appendChild(textNode); } } } // MedNote_SetValueNumber //////////////////////////////////////////////////////////////////////////////// // // [MedNote_SetValueNumberWithComment] // //////////////////////////////////////////////////////////////////////////////// function MedNote_SetValueNumberWithComment(valueNameStr, intVal, commentStr) { var outputStr = ""; var textNode; //LogEvent("MedNote_SetValueNumberWithComment. valueNameStr= " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if (!valueEntry) { LogEvent("!!!!BUG!!!!!! MedNote_SetValueNumberWithComment. NULL valueEntry. valueNameStr= " + valueNameStr); return; } if (!commentStr) { commentStr = ""; } if (valueEntry.userInput == "1") { // This should not happen, but do not panic if it does. // We just ignore the comment. MedNote_SetValueNumber(valueNameStr, intVal); } else { // if (valueEntry.userInput != "1") valueEntry.intVal = Math.round(intVal * 10) / 10; // If we are initializing, then set the input or output to an empty string. if (intVal == -1) { valueEntry.strVal = "" + commentStr; // Otherwise, we are settiung it to a valid value. } else { valueEntry.strVal = valueEntry.intVal.toString(); outputStr = ""; if (valueEntry.outputPrefixStr) { outputStr = outputStr + valueEntry.outputPrefixStr; } outputStr = outputStr + valueEntry.strVal; if (valueEntry.outputSuffixStr) { outputStr = outputStr + valueEntry.outputSuffixStr; } outputStr = outputStr + " " + commentStr; } if (valueEntry.htmlElement) { Util_RemoveAllChildNodes(valueEntry.htmlElement); textNode = document.createTextNode(outputStr); valueEntry.htmlElement.appendChild(textNode); } } } // MedNote_SetValueNumberWithComment //////////////////////////////////////////////////////////////////////////////// // // [MedNote_SetValueString] // //////////////////////////////////////////////////////////////////////////////// function MedNote_SetValueString(valueNameStr, strVal) { var outputStr = ""; var textNode; //LogEvent("MedNote_SetValueString. valueNameStr= " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if (!valueEntry) { LogEvent("!!!!BUG!!!!!! MedNote_SetValueString. NULL valueEntry. valueNameStr= " + valueNameStr); return; } if (valueEntry.userInput == "1") { // Really, this function is used for error messages or complex results (with alternate values). LogEvent("!!!!BUG!!!!!! MedNote_SetValueString. User input valueEntry. valueNameStr= " + valueNameStr); // It should never be called here. But just in case, do something halfway reasonable. valueEntry.intVal = -1; if ((valueEntry.htmlElement) && (valueEntry.inputType == "text")) { valueEntry.strVal = strVal; valueEntry.htmlElement.value = strVal; } } else { // if (valueEntry.userInput != "1") valueEntry.intVal = -1; valueEntry.strVal = strVal; if (valueEntry.htmlElement) { Util_RemoveAllChildNodes(valueEntry.htmlElement); textNode = document.createTextNode(strVal); valueEntry.htmlElement.appendChild(textNode); } } } // MedNote_SetValueString //////////////////////////////////////////////////////////////////////////////// // // [GetLabValue] // //////////////////////////////////////////////////////////////////////////////// function GetLabValue(valueNameStr) { //LogEvent("GetLabValue. valueNameStr= " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if (!valueEntry) { return(-1); } return(valueEntry.intVal); } // GetLabValue //////////////////////////////////////////////////////////////////////////////// // // [GetLabValueStringForPlan] // // This returns a string that can be used in the text of a plan. If the lab value // is not defined, then it returns some placeholder (like 'x') for a human // to edit later. //////////////////////////////////////////////////////////////////////////////// function GetLabValueStringForPlan(valueNameStr) { //LogEvent("GetLabValue. valueNameStr= " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if (!valueEntry) { return("x"); } if (valueEntry.intVal < 0) { return("x"); } else { return(valueEntry.strVal); } } // GetLabValueStringForPlan //////////////////////////////////////////////////////////////////////////////// // // [NBQuant_ToggleBooleanButton] // //////////////////////////////////////////////////////////////////////////////// function NBQuant_ToggleBooleanButton(valueNameStr) { var resultTextStr = ""; //LogEvent("NBQuant_ToggleBooleanButton, valueNameStr = " + valueNameStr); var valueEntry = g_AllLabValuesDeclaration[valueNameStr]; if (!valueEntry) { LogEvent("!!!!BUG!!!!!! NBQuant_ToggleBooleanButton. NULL valueEntry. valueNameStr= " + valueNameStr); return(1); } if ((valueEntry.userInput != "1") || (valueEntry.inputType != "bool") || (!valueEntry.htmlElement)) { LogEvent("!!!!BUG!!!!!! NBQuant_ToggleBooleanButton. Invalid valueEntry. valueNameStr= " + valueNameStr); return(0); } // Get the current value. var currentStr = valueEntry.htmlElement.getAttribute('boolVal'); if (!currentStr) { currentStr = "ON"; } // Toggle the current value if (currentStr.toUpperCase() == "ON") { currentStr = "OFF"; valueEntry.intVal = 0; } else { currentStr = "ON"; valueEntry.intVal = 1; } valueEntry.htmlElement.setAttribute('boolVal', currentStr); if (valueEntry.boolResultHTMLElement) { if (valueEntry.intVal) { resultTextStr = valueEntry.outputOnStr; if (valueEntry.drawColorsInRedGreen) { valueEntry.boolResultHTMLElement.style="background-color:#00FF00;" } } else { resultTextStr = valueEntry.outputOffStr; if (valueEntry.drawColorsInRedGreen) { valueEntry.boolResultHTMLElement.style="background-color:#FF0000;" } } Util_RemoveAllChildNodes(valueEntry.boolResultHTMLElement); var textNode = document.createTextNode(resultTextStr); valueEntry.boolResultHTMLElement.appendChild(textNode); } // if (valueEntry.boolResultHTMLElement) return(valueEntry.intVal); } // NBQuant_ToggleBooleanButton