-
Notifications
You must be signed in to change notification settings - Fork 0
/
auditRecordCount.js
62 lines (52 loc) · 1.86 KB
/
auditRecordCount.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
alterState(state => {
const { Patient, Visit } = state.data;
function reduceArray(array, groupBy) {
return array.reduce((r, a) => {
r[a[groupBy]] = r[a[groupBy]] || [];
r[a[groupBy]].push(a);
return r;
}, Object.create(null));
}
function checkLength(array, key) {
return array[key] ? array[key].length : 0;
}
console.log('Total size Patient', Patient.length);
console.log('Total size Visit', Visit.length);
function uniqueArray(array, key) {
return Array.from(new Set(array.map(a => a[key]))).map(id => {
return array.find(c => id === c[key]);
});
}
// setting unique arrays =================
const uniquePatients = uniqueArray(Patient, 'CommCare_Case_ID__c');
const uniqueVisits = uniqueArray(Visit, 'Visit_ID__c');
// =======================================
const resultUniquePatient = reduceArray(uniquePatients, 'CreatedById');
const resultUniqueVisit = reduceArray(uniqueVisits, 'CreatedById');
// PATIENT ======================================================
console.log('Audit record for Patient');
for (let key in resultUniquePatient) {
console.log(
`Total count of unique patients with ${key} ${checkLength(
resultUniquePatient,
key
)}`
);
}
console.log('==============================================================');
// ==============================================================
// VISIT ========================================================
console.log('Audit record for Visit');
for (let key in resultUniqueVisit) {
console.log(
`Total count of unique patients with ${key} ${checkLength(
resultUniqueVisit,
key
)}`
);
}
console.log('==============================================================');
// ==============================================================
state.data = {};
return state;
});