Public/New-PatientDeviceNeedsCsv.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
<#
    .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
    }
}