Skip to content

Commit 1a62b22

Browse files
authored
Merge pull request #3 from edanalytics/bugfix/student_keying
Bugfix/student keying
2 parents 2c4b637 + 6bb556f commit 1a62b22

File tree

3 files changed

+85
-7
lines changed

3 files changed

+85
-7
lines changed

README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,75 @@ OneRoster CSV standard in the EDU framework
2626
database. The tables are _not_ specified with case-sensitivity, but files
2727
created from them should be.
2828

29+
## Unique Keys
30+
OneRoster uses the term `SourcedId` to refer to the unique key of all files in the OneRoster standard. This implementation uses the following methodology and principles:
31+
- All unique keys are the MD5 hash of a concatenation of Natural key values, separated by hyphens (`-`).
32+
- For clarity/transparency, the literal string value that is hashed is included in the file as an extension column called `metadata.edu.natural_key`
33+
- By default, all natural keys are prefixed with `tenant_code`, which is a human-readable string identifying a district. This can be overridden to be a constant string if desired using the variable `oneroster:id_prefix`
34+
- Any natural key component that is non-integer is cast to lower-case for consistency
35+
36+
The natural keys for each resource are defined in the macro [gen_sourced_id](macros/gen_sourced_id.sql), but are written out below for clarity.
37+
38+
### Org
39+
- tenant_code (or constant string, if configured)
40+
- ed_org_id (`sea_id`, `lea_id`, or `school_id`, for the respective org-types)
41+
42+
### Users
43+
- tenant_code (or constant string, if configured)
44+
- The literal string `STU`, `STA`, or `PAR`, for students, staff, or parents
45+
- `student_unique_id`, `staff_unique_id`, or `parent_unique_id`, respectively
46+
- Note that this is the unique person identifier configured in Ed-Fi, and exactly which type of ID this is can vary across implementations.
47+
48+
### Sessions
49+
For terms/semesters/etc, this is a school-specific session definition, taken
50+
from Ed-Fi's definition of Sessions.
51+
- tenant_code (or constant string, if configured)
52+
- school_id
53+
- session_name
54+
55+
For school years, each district has its own definition:
56+
- tenant_code (or constant string, if configured)
57+
- lea_id
58+
- school_year (4 digit number representing the Spring year, e.g. for 2023-2024, `2024`)
59+
60+
### Courses
61+
- tenant_code (or constant string, if configured)
62+
- lea_id
63+
- course_code
64+
65+
### Classes
66+
- tenant_code (or constant string, if configured)
67+
- school_id
68+
- lower(section_id)
69+
- lower(session_name)
70+
71+
Section ID and Session Name are cast to lower case to ensure consistency.
72+
Session is included in the Class definition to align with how Ed-Fi thinks about
73+
Sections, as well as because Ed-Fi Sessions are not date-exclusive and using dates
74+
alone may not uniquely identify the session in which a Section is offered.
75+
76+
### Enrollments
77+
Student Enrollments are a `student_unique_id`, the `local_course_code` from Ed-Fi's `CourseOffering`, the unique key of a Class, plus the `begin_date`. Note that students may enter and exit the same Class multiple times,
78+
requiring the presence of `begin_date` in the enrollment record.
79+
- tenant_code (or constant string, if configured)
80+
- student_unique_id
81+
- lower(local_course_code)
82+
- school_id
83+
- lower(section_id)
84+
- lower(session_name)
85+
- begin_date
86+
87+
Staff enrollments are the same, but substituting staff_unique_id
88+
- tenant_code (or constant string, if configured)
89+
- staff_unique_id
90+
- lower(local_course_code)
91+
- school_id
92+
- lower(section_id)
93+
- lower(session_name)
94+
- begin_date
95+
96+
97+
2998
## Required Seed Files
3099
Templates for required seed files are located in the [seed_templates](seed_templates/)
31100

@@ -65,6 +134,6 @@ OneRoster is an extensible standard. Extensions in this package begin with `meta
65134

66135
`metadata.edu.natural_key`: All sourcedIds in this implementation are an MD5 hash of an underlying natural key. The definitions of the columns included in that key are in the [gen_sourced_id macro](macros/gen_sourced_id.sql). The unhashed string is included for clarity in this extension.
67136

68-
`metadata.edu.staffClassification`: The Ed-Fi Staff Classification field, for more
137+
`metadata.edu.staff_classification`: The Ed-Fi Staff Classification field, for more
69138
detailed role information. Since Ed-Fi permits multiple staffClassifications,
70139
but OneRoster 1.1 does not, we have to choose one.

models/oneroster_1_1/or1_1__int_users_staff.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ formatted as (
7878
null:string as "grades",
7979
null::string as "password",
8080
{{ gen_natural_key('staff') }} as "metadata.edu.natural_key",
81-
staff_role.staff_classification as "metadata.edu.staffClassification",
81+
staff_role.staff_classification as "metadata.edu.staff_classification",
8282
dim_staff.tenant_code
8383
from dim_staff
8484
join user_ids

models/oneroster_1_1/or1_1__int_users_student.sql

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ student_orgs as (
4242
k_student,
4343
dim_school.k_lea,
4444
dim_school.k_school,
45-
dim_school.school_id
45+
dim_school.school_id,
46+
student_school.tenant_code
4647
from student_school
4748
join dim_school
4849
on student_school.k_school = dim_school.k_school
@@ -55,10 +56,16 @@ student_orgs_agg as (
5556
from student_orgs
5657
group by all
5758
),
58-
59+
student_keys as (
60+
select
61+
k_student,
62+
{{ gen_sourced_id('student') }} as sourced_id,
63+
{{ gen_natural_key('student') }} as natural_key
64+
from dim_student
65+
),
5966
formatted as (
6067
select
61-
{{ gen_sourced_id('student') }} as "sourcedId",
68+
student_keys.sourced_id as "sourcedId",
6269
null::string as "status",
6370
null::date as "dateLastModified",
6471
true as "enabledUser",
@@ -76,10 +83,12 @@ formatted as (
7683
null::string as "agentSourceIds",
7784
grade_level_xwalk.oneroster_grade_level as "grades",
7885
null::string as "password",
79-
{{ gen_natural_key('student') }} as "metadata.edu.natural_key",
80-
null::string as "metadata.edu.staffClassfication",
86+
student_keys.natural_key as "metadata.edu.natural_key",
87+
null::string as "metadata.edu.staff_classfication",
8188
dim_student.tenant_code
8289
from dim_student
90+
join student_keys
91+
on dim_student.k_student = student_keys.k_student
8392
-- note that this join expands the grain by district in certain cases
8493
join student_orgs_agg
8594
on dim_student.k_student = student_orgs_agg.k_student

0 commit comments

Comments
 (0)