From 51dad3b8df13ced49ffa6d8f0f1f4e8bd6c8e1ac Mon Sep 17 00:00:00 2001 From: alexiswl <8197659+alexiswl@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:31:24 +1100 Subject: [PATCH] Coerce is_identified to boolean This prevents any 'if' statement issues for string deidentified, which would return true. Resolves #148 --- .../lambda_code.py | 8 +++++++- .../lambda_code.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_defaults_and_launch_validation_workflow/lambda_code.py b/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_defaults_and_launch_validation_workflow/lambda_code.py index df6f153..344cce7 100644 --- a/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_defaults_and_launch_validation_workflow/lambda_code.py +++ b/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_defaults_and_launch_validation_workflow/lambda_code.py @@ -90,10 +90,16 @@ def lambda_handler(event, context): sample_type = VALIDATION_DEFAULTS["sample_type"] # Get is identified - is_identified: str + is_identified: any # Union[str | bool] not supported in python=3.9 if (is_identified := event.get("is_identified", None)) is None: is_identified = VALIDATION_DEFAULTS["is_identified"] + # Coerce is_identified to a boolean value + if isinstance(is_identified, str) and is_identified == 'identified': + is_identified = True + elif isinstance(is_identified, str) and is_identified == 'deidentified': + is_identified = False + # Check disease name if (disease_name := event.get("disease_name", None)) is None: disease_name = VALIDATION_DEFAULTS["disease_name"] diff --git a/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_redcap_and_launch_clinical_workflow/lambda_code.py b/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_redcap_and_launch_clinical_workflow/lambda_code.py index 403f983..d383ed4 100644 --- a/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_redcap_and_launch_clinical_workflow/lambda_code.py +++ b/deploy/cttso-ica-to-pieriandx-cdk/lambdas/get_metadata_from_portal_and_redcap_and_launch_clinical_workflow/lambda_code.py @@ -210,9 +210,16 @@ def lambda_handler(event, context): if (sample_type := event.get("sample_type", None)) is None: sample_type = CLINICAL_DEFAULTS["sample_type"].name.lower() + is_identified: any # Union[str | bool] not supported in python=3.9 if (is_identified := event.get("is_identified", None)) is None: is_identified = CLINICAL_DEFAULTS["is_identified"].name.lower() + # Coerce is_identified to a boolean value + if isinstance(is_identified, str) and is_identified == 'identified': + is_identified = True + elif isinstance(is_identified, str) and is_identified == 'deidentified': + is_identified = False + # Set panel type (if not null) merged_df["panel_type"] = panel_type merged_df["sample_type"] = sample_type