Public/Get-SfPatients.ps1
<# .SYNOPSIS Queries salesforce for patients .DESCRIPTION Used to query for patients in the salesforce org by status .INPUTS None. You cannot pipe objects to Get-SfPatients. .OUTPUTS An array of PSCustomObject with the properties: Id phecc__CDRPID__c phecc__Delivery_Channel__c phecc__Permission__c phecc__Status__c phecc__Tier_of_Service__c .PARAMETER Status The status to query patients. If not supplid then the default is "Active". Use $null for all patients. .EXAMPLE PS> $allPatients = Get-Patients -Status $null PS> $activePatients = Get-Patients PS> $pending = Get-Patients -Status "Pending - Activation" .LINK Set-Config .NOTES Assumes config is initialized for org access. #> function Get-SfPatients { [CmdletBinding()] [OutputType([PSCustomObject[]])] param( [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline)] [ValidateSet("Pending - Activation", "Active", "Suspended", "Pending - Removal", "Removed", "All", "Deleted")] [String] $Status = "All", [Parameter(Mandatory = $false, Position = 1)] [String] $Id ) begin { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function started" } end { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Complete" } process { Write-Debug "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)" $query = "SELECT Id,phecc__CDRPID__c,phecc__Permission__c,phecc__Status__c,phecc__Tier_of_Service__c,phecc__Delivery_Channel__c,phecc__Site__c,phecc__Deleted__c FROM phecc__Patient__c " if ($PSBoundParameters.ContainsKey('Status') -and ($Status -cne "All") -and ($Status -cne "Deleted")) { $query += "WHERE phecc__Deleted__c=False AND phecc__Status__c='$($Status)'" } elseif ($PSBoundParameters.ContainsKey('Status') -and ($Status -ceq "Deleted")) { $query += "WHERE phecc__Deleted__c=True" } else { $query += "WHERE phecc__Deleted__c=False" } if ($PSBoundParameters.ContainsKey('Id')) { $query += " AND Id='$($Id)'" } Invoke-SfQuery $query } } |