diff --git a/engine.ps1 b/engine.ps1 index 83cae3c..4b363df 100644 --- a/engine.ps1 +++ b/engine.ps1 @@ -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