-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitData.js
66 lines (54 loc) · 1.56 KB
/
splitData.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
63
64
65
66
alterState(async state => {
const { Patient, Visit, Clinic, VisitDeleted, LookupTable } = state.data;
const chunk = (arr, chunkSize) => {
var R = [];
for (var i = 0, len = arr.length; i < len; i += chunkSize)
R.push(arr.slice(i, i + chunkSize));
return R;
};
// console.log('Patient:', Patient.length)
// console.log('Visit:', Visit.length)
// return state;
const patientSets = chunk(Patient, 10);
const visitSets = chunk(Visit, 10);
console.log('Patient sets:', patientSets.length);
console.log('Visit sets:', visitSets.length);
const visitChunks = [];
const patientChunks = [];
patientSets.forEach((sets, i) => {
// console.log(`${i+1} patient set = ${sets.length}`);
const data = {
Visit: [],
Clinic,
LookupTable,
VisitDeleted,
Patient: sets,
};
patientChunks.push(data);
});
visitSets.forEach((sets, i) => {
// console.log(`${i + 1} visit set = ${sets.length}`);
const data = {
Visit: sets,
Clinic,
LookupTable,
VisitDeleted,
Patient: [],
};
visitChunks.push(data);
});
let countInbox = 0;
const postToInbox = async data => {
countInbox++;
console.log(`${countInbox} request to inbox`);
await new Promise(resolve => setTimeout(resolve, 2000));
await post(state.configuration.inboxUrl, { body: data })(state);
};
for (const patient of patientChunks) {
await postToInbox(patient);
}
for (const visit of visitChunks) {
await postToInbox(visit);
}
return { ...state, patientChunks, visitChunks };
});