From 81e5fb2d1ed324eda897060702b87b544c8d31d5 Mon Sep 17 00:00:00 2001 From: "Bella L. Quintero" <96704946+pluckyswan@users.noreply.github.com> Date: Mon, 23 Sep 2024 09:39:36 -0600 Subject: [PATCH] Updated RS Hurl Script to Replace MSH Header When Not Toggled (#1342) * Updating hurl scripts * Fixed typo in readme, create temp folder, write scrambled file into temp folder * Fixed directory creation, resolved issue with sed command not copying rest of file * updated readme to include toggle in options, add comments to scramble doing, alerted user to scrambling, removed folder creation for individual file * replaced msh header for oru and orm message types * added msh header replacement for oml message type * switched to msh-9.2 as subfield in conditional * remove temp directory after hurl script runs --------- Co-authored-by: jcrichlake Co-authored-by: Sylvie Co-authored-by: jcrichlake <145698165+jcrichlake@users.noreply.github.com> Co-authored-by: saquino0827 --- .gitignore | 2 +- scripts/hurl/rs/hrl | 37 ++++++++++++++++++++++++++++++++++++- scripts/hurl/rs/readme.md | 5 +++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 01c7fe4a6..29797a0a2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,4 @@ __pycache__ localfileorder.json -logback.log +logback.log \ No newline at end of file diff --git a/scripts/hurl/rs/hrl b/scripts/hurl/rs/hrl index 49b4ca8f6..7b07b4ef1 100755 --- a/scripts/hurl/rs/hrl +++ b/scripts/hurl/rs/hrl @@ -14,6 +14,8 @@ client_id=flexion client_sender=simulated-hospital verbose="" submission_id="" +allow_outbound=false +msh_header_replacement="" show_help() { echo "Usage: $(basename $0) [OPTIONS]" @@ -29,6 +31,7 @@ show_help() { echo " -i The submissionId to call the history API with (Required for history API)" echo " -v Verbose mode" echo " -h Display this help and exit" + echo " -p By default, the MSH segment is replaced to contain a Flexion receiver in order to avoid sending messages to partners inadvertently. When using this flag, the MSH segment will not be replaced" } # Check if required HURL_FILE is provided @@ -47,7 +50,7 @@ fi hurl_file="$1" # Assign the first argument to hurl_file shift # Remove the first argument from the list of arguments -while getopts ':f:r:t:e:c:s:x:i:vh' opt; do +while getopts ':f:r:t:e:c:s:x:i:vh:p' opt; do case "$opt" in f) fpath="$OPTARG" @@ -80,6 +83,9 @@ while getopts ':f:r:t:e:c:s:x:i:vh' opt; do show_help exit 0 ;; + p) + allow_outbound=true + ;; :) echo -e "Option requires an argument" show_help @@ -114,6 +120,30 @@ if [ -z "$secret" ]; then exit 1 fi +if [ "$allow_outbound" = false ]; then +# Grab MSH Header + msh_header=$(head -n1 "$CDCTI_HOME/$fpath") +# Check message type + if [[ "$msh_header" = *"^R01"* ]]; then + msh_header_replacement="MSH|^~\&|Sender Application^sender.test.com^DNS|Sender Facility^0.0.0.0.0.0.0.0^ISO|Receiver Application^0.0.0.0.0.0.0.0^ISO|Receiver Facility^simulated-hospital-id^DNS|20230101010000-0000||ORU^R01^ORU_R01|111111|T|2.5.1||||||||||" + elif [[ "$msh_header" = *"^O01"* ]]; then + msh_header_replacement="MSH|^~\&|Sender Application^sender.test.com^DNS|Sender Facility^0.0.0.0.0.0.0.0^ISO|Receiver Application^0.0.0.0.0.0.0.0^ISO|Receiver Facility^simulated-lab-id^DNS|20230101010000-0000||ORM^O01^ORM_O01|111111|T|2.5.1||||||||||" + elif [[ "$msh_header" = *"^O21"* ]]; then + msh_header_replacement="MSH|^~\&|Sender Application^sender.test.com^DNS|Sender Facility^0.0.0.0.0.0.0.0^ISO|Receiver Application^0.0.0.0.0.0.0.0^ISO|Receiver Facility^simulated-lab-id^DNS|20230101010000-0000||OML^O21^OML_O21|111111|T|2.5.1||||||||||" + else + echo "File does not contain valid message type (MSH-9) values." + exit 1 + fi + file_path=$(dirname "$fpath") + substitutedFilePathPrefix="$CDCTI_HOME/substituted_header" +# Make temporary directory to store scrambled file + mkdir -p "$substitutedFilePathPrefix/$file_path" && touch -f "$substitutedFilePathPrefix/$fpath" +# Replace MSH Header and write into temporary directory + sed "1s/.*/$msh_header_replacement/" "$CDCTI_HOME/$fpath" > "$substitutedFilePathPrefix/$fpath" + fpath=$substitutedFilePathPrefix/$fpath + echo "By default, the MSH segment is replaced to contain a Flexion receiver in order to avoid sending messages to partners inadvertently. To toggle this, run with -p." +fi + hurl \ --variable fpath=$fpath \ --file-root $root \ @@ -126,3 +156,8 @@ hurl \ $verbose \ $hurl_file \ $@ + +# Remove temporary directory +if [ "$allow_outbound" = false ]; then + rm -r "$substitutedFilePathPrefix" +fi \ No newline at end of file diff --git a/scripts/hurl/rs/readme.md b/scripts/hurl/rs/readme.md index 296245194..d81f835ec 100644 --- a/scripts/hurl/rs/readme.md +++ b/scripts/hurl/rs/readme.md @@ -16,6 +16,7 @@ Options: -i The submissionId to call the history API with (Required for history API) -v Verbose mode -h Display this help and exit + -p By default, the MSH segment is replaced to contain a Flexion receiver in order to avoid sending messages to partners inadvertently. When using this flag, the MSH segment will not be replaced ``` ## Examples @@ -35,12 +36,12 @@ Sending an order to staging ./hrl waters.hurl -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 -e staging -x /path/to/staging/private/key ``` -Checking the history in local environment for a submision id +Checking the history in local environment for a submission id ``` ./hrl history.hurl -i 100 ``` -Checking the history in staging for a submision id +Checking the history in staging for a submission id ``` ./hrl history.hurl -i 100 -e staging -x /path/to/staging/private/key ```