forked from AMPATH/eid-process-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.mjs
60 lines (43 loc) · 1.46 KB
/
app.mjs
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
'use strict'
import { syncPatientResults } from './services/sync-manager-service.mjs';
import { SyncSettings } from './syncSettinngs/SyncSettings.mjs';
import { syncIntervalSettings } from './conf/config.mjs';
import moment from "moment";
const start = ()=>{
console.log('Start Sync process...');
Promise.allSettled([syncPatientLabs('ampath'),syncPatientLabs('alupe')])
.then((results)=>{
console.log('Results :', results);
}).catch((error)=>{
console.error('Error :',error);
});
}
const syncPatientLabs = (lab)=>{
return new Promise((resolve,reject)=>{
console.log(`Sync ${lab} Patients ...`);
const syncInterval = getSyncSettings(lab);
console.log('syncInterval',syncInterval);
setTimeout(()=>{
syncPatientResults(lab)
.then((results)=>{
console.log('Results', results);
syncPatientLabs(lab);
})
.catch((error)=>{
console.log(error);
});
},syncInterval);
resolve(`Started Sync for ${lab}`);
});
}
const getSyncSettings = (lab)=>{
let syncInterval = 10000;
const curTimeInHrs = moment().format('HH');
console.log('curTimeInHrs',curTimeInHrs);
const labSyncIntervalSettings = syncIntervalSettings[lab];
console.log(`${lab}SyncSettings`,labSyncIntervalSettings);
const labSyncSettings = new SyncSettings(lab,labSyncIntervalSettings.offpeakHrSyncInterval,labSyncIntervalSettings.peakHrSyncInterval);
syncInterval = labSyncSettings.getSyncIntervals(curTimeInHrs);
return syncInterval;
}
start();