Public/New-PatientDeviceNeedsCsv.ps1

<#
    .SYNOPSIS
    Create a new CSV file that contains new patient device needs.
 
    .DESCRIPTION
    The patient device needs
 
    .INPUTS
    None. You cannot pipe objects to New-PatientDeviceNeedsCs.
 
    .OUTPUTS
    The file name if there are new needs or $null.
 
    If created, the CSV file create will contain the following columns:
        FamilyName
        GivenName
        Needs
        DeliveryChannel
        TierOfService
        Preferences
        MRN
        City
        State
        Address
        PostalCode
        District
        Country
        HomePhone
        MobilePhone
        CdrId
 
    .PARAMETER Folder
    The folder to place the needs file.
 
    .LINK
 
    .NOTES
    The file name will be created in yyyy-MM-dd-hhmmss format
#>

function New-PatientDeviceNeedsCsv {
    param([String]$Folder = "./temp", $Def)
    New-Item -ItemType Directory -Force -Path $Folder | Out-Null
    if (-not $PSBoundParameters.ContainsKey('Def')) {
        $Def = Get-MetricDefinitions -CacheFile (Join-Path -Path $Folder -ChildPath "metric-definition-cache.json")
    }
    $File = Join-Path -Path $Folder -ChildPath "$(Get-Date -f 'yyyy-MM-dd-hhmmss').csv"
    $needs = Get-NewPatientDeviceNeeds -Def $Def -Folder $Folder
    if ($needs) {
        Write-Information "Found $($needs.length) new device need(s)"
        $needs | Select-Object -Property FamilyName,GivenName,Needs,DeliveryChannel,TierOfService,Preferences,MRN,City,State,Address,PostalCode,District,Country,HomePhone,MobilePhone,CdrId | Export-Csv -Path $File -NoTypeInformation | Out-Null
        Write-Output $File
    }
}