Skip to content

ImportPreProcessor

Implements IImportPreProcessor, the file-system-level front end of the auto-import pipeline: it parses an incoming file's name into its expected REFERENCENUM_DOCDESCRIPTION[_DOCDATE]_UNIQUE.EXT segments, copies the file into the auto-import directory, delegates index-file creation to IAutoImportHelperService, and routes the source file into a complete, error, or UndefinedDocument subfolder based on outcome. It depends on IAutoImportHelperService for index generation and the destination path, and holds (but does not directly use in the shown code paths) IUnitOfWork and IEnvironmentService.

Purpose

  • Parses an incoming file name into reference number, document description code, optional document date, and file-count segments, validating the expected 3- or 4-segment naming convention.
  • Copies the source file into the auto-import output directory under a uniquely timestamped name and triggers .idx file generation for it.
  • Moves the original file into a complete subfolder on success, an UndefinedDocument subfolder when no matching index defaults exist for a Majoris-medical file, or an error subfolder for any other failure — without overwriting existing files at the destination.

Context

  • Namespace: SAIF.Services.Imaging
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
ImportPreProcessor(...) public ImportPreProcessor(IUnitOfWork unitOfWork, IEnvironmentService environmentService, IAutoImportHelperService autoImportHelperService, string failureEmailRecipient) Wires in the unit of work, environment service, auto-import helper, and failure-notification recipient (all enforced non-null), and initializes a per-instance unique timestamp used to disambiguate output file names.
ProcessFile public FileInfo ProcessFile(FileInfo fileInfo) Parses the file name, copies and indexes the file via IAutoImportHelperService, and moves it to the appropriate outcome folder; returns the generated index FileInfo on success, or throws with the underlying error message on any failure.

Behavioral notes

  • Strips zero-width non-joiner characters (\u200C) from the file name before parsing, suggesting the source system occasionally injects them into file names*.
  • Accepts either a 4-segment name (REF_DESC_DOCDATE_UNIQUE.EXT) or a 3-segment name (REF_DESC_UNIQUE.EXT); any other segment count is treated as an immediate naming-convention failure.
  • Parses the document-date segment against a fixed list of accepted date formats (e.g. M-d-yyyy, yyyyMMdd, yyyy-MM-dd), and separately detects an NofM file-count pattern (e.g. "1of5") case-insensitively via regex.
  • On failure, files whose name contains "MAJORIS-MEDICAL-" and whose error indicates missing index defaults are routed to the UndefinedDocument folder instead of error, treating that specific combination as an expected/benign condition rather than a true error*.
  • MoveFileWithoutOverwrite appends an incrementing (n) suffix to the destination file name until a non-colliding path is found, so no destination file is ever silently overwritten.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Services/SAIF.Services/Imaging/ImportPreProcessor.cs