Public/Get-MetricDefinitions.ps1

<#
    .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
    }
}