Public/Set-PatientStatus.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
58
<#
    .SYNOPSIS
    Sets the patient status.

    .DESCRIPTION
    Sets a patient status.

    .INPUTS
    A PSCustomObject that is the patient.

    .INPUTS
    None

    .OUTPUTS
    None.

    .PARAMETER Patient
    The Patient PSCustomObject.

    .PARAMETER Status
    The status to set on the Patient

    .NOTES
    You must ensure that a calendar exists if the status is anything other than 'Pending - Activation'

    .LINK
    Get-Patients
#>

function Set-PatientStatus {

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

        [Parameter(Mandatory, Position = 1)]
        [ValidateSet("Pending - Activation", "Active", "Suspended", "Pending - Removal", "Removed")]
        [String]
        $Status
    )
    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)"
        $body = [PSCustomObject]@{ phecc__Status__c = $Status }
        $json = ConvertTo-Json $body -Depth 100
        Invoke-SfApi -Path "/sobjects/phecc__Patient__c/$($Patient.sfPatient.Id)" -Method Patch -Body $json | Out-Null
    }
}