Public/New-Observation.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<#
    .SYNOPSIS
    Creates an observation object.

    .DESCRIPTION
    Creates the observation portion of the JSON message in hashtable form to send to the eCC Salesforce API to accept measurements

    .INPUTS
    None. You cannot pipe objects to New-Observation.

    .OUTPUTS
    PSCustomObject that contains the observation data

    .PARAMETER PatientId
    The salesforce Patient__c object Id

    .PARAMETER DateTime
    Datetime of the measurements

    .PARAMETER DeviceType
    The device type

    .PARAMETER DeviceId
    The device id

    .PARAMETER Gateway
    The gatway name

    .PARAMETER GatewayDeviceId
    The gatway device id

    .PARAMETER ExternalObsId
    An external observation id
#>

function New-Observation {

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        [String]
        $PatientId,

        [Parameter(Mandatory = $true, Position = 1)]
        [System.DateTime]
        $DateTime,

        [Parameter(Mandatory = $true, Position = 2)]
        [ValidateNotNullOrEmpty()]
        [String]
        $DeviceType,

        [Parameter(Mandatory = $true, Position = 3)]
        [ValidateNotNullOrEmpty()]
        [String]$DeviceId,

        [Parameter(Mandatory = $true, Position = 4)]
        [ValidateNotNullOrEmpty()]
        [String]$Gateway,

        [Parameter(Mandatory = $true, Position = 5)]
        [ValidateNotNullOrEmpty()]
        [String]$GatewayDeviceId,

        [Parameter(Mandatory = $true, Position = 6)]
        [ValidateNotNullOrEmpty()]
        [String]$ExternalObsId
    )
    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)"
        @{
            "attributes"                    = @{
                "type" = "Observation__c"
            }
            "External_Observation_ID__c"    = $ExternalObsId
            "Patient_ID__c"                 = $PatientId
            "Patient__c"                    = $PatientId
            "Assigning_Authority__c"        = "eCareCoordinator"
            "Device_ID__c"                  = $DeviceId
            "Device_Type__c"                = $DeviceType
            "Observation_Date_Time__c"      = ("{0:o}" -f $DateTime) -replace "00.0000000", "00"
            "Sending_Application__c"        = "PwshDataTool"
            "Measurement_Device_Gateway__c" = $Gateway
            "Gateway_Device_ID__c"          = $GatewayDeviceId
            "Device_Message__c"             = "msg-here"
        }
    }
}