Public/New-PatientCalendar.ps1
function New-PatientCalendar { param( [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [PSCustomObject]$Patient ) begin { $metricDefs = Get-MetricDefinitions $measurement = $metricDefs.measurements | Where-Object { $_.Name -eq "Weight" } $metric = $metricDefs.metrics | Where-Object { $_.Name -eq "Body Weight" } $unit = $metricDefs.units | Where-Object { $_.Name -eq "lb" } $cdrId = $Patient.cdrPatient.resource.id $sfId = $Patient.sfPatient.id $message = @{ patient = @{ attributes = @{ type = "Patient__c" url = "/services/data/v49.0/sobjects/Patient__c/$($sfId)" } Id = $sfId CDRPID__c = $cdrId Name = $cdrId Status__c = "Pending - Activation" Unexpected_Observation__c = $false Time_Zone__c = "Eastern Time (America/New_York)" Interventions_Expired__c = $true Language__c = "English" } protocolSubs = @( @{ eId = "1" Patient__c = $sfId Is_Adhoc__c = $true Start_Date__c = "2020-09-16" } ) plannedEntries = @( @{ eId = "2" pEId = "1" Protocol_Subscription__c = $null title = $measurement.Name Is_Template__c = $false Type__c = "Measurement" Measurement_Type__c = $measurement.Id Recurrence_Pattern_Type__c = "Repeat Daily" Until_Date__c = "2020-10-30" Delay__c = 0 modified = "true" Hour__c = 6 Minute__c = 0 } ) interventionRules = @( @{ Is_Template__c = $false eId = "3" pEId = "2" psEId = "1" markedDeleted = $false allowSuppression = $false suppressionIntervalInMinute = 0 allowMultipleIRConditions = $true seqNum = 1 isSuppressIntervalInMinuteInValid = $false Condition_Type__c = "Simple comparison" Sequence_Number__c = 1 Allow_Suppression__c = $false Suppression_Interval_In_Minute__c = 0 Rule_Text__c = "If : ( Body Weight: > 200.0 lb ) Then : ( Flag : Low )" } ) stickyNotes = @() appointments = @() clinicianTasks = @() ruleConditions = @( @{ eId = "4" Intervention_Rule__c = $null Is_Template__c = $false pEId = "3" seqNum = 1 trendThresholdError = $false trendWindowError = $false xValueError = $false yValueError = $false changeOverTimeError = $false movingAverageError = $false baselinePercentageError = $false Sequence_Number__c = 1 Survey_Answer__c = $null Change_Over_Time_Days__c = $null Moving_Average_Days__c = $null Baseline_Percentage__c = $null Trend_Window__c = $null Trend_Threshold__c = $null Metric__c = $metric.Id Unit__c = $unit.Id Low_Value__c = "200" Normalized_Low_Value__c = 90.718474 High_Value__c = $null }) ruleActions = @(@{ eId = "5" Intervention_Rule__c = $null Is_Template__c = $false pEId = "3" seqNum = 1 cTaskDescriptionError = $false cTaskDueDaysError = $false Action__c = "Set a flag" Sequence_Number__c = 1 Flag_Severity_LT__c = "Low" PT_Survey__c = $null PT_Measurement_Type__c = $null CT_Description__c = $null CT_Detail__c = $null CT_AssignedTo__c = $null CT_Due_Days__c = $null CT_Due_Minutes__c = $null } ) deletedProtocolSubs = @() deletedPlannedEntries = @() deletedStickyNotes = @() deletedAppointments = @() skipDates = @() deletedInterventionRules = @() deletedRuleConditions = @() deletedRuleActions = @() deletedClinicianTasks = @() } $calendarJson = ($message | ConvertTo-Json -Depth 100 -Compress) $calendarJson = $calendarJson -Replace """", "\""" Invoke-SfExecuteApex "phecc.DataManager.updateCalendarService('$($calendarJson)');" | Out-Null } } |