private static void SplitEncounterFile(string fileName) { var validator = new EncounterFileValidator(); validator.Validate(fileName, ErrorMode.SaveAndContinue); Console.WriteLine("Skipped {0} of {1} rows due to validation errors.", validator.NumSkipped, validator.TotalRows); var rows = validator.Rows; var query = (from r in rows select new { r.Facility }).Distinct(); if (query.Count() > 1) { var engine = new FileHelperEngine(typeof(PatientEncounter)); foreach (var facility in query) { var matchedRows = rows.Where(x => x.Facility == facility.Facility).ToArray(); //NOTE: We have the potential to have collisions if the only difference in facility names are invalid characters var outputFileName = string.Format(@"{3}\{0}_{1}{2}", Path.GetFileNameWithoutExtension(fileName), CleanFacilityName(facility.Facility), Path.GetExtension(fileName), Path.GetDirectoryName(Path.GetFullPath(fileName))); bool writeFile = true; if (File.Exists(outputFileName)) { writeFile = false; Console.WriteLine("File {0} already exists. Overwrite(Y/N)?", outputFileName); var response = Console.ReadKey(); writeFile = (response.ToString().ToUpper() == "Y"); } else { Console.WriteLine(outputFileName); } if (writeFile) { engine.HeaderText = PatientEncounter.FileHeader; engine.WriteFile(outputFileName, matchedRows); } } } else { Console.WriteLine("File only contains 1 facility"); } }
/// <summary> /// Reads the EncounterNumber and Cost from the file. /// If a match can be found in the database, update it. /// </summary> /// <param name="fileName"></param> private static void UpdateCost(string fileName) { var validator = new EncounterFileValidator(); validator.Validate(fileName, ErrorMode.SaveAndContinue); Console.WriteLine("Skipped {0} of {1} rows due to validation errors.", validator.NumSkipped, validator.TotalRows); var rows = validator.Rows; StringBuilder sb = new StringBuilder(); foreach (var row in rows.Where(x => x.Cost > 0)) { sb.AppendFormat("UPDATE HIPAA.Encounter SET Cost = {1} WHERE EncounterNumber = '{0}'", row.EncounterNumber, row.Cost); sb.AppendLine(); } File.AppendAllText(fileName + ".SQL", sb.ToString()); Console.WriteLine("Finished processing {0}", fileName); }
public void ShowPatientEncounterFileContents(string fileName) { this.Show(); tslFileName.Text = string.Format("Viewing: {0}", fileName); this.Cursor = Cursors.WaitCursor; this.Update(); gvFileViewer.BeginUpdate(); try { EncounterFileValidator validator = new EncounterFileValidator(); validator.Validate(fileName); DisplayErrors(validator); gvFileViewer.Columns.Clear(); gvFileViewer.AutoGenerateColumns = true; gvFileViewer.DataSource = validator.Rows; gvFileViewer.Refresh(); foreach (var column in gvFileViewer.Columns) { column.AutoSizeMode = BestFitColumnMode.DisplayedCells; } gvFileViewer.BestFitColumns(); string contents = System.IO.File.ReadAllText(fileName); tbFileContents.Text = contents; //tbErrors.Text = "No Errors Found"; } catch (Exception ex) { tbErrors.Text += ex.ToString(); } finally { gvFileViewer.EndUpdate(); this.Cursor = Cursors.Default; } }
private bool ValidateEncounterFile(ImportedFileStatus candidate) { EncounterFileValidator validator = new EncounterFileValidator(); // Validate the file and record the results validator.Validate(candidate.FileName); StringBuilder sb = new StringBuilder(); validator.Errors.ForEach(x => sb.AppendLine(x.ToString())); SystemDataProvider.ClientDataProvider.ValidateImportedFile(candidate.ImportedFileStatusID, validator.TotalRows, validator.HasErrors, sb.ToString()); if (validator.HasErrors) { log.WarnFormat("Row {0} has {1} errors!", candidate.ImportedFileStatusID, validator.Errors.Count()); } else { log.DebugFormat("Row {0} validated successfully!", candidate.ImportedFileStatusID); } return !validator.HasErrors; }
private void tsbEncounterImportValidator_Click(object sender, EventArgs e) { dlgOpenFile.Title = "Select Encounter File to Validate"; if (dlgOpenFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.Cursor = Cursors.WaitCursor; try { EncounterFileValidator validator = new EncounterFileValidator(); bool Validated = false; int TotalRows = 0; int SkippedRows = 0; Validated = validator.Validate(dlgOpenFile.FileName); TotalRows = validator.TotalRows; SkippedRows = validator.NumSkipped; if (!Validated) { //StringBuilder sbErrors = new StringBuilder(); //validator.Errors.ForEach(x => sbErrors.AppendLine(x.ToString())); //string errorMessage = sbErrors.ToString(); //MessageBox.Show(String.Format("File {0} fails validation!{2}{1}", dlgOpenFile.FileName, errorMessage.Substring(0, 100), Environment.NewLine)); MessageBox.Show(String.Format("File {0} fails validation! {0} Valid Rows, {1}, Skipped Rows{2}", dlgOpenFile.FileName, TotalRows, SkippedRows)); } else { MessageBox.Show(string.Format("File passed validation. {0} Valid Rows, {1} Rows Skipped", TotalRows, SkippedRows)); } } finally { this.Cursor = Cursors.Default; } } }