From 82d6cab4ec2bfb64014a2f4966bcb8c285212520 Mon Sep 17 00:00:00 2001 From: nazarfil Date: Mon, 30 Dec 2024 18:06:38 +0100 Subject: [PATCH 1/2] fix: adds feilds to levels of organisation units --- openhexa/toolbox/dhis2/dhis2.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/openhexa/toolbox/dhis2/dhis2.py b/openhexa/toolbox/dhis2/dhis2.py index 7846b27..c6ef1b6 100644 --- a/openhexa/toolbox/dhis2/dhis2.py +++ b/openhexa/toolbox/dhis2/dhis2.py @@ -51,24 +51,23 @@ def identifiable_objects(self, uid: str) -> dict: r = self.client.api.get(f"identifiableObjects/{uid}") return r - def organisation_unit_levels(self) -> List[dict]: + def organisation_unit_levels(self, fields: str = "id,name,level") -> List[dict]: """Get names of all organisation unit levels. + Parameters + ---------- + fields: str, optional + DHIS2 fields to include in the response, where default value is "id,name,level" Return ------ list of dict Id, number and name of each org unit level. """ - r = self.client.api.get("filledOrganisationUnitLevels") + params = {"fields": fields} + r = self.client.api.get("filledOrganisationUnitLevels", params=params) levels = [] for level in r: - levels.append( - { - "id": level.get("id"), - "level": level.get("level"), - "name": level.get("name"), - } - ) + levels.append({k: v for k, v in level.items() if k in fields.split(",")}) return levels def organisation_units(self, fields: str = "id,name,level,path,geometry", filter: str = None) -> List[dict]: From 09f728ba1294c645d6d4e4339cbf4afd14870cd8 Mon Sep 17 00:00:00 2001 From: nazarfil Date: Tue, 31 Dec 2024 09:03:35 +0100 Subject: [PATCH 2/2] move out fields split --- openhexa/toolbox/dhis2/dhis2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openhexa/toolbox/dhis2/dhis2.py b/openhexa/toolbox/dhis2/dhis2.py index c6ef1b6..2da3fc4 100644 --- a/openhexa/toolbox/dhis2/dhis2.py +++ b/openhexa/toolbox/dhis2/dhis2.py @@ -66,8 +66,9 @@ def organisation_unit_levels(self, fields: str = "id,name,level") -> List[dict]: params = {"fields": fields} r = self.client.api.get("filledOrganisationUnitLevels", params=params) levels = [] + fields_list = fields.split(",") for level in r: - levels.append({k: v for k, v in level.items() if k in fields.split(",")}) + levels.append({k: v for k, v in level.items() if k in fields_list}) return levels def organisation_units(self, fields: str = "id,name,level,path,geometry", filter: str = None) -> List[dict]: