Skip to content

Instantly share code, notes, and snippets.

@gbautista72
Last active August 22, 2019 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbautista72/a319218beaa53df8a935906f9be0c91d to your computer and use it in GitHub Desktop.
Save gbautista72/a319218beaa53df8a935906f9be0c91d to your computer and use it in GitHub Desktop.
Get Doctor Count Powershell Script
Clear-Variable content -erroraction SilentlyContinue
#Clear-Variable list -erroraction SilentlyContinue
$documentPaths = New-Object System.Collections.ArrayList
$doctorResults = @{}
$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"
$completeTotal = 0
$errorLog = "D:\script\Isaacs-Scripts\scripts\get-doctorcount\errorlogs\$dateTime.html"
$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)
$doctors = @(
'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"
)
try {
# add firstnames to list
$firstnames = New-Object System.Collections.ArrayList
foreach ($doctor in $doctors) {
$docname = ($doctor -split '\s')
$docname = $docname[0]+$docname[-1][0]
$firstnames += $docname
}
# foreach doctor name, name a new variable called the doctor name
foreach ($firstname in $firstnames) {
if (Get-Variable -name $firstname -ErrorAction SilentlyContinue) {
Remove-Variable $firstname
}
New-Variable -Name $firstname -Value @{}
$drvar = (Get-Variable -Name $firstname -ValueOnly)
$drvar.add('rdc',(New-Object System.Collections.Arraylist))
$drvar.add('cdc',(New-Object System.Collections.Arraylist))
$drvar.add('fh',(New-Object System.Collections.Arraylist))
$drvar.add('mrmc',(New-Object System.Collections.Arraylist))
$drvar.add('svh',(New-Object System.Collections.Arraylist))
$drvar.add('scdc',(New-Object System.Collections.Arraylist))
}
foreach ($site in $sites) {
# if site is rdc use rdc path
if ($site -eq 'rdc') {
$items = gci "D:\reports\dr_reports\archive\$date"
} else {
$items = gci "D:\ininbound\$site\archive\$date"
}
foreach ($item in $items) {
$documentPaths += $item.fullname
}
}
foreach ($document in $documentPaths) {
If ($Match = Select-String -Path $document -Pattern '^*Dictated\s+by\s*:?\s*(.*?)\s*\Z' | Select-Object -Last 1 -ExpandProperty Matches) {
$content = $Match.Groups[1].Value
$sitename = $document.split('\')[2]
if ($sitename -match 'dr_reports') { $sitename = 'rdc' }
Write-Host "`r`n"
Write-Host $document -ForegroundColor Cyan
Write-Host $content
foreach ($doctor in $doctors) {
if ($content -match $doctor) {
# create dyn string to call dr variable
$docsplit = $doctor.split(' ')
[string]$tempDrVar = $docsplit[0]+$docsplit[-1][0]
# call doctor firstname variable
$doctorVariable = Get-Variable -Name $tempDrVar
$doctorVariable.value.$sitename += $document
Write-Host "$document matched $doctor" -ForegroundColor Yellow
Add-Content -path $doctorLog -value "$doctor found on $document"
}
}
} Else {
# String not found
}
}
New-Item -Path $csvPath -itemtype file
Add-Content $csvPath -Value $dateTime
Add-Content $csvPath -value "DRName,TOTAL,RASLO,AGCH,FH,MRMC,SVH,SCDC"
foreach ($firstname in $firstnames) {
$total = 0
$docVar = Get-Variable -name $firstname -ValueOnly
$keys = $docVar.keys
foreach ($key in $keys) {
$total = $docVar.$key.count + $total
}
$completeTotal = $completeTotal + $total
Add-Content $csvPath -Value "$firstname,$total,$($docVar.rdc.count),$($docVar.cdc.count),$($docVar.fh.count),$($docVar.mrmc.count),$($docVar.svh.count),$($docVar.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 "Radiologist Daily Read Count for $date" -Body "Radiologist counts for $date" -SmtpServer 'aspmx.l.google.com' -port '25' -Attachments $csvPath
$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
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment