Public/Remove-Observations.ps1

<#
    .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 {
    param([PSObject]$Patient)
    Write-Information "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)"
    }
}