-
Notifications
You must be signed in to change notification settings - Fork 2
/
completude_hgr.js
62 lines (53 loc) · 1.95 KB
/
completude_hgr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const API = require('./lib/dhis2-api');
const mailer = require('./mailer');
module.exports.postData = (auth) => {
// const url = `https://ima-assp.org/api/analytics/dataValueSet.json`;
const api = new API({
credentials: auth,
// url: url
url: 'https://ima-assp.org/api/analytics/dataValueSet.json',
});
// Données éxistantes de la complétude HGR
/*
const apiHGR = new API({
credentials: auth,
url: url
});
*/
const query = 'dimension=dx:pJxcWVobpl2.ACTUAL_REPORTS&dimension=ou:LEVEL-3;s7ZjqzKnWsJ&dimension=pe:THIS_QUARTER;LAST_QUARTER&displayProperty=NAME';
// //Données éxistantes de la complétude HGR
// const queryHGR = `dimension=pe:THIS_QUARTER;LAST_QUARTER&dimension=ou:LEVEL-3;s7ZjqzKnWsJ&dimension=dx:fQAidw8S5ud&displayProperty=NAME`;
// download the Data
api.analytics({ query })
.then((source) => {
const { dataValues } = source;
const result = {
dataValues: [],
};
const completude = 'fQAidw8S5ud';
datasetMap = {};
dataValues.forEach((source) => {
// console.log('source element : ', source);
const data = Math.round(source.value / 3);
result.dataValues.push({
dataElement: completude,
period: source.period,
orgUnit: source.orgUnit,
value: data,
storedBy: `IMA ${source.created}`,
created: source.created,
});
});
// console.log(result);
return api.postData({
data: result,
// url: 'https://ima-assp.org/api/dataValueSets?importStrategy=CREATE'
url: 'https://ima-assp.org/api/dataValueSets?skipAudit=true',
});
})
.then((response) => {
mailer.sendMail(`success!!! Import Completness for HGR${JSON.stringify(response)}`, 'Import Completness for HGR');
}).catch((err) => {
mailer.sendMail(`Fail!!! Import Completness for HGR${JSON.stringify(err)}`, 'Fail!!! Import Completness for HGR');
});
};