Api reference
components.affiliation_occ_health.public.api ¶
Public API of the Affiliation component.
affiliate ¶
affiliate(
*,
affiliation_service,
affiliable_ref,
start_date,
end_date=None,
subscription_ref=None,
commit=True
)
Affiliate an affiliable to an affiliation service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
affiliation_service
|
AffiliationService
|
which product / service should we affiliate to? |
required |
affiliable_ref
|
str
|
opaque reference describing who will be affiliated (can be a user ID, etc) |
required |
start_date
|
date
|
when the affiliation starts |
required |
end_date
|
date | None
|
if we know it at affiliation time, when it will end |
None
|
subscription_ref
|
str | None
|
optional reference to a subscription (e.g. contract ID) |
None
|
commit
|
bool
|
whether to commit the transaction |
True
|
Returns: the UUID of the newly-created affiliation
Raises:
| Type | Description |
|---|---|
AffiliationAlreadyExistsOrOverlapsError
|
if an affiliation already exists or overlaps with the given dates |
Source code in components/affiliation_occ_health/public/api.py
cancel_affiliation ¶
Cancel the affiliation.
This is different from termination in that it invalidates the affiliation entirely, rather than setting an end date. The affiliation will be considered as if it never existed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
affiliation_service
|
AffiliationService
|
which product / service the affiliation belongs to |
required |
affiliation_id
|
UUID
|
the UUID of the affiliation to cancel |
required |
commit
|
bool
|
whether to commit the transaction |
True
|
Raises:
| Type | Description |
|---|---|
AffiliableNotFound
|
if no affiliation is found |
AffiliationError
|
if the affiliation is already cancelled |
Source code in components/affiliation_occ_health/public/api.py
get_active_affiliation ¶
Retrieve the affiliation data for a given affiliable.
If on_date is not provided, it defaults to today.
Beware: for services supporting concurrent affiliation, please provide a subscription_ref. Otherwise, the query will raise if there are multiple active affiliations.
Source code in components/affiliation_occ_health/public/api.py
get_active_affiliations_list ¶
get_active_affiliations_list(
affiliable_ref,
affiliation_service,
subscription_ref=None,
on_date=None,
)
Retrieve the list of affiliation data for a given affiliable.
If on_date is not provided, it defaults to today.
This is mostly useful for services supporting concurrent affiliation.
Source code in components/affiliation_occ_health/public/api.py
get_affiliation_list ¶
get_affiliation_list(
affiliation_service,
subscription_ref=None,
affiliable_ref=None,
include_cancelled=False,
only_active_on=None,
)
Return the list of absolutely all affiliation data, or filtered by subscription and/or affiliable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
affiliation_service
|
str
|
which service to filter on |
required |
subscription_ref
|
str | None
|
optional reference to a subscription (e.g. contract ID) to filter on |
None
|
affiliable_ref
|
str | None
|
optional reference to an affiliable (e.g. profile ID) to filter on |
None
|
include_cancelled
|
bool
|
whether to include cancelled affiliations |
False
|
only_active_on
|
date | None
|
if provided, filter the affiliations to only include those active on that date |
None
|
Source code in components/affiliation_occ_health/public/api.py
terminate_affiliation ¶
terminate_affiliation(
affiliation_service,
affiliable_ref,
end_date,
termination_type=None,
subscription_ref=None,
commit=True,
)
Terminate the affiliation.
If a subscription_ref is passed, then we require the affiliation to be tied to that subscription. This is useful for services allowing overlapping affiliation through different subscriptions (e.g. Occupational Health).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
affiliation_service
|
AffiliationService
|
which product / service should we terminate the affiliation from? |
required |
affiliable_ref
|
str
|
opaque reference describing who will be unaffiliated |
required |
end_date
|
date
|
when the affiliation ends |
required |
termination_type
|
str | None
|
optional type of termination (e.g. "voluntary", "involuntary") |
None
|
subscription_ref
|
str | None
|
optional reference to a subscription (e.g. contract ID). |
None
|
commit
|
bool
|
whether to commit the transaction |
True
|
Returns: the UUID of the terminated affiliation.
Raises:
| Type | Description |
|---|---|
AffiliableNotFound
|
if the affiliable has no affiliation, or no active affiliation at the date of termination. |
AffiliationError
|
if the affiliation is already terminated or not active on the end date |
Source code in components/affiliation_occ_health/public/api.py
update_affiliation_dates ¶
update_affiliation_dates(
*,
affiliation_service,
affiliation_id,
start_date=NOT_SET,
end_date=NOT_SET,
commit=True
)
Update the start date and/or end date of the affiliation.
NOT_SET can be passed in either start_date or end_date to leave the date unchanged (default behavior).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
affiliation_service
|
AffiliationService
|
which product / service should we update the affiliation from? |
required |
affiliation_id
|
UUID
|
the UUID of the affiliation to update |
required |
start_date
|
NotSet[date]
|
when the affiliation starts |
NOT_SET
|
end_date
|
NotSet[date | None]
|
when the affiliation ends (can be |
NOT_SET
|
commit
|
bool
|
whether to commit the transaction |
True
|
Returns: the UUID of the updated affiliation
Raises:
| Type | Description |
|---|---|
ValueError
|
if neither start_date nor end_date is provided |
AffiliableNotFound
|
if no affiliation is found |
AffiliationError
|
if the new dates are invalid |
Source code in components/affiliation_occ_health/public/api.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
components.affiliation_occ_health.public.entities ¶
AffiliationData
dataclass
¶
AffiliationData(
affiliation_id,
start_date,
end_date,
is_cancelled,
affiliable_ref,
affiliation_service,
subscription_ref,
)
Bases: DataHistorizable
Represent the affiliation of an affiliable to a service, over a set of dates.
components.affiliation_occ_health.public.enums ¶
components.affiliation_occ_health.public.exceptions ¶
AffiliableNotFound ¶
Bases: BaseAffiliationError
Affiliable matching criteria not found.
AffiliationAlreadyExistsOrOverlapsError ¶
Bases: BaseAffiliationError
Enrollment already exists or overlaps with an existing one.
AffiliationError ¶
Bases: BaseAffiliationError
Affiliation operation was not successful (eg because the affiliation was already cancelled/terminated, the new dates are invalid...)
BaseAffiliationError ¶
Bases: Exception
Generic affiliation error.