Public/New-FakePatientParameters.ps1
<# .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() } } } } |