Public/Remove-Flags.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
<#
    .SYNOPSIS
    Removes flags from the salesforce org associated to a patient

    .DESCRIPTION
    Removes flags from the salesforce org associated to a patient

    .INPUTS
    None. You cannot pipe objects to Remove-Flags.

    .OUTPUTS
    None

    .PARAMETER Patient
    The patient object from Get-Patients

    .EXAMPLE
    PS> Remove-Flags -Patient (Get-Patient -SelectCdrIds @("c54dab55-7a68-4795-93bc-66b6e192121e"))

    .LINK
    Set-FileConfig
    Get-Patients

    .NOTES
    Assumes config is initialized for org access.
    Will write progress
#>

function Remove-Flags {
    param([PSObject]$Patient)
    Write-Information "Clearing Flags for $($Patient.cdrPatient.resource.id)"
    $Flags = Get-FlagsForPatient $Patient
    $i = 0
    foreach($Flag in $Flags) {
        Invoke-SfApi "/sobjects/phecc__Flag__c/$($Flag.Id)" -Method Delete | Out-Null
        $i++
        Write-Progress -Activity "Clear Flags" -PercentComplete (($i / $Flags.Count)  * 100) -Status "Cleared: $i of $($Flags.Count)"
    }
}