Replace Unicode arrows/dashes with ASCII in engine.ps1 and run-all.ps1

Windows PowerShell (5.1) reads .ps1 files without a UTF-8 BOM using the
system codepage, which mangles multi-byte UTF-8 characters like -> and --
into garbage that includes smart-quote characters PowerShell treats as
string terminators - this broke parsing on Melissa's PC (error at
engine.ps1:283, cascading missing-brace errors above it). Sticking to plain
ASCII avoids the whole encoding-dependent failure class.
This commit is contained in:
2026-07-05 19:18:26 -05:00
parent e18010e54e
commit 83e16ed6cd
2 changed files with 20 additions and 20 deletions
+19 -19
View File
@@ -1,4 +1,4 @@
# Core upload engine called by run.ps1 with an entity directory path
# Core upload engine - called by run.ps1 with an entity directory path
param(
[Parameter(Mandatory=$true)]
[string]$EntityDir
@@ -8,7 +8,7 @@ $scriptRoot = Split-Path -Parent $PSCommandPath
$winscpDll = Join-Path $scriptRoot "WinSCP\WinSCPnet.dll"
$today = Get-Date -Format "yyyyMMdd"
# ── Logging setup ────────────────────────────────────────────────────────────
# -- Logging setup ------------------------------------------------------------
$logsDir = Join-Path $scriptRoot "Logs"
if (-not (Test-Path $logsDir)) { New-Item -ItemType Directory -Path $logsDir | Out-Null }
$logFile = Join-Path $logsDir "$today.log"
@@ -45,7 +45,7 @@ function Write-Debug($message) {
}
}
# ── WinSCP ───────────────────────────────────────────────────────────────────
# -- WinSCP -------------------------------------------------------------------
if (-not (Test-Path $winscpDll)) {
Write-Host "ERROR: WinSCP not found. Run setup.bat first." -ForegroundColor Red
Write-Log "error" "WinSCP DLL not found at $winscpDll"
@@ -53,7 +53,7 @@ if (-not (Test-Path $winscpDll)) {
}
Add-Type -Path $winscpDll
# ── Entity config ─────────────────────────────────────────────────────────────
# -- Entity config -------------------------------------------------------------
$entityConfigFile = Join-Path $EntityDir "entity.json"
if (-not (Test-Path $entityConfigFile)) {
Write-Host "ERROR: entity.json not found in $EntityDir" -ForegroundColor Red
@@ -77,7 +77,7 @@ Write-Host "Entity: $entityName | Workflow: $workflow | Date: $today | Log: $log
Write-Host ("=" * 60)
Write-Info "=== START entity=$entityName workflow=$workflow ==="
# ── Helpers ──────────────────────────────────────────────────────────────────
# -- Helpers ------------------------------------------------------------------
function Merge-Config($base, $override) {
if (-not $override) { return $base }
$merged = $base | ConvertTo-Json -Depth 10 | ConvertFrom-Json
@@ -104,7 +104,7 @@ function Get-ArchiveDir($parent, $name) {
return $path
}
# ── Upload via FTPS ───────────────────────────────────────────────────────────
# -- Upload via FTPS -----------------------------------------------------------
function Invoke-FTPSUpload($ftpConfig, $files, $remotePath, $entity, $practice) {
$opts = New-Object WinSCP.SessionOptions
$opts.Protocol = [WinSCP.Protocol]::Ftp
@@ -150,7 +150,7 @@ function Invoke-FTPSUpload($ftpConfig, $files, $remotePath, $entity, $practice)
return @{ Ok = $ok; Fail = $fail }
}
# ── Upload via SFTP ───────────────────────────────────────────────────────────
# -- Upload via SFTP -----------------------------------------------------------
function Invoke-SFTPUpload($sftpConfig, $files, $remotePath, $entity, $practice) {
$opts = New-Object WinSCP.SessionOptions
$opts.Protocol = [WinSCP.Protocol]::Sftp
@@ -195,7 +195,7 @@ function Invoke-SFTPUpload($sftpConfig, $files, $remotePath, $entity, $practice)
return @{ Ok = $ok; Fail = $fail }
}
# ── Main loop ─────────────────────────────────────────────────────────────────
# -- Main loop -----------------------------------------------------------------
$totalOk = 0; $totalFail = 0
$practices = Get-ChildItem -Path $export1 -Directory
@@ -216,10 +216,10 @@ foreach ($practice in $practices) {
$config = Merge-Config $entityConfig $override
if ($override) { Write-Debug "practice.json override loaded for $pracName" }
# ── Insurance + PT STMT FTPS ───────────────────────────────────────────
# -- Insurance + PT STMT -> FTPS -------------------------------------------
$dateDir = Join-Path $practice.FullName $today
if (-not (Test-Path $dateDir)) {
Write-Host " No $today\ folder skipping insurance." -ForegroundColor Gray
Write-Host " No $today\ folder - skipping insurance." -ForegroundColor Gray
Write-Info "SKIP entity=$entityName practice=$pracName reason=no date folder"
} else {
$allPdfs = Get-ChildItem -Path $dateDir -Filter "*.pdf" -File
@@ -231,12 +231,12 @@ foreach ($practice in $practices) {
$insResult = @{ Ok = 0; Fail = 0 }
if ($insFiles.Count -gt 0) {
Write-Host " Insurance ($($insFiles.Count)) $insPath" -ForegroundColor White
Write-Host " Insurance ($($insFiles.Count)) -> $insPath" -ForegroundColor White
$r = Invoke-FTPSUpload $config.ftps $insFiles $insPath $entityName $pracName
$insResult.Ok += $r.Ok; $insResult.Fail += $r.Fail
}
if ($ptStmts.Count -gt 0) {
Write-Host " PT STMT PDF ($($ptStmts.Count)) $pdfPath" -ForegroundColor White
Write-Host " PT STMT PDF ($($ptStmts.Count)) -> $pdfPath" -ForegroundColor White
$r = Invoke-FTPSUpload $config.ftps $ptStmts $pdfPath $entityName $pracName
$insResult.Ok += $r.Ok; $insResult.Fail += $r.Fail
}
@@ -248,7 +248,7 @@ foreach ($practice in $practices) {
Write-Host " $today\ archived." -ForegroundColor Green
Write-Info "ARCHIVE entity=$entityName practice=$pracName folder=$today"
} elseif ($insResult.Fail -gt 0) {
Write-Host " $($insResult.Fail) failed $today\ left for retry." -ForegroundColor Yellow
Write-Host " $($insResult.Fail) failed - $today\ left for retry." -ForegroundColor Yellow
} elseif ($totalUploaded -eq 0) {
Write-Host " No PDFs in $today\." -ForegroundColor Gray
Write-Info "SKIP entity=$entityName practice=$pracName reason=no PDFs in date folder"
@@ -257,11 +257,11 @@ foreach ($practice in $practices) {
$totalOk += $insResult.Ok; $totalFail += $insResult.Fail
}
# ── Patient files SFTP ─────────────────────────────────────────────────
# -- Patient files -> SFTP -------------------------------------------------
if ($workflow -eq "insurance+patient") {
$patientExport = Join-Path $practice.FullName "Patient\Export"
if (-not (Test-Path $patientExport)) {
Write-Host " No Patient\Export folder skipping patient." -ForegroundColor Gray
Write-Host " No Patient\Export folder - skipping patient." -ForegroundColor Gray
Write-Info "SKIP entity=$entityName practice=$pracName reason=no Patient\Export"
} else {
$ptFolder = Get-ChildItem -Path $patientExport -Directory |
@@ -269,18 +269,18 @@ foreach ($practice in $practices) {
Select-Object -First 1
if (-not $ptFolder) {
Write-Host " No PT STMT_$today folder skipping patient." -ForegroundColor Gray
Write-Host " No PT STMT_$today folder - skipping patient." -ForegroundColor Gray
Write-Info "SKIP entity=$entityName practice=$pracName reason=no PT STMT_$today folder"
} else {
$patFiles = Get-ChildItem -Path $ptFolder.FullName -File |
Where-Object { $_.Extension -imatch '\.(txt|tif|tiff)$' }
if ($patFiles.Count -eq 0) {
Write-Host " No txt/tif files in $($ptFolder.Name)\ skipping." -ForegroundColor Gray
Write-Host " No txt/tif files in $($ptFolder.Name)\ - skipping." -ForegroundColor Gray
Write-Info "SKIP entity=$entityName practice=$pracName reason=no txt/tif files"
} else {
$patPath = Expand-Path $config.sftp.patient_path $pracName
Write-Host " Patient ($($patFiles.Count)) $patPath" -ForegroundColor White
Write-Host " Patient ($($patFiles.Count)) -> $patPath" -ForegroundColor White
$r = Invoke-SFTPUpload $config.sftp $patFiles $patPath $entityName $pracName
if ($r.Fail -eq 0) {
@@ -289,7 +289,7 @@ foreach ($practice in $practices) {
Write-Host " $($ptFolder.Name)\ archived." -ForegroundColor Green
Write-Info "ARCHIVE entity=$entityName practice=$pracName folder=$($ptFolder.Name)"
} else {
Write-Host " $($r.Fail) failed left for retry." -ForegroundColor Yellow
Write-Host " $($r.Fail) failed - left for retry." -ForegroundColor Yellow
}
$totalOk += $r.Ok; $totalFail += $r.Fail
+1 -1
View File
@@ -27,5 +27,5 @@ Write-Host ""
if (-not $anyFail) {
Write-Host "All entities complete." -ForegroundColor Green
} else {
Write-Host "One or more entities had failures check output above." -ForegroundColor Yellow
Write-Host "One or more entities had failures - check output above." -ForegroundColor Yellow
}