From 8cf6beed65317a31ab57ededd82f984d2a5d7ca9 Mon Sep 17 00:00:00 2001 From: Rob Harrison <48765695+robjharrison@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:48:15 +0000 Subject: [PATCH] consistency check fixes batch 2 --- .../mosaic/SQL_Permanence_DW.sql | 291 ++++----- .../mosaic/SQL_Permanence_Live.sql | 590 ++++++++---------- cms_ssd_extract_sql/mosaic/SQL_Person_DW.sql | 2 +- .../mosaic/SQL_Person_Live.sql | 2 +- cms_ssd_extract_sql/mosaic/SQL_SDQ_DW.sql | 2 +- cms_ssd_extract_sql/mosaic/SQL_SDQ_Live.sql | 2 +- .../mosaic/populate_ssd_data_warehouse.sql | 76 +-- .../mosaic/ssd_address_essex.sql | 2 +- .../mosaic/ssd_cin_episodes_tag_dw.sql | 2 +- .../mosaic/ssd_cla_placement_essex.sql | 4 +- .../mosaic/ssd_cla_plans_dm_kt.sql | 4 +- .../mosaic/ssd_cla_reviews_tag_dw.sql | 4 +- .../mosaic/ssd_cp_plans_essex.sql | 2 +- .../mosaic/ssd_cp_reviews_essex.sql | 2 +- .../mosaic/ssd_cp_visits_dm_kt.sql | 4 +- .../mosaic/ssd_immigration_status_dm_kt.sql | 4 +- .../mosaic/ssd_linked_identifiers_tag_dw.sql | 2 +- .../mosaic/ssd_missing_tag_dw.sql | 6 +- .../mosaic/ssd_permanence_essex.sql | 83 +-- .../mosaic/ssd_person_essex.sql | 2 +- .../mosaic/ssd_person_tag_dw.sql | 2 +- .../mosaic/ssd_sdq_scores_essex.sql | 2 +- ...nsistency_checks-locate_variable_in_sql.py | 2 +- 23 files changed, 471 insertions(+), 621 deletions(-) diff --git a/cms_ssd_extract_sql/mosaic/SQL_Permanence_DW.sql b/cms_ssd_extract_sql/mosaic/SQL_Permanence_DW.sql index d026fc6..2a7e42e 100644 --- a/cms_ssd_extract_sql/mosaic/SQL_Permanence_DW.sql +++ b/cms_ssd_extract_sql/mosaic/SQL_Permanence_DW.sql @@ -9,94 +9,82 @@ DECLARE IF OBJECT_ID('Tempdb..#t','u') IS NOT NULL BEGIN -DROP TABLE #t + DROP TABLE #t END CREATE TABLE #t ( -perm_permanence_id INT, -perm_person_id INT, -perm_adm_decision_date DATE, -perm_entered_care_date DATE, -perm_ffa_cp_decision_date DATE, -perm_placement_order_date DATE, -perm_placed_for_adoption_date DATE, -perm_matched_date DATE, -perm_placed_ffa_cp_date DATE, -perm_decision_reversed_date DATE, -perm_placed_foster_carer_date DATE, -perm_part_of_sibling_group VARCHAR(1), -perm_siblings_placed_together INT, -perm_siblings_placed_apart INT, -perm_placement_provider_urn VARCHAR(10), -perm_decision_reversed_reason VARCHAR(3), -perm_permanence_order_date DATE, -perm_permanence_order_type VARCHAR(10), -perm_guardian_status VARCHAR(50), -perm_guardian_age VARCHAR(20), -perm_adopted_by_carer_flag VARCHAR(1), -perm_cla_id INT, -perm_adoption_worker_id INT, -- [REVIEW] 310524 RH -perm_allocated_worker INT -- depreciated item + perm_table_id INT, -- [REVIEW] + perm_person_id INT, + perm_adm_decision_date DATE, + perm_ffa_cp_decision_date DATE, + perm_placement_order_date DATE, + perm_placed_for_adoption_date DATE, + perm_matched_date DATE, + perm_placed_ffa_cp_date DATE, + perm_decision_reversed_date DATE, + perm_placed_foster_carer_date DATE, + perm_part_of_sibling_group VARCHAR(1), + perm_siblings_placed_together INT, + perm_siblings_placed_apart INT, + perm_placement_provider_urn VARCHAR(10), + perm_decision_reversed_reason VARCHAR(3), + perm_permanence_order_date DATE, + perm_permanence_order_type VARCHAR(10), + perm_adopted_by_carer_flag VARCHAR(1), + perm_cla_id INT, + perm_adoption_worker_id INT -- [REVIEW] 310524 RH ) INSERT #t ( -perm_permanence_id, -perm_person_id, -perm_adm_decision_date, -perm_entered_care_date, -perm_ffa_cp_decision_date, -perm_placement_order_date, -perm_placed_for_adoption_date, -perm_matched_date, -perm_placed_ffa_cp_date, -perm_decision_reversed_date, -perm_placed_foster_carer_date, -perm_part_of_sibling_group, -perm_siblings_placed_together, -perm_siblings_placed_apart, -perm_placement_provider_urn, -perm_decision_reversed_reason, -perm_permanence_order_date, -perm_permanence_order_type, -perm_guardian_status, -perm_guardian_age, -perm_adopted_by_carer_flag, -perm_cla_id, -perm_adoption_worker_id, -perm_allocated_worker + perm_table_id, + perm_person_id, + perm_adm_decision_date, + perm_ffa_cp_decision_date, + perm_placement_order_date, + perm_placed_for_adoption_date, + perm_matched_date, + perm_placed_ffa_cp_date, + perm_decision_reversed_date, + perm_placed_foster_carer_date, + perm_part_of_sibling_group, + perm_siblings_placed_together, + perm_siblings_placed_apart, + perm_placement_provider_urn, + perm_decision_reversed_reason, + perm_permanence_order_date, + perm_permanence_order_type, + perm_adopted_by_carer_flag, + perm_cla_id, + perm_adoption_worker_id ) /*Adoption Cases*/ Select -NULL perm_permanence_id, -a.[Person ID] perm_person_id, -a.[Best Interest Decision (SHODPA)] perm_adm_decision_date, -a.[Entered Care] perm_entered_care_date, -NULL perm_ffa_cp_decision_date, /*PW - to be added to Adoption Tracking Spreadsheet*/ -a.[Placement Order Granted] perm_placement_order_date, -a.[Date Placed for Adoption] perm_placed_for_adoption_date, -a.[Date Matched (Panel ADM)] perm_matched_date, -a.[Date of Fostering For Adoption (FFA) / Concurrency Placement] perm_placed_ffa_cp_date, -a.[Date Placed Ceased] perm_decision_reversed_date, -a.[Date Moved in with Foster Carer] perm_placed_foster_carer_date, -CASE when a.[Sibling Group] is not null then 1 else 0 END perm_part_of_sibling_group, -a.[Children Placed Together] perm_siblings_placed_together, -a.[Children Placed Apart] perm_siblings_placed_apart, -a.[Ofsted URN of LA or Agency Providing Placement] perm_placement_provider_urn, -NULL perm_decision_reversed_reason, -a.[Date of Adoption Order (Date Adopted)] perm_permanence_order_date, -CASE when a.[Date of Adoption Order (Date Adopted)] is not null then 'Adoption' END perm_permanence_order_type, -NULL perm_guardian_status, -NULL perm_guardian_age, -a.[Adoption by Existing Foster Carer] perm_adopted_by_carer_flag, -b.LLPID perm_cla_id, -NULL perm_adoption_worker_id, -NULL perm_allocated_worker + NULL perm_table_id, + a.[Person ID] perm_person_id, + a.[Best Interest Decision (SHODPA)] perm_adm_decision_date, + NULL perm_ffa_cp_decision_date, /*PW - to be added to Adoption Tracking Spreadsheet*/ + a.[Placement Order Granted] perm_placement_order_date, + a.[Date Placed for Adoption] perm_placed_for_adoption_date, + a.[Date Matched (Panel ADM)] perm_matched_date, + a.[Date of Fostering For Adoption (FFA) / Concurrency Placement] perm_placed_ffa_cp_date, + a.[Date Placed Ceased] perm_decision_reversed_date, + a.[Date Moved in with Foster Carer] perm_placed_foster_carer_date, + CASE when a.[Sibling Group] is not null then 1 else 0 END perm_part_of_sibling_group, + a.[Children Placed Together] perm_siblings_placed_together, + a.[Children Placed Apart] perm_siblings_placed_apart, + a.[Ofsted URN of LA or Agency Providing Placement] perm_placement_provider_urn, + NULL perm_decision_reversed_reason, + a.[Date of Adoption Order (Date Adopted)] perm_permanence_order_date, + CASE when a.[Date of Adoption Order (Date Adopted)] is not null then 'Adoption' END perm_permanence_order_type, + a.[Adoption by Existing Foster Carer] perm_adopted_by_carer_flag, + b.LLPID perm_cla_id, + NULL perm_adoption_worker_id from ChildrensReports.Temp.OfstedInspList10RawData a inner join Mosaic.D.LACLegalPeriods b on a.[Person ID] = b.LLPPersonID - and a.[Best Interest Decision (SHODPA)] between b.LLPStartDate and COALESCE(b.LLPEndDate,'99991231') + and a.[Best Interest Decision (SHODPA)] between b.LLPStartDate and COALESCE(b.LLPEndDate,'99991231') where (a.[Best Interest Decision (SHODPA)] >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) or a.[Placement Order Granted] >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) @@ -107,39 +95,35 @@ or a.[Date of Adoption Order (Date Adopted)] >= DATEADD(YYYY, -@ssd_timeframe_ye UNION /*SGO / CAO Cases - Note only SGO / CAO from Care recorded, for all SGO / CAO also use Mosaic.M.PERSON_NON_LA_LEGAL_STATUSES (LEGAL_STATUS in ('SGO','CAO'))*/ + Note only SGO / CAO from Care recorded, for all SGO / CAO also use Mosaic.M.PERSON_NON_LA_LEGAL_STATUSES (LEGAL_STATUS in ('SGO','CAO'))*/ Select -NULL perm_permanence_id, -a.PERSON_ID perm_person_id, -NULL perm_adm_decision_date, -b.llpStartDate perm_entered_care_date, -NULL perm_ffa_cp_decision_date, /*PW - to be added to Adoption Tracking Spreadsheet*/ -NULL perm_placement_order_date, -NULL perm_placed_for_adoption_date, -NULL perm_matched_date, -NULL perm_placed_ffa_cp_date, -NULL perm_decision_reversed_date, -NULL perm_placed_foster_carer_date, -NULL perm_part_of_sibling_group, -NULL perm_siblings_placed_together, -NULL perm_siblings_placed_apart, -NULL perm_placement_provider_urn, -NULL perm_decision_reversed_reason, -a.END_DATE perm_permanence_order_date, -CASE - when a.REASON_EPISODE_CEASED = 'E41' then 'CAO' - when a.REASON_EPISODE_CEASED between 'E42' and 'E48' then 'SGO' -END perm_permanence_order_type, -NULL perm_guardian_status, -NULL perm_guardian_age, -NULL perm_adopted_by_carer_flag, -b.LLPID perm_cla_id, -NULL perm_adoption_worker_id, -NULL perm_allocated_worker + NULL perm_table_id, -- [REVIEW] + a.PERSON_ID perm_person_id, + NULL perm_adm_decision_date, + NULL perm_ffa_cp_decision_date, /*PW - to be added to Adoption Tracking Spreadsheet*/ + NULL perm_placement_order_date, + NULL perm_placed_for_adoption_date, + NULL perm_matched_date, + NULL perm_placed_ffa_cp_date, + NULL perm_decision_reversed_date, + NULL perm_placed_foster_carer_date, + NULL perm_part_of_sibling_group, + NULL perm_siblings_placed_together, + NULL perm_siblings_placed_apart, + NULL perm_placement_provider_urn, + NULL perm_decision_reversed_reason, + a.END_DATE perm_permanence_order_date, + CASE + when a.REASON_EPISODE_CEASED = 'E41' then 'CAO' + when a.REASON_EPISODE_CEASED between 'E42' and 'E48' then 'SGO' + END perm_permanence_order_type, + NULL perm_adopted_by_carer_flag, + b.LLPID perm_cla_id, + NULL perm_adoption_worker_id from Mosaic.M.LOOKED_AFTER_PLACEMENTS a inner join Mosaic.D.LACLegalPeriods b on a.PERSON_ID = b.LLPPersonID - and CAST(a.END_DATE as date) between b.LLPStartDate and COALESCE(b.LLPEndDate,'99991231') + and CAST(a.END_DATE as date) between b.LLPStartDate and COALESCE(b.LLPEndDate,'99991231') where CAST(a.END_DATE as date) >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) and a.REASON_EPISODE_CEASED between 'E41' and 'E48' @@ -152,77 +136,46 @@ SET perm_adoption_worker_id = d.perm_adoption_worker_id from #t t inner join ( - Select - t.perm_person_id, - COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') PermEndDate, - pw.WORKER_ID perm_adoption_worker_id, - DENSE_RANK() OVER(PARTITION BY t.perm_person_id, COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') ORDER BY pw.END_DATE DESC, pw.ID DESC) Rnk - - from #t t - inner join Mosaic.M.PEOPLE_WORKERS pw on t.perm_person_id = pw.PERSON_ID - and CAST(pw.START_DATE as date) <= COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') - and COALESCE(CAST(pw.END_DATE as date),'99991231') >= t.perm_entered_care_date - - where pw.TYPE = 'FAMFINDSOC' -) -d on t.perm_person_id = d.perm_person_id - and COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') = d.PermEndDate + Select + t.perm_person_id, + COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') PermEndDate, + pw.WORKER_ID perm_adoption_worker_id, + DENSE_RANK() OVER(PARTITION BY t.perm_person_id, COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') ORDER BY pw.END_DATE DESC, pw.ID DESC) Rnk -where d.Rnk = 1 -and COALESCE(t.perm_permanence_order_type, 'Adoption') = 'Adoption' + from #t t + inner join Mosaic.M.PEOPLE_WORKERS pw on t.perm_person_id = pw.PERSON_ID + and CAST(pw.START_DATE as date) <= COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') + and COALESCE(CAST(pw.END_DATE as date),'99991231') >= t.perm_decision_reversed_date - -/*Latest Allocated Worker*/ -UPDATE #t -SET perm_allocated_worker = d.perm_allocated_worker - -from #t t -inner join -( - Select - t.perm_person_id, - COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') PermEndDate, - pw.WORKER_ID perm_allocated_worker, - DENSE_RANK() OVER(PARTITION BY t.perm_person_id, COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') ORDER BY pw.END_DATE DESC, pw.ID DESC) Rnk - - from #t t - inner join Mosaic.M.PEOPLE_WORKERS pw on t.perm_person_id = pw.PERSON_ID - and CAST(pw.START_DATE as date) <= COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') - and COALESCE(CAST(pw.END_DATE as date),'99991231') >= t.perm_entered_care_date - - where pw.TYPE = 'ALLWKR' -) -d on t.perm_person_id = d.perm_person_id - and COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') = d.PermEndDate + where pw.TYPE = 'FAMFINDSOC' +) d on t.perm_person_id = d.perm_person_id + and COALESCE(t.perm_permanence_order_date, t.perm_decision_reversed_date, '99991231') = d.PermEndDate where d.Rnk = 1 +and COALESCE(t.perm_permanence_order_type, 'Adoption') = 'Adoption' /*Output Data*/ Select -t.perm_permanence_id, -t.perm_person_id, -t.perm_adm_decision_date, -t.perm_entered_care_date, -t.perm_ffa_cp_decision_date, -t.perm_placement_order_date, -t.perm_placed_for_adoption_date, -t.perm_matched_date, -t.perm_placed_ffa_cp_date, -t.perm_decision_reversed_date, -t.perm_placed_foster_carer_date, -t.perm_part_of_sibling_group, -t.perm_siblings_placed_together, -t.perm_siblings_placed_apart, -t.perm_placement_provider_urn, -t.perm_decision_reversed_reason, -t.perm_permanence_order_date, -t.perm_permanence_order_type, -t.perm_guardian_status, -t.perm_guardian_age, -t.perm_adopted_by_carer_flag, -t.perm_cla_id, -t.perm_adoption_worker_id, -t.perm_allocated_worker - -from #t t \ No newline at end of file + t.perm_table_id, + t.perm_person_id, + t.perm_adm_decision_date, + t.perm_ffa_cp_decision_date, + t.perm_placement_order_date, + t.perm_placed_for_adoption_date, + t.perm_matched_date, + t.perm_placed_ffa_cp_date, + t.perm_decision_reversed_date, + t.perm_placed_foster_carer_date, + t.perm_part_of_sibling_group, + t.perm_siblings_placed_together, + t.perm_siblings_placed_apart, + t.perm_placement_provider_urn, + t.perm_decision_reversed_reason, + t.perm_permanence_order_date, + t.perm_permanence_order_type, + t.perm_adopted_by_carer_flag, + t.perm_cla_id, + t.perm_adoption_worker_id + +from #t t diff --git a/cms_ssd_extract_sql/mosaic/SQL_Permanence_Live.sql b/cms_ssd_extract_sql/mosaic/SQL_Permanence_Live.sql index abb417f..19c7c0f 100644 --- a/cms_ssd_extract_sql/mosaic/SQL_Permanence_Live.sql +++ b/cms_ssd_extract_sql/mosaic/SQL_Permanence_Live.sql @@ -16,440 +16,356 @@ DECLARE /*Temporary Table - Create LAC Periods (Get LAC Legal Statuses)*/ IF OBJECT_ID('Tempdb..#LLP','u') IS NOT NULL BEGIN -DROP TABLE #LLP + DROP TABLE #LLP END CREATE TABLE #LLP ( -RowID INT IDENTITY, -PersonID INT, -RecordID INT, -StartDate DATE, -EndDate DATE, -LSCode VARCHAR(16), -Gap SMALLINT, -MasterRecordID INT + RowID INT IDENTITY, + PersonID INT, + RecordID INT, + StartDate DATE, + EndDate DATE, + LSCode VARCHAR(16), + Gap SMALLINT, + MasterRecordID INT ) CREATE UNIQUE CLUSTERED INDEX ix_LLP ON #LLP(PersonID,StartDate) - INSERT #LLP ( -PersonID, -RecordID, -StartDate, -EndDate, -LSCode, -Gap + PersonID, + RecordID, + StartDate, + EndDate, + LSCode, + Gap ) Select -l.PERSON_ID PersonID, -l.ID RecordID, -l.START_DATE StartDate, -l.END_DATE EndDate, -l.LEGAL_STATUS LSCode, -DATEDIFF(DAY, LAG(l.END_DATE) OVER(PARTITION BY l.PERSON_ID ORDER BY l.START_DATE),l.START_DATE) Gap - + l.PERSON_ID PersonID, + l.ID RecordID, + l.START_DATE StartDate, + l.END_DATE EndDate, + l.LEGAL_STATUS LSCode, + DATEDIFF(DAY, LAG(l.END_DATE) OVER(PARTITION BY l.PERSON_ID ORDER BY l.START_DATE),l.START_DATE) Gap from moLive.dbo.PERSON_LEGAL_STATUSES l - where l.LEGAL_STATUS not in ('V1','V3','V4') /*Short Break Placements*/ -and l.START_DATE < COALESCE(l.END_DATE,'99991231') - + and l.START_DATE < COALESCE(l.END_DATE,'99991231') order by l.PERSON_ID, l.START_DATE - /*Add 'MasterRecordID'*/ -DECLARE @PrevPersonID INT, - @MasterRecordID INT, - @Anchor INT; +DECLARE @PrevPersonID INT, + @MasterRecordID INT, + @Anchor INT; -UPDATE #LLP -SET @MasterRecordID = MasterRecordID = +UPDATE #LLP +SET @MasterRecordID = MasterRecordID = CASE - when PersonID <> @PrevPersonID then RecordID - when PersonID = @PrevPersonID and Gap < 1 then @MasterRecordID - else RecordID + when PersonID <> @PrevPersonID then RecordID + when PersonID = @PrevPersonID and Gap < 1 then @MasterRecordID + else RecordID END, - @PrevPersonID = PersonId, - @Anchor = RowID - + @PrevPersonID = PersonId, + @Anchor = RowID /*Temporary Table - Create LAC Periods*/ IF OBJECT_ID('Tempdb..#LAC','u') IS NOT NULL BEGIN -DROP TABLE #LAC + DROP TABLE #LAC END CREATE TABLE #LAC ( -LLPID INT, -PersonID INT, -LACStartDate DATE, -LACEndDate DATE + LLPID INT, + PersonID INT, + LACStartDate DATE, + LACEndDate DATE ) CREATE UNIQUE CLUSTERED INDEX ix_LAC ON #LAC(PersonID,LACStartDate) - INSERT #LAC ( -LLPID, -PersonID, -LACStartDate, -LACEndDate + LLPID, + PersonID, + LACStartDate, + LACEndDate ) Select -llp.MasterRecordID LLPID, -llp.PersonID, -MIN (llp.StartDate) LACStartDate, -CASE when MAX(COALESCE(llp.EndDate,'20790606')) = '20790606' then NULL else MAX(COALESCE(llp.EndDate,'20790606')) END LACEndDate - + llp.MasterRecordID LLPID, + llp.PersonID, + MIN (llp.StartDate) LACStartDate, + CASE when MAX(COALESCE(llp.EndDate,'20790606')) = '20790606' then NULL else MAX(COALESCE(llp.EndDate,'20790606')) END LACEndDate from #LLP llp - group by llp.PersonID, llp.MasterRecordID - /*Output Data*/ ---Select * ---from #LAC lac - ---order by lac.PersonID, lac.LACStartDate - - +/*Select * +from #LAC lac +order by lac.PersonID, lac.LACStartDate*/ /*Temporary Table - Permanence Table*/ IF OBJECT_ID('Tempdb..#t','u') IS NOT NULL BEGIN -DROP TABLE #t + DROP TABLE #t END CREATE TABLE #t ( -perm_permanence_id INT, -perm_person_id INT, -perm_adm_decision_date DATE, -perm_entered_care_date DATE, -perm_ffa_cp_decision_date DATE, -perm_placement_order_date DATE, -PlacementOrderEnd DATE, -perm_placed_for_adoption_date DATE, -perm_matched_date DATE, -perm_placed_ffa_cp_date DATE, -perm_decision_reversed_date DATE, -perm_placed_foster_carer_date DATE, -perm_part_of_sibling_group VARCHAR(1), -perm_siblings_placed_together INT, -perm_siblings_placed_apart INT, -perm_placement_provider_urn VARCHAR(10), -perm_decision_reversed_reason VARCHAR(3), -perm_permanence_order_date DATE, -perm_permanence_order_type VARCHAR(10), -perm_guardian_status VARCHAR(50), -perm_guardian_age VARCHAR(20), -perm_adopted_by_carer_flag VARCHAR(1), -perm_cla_id INT, -perm_adoption_worker_id INT, -- [REVIEW] 310524 RH -perm_allocated_worker INT + perm_table_id INT, -- [REVIEW] + perm_person_id INT, + perm_adm_decision_date DATE, + perm_ffa_cp_decision_date DATE, + perm_placement_order_date DATE, + PlacementOrderEnd DATE, + perm_placed_for_adoption_date DATE, + perm_matched_date DATE, + perm_placed_ffa_cp_date DATE, + perm_decision_reversed_date DATE, + perm_placed_foster_carer_date DATE, + perm_part_of_sibling_group VARCHAR(1), + perm_siblings_placed_together INT, + perm_siblings_placed_apart INT, + perm_placement_provider_urn VARCHAR(10), + perm_decision_reversed_reason VARCHAR(3), + perm_permanence_order_date DATE, + perm_permanence_order_type VARCHAR(10), + perm_adopted_by_carer_flag VARCHAR(1), + perm_cla_id INT, + perm_adoption_worker_id INT -- [REVIEW] 310524 RH ) INSERT #t ( -perm_permanence_id, -perm_person_id, -perm_adm_decision_date, -perm_entered_care_date, -perm_ffa_cp_decision_date, -perm_placement_order_date, -PlacementOrderEnd, -perm_placed_for_adoption_date, -perm_matched_date, -perm_placed_ffa_cp_date, -perm_decision_reversed_date, -perm_placed_foster_carer_date, -perm_part_of_sibling_group, -perm_siblings_placed_together, -perm_siblings_placed_apart, -perm_placement_provider_urn, -perm_decision_reversed_reason, -perm_permanence_order_date, -perm_permanence_order_type, -perm_guardian_status, -perm_guardian_age, -perm_adopted_by_carer_flag, -perm_cla_id, -perm_adoption_worker_id, -perm_allocated_worker + perm_table_id, + perm_person_id, + perm_adm_decision_date, + perm_ffa_cp_decision_date, + perm_placement_order_date, + PlacementOrderEnd, + perm_placed_for_adoption_date, + perm_matched_date, + perm_placed_ffa_cp_date, + perm_decision_reversed_date, + perm_placed_foster_carer_date, + perm_part_of_sibling_group, + perm_siblings_placed_together, + perm_siblings_placed_apart, + perm_placement_provider_urn, + perm_decision_reversed_reason, + perm_permanence_order_date, + perm_permanence_order_type, + perm_adopted_by_carer_flag, + perm_cla_id, + perm_adoption_worker_id ) /*Adoption Cases*/ Select -NULL perm_permanence_id, -a.PERSON_ID perm_person_id, -NULL perm_adm_decision_date, -lac.LACStartDate perm_entered_care_date, -NULL perm_ffa_cp_decision_date, -CAST(a.START_DATE as date) perm_placement_order_date, -CAST(a.END_DATE as date) PlacementOrderEnd, -CAST(p.START_DATE as date) perm_placed_for_adoption_date, -NULL perm_matched_date, -NULL perm_placed_ffa_cp_date, -NULL perm_decision_reversed_date, -NULL perm_placed_foster_carer_date, -NULL perm_part_of_sibling_group, -NULL perm_siblings_placed_together, -NULL perm_siblings_placed_apart, -NULL perm_placement_provider_urn, -NULL perm_decision_reversed_reason, -CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then CAST(p.END_DATE as date) END perm_permanence_order_date, -CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then 'Adoption' END perm_permanence_order_type, -NULL perm_guardian_status, -NULL perm_guardian_age, -NULL perm_adopted_by_carer_flag, -lac.LLPID perm_cla_id, -NULL perm_adoption_worker_id, -NULL perm_allocated_worker - + NULL perm_table_id, + a.PERSON_ID perm_person_id, + NULL perm_adm_decision_date, + lac.LACStartDate, + NULL perm_ffa_cp_decision_date, + CAST(a.START_DATE as date) perm_placement_order_date, + CAST(a.END_DATE as date) PlacementOrderEnd, + CAST(p.START_DATE as date) perm_placed_for_adoption_date, + NULL perm_matched_date, + NULL perm_placed_ffa_cp_date, + NULL perm_decision_reversed_date, + NULL perm_placed_foster_carer_date, + NULL perm_part_of_sibling_group, + NULL perm_siblings_placed_together, + NULL perm_siblings_placed_apart, + NULL perm_placement_provider_urn, + NULL perm_decision_reversed_reason, + CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then CAST(p.END_DATE as date) END perm_permanence_order_date, + CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then 'Adoption' END perm_permanence_order_type, + NULL perm_adopted_by_carer_flag, + lac.LLPID perm_cla_id, + NULL perm_adoption_worker_id from moLive.dbo.PERSON_LEGAL_STATUSES a inner join #LAC lac on a.PERSON_ID = lac.PersonID - and COALESCE(CAST(a.END_DATE as date),'99991231') between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') + and COALESCE(CAST(a.END_DATE as date),'99991231') between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') left join moLive.dbo.LOOKED_AFTER_PLACEMENTS p on a.PERSON_ID = p.PERSON_ID - and p.PLACEMENT_CODE like 'A%' - and p.START_DATE >= a.START_DATE - + and p.PLACEMENT_CODE like 'A%' + and p.START_DATE >= a.START_DATE where a.LEGAL_STATUS in ('D1','E1') -and COALESCE(CAST(a.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) + and COALESCE(CAST(a.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) UNION /*Adoption Cases - Relinquished Child - No Placement Order*/ Select -NULL perm_permanence_id, -p.PERSON_ID perm_person_id, -NULL perm_adm_decision_date, -lac.LACStartDate perm_entered_care_date, -NULL perm_ffa_cp_decision_date, -NULL perm_placement_order_date, -NULL PlacementOrderEnd, -CAST(p.START_DATE as date) perm_placed_for_adoption_date, -NULL perm_matched_date, -NULL perm_placed_ffa_cp_date, -NULL perm_decision_reversed_date, -NULL perm_placed_foster_carer_date, -NULL perm_part_of_sibling_group, -NULL perm_siblings_placed_together, -NULL perm_siblings_placed_apart, -NULL perm_placement_provider_urn, -NULL perm_decision_reversed_reason, -CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then CAST(p.END_DATE as date) END perm_permanence_order_date, -CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then 'Adoption' END perm_permanence_order_type, -NULL perm_guardian_status, -NULL perm_guardian_age, -NULL perm_adopted_by_carer_flag, -lac.LLPID perm_cla_id, -NULL perm_adoption_worker_id, -NULL perm_allocated_worker - + NULL perm_table_id, + p.PERSON_ID perm_person_id, + NULL perm_adm_decision_date, + lac.LACStartDate, + NULL perm_ffa_cp_decision_date, + NULL perm_placement_order_date, + NULL PlacementOrderEnd, + CAST(p.START_DATE as date) perm_placed_for_adoption_date, + NULL perm_matched_date, + NULL perm_placed_ffa_cp_date, + NULL perm_decision_reversed_date, + NULL perm_placed_foster_carer_date, + NULL perm_part_of_sibling_group, + NULL perm_siblings_placed_together, + NULL perm_siblings_placed_apart, + NULL perm_placement_provider_urn, + NULL perm_decision_reversed_reason, + CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then CAST(p.END_DATE as date) END perm_permanence_order_date, + CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then 'Adoption' END perm_permanence_order_type, + NULL perm_adopted_by_carer_flag, + lac.LLPID perm_cla_id, + NULL perm_adoption_worker_id from moLive.dbo.LOOKED_AFTER_PLACEMENTS p inner join #LAC lac on p.PERSON_ID = lac.PersonID - and COALESCE(CAST(p.END_DATE as date),'99991231') between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') + and COALESCE(CAST(p.END_DATE as date),'99991231') between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') left join moLive.dbo.PERSON_LEGAL_STATUSES a on p.PERSON_ID = a.PERSON_ID - and a.LEGAL_STATUS in ('D1','E1') - and a.START_DATE <= p.START_DATE - + and a.LEGAL_STATUS in ('D1','E1') + and a.START_DATE <= p.START_DATE where p.PLACEMENT_CODE like 'A%' -and COALESCE(CAST(p.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) -and a.PERSON_ID is null - + and COALESCE(CAST(p.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) + and a.PERSON_ID is null /*Exclude children already included*/ -and p.PERSON_ID not in -( - Select a.PERSON_ID - - from moLive.dbo.PERSON_LEGAL_STATUSES a - left join moLive.dbo.LOOKED_AFTER_PLACEMENTS p on a.PERSON_ID = p.PERSON_ID - and p.PLACEMENT_CODE like 'A%' - and p.START_DATE >= a.START_DATE - - where a.LEGAL_STATUS in ('D1','E1') - and COALESCE(CAST(a.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) -) + and p.PERSON_ID not in + ( + Select a.PERSON_ID + from moLive.dbo.PERSON_LEGAL_STATUSES a + left join moLive.dbo.LOOKED_AFTER_PLACEMENTS p on a.PERSON_ID = p.PERSON_ID + and p.PLACEMENT_CODE like 'A%' + and p.START_DATE >= a.START_DATE + where a.LEGAL_STATUS in ('D1','E1') + and COALESCE(CAST(a.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) + ) UNION /*Adoption Cases - Private Adoption by Foster Carer*/ Select -NULL perm_permanence_id, -p.PERSON_ID perm_person_id, -NULL perm_adm_decision_date, -lac.LACStartDate perm_entered_care_date, -NULL perm_ffa_cp_decision_date, -CAST(a.START_DATE as date) perm_placement_order_date, -CAST(a.END_DATE as date) PlacementOrderEnd, -CAST(p.START_DATE as date) perm_placed_for_adoption_date, -NULL perm_matched_date, -NULL perm_placed_ffa_cp_date, -NULL perm_decision_reversed_date, -NULL perm_placed_foster_carer_date, -NULL perm_part_of_sibling_group, -NULL perm_siblings_placed_together, -NULL perm_siblings_placed_apart, -NULL perm_placement_provider_urn, -NULL perm_decision_reversed_reason, -CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then CAST(p.END_DATE as date) END perm_permanence_order_date, -CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then 'Adoption' END perm_permanence_order_type, -NULL perm_guardian_status, -NULL perm_guardian_age, -NULL perm_adopted_by_carer_flag, -lac.LLPID perm_cla_id, -NULL perm_adoption_worker_id, -NULL perm_allocated_worker - + NULL perm_table_id, + p.PERSON_ID perm_person_id, + NULL perm_adm_decision_date, + lac.LACStartDate, + NULL perm_ffa_cp_decision_date, + CAST(a.START_DATE as date) perm_placement_order_date, + CAST(a.END_DATE as date) PlacementOrderEnd, + CAST(p.START_DATE as date) perm_placed_for_adoption_date, + NULL perm_matched_date, + NULL perm_placed_ffa_cp_date, + NULL perm_decision_reversed_date, + NULL perm_placed_foster_carer_date, + NULL perm_part_of_sibling_group, + NULL perm_siblings_placed_together, + NULL perm_siblings_placed_apart, + NULL perm_placement_provider_urn, + NULL perm_decision_reversed_reason, + CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then CAST(p.END_DATE as date) END perm_permanence_order_date, + CASE when p.REASON_EPISODE_CEASED in ('E11','E12') then 'Adoption' END perm_permanence_order_type, + NULL perm_adopted_by_carer_flag, + lac.LLPID perm_cla_id, + NULL perm_adoption_worker_id from moLive.dbo.LOOKED_AFTER_PLACEMENTS p inner join #LAC lac on p.PERSON_ID = lac.PersonID - and COALESCE(CAST(p.END_DATE as date),'99991231') between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') + and COALESCE(CAST(p.END_DATE as date),'99991231') between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') left join moLive.dbo.PERSON_LEGAL_STATUSES a on p.PERSON_ID = a.PERSON_ID - and a.LEGAL_STATUS in ('D1','E1') - and a.START_DATE <= p.START_DATE - + and a.LEGAL_STATUS in ('D1','E1') + and a.START_DATE <= p.START_DATE where p.REASON_EPISODE_CEASED in ('E11','E12') -and p.PLACEMENT_CODE not like 'A%' -and COALESCE(CAST(p.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) - + and p.PLACEMENT_CODE not like 'A%' + and COALESCE(CAST(p.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) /*Exclude children already included*/ -and p.PERSON_ID not in -( - Select a.PERSON_ID - - from moLive.dbo.PERSON_LEGAL_STATUSES a - left join moLive.dbo.LOOKED_AFTER_PLACEMENTS p on a.PERSON_ID = p.PERSON_ID - and p.PLACEMENT_CODE like 'A%' - and p.START_DATE >= a.START_DATE - - where a.LEGAL_STATUS in ('D1','E1') - and COALESCE(CAST(a.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) -) + and p.PERSON_ID not in + ( + Select a.PERSON_ID + from moLive.dbo.PERSON_LEGAL_STATUSES a + left join moLive.dbo.LOOKED_AFTER_PLACEMENTS p on a.PERSON_ID = p.PERSON_ID + and p.PLACEMENT_CODE like 'A%' + and p.START_DATE >= a.START_DATE + where a.LEGAL_STATUS in ('D1','E1') + and COALESCE(CAST(a.END_DATE as date),'99991231') >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) + ) UNION /*SGO / CAO Cases - Note only SGO / CAO from Care recorded, for all SGO / CAO also use Mosaic.M.PERSON_NON_LA_LEGAL_STATUSES (LEGAL_STATUS in ('SGO','CAO'))*/ + Note only SGO / CAO from Care recorded, for all SGO / CAO also use Mosaic.M.PERSON_NON_LA_LEGAL_STATUSES (LEGAL_STATUS in ('SGO','CAO'))*/ Select -NULL perm_permanence_id, -a.PERSON_ID perm_person_id, -NULL perm_adm_decision_date, -lac.LACStartDate perm_entered_care_date, -NULL perm_ffa_cp_decision_date, /*PW - to be added to Adoption Tracking Spreadsheet*/ -NULL perm_placement_order_date, -NULL PlacementOrderDate, -NULL perm_placed_for_adoption_date, -NULL perm_matched_date, -NULL perm_placed_ffa_cp_date, -NULL perm_decision_reversed_date, -NULL perm_placed_foster_carer_date, -NULL perm_part_of_sibling_group, -NULL perm_siblings_placed_together, -NULL perm_siblings_placed_apart, -NULL perm_placement_provider_urn, -NULL perm_decision_reversed_reason, -a.END_DATE perm_permanence_order_date, -CASE - when a.REASON_EPISODE_CEASED = 'E41' then 'CAO' - when a.REASON_EPISODE_CEASED between 'E42' and 'E48' then 'SGO' -END perm_permanence_order_type, -NULL perm_guardian_status, -NULL perm_guardian_age, -NULL perm_adopted_by_carer_flag, -lac.LLPID perm_cla_id, -NULL perm_adoption_worker_id, -NULL perm_allocated_worker - + NULL perm_table_id, + a.PERSON_ID perm_person_id, + NULL perm_adm_decision_date, + lac.LACStartDate, + NULL perm_ffa_cp_decision_date, /*PW - to be added to Adoption Tracking Spreadsheet*/ + NULL perm_placement_order_date, + NULL PlacementOrderDate, + NULL perm_placed_for_adoption_date, + NULL perm_matched_date, + NULL perm_placed_ffa_cp_date, + NULL perm_decision_reversed_date, + NULL perm_placed_foster_carer_date, + NULL perm_part_of_sibling_group, + NULL perm_siblings_placed_together, + NULL perm_siblings_placed_apart, + NULL perm_placement_provider_urn, + NULL perm_decision_reversed_reason, + a.END_DATE perm_permanence_order_date, + CASE + when a.REASON_EPISODE_CEASED = 'E41' then 'CAO' + when a.REASON_EPISODE_CEASED between 'E42' and 'E48' then 'SGO' + END perm_permanence_order_type, + NULL perm_adopted_by_carer_flag, + lac.LLPID perm_cla_id, + NULL perm_adoption_worker_id from moLive.dbo.LOOKED_AFTER_PLACEMENTS a inner join #LAC lac on a.PERSON_ID = lac.PersonID - and CAST(a.END_DATE as date) between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') - + and CAST(a.END_DATE as date) between lac.LACStartDate and COALESCE(lac.LACEndDate,'99991231') where CAST(a.END_DATE as date) >= DATEADD(YYYY, -@ssd_timeframe_years, @STARTTIME) -and a.REASON_EPISODE_CEASED between 'E41' and 'E48' - + and a.REASON_EPISODE_CEASED between 'E41' and 'E48' /*Latest Adoption Worker*/ UPDATE #t SET perm_adoption_worker_id = d.perm_adoption_worker_id - from #t t inner join ( - Select - t.perm_person_id, - COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') PermEndDate, - pw.WORKER_ID perm_adoption_worker_id, - DENSE_RANK() OVER(PARTITION BY t.perm_person_id, COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') ORDER BY pw.END_DATE DESC, pw.ID DESC) Rnk - - from #t t - inner join moLive.dbo.PEOPLE_WORKERS pw on t.perm_person_id = pw.PERSON_ID - and CAST(pw.START_DATE as date) <= COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') - - where pw.TYPE = 'FAMFINDSOC' -) -d on t.perm_person_id = d.perm_person_id - and COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') = d.PermEndDate - + Select + t.perm_person_id, + COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') PermEndDate, + pw.WORKER_ID perm_adoption_worker_id, + DENSE_RANK() OVER(PARTITION BY t.perm_person_id, COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') ORDER BY pw.END_DATE DESC, pw.ID DESC) Rnk + from #t t + inner join moLive.dbo.PEOPLE_WORKERS pw on t.perm_person_id = pw.PERSON_ID + and CAST(pw.START_DATE as date) <= COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') + where pw.TYPE = 'FAMFINDSOC' +) d on t.perm_person_id = d.perm_person_id + and COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') = d.PermEndDate where d.Rnk = 1 -and COALESCE(t.perm_permanence_order_type, 'Adoption') = 'Adoption' - - -/*Latest Allocated Worker*/ -UPDATE #t -SET perm_allocated_worker = d.perm_allocated_worker - -from #t t -inner join -( - Select - t.perm_person_id, - COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') PermEndDate, - pw.WORKER_ID perm_allocated_worker, - DENSE_RANK() OVER(PARTITION BY t.perm_person_id, COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') ORDER BY pw.END_DATE DESC, pw.ID DESC) Rnk - - from #t t - inner join moLive.dbo.PEOPLE_WORKERS pw on t.perm_person_id = pw.PERSON_ID - and CAST(pw.START_DATE as date) <= COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') - - where pw.TYPE = 'ALLWKR' -) -d on t.perm_person_id = d.perm_person_id - and COALESCE(t.perm_permanence_order_date, t.PlacementOrderEnd, '99991231') = d.PermEndDate - -where d.Rnk = 1 - + and COALESCE(t.perm_permanence_order_type, 'Adoption') = 'Adoption' /*Output Data*/ Select -t.perm_permanence_id, -t.perm_person_id, -t.perm_adm_decision_date, -t.perm_entered_care_date, -t.perm_ffa_cp_decision_date, -t.perm_placement_order_date, ---t.PlacementOrderEnd, -t.perm_placed_for_adoption_date, -t.perm_matched_date, -t.perm_placed_ffa_cp_date, -t.perm_decision_reversed_date, -t.perm_placed_foster_carer_date, -t.perm_part_of_sibling_group, -t.perm_siblings_placed_together, -t.perm_siblings_placed_apart, -t.perm_placement_provider_urn, -t.perm_decision_reversed_reason, -t.perm_permanence_order_date, -t.perm_permanence_order_type, -t.perm_guardian_status, -t.perm_guardian_age, -t.perm_adopted_by_carer_flag, -t.perm_cla_id, -t.perm_adoption_worker_id, -t.perm_allocated_worker - -from #t t \ No newline at end of file + t.perm_table_id, + t.perm_person_id, + t.perm_adm_decision_date, + t.perm_ffa_cp_decision_date, + t.perm_placement_order_date, + --t.PlacementOrderEnd, + t.perm_placed_for_adoption_date, + t.perm_matched_date, + t.perm_placed_ffa_cp_date, + t.perm_decision_reversed_date, + t.perm_placed_foster_carer_date, + t.perm_part_of_sibling_group, + t.perm_siblings_placed_together, + t.perm_siblings_placed_apart, + t.perm_placement_provider_urn, + t.perm_decision_reversed_reason, + t.perm_permanence_order_date, + t.perm_permanence_order_type, + t.perm_adopted_by_carer_flag, + t.perm_cla_id, + t.perm_adoption_worker_id +from #t t diff --git a/cms_ssd_extract_sql/mosaic/SQL_Person_DW.sql b/cms_ssd_extract_sql/mosaic/SQL_Person_DW.sql index c965257..23cb329 100644 --- a/cms_ssd_extract_sql/mosaic/SQL_Person_DW.sql +++ b/cms_ssd_extract_sql/mosaic/SQL_Person_DW.sql @@ -14,7 +14,7 @@ p.pGender pers_gender, COALESCE(ec.CINCode,'NOBT') pers_ethnicity, p.PDoB pers_dob, p.PNHSNumber pers_common_child_id, -p.PUniquePupilNumber pers_upn, +-- p.PUniquePupilNumber pers_upn, -- [depreciated] [REVIEW] NULL pers_upn_unknown, CASE when ehcp.PersonID is not null then 'Y' END pers_send_flag, p.PDoBEstimated pers_expected_dob, diff --git a/cms_ssd_extract_sql/mosaic/SQL_Person_Live.sql b/cms_ssd_extract_sql/mosaic/SQL_Person_Live.sql index 242139b..4aabb21 100644 --- a/cms_ssd_extract_sql/mosaic/SQL_Person_Live.sql +++ b/cms_ssd_extract_sql/mosaic/SQL_Person_Live.sql @@ -15,7 +15,7 @@ pg.GENDER_CODE pers_gender, e.CIN_ETHNICITY_DESCRIPTION pers_ethnicity, CAST(DATE_OF_BIRTH as date) pers_dob, r1.REFERENCE pers_common_child_id, -r2.REFERENCE pers_upn, +-- r2.REFERENCE pers_upn, -- [depreciated] [REVIEW] NULL pers_upn_unknown, NULL pers_send_flag, /*PW - Information held in Education System*/ p.AGE_ESTIMATED pers_expected_dob, diff --git a/cms_ssd_extract_sql/mosaic/SQL_SDQ_DW.sql b/cms_ssd_extract_sql/mosaic/SQL_SDQ_DW.sql index 88001d5..d958db7 100644 --- a/cms_ssd_extract_sql/mosaic/SQL_SDQ_DW.sql +++ b/cms_ssd_extract_sql/mosaic/SQL_SDQ_DW.sql @@ -9,7 +9,7 @@ DECLARE /*Form Data*/ Select -a.FormID sdq_sdq_id, +a.FormID sdq_sdq_id, -- [REVIEW] should this be csdq_sdq_id - which has subsequently changed to csdq_table_id a.PersonID sdq_person_id, CAST(a.DateOfAssessment as date) sdq_sdq_completed_date, NULL sdq_sdq_reason, diff --git a/cms_ssd_extract_sql/mosaic/SQL_SDQ_Live.sql b/cms_ssd_extract_sql/mosaic/SQL_SDQ_Live.sql index b113ed2..e907809 100644 --- a/cms_ssd_extract_sql/mosaic/SQL_SDQ_Live.sql +++ b/cms_ssd_extract_sql/mosaic/SQL_SDQ_Live.sql @@ -9,7 +9,7 @@ DECLARE /*Form Data*/ Select -a.FORM_ID sdq_sdq_id, +a.FORM_ID sdq_sdq_id, -- [REVIEW] should this be csdq_sdq_id - which has subsequently changed to csdq_table_id sg.ONLY_SUBJECT_COMPOUND_ID sdq_person_id, CAST(fda.DATE_ANSWER as date) sdq_sdq_completed_date, NULL sdq_sdq_reason, diff --git a/cms_ssd_extract_sql/mosaic/populate_ssd_data_warehouse.sql b/cms_ssd_extract_sql/mosaic/populate_ssd_data_warehouse.sql index 88abba2..c4efb15 100644 --- a/cms_ssd_extract_sql/mosaic/populate_ssd_data_warehouse.sql +++ b/cms_ssd_extract_sql/mosaic/populate_ssd_data_warehouse.sql @@ -776,7 +776,7 @@ Dependencies: lacp_cla_care_plan_id varchar(48), lacp_cla_care_plan_start_date datetime, lacp_cla_care_plan_end_date datetime, - lacp_cla_care_plan varchar(100), + lacp_cla_care_plan_json varchar(100), -- [REVIEW] changed from lacp_ cla_ care_ plan (spaced here to avoiding name being picked up by other processes) lacp_person_id varchar(48) ) -- @@ -823,7 +823,7 @@ Dependencies: lacp_cla_care_plan_id, lacp_cla_care_plan_start_date, lacp_cla_care_plan_end_date, - lacp_cla_care_plan, + lacp_cla_care_plan_json, lacp_person_id ) select @@ -848,7 +848,7 @@ Dependencies: else cfa.subject_person_id end = sgs.SUBJECT_COMPOUND_ID - ) lacp_cla_care_plan, + ) lacp_cla_care_plan_json, sgs.SUBJECT_COMPOUND_ID lacp_person_id from dm_workflow_steps stp @@ -1033,14 +1033,14 @@ Dependencies: -- insert into ##ssd_immigration_status ( immi_person_id, - immi_Immigration_status_id, + immi_immigration_status_id, immi_immigration_status, immi_immigration_status_start_date, immi_immigration_status_end_date ) select sub.immi_person_id, - sub.immi_Immigration_status_id, + sub.immi_immigration_status_id, sub.immi_immigration_status, dbo.no_time(sub.immi_immigration_status_start_date) immi_immigration_status_start_date, dbo.no_time(sub.immi_immigration_status_end_date) immi_immigration_status_end_date @@ -1048,7 +1048,7 @@ Dependencies: ( select sgs.subject_compound_id immi_person_id, - dbo.append2(f.form_id, '.', sgs.subject_compound_id) immi_Immigration_status_id, + dbo.append2(f.form_id, '.', sgs.subject_compound_id) immi_immigration_status_id, lkp.text_answer immi_immigration_status, d1.date_answer immi_immigration_status_start_date, d2.date_answer immi_immigration_status_end_date, @@ -1150,7 +1150,7 @@ Dependencies: DROP TABLE ##ssd_cp_visits -- create table ##ssd_cp_visits ( - cppv_visit_id varchar(48), + cppv_cp_visit_id varchar(48), cppv_cp_plan_id varchar(48), cppv_cp_visit_id varchar(48), cppv_cp_visit_date datetime, @@ -1183,7 +1183,7 @@ Dependencies: ('child_seen') -- insert into ##ssd_cp_visits ( - cppv_visit_id, + cppv_cp_visit_id, cppv_cp_plan_id, cppv_cp_visit_id, cppv_cp_visit_date, @@ -1192,7 +1192,7 @@ Dependencies: cppv_cp_visit_bedroom ) select - null cppv_visit_id, + null cppv_cp_visit_id, ( select max(cpp.registration_id) @@ -1777,7 +1777,7 @@ Dependencies: addr_address_type varchar(48), addr_address_start_date datetime, addr_address_end_date datetime, - addr_postcode varchar(15) + addr_address_postcode varchar(15) ) -- insert into ##ssd_address ( @@ -1794,9 +1794,9 @@ Dependencies: addr.ADDRESS addr_address_json, addr.PERSON_ID addr_person_id, addr.ADDRESS_TYPE addr_address_type, - addr.START_DATE addr_start_date, - addr.END_DATE addr_end_date, - addr.POST_CODE addr_postcode + addr.START_DATE addr_address_start_date, + addr.END_DATE addr_address_end_date, + addr.POST_CODE addr_address_postcode from dm_ADDRESSES addr -- @@ -1850,7 +1850,7 @@ Dependencies: DROP TABLE ##ssd_sdq_scores -- create table ##ssd_sdq_scores ( - csdq_sdq_id varchar(48), + csdq_table_id varchar(48), -- [REVIEW] was csdq_sdq_id csdq_person_id varchar(48), csdq_sdq_completed_date datetime, csdq_sdq_reason varchar(100), @@ -1858,14 +1858,14 @@ Dependencies: ) -- insert into ##ssd_sdq_scores ( - csdq_sdq_id, + csdq_table_id, csdq_person_id, csdq_sdq_completed_date, csdq_sdq_reason, csdq_sdq_score ) select - hlth.HEALTH_ID csdq_sdq_id, + hlth.HEALTH_ID csdq_table_id, hlth.PERSON_ID csdq_person_id, hlth.HEALTH_ASSESSMENT_DATE csdq_sdq_completed_date, hlth.SDQ_REASON csdq_sdq_reason, @@ -2415,9 +2415,9 @@ Dependencies: pers_ethnicity varchar(48), pers_dob datetime, pers_common_child_id varchar(48), - pers_upn varchar(48), + -- pers_upn varchar(48), -- [depreciated] [REVIEW] pers_upn_unknown varchar(20), - pers_send varchar(1), + pers_send_flag varchar(1), pers_expected_dob datetime, pers_death_date datetime, pers_is_mother varchar(1), @@ -2431,9 +2431,9 @@ Dependencies: pers_ethnicity, pers_dob, pers_common_child_id, - pers_upn, + -- pers_upn, pers_upn_unknown, - pers_send, + pers_send_flag, pers_expected_dob, pers_death_date, pers_is_mother, @@ -2478,9 +2478,9 @@ Dependencies: per.DATE_OF_BIRTH end pers_dob, per.nhs_id pers_common_child_id, - per.UPN_ID pers_upn, + -- per.UPN_ID pers_upn, -- [depreciated] [REVIEW] null pers_upn_unknown, - null pers_send, + null pers_send_flag, case when per.DATE_OF_BIRTH > dbo.today() then per.DATE_OF_BIRTH @@ -3403,8 +3403,8 @@ Dependencies: miss_missing_rhi_accepted ) select - stp.workflow_step_id misw_table_id, - sgs.SUBJECT_COMPOUND_ID misw_person_id, + stp.workflow_step_id miss_table_id, + sgs.SUBJECT_COMPOUND_ID miss_person_id, stp.started_on miss_missing_episode_start_date, ( select @@ -3537,7 +3537,7 @@ Dependencies: DROP TABLE ##ssd_linked_identifiers -- create table ##ssd_linked_identifiers ( - link_link_id varchar(48), + link_table_id varchar(48), -- [REVIEW] link_person_id varchar(48), link_identifier_type varchar(20), link_identifier_value varchar(20), @@ -3546,7 +3546,7 @@ Dependencies: ) -- insert into ##ssd_linked_identifiers ( - link_link_id, + link_table_id, link_person_id, link_identifier_type, link_identifier_value, @@ -3554,7 +3554,7 @@ Dependencies: link_valid_to_date ) select - pref.REFERENCE_ID link_link_id, + pref.REFERENCE_ID link_table_id, pref.PERSON_ID link_person_id, pref.REFERENCE_TYPE link_identifier_type, pref.REFERENCE link_identifier_value, @@ -4445,7 +4445,7 @@ Dependencies: create table ##ssd_cp_plans ( cppl_cp_plan_id varchar(48), cppl_referral_id varchar(48), - cppl_initial_cp_conference_id varchar(48), + cppl_icpc_id varchar(48), cppl_person_id varchar(48), cppl_cp_plan_start_date datetime, cppl_cp_plan_end_date datetime, @@ -4456,7 +4456,7 @@ Dependencies: insert into ##ssd_cp_plans ( cppl_cp_plan_id, cppl_referral_id, - cppl_initial_cp_conference_id, + cppl_icpc_id, cppl_person_id, cppl_cp_plan_start_date, cppl_cp_plan_end_date, @@ -4477,7 +4477,7 @@ Dependencies: and dbo.future(ref.CLOSURE_DATE)>= cpp.REGISTRATION_START_DATE ) cppl_referral_id, - cpp.REGISTRATION_STEP_ID cppl_initial_cp_conference_id, + cpp.REGISTRATION_STEP_ID cppl_icpc_id, cpp.PERSON_ID cppl_person_id, cpp.REGISTRATION_START_DATE cppl_cp_plan_start_date, cpp.DEREGISTRATION_DATE cppl_cp_plan_end_date, @@ -4952,7 +4952,7 @@ Dependencies: then dateadd(dd,91,x.date_of_prev_review) else dateadd(dd,183,x.date_of_prev_review) - end clar_cla_due_date, + end clar_cla_review_due_date, null clar_cla_review_date, null clar_cla_review_participation, x.period_of_care_id clar_cla_id, @@ -5229,8 +5229,8 @@ Dependencies: create table ##ssd_cla_episodes ( clae_cla_episode_id varchar(48), clae_person_id varchar(48), - clae_cla_episode_start datetime, - clae_episode_start_reason varchar(100), + clae_cla_episode_start_date datetime, + clae_cla_episode_start_reason varchar(100), clae_cla_primary_need_code varchar(100), clae_cla_id varchar(48), clae_referral_id varchar(48), @@ -5238,13 +5238,13 @@ Dependencies: clae_cla_episode_ceased datetime, clae_cla_placement_id varchar(48), clae_entered_care_date datetime, - clae_cla_episode_cease_reason varchar(255) + clae_cla_episode_ceased_reason varchar(255) ) insert into ##ssd_cla_episodes ( clae_cla_episode_id, clae_person_id, - clae_cla_episode_start, - clae_episode_start_reason, + clae_cla_episode_start_date, + clae_cla_episode_start_reason, clae_cla_primary_need_code, clae_cla_id, clae_referral_id, @@ -5252,7 +5252,7 @@ Dependencies: clae_cla_episode_ceased, clae_cla_placement_id, clae_entered_care_date, - clae_cla_episode_cease_reason + clae_cla_episode_ceased_reason ) select dbo.to_weighted_start(cla.START_DATE,cla.PERSON_ID) clae_cla_episode_id, @@ -5321,7 +5321,7 @@ Dependencies: cla.END_DATE clae_cla_episode_ceased, cla.placement_id clae_cla_placement_id, poc.start_date clae_entered_care_date, - pla.REASON_EPISODE_CEASED clae_cla_episode_cease_reason + pla.REASON_EPISODE_CEASED clae_cla_episode_ceased_reason from dm_cla_summaries cla inner join dm_PERIODS_OF_CARE poc diff --git a/cms_ssd_extract_sql/mosaic/ssd_address_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_address_essex.sql index 54f891f..4e6144a 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_address_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_address_essex.sql @@ -5,6 +5,6 @@ select addr.ADDRESS_TYPE addr_address_type, addr.START_DATE addr_address_start_date, addr.END_DATE addr_address_end_date, - addr.post_code addr_address_postode + addr.post_code addr_address_postcode -- [REVIEW] from raw.mosaic_fw_dm_addresses addr \ No newline at end of file diff --git a/cms_ssd_extract_sql/mosaic/ssd_cin_episodes_tag_dw.sql b/cms_ssd_extract_sql/mosaic/ssd_cin_episodes_tag_dw.sql index 43b1550..d585db1 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cin_episodes_tag_dw.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cin_episodes_tag_dw.sql @@ -21,7 +21,7 @@ select else 'Y' end cin_referral_nfa, - ref.CLOSURE_REASON cine_clos_reason, + ref.CLOSURE_REASON cine_close_reason, stp.RESPONSIBLE_TEAM_ID cine_referral_team, stp.ASSIGNEE_ID cine_referral_worker_id from diff --git a/cms_ssd_extract_sql/mosaic/ssd_cla_placement_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_cla_placement_essex.sql index a1b182f..b331061 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cla_placement_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cla_placement_essex.sql @@ -5,10 +5,10 @@ select cla.PLACEMENT_START clap_cla_placement_start_date, cla.PLACEMENT_TYPE_CODE cla_cla_placement_type, cla.OFSTED_URN clap_cla_placement_urn, - cla.DISTANCE_FROM_HOME clap_placement_distance, + cla.DISTANCE_FROM_HOME clap_cla_placement_distance, cla.period_of_care_id clap_cla_id, cla.PLACEMENT_COUNTY clap_cla_placement_la, - cla.PROVIDER_NAME clap_cla_placement_provider, + cla.PROVIDER_NAME clap_cla_placement_provider, cla.PLACEMENT_POSTCODE clap_cla_placement_postcode, cla.PLACEMENT_END clap_cla_placement_end_date, cla.REASON_FOR_PLACEMENT_CHANGE clap_cla_placement_change_reason diff --git a/cms_ssd_extract_sql/mosaic/ssd_cla_plans_dm_kt.sql b/cms_ssd_extract_sql/mosaic/ssd_cla_plans_dm_kt.sql index ead3846..403627e 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cla_plans_dm_kt.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cla_plans_dm_kt.sql @@ -171,7 +171,7 @@ select sub.lacp_cla_care_plan_id ,sub.lacp_cla_care_plan_start_date ,sub.lacp_cla_care_plan_end_date - ,sub.lacp_cla_care_plan + ,sub.lacp_cla_care_plan_json ,sub.lacp_person_id from ( @@ -188,7 +188,7 @@ from lkp.workflow_step_id = o.lacp_cla_care_plan_id and lkp.person_id = o.person_id - ) lacp_cla_care_plan + ) lacp_cla_care_plan_json ,( select min(o1.closing_step_date) from output o1 diff --git a/cms_ssd_extract_sql/mosaic/ssd_cla_reviews_tag_dw.sql b/cms_ssd_extract_sql/mosaic/ssd_cla_reviews_tag_dw.sql index 3b25c4c..17e7fa9 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cla_reviews_tag_dw.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cla_reviews_tag_dw.sql @@ -104,7 +104,7 @@ select then dateadd(dd,91,x.date_of_prev_review) else dateadd(dd,183,x.date_of_prev_review) - end clar_cla_due_date, + end clar_cla_review_due_date, x.LAC_REVIEW_DATE clar_cla_review_date, x.participation_type clar_cla_review_participation, x.period_of_care_id clar_cla_id, @@ -213,7 +213,7 @@ select then dateadd(dd,91,x.date_of_prev_review) else dateadd(dd,183,x.date_of_prev_review) - end clar_cla_due_date, + end clar_cla_review_due_date, null clar_cla_review_date, null clar_cla_review_participation, x.period_of_care_id clar_cla_id, diff --git a/cms_ssd_extract_sql/mosaic/ssd_cp_plans_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_cp_plans_essex.sql index 76f8cad..0d5a55f 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cp_plans_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cp_plans_essex.sql @@ -94,7 +94,7 @@ select where ref.REGISTRATION_ID = cpp.REGISTRATION_ID ) cppl_referral_id, - cpp.REGISTRATION_STEP_ID cppl_icpc_id, -- [REVIEW] from cppl_initial_cp_conference_id 290424 RH + cpp.REGISTRATION_STEP_ID cppl_icpc_id, -- [REVIEW] from cppl_initial_cp_conference_id 290424 RH cpp.person_id cppl_person_id, cpp.REGISTRATION_START_DATE cppl_cp_plan_start_date, cpp.DEREGISTRATION_DATE cppl_cp_plan_end_date, diff --git a/cms_ssd_extract_sql/mosaic/ssd_cp_reviews_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_cp_reviews_essex.sql index 6672e06..e049f44 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cp_reviews_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cp_reviews_essex.sql @@ -1,6 +1,6 @@ select rev.WORKFLOW_STEP_ID cppr_cp_review_id, - rev.person_id cppr_cp_person_id, + rev.person_id cppr_person_id, ( select max(cpp.registration_id) diff --git a/cms_ssd_extract_sql/mosaic/ssd_cp_visits_dm_kt.sql b/cms_ssd_extract_sql/mosaic/ssd_cp_visits_dm_kt.sql index edb65ff..c0e01d1 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_cp_visits_dm_kt.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_cp_visits_dm_kt.sql @@ -158,7 +158,7 @@ where ) -- select - sub.cppv_visit_id, + sub.cppv_cp_visit_id, ( select reg.registration_id @@ -189,7 +189,7 @@ from ( select stp.person_id, - dbo.append2(stp.workflow_step_id, '.', stp.person_id) cppv_visit_id, + -- dbo.append2(stp.workflow_step_id, '.', stp.person_id) cppv_visit_id, -- [REVIEW] replaced by below... re-test and remove this line dbo.append2(stp.workflow_step_id, '.', stp.person_id) cppv_cp_visit_id, coalesce( ( diff --git a/cms_ssd_extract_sql/mosaic/ssd_immigration_status_dm_kt.sql b/cms_ssd_extract_sql/mosaic/ssd_immigration_status_dm_kt.sql index 1e9d608..988c733 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_immigration_status_dm_kt.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_immigration_status_dm_kt.sql @@ -109,7 +109,7 @@ where -- select sub.immi_person_id, - sub.immi_Immigration_status_id, + sub.immi_immigration_status_id, sub.immi_immigration_status, cast(sub.immi_immigration_status_start_date as date) immi_immigration_status_start_date, cast(sub.immi_immigration_status_end_date as date) immi_immigration_status_end_date @@ -117,7 +117,7 @@ from ( select sgs.subject_compound_id immi_person_id, - dbo.append2(f.form_id, '.', sgs.subject_compound_id) immi_Immigration_status_id, + dbo.append2(f.form_id, '.', sgs.subject_compound_id) immi_immigration_status_id, lkp.text_answer immi_immigration_status, d1.date_answer immi_immigration_status_start_date, d2.date_answer immi_immigration_status_end_date, diff --git a/cms_ssd_extract_sql/mosaic/ssd_linked_identifiers_tag_dw.sql b/cms_ssd_extract_sql/mosaic/ssd_linked_identifiers_tag_dw.sql index a6ab953..c296569 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_linked_identifiers_tag_dw.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_linked_identifiers_tag_dw.sql @@ -1,5 +1,5 @@ select - pref.REFERENCE_ID link_link_id, + pref.REFERENCE_ID link_table_id, -- [REVIEW] pref.PERSON_ID link_person_id, pref.REFERENCE_TYPE link_identifier_type, pref.REFERENCE link_identifier_value, diff --git a/cms_ssd_extract_sql/mosaic/ssd_missing_tag_dw.sql b/cms_ssd_extract_sql/mosaic/ssd_missing_tag_dw.sql index 6a869f0..d0d9b73 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_missing_tag_dw.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_missing_tag_dw.sql @@ -1,7 +1,7 @@ select - stp.workflow_step_id misw_table_id, - sgs.SUBJECT_COMPOUND_ID misw_person_id, - stp.started_on miss_missing_episode_start, + stp.workflow_step_id miss_table_id, + sgs.SUBJECT_COMPOUND_ID miss_person_id, + stp.started_on miss_missing_episode_start_date, ( select --Should be only one per episode, but max() just in case diff --git a/cms_ssd_extract_sql/mosaic/ssd_permanence_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_permanence_essex.sql index d5cfabb..b6fb31c 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_permanence_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_permanence_essex.sql @@ -1,52 +1,33 @@ -select - null perm_permanence_id, - c.id perm_person_id, - c.adm_decision_date perm_adm_decision_date, - null perm_ffa_cp_decision_date, - c.placement_order_date perm_placement_order_date, - c.date_placed_for_adoption perm_placed_for_adoption_date, - c.panel_matching_date perm_matched_date, - c.date_ffa perm_placed_ffa_cp_date, - c.date_decision_reversed perm_decision_revered_date, - c.sibling_group perm_part_of_sibling_group, - c.sibling_together perm_siblings_placed_together, - null perm_siblings_placed_apart, - null perm_placement_provider_urn, - c.reason_reversed perm_decision_reversed_reason, - c.ao_date perm_permanence_order_date, - null perm_permanence_order_type, - null perm_guardian_status, - null perm_guardian_age, - null perm_adopted_by_carer_flag, - ( - select - max(cla.PERIOD_OF_CARE_ID) - from - SCF.Children_In_Care cla - where - cla.person_id = c.id - and - cla.poc_start = c.poc_start - ) perm_cla_id, - c.worker_name perm_adoption_worker_id, -- [REVIEW][_name] - ( - select - wkr.worker_id - from - raw.mosaic_fw_dm_prof_relationships prel - inner join raw.mosaic_fw_dm_workers wkr - on wkr.worker_id = prel.worker_id - where - prel.person_id = c.id - and - prel.PROF_REL_TYPE_CODE in ( - 'REL.ALLWORK', - 'REL.ALLWORKCF' - ) - and - convert(datetime, convert(varchar, getdate(), 103), 103) between prel.START_DATE and coalesce(prel.end_date,'1 January 2300') - ) perm_allocated_worker -from - SCF.ALB_Children c +SELECT + NULL perm_table_id, + c.id perm_person_id, + c.adm_decision_date perm_adm_decision_date, + NULL perm_ffa_cp_decision_date, + c.placement_order_date perm_placement_order_date, + c.date_placed_for_adoption perm_placed_for_adoption_date, + c.panel_matching_date perm_matched_date, + c.date_ffa perm_placed_ffa_cp_date, + c.date_decision_reversed perm_decision_reversed_date, + c.sibling_group perm_part_of_sibling_group, + c.sibling_together perm_siblings_placed_together, + NULL perm_siblings_placed_apart, + NULL perm_placement_provider_urn, + c.reason_reversed perm_decision_reversed_reason, + c.ao_date perm_permanence_order_date, + NULL perm_permanence_order_type, + NULL perm_adopted_by_carer_flag, + ( + SELECT + MAX(cla.PERIOD_OF_CARE_ID) + FROM + SCF.Children_In_Care cla + WHERE + cla.person_id = c.id + AND + cla.poc_start = c.poc_start + ) perm_cla_id, + c.worker_name perm_adoption_worker_id -- [REVIEW][_name] +FROM + SCF.ALB_Children c ---select top 100 * from SCF.ALB_Children c \ No newline at end of file +--select top 100 * from SCF.ALB_Children c diff --git a/cms_ssd_extract_sql/mosaic/ssd_person_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_person_essex.sql index 2d8412f..c94c975 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_person_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_person_essex.sql @@ -7,7 +7,7 @@ select per.date_of_birth end pers_dob, per.NHS_ID pers_common_child_id, - per.UPN_ID pers_upn, + -- per.UPN_ID pers_upn, -- [depreciated] [REVIEW] null pers_upn_unknown, null pers_send_flag, case diff --git a/cms_ssd_extract_sql/mosaic/ssd_person_tag_dw.sql b/cms_ssd_extract_sql/mosaic/ssd_person_tag_dw.sql index 268f63d..231b9ec 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_person_tag_dw.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_person_tag_dw.sql @@ -37,7 +37,7 @@ select per.DATE_OF_BIRTH end pers_dob, per.nhs_id pers_common_child_id, - per.UPN_ID pers_upn, + -- per.UPN_ID pers_upn, -- [depreciated] [REVIEW] null pers_upn_unknown, null pers_send_flag, case diff --git a/cms_ssd_extract_sql/mosaic/ssd_sdq_scores_essex.sql b/cms_ssd_extract_sql/mosaic/ssd_sdq_scores_essex.sql index 5409db8..e790da4 100644 --- a/cms_ssd_extract_sql/mosaic/ssd_sdq_scores_essex.sql +++ b/cms_ssd_extract_sql/mosaic/ssd_sdq_scores_essex.sql @@ -1,5 +1,5 @@ select - replace(replace(replace(convert(varchar, sdq.SDQ_DATE, 120), '-', ''), ' ', ''), ':', '') + '.' + replicate('0', 9 - len(cast(sdq.person_id as varchar(9)))) + cast(sdq.person_id as varchar(9)) csdq_sdq_id, + replace(replace(replace(convert(varchar, sdq.SDQ_DATE, 120), '-', ''), ' ', ''), ':', '') + '.' + replicate('0', 9 - len(cast(sdq.person_id as varchar(9)))) + cast(sdq.person_id as varchar(9)) csdq_table_id, sdq.PERSON_ID csdq_person_id, sdq.SDQ_DATE csdq_sdq_completed_date, sdq.SDQ_REASON csdq_sdq_reason, diff --git a/tools-ssd_workflow/admin/consistency_checks-locate_variable_in_sql.py b/tools-ssd_workflow/admin/consistency_checks-locate_variable_in_sql.py index 094955e..652cc41 100755 --- a/tools-ssd_workflow/admin/consistency_checks-locate_variable_in_sql.py +++ b/tools-ssd_workflow/admin/consistency_checks-locate_variable_in_sql.py @@ -16,7 +16,7 @@ ] -variable_name = 'clap_cla_placement_end' # var name to search +variable_name = 'post_code' # var name to search variable_stem = '' # stem to search variable_suffix = '' # suffix to search search_file_type = '.sql' # or .py or .txt