AgentSkillsCN

dhis2-datasets

从DHIS2中提取数据集的元数据。适用于数据集定义、数据录入表单,或报告频率。对于一般的DHIS2请求,可通过dhis2技能进行路由。

SKILL.md
--- frontmatter
name: dhis2-datasets
description: Extract datasets metadata from DHIS2. Use for dataset definitions, data entry forms, or reporting frequencies. Routed via dhis2 skill for general DHIS2 requests.

DHIS2 Datasets

Extract dataset metadata from DHIS2 instances.

Prerequisites: Client setup from dhis2 skill (assumes dhis is initialized)

Get Datasets

python
# Get all datasets
datasets = dhis.meta.datasets()

# With pagination
datasets = dhis.meta.datasets(
    page=1,
    pageSize=100
)

# With filters
datasets = dhis.meta.datasets(
    filters=["name:ilike:monthly"]
)

# Custom fields
datasets = dhis.meta.datasets(
    fields="id,name,shortName,periodType,dataSetElements[dataElement[id,name]]"
)

Custom API Endpoint (Alternative)

For endpoints not covered by toolbox methods:

python
# Get datasets with full details
response = dhis.api.get(
    "dataSets",
    params={
        "fields": "id,name,shortName,code,periodType,"
                  "dataSetElements[dataElement[id,name]],"
                  "organisationUnits[id,name]",
        "paging": False
    }
)
datasets = response.get("dataSets", [])

Get Dataset by ID

python
def get_dataset(dhis, dataset_id: str) -> dict:
    """Get single dataset with full details."""
    return dhis.api.get(
        f"dataSets/{dataset_id}",
        params={
            "fields": "*,dataSetElements[*,dataElement[id,name,valueType]],"
                      "organisationUnits[id,name,level],"
                      "sections[id,name,dataElements[id,name]]"
        }
    )

Get Datasets for Org Unit

python
def get_datasets_for_org_unit(dhis, org_unit_id: str) -> list:
    """Get all datasets assigned to an org unit."""
    response = dhis.api.get(
        "dataSets",
        params={
            "fields": "id,name,periodType",
            "filter": f"organisationUnits.id:eq:{org_unit_id}",
            "paging": False
        }
    )
    return response.get("dataSets", [])

Get Dataset Data Elements

python
def get_dataset_data_elements(dhis, dataset_id: str) -> list:
    """Get all data elements in a dataset."""
    dataset = dhis.api.get(
        f"dataSets/{dataset_id}",
        params={
            "fields": "dataSetElements[dataElement[id,name,valueType,categoryCombo[id,name]]]"
        }
    )
    return [
        dse["dataElement"]
        for dse in dataset.get("dataSetElements", [])
    ]

Get Dataset Sections

python
def get_dataset_sections(dhis, dataset_id: str) -> list:
    """Get dataset form sections."""
    dataset = dhis.api.get(
        f"dataSets/{dataset_id}",
        params={
            "fields": "sections[id,name,sortOrder,dataElements[id,name]]"
        }
    )
    return dataset.get("sections", [])

Period Types

Period TypeDescriptionExample
DailyDaily reporting20240115
WeeklyISO week2024W03
MonthlyMonthly202401
QuarterlyQuarter2024Q1
SixMonthlyHalf-year2024S1
YearlyAnnual2024
FinancialAprilFiscal year (Apr)2024April
FinancialJulyFiscal year (Jul)2024July
FinancialOctFiscal year (Oct)2024Oct

Common Filters

FilterDescription
periodType:eq:MonthlyMonthly datasets
name:ilike:malariaName contains
organisationUnits.id:eq:xyzAssigned to org unit
dataSetElements.dataElement.id:eq:abcContains data element

Output Fields

Common fields to request:

code
id,name,shortName,code,
periodType,openFuturePeriods,
expiryDays,timelyDays,
dataSetElements[dataElement[id,name]],
organisationUnits[id,name],
sections[id,name,sortOrder]

Completeness Reporting

Get Dataset Completeness

python
def get_dataset_completeness(dhis, dataset_id: str, period: str, org_unit_id: str) -> dict:
    """Get completeness stats for a dataset."""
    response = dhis.api.get(
        "completeDataSetRegistrations",
        params={
            "dataSet": dataset_id,
            "period": period,
            "orgUnit": org_unit_id,
            "children": True
        }
    )
    return response