Skip to content

Commit

Permalink
CAST(person_id) applied & multiple minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robjharrison committed Jul 17, 2024
1 parent 3757dd9 commit 40407ec
Show file tree
Hide file tree
Showing 5 changed files with 18,146 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Currently in [REVIEW]
-- Run SSD into Temporary OR Persistent extract structure
--
DECLARE @Run_SSD_As_Temporary_Tables BIT;
SET @Run_SSD_As_Temporary_Tables = 1; -- 1==Single use SSD extract uses tempdb..# | 2==Persistent SSD table set up
SET @Run_SSD_As_Temporary_Tables = 0; -- 1==Single use SSD extract uses tempdb..# | 0==Persistent SSD table set up



Expand Down Expand Up @@ -83,14 +83,14 @@ BEGIN
-- extracting into non-persistent temp tables
-- no constraint clean-up required

PRINT 'Establishing SSD in temporary db namespace, prefixed as #ssd_' ;
PRINT CHAR(13) + CHAR(10) + 'Establishing SSD in temporary db namespace, prefixed as #ssd_' + CHAR(13) + CHAR(10);
END
ELSE
BEGIN
-- extracting into persistent|perm tables
-- therefore some potential clean-up need from any previous implementations

PRINT 'Establishing SSD as persistant tables, prefixed as ssd_' ;
PRINT CHAR(13) + CHAR(10) + 'Establishing SSD as persistant tables, prefixed as ssd_' + CHAR(13) + CHAR(10);

/* START drop all ssd_development. schema constraints */
DECLARE @sql NVARCHAR(MAX) = N'';
Expand Down Expand Up @@ -146,7 +146,7 @@ DECLARE @LastSept30th DATE;

/*
=============================================================================
Object Name: ssd_version
Object Name: ssd_version_log
Description: maintain SSD versioning meta data
Author: D2I
Version: 1.0
Expand All @@ -157,16 +157,16 @@ Dependencies:
=============================================================================
*/
-- [TESTING] Create marker
SET @TableName = N'ssd_version';
SET @TableName = N'ssd_version_log';
PRINT 'Creating table: ' + @TableName;


-- Check if exists, & drop
IF OBJECT_ID('ssd_development.ssd_version', 'U') IS NOT NULL DROP TABLE ssd_development.ssd_version;
IF OBJECT_ID('tempdb..#ssd_version', 'U') IS NOT NULL DROP TABLE #ssd_version;
IF OBJECT_ID('ssd_development.ssd_version_log', 'U') IS NOT NULL DROP TABLE ssd_development.ssd_version_log;
IF OBJECT_ID('tempdb..#ssd_version_log', 'U') IS NOT NULL DROP TABLE #ssd_version_log;

-- create versioning information object
CREATE TABLE ssd_development.ssd_version (
CREATE TABLE ssd_development.ssd_version_log (
version_number NVARCHAR(10) NOT NULL, -- version num (e.g., "1.0.0")
release_date DATE NOT NULL, -- date of version release
description NVARCHAR(100), -- brief description of version
Expand All @@ -177,22 +177,22 @@ CREATE TABLE ssd_development.ssd_version (
);

-- ensure any previous current-version flag is set to 0 (not current), before adding new current version
UPDATE ssd_development.ssd_version SET is_current = 0 WHERE is_current = 1;
UPDATE ssd_development.ssd_version_log SET is_current = 0 WHERE is_current = 1;


-- insert & update current version (using MAJOR.MINOR.PATCH)
INSERT INTO ssd_development.ssd_version
INSERT INTO ssd_development.ssd_version_log
(version_number, release_date, description, is_current, created_by, impact_description)
VALUES
('1.1.8', GETDATE(), 'admin table creation logging process defined', 1, 'admin', '');


-- historic versioning log data
INSERT INTO ssd_development.ssd_version (version_number, release_date, description, is_current, created_by, impact_description)
INSERT INTO ssd_development.ssd_version_log (version_number, release_date, description, is_current, created_by, impact_description)
VALUES
('1.0.0', '2023-01-01', 'Initial alpha release (Phase 1 end)', 0, 'admin', ''),
('1.1.1', '2024-06-26', 'Minor updates with revised assessment_factors', 0, 'admin', 'Revised JSON Array structure implemented for CiN'),
('1.1.2', '2024-06-26', 'ssd_version obj added and minor patch fixes', 0, 'admin', 'Provide mech for extract ver visibility'),
('1.1.2', '2024-06-26', 'ssd_version_log obj added and minor patch fixes', 0, 'admin', 'Provide mech for extract ver visibility'),
('1.1.3', '2024-06-27', 'Revised filtering on ssd_person', 0, 'admin', 'Check IS_CLIENT flag first'),
('1.1.4', '2024-07-01', 'ssd_department obj added', 0, 'admin', 'Increased seperation btw professionals and depts enabling history'),
('1.1.5', '2024-07-09', 'ssd_person involvements history', 0, 'admin', 'Improved consistency on _json fields, clean-up involvements_history_json'),
Expand Down Expand Up @@ -923,7 +923,8 @@ PRINT 'Test Progress Counter: ' + CAST(@TestProgress AS NVARCHAR(10));
Object Name: ssd_contacts
Description:
Author: D2I
Version: 1.0
Version: 1.1
1.0 fc.OUTCOME_COMMENTS added to cont_contact_outcome_json #DtoI-1796 160724 RH
0.2 cont_contact_source_code field name edit 260124 RH
0.1 cont_contact_source_desc added RH
Status: [R]elease
Expand Down Expand Up @@ -983,7 +984,8 @@ SELECT
ISNULL(fc.OUTCOME_ADVICE_FLAG, '') AS ADVICE_FLAG,
ISNULL(fc.OUTCOME_MISSING_FLAG, '') AS MISSING_FLAG,
ISNULL(fc.OUTCOME_OLA_CP_FLAG, '') AS OLA_CP_FLAG,
ISNULL(fc.OTHER_OUTCOMES_EXIST_FLAG, '') AS OTHER_OUTCOMES_EXIST_FLAG
ISNULL(fc.OTHER_OUTCOMES_EXIST_FLAG, '') AS OTHER_OUTCOMES_EXIST_FLAG,
ISNULL(fc.OUTCOME_COMMENTS, '') AS COMMENTS
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
) AS cont_contact_outcome_json
FROM
Expand Down Expand Up @@ -1114,7 +1116,8 @@ PRINT 'Test Progress Counter: ' + CAST(@TestProgress AS NVARCHAR(10));
Object Name: ssd_cin_episodes
Description:
Author: D2I
Version: 1.2
Version: 1.3
1.2: rem NFA_OUTCOME from cine_referral_outcome_json #DtoI-1796 160724 RH
1.1: Roll-back to use of worker_id #DtoI-1755 040624 RH
0.3 primary _need suffix of _code added #DtoI-1738 2105 RH
0.2: primary _need type/size adjustment from revised spec 160524 RH
Expand Down Expand Up @@ -1180,15 +1183,17 @@ SELECT
-- SSD standard
-- all keys in structure regardless of data presence ISNULL() not NULLIF()
ISNULL(fr.OUTCOME_SINGLE_ASSESSMENT_FLAG, '') AS SINGLE_ASSESSMENT_FLAG,
ISNULL(fr.OUTCOME_NFA_FLAG, '') AS NFA_FLAG,
-- ISNULL(fr.OUTCOME_NFA_FLAG, '') AS NFA_FLAG,
ISNULL(fr.OUTCOME_STRATEGY_DISCUSSION_FLAG, '') AS STRATEGY_DISCUSSION_FLAG,
ISNULL(fr.OUTCOME_CLA_REQUEST_FLAG, '') AS CLA_REQUEST_FLAG,
ISNULL(fr.OUTCOME_NON_AGENCY_ADOPTION_FLAG, '') AS NON_AGENCY_ADOPTION_FLAG,
ISNULL(fr.OUTCOME_PRIVATE_FOSTERING_FLAG, '') AS PRIVATE_FOSTERING_FLAG,
ISNULL(fr.OUTCOME_CP_TRANSFER_IN_FLAG, '') AS CP_TRANSFER_IN_FLAG,
ISNULL(fr.OUTCOME_CP_CONFERENCE_FLAG, '') AS CP_CONFERENCE_FLAG,
ISNULL(fr.OUTCOME_CARE_LEAVER_FLAG, '') AS CARE_LEAVER_FLAG,
ISNULL(fr.OTHER_OUTCOMES_EXIST_FLAG, '') AS OTHER_OUTCOMES_EXIST_FLAG
ISNULL(fr.OTHER_OUTCOMES_EXIST_FLAG, '') AS OTHER_OUTCOMES_EXIST_FLAG,
ISNULL(fr.TOTAL_NUMBER_OF_OUTCOMES, '') AS NUMBER_OF_OUTCOMES,
ISNULL(fr.OUTCOME_COMMENTS, '') AS COMMENTS
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
) AS cine_referral_outcome_json,
fr.OUTCOME_NFA_FLAG,
Expand Down Expand Up @@ -1961,9 +1966,9 @@ BEGIN
ALTER TABLE ssd_development.ssd_initial_cp_conference ADD CONSTRAINT FK_icpc_person_id
FOREIGN KEY (icpc_person_id) REFERENCES ssd_development.ssd_person(pers_person_id);

-- -- [TESTING]
-- ALTER TABLE ssd_development.ssd_initial_cp_conference ADD CONSTRAINT FK_icpc_referral_id
-- FOREIGN KEY (icpc_referral_id) REFERENCES ssd_development.ssd_cin_episodes(cine_referral_id);
-- [TESTING] #DtoI-1769
ALTER TABLE ssd_development.ssd_initial_cp_conference ADD CONSTRAINT FK_icpc_referral_id
FOREIGN KEY (icpc_referral_id) REFERENCES ssd_development.ssd_cin_episodes(cine_referral_id);


-- Create index(es)
Expand Down Expand Up @@ -5590,7 +5595,7 @@ PRINT 'Test Progress Counter: ' + CAST(@TestProgress AS NVARCHAR(10));


-- output for ref most recent/current ssd version and last update
SELECT * FROM ssd_development.ssd_version WHERE is_current = 1;
SELECT * FROM ssd_development.ssd_version_log WHERE is_current = 1;



Expand Down Expand Up @@ -5642,11 +5647,11 @@ END


-- Check if exists, & drop
IF OBJECT_ID('ssd_development.ssd_table_creation_log', 'U') IS NOT NULL DROP TABLE ssd_development.ssd_table_creation_log;
IF OBJECT_ID('tempdb..#ssd_table_creation_log', 'U') IS NOT NULL DROP TABLE #ssd_table_creation_log;
IF OBJECT_ID('ssd_development.ssd_extract_log', 'U') IS NOT NULL DROP TABLE ssd_development.ssd_extract_log;
IF OBJECT_ID('tempdb..#ssd_extract_log', 'U') IS NOT NULL DROP TABLE #ssd_extract_log;

-- Create logging structure
CREATE TABLE ssd_development.ssd_table_creation_log (
CREATE TABLE ssd_development.ssd_extract_log (
table_name NVARCHAR(255),
schema_name NVARCHAR(255),
status NVARCHAR(50), -- status code includes error output + schema.table_name
Expand Down Expand Up @@ -5732,7 +5737,7 @@ SELECT 'ssd_sdq_scores' UNION ALL
SELECT 'ssd_sen_need' UNION ALL
SELECT 'ssd_send' UNION ALL
SELECT 'ssd_voice_of_child' UNION ALL
SELECT 'ssd_version'; -- Admin table
SELECT 'ssd_version_log'; -- Admin table

OPEN table_cursor;

Expand Down Expand Up @@ -5783,7 +5788,7 @@ BEGIN


-- Insert log entry
INSERT INTO ssd_development.ssd_table_creation_log (
INSERT INTO ssd_development.ssd_extract_log (
table_name,
schema_name,
status,
Expand All @@ -5800,7 +5805,7 @@ BEGIN
BEGIN CATCH
-- Log error
SET @error_message = ERROR_MESSAGE();
INSERT INTO ssd_development.ssd_table_creation_log (table_name, schema_name, status, rows_inserted, table_size_kb, has_pk, has_fks, index_count, additional_detail, error_message)
INSERT INTO ssd_development.ssd_extract_log (table_name, schema_name, status, rows_inserted, table_size_kb, has_pk, has_fks, index_count, additional_detail, error_message)
VALUES (@table_name, @schema_name, 'Error', 0, NULL, 0, 0, 0, NULL, @error_message);
END CATCH;

Expand All @@ -5815,7 +5820,7 @@ SET @sql = N'';


-- Forming part of the extract admin results output
SELECT * FROM ssd_development.ssd_table_creation_log ORDER BY rows_inserted DESC;
SELECT * FROM ssd_development.ssd_extract_log ORDER BY rows_inserted DESC;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4449,7 +4449,6 @@ SELECT
THEN fi.COMMENTS
END -- if fi.COMMENTS is NULL, results in NULL
), 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 40407ec

Please sign in to comment.