Skip to content

Commit

Permalink
ssd_involvements _team truncation at 255 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robjharrison committed Jun 11, 2024
1 parent 70d9c47 commit 6594205
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 119 deletions.
14 changes: 7 additions & 7 deletions cms_ssd_extract_sql/cmsname_dbtype_ssd_template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2934,7 +2934,7 @@ CREATE TABLE ssd_development.ssd_involvements (
invo_involvements_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"INVO005A"}
invo_professional_id NVARCHAR(48), -- metadata={"item_ref":"INVO006A"}
invo_professional_role_id NVARCHAR(200), -- metadata={"item_ref":"INVO007A"}
invo_professional_team NVARCHAR(1000), -- metadata={"item_ref":"INVO009A"}
invo_professional_team NVARCHAR(255), -- metadata={"item_ref":"INVO009A", "info":"This is a truncated field at 255"}
invo_person_id NVARCHAR(48), -- metadata={"item_ref":"INVO011A"}
invo_involvement_start_date DATETIME, -- metadata={"item_ref":"INVO002A"}
invo_involvement_end_date DATETIME, -- metadata={"item_ref":"INVO003A"}
Expand All @@ -2959,12 +2959,12 @@ INSERT INTO ssd_involvements (
-- EXTRACT SELECT


WHERE EXISTS
(
SELECT 1
FROM ssd_person p
WHERE p.pers_person_id = fi.DIM_PERSON_ID
);
-- WHERE EXISTS
-- (
-- SELECT 1
-- FROM ssd_person p
-- WHERE p.pers_person_id = fi.DIM_PERSON_ID
-- );



Expand Down
128 changes: 62 additions & 66 deletions cms_ssd_extract_sql/mosaic/populate_ssd_data_warehouse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3515,7 +3515,17 @@ Version: 1.0
Status: AwaitingReview
Remarks:
Remarks: The list of allowed identifier_type codes are:
['Case Number',
'Unique Pupil Number',
'NHS Number',
'Home Office Registration',
'National Insurance Number',
'YOT Number',
'Court Case Number',
'RAA ID',
'Incident ID']
To have any further codes agreed into the standard, issue a change request
Dependencies:
Expand Down Expand Up @@ -6425,70 +6435,6 @@ go



--[REVIEW] added RH 290424
if object_id('tempdb..##populate_ssd_linked_identifiers') is not null
drop procedure ##populate_ssd_linked_identifiers
go
--
create procedure ##populate_ssd_linked_identifiers
begin
/*
=============================================================================
Object Name: ssd_linked_identifiers
Description:
Author: D2I
Version: 1.0
Status: AwaitingReview
Remarks: The list of allowed identifier_type codes are:
['Case Number',
'Unique Pupil Number',
'NHS Number',
'Home Office Registration',
'National Insurance Number',
'YOT Number',
'Court Case Number',
'RAA ID',
'Incident ID']
To have any further codes agreed into the standard, issue a change request
Dependencies:
- Yet to be defined
=============================================================================
*/
begin try
--set nocount on
--
IF OBJECT_ID('tempdb..##ssd_linked_identifiers') IS NOT NULL
DROP TABLE ##ssd_linked_identifiers
--
create table ##ssd_linked_identifiers (
link_table_id nvarchar(48) primary key default NEWID(),
link_person_id nvarchar(48),
link_identifier_type nvarchar(100),
link_identifier_value nvarchar(100),
link_valid_from_date datetime,
link_valid_to_date datetime
)
--
return 0
end try
begin catch
-- Record error details in log
declare @v_error_number int,
@v_error_message nvarchar(4000)
select
@v_error_number = error_number(),
@v_error_message = error_message()
--
return @v_error_number
end catch
go
--






-- [REVIEW] added RH 290424
if object_id('tempdb..##populate_ssd_s251_finance') is not null
drop procedure ##populate_ssd_s251_finance
Expand Down Expand Up @@ -6951,6 +6897,55 @@ end catch
go
--

--[REVIEW] added RH 100624
if object_id('tempdb..##populate_ssd_department') is not null
drop procedure ##populate_ssd_department
go
--
create procedure ##populate_ssd_department
begin
/*
=============================================================================
Object Name: ssd_department
Description: In progress/To be developed
Author: D2I
Version: 0.1
Status: Development
Remarks: New object - source data to be confirmed
Dependencies:
- Yet to be defined
-
=============================================================================
*/
begin try
--set nocount on
--
IF OBJECT_ID('tempdb..##ssd_department') IS NOT NULL
DROP TABLE ##ssd_department
--
create table ##ssd_department (
dept_team_id NVARCHAR(48) primary key,
dept_team_name NVARCHAR(255),
dept_team_parent_id NVARCHAR(48),
dept_team_parent_name NVARCHAR(255)
)
--
return 0
end try
begin catch
-- Record error details in log
declare @v_error_number int,
@v_error_message nvarchar(4000)
select
@v_error_number = error_number(),
@v_error_message = error_message()
--
return @v_error_number
end catch
go
--




--
Expand Down Expand Up @@ -6992,6 +6987,7 @@ begin

-- end placeholder tables

exec ##ssd_department; -- NEW/Development [REVIEW] added RH 100624 (source data not yet set up)

exec ##populate_ssd_care_leavers;
exec ##populate_ssd_assessment_factors @start_date, @end_date;
Expand All @@ -7007,7 +7003,7 @@ begin
exec ##populate_ssd_initial_cp_conference @start_date, @end_date;
exec ##populate_ssd_involvements @start_date, @end_date;
exec ##populate_ssd_legal_status @start_date, @end_date;
exec ##populate_ssd_linked_identifiers; -- AwaitingReview
exec ##populate_ssd_linked_identifiers;
exec ##populate_ssd_missing @start_date, @end_date;
exec ##populate_ssd_mother;
exec ##populate_ssd_permanence;
Expand Down
2 changes: 1 addition & 1 deletion cms_ssd_extract_sql/mosaic/ssd_cp_plans_essex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cms_ssd_extract_sql/mosaic/ssd_cp_plans_tag_dw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ select
and
dbo.future(ref.CLOSURE_DATE)>= cpp.REGISTRATION_START_DATE
) 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,
Expand Down
2 changes: 1 addition & 1 deletion cms_ssd_extract_sql/mosaic/ssd_cp_visits_dm_kt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ from
(
select
stp.person_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_ 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(
(
Expand Down
10 changes: 10 additions & 0 deletions cms_ssd_extract_sql/mosaic/ssd_department_tag_dw.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- placeholder file. source data unknown - for ref TeamMosaic

select
null dept_team_id, -- [REVIEW]
null dept_team_name, -- [REVIEW]
null dept_team_parent_id, -- [REVIEW]
null dept_team_parent_name -- [REVIEW]

from
dm_xxxx dept -- [REVIEW]
81 changes: 44 additions & 37 deletions cms_ssd_extract_sql/systemc/liquidlogic_sqlserver_perm_ssd.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2905,15 +2905,13 @@ WHERE
AND
ffa.ANSWER IS NOT NULL



-- Create structure
CREATE TABLE ssd_development.ssd_cla_previous_permanence (
lapp_table_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"LAPP001A"}
lapp_person_id NVARCHAR(48), -- metadata={"item_ref":"LAPP002A"}
lapp_previous_permanence_option NVARCHAR(200), -- metadata={"item_ref":"LAPP004A"}
lapp_previous_permanence_la NVARCHAR(100), -- metadata={"item_ref":"LAPP005A"}
lapp_previous_permanence_order_date NVARCHAR(100) -- metadata={"item_ref":"LAPP003A", "info": "must remain NVARCHAR"}
lapp_table_id NVARCHAR(48) PRIMARY KEY,
lapp_person_id NVARCHAR(48),
lapp_previous_permanence_option NVARCHAR(200),
lapp_previous_permanence_la NVARCHAR(100),
lapp_previous_permanence_order_date NVARCHAR(10)
);

-- Insert data
Expand All @@ -2923,50 +2921,52 @@ INSERT INTO ssd_cla_previous_permanence (
lapp_previous_permanence_option,
lapp_previous_permanence_la,
lapp_previous_permanence_order_date

)
SELECT
tmp_ffa.FACT_FORM_ID AS lapp_table_id,
ff.DIM_PERSON_ID AS lapp_person_id,
COALESCE(MAX(ISNULL(CASE WHEN tmp_ffa.ANSWER_NO = 'PREVADOPTORD' THEN tmp_ffa.ANSWER END, '')), NULL) AS lapp_previous_permanence_option,
COALESCE(MAX(ISNULL(CASE WHEN tmp_ffa.ANSWER_NO = 'INENG' THEN tmp_ffa.ANSWER END, '')), NULL) AS lapp_previous_permanence_la,
COALESCE(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'PREVADOPTORD' THEN tmp_ffa.ANSWER END), NULL) AS lapp_previous_permanence_option,
COALESCE(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'INENG' THEN tmp_ffa.ANSWER END), NULL) AS lapp_previous_permanence_la,
CASE
WHEN PATINDEX('%[^0-9]%', ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERDATE' THEN tmp_ffa.ANSWER END), '')) = 0 AND
CAST(ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERDATE' THEN tmp_ffa.ANSWER END), '') AS INT) BETWEEN 1 AND 31 THEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERDATE' THEN tmp_ffa.ANSWER END), '')
WHEN PATINDEX('%[^0-9]%', MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERDATE' THEN tmp_ffa.ANSWER END)) = 0 AND
CAST(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERDATE' THEN tmp_ffa.ANSWER END) AS INT) BETWEEN 1 AND 31 THEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERDATE' THEN tmp_ffa.ANSWER END)
ELSE 'zz'
END + '/' +
-- Adjusted CASE statement for ORDERMONTH to convert month names to numbers
CASE
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('January', 'Jan') THEN '01'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('February', 'Feb') THEN '02'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('March', 'Mar') THEN '03'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('April', 'Apr') THEN '04'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('May') THEN '05'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('June', 'Jun') THEN '06'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('July', 'Jul') THEN '07'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('August', 'Aug') THEN '08'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('September', 'Sep') THEN '09'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('October', 'Oct') THEN '10'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('November', 'Nov') THEN '11'
WHEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END), '') IN ('December', 'Dec') THEN '12'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('January', 'Jan') THEN '01'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('February', 'Feb') THEN '02'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('March', 'Mar') THEN '03'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('April', 'Apr') THEN '04'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('May') THEN '05'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('June', 'Jun') THEN '06'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('July', 'Jul') THEN '07'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('August', 'Aug') THEN '08'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('September', 'Sep') THEN '09'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('October', 'Oct') THEN '10'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('November', 'Nov') THEN '11'
WHEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERMONTH' THEN tmp_ffa.ANSWER END) IN ('December', 'Dec') THEN '12'
ELSE 'zz' -- also handles 'unknown' string
END + '/' +
CASE
WHEN PATINDEX('%[^0-9]%', ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERYEAR' THEN tmp_ffa.ANSWER END), '')) = 0 THEN ISNULL(MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERYEAR' THEN tmp_ffa.ANSWER END), '')
WHEN PATINDEX('%[^0-9]%', MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERYEAR' THEN tmp_ffa.ANSWER END)) = 0 THEN MAX(CASE WHEN tmp_ffa.ANSWER_NO = 'ORDERYEAR' THEN tmp_ffa.ANSWER END)
ELSE 'zzzz'
END
AS lapp_previous_permanence_order_date

FROM
#ssd_TMP_PRE_previous_permanence tmp_ffa
JOIN
Child_Social.FACT_FORMS ff ON tmp_ffa.FACT_FORM_ID = ff.FACT_FORM_ID


AND EXISTS ( -- only ssd relevant records
SELECT 1
FROM ssd_person p
FROM #ssd_person p
WHERE p.pers_person_id = ff.DIM_PERSON_ID
)

)
GROUP BY tmp_ffa.FACT_FORM_ID, ff.FACT_FORM_ID, ff.DIM_PERSON_ID;


-- -- Add constraint(s)
-- ALTER TABLE ssd_cla_previous_permanence ADD CONSTRAINT FK_lapp_person_id
Expand Down Expand Up @@ -3036,9 +3036,9 @@ LatestResponses AS (
SELECT -- Now add the answered_date (only indirectly of use here/cross referencing)
mrqr.DIM_PERSON_ID,
mrqr.ANSWER_NO,
mrqr.MaxFormID AS FACT_FORM_ID,
mrqr.MaxFormID AS FACT_FORM_ID,
ffa.ANSWER,
ffa.ANSWERED_DTTM AS LatestResponseDate
ffa.ANSWERED_DTTM AS LatestResponseDate
FROM
MostRecentQuestionResponse mrqr
JOIN
Expand Down Expand Up @@ -3105,7 +3105,6 @@ SELECT
FROM
Child_Social.FACT_CARE_PLANS AS fcp


WHERE fcp.DIM_LOOKUP_PLAN_STATUS_ID_CODE = 'A';


Expand Down Expand Up @@ -4001,10 +4000,16 @@ PRINT 'Test Progress Counter: ' + CAST(@TestProgress AS NVARCHAR(10));
Object Name: ssd_involvements
Description:
Author: D2I
Version: 1.0
Version: 1.1
1.0: Trancated professional_team field IF comment data populates 110624 RH
0.9: added person_id and changed source of professional_team 090424 JH
Status: [R]elease
Remarks:
Remarks: Regarding the increased size/len on invo_professional_team
The (truncated)COMMENTS field is only used if:
WORKER_HISTORY_DEPARTMENT_DESC is NULL.
DEPARTMENT_NAME is NULL.
GROUP_NAME is NULL.
COMMENTS contains the keyword %WORKER% or %ALLOC%.
Dependencies:
- ssd_professionals
- FACT_INVOLVEMENTS
Expand All @@ -4024,7 +4029,7 @@ CREATE TABLE ssd_development.ssd_involvements (
invo_involvements_id NVARCHAR(48) PRIMARY KEY, -- metadata={"item_ref":"INVO005A"}
invo_professional_id NVARCHAR(48), -- metadata={"item_ref":"INVO006A"}
invo_professional_role_id NVARCHAR(200), -- metadata={"item_ref":"INVO007A"}
invo_professional_team NVARCHAR(1000), -- metadata={"item_ref":"INVO009A"}
invo_professional_team NVARCHAR(255), -- metadata={"item_ref":"INVO009A", "info":"This is a truncated field at 255"}
invo_person_id NVARCHAR(48), -- metadata={"item_ref":"INVO011A"}
invo_involvement_start_date DATETIME, -- metadata={"item_ref":"INVO002A"}
invo_involvement_end_date DATETIME, -- metadata={"item_ref":"INVO003A"}
Expand All @@ -4049,16 +4054,18 @@ SELECT
fi.DIM_WORKER_ID AS invo_professional_id,
fi.DIM_LOOKUP_INVOLVEMENT_TYPE_DESC AS invo_professional_role_id,
-- use first non-NULL value for prof team, in order of : i)dept, ii)grp, or iii)relevant comment
COALESCE(
LEFT(
COALESCE(
fi.FACT_WORKER_HISTORY_DEPARTMENT_DESC, -- prev/relevant dept name if available
fi.DIM_DEPARTMENT_NAME, -- otherwise, use existing dept name
fi.DIM_GROUP_NAME, -- then, use wider grp name if the above are NULL

CASE -- if still NULL, refer into comments data
CASE -- if still NULL, refer into comments data but only when...
WHEN fi.COMMENTS LIKE '%WORKER%' OR fi.COMMENTS LIKE '%ALLOC%' -- refer to comments for specific keywords
THEN fi.COMMENTS
END -- if fi.COMMENTS is NULL, results in NULL
) AS invo_professional_team,
), 255) AS invo_professional_team,

fi.DIM_PERSON_ID AS invo_person_id,
fi.START_DTTM AS invo_involvement_start_date,
fi.END_DTTM AS invo_involvement_end_date,
Expand Down
Loading

0 comments on commit 6594205

Please sign in to comment.