Skip to content

Commit

Permalink
KH-541: Flattened Analytics locations to include location tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruhanga authored and rbuisson committed May 29, 2024
1 parent f80e952 commit 99f1eaf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 36 deletions.
1 change: 1 addition & 0 deletions analytics/dsl/export/tables/locations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CREATE TABLE locations (
location_id BIGINT,
name VARCHAR,
description VARCHAR,
location_tags VARCHAR,
address1 VARCHAR,
address2 VARCHAR,
city_village VARCHAR,
Expand Down
82 changes: 46 additions & 36 deletions analytics/dsl/flattening/queries/locations.sql
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
SELECT
location_id,
name,
description,
address1,
address2,
city_village,
state_province,
postal_code,
country,
latitude,
longitude,
creator,
date_created,
county_district,
address3,
address4,
address5,
address6,
retired,
retired_by,
date_retired,
retire_reason,
parent_location,
uuid,
changed_by,
date_changed,
address7,
address8,
address9,
address10,
address11,
address12,
address13,
address14,
address15
l.location_id,
l.name,
l.description,
(
SELECT
LISTAGG(l_t.name, ', ')
FROM
location_tag_map l_t_m
JOIN
location_tag l_t ON l_t.location_tag_id = l_t_m.location_tag_id
WHERE
l_t_m.location_id = l.location_id
) AS location_tags,
l.address1,
l.address2,
l.city_village,
l.state_province,
l.postal_code,
l.country,
l.latitude,
l.longitude,
l.creator,
l.date_created,
l.county_district,
l.address3,
l.address4,
l.address5,
l.address6,
l.retired,
l.retired_by,
l.date_retired,
l.retire_reason,
l.parent_location,
l.uuid,
l.changed_by,
l.date_changed,
l.address7,
l.address8,
l.address9,
l.address10,
l.address11,
l.address12,
l.address13,
l.address14,
l.address15
FROM
location
location l
15 changes: 15 additions & 0 deletions analytics/dsl/flattening/tables/openmrs/location_tag.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE `location_tag` (
`location_tag_id` int,
`name` VARCHAR,
`description` VARCHAR,
`creator` int,
`date_created` TIMESTAMP,
`retired` tinyint,
`retired_by` int,
`date_retired` TIMESTAMP,
`retire_reason` VARCHAR,
`uuid` VARCHAR,
`changed_by` int,
`date_changed` TIMESTAMP,
PRIMARY KEY (`location_tag_id`) NOT ENFORCED
)
5 changes: 5 additions & 0 deletions analytics/dsl/flattening/tables/openmrs/location_tag_map.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE `location_tag_map` (
`location_id` int,
`location_tag_id` int,
PRIMARY KEY (`location_id`,`location_tag_id`) NOT ENFORCED
)
1 change: 1 addition & 0 deletions analytics/liquibase/analytics/changelogs/0001-init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
</column>
<column name="name" type="VARCHAR"/>
<column name="description" type="VARCHAR"/>
<column name="location_tags" type="VARCHAR"/>
<column name="address1" type="VARCHAR"/>
<column name="address2" type="VARCHAR"/>
<column name="city_village" type="VARCHAR"/>
Expand Down

0 comments on commit 99f1eaf

Please sign in to comment.