@@ -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
6263where 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,
0 commit comments