Dear @Tumaini_Kilimba,
I think this guideline and script will be useful: https://dhis2trainingland.com/eportal/wp-content/uploads/expert-academy-2018/Scripting_in_Multiple_Languages.pdf
Linking DHIS2 to an external web portal using DHIS2 Web API and R
#Linking DHIS2 to an external web portal using DHIS2 Web API – DHIS2 Web Portal
Script:
dhis.json file:
{
“dhis”: {
“baseurl”: “https://server-url”,
“username”: “username”,
“password”: “password”
},
“database”: {
“host”: “localhost”,
“port”: 5432,
“username”: “username”,
“password”: “password”,
“dbname”: “dhis2”
}
}
#!/usr/bin/env Rscript
modifyDataStore.R, an R script by Jason Pickering loosely based on a script by Ben Guaraldi (and lightly edited by same)
require(httr)
require(rlist)
require(jsonlite)
require(magrittr)
require(assertthat)
Get parameters from dish.json
config ← fromJSON(‘/opt/dhis2/dish.json’)
url<-paste0(config$dhis$baseurl, ‘/api/dataStore/assignments/organisationUnitLevels.json’)
Get the current JSON from the organisationUnitLevels key of the assignments namespace in the data store
j <-GET(url, authenticate(config$dhis$username, config$dhis$password)) %>%
content(., “text”) %>%
fromJSON(.)
Construct a new JSON from the current JSON, adding a new key and resorting it
j$Pirate ← j$Zimbabwe
j$Pirate$name3 ← ‘Pirate’
j ← j[order(names(j))]
Replace the old JSON with the new JSON
r ← PUT(url, body = toJSON(j, auto_unbox = TRUE), content_type_json())
Report completion
message(‘Exiting normally’)
Credit: Ben Guaraldi, Technical Lead for DATIM
Julhas