Skip to content

Commit

Permalink
clean up the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
laureen committed Feb 7, 2024
1 parent f931d2a commit e0d5c38
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e0d5c38

Please sign in to comment.