-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
82 lines (73 loc) · 2.22 KB
/
app.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const syncService = require("./service/sync-service");
const eidMassSync = require("./service/eid-mass-sync-service");
const moment = require("moment");
const config = require("./conf/config");
let shouldSync = false;
let syncScheduled = false;
const syncTime = config.syncSettings.eidSyncHr;
const syncInterval = config.syncSettings.syncInterval;
const scheduledPatientsSyncHr = config.syncSettings.scheduledSyncHour;
function startEidLabSync() {
console.log("start eid lab sync ######################");
setInterval(() => {
const syncLabs = sync();
if (syncLabs) {
syncService.getTodaysEidLabResults().then((results) => {
return results.forEach((result) => {
console.table("result", [result, result.status]);
console.log("end eid lab sync ######################");
});
});
} else {
console.log("should not sync labs..", syncLabs);
}
const syncRtcPatients = determineScheduledPatientsSync();
if (syncRtcPatients) {
syncService.syncScheduledPatients().then((results) => {
return results.forEach((result) => {
console.table("result", [result, result.status]);
console.log("end scheduled patients queueing -------------------");
});
});
} else {
console.log("syncRtcPatients not true", syncRtcPatients);
}
}, syncInterval);
}
function sync() {
// only sync labs at 7pm
const currentHour = moment().format("HH");
console.log("Current hour..", currentHour);
console.log("shouldSync", shouldSync);
if (parseInt(currentHour) == syncTime) {
if (shouldSync === false) {
shouldSync = true;
console.log("shouldSync2", shouldSync);
return true;
} else {
return false;
}
} else {
shouldSync = false;
return false;
}
}
function determineScheduledPatientsSync() {
/*
Gets patients who have appointmennts the next day
and adds them to the eid sync queue
*/
const currentHour = moment().format("HH");
if (parseInt(currentHour) === scheduledPatientsSyncHr) {
if (syncScheduled === false) {
syncScheduled = true;
return true;
} else {
return false;
}
} else {
syncScheduled = false;
return false;
}
}
startEidLabSync();