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

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

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

    .OUTPUTS
    None

    .PARAMETER Patient
    The patient object from Get-Patients

    .EXAMPLE
    PS> Remove-Measurements -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-Measurements {

    [CmdletBinding()]
    [OutputType([System.Void])]
    param(
        [Parameter(Mandatory = $true, 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)"
        Write-Information "$(Get-Date -f 'hh:mm:ss') Clearing Measurements for $($Patient.cdrPatient.resource.id)"
        $Observations = Get-ObservationsForPatient $Patient
        $i = 0
        foreach ($Observation in $Observations) {
            Invoke-SfApi "/sobjects/phecc__Observation__c/$($Observation.Id)" -Method Delete | Out-Null
            $i++
            Write-Progress -Activity "Clear Observations" -PercentComplete (($i / $Observations.Count) * 100) -Status "Cleared: $i of $($Observations.Count)"
        }
    }
}