DHIS2 Application Runtime Fetching
Data query
A data query is defined as a mapping of names to query definitions; or in more practical terms: an object with string keys where each key has a query definition value.
A query definition declares what resource it's interested in, if it wants a specific instance of said resource and a list of parameters or a function that returns an object. The resource is the only property that's required and must be a string value corresponding to a DHIS2 resource.
Example data query: single resource
The data query below is a data query with one query definition named
programs which we have to use later when accessing the result of a
data query execution.
const query = {programs: {resource: 'programs',},}
Example data query: multiple resources
The data query below is a data query with two query definitions named
programs and dataSets. The application runtime's query execution
logic will make sure to optimize this query as much as possible and
fetch the data you need even if it has to make several requests to
different endpoints.
const query = {programs: {resource: "programs",}dataSets: {resource: "dataSets",}}
Example data query: static specific instance of collection
The data query below is a data query with one query definition named
programs, but instead of being interested in the entire collection
we're only interested in the program with the id abc.
const query = {programs: {resource: 'programs',id: 'abc',},}
Example data query: dynamic specific instance of collection
The data query below is a data query with one query definition named
programs, but we want the consumer of the query to be able to
specify which instance of the collection they're interested in.
const query = {programs: {resource: 'programs',id: ({ id }) => id,},}
Example data query: static parameters
The data query below is a data query with one query definition named
programs, but we're also specifying some parameters. The names
(keys) of the parameters must correspond to parameter names in the
DHIS2 API.
const query = {programs: {resource: 'programs',params: {fields: ['id', 'displayName'],paging: false,},},}
Example data query: dynamic parameters
The data query below is a data query with one query definition named
orgUnits and a couple of parameters. The params property of the
query definition is a function that returns an object (the
parameters). We can execute this query with custom runtime level
values.
const query = {orgUnits: {resource: 'organisationUnits',params: ({ level }) => ({fields: 'id',filter: `level:eq:${level}`,paging: false,}),},}