From e0d5c38f344aafd1b4f8ca99649e80113ac62fcf Mon Sep 17 00:00:00 2001 From: laureen Date: Wed, 7 Feb 2024 14:37:44 +0300 Subject: [PATCH] clean up the functions --- .../functions/fn_mamba_calculate_agegroup.sql | 30 +++++++++---------- .../fn_mamba_get_datatype_for_concept.sql | 12 ++++---- .../fn_mamba_get_obs_value_column.sql | 8 ++--- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/api/src/main/resources/_core/database/mysql/functions/fn_mamba_calculate_agegroup.sql b/api/src/main/resources/_core/database/mysql/functions/fn_mamba_calculate_agegroup.sql index b8ce6b82..ec9c9cf6 100644 --- a/api/src/main/resources/_core/database/mysql/functions/fn_mamba_calculate_agegroup.sql +++ b/api/src/main/resources/_core/database/mysql/functions/fn_mamba_calculate_agegroup.sql @@ -6,22 +6,22 @@ CREATE FUNCTION fn_mamba_calculate_agegroup(age INT) RETURNS VARCHAR(15) DETERMINISTIC BEGIN DECLARE agegroup VARCHAR(15); - CASE + CASE age WHEN age < 1 THEN agegroup = '<1'; - WHEN age between 1 and 4 THEN agegroup = '1-4'; - WHEN age between 5 and 9 THEN agegroup = '5-9'; - WHEN age between 10 and 14 THEN agegroup = '10-14'; - WHEN age between 15 and 19 THEN agegroup = '15-19'; - WHEN age between 20 and 24 THEN agegroup = '20-24'; - WHEN age between 25 and 29 THEN agegroup = '25-29'; - WHEN age between 30 and 34 THEN agegroup = '30-34'; - WHEN age between 35 and 39 THEN agegroup = '35-39'; - WHEN age between 40 and 44 THEN agegroup = '40-44'; - WHEN age between 45 and 49 THEN agegroup = '45-49'; - WHEN age between 50 and 54 THEN agegroup = '50-54'; - WHEN age between 55 and 59 THEN agegroup = '55-59'; - WHEN age between 60 and 64 THEN agegroup = '60-64'; - WHEN agegroup = '65+'; + WHEN age between 1 and 4 THEN SET agegroup = '1-4'; + WHEN age between 5 and 9 THEN SET agegroup = '5-9'; + WHEN age between 10 and 14 THEN SET agegroup = '10-14'; + WHEN age between 15 and 19 THEN SET agegroup = '15-19'; + WHEN age between 20 and 24 THEN SET agegroup = '20-24'; + WHEN age between 25 and 29 THEN SET agegroup = '25-29'; + WHEN age between 30 and 34 THEN SET agegroup = '30-34'; + WHEN age between 35 and 39 THEN SET agegroup = '35-39'; + WHEN age between 40 and 44 THEN SET agegroup = '40-44'; + WHEN age between 45 and 49 THEN SET agegroup = '45-49'; + WHEN age between 50 and 54 THEN SET agegroup = '50-54'; + WHEN age between 55 and 59 THEN SET agegroup = '55-59'; + WHEN age between 60 and 64 THEN SET agegroup = '60-64'; + ELSE SET agegroup = '65+'; END CASE; RETURN agegroup; diff --git a/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_datatype_for_concept.sql b/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_datatype_for_concept.sql index 87e7ac62..0dca9c43 100644 --- a/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_datatype_for_concept.sql +++ b/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_datatype_for_concept.sql @@ -8,13 +8,11 @@ BEGIN DECLARE mysqlDatatype VARCHAR(20); CASE conceptDatatype - WHEN conceptDatatype = 'Coded' THEN mysqlDatatype = 'TEXT'; - WHEN conceptDatatype = 'N/A' THEN mysqlDatatype = 'TEXT'; - WHEN conceptDatatype = 'Text' THEN mysqlDatatype = 'TEXT'; - WHEN conceptDatatype = 'Boolean' THEN mysqlDatatype = 'VARCHAR(50)'; - WHEN conceptDatatype = 'Date' THEN mysqlDatatype = 'DATE'; - WHEN conceptDatatype = 'Datetime' THEN mysqlDatatype = 'DATETIME'; - WHEN conceptDatatype = 'Numeric' THEN mysqlDatatype = 'DOUBLE'; + WHEN conceptDatatype IN ('Coded','N/A','Text') THEN SET mysqlDatatype = 'TEXT'; + WHEN conceptDatatype = 'Boolean' THEN SET mysqlDatatype = 'VARCHAR(50)'; + WHEN conceptDatatype = 'Date' THEN SET mysqlDatatype = 'DATE'; + WHEN conceptDatatype = 'Datetime' THEN SET mysqlDatatype = 'DATETIME'; + WHEN conceptDatatype = 'Numeric' THEN SET mysqlDatatype = 'DOUBLE'; END CASE; RETURN mysqlDatatype; diff --git a/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_obs_value_column.sql b/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_obs_value_column.sql index 2d87ac68..76cdb35e 100644 --- a/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_obs_value_column.sql +++ b/api/src/main/resources/_core/database/mysql/functions/fn_mamba_get_obs_value_column.sql @@ -7,10 +7,10 @@ CREATE FUNCTION fn_mamba_get_obs_value_column(conceptDatatype VARCHAR(20)) RETUR BEGIN DECLARE obsValueColumn VARCHAR(20); - CASE - WHEN conceptDatatype IN ('Text','Coded','N/A','Boolean') THEN obsValueColumn = 'obs_value_text'; - WHEN conceptDatatype IN ('Date','Datetime') THEN obsValueColumn = 'obs_value_datetime'; - WHEN conceptDatatype = 'Numeric' THEN obsValueColumn = 'obs_value_numeric'; + CASE conceptDatatype + WHEN conceptDatatype IN ('Text','Coded','N/A','Boolean') THEN SET obsValueColumn = 'obs_value_text'; + WHEN conceptDatatype IN ('Date','Datetime') THEN SET obsValueColumn = 'obs_value_datetime'; + WHEN conceptDatatype = 'Numeric' THEN SET obsValueColumn = 'obs_value_numeric'; END CASE; RETURN obsValueColumn;