From: Chris Sharp Date: Tue, 23 Mar 2021 23:03:32 +0000 (-0400) Subject: LP#1921057 - Expand reporter.demographic to include detailed age breakdown X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3117f61a8811c64f44736d7db6766183c96f4e12;p=working%2FEvergreen.git LP#1921057 - Expand reporter.demographic to include detailed age breakdown Add "age_division" column to reporter.demographic. Expose the new column to the reporter as "Detailed Age Division" resulting in the following options: Child 0-5 Years Old Child 6-12 Years Old Teen 13-17 Years Old Adult 18-25 Years Old Adult 50-59 Years Old Adult 50-59 Years Old Adult 60-69 Years Old Adult 70+ If no DOB is present, say so. Signed-off-by: Chris Sharp --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 0cf9ec03e5..cca16fa6ef 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -10789,6 +10789,7 @@ SELECT usr, + diff --git a/Open-ILS/src/sql/Pg/reporter-schema.sql b/Open-ILS/src/sql/Pg/reporter-schema.sql index 68b7cfcb5e..d2cb83d0af 100644 --- a/Open-ILS/src/sql/Pg/reporter-schema.sql +++ b/Open-ILS/src/sql/Pg/reporter-schema.sql @@ -233,16 +233,37 @@ CREATE OR REPLACE FUNCTION reporter.refresh_materialized_simple_record () RETURN $$ LANGUAGE SQL; CREATE OR REPLACE VIEW reporter.demographic AS -SELECT u.id, - u.dob, - CASE - WHEN u.dob IS NULL - THEN 'Adult' - WHEN AGE(u.dob) > '18 years'::INTERVAL - THEN 'Adult' - ELSE 'Juvenile' - END AS general_division - FROM actor.usr u; +SELECT u.id, + u.dob, + CASE + WHEN u.dob IS NULL + THEN 'Adult' + WHEN AGE(u.dob) > '18 years'::INTERVAL + THEN 'Adult' + ELSE 'Juvenile' + END AS general_division, + CASE + WHEN u.dob IS NULL + THEN 'No Date of Birth Entered'::text + WHEN age(u.dob::timestamp with time zone) >= '0 years'::interval and age(u.dob::timestamp with time zone) < '6 years'::interval + THEN 'Child 0-5 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '6 years'::interval and age(u.dob::timestamp with time zone) < '13 years'::interval + THEN 'Child 6-12 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '13 years'::interval and age(u.dob::timestamp with time zone) < '18 years'::interval + THEN 'Teen 13-17 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '18 years'::interval and age(u.dob::timestamp with time zone) < '26 years'::interval + THEN 'Adult 18-25 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '26 years'::interval and age(u.dob::timestamp with time zone) < '50 years'::interval + THEN 'Adult 26-49 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '50 years'::interval and age(u.dob::timestamp with time zone) < '60 years'::interval + THEN 'Adult 50-59 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '60 years'::interval and age(u.dob::timestamp with time zone) < '70 years'::interval + THEN 'Adult 60-69 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '70 years'::interval + THEN 'Adult 70+'::text + ELSE NULL::text + END AS age_division + FROM actor.usr u; CREATE OR REPLACE VIEW reporter.circ_type AS SELECT id, diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql new file mode 100644 index 0000000000..6cc62fb3d0 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql @@ -0,0 +1,38 @@ +BEGIN; + +-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +CREATE OR REPLACE VIEW reporter.demographic AS +SELECT u.id, + u.dob, + CASE + WHEN u.dob IS NULL + THEN 'Adult' + WHEN AGE(u.dob) > '18 years'::INTERVAL + THEN 'Adult' + ELSE 'Juvenile' + END AS general_division, + CASE + WHEN u.dob IS NULL + THEN 'No Date of Birth Entered'::text + WHEN age(u.dob::timestamp with time zone) >= '0 years'::interval and age(u.dob::timestamp with time zone) < '6 years'::interval + THEN 'Child 0-5 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '6 years'::interval and age(u.dob::timestamp with time zone) < '13 years'::interval + THEN 'Child 6-12 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '13 years'::interval and age(u.dob::timestamp with time zone) < '18 years'::interval + THEN 'Teen 13-17 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '18 years'::interval and age(u.dob::timestamp with time zone) < '26 years'::interval + THEN 'Adult 18-25 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '26 years'::interval and age(u.dob::timestamp with time zone) < '50 years'::interval + THEN 'Adult 26-49 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '50 years'::interval and age(u.dob::timestamp with time zone) < '60 years'::interval + THEN 'Adult 50-59 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '60 years'::interval and age(u.dob::timestamp with time zone) < '70 years'::interval + THEN 'Adult 60-69 Years Old'::text + WHEN age(u.dob::timestamp with time zone) >= '70 years'::interval + THEN 'Adult 70+'::text + ELSE NULL::text + END AS age_division + FROM actor.usr u; + +COMMIT;