LP#1921057 - Expand reporter.demographic to include detailed age breakdown
authorChris Sharp <csharp@georgialibraries.org>
Tue, 23 Mar 2021 23:03:32 +0000 (19:03 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Thu, 23 Sep 2021 14:31:26 +0000 (10:31 -0400)
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 <csharp@georgialibraries.org>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/reporter-schema.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.reporter-demographic-expansion.sql [new file with mode: 0644]

index 62c5471..227619a 100644 (file)
@@ -10959,6 +10959,7 @@ SELECT  usr,
                        <field reporter:label="User ID" name="id" reporter:datatype="id" />
                        <field reporter:label="Date of Birth" name="dob" reporter:datatype="timestamp"/>
                        <field reporter:label="General Demographic Division" name="general_division" reporter:datatype="text"/>
+                       <field reporter:label="Detailed Age Division" name="age_division" reporter:datatype="text"/>
                </fields>
                <links>
                        <link field="id" reltype="might_have" key="id" map="" class="au"/>
index ec1b6c8..066071f 100644 (file)
@@ -257,16 +257,37 @@ CREATE OR REPLACE VIEW reporter.asset_call_number_dewey AS
   WHERE call_number_dewey(label) ~ '^[0-9]'::text;
 
 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 (file)
index 0000000..6cc62fb
--- /dev/null
@@ -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;