Public/Get-SfPatientPreferences.ps1

<#
    .SYNOPSIS
    Queries salesforce for patient preferences.

    .DESCRIPTION
    Used to query for patient preferences for a single patient or all patients.

    .INPUTS
    None. You cannot pipe objects to Get-SfPatientPreferences.

    .OUTPUTS
    An array of PSCustomObject with the properties:
        Id
        Name
        phecc__Patient__c ( sfdc patient object id)

    .PARAMETER Patient
    The patient object from Get-Patients. If not supplied then all patient preferences are queries.

    .EXAMPLE
    PS> $ptPrefs = Get-SfPatientPreferences

    .LINK
    Set-Config
    Get-Patients

    .NOTES
    Assumes config is initialized for org access.
#>

function Get-SfPatientPreferences {

    [CmdletBinding()]
    [OutputType([PSCustomObject[]])]
    param(
        [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline)]
        [ValidateNotNull()]
        [PSCustomObject]
        $Patient
    )

    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,Name,phecc__Patient__c FROM phecc__Patient_Preference__c"
        if ($PSBoundParameters.ContainsKey('Patient')) {
            $query += " WHERE phecc__Patient__c='$($Patient.sfPatient.Id)'"
        }
        Invoke-SfQuery $query
    }
}