Local SFTP intake rehearsal (J3)¶
SftpDropFolderIngestor watches a local folder by polling. It stands in for the landing directory of an SFTP server; it does not implement SSH, authentication or a network SFTP service. Use synthetic files only.
Run dotnet run --project src/FhirDemo.Cli -- sftp scan for one scan or sftp watch for continuous intake. Aspire registers the sftp-intake resource with sftp watch. Publish each file by uploading under a .tmp name, closing it, then atomically renaming it into data/inbox as .json, .hl7 or .oru. Published files must be immutable.
FHIR bundles use the existing FHIR mapper and intake-answer validation. ORU files use the existing limited parser: exactly one MSH, PID and numeric LOINC OBX. Multiple observations or messages are quarantined explicitly; no secondary result is silently discarded. This is not a production HL7 interface engine.
The callback upserts into a separate data/intake.db, preserving source isolation from the fixture, local-EHR and Oystehr databases. It reads every submitted resource back from committed storage and compares its JSON before acknowledging the file. Conflicting or unorderable versions stop the scan for operator attention; they cannot receive an accepted receipt.
Successful raw-file SHA-256 receipts live in data/processed. Identical bytes under another name or after restart are skipped. Inputs remain in the inbox. A crash after database commit but before the atomic receipt can replay the callback; clinical upserts and readback make replay safe. This is durable hash deduplication with an idempotent sink, not a distributed exactly-once claim.
Malformed files, invalid UTF-8 and files exceeding 16 MiB move into data/quarantine, with a hash-based name and INVALID_CLINICAL_PAYLOAD reason. Parser messages and clinical text are not written to reason files. Files and receipts contain synthetic clinical payloads and are ignored by Git. Symlink/reparse paths and overlapping intake directories are rejected.
Persistence/readback failures leave the file unacknowledged and terminate the watcher. Correct the underlying issue and restart it. Cancellation also preserves retryability. Watcher tests cover successful files, malformed files, restart/renamed duplicates, callback failures, incomplete uploads, multiple-OBX rejection, conflicts and filesystem guards.