Public/Get-SfPlannedEntries.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#
    .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
    }
}