Public/Set-PatientSoftDeleted.ps1

<#
    .SYNOPSIS
    Sets a patient soft deleted flag in Salesforce

    .DESCRIPTION
    Sets a patient as soft deleted in Salesforce

    .INPUTS
    A PSCustomObject that is the patient.

    .OUTPUTS
    None.

    .PARAMETER Patient
    The Patient PSCustomObject.

    .PARAMETER Deleted
    Indicates the soft delete flag value. Defaults to $true if not specified

    .NOTES

    .LINK
    Get-Patients
#>

function Set-PatientSoftDeleted {

    [CmdletBinding()]
    [OutputType([System.Void])]
    param(
        [Parameter(Mandatory, Position = 0, ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        [PSCustomObject]
        $Patient,

        [Parameter(Mandatory = $false, Position = 1)]
        [Bool]
        $Deleted
    )
    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)"
        if (-not $PSBoundParameters.ContainsKey('Deleted')) {
            $Deleted = $true
        }
        $body = [PSCustomObject]@{
            phecc__Deleted__c = $Deleted
        }
        $json = ConvertTo-Json $body -Depth 100
        Invoke-SfApi -Path "/sobjects/phecc__Patient__c/$($Patient.sfPatient.Id)" -Method Patch -Body $json | Out-Null
    }
}