Public/Get-SfDevices.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
<#
    .SYNOPSIS
    Queries salesforce for devices.

    .DESCRIPTION
    Used to query for devices in the salesforce org. Can query all devices or just devices for one patient.

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

    .OUTPUTS
    An array of PSCustomObject with the properties:
        Id
        phecc__Device_ID__c
        phecc__Device_Master_Id__c
        phecc__Device_Model__c
        phecc__Patient__c
        phecc__Site_Name__c
        phecc__Site__c

    .EXAMPLE
    PS> $devicesAssignedToPatients = Get-SfDevices | Where-Object {$_.phecc__Patient__c}

    .LINK
    Set-FileConfig

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

function Get-SfDevices {
    param($Patient)
    if ($Patient) {
        Invoke-SfQuery "SELECT Id,Name,phecc__Device_ID__c,phecc__Device_Master_Id__c,phecc__Device_Model__c,phecc__Patient__c,phecc__Site_Name__c,phecc__Site__c FROM phecc__Device__c WHERE phecc__Patient__c = '$($Patient.sfPatient.Id)'"
    } else {
        Invoke-SfQuery "SELECT Id,Name,phecc__Device_ID__c,phecc__Device_Master_Id__c,phecc__Device_Model__c,phecc__Patient__c,phecc__Site_Name__c,phecc__Site__c FROM phecc__Device__c"
    }
}