Validate FTPS/SFTP config fields and name what's missing before connecting

CAMBS's run showed host= blank, an empty upload path, and WinSCP's
"Password is set, but UserName is not" - i.e. entity.json's ftps section
had a readable password but host/username/insurance_path came up empty,
which points at misspelled or misplaced keys. Instead of letting WinSCP
throw a cryptic connect error per practice, check the merged config up
front and print exactly which entity.json fields are missing or blank.
This commit is contained in:
2026-07-05 20:05:31 -05:00
parent dae1bf5754
commit d03dca38af
+26
View File
@@ -110,6 +110,16 @@ function Expand-Path($template, $practice) {
return $template -replace '\{practice\}', $practice
}
function Get-MissingFields($section, $sectionName, $fieldNames) {
$missing = @()
foreach ($f in $fieldNames) {
if (-not $section -or [string]::IsNullOrWhiteSpace([string]$section.$f)) {
$missing += "$sectionName.$f"
}
}
return $missing
}
function Get-ArchiveDir($parent, $name) {
$found = Get-ChildItem -Path $parent -Directory |
Where-Object { $_.Name -ieq $name } | Select-Object -First 1
@@ -245,6 +255,16 @@ foreach ($practice in $practices) {
$pdfPath = Expand-Path $config.ftps.pdf_path $pracName
$insResult = @{ Ok = 0; Fail = 0 }
$missing = Get-MissingFields $config.ftps "ftps" @("host", "username", "password", "insurance_path", "pdf_path")
if (($insFiles.Count -gt 0 -or $ptStmts.Count -gt 0) -and $missing.Count -gt 0) {
Write-Host " CONFIG ERROR: entity.json is missing or has blank: $($missing -join ', ')" -ForegroundColor Red
Write-Host " Check spelling of those keys in entity.json (and practice.json if present)." -ForegroundColor Yellow
Write-Log "error" "CONFIG entity=$entityName practice=$pracName missing=$($missing -join ',')"
$totalFail += $insFiles.Count + $ptStmts.Count
Write-Host " $today\ left for retry." -ForegroundColor Yellow
continue
}
if ($insFiles.Count -gt 0) {
Write-Host " Insurance ($($insFiles.Count)) -> $insPath" -ForegroundColor White
$r = Invoke-FTPSUpload $config.ftps $insFiles $insPath $entityName $pracName
@@ -293,6 +313,12 @@ foreach ($practice in $practices) {
if ($patFiles.Count -eq 0) {
Write-Host " No txt/tif files in $($ptFolder.Name)\ - skipping." -ForegroundColor Gray
Write-Info "SKIP entity=$entityName practice=$pracName reason=no txt/tif files"
} elseif (($sftpMissing = Get-MissingFields $config.sftp "sftp" @("host", "username", "password", "patient_path")).Count -gt 0) {
Write-Host " CONFIG ERROR: entity.json is missing or has blank: $($sftpMissing -join ', ')" -ForegroundColor Red
Write-Host " Check spelling of those keys in entity.json (and practice.json if present)." -ForegroundColor Yellow
Write-Log "error" "CONFIG entity=$entityName practice=$pracName missing=$($sftpMissing -join ',')"
$totalFail += $patFiles.Count
Write-Host " $($ptFolder.Name)\ left for retry." -ForegroundColor Yellow
} else {
$patPath = Expand-Path $config.sftp.patient_path $pracName
Write-Host " Patient ($($patFiles.Count)) -> $patPath" -ForegroundColor White