-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add columns to eligible_households table to keep track of selection s…
…tatus. Will have to make breaking changes and change the flow of pre-eligiblity verification runs
- Loading branch information
Showing
10 changed files
with
306 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ces/db/migration/V1.4.4.1650898807416__Revise_eligible_household_details_view_for_api.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
DROP VIEW IF EXISTS eligible_households_v; | ||
|
||
CREATE VIEW eligible_households_v | ||
AS | ||
SELECT eh.session_id | ||
, h.household_id | ||
, h.ml_code | ||
, h.ubr_code AS form_number | ||
, (SELECT count(id) FROM individuals i WHERE i.household_id = h.household_id) AS members | ||
, l.name AS district | ||
, l.code AS district_code | ||
, l2.name AS ta | ||
, l2.code AS ta_code | ||
, l3.name AS cluster | ||
, l3.code AS cluster_code | ||
, l4.name AS "zone" | ||
, l4.code AS zone_code | ||
, l6.name AS village | ||
, l6.code AS village_code | ||
, h.group_village_head_name AS village_head | ||
, CONCAT(i2.first_name, ' ', i2.last_name) AS household_head | ||
, (SELECT JSON_ARRAYAGG( | ||
JSON_OBJECT( | ||
'id', id | ||
, 'created_at', created_at | ||
, 'deleted_at', deleted_at | ||
, 'modified_at', modified_at | ||
, 'first_name', first_name | ||
, 'last_name', last_name | ||
, 'date_of_birth', date_of_birth | ||
, 'gender', gender | ||
, 'relationship', relationship_to_head | ||
, 'household_code', household_code | ||
, 'household_id', household_id | ||
, 'individual_id', individual_id | ||
, 'id_issue_date', id_issue_date | ||
, 'id_expiry_date', id_expiry_date | ||
, 'phone_number', phone_number | ||
, 'education_level', highest_education_level | ||
, 'grade_level', grade_level | ||
, 'school_name', school_name | ||
, 'disability', disability | ||
, 'orphan_status', orphan_status | ||
, 'fit_for_work', fit_for_work | ||
, 'chronic_illness', chronic_illness | ||
, 'status', status | ||
, 'marital_status', marital_status | ||
)) | ||
FROM individuals WHERE household_id = eh.household_id | ||
) AS member_details | ||
FROM eligible_households eh | ||
LEFT JOIN households h ON h.household_id = eh.household_id | ||
LEFT JOIN locations l ON l.code = h.location_code | ||
LEFT JOIN locations l2 ON l2.code = h.ta_code | ||
LEFT JOIN locations l3 ON l3.code = h.cluster_code | ||
LEFT JOIN locations l4 ON l4.code = h.zone_code | ||
LEFT JOIN locations l5 ON l5.code = h.group_village_head_code | ||
LEFT JOIN locations l6 ON l6.code = h.village_code | ||
LEFT JOIN individuals i2 ON i2.household_id = h.household_id AND i2.relationship_to_head = 1 | ||
; |
63 changes: 63 additions & 0 deletions
63
...ces/db/migration/V1.4.4.1650961837201__Revise_eligible_household_details_view_for_api.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
DROP VIEW IF EXISTS eligible_households_v; | ||
|
||
CREATE VIEW eligible_households_v | ||
AS | ||
SELECT eh.session_id | ||
, h.household_id | ||
, h.ml_code | ||
, h.ubr_code AS form_number | ||
, (SELECT count(id) FROM individuals i WHERE i.household_id = h.household_id) AS members | ||
, l.name AS district | ||
, l.code AS district_code | ||
, l2.name AS ta | ||
, l2.code AS ta_code | ||
, l3.name AS cluster | ||
, l3.code AS cluster_code | ||
, l4.name AS "zone" | ||
, l4.code AS zone_code | ||
, l6.name AS village | ||
, l6.code AS village_code | ||
, h.group_village_head_name AS village_head | ||
, "PreEligible" AS selection | ||
, h.cbt_rank AS ranking | ||
, h.last_cbt_ranking | ||
, CONCAT(i2.first_name, ' ', i2.last_name) AS household_head | ||
, (SELECT JSON_ARRAYAGG( | ||
JSON_OBJECT( | ||
'id', id | ||
, 'created_at', created_at | ||
, 'deleted_at', deleted_at | ||
, 'modified_at', modified_at | ||
, 'first_name', first_name | ||
, 'last_name', last_name | ||
, 'date_of_birth', date_of_birth | ||
, 'gender', gender | ||
, 'relationship', relationship_to_head | ||
, 'household_code', household_code | ||
, 'household_id', household_id | ||
, 'individual_id', individual_id | ||
, 'id_issue_date', id_issue_date | ||
, 'id_expiry_date', id_expiry_date | ||
, 'phone_number', phone_number | ||
, 'education_level', highest_education_level | ||
, 'grade_level', grade_level | ||
, 'school_name', school_name | ||
, 'disability', disability | ||
, 'orphan_status', orphan_status | ||
, 'fit_for_work', fit_for_work | ||
, 'chronic_illness', chronic_illness | ||
, 'status', status | ||
, 'marital_status', marital_status | ||
)) | ||
FROM individuals WHERE household_id = eh.household_id | ||
) AS member_details | ||
FROM eligible_households eh | ||
LEFT JOIN households h ON h.household_id = eh.household_id | ||
LEFT JOIN locations l ON l.code = h.location_code | ||
LEFT JOIN locations l2 ON l2.code = h.ta_code | ||
LEFT JOIN locations l3 ON l3.code = h.cluster_code | ||
LEFT JOIN locations l4 ON l4.code = h.zone_code | ||
LEFT JOIN locations l5 ON l5.code = h.group_village_head_code | ||
LEFT JOIN locations l6 ON l6.code = h.village_code | ||
LEFT JOIN individuals i2 ON i2.household_id = h.household_id AND i2.relationship_to_head = 1 | ||
; |
74 changes: 74 additions & 0 deletions
74
...ion/V1.4.4.1651658718187__Add_ranking_and_status_columns_to_eligible_households_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
DROP VIEW IF EXISTS eligible_households_v; | ||
|
||
ALTER table eligible_households | ||
ADD COLUMN ranking int, | ||
ADD COLUMN selection_status varchar(50), | ||
ADD COLUMN second_community_selection_by bigint, | ||
ADD COLUMN second_community_selection_date timestamp, | ||
ADD COLUMN district_community_selection_by bigint, | ||
ADD COLUMN district_community_selection_date timestamp | ||
; | ||
|
||
ALTER TABLE eligible_households ADD INDEX(household_id); | ||
|
||
CREATE VIEW eligible_households_v | ||
AS | ||
SELECT eh.session_id | ||
, h.household_id | ||
, h.ml_code | ||
, h.ubr_code AS form_number | ||
, (SELECT count(id) FROM individuals i WHERE i.household_id = h.household_id) AS members | ||
, l.name AS district | ||
, l.code AS district_code | ||
, l2.name AS ta | ||
, l2.code AS ta_code | ||
, l3.name AS cluster | ||
, l3.code AS cluster_code | ||
, l4.name AS "zone" | ||
, l4.code AS zone_code | ||
, l6.name AS village | ||
, l6.code AS village_code | ||
, h.group_village_head_name AS village_head | ||
, "PreEligible" AS selection | ||
, h.cbt_rank AS ranking | ||
, h.last_cbt_ranking | ||
, CONCAT(i2.first_name, ' ', i2.last_name) AS household_head | ||
, (SELECT JSON_ARRAYAGG( | ||
JSON_OBJECT( | ||
'id', id | ||
, 'created_at', created_at | ||
, 'deleted_at', deleted_at | ||
, 'modified_at', modified_at | ||
, 'first_name', first_name | ||
, 'last_name', last_name | ||
, 'date_of_birth', date_of_birth | ||
, 'gender', gender | ||
, 'relationship', relationship_to_head | ||
, 'household_code', household_code | ||
, 'household_id', household_id | ||
, 'individual_id', individual_id | ||
, 'id_issue_date', id_issue_date | ||
, 'id_expiry_date', id_expiry_date | ||
, 'phone_number', phone_number | ||
, 'education_level', highest_education_level | ||
, 'grade_level', grade_level | ||
, 'school_name', school_name | ||
, 'disability', disability | ||
, 'orphan_status', orphan_status | ||
, 'fit_for_work', fit_for_work | ||
, 'chronic_illness', chronic_illness | ||
, 'status', status | ||
, 'marital_status', marital_status | ||
)) | ||
FROM individuals WHERE household_id = eh.household_id | ||
) AS member_details | ||
FROM eligible_households eh | ||
LEFT JOIN households h ON h.household_id = eh.household_id | ||
LEFT JOIN locations l ON l.code = h.location_code | ||
LEFT JOIN locations l2 ON l2.code = h.ta_code | ||
LEFT JOIN locations l3 ON l3.code = h.cluster_code | ||
LEFT JOIN locations l4 ON l4.code = h.zone_code | ||
LEFT JOIN locations l5 ON l5.code = h.group_village_head_code | ||
LEFT JOIN locations l6 ON l6.code = h.village_code | ||
LEFT JOIN individuals i2 ON i2.household_id = h.household_id AND i2.relationship_to_head = 1 | ||
; |
67 changes: 67 additions & 0 deletions
67
...ces/db/migration/V1.4.4.1651661276242__Add_reason_column_to_eligible_households_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
DROP VIEW IF EXISTS eligible_households_v; | ||
|
||
ALTER table eligible_households | ||
ADD COLUMN reason varchar(200) after selection_status | ||
; | ||
|
||
CREATE VIEW eligible_households_v | ||
AS | ||
SELECT eh.session_id | ||
, h.household_id | ||
, h.ml_code | ||
, h.ubr_code AS form_number | ||
, (SELECT count(id) FROM individuals i WHERE i.household_id = h.household_id) AS members | ||
, l.name AS district | ||
, l.code AS district_code | ||
, l2.name AS ta | ||
, l2.code AS ta_code | ||
, l3.name AS cluster | ||
, l3.code AS cluster_code | ||
, l4.name AS "zone" | ||
, l4.code AS zone_code | ||
, l6.name AS village | ||
, l6.code AS village_code | ||
, h.group_village_head_name AS village_head | ||
, "PreEligible" AS selection | ||
, h.cbt_rank AS ranking | ||
, h.last_cbt_ranking | ||
, CONCAT(i2.first_name, ' ', i2.last_name) AS household_head | ||
, (SELECT JSON_ARRAYAGG( | ||
JSON_OBJECT( | ||
'id', id | ||
, 'created_at', created_at | ||
, 'deleted_at', deleted_at | ||
, 'modified_at', modified_at | ||
, 'first_name', first_name | ||
, 'last_name', last_name | ||
, 'date_of_birth', date_of_birth | ||
, 'gender', gender | ||
, 'relationship', relationship_to_head | ||
, 'household_code', household_code | ||
, 'household_id', household_id | ||
, 'individual_id', individual_id | ||
, 'id_issue_date', id_issue_date | ||
, 'id_expiry_date', id_expiry_date | ||
, 'phone_number', phone_number | ||
, 'education_level', highest_education_level | ||
, 'grade_level', grade_level | ||
, 'school_name', school_name | ||
, 'disability', disability | ||
, 'orphan_status', orphan_status | ||
, 'fit_for_work', fit_for_work | ||
, 'chronic_illness', chronic_illness | ||
, 'status', status | ||
, 'marital_status', marital_status | ||
)) | ||
FROM individuals WHERE household_id = eh.household_id | ||
) AS member_details | ||
FROM eligible_households eh | ||
LEFT JOIN households h ON h.household_id = eh.household_id | ||
LEFT JOIN locations l ON l.code = h.location_code | ||
LEFT JOIN locations l2 ON l2.code = h.ta_code | ||
LEFT JOIN locations l3 ON l3.code = h.cluster_code | ||
LEFT JOIN locations l4 ON l4.code = h.zone_code | ||
LEFT JOIN locations l5 ON l5.code = h.group_village_head_code | ||
LEFT JOIN locations l6 ON l6.code = h.village_code | ||
LEFT JOIN individuals i2 ON i2.household_id = h.household_id AND i2.relationship_to_head = 1 | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters