Public/Get-CdrPatients.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
<#
    .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
}