Skip to content

Commit

Permalink
[BIA-1287] Updates StudentCharacteristic joins on StudentSchoolDemogr…
Browse files Browse the repository at this point in the history
…aphicsBridge. (#229)

* Updates StudentCharacteristic joins on StudentSchoolDemographicsBridge.

* Adds data and new unit tests for the new scenario.
  • Loading branch information
DavidJGapCR authored Dec 20, 2022
1 parent c659826 commit e13732f
Show file tree
Hide file tree
Showing 12 changed files with 2,299 additions and 976 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
-- SPDX-License-Identifier: Apache-2.0
-- Licensed to the Ed-Fi Alliance under one or more agreements.
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
-- See the LICENSE and NOTICES files in the project root for more information.

IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'analytics' AND TABLE_NAME = 'StudentSchoolDemographicsBridge')
BEGIN
DROP VIEW analytics.StudentSchoolDemographicsBridge
END
GO

CREATE VIEW analytics.StudentSchoolDemographicsBridge AS
WITH StudentSchoolDemographics AS (
SELECT
CONCAT('CohortYear:', SchoolYearType.SchoolYear, '-', Descriptor.CodeValue
,'-', Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('CohortYear:', SchoolYearType.SchoolYear, '-', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationCohortYear
INNER JOIN
edfi.SchoolYearType ON
StudentEducationOrganizationAssociationCohortYear.SchoolYear = SchoolYearType.SchoolYear
INNER JOIN
edfi.CohortYearTypeDescriptor ON
StudentEducationOrganizationAssociationCohortYear.CohortYearTypeDescriptorId = CohortYearTypeDescriptor.CohortYearTypeDescriptorId
INNER JOIN
edfi.Descriptor ON
CohortYearTypeDescriptor.CohortYearTypeDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationCohortYear.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationCohortYear.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationCohortYear.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('Disability:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('Disability:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationDisability
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationDisability.DisabilityDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationDisability.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationDisability.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationDisability.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('DisabilityDesignation:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('DisabilityDesignation:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationDisabilityDesignation
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationDisabilityDesignation.DisabilityDesignationDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationDisabilityDesignation.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationDisabilityDesignation.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationDisabilityDesignation.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('Language:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('Language:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationLanguage
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationLanguage.LanguageDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationLanguage.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationLanguage.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationLanguage.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('LanguageUse:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('LanguageUse:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationLanguageUse
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationLanguageUse.LanguageUseDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationLanguageUse.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationLanguageUse.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationLanguageUse.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('Race:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('Race:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationRace
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationRace.RaceDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationRace.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationRace.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationRace.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('TribalAffiliation:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('TribalAffiliation:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationTribalAffiliation
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationTribalAffiliation.TribalAffiliationDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationTribalAffiliation.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationTribalAffiliation.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationTribalAffiliation.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
UNION ALL
SELECT
CONCAT('StudentCharacteristic:', Descriptor.CodeValue,
'-', Student.StudentUniqueId, '-',StudentSchoolAssociation.SchoolId) AS ​StudentSchoolDemographicBridgeKey,
CONCAT(Student.StudentUniqueId, '-', StudentSchoolAssociation.SchoolId) AS StudentSchoolKey,
CONCAT('StudentCharacteristic:', Descriptor.CodeValue) AS DemographicKey,
StudentSchoolAssociation.ExitWithdrawDate
FROM
edfi.StudentEducationOrganizationAssociationStudentCharacteristic
INNER JOIN
edfi.Descriptor ON
StudentEducationOrganizationAssociationStudentCharacteristic.StudentCharacteristicDescriptorId = Descriptor.DescriptorId
INNER JOIN
edfi.School ON
StudentEducationOrganizationAssociationStudentCharacteristic.EducationOrganizationId = School.SchoolId
INNER JOIN
edfi.StudentEducationOrganizationAssociation ON
StudentEducationOrganizationAssociation.StudentUSI = StudentEducationOrganizationAssociationStudentCharacteristic.StudentUSI
AND StudentEducationOrganizationAssociation.EducationOrganizationId =StudentEducationOrganizationAssociationStudentCharacteristic.EducationOrganizationId
INNER JOIN
edfi.StudentSchoolAssociation ON
StudentSchoolAssociation.StudentUSI = StudentEducationOrganizationAssociation.StudentUSI
AND School.SchoolId = StudentSchoolAssociation.SchoolId
INNER JOIN
edfi.Student ON
Student.StudentUsi = StudentEducationOrganizationAssociation.StudentUSI
LEFT JOIN edfi.StudentEducationOrganizationAssociationStudentCharacteristicPeriod ON
StudentEducationOrganizationAssociationStudentCharacteristicPeriod.EducationOrganizationID=StudentEducationOrganizationAssociationStudentCharacteristic.EducationOrganizationID
AND StudentEducationOrganizationAssociationStudentCharacteristicPeriod.StudentUSI=StudentEducationOrganizationAssociationStudentCharacteristic.StudentUSI
AND StudentEducationOrganizationAssociationStudentCharacteristicPeriod.StudentCharacteristicDescriptorId=StudentEducationOrganizationAssociationStudentCharacteristic.StudentCharacteristicDescriptorId
WHERE StudentEducationOrganizationAssociationStudentCharacteristicPeriod.EndDate IS NULL OR StudentEducationOrganizationAssociationStudentCharacteristicPeriod.EndDate > GETDATE()
)
SELECT
StudentSchoolDemographicBridgeKey,
StudentSchoolKey,
DemographicKey
FROM StudentSchoolDemographics
WHERE ExitWithdrawDate IS NULL OR ExitWithdrawDate > GETDATE();
GO
Loading

0 comments on commit e13732f

Please sign in to comment.