Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Constants (1.1)

Volker edited this page Feb 5, 2019 · 7 revisions

Constant values can be defined for a value in DHIS 2 that may change depending on defined Tracked Entity Attributes, Tracked Entity Types, Tracker Programs, Data Elements, Option Sets and Options. The typical use case are the options for male and female. These may be defined in a different way.

For a detailed description of all fields, please check the REST API documentation for administration and configuration.

{
  "name": "Gender Male",
  "description": null,
  "category": "GENDER",
  "code": "GENDER_MALE",
  "dataType": "STRING",
  "value": "Male",
  "_links": {
    "self": {
        "href": "https://demos.dhis2.org/fhir-adapter/api/constants/1ded2081-8836-43dd-a5e1-7cb9562c93ef"
    },
    "constant": {
        "href": "https://demos.dhis2.org/fhir-adapter/api/constants/1ded2081-8836-43dd-a5e1-7cb9562c93ef"
    }
  }
}

The example above defines the constant named "GENDER_MALE". This constant can be used to reference the value "Male". The value "Male" may have been used in as a option set code in DHIS 2. Since the comparison is made case-insensitively by the DHIS 2 FHIR Adapter, there is no need to take care about it when defining the constant in the DHIS 2 FHIR Adapter. The constant value may be "Male" and it will match the DHIS 2 option set code "MALE" as well.

The constants GENDER_MALE and GENDER_FEMALE exist by default and are used to map FHIR Administrative Genders from and to DHIS 2 Options.

The following code snippet maps FHIR administrative gender (variable input is a FHIR Patient, variable output is a DHIS 2 Tracked Entity Instance) to a DHIS 2 Tracked Entity Attribute that has the code "PERSON_GENDER".

output.setValue(context.createReference('PERSON_GENDER', 'CODE'), input.gender);

When converting from FHIR to DHIS 2 a lot of conversions from FHIR specific data types (like administrative gender) to DHIS 2 are done automatically.

Clone this wiki locally