Skip to content

Commit 24b1c3b

Browse files
committed
avniproject/avni-server#866 | Update custom Query Insert sql
1 parent 3a5dbef commit 24b1c3b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

rwb/src/main/resources/custom_query_insert.sql

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
1010
and u.last_activated_date_time is null OR u.last_activated_date_time < now() - INTERVAL ''3 DAYS''
1111
and u.is_voided = false
1212
),
13-
work_orders as (
13+
work_orders as (
1414
select i.id wo_id, i.address_id, organisation_id
1515
from individual i
1616
where i.is_voided = false
@@ -20,7 +20,7 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
2020
and organisation_id = (select id from organisation where db_user = :org_db_user)
2121
and not subject_type.is_voided)
2222
),
23-
closed_work_orders as (select wo.wo_id, wo.address_id
23+
closed_work_orders as (select wo.wo_id, wo.address_id
2424
from work_orders wo
2525
join encounter e on wo.wo_id = e.individual_id
2626
where e.encounter_type_id =
@@ -33,7 +33,7 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
3333
and wo.organisation_id = (select id from organisation where db_user = :org_db_user)
3434
group by 1, 2
3535
having count(e.id) = 1),
36-
catchments_without_work_orders_or_atleast_one_open_work_order as (
36+
catchments_without_work_orders_or_atleast_one_open_work_order as (
3737
select c.id
3838
from catchment c
3939
join virtual_catchment_address_mapping_table cam on cam.catchment_id = c.id
@@ -44,7 +44,7 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
4444
having count(wo.wo_id) = null
4545
OR count( wo.wo_id) > count( cwo.wo_id)
4646
),
47-
active_user_ids as (select (case
47+
active_user_ids as (select (case
4848
when ind.created_date_time > TO_TIMESTAMP(:cutOffDate, ''YYYY-MM-DDTHH24:MI:ss.MS'')
4949
then ind.created_by_id end) as cuid,
5050
ind.last_modified_by_id as muid
@@ -58,13 +58,14 @@ VALUES (DEFAULT, '69f9f68d-7870-4ea4-b69f-49f68da0c17a', 'Inactive users', 'WITH
5858
from encounter enc
5959
where enc.last_modified_date_time > TO_TIMESTAMP(:cutOffDate, ''YYYY-MM-DDTHH24:MI:ss.MS'')
6060
order by 1 asc)
61-
select distinct user_id, first_name from primary_users pu
61+
select distinct user_id, first_name
62+
from primary_users pu
6263
join catchments_without_work_orders_or_atleast_one_open_work_order cat on pu.catchment_id = cat.id
6364
where user_id not in (select cuid
64-
from active_user_ids
65-
union
66-
select muid
67-
from active_user_ids);',
65+
from active_user_ids where cuid is not null
66+
union
67+
select muid
68+
from active_user_ids where muid is not null);',
6869
:org_id,
6970
false,
7071
0,

0 commit comments

Comments
 (0)