diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f0e514..9a6fe7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,4 +33,10 @@ ## [1.2.6] - 2024-10-04 ## Changed - Added JSON Parsing. -- Added fix for piping into filterLogic being messed up. See README. \ No newline at end of file +- Added fix for piping into filterLogic being messed up. See README. + +## [1.3.0] - 2025-01-21 +## Changed +- Added a descriptive label in the configuration so you can keep up with your triggers better. +- Added the ability to convert MDY days to YMD for REDCap importing. +- Added the ability to insert escaping for quotes. \ No newline at end of file diff --git a/ConditionalAPITriggerModule.php b/ConditionalAPITriggerModule.php index 270ce3b..970abcf 100644 --- a/ConditionalAPITriggerModule.php +++ b/ConditionalAPITriggerModule.php @@ -54,6 +54,8 @@ public function redcap_save_record($project_id, $record, $instrument, $event_id, // create the url $url = Piping::replaceVariablesInLabel($apiUrls[$i], $record, $event_id, $repeat_instance, $recordData, false, $project_id, false); + // not sure why we'd ever want to have dates in the url but I'm CMA here + $url = $this->replaceYMD($url); $method = $apiMethods[$i]; @@ -63,6 +65,8 @@ public function redcap_save_record($project_id, $record, $instrument, $event_id, curl_setopt($conn, CURLOPT_RETURNTRANSFER, true); if ($apiData[$i] != "") { $formData = Piping::replaceVariablesInLabel($apiData[$i], $record, $event_id, $repeat_instance, $recordData, false, $project_id, false); + $formData = $this->replaceYMD($formData); + $formData = $this->replaceSlashes($formData); if ($sanitizeBrackets[$i] == '1') { // replace {{ and }} with [ and ] $formData = str_replace('{{', '[', $formData); @@ -78,6 +82,8 @@ public function redcap_save_record($project_id, $record, $instrument, $event_id, $headerArr = array(); if ($apiHeaders[$i] != "") { $headers = Piping::replaceVariablesInLabel($apiHeaders[$i], $record, $event_id, $repeat_instance, $recordData, false, $project_id, false); + $headers = $this->replaceYMD($headers); + $headers = $this->replaceSlashes($headers); if ($sanitizeBrackets[$i] == '1') { // replace {{ and }} with [ and ] $headers = str_replace('{{', '[', $headers); @@ -132,6 +138,41 @@ public function redcap_save_record($project_id, $record, $instrument, $event_id, } } + // looks for convertMDYtoYMD() and converts the containing data to that date + private function replaceYMD($formData) + { + $begin = strpos($formData, "convertMDYtoYMD("); + if ($begin === false) + { + return $formData; + } + else + { + $end = strpos($formData, ")", $begin); + $toconvert = substr($formData, $begin + 16, $end - ($begin+16)); + $date = date_create_from_format("m-d-Y", $toconvert); + $date = date_format($date, "Y-m-d"); + return $this->replaceYMD(substr_replace($formData, $date, $begin, ($end - $begin + 1))); + } + } + + // looks for addSlashes<<<>>> and adds slashes to the containing data. Not using () to keep from mucking things up when parenthesis appears in the code + private function replaceSlashes($formData) + { + $begin = strpos($formData, "addSlashes<<<"); + if ($begin === false) + { + return $formData; + } + else + { + $end = strpos($formData, ">>>", $begin); + $toconvert = substr($formData, $begin + 13, $end - ($begin+13)); + $toconvert = addslashes($toconvert); + return $this->replaceSlashes(substr_replace($formData, $toconvert, $begin, ($end - $begin + 3))); + } + } + private function parseResponse($response, $jsonParsing, $jsonKey, $jsonIsArray, $jsonArrayIndex) { if ($jsonParsing == '1') { diff --git a/README.md b/README.md index 80b4764..742f00a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A REDCap module that executes an API call (to any API) when a certain condition ## How to use You can define multiple triggers in **Project Settings**. For each trigger, define: +- **Label** - This is a label so you can describe what the trigger does. - **Instrument** (required)- This is the instrument that the trigger will fire upon saving. - **Condition** (required)- This is the condition (in addition to the above instrument being saved) that will cause the trigger to fire. This field should evaluate to true/false. - **API URL** (required)- This is full API URL of the API request. You can pipe variables and smart tags in here. @@ -46,4 +47,10 @@ This example imports a value into another REDCap project. **API Data** `token=ABC123FAKETOKENFAKETOKEN;content=record;action=import;format=json;type=flat;overwriteBehavior=normal;forceAutoNumber=false;data=[{"record_id":"[record_id]","redcap_event_name":"event_1_arm_1","otherconsentvariable":"[consent_yn]"}];returnContent=ids;returnFormat=json` **Separate Post Data** `Checked` **Data Item Separator** `;` -**Data Value Separator** `=` \ No newline at end of file +**Data Value Separator** `=` + +## Date Conversion +In order to convert anything in the **API Data** or **API Header** from MM-DD-YYYY to YYYY-MM-DDDD, wrap the piped in variable in `convertMDYtoYMD()`. This function call will be removed when the data is actually sent to the API. + +## Add Slashes +If you have quotes in your data, this can mess up the API call if the data is being placed into JSON. If this is the case, wrap the piped in variable in `addSlashes<<< >>>` (I use triple angle brackets because it's possible that the data will have parenthesis.) This will escape the quotation marks so they shouldn't cause issues. \ No newline at end of file diff --git a/config.json b/config.json index 38751e4..4d43bf8 100644 --- a/config.json +++ b/config.json @@ -20,6 +20,11 @@ "type": "sub_settings", "repeatable": true, "sub_settings" : [ + { + "key": "label", + "name": "Label", + "type": "text" + }, { "key": "instrument", "name": "Instrument",