public void SetRecordStatus(EnrollmentInformation info) { /// <summary> /// If record follows age requriement and effective date range, then declare status as accept, else declare as rejected /// </summary> /// <param name="dob"></param> /// <returns></returns> string acceptedStatus = ConfigurationManager.AppSettings["RecordAccepted"].ToString(); string rejectedStatus = ConfigurationManager.AppSettings["RecordRejected"].ToString(); string ageMinimum = ConfigurationManager.AppSettings["AgeRequirement"].ToString(); double ageRequirement = double.Parse(ageMinimum); // Could use app.cong variable or constant variable //const string ACCEPTED_STATUS = "Accepted"; //const string REJECTED_STATUS = "Rejected"; if (info.Age >= ageRequirement && IsEffectiveDateInRange(info.EffectiveDate)) { info.Status = acceptedStatus; } else { info.Status = rejectedStatus; } }
public List <EnrollmentInformation> ProcessEnrollmentData(string sourceDirectory) { List <EnrollmentInformation> listOfEnrollments = new List <EnrollmentInformation>(); if (Directory.Exists(sourceDirectory)) { var directory = new DirectoryInfo(sourceDirectory); var files = directory.GetFiles().ToList(); // Loop through files in the configured directory path. if (files.Count > 0) { foreach (var file in files) { // Read all records in the file. string[] lines = File.ReadAllLines(file.FullName); if (lines != null) { foreach (string line in lines) { // Parse out enrollment record values. EnrollmentInformation enrollmentInformation = ParseEnrollmentRecord(line); // Will throw an exception if the record doesn't get parsed. if (enrollmentInformation == null) { throw new NullReferenceException(); } // If record is parsed, we will add to our list of enrollments. listOfEnrollments.Add(enrollmentInformation); } } } } } return(listOfEnrollments); }
EnrollmentInformation ParseEnrollmentRecord(string lineInCSV) { var values = lineInCSV.Split(','); // If the data doesn't meet requirements or standards, return null if (!_dataValidator.IsRecordValidToProcess(values)) { return(null); } // Associate the property with the value in the csv by location. EnrollmentInformation enrollmentInformation = new EnrollmentInformation(); enrollmentInformation.FirstName = values[0]; enrollmentInformation.LastName = values[1]; enrollmentInformation.DateOfBirth = _dataConverter.ConvertStringToDate(values[2], DATE_FORMAT).Value; enrollmentInformation.PlanType = values[3]; enrollmentInformation.EffectiveDate = _dataConverter.ConvertStringToDate(values[4], DATE_FORMAT).Value; // Associate Age property by calculating the age, set the record status via the information we have gathered enrollmentInformation.Age = _dataValidator.CalculateAge(enrollmentInformation.DateOfBirth); _dataValidator.SetRecordStatus(enrollmentInformation); return(enrollmentInformation); }
public static void PrintEnrollmentRecordsToConsole(EnrollmentInformation enrollmentInfo) { // print out enrollment records. Console.WriteLine($"{enrollmentInfo.Status} | {enrollmentInfo.FirstName} | {enrollmentInfo.LastName} | " + $"{enrollmentInfo.DateOfBirth.ToShortDateString()} | {enrollmentInfo.PlanType} | {enrollmentInfo.EffectiveDate} | \n"); }