// -- 將all-patient 加入 Secondary diagnosis public static void Load_SecondaryCD_to_All_Patient( List<SecondDiagnosisGroup> list_second_Diagnosis_Group, List<PatientBasedData_ID> List_PatientBasedData, string str_FilePath ) { using (var sr = new StreamReader(str_FilePath)) { // -- 取得欄位index List<string> title = new List<string>(sr.ReadLine().Split('\t')); int int_ID_index = title.FindIndex(x => x == "ID"); int int_Birthday_index = title.FindIndex(x => x.IndexOf("ID_BIRTHDAY") >= 0); int int_InDate_index = title.FindIndex(x => x.IndexOf("FUNC_DATE") >= 0); int int_Gender_index = title.FindIndex(x => x.IndexOf("ID_SEX") >= 0); int int_ICD_index = title.FindIndex(x => x.IndexOf("ACODE_ICD9_1") >= 0); // -- sr之迴圈 var int_error_count = 0; while (sr.Peek() >= 0) { // 建立該行資料 string[] str_currentline_split = sr.ReadLine().Split('\t'); string str_currentID = str_currentline_split[int_ID_index]; string str_currentBirthday = str_currentline_split[int_Birthday_index]; string str_currentInDate = str_currentline_split[int_InDate_index]; if (Convert.ToInt32(str_currentInDate.Substring(0, 4)) < 2000) continue; //***年份限制 string str_currentGender = str_currentline_split[int_Gender_index]; string[] str_currentICDs = new string[] { str_currentline_split[int_ICD_index], str_currentline_split[int_ICD_index + 1], str_currentline_split[int_ICD_index + 2] }; var newPT = new PatientBasedData_ID(str_currentID, str_currentBirthday); int int_BinarySearchResult = List_PatientBasedData .BinarySearch(newPT); if (int_BinarySearchResult < 0) { Console.Write("\rCan not find ID in All patient! :{0}", ++int_error_count); } else { //各組次要診斷的迴圈 for (int i = 0; i < list_second_Diagnosis_Group.Count; i++) { // 核對該組ICD 符合的話更新病人的第一次診斷時間 if (int_BinarySearchResult >= 0 && check_ICD(list_second_Diagnosis_Group[i].list_ICD9, str_currentICDs)) { List_PatientBasedData[int_BinarySearchResult] .secondary_Diagnosis[i].str_Event_Time = str_currentInDate; } } } } Console.Write('\n'); } }
// -- 載入all patient總表 public static void Load_All_Patient(List<SecondDiagnosisGroup> list_second_Diagnosis_Group, List<PatientBasedData_ID> List_PatientBasedData, string str_path) { using (var sr = new StreamReader(str_path)) { // -- 取得欄位index List<string> title = new List<string>(sr.ReadLine().Split('\t')); int int_ID_index = title.FindIndex(x => x == "ID"); int int_Birthday_index = title.FindIndex(x => x.IndexOf("Birthday") >= 0); int int_Gender_index = title.FindIndex(x => x.IndexOf("Sex") >= 0); int int_First_Start_Date_index = title.FindIndex(x => x.IndexOf("First Start Date") >= 0); int int_Last_Start_Date_index = title.FindIndex(x => x.IndexOf("Last Start Date") >= 0); int int_Last_End_Date_index = title.FindIndex(x => x.IndexOf("Last End Date") >= 0); //載入資料 while (sr.Peek() >= 0) { var currentlinesplit = sr.ReadLine().Split('\t'); var newPatientBasedData = new PatientBasedData_ID(currentlinesplit[int_ID_index], currentlinesplit[int_Birthday_index], list_second_Diagnosis_Group); newPatientBasedData.str_Gender = currentlinesplit[int_Gender_index]; newPatientBasedData.str_InsuranceFirstStartDate = currentlinesplit[int_First_Start_Date_index]; newPatientBasedData.str_InsuranceLastStartDate = currentlinesplit[int_Last_Start_Date_index]; newPatientBasedData.str_InsuranceEndDate = currentlinesplit[int_Last_End_Date_index]; var index = List_PatientBasedData.BinarySearch(newPatientBasedData); if (index < 0) { List_PatientBasedData.Insert(-index - 1, newPatientBasedData); } if (List_PatientBasedData.Count() % 10000 == 0) Console.Write("\r - patients: {0} loaded", List_PatientBasedData.Count()); } Console.WriteLine("\r - patients: {0} loaded", List_PatientBasedData.Count()); } }