|
| 1 | +# Districts and Their Grama Panchayats and Wards |
| 2 | + |
| 3 | +> Hierarchical mapping of districts to their grama panchayats and wards |
| 4 | +
|
| 5 | +## Purpose |
| 6 | + |
| 7 | +Provides a location hierarchy list of government organizations by mapping: |
| 8 | +- District -> Grama Panchayat -> Ward |
| 9 | + |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Query |
| 14 | + |
| 15 | +```sql |
| 16 | +SELECT |
| 17 | + district.id AS district_id, |
| 18 | + district.name AS district, |
| 19 | + grama.id AS grama_panchayat_id, |
| 20 | + grama.name AS grama_panchayat, |
| 21 | + ward.id AS ward_id, |
| 22 | + ward.name AS ward |
| 23 | +FROM emr_organization AS district |
| 24 | +JOIN emr_organization AS grama |
| 25 | + ON grama.parent_cache @> ARRAY[district.id::integer] |
| 26 | + AND grama.deleted = false |
| 27 | + AND grama.org_type = 'govt' |
| 28 | + AND grama.metadata->>'govt_org_type' = 'grama_panchayat' |
| 29 | +JOIN emr_organization AS ward |
| 30 | + ON ward.parent_id = grama.id |
| 31 | + AND ward.deleted = false |
| 32 | + AND ward.org_type = 'govt' |
| 33 | + AND ward.metadata->>'govt_org_type' = 'ward' |
| 34 | +WHERE district.deleted = false |
| 35 | + AND district.org_type = 'govt' |
| 36 | + AND district.level_cache = 1 |
| 37 | +ORDER BY district.name, grama.name, ward.name; |
| 38 | +``` |
| 39 | + |
| 40 | +## Notes |
| 41 | + |
| 42 | +- This query has no runtime parameters. |
| 43 | +- The district records are represented at `level_cache = 1`. |
| 44 | +- Filters only non-deleted government organizations (`org_type = 'govt'`). |
| 45 | +- Government subtype filtering is based on `metadata->>'govt_org_type'` values: |
| 46 | + - `grama_panchayat` |
| 47 | + - `ward` |
| 48 | + |
| 49 | +*Last updated: 2026-08-03* |
0 commit comments