Public/New-FakePatients.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
59
60
61
62
63
64
65
66
67
68
69
70
71
<#
    .SYNOPSIS
    Creates fake patients in eCC with option to activate the patients.

    .DESCRIPTION
    Creates fake patients in eCC with option to activate the patients.

    .INPUTS
    The number of patients to create

    .OUTPUTS
    An array of PSCustomObjects that represent the patients

    .PARAMETER Count
    The number of hashtables to generate. Defaults to 1 if not specified

    .PARAMETER Status
    The status to set the patient.

    .EXAMPLE
    PS> $Patients = New-FakePatients -Count 2

    .LINK
    New-Patient
    New-PatientCalendar
    Set-PatientStatus

    .NOTES
    If the status is anything other then 'Pending - Activation' then the patient will have measurements
    added to the calendar and then the patient will be set to status='Active'. If the status is anything
    other than 'Active' then the status will be set.
#>

function New-FakePatients {
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline)]
        [int]$Count,

        [ValidateSet("Pending - Activation", "Active", "Suspended", "Pending - Removal", "Removed")]
        $Status = "Pending - Activation"
    )

    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('Count')) {
            $Count = 1
        }

        New-FakePatientParameters -Count $Count | ForEach-Object {
            $Patient = New-Patient @_
            if ($Status -ne "Pending - Activation") {
                New-PatientCalendar -Patient $Patient | Out-Null
                Set-PatientStatus -Patient $Patient -Status "Active" | Out-Null
                if ($Status -ne "Active") {
                    Set-PatientStatus -Patient $Patient -Status  $Status | Out-Null
                }
                $Patient = [PSCustomObject](Get-Patients -sfid $Patient.sfPatient.Id | Select-Object -First 1)
            }
            Write-Output $Patient
        }
    }
}