Mapping Kobo geolocation data to DHIS2 coordinates

In a recent call with an OpenFn user integrating #Kobo to #DHIS2, they asked how is it possible sync geolocation data / gps coordinates between the 2 systems.

To answer this… we need to understand the data types/formats of these geolocation fields in both the Kobo and DHIS2 systems.

Input: Kobo Form Submission
Kobo geolocation data often looks like this:
"_geolocation": [ -4.0824972, 39.6618433 ]

Or like this: "geo": "2.214224 16.305155 0 0"

Output: DHIS2 Tracker coordinates field
From what I can find in DHIS2 documentation (check out this link), it looks like coordinates field values are typically structured as follows:

"geometry":{   
  "type":"Point",  
  "coordinates":[18.735,15.4461] //longitude, latitude
}

Or sometimes in DHIS2 it might also look like this:
"geometry":{ "type":"Point", "coordinate":{"longitude":18.735,"latitude":15.4461}}

You’ll want to inspect the JSON payload from a Kobo Message body to see what the data format looks like. And then, you’ll probably need to implement a Javascript data cleaning function to reformat the Kobo geolocation data to match whatever format is used in your DHIS2 org.

geometry: state => {    
     const yourKoboField = state.data._geolocation; 
     console.log("Do anything you want here with JS to modify ::", yourKoboField);
     //write your own custom function to clean/reformat the data
     return yourNewOutput; 
}