public IEnumerable<ICD9Entry> GetEntries() { var commaDelimitedExpression = ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"; var modelProperties = typeof(ICD9Entry).GetProperties(BindingFlags.Public | BindingFlags.Instance); var lines = File.ReadAllLines("Data\\ICD9.csv"); var header = lines.First().Split(','); return lines.Skip(1).Select(x => Regex.Split(x, commaDelimitedExpression)).Select(x => { var model = new ICD9Entry(); foreach (var field in header) { var property = modelProperties.First(p => p.Name == field); var propertyType = property.PropertyType; var stringValue = x[Array.IndexOf(header, property.Name)]; var value = (propertyType.IsEnum) ? Enum.Parse(propertyType, stringValue) : Convert.ChangeType(stringValue, propertyType); property.SetValue(model, value); } return model; }); }
private static void DecoratePatientDiagnosisFromICD9Entry(PatientDiagnosis diagnosis, ICD9Entry entry) { diagnosis.ICD9 = entry.ICD9Code; diagnosis.DiagnosisDescription = entry.DisplayName; }