Public/Get-CdrPatients.ps1

<#
    .SYNOPSIS
    Fetchs patient FHIR resources from the CDR/PDS for a supplied list of CDR ids.

    .DESCRIPTION

    .INPUTS
    None. You cannot pipe objects to Get-CdrPatients.

    .OUTPUTS
    The response from the POST to /Patient/_search to the CDR/PDS endpoint configured in the salesforce org

    .PARAMETER Ids
    An array of patient resource ids

    .EXAMPLE
    C:\PS> $result = Get-CdrPatients -Ids @("5b135c52-f603-4044-a49f-2f56967c4449", "5555c808-c186-48ab-a6c0-a8aedbfad852")

    .LINK
    Set-Config

    .NOTES
    Assumes config is initialized for org access.
    Returns a maximum of 10000 patient resources
#>

function Get-CdrPatients {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline)]
        [String[]]
        $Ids
    )

    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)"

        $fhirUrl = "$((Get-SfConfig).phecc__FHIRURL__c)/Patient/_search"
        $headers = @{
            "Connection"    = "keep-alive"
            "api-version"   = "2"
            "Authorization" = "Bearer $($script:__iamAuth.access_token)"
            "Content-Type"  = "application/x-www-form-urlencoded; charset=UTF-8"
        }
        $idList = $Ids -join ","
        $body = "_id=$($idList)&_count=10000"
        Invoke-RestMethod -Uri $fhirUrl -Method Post -Headers $headers -Body $body
    }
}