Public/New-FakePatientParameters.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
72
73
74
75
<#
    .SYNOPSIS
    Generates an array of hashtables that represents a fake patient fields

    .DESCRIPTION
    The hashtable maybe used to splat parameters to the New-Patient cmdlet

    .INPUTS
    The number of hashtables to create

    .OUTPUTS
    An array of hashtables

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

    .EXAMPLE
    PS> $params = New-FakePatientParameters

    .LINK
    New-Patient

    .NOTES
    Uses the URL https://api.namefake.com/. This API endpoint can sometime timeout. It maybe rate limiting.
#>

function New-FakePatientParameters {
    [OutputType([HashTable[]])]
    param(
        [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline)]
        [int]$Count
    )
    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
        }

        For ($i = 0; $i -lt $Count; $i++) {
            $gender = @("male", "female") | Select-Object -skip (get-random -Min 0 -Max 2) -first 1
            $p = Invoke-RestMethod -Uri https://api.namefake.com/$($gender)
            $nameParts = $p.name.split(" ")
            if ($nameParts.length -gt 2) {
                if ($nameParts[0] -like "*.") {
                    $given = $p.name.split(" ")[1]
                    $family = $p.name.split(" ")[2]
                }
                else {
                    $given = $p.name.split(" ")[0]
                    $family = $p.name.split(" ")[1]
                }
            }
            elseif ($nameParts.length -eq 2) {
                $given = $p.name.split(" ")[0]
                $family = $p.name.split(" ")[1]
            }
            [HashTable]@{
                GivenName  = $given
                FamilyName = $family
                BirthDate  = [datetime]::ParseExact($p.birth_data, 'yyyy-MM-dd', $null)
                Gender     = $gender
                EMRPID     = (new-guid).ToString()
                MRN        = (new-guid).ToString()
            }
        }
    }
}