Public/Get-FormattedPatientName.ps1
<# .SYNOPSIS Help cmdlet to return just the patient name. .DESCRIPTION Returns just the patient name in the format "Family, Given" .INPUTS The patient PSCustomObject .OUTPUTS Formatted patient name .PARAMETER Patient The patient PSCustomObject .EXAMPLE PS> Get-Patients | % { Get-FormattedPatientName $_ } #> function Get-FormattedPatientName { [CmdletBinding()] [OutputType([String])] param( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline)] [PSCustomObject] $Patient ) begin { $p = ($Patient | Select-Object -expand cdrPatient ` | ForEach-Object { $_.resource } ` | Select-Object id, @{Name = 'family'; expression = { ($_.name | Where-Object { $_.use -eq 'usual' }).family } }, @{Name = 'given'; expression = { ($_.name | Where-Object { $_.use -eq 'usual' }).given } }) Write-Output "$($p.given), $($p.family)" } } |