Skip to content

Commit 981cf53

Browse files
committed
avniproject/avni-server#866 | use disabled_in_cognito and last_activated_date_time info to filter out users to nudge
1 parent 43064f5 commit 981cf53

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

rwb/src/main/resources/custom_query_insert.sql

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
66
join user_group ug on u.id = ug.user_id and ug.is_voided = false
77
join groups g on g.id = ug.group_id and g.is_voided = false
88
where g.name = ''Primary Users''
9-
and u.is_voided = false
9+
and u.disabled_in_cognito = false
10+
and u.last_activated_date_time is null OR u.last_activated_date_time < now() - INTERVAL ''3 DAYS''
11+
and u.is_voided = false
1012
),
11-
work_orders as (
13+
work_orders as (
1214
select i.id wo_id, i.address_id, organisation_id
1315
from individual i
1416
where i.is_voided = false
@@ -18,7 +20,7 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
1820
and organisation_id = (select id from organisation where db_user = :org_db_user)
1921
and not subject_type.is_voided)
2022
),
21-
closed_work_orders as (select wo.wo_id, wo.address_id
23+
closed_work_orders as (select wo.wo_id, wo.address_id
2224
from work_orders wo
2325
join encounter e on wo.wo_id = e.individual_id
2426
where e.encounter_type_id =
@@ -28,21 +30,21 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
2830
and organisation_id = (select id from organisation where db_user = :org_db_user)
2931
and not encounter_type.is_voided)
3032
and (e.is_voided is null or e.is_voided = false)
31-
and wo.organisation_id = :org_id
33+
and wo.organisation_id = (select id from organisation where db_user = :org_db_user)
3234
group by 1, 2
3335
having count(e.id) = 1),
34-
catchments_without_work_orders_or_atleast_one_open_work_order as (
36+
catchments_without_work_orders_or_atleast_one_open_work_order as (
3537
select c.id
3638
from catchment c
3739
join virtual_catchment_address_mapping_table cam on cam.catchment_id = c.id
3840
left join work_orders wo on wo.address_id = cam.addresslevel_id
39-
left join closed_work_orders cwo on cwo.address_id = cam.addresslevel_id
41+
left join closed_work_orders cwo on cwo.wo_id = wo.wo_id
4042
where c.is_voided = false
4143
group by 1
4244
having count(wo.wo_id) = null
43-
OR count(wo.wo_id) > count(cwo.wo_id)
45+
OR count( wo.wo_id) > count( cwo.wo_id)
4446
),
45-
active_user_ids as (select (case
47+
active_user_ids as (select (case
4648
when ind.created_date_time > TO_TIMESTAMP(:cutOffDate, ''YYYY-MM-DDTHH24:MI:ss.MS'')
4749
then ind.created_by_id end) as cuid,
4850
ind.last_modified_by_id as muid
@@ -56,13 +58,12 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
5658
from encounter enc
5759
where enc.last_modified_date_time > TO_TIMESTAMP(:cutOffDate, ''YYYY-MM-DDTHH24:MI:ss.MS'')
5860
order by 1 asc)
59-
select distinct user_id, first_name
60-
from primary_users pu
61+
select distinct user_id, first_name from primary_users pu
6162
join catchments_without_work_orders_or_atleast_one_open_work_order cat on pu.catchment_id = cat.id
6263
where user_id not in (select cuid
63-
from active_user_ids
64-
union
65-
select muid
64+
from active_user_ids
65+
union
66+
select muid
6667
from active_user_ids);',
6768
:org_id,
6869
false,

rwb/src/main/resources/select_inactive_users_id.sql

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ WITH primary_users as (
44
join user_group ug on u.id = ug.user_id and ug.is_voided = false
55
join groups g on g.id = ug.group_id and g.is_voided = false
66
where g.name = 'Primary Users'
7-
and u.is_voided = false
7+
and u.disabled_in_cognito = false
8+
and u.last_activated_date_time is null OR u.last_activated_date_time < now() - INTERVAL '3 DAYS'
9+
and u.is_voided = false
810
),
911
work_orders as (
1012
select i.id wo_id, i.address_id, organisation_id
@@ -20,10 +22,10 @@ WITH primary_users as (
2022
from work_orders wo
2123
join encounter e on wo.wo_id = e.individual_id
2224
where e.encounter_type_id =
23-
(select id
24-
from encounter_type
25-
where name = 'Work order endline'
26-
and organisation_id = (select id from organisation where db_user = :org_db_user)
25+
(select id
26+
from encounter_type
27+
where name = 'Work order endline'
28+
and organisation_id = (select id from organisation where db_user = :org_db_user)
2729
and not encounter_type.is_voided)
2830
and (e.is_voided is null or e.is_voided = false)
2931
and wo.organisation_id = (select id from organisation where db_user = :org_db_user)
@@ -57,8 +59,8 @@ WITH primary_users as (
5759
select distinct user_id, first_name
5860
from primary_users pu
5961
join catchments_without_work_orders_or_atleast_one_open_work_order cat on pu.catchment_id = cat.id
60-
where user_id not in (select cuid
61-
from active_user_ids
62-
union
63-
select muid
64-
from active_user_ids);
62+
where user_id in (select cuid
63+
from active_user_ids
64+
union
65+
select muid
66+
from active_user_ids);

0 commit comments

Comments
 (0)