Yes, I agree. Lots of tweeking going on. Here’s the latest.
[PRE]
$sites = ‘cdc’,‘fh’,‘mrmc’,‘svh’,‘scdc’,‘rdc’
$date = (Get-Date(Get-Date).AddDays(-1) -Format ‘yyyy-MM-dd’)
$dateTime = (Get-Date(Get-Date).AddDays(-1) -Format ‘MM-dd-yyyy.hh.mm’)
$csvPath = “D:\script\Isaacs-Scripts\scripts\get-doctorcount\CSVs$dateTime.csv”
$errorLog = “D:\script\Isaacs-Scripts\scripts\get-doctorcount\errorlogs$dateTime.html”
$errordoc = “D:\script\Isaacs-Scripts\scripts\get-doctorcount\errorlogs$dateTime-doctor-error.txt”
$doctorLog = “D:\script\Isaacs-Scripts\scripts\get-doctorcount\logs$dateTime.txt”
array of all doctor names
to add to it, simply add quotes and a comma (unless its the last in the array)
$docList = @(
‘Benjamin T. Addicott’,
‘Timothy L. Auran’,
‘Eugene F. Barasch’,
‘William C. Burnette’,
‘Kevin R. Connolly’,
‘Harry F. Corbett’,
‘Timothy L. Davis’,
‘Arthur C. Duberg’,
‘Stephen R. Holtzman’,
‘Taylor R. Jordan’,
‘Thomas L. Miller’,
‘Linda D. Mulder’,
‘Ragu C. Nathan’,
‘Erik M. Olson’,
‘Jaywant P. Parmar’,
‘Mohsin M. Rahman’,
‘David A. Rigual’,
‘William M. Russell’,
‘Farhad W. Sani’,
‘Melissa E. Sims’,
‘Laura E. Traube’,
‘David J. Tuttle’,
‘Erica Vergara’,
‘Donna E. Winingham’,
‘Felix Y. Yap’,
‘Mark Ziemba’,
“Teresa O’Neill”,
“Sonja M. O’Brien”
)
hash table of alternative names in format @{‘alias’ = ‘standard name’, ‘alias’ = ‘standard name’}
Would like some way of capturing the KNOWN maflormed names so that the script continues. Take that malformed name and add it to the running total for the doctor and for the site.
$docSynonyms = @{‘YAP, FELIX Y.’ = ‘Felix Y. Yap’}
$doc = @{}
try {
predefine doctor structure
foreach ($name in $docList)
{
$doc[$name] = @{}
foreach ($site in $sites) { $doc[$name] += @{ $site = @() } }
}
process documents based on site
foreach ($site in $sites)
{
Get-ChildItem ($(if ($site -eq ‘rdc’) { “D:\reports\dr_reports” } else { “D:\ininbound$site” }) + “\archive$date”) |
% {
$document = $_.FullName
if ($Match = Select-String -Path $document -Pattern ‘^Dictated\s+by`:\s**?(.*?),\s’ | Select-Object -Last 1 -ExpandProperty Matches)
{
$content = $Match.Groups[1].Value
Write-Host “`r`n”
Write-Host $document -ForegroundColor Cyan
Write-Host $content
if ($content -in $docSynonyms) { $content = $docSynonyms[$content] }
if ($doc[$content])
{
$doc[$content].$site += $document
Write-Host “$document matched $content” -ForegroundColor Yellow
Add-Content -path $doctorLog -value “$content found on $document”
} else {
Write-Host -f red “$content not in list of doctors”
Add-Content $errordoc -Value “$content not in the list of doctors”
}
} else {
String not found
}
}
}
Set-Content $csvPath -Value $dateTime
Add-Content $csvPath -value “DRName,TOTAL,RASLO,AGCH,FH,MRMC,SVH,SCDC”
$completeTotal = 0
foreach ($doctor in $docList)
{
$curdoc = $Doc[$doctor]
$total = ($curdoc[$sites] | % { $_ }).Count
$completeTotal += $total
$firstname = $doctor.Split(’ ')
$firstname = $firstname[0] + $firstname[-1][0]
Add-Content $csvPath -Value “$firstname,$total,$($curdoc.rdc.count),$($curdoc.cdc.count),$($curdoc.fh.count),$($curdoc.mrmc.count),$($curdoc.svh.count),$($curdoc.scdc.count)”
}
Add-Content $csvPath -Value “Total Doctor Count,$completeTotal”
Send-MailMessage -From ‘email’ -to ‘email’ -Subject “Radiologist Daily Read Count for $date” -Body “Radiologist counts for $date” -SmtpServer ‘aspmx.l.google.com’ -port ‘25’ -Attachments $csvPath
Send-MailMessage -From ‘email’ -to ‘email’ -Subject “Error - NON Rads for $date” -Body “Error - Rads not in rad array for $date” -SmtpServer ‘aspmx.l.google.com’ -port ‘25’ -Attachments $errordoc
$sortedContent = Get-Content $doctorLog | Sort-Object
Set-Content -path $doctorLog -Value $sortedContent
} catch {
Add-Content $errorlog -Value “<font color = ‘red’>Error Content</font> -<br><br>Exception: $($.Exception)<br><br> CategoryInfo: $($.CategoryInfo)<br><br> StackLocation: $($.ScriptStackTrace)<hr>"
Send-MailMessage -From ‘email’ -to ‘email’ -Subject ‘Error found with Doctor Count:’ -Body "<font color = ‘red’>Error Content</font> -<br><br>Exception: $($.Exception)<br><br> CategoryInfo: $($.CategoryInfo)<br><br> StackLocation: $($.ScriptStackTrace)<hr>” -SmtpServer ‘aspmx.l.google.com’ -port ‘25’ -BodyAsHtml
}
[/PRE]