static void Main(string[] args) { // Read the csv file for inputs using (StreamWriter outputFile = File.CreateText("testcaseResults.csv")) using (StreamReader reader = new StreamReader("testcases.csv")) using (CsvReader csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { Testcase.WriteHeaders(outputFile); csv.Configuration.BadDataFound = null; csv.Configuration.HasHeaderRecord = false; // Can't use headers since CsvHelper fails on headers with spaces and/or slash (e.g. "Scr 1 mg/dl") csv.Configuration.RegisterClassMap <TestcaseMap>(); csv.Read(); while (csv.Read()) // Foreach row { string value; List <string> values = new List <string>(); for (int i = 0; csv.TryGetField <string>(i, out value); i++) { values.Add(value); } //Testcase testcase = csv.GetRecord<Testcase>(); Testcase testcase = new Testcase(values); // Run Hypokalemia Module // Add Treatments, Actions and Reasons to the testcase RunTestcase(testcase); // Write testcase to a new csv file. testcase.WriteHypokalemiaV2(outputFile); } } }
public Testcase(Testcase other) { PatientID = other.PatientID; Gender = other.Gender; DOB = other.DOB; Ethnicity = other.Ethnicity; Creatinine1 = other.Creatinine1; SCr1date = other.SCr1date; Creatinine2 = other.Creatinine2; SCr2date = other.SCr2date; CCR = other.CCR; CCRdate = other.CCRdate; Dialysis = other.Dialysis; UrineProduction = other.UrineProduction; UrineDate = other.UrineDate; Weight = other.Weight; WtDate = other.WtDate; Potassium = other.Potassium; KDate = other.KDate; Phosphorus = other.Phosphorus; PhosDate = other.PhosDate; Calcium = other.Calcium; CaDate = other.CaDate; CaType = other.CaType; Magnesium = other.Magnesium; MgDate = other.MgDate; Diarrhea = other.Diarrhea; Albumin = other.Albumin; AlbDate = other.AlbDate; Supplement24hrs = other.Supplement24hrs; Supplement48hrs = other.Supplement48hrs; Supplements = other.Supplements; }
public Testcase(Testcase other) { admissionID = other.admissionID; newPotassiumValue = other.newPotassiumValue; PatientID = other.PatientID; Gender = other.Gender; DOB = other.DOB; Ethnicity = other.Ethnicity; Creatinine1 = other.Creatinine1; SCr1date = other.SCr1date; Creatinine2 = other.Creatinine2; SCr2date = other.SCr2date; Creatinine3 = other.Creatinine3; SCr3date = other.SCr3date; CCR1 = other.CCR1; CCR1date = other.CCR1date; CCR2 = other.CCR2; CCR2date = other.CCR2date; CCR3 = other.CCR3; CCR3date = other.CCR3date; Dialysis = other.Dialysis; UrineProduction3hours = other.UrineProduction3hours; UrineProduction6hours = other.UrineProduction6hours; UrineProduction24hours = other.UrineProduction24hours; Weight = other.Weight; WtDate = other.WtDate; LoopDiureticsDsc = other.LoopDiureticsDsc; Potassium1 = other.Potassium1; K1Date = other.K1Date; Potassium2 = other.Potassium2; K2Date = other.K2Date; Potassium3 = other.Potassium3; K3Date = other.K3Date; Phosphorus = other.Phosphorus; PhosDate = other.PhosDate; Calcium = other.Calcium; CaDate = other.CaDate; CaType = other.CaType; Magnesium = other.Magnesium; MgDate = other.MgDate; Diarrhea = other.Diarrhea; Albumin = other.Albumin; AlbDate = other.AlbDate; Supplement24hrs = other.Supplement24hrs; Supplement48hrs = other.Supplement48hrs; Supplements = other.Supplements; }
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(); }
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(); }