Пример #1
0
        private static void RunTestcase(Testcase testcase)
        {
            ValueTable testData      = new ValueTable(testcase.KDate);
            ValueTable treatmentData = new ValueTable(testcase.KDate);

            double temp;
            double temp2;

            if (testcase.Dialysis.ToLower().StartsWith("y"))
            {
                testData.SetValue("GFR", -1, "", testcase.KDate);
            }
            else
            {
                if (testcase.Creatinine1 != "")
                {
                    double GFR1 = GetGFR(testcase.Creatinine1, testcase.DOB, testcase.KDate, testcase.Gender, testcase.Ethnicity);
                    if (GFR1 >= 0)
                    {
                        testData.SetValue("gfr", GFR1, "ml/min", testcase.SCr1date);
                    }
                }
                if (testcase.Creatinine2 != "")
                {
                    double GFR2 = GetGFR(testcase.Creatinine2, testcase.DOB, testcase.KDate, testcase.Gender, testcase.Ethnicity);
                    if (GFR2 >= 0)
                    {
                        testData.SetValue("gfr", GFR2, "ml/min", testcase.SCr2date);
                    }
                }
            }
            if (double.TryParse(testcase.UrineProduction, out temp))
            {
                testData.SetValue("urine production", temp, "ml/kg/hr", testcase.UrineDate);
            }
            if (double.TryParse(testcase.Potassium, out temp))
            {
                testData.SetValue("potassium", temp, "mEq/l", testcase.KDate);
            }
            if (double.TryParse(testcase.Magnesium, out temp))
            {
                testData.SetValue("magnesium", temp, "mg/dl", testcase.MgDate);
            }
            if (double.TryParse(testcase.Phosphorus, out temp))
            {
                testData.SetValue("phosphorus", temp, "mg/dl", testcase.PhosDate);
            }
            if (testcase.CaType == "ionized" && double.TryParse(testcase.Calcium, out temp))
            {
                testData.SetValue("calcium, ionized", temp, "mg/dl", testcase.CaDate);
            }
            if (testcase.CaType == "total" && double.TryParse(testcase.Calcium, out temp) && double.TryParse(testcase.Albumin, out temp2))
            {
                if (temp2 < 4.0)
                {
                    temp += 0.8 * (4.0 - temp2);
                }
                testData.SetValue("calcium, ionized", temp, "mg/dl", testcase.CaDate);
            }
            testData.SetValue("diarrhea", testcase.Diarrhea.ToLower().StartsWith("y") ? "Yes" : "No", "", testcase.KDate);

            testData.SetValue("EnteralRoute", true, "", testcase.KDate);
            testData.SetValue("CentralRoute", true, "", testcase.KDate);
            testData.SetValue("PeripheralRoute", true, "", testcase.KDate);

            if (double.TryParse(testcase.Supplement48hrs, out temp))
            {
                treatmentData.SetValue("kcl", temp, "mEq", testcase.KDate.AddDays(-1));
            }


            Intervention   hypokalemia = new Module(testcase.PatientID, testData, treatmentData);
            DecisionResult results     = hypokalemia.IdentifyTreatment();

            testcase.Treatments = results.treatments.OrderBy(t => t.index)
                                  .Select(t => t.index + ": " + t.type + ": " + t.med
                                          + " " + t.quantity + " " + t.units + " " + t.route).ToList();
            testcase.Actions = results.actions.Select(a => a.text.Trim('"')).ToList();;
            testcase.Reasons = results.reasons.Select(r => r.level + ": " + r.text.Trim('"')).ToList();
        }
Пример #2
0
        private static void RunTestcase(Testcase testcase)
        {
            ValueTable testData      = new ValueTable(testcase.K1Date);
            ValueTable treatmentData = new ValueTable(testcase.K1Date);

            double temp;
            double temp2;

            //(data-value(name dialysis) (patient 123456) (value NO))
            if (testcase.Dialysis.ToLower().StartsWith("y"))
            {
                testData.SetValue("dialysis", "YES", "", testcase.K1Date);
            }
            else
            {
                testData.SetValue("dialysis", "NO", "", testcase.K1Date);
            }

            //(data-value(name GFR) (patient 123456) (value 45))
            if (testcase.Creatinine1 != "")
            {
                double GFR = GetGFR(testcase.Creatinine1, testcase.DOB, testcase.K1Date, testcase.Gender, testcase.Ethnicity);
                if (GFR >= 0)
                {
                    testData.SetValue("GFR", GFR, "ml/min", testcase.SCr1date);
                }
            }

            //GFR-trend is calculated in the module. (data-value(name GFR-trend) (patient 123456) (value Stable))
            if (testcase.Creatinine2 != "")
            {
                double GFR = GetGFR(testcase.Creatinine2, testcase.DOB, testcase.K1Date, testcase.Gender, testcase.Ethnicity);
                if (GFR >= 0)
                {
                    testData.SetValue("GFR", GFR, "ml/min", testcase.SCr2date);
                }
            }

            if (testcase.Creatinine3 != "")
            {
                double GFR = GetGFR(testcase.Creatinine3, testcase.DOB, testcase.K1Date, testcase.Gender, testcase.Ethnicity);
                if (GFR >= 0)
                {
                    testData.SetValue("GFR", GFR, "ml/min", testcase.SCr3date);
                }
            }

            if (double.TryParse(testcase.UrineProduction3hours, out temp))
            {
                testData.SetValue("urine production", temp, "ml/kg/hr", testcase.K1Date);
            }
            if (double.TryParse(testcase.Potassium1, out temp))
            {
                testData.SetValue("potassium", temp, "mEq/l", testcase.K1Date);
            }
            if (double.TryParse(testcase.Potassium2, out temp))
            {
                testData.SetValue("potassium", temp, "mEq/l", testcase.K2Date);
            }
            if (double.TryParse(testcase.Potassium3, out temp))
            {
                testData.SetValue("potassium", temp, "mEq/l", testcase.K3Date);
            }
            if (double.TryParse(testcase.Magnesium, out temp))
            {
                testData.SetValue("magnesium", temp, "mg/dl", testcase.MgDate);
            }
            if (double.TryParse(testcase.Phosphorus, out temp))
            {
                testData.SetValue("phosphorus", temp, "mg/dl", testcase.PhosDate);
            }
            if (testcase.CaType == "ionized" && double.TryParse(testcase.Calcium, out temp))
            {
                testData.SetValue("calcium, ionized", temp, "mg/dl", testcase.CaDate);
            }
            if (testcase.CaType == "total" && double.TryParse(testcase.Calcium, out temp) && double.TryParse(testcase.Albumin, out temp2))
            {
                if (temp2 < 4.0)
                {
                    temp += 0.8 * (4.0 - temp2);
                }
                testData.SetValue("calcium, ionized", temp, "mg/dl", testcase.CaDate);
            }
            testData.SetValue("past-loop-diuretic", testcase.LoopDiureticsDsc.ToLower().StartsWith("y") ? "Yes" : "No", "", testcase.K1Date);
            testData.SetValue("past-diarrhea", testcase.Diarrhea.ToLower().StartsWith("y") ? "Yes" : "No", "", testcase.K1Date);

            if (double.TryParse(testcase.Supplement24hrs, out temp))
            {
                treatmentData.SetValue("supplement24hrs", temp, "mEq", testcase.K1Date);
            }


            Intervention   hypokalemia = new Module(testcase.PatientID, testData, treatmentData);
            DecisionResult results     = hypokalemia.IdentifyTreatment();

            //testcase.Treatments = results.treatments.OrderBy(t => t.index)
            //    .Select(t => t.index + ": " + t.type + ": " + t.med
            //        + " " + t.quantity + " " + t.units + " " + t.route).ToList();
            if (results.treatments.Count == 1 && results.treatments[0].type.Contains("KCl")) // KCl only
            {
                testcase.Treatments = results.treatments.Select(t => t.type.Trim('"') + (t.route == "nil" ? "" : " " + t.route)).ToList();
            }
            else // Kphos and KCl, ignore routes
            {
                testcase.Treatments = results.treatments.Select(t => t.type.Trim('"')).ToList();
            }
            testcase.Actions = results.actions.Select(a => a.text.Trim('"')).ToList();
            testcase.Reasons = results.reasons.Select(r => r.text.Trim('"')).ToList();
        }
Пример #3
0
        private void RunButton_Click(object sender, EventArgs e)
        {
            CultureInfo culture = new CultureInfo("en-US");

            List <AutoICU.AI.Treatment> treatments = new List <AutoICU.AI.Treatment>();
            List <AutoICU.AI.Action>    actions    = new List <AutoICU.AI.Action>();
            List <AutoICU.AI.Reason>    reasons    = new List <AutoICU.AI.Reason>();

            List <double> test_x_values      = new List <double>();
            List <double> test_y_values      = new List <double>();
            List <double> treatment_x_values = new List <double>();
            List <double> treatment_y_values = new List <double>();
            List <double> weights            = new List <double>();
            DateTime      now = DateTime.Now;

            AutoICU.AI.ValueTable testData = new ValueTable();
            bool     latestSet             = false;
            DateTime latest = DateTime.UtcNow;

            for (int dt_index = 1; dt_index < valuesDataGridView.ColumnCount; dt_index++)
            {
                string date = valuesDataGridView.Rows[0].Cells[dt_index].Value.ToString();
                string time = valuesDataGridView.Rows[1].Cells[dt_index].Value.ToString();

                if (date != "")
                {
                    if (time == "")
                    {
                        time = "12:00";
                    }
                    else
                    {
                        if (!time.Contains(":") && time.Length > 2)
                        {
                            time = time.Substring(0, time.Length - 2) + ":" + time.Substring(time.Length - 2);
                        }
                    }
                    try
                    {
                        DateTime timestamp = Convert.ToDateTime(date + " " + time, culture);
                        if (!latestSet)
                        {
                            latest    = timestamp;
                            latestSet = true;
                        }
                        for (int test_index = 2; test_index < valuesDataGridView.RowCount; test_index++)
                        {
                            string testName  = valuesDataGridView.Rows[test_index].Cells[0].Value.ToString();
                            string testValue = valuesDataGridView.Rows[test_index].Cells[dt_index].Value as string;
                            if (testValue != "")
                            {
                                testData.SetValue(testName, testValue, "", timestamp);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        AutoICU.AI.Action action = new AutoICU.AI.Action();
                        action.text = "Unusable date and/or time: " + date + " " + time;
                        actions.Add(action);
                    }
                }
            }

            if (enteralRouteCheckBox.Checked)
            {
                testData.SetValue("EnteralRoute", true, "", latest);
            }
            if (centralIvRouteCheckBox.Checked)
            {
                testData.SetValue("CentralRoute", true, "", latest);
            }
            if (peripheralIvRouteCheckBox.Checked)
            {
                testData.SetValue("PeripheralRoute", true, "", latest);
            }

            AutoICU.AI.ValueTable treatmentData = new ValueTable();
            for (int dt_index = 1; dt_index < medsDataGridView.ColumnCount; dt_index++)
            {
                string date = medsDataGridView.Rows[0].Cells[dt_index].Value.ToString();
                string time = medsDataGridView.Rows[1].Cells[dt_index].Value.ToString();

                if (date != "")
                {
                    if (time == "")
                    {
                        time = "12:00";
                    }
                    else
                    {
                        if (!time.Contains(":") && time.Length > 2)
                        {
                            time = time.Substring(0, time.Length - 2) + ":" + time.Substring(time.Length - 2);
                        }
                    }
                    try
                    {
                        DateTime timestamp = Convert.ToDateTime(date + " " + time, culture);
                        for (int test_index = 2; test_index < medsDataGridView.RowCount; test_index++)
                        {
                            string treatmentName  = medsDataGridView.Rows[test_index].Cells[0].Value.ToString();
                            string treatmentValue = medsDataGridView.Rows[test_index].Cells[dt_index].Value as string;
                            if (treatmentValue != "")
                            {
                                treatmentData.SetValue(treatmentName, treatmentValue, "", timestamp);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        AutoICU.AI.Action action = new AutoICU.AI.Action();
                        action.text = "Unusable date and/or time: " + date + " " + time;
                        actions.Add(action);
                    }
                }
            }

            AutoICU.AI.Intervention hypokalemia = new AutoICU.AI.HypokalemiaV1.Module("p123456", testData, treatmentData);
            DecisionResult          results     = hypokalemia.IdentifyTreatment();

            treatementsDataGridView.DataSource = results.treatments;
            treatementsDataGridView.ClearSelection();

            actionsDataGridView.DataSource = results.actions;
            actionsDataGridView.ClearSelection();

            reasonsDataGridView.DataSource = results.reasons;
            reasonsDataGridView.ClearSelection();

            // Tests the loading of AutoICU.AI intervention modules and running them.
            //Physician.LoadAssemblies();
            //Physician.IdentifyTreatments("p123456", testData, treatmentData);
        }