Attribute values¶
client.attribute_values — read + write the attributeValues collection that every Identifiable metadata resource carries. DHIS2 lets implementations stamp arbitrary typed Attribute records onto any metadata (program, data element, indicator, ...) — the accessor is the typed entry point for that pattern.
async with Dhis2Client(...) as client:
# Read every attribute value across one resource.
values = await client.attribute_values.list_for(
resource="dataElements",
uid="dataEl0001U",
)
# Find a specific one by Attribute UID.
one = await client.attribute_values.find(
resource="dataElements",
uid="dataEl0001U",
attribute_uid="legacyId001",
)
# Set / overwrite.
await client.attribute_values.set(
resource="dataElements",
uid="dataEl0001U",
attribute_uid="legacyId001",
value="DE-123",
)
Works against every resource that has an attributeValues field (the bulk of /api/{resource} endpoints). Worked example: examples/v42/client/attribute_values.py.
attribute_values
¶
Cross-resource attributeValues helpers for DHIS2 integration workflows.
DHIS2 exposes user-defined Attribute objects as the extensibility point
for metadata: any resource that carries an attributeValues field
(DataElements, Options, OrganisationUnits, Indicators, Dashboards, …)
can attach arbitrary typed key-value pairs, keyed by the Attribute's
UID. Integrations use this for cross-system code mapping — ICD-10 on
DataElements, SNOMED on Options, external-warehouse IDs on OrgUnits.
This accessor gives one consistent surface for those workflows. Every
method dispatches on a plural resource string matching the DHIS2 API
endpoint ("dataElements", "options", "organisationUnits", …), so
one helper works across every attribute-bearing resource without a
per-type sibling class.
client.option_sets keeps its own thin option-specific wrappers
(get_option_attribute_value etc.) for ergonomics — they now delegate
here so the wire-shape workarounds (BUGS.md #21's attribute-UID-as-
filter-property) live in one place.
Classes¶
AttributeValuesAccessor
¶
Dhis2Client.attribute_values — read / write / search AttributeValues on any resource.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/attribute_values.py
31 32 33 34 35 36 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 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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
Functions¶
__init__(client)
¶
Bind to the sharing client — reuses its auth + HTTP pool for every request.
resolve_attribute_uid(attribute_code_or_uid)
async
¶
Resolve an Attribute identifier to its DHIS2 UID; raise LookupError on miss.
Integrations usually know an Attribute by its business code
(e.g. SNOMED_CODE) but DHIS2's filter DSL for attribute values
keys by the Attribute's UID (BUGS.md #21). This helper turns the
code into a UID via /api/attributes?filter=code:eq:{code}; UIDs
pass through unchanged.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/attribute_values.py
get_value(resource, resource_uid, attribute_code_or_uid)
async
¶
Read one attribute value off a resource; None if the attribute isn't set.
resource is the plural DHIS2 API name ("dataElements",
"options", "organisationUnits", …). The resource must carry
an attributeValues field server-side — DHIS2 returns a typed
error otherwise, which bubbles up unchanged.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/attribute_values.py
set_value(resource, resource_uid, attribute_code_or_uid, value)
async
¶
Set / replace one attribute value on a resource (read-merge-write).
Reads the full resource, merges the new attribute value (replaces
any prior entry for the same attribute UID), PUTs the payload
back. DHIS2 rejects partial PATCH on attributeValues on
multiple resource types (the list is identity-keyed by attribute
UID, not index), so the full round-trip is the only path that
behaves consistently.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/attribute_values.py
delete_value(resource, resource_uid, attribute_code_or_uid)
async
¶
Remove one attribute value from a resource; return True if anything was removed.
Same read-merge-write pattern as set_value; when the attribute
isn't present on the resource the call is a no-op and returns
False (no HTTP PUT fires — avoids gratuitous churn on
lastUpdated fields).
Source code in packages/dhis2w-client/src/dhis2w_client/v42/attribute_values.py
find_uids_by_value(resource, attribute_code_or_uid, value, *, extra_filters=None)
async
¶
Reverse lookup — every resource UID whose attribute value matches.
DHIS2's filter DSL for attribute values is the quirky
<attributeUid>:eq:<value> form (see BUGS.md #21). This helper
resolves the business code to UID then emits the quirky-but-
working filter. Additional constraints pass through as
extra_filters — e.g. scope an Option lookup to one OptionSet
via extra_filters=["optionSet.id:eq:OsVaccType1"], or narrow a
DataElement lookup via extra_filters=["domainType:eq:AGGREGATE"].
Callers wanting the full typed model should round-trip the
returned UIDs through client.resources.<resource>.get(uid) —
this accessor stays generic over resource types by returning
UIDs only.
Source code in packages/dhis2w-client/src/dhis2w_client/v42/attribute_values.py
find_one_uid_by_value(resource, attribute_code_or_uid, value, *, extra_filters=None)
async
¶
Reverse lookup helper — return the first matching UID, or None on miss.