From 87ef3e78b3e6049ed5949e5e81f22481953e19a0 Mon Sep 17 00:00:00 2001 From: sonzsara Date: Tue, 6 Jan 2026 10:16:40 +0530 Subject: [PATCH 1/2] Add users list with departments documentation and query for ssmm --- Care/Operations/userslistwithdept_ssmm.md | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Care/Operations/userslistwithdept_ssmm.md diff --git a/Care/Operations/userslistwithdept_ssmm.md b/Care/Operations/userslistwithdept_ssmm.md new file mode 100644 index 0000000..be2b364 --- /dev/null +++ b/Care/Operations/userslistwithdept_ssmm.md @@ -0,0 +1,54 @@ +# Users List with Departments + +> Comprehensive list of active users with their contact details, roles, and department assignments + +## Purpose + +This query provides a directory of all active users in the system, including their contact information, user type, assigned departments (organizations), and security roles. It's useful for user management, access auditing, and understanding organizational structure. + +## Parameters + +| Parameter | Type | Description | Example | +|-----------|------|-------------|---------| +| `full_name` | TEXT | Filters by user's full name | `'John Doe'` | +| `department` | TEXT | Filters by department/organization name | `'Cardiology'` | +| `role` | TEXT | Filters by security role name | `'Doctor'` | + +--- + +## Query + +```sql +SELECT + CONCAT(u.first_name, ' ', u.last_name) AS full_name, + u.phone_number, + u.email, + u.user_type, + STRING_AGG(DISTINCT fo.name, ', ') AS departments, + STRING_AGG(DISTINCT rm.name, ', ') AS roles +FROM users_user u +LEFT JOIN emr_facilityorganizationuser fou + ON fou.user_id = u.id +LEFT JOIN emr_facilityorganization fo + ON fo.id = fou.organization_id +LEFT JOIN security_rolemodel rm + ON rm.id = fou.role_id +WHERE u.deleted = FALSE + [[AND (CONCAT(u.first_name, ' ', u.last_name)) = ({{full_name}}) ]] + [[AND (fo.name) = ({{department}}) ]] + [[AND (rm.name) = ({{role}}) ]] +GROUP BY + u.id, full_name, u.phone_number, u.email, u.user_type +ORDER BY full_name; +``` + + +## Notes + +- Only includes active users (deleted = FALSE) +- Users with multiple department or role assignments have them aggregated into comma-separated strings +- Left joins ensure users are shown even if they have no department or role assignments +- Results are ordered alphabetically by full name +- Uses STRING_AGG with DISTINCT to avoid duplicate entries when users have multiple organization assignments + +*Last updated: 2026-01-06* From 32d6318a3bf4c8e1db2c4ff30228ccabcd85ef3f Mon Sep 17 00:00:00 2001 From: sonzsara Date: Tue, 6 Jan 2026 10:50:57 +0530 Subject: [PATCH 2/2] Comment out filter conditions in users list query for clarity --- Care/Operations/userslistwithdept_ssmm.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Care/Operations/userslistwithdept_ssmm.md b/Care/Operations/userslistwithdept_ssmm.md index be2b364..50547a1 100644 --- a/Care/Operations/userslistwithdept_ssmm.md +++ b/Care/Operations/userslistwithdept_ssmm.md @@ -34,9 +34,9 @@ LEFT JOIN emr_facilityorganization fo LEFT JOIN security_rolemodel rm ON rm.id = fou.role_id WHERE u.deleted = FALSE - [[AND (CONCAT(u.first_name, ' ', u.last_name)) = ({{full_name}}) ]] - [[AND (fo.name) = ({{department}}) ]] - [[AND (rm.name) = ({{role}}) ]] + -- [[AND (CONCAT(u.first_name, ' ', u.last_name)) = ({{full_name}}) ]] + -- [[AND (fo.name) = ({{department}}) ]] + -- [[AND (rm.name) = ({{role}}) ]] GROUP BY u.id, full_name, u.phone_number, u.email, u.user_type ORDER BY full_name;