Z.Enrollments (Portico/Z v0.1.0)
Context module for dealing with EXPLO enrollments
Note that currently these functions all work with and return
ZSchemas.FlatEnrollment
structs. This may change in the future.
Link to this section Summary
Functions
Search ZSchemas.Flat.Enrollment
s but return ZSchemas.Flat/Contact
s.
Find enrollments by field/value matches (parameters
)
Searches only current-year, only enrolled students
Searches only current-year, only enrolled students
Link to this section Functions
get_enrollments_and_contacts_by(opts)
Search ZSchemas.Flat.Enrollment
s but return ZSchemas.Flat/Contact
s.
Opts
Takes the following opts
:
enrollments
- args to be forwarded toget_enrollments_by/2
contacts
- args to be forwarded toZ.Contacts.search/2
See apply/3
for details of how to pass arguments to the sub-search functions.
Examples
iex> Z.Enrollments.get_enrollments_and_contacts_by(enrollments: [[program_identifier: "JUN"]]
[%ZSchemas.Flat.Enrollment, ...]
iex> Z.Enrollments.get_enrollments_and_contacts_by(contacts: [[first_name: "Andy"]]
[%ZSchemas.Flat.Enrollment, ...]
iex> Z.Enrollments.get_enrollments_and_contacts_by(enrollments: [[year: 2021]], contacts: [[first_name: "Donald"], [limit: 2]])
[%ZSchemas.Flat.Enrollment, ...]
get_enrollments_by(parameters, opts \\ [])
Specs
Find enrollments by field/value matches (parameters
)
This is very similar to Z.Repo.get_by/2
and friends, with a few exceptions, noted below:
Session-Specific Fields
ZSchemas.Flat.Enrollment
stores each session variant as a diferent field
name (eg s1_program_identifier
, s2_program_identifier
, and so on).
Sometimes we wish to search for enrollments matching a particular session, in which case this function will directly pass your request along to the database:
iex> Z.Enrollments.get_enrollments_by s1_program_identifier: "JUN"
[%ZSchemas.Flat.Enrollment{}, ...]
However, if you want to search all sessions for a potential program identifier match, you'd be really sad to have to write that search this way:
# DOESN'T WORK ANYHOW
Z.Enrollments.get_enrollments_by s1_program_identifier: "JUN", s2_program_identifier: "JUN", s3_program_identifier: "JUN", ...
This doesn't work for two reasons:
- Too hard to type, nobody will ever do it
- The syntax doesn't allow for "OR" statements anyhow, so the above query
would return only students enrolled in
"JUN"
for every session, which is not what you want.
Given this, we've added a "special case" to this function for the following
search fields. For these fields, if you search by the field name with no
session identifier prepended (eg program_identifier
and not
s1_program_identifier
), your query will be understood to mean "find a match
in any session for this field/value pair":
iex> Z.Enrollments.get_enrollments_by program_identifier: "JUN"
[%ZSchemas.Flat.Enrollment, ...]
- program_name
- program_identifier
- res_type
- session_id
- status
- status_date
- student_group_name
- student_group_id
Storing the Query
This function currently takes one option in the opts
key:
return_query
(boolean). If this is sent astrue
, then theEcto.Query
will be returned instead of the query result. This can be handy for chaining with other searches.
search_currently_enrolled_students(contact_args)
Searches only current-year, only enrolled students
This is mostly an internal modality, but you can use it to search any contact argument you want. See the source of search_currently_enrolled_students/2
for details of how to call this version.
search_currently_enrolled_students(first_name, last_name)
Searches only current-year, only enrolled students
Default modality is first_name
and last_name
, which will actually search preferred_name
as well if no first_name
match happens.
Examples
search_currently_enrolled_students("victor", "laslo")
[%ZSchemas.Flat.Enrollment, ...]