/language-dhis2

Language Pack for building expressions and operations for working with the DHIS2 API.

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

Language DHIS2 Build Status

Language Pack for building expressions and operations for working with the DHIS2 API.

Documentation

Sample State

{
  "configuration": {
    "username": "admin",
    "password": "district",
    "apiUrl": "https://play.dhis2.org/2.31.1"
  },
  "data": {
    "a": 1,
    "b": 2,
  }
}

Analytics API

Fetch analytics data for PMTCT data over last 6 months.

fetchAnalytics({
  query: {
    dimension: ["dx:CYI5LEmm3cG;GDVU1o5rTNF", "pe:LAST_6_MONTHS"],
    filter: "ou:GHlyx9Pg9mn",
    displayProperty: "NAME",
    outputIdScheme: "UID"
  }
});

Tracked Entity API

Create a new tracked entity instance and enroll them from a CommCare form submission.

createTEI({
  "trackedEntityType": "nEenWmSyUEp",
  "orgUnit": "g8upMTyEZGZ",
  "attributes": [
    {
      "attribute": "w75KJ2mc4zz",
      "value": dataValue("form.first_name")(state)
    },
    {
      "attribute": "zDhUuAYrxNC",
      "value": dataValue("form.last_name")(state)
    }
  ],
  "enrollments": [
    {
        "orgUnit": "g8upMTyEZGZ",
        "program": "IpHINAT79UW",
        "enrollmentDate": "2019-04-08",
        "incidentDate": "2019-04-08"
     }
   ]
});

Events API

Events API expression

event(
  fields(
    field("program", "eBAyeGv0exc"),
    field("orgUnit", "DiszpKrYNg8"),
    field("eventDate", dataValue("date")),
    field("status", "COMPLETED"),
    field("storedBy", "admin"),
    field("coordinate", {
      "latitude": "59.8",
      "longitude": "10.9"
    }),
    field("dataValues", function(state) {
      return [
        dataElement("qrur9Dvnyt5", dataValue("prop_a"))(state)
        dataElement("oZg33kd9taw", dataValue("prop_b"))(state)
        dataElement("msodh3rEMJa", dataValue("prop_c"))(state)
      ]
    })
  )
)

Current fetchEvents API expression (Optional postUrl for a complete fetch)

fetchEvents({
  fields: {
    orgUnit: 'DiszpKrYNg8',
    program: 'eBAyeGv0exc',
    endDate: '2016-01-01'
  },
  postUrl: "https://www.openfn.org/inbox/123"
})

Data Values / Data Value Sets API

Current DataValueSets API expression

dataValueSet({
  dataSet: dataValue("set"),
  orgUnit: "DiszpKrYNg8",
  period: "201402",
  completeData: "2014-03-03",
  dataValues: [
    dataElement("f7n9E0hX8qk", dataValue("data[0].site_school_number")),
    dataElement("Ix2HsbDMLea", dataValue("age")),
    dataElement("eY5ehpbEsB7", 30)
  ]
});

Current fetchData API expression (Optional postUrl for a complete fetch)

fetchData({
  fields: {
    dataSet: 'pBOMPrpg1QX',
    orgUnit: 'DiszpKrYNg8',
    period: '201711'
  },
  postUrl: "https://www.openfn.org/inbox/123"
})

Docs

Development

Clone the repo, run npm install.

Run tests using npm run test or npm run test:watch

Build the project using make.