Public/Get-SfPlannedEntries.ps1

<#
    .SYNOPSIS
    Queries salesforce for patient calendar planned entries that are not deleted

    .DESCRIPTION
    Can be used for a single patient or for all patients

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

    .OUTPUTS
    An array of PSCustomObject with the properties:
        CreatedDate
        Id
        phecc__Measurement_Type__c
        phecc__Permission__c

    .PARAMETER Patient
    The patient object from Get-Patients

    .PARAMETER Type
    The type of planned entry. Defaults to "Measurement"

    .EXAMPLE
    PS> $pes = Get-SfPlannedEntries -Patient (Get-Patients -SelectCdrIds @("36eeb673-9dc2-409e-a328-b994b377244d"))

    .LINK
    Set-Config

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

function Get-SfPlannedEntries {

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

        [Parameter(Mandatory = $false, Position = 1)]
        [String]
        $Type = "Measurement"
    )
    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__Measurement_Type__c,CreatedDate,phecc__Permission__c FROM phecc__Planned_Entry__c"
        if ($PSBoundParameters.ContainsKey('Patient')) {
            $query += " WHERE phecc__Permission__c='$($Patient.sfPatient.phecc__Permission__c)' AND IsDeleted = false AND phecc__Type__c = '$($Type)'"
        }
        else {
            $query += " WHERE IsDeleted = false AND phecc__Type__c = '$($Type)'"
        }
        Invoke-SfQuery $query
    }
}