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
 
    .NOTES
    Assumes config is initialized for org access.
    Returns a maximum of 5000 patient resources
#>

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