Saltar a contenido
For the complete DHIS2 documentation index, see llms.txt.

Object style

Algunos elementos incluyen una propiedad llamada "estilo" que define un icono y un color. Esta información visual es muy útil para navegar rápidamente por la aplicación. Algunos casos de uso típicos:

  • Distinguir diferentes programas y trackedEntityTypes en una lista de programas.
  • En formularios de entrada de datos con un Set de opciones, muestra las opciones con iconos y colores en lugar de nombres.
  • Diferentes etapas de programa dentro de un programa.

Esta propiedad es opcional y no está definida en la mayoría de los casos. Un estilo de objeto puede tener un icono, un color o ambos.

Icono

DHIS2 includes a predefined set of icons. Those icons are included in the SDK and are located within the resources, in the "drawable" folder.

Staring on version v41, it is possible to upload user-defined icons and assign them to metadata objects. The actual images of these icons are stored as a FileResource and must be explicitly downloaded in a separate query.

d2.fileResourceModule().fileResourceDownloader()
    .byDomainType().eq(FileResourceDomainType.ICON)
    .download()

You can get the information about a particular icon by using the IconCollectionRepository. It returns an Icon object, which is a sealed class with two possible values: Default or Custom.

The way to render the actual image will depend on the Icon type.

val icon = d2.iconModule().icons().key("icon_key").blockingGet()

icon?.let {
    when (icon) {
        is Icon.Custom -> {
            val path = icon.path
            val fileResourceUid = icon.fileResourceUid
            // Use this information to load the file
        }

        is Icon.Default -> {
            val resourceName = icon.key
            // Use this information to load the resource
        }
    }
}

Color

Contiene el valor hexadecimal del color. Se puede utilizar para personalizar el fondo, el color del texto, los encabezados de línea, etc.

program.style().color()    // For example #9C33FF