Categories¶
client.categories — CRUD over /api/categories (the second tier of DHIS2's disaggregation model). A Category is a named grouping of CategoryOptions along one axis (e.g. "Sex", "Age band"). One or more Category records get combined into a CategoryCombo for the cross-product disaggregation actually attached to data elements.
async with Dhis2Client(...) as client:
sex = await client.categories.create(
name="Sex",
short_name="Sex",
data_dimension_type="DISAGGREGATION",
category_option_uids=["male001UID0", "female01UID0"],
)
# `.add_option(category_uid, option_uid)` and `.remove_option(...)` are also available.
CRUD verbs mirror the standard pattern: list_all / get / create / update / rename / delete. The accessor wraps the typed Category model from dhis2w_client.generated.v42.schemas.category.
categories
¶
Category authoring — Dhis2Client.categories.
A Category is one axis of a disaggregation (e.g. Sex, Age group,
Modality). Each Category owns an ordered list of CategoryOptions
(the values along that axis). DHIS2 then composes Categories into a
CategoryCombo (the disaggregation grid) — and the cross-product of
options across the combo's categories materialises as the
CategoryOptionCombo set that data values key on.
This module covers the Category layer. The CategoryOption leaf already
ships in dhis2w_client.category_options; CategoryCombo + the
auto-generated CategoryOptionCombo matrix are the next layers in the
strategic-option queue.
Generic CRUD stays on the generated accessor
(client.resources.categories); this module adds keyword-arg creation
with optional --options wiring at create time, partial rename, and
per-item add_option / remove_option shortcuts that round-trip the
ordered membership via add_collection_item /
remove_collection_item.
Classes¶
Category
¶
Bases: BaseModel
Generated model for DHIS2 Category.
DHIS2 Category - persisted metadata (generated from /api/schemas at DHIS2 v42).
API endpoint: /api/categories.
Field Field(description=...) entries flag DHIS2 semantics the bare
type can't capture: which side of a relationship owns the link
(writable) vs the inverse side (ignored by the API), uniqueness
constraints, and length bounds.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/schemas/category.py
CategoriesAccessor
¶
Dhis2Client.categories — CRUD + rename + per-item option membership helpers.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 | |
Functions¶
__init__(client)
¶
list_all(*, page=1, page_size=50)
async
¶
Page through Categories with categoryOptions resolved inline.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
get(uid)
async
¶
create(*, name, short_name, code=None, description=None, data_dimension_type='DISAGGREGATION', options=None, uid=None)
async
¶
Create a Category, optionally wiring CategoryOption members on create.
data_dimension_type is DISAGGREGATION (the default — categories
that participate in the data-value matrix) or ATTRIBUTE (categories
used for attribute-option-combo metadata only). options is an
ordered list of CategoryOption UIDs; DHIS2 preserves the order on
save and uses it when materialising the CategoryOptionCombo matrix.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
update(category)
async
¶
PUT an edited Category back. category.id must be set.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
rename(uid, *, name=None, short_name=None, description=None)
async
¶
Partial-update the label fields — read, mutate, PUT.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
add_option(uid, option_uid)
async
¶
Append a CategoryOption to this Category's ordered membership.
DHIS2 preserves insertion order on the categoryOptions array —
relevant when the parent CategoryCombo materialises its
CategoryOptionCombo matrix. To re-order, edit the array via
update(category) directly.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
remove_option(uid, option_uid)
async
¶
Remove a CategoryOption from this Category's membership.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/categories.py
delete(uid)
async
¶
Delete a Category — DHIS2 rejects deletes on categories referenced by a CategoryCombo.