private void readIDCriteria(string filePath)
 {
     using (var sr = new StreamReader(filePath, Encoding.Default))
     {
         IDCriteria = new List<IDData>();
         string[] titles = sr.ReadLine().Split('\t');
         int index_ID = Array.IndexOf(titles, "ID");
         int index_Birthday = Array.IndexOf(titles, "Birthday");
         while (!sr.EndOfStream)
         {
             string[] splitline = sr.ReadLine().Split('\t');
             IDData toAdd = new IDData()
             {
                 ID = splitline[index_ID],
                 Birthday = splitline[index_Birthday],
             };
             IDCriteria.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);
                            }
                        }
                    }

                }
            }
        }
Exemplo n.º 3
0
            public List<ActionData> ActionCriteriaList;  //將上述檔案內容提取入ActionList

            //實際執行判斷的方法
            public bool DoCheck(DataRow InputDataRow)
            {
                if (key == "IDLIST")
                {
                    if (indexID == -1 || indexBirthday == -1) return true;
                    var thisID = new IDData { ID = InputDataRow.stringData[indexID], Birthday = InputDataRow.stringData[indexBirthday] };
                    if (IDCriteriaList.BinarySearch(thisID) >= 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else if (key == "ACTIONLIST")
                {
                    if (indexHOSP_ID == -1 || indexAPPL_DATE == -1 || indexAPPL_TYPE == -1
                        || indexCASE_TYPE == -1 || indexSEQ_NO == -1 || indexFEE_YM == -1)
                        return true;
                    var thisAction = new ActionData
                    {
                        FEE_YM = InputDataRow.stringData[indexFEE_YM],
                        APPL_DATE = InputDataRow.stringData[indexAPPL_DATE],
                        APPL_TYPE = InputDataRow.stringData[indexAPPL_TYPE],
                        CASE_TYPE = InputDataRow.stringData[indexCASE_TYPE],
                        HOSP_ID = InputDataRow.stringData[indexHOSP_ID],
                        SEQ_NO = InputDataRow.numberData[indexSEQ_NO].ToString()
                    };
                    if (ActionCriteriaList.BinarySearch(thisAction) >= 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else if (key == "AGE")
                {
                    if (indexBirthday == -1 || indexEventday == -1) return true;
                    DateTime birthday = InputDataRow.stringData[indexBirthday].StringToDate();
                    DateTime eventday = InputDataRow.stringData[indexEventday].StringToDate();
                    double age = eventday.Subtract(birthday).TotalDays / 365;
                    if ((age < CriteriaNumUpper || CriteriaNumUpper == 0) && (age >= CriteriaNumLower || CriteriaNumLower == 0))
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else if (indexStrDatalist.Count > 0)
                {
                    bool include = false, exclude = false;
                    foreach (var index in indexStrDatalist)
                    {
                        foreach (string criteria in StringIncludeList)
                        {
                            if (InputDataRow.stringData[index].Substring(0, criteria.Length) == criteria)
                            {
                                include = true;
                            }
                        }
                        if (StringExcludeList != null && StringExcludeList.Count > 0)
                        {
                            foreach (string criteria in StringExcludeList)
                            {
                                if (InputDataRow.stringData[index].Substring(0, criteria.Length) == criteria)
                                {
                                    exclude = true;
                                }
                            }
                        }
                        if (include && !exclude)
                            return true;
                    }
                    return false;
                }
                else if (indexNumData >= 0)
                {
                    if ((InputDataRow.numberData[indexNumData] < CriteriaNumUpper || CriteriaNumUpper == 0) &&
                        (InputDataRow.numberData[indexNumData] >= CriteriaNumLower || CriteriaNumLower == 0))
                    {
                        return true;
                    }
                }
                else  //此條件沒有找到index => 跳過
                {
                    return true;
                }
                return false;
            }