private void readPBD(string filePath) { using (var sr = new StreamReader(filePath, Encoding.Default)) { patientBasedDataWithEvents = new List<PatientBasedDataWithEvent>(); string[] titles = sr.ReadLine().Split('\t'); initializeEventIndex(titles); int index_ID = Array.IndexOf(titles, "ID"); int index_Birthday = Array.IndexOf(titles, "Birthday"); int index_Gender = Array.IndexOf(titles, "Gender"); while (!sr.EndOfStream) { string[] splitline = sr.ReadLine().Split('\t'); PatientBasedDataWithEvent toAdd = new PatientBasedDataWithEvent() { ID = splitline[index_ID], Birthday = splitline[index_Birthday], gender = splitline[index_Gender] == "F" ? Gender.Female : Gender.Male }; foreach (var i in EventIndex) { double age = -1; if (splitline[i] != "") { age = Convert.ToDouble(splitline[i]); } toAdd.eventAges.Add(age); } patientBasedDataWithEvents.Add(toAdd); } } }
private void readSID(string filePath) { using (var sr = new StreamReader(filePath, Encoding.Default)) { string[] titles = sr.ReadLine().Split('\t'); int index_ID = Array.IndexOf(titles, "ID"); int index_Birthday = Array.IndexOf(titles, "Birthday"); int index_Gender = Array.IndexOf(titles, "Gender"); int index_firstInDate = Array.IndexOf(titles, "firstInDate"); int index_lastOutDate = Array.IndexOf(titles, "lastOutDate"); while (!sr.EndOfStream) { string[] splitline = sr.ReadLine().Split('\t'); string ID = splitline[index_ID]; string Birthday = splitline[index_Birthday]; var IDtoCompare = new IDData() { ID = ID, Birthday = Birthday }; if (IDCriteraiEnable && IDCriteria.BinarySearch(IDtoCompare) < 0) //ID criteria { continue; } Gender gender = splitline[index_Gender] == "F" ? Gender.Female : Gender.Male; string firstInDate = splitline[index_firstInDate]; string lastOutDate = splitline[index_lastOutDate]; double firstInAge = firstInDate.StringToDate().Subtract(Birthday.StringToDate()).TotalDays / 365.25; if (firstInAge < 0) { firstInAge = 0; } if (firstInAge > 99) { firstInAge = 99; } double lastOutAge = lastOutDate.StringToDate().Subtract(Birthday.StringToDate()).TotalDays / 365.25; if (lastOutAge < 0 || lastOutDate.StringToDate() > dataEndDate) { lastOutAge = dataEndDate.Subtract(Birthday.StringToDate()).TotalDays / 365.25; } var toCompare = new PatientBasedDataWithEvent() { ID = ID, Birthday = Birthday }; int index = patientBasedDataWithEvents.BinarySearch(toCompare); if (index < 0) { for (int i = 0; i < ASITables.Count(); i++) { ASITables[i].addPatientYear(gender, firstInAge, lastOutAge); } } else if (index >= 0) { lastOutAge = dataEndDate.Subtract(Birthday.StringToDate()).TotalDays / 365.25; for (int i = 0; i < ASITables.Count(); i++) { double currentEventAge = patientBasedDataWithEvents[index].eventAges[i]; if (currentEventAge >= 0) { ASITables[i].addPatientYear(gender, firstInAge, currentEventAge); ASITables[i].addEvent(gender, currentEventAge); } else { ASITables[i].addPatientYear(gender, firstInAge, lastOutAge); } } } } } }