Public/Get-MetricDefinitions.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
<#
    .SYNOPSIS
    Retrieve the metadata from the salesforce org related to measurements, metrics, units, and device models.

    .DESCRIPTION
    This function returns a hastable with the following keys:
        measurements - the contents of the table "phecc__Measurement_Type__c"
        measurementMetrics - the contents of the table "phecc__Measurement_Type_Metric__c"
        metrics - the contents of the table "phecc__Metric__c"
        metricUnits - the contents of the table "phecc__Metric_Unit__c"
        units - the contents of the table "phecc__Unit__c"
        models - the contents of the table "phecc__Device_Model__c"
        capabilities - the contents of the table "phecc__Measurement_Type_Capability__c"

    The multiple queries can 10 seconds or more so the result is cached in a file as specified by the CacheFile parameter.

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

    .OUTPUTS
    An Hashtable with keys contains metadata related to measurements, metrics, units, and device models in the org

    .PARAMETER CacheFile
    An existing cache file to avoid the call if exists. Defaults to "./measurement-metric-cache.json"

    .EXAMPLE
    C:\PS> $def = Get-MetricDefinitions

    .LINK
    Set-Config
    Get-Patients

    .NOTES
    Assumes config is initialized for org access.
#>

function Get-MetricDefinitions {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param()

    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)"
        $def = @{
            measurements       = (Invoke-SfQuery "SELECT Id,Name,phecc__Device_Type_Code__c,phecc__Device_Type__c FROM phecc__Measurement_Type__c")
            measurementMetrics = (Invoke-SfQuery "SELECT Id,phecc__Measurement_Type_Metric_Code__c,phecc__Measurement_Type__c,phecc__Metric__c FROM phecc__Measurement_Type_Metric__c")
            metrics            = (Invoke-SfQuery "SELECT Id,Name,phecc__Metric_Type_Code__c FROM phecc__Metric__c")
            metricUnits        = (Invoke-SfQuery "SELECT Id,phecc__Metric_Unit_Code__c,phecc__Metric__c,phecc__Unit__c FROM phecc__Metric_Unit__c")
            units              = (Invoke-SfQuery "SELECT Id,Name,phecc__Unit_Type_Code__c FROM phecc__Unit__c")
            models             = (Invoke-SfQuery "SELECT Id,Name FROM phecc__Device_Model__c")
            capabilities       = (Invoke-SfQuery "SELECT Id,phecc__Device_Model__c,phecc__Measurement_Type__c FROM phecc__Measurement_Type_Capability__c")
        }
        Write-Output $def
    }
}