Carloscnk
(Carlos Nyembwe)
17 August 2022 13:44
1
Hi All,
I have a problem, we have a lot of data in the tracker by for now, too many bad data quality, we need to update some datavalue or attribute value mayby by API.
Who can help my?
Regards
Gassim
(AL-Gassim Sharaf Addin)
17 August 2022 17:52
2
Hi @Carloscnk ,
Welcome back to the Community of Practice!
It is possible to use the Import / Export app by exporting the data and then use it again to import the new updated values. Maybe you could give it a try!
Thank you!
Carloscnk
(Carlos Nyembwe)
19 August 2022 09:14
3
Thanks @Gassim
But now, if I want to change de orgunit?
It’s not possible to update just one dataelement value? because we have too many data to update
1 Like
didate
(Mamadou Lamarana)
19 August 2022 11:27
4
@Carloscnk
For this kind of thing I often write a script.
Here are some examples to inspire you
const { dhis2destination , dhis2source } = require('./dhis2');
const fs = require('fs');
const csv = require('csv-parser');
const run = async () => {
// En cas de reprise, supprimer les lignes des annees deja traiter et recuperer le dernier trimester traité dans le fichier des OK
const periods = [
{ year: 2014, start: 1, end: 4 },
{ year: 2015, start: 1, end: 4 },
{ year: 2016, start: 1, end: 4 },
{ year: 2017, start: 1, end: 4 },
{ year: 2018, start: 1, end: 4 },
{ year: 2019, start: 1, end: 4 },
{ year: 2020, start: 1, end: 4 }
]
This file has been truncated. show original
const { dhis2 } = require('./dhis2');
const fs = require('fs');
const csv = require('csv-parser');
const run = () => {
// Read data.csv row by row
const datas = [];
fs.createReadStream('./data.csv').pipe(csv()).on('data', (row) => {
// ADD row to datas array
datas.push(row);
}).on('end', async () => {
const date = new Date();
for (let index = 0; index < datas.length; index++) {
const row = datas[index];
try {
// Get trackedEntityInstance from server
const trackedEntityInstance = await dhis2.get(`/trackedEntityInstances/${row.tei}.json`);
const content = trackedEntityInstance.data;
This file has been truncated. show original
2 Likes
Gassim
(AL-Gassim Sharaf Addin)
19 August 2022 17:21
5
You’re welcome @Carloscnk ! I was thinking more like using tools like ‘fine and replace’ after downloading as a json file but you’d know the data you’re dealing with better so it might be the best solution to use a script as @didate suggested
Thanks!
Carloscnk
(Carlos Nyembwe)
19 August 2022 18:14
6
Hi!
But now, which kind of url I will use?
1 Like
Gassim
(AL-Gassim Sharaf Addin)
19 August 2022 18:31
7
Carlos Nyembwe:
But now, if I want to change de orgunit?
It’s not possible to update just one dataelement value? because we have too many data to update
Just moments ago someone had a similar issue and wanted to update the ‘value type’ of a data element. I suggested using ‘partial updates’ please see:
https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/metadata.html#webapi_partial_updates