Skip to content

Commit 7ff6d51

Browse files
committed
Re-implemented data pipeline spec coercion on field: [disability] 4 char max
1 parent 1118bd2 commit 7ff6d51

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sql_json_query/populate_ssd_api_data_staging_2016.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ RawPayloads AS (
713713
JOIN EligibleBySpec elig ON elig.pers_person_id = p.pers_person_id -- either unborn, or 26th bday falls on or after @ea_cohort_window_start (deceased not filtered)
714714
JOIN SpecInclusion si ON si.person_id = p.pers_person_id -- appearing in ActiveReferral, WaitingAssessment, CIN plan, CP plan, LAC, Care leavers 16 to 25, Disabled
715715

716-
/* Disabilities array, return NULL when no codes */
716+
/* Disabilities array, return NULL when no codes, truncate codes to 4 chars max */
717717
OUTER APPLY (
718718
SELECT
719719
CASE
@@ -729,12 +729,12 @@ RawPayloads AS (
729729
SELECT N',' + QUOTENAME(u.code, '"')
730730
FROM (
731731
SELECT TOP (12)
732-
UPPER(LTRIM(RTRIM(d2.disa_disability_code))) AS code
732+
LEFT(UPPER(LTRIM(RTRIM(d2.disa_disability_code))), 4) AS code
733733
FROM ssd_disability d2
734734
WHERE d2.disa_person_id = p.pers_person_id
735735
AND NULLIF(LTRIM(RTRIM(d2.disa_disability_code)), '') IS NOT NULL
736-
GROUP BY UPPER(LTRIM(RTRIM(d2.disa_disability_code)))
737-
ORDER BY UPPER(LTRIM(RTRIM(d2.disa_disability_code)))
736+
GROUP BY LEFT(UPPER(LTRIM(RTRIM(d2.disa_disability_code))), 4)
737+
ORDER BY LEFT(UPPER(LTRIM(RTRIM(d2.disa_disability_code))), 4)
738738
) u
739739
FOR XML PATH(''), TYPE
740740
).value('.', 'nvarchar(max)'), 1, 1, N'')
@@ -744,6 +744,7 @@ RawPayloads AS (
744744
END AS disabilities
745745
) AS disab
746746

747+
747748
/* SDQ prebuild, reuse once, and flag presence */
748749
OUTER APPLY (
749750
SELECT

0 commit comments

Comments
 (0)