@aleonnet/healthcare-scheduler 0.1.21 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/HealthcareScheduler.d.ts +1 -0
- package/dist/core/HealthcareScheduler.d.ts.map +1 -1
- package/dist/core/HealthcareScheduler.js +3 -3
- package/dist/core/HealthcareScheduler.js.map +1 -1
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/database/adapters/SupabaseAdapter.d.ts.map +1 -1
- package/dist/database/adapters/SupabaseAdapter.js +24 -8
- package/dist/database/adapters/SupabaseAdapter.js.map +1 -1
- package/dist/database/repositories/EventsRepository.js +2 -2
- package/dist/database/repositories/EventsRepository.js.map +1 -1
- package/dist/database/repositories/ItemsRepository.d.ts.map +1 -1
- package/dist/database/repositories/ItemsRepository.js +21 -1
- package/dist/database/repositories/ItemsRepository.js.map +1 -1
- package/dist/database/repositories/OccurrencesRepository.d.ts.map +1 -1
- package/dist/database/repositories/OccurrencesRepository.js +16 -3
- package/dist/database/repositories/OccurrencesRepository.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/notifications/adapters/MockNotificationAdapter.d.ts.map +1 -1
- package/dist/notifications/adapters/MockNotificationAdapter.js +5 -3
- package/dist/notifications/adapters/MockNotificationAdapter.js.map +1 -1
- package/dist/notifications/adapters/NotifeeAdapter.d.ts.map +1 -1
- package/dist/notifications/adapters/NotifeeAdapter.js +116 -41
- package/dist/notifications/adapters/NotifeeAdapter.js.map +1 -1
- package/dist/plugins/InventoryPlugin.js +0 -1
- package/dist/plugins/InventoryPlugin.js.map +1 -1
- package/dist/plugins/SyncPluginEventDriven.d.ts.map +1 -1
- package/dist/plugins/SyncPluginEventDriven.js +19 -6
- package/dist/plugins/SyncPluginEventDriven.js.map +1 -1
- package/dist/plugins/gamification/GamificationPlugin.d.ts +0 -1
- package/dist/plugins/gamification/GamificationPlugin.d.ts.map +1 -1
- package/dist/plugins/gamification/GamificationPlugin.js +21 -22
- package/dist/plugins/gamification/GamificationPlugin.js.map +1 -1
- package/dist/reconciler/WindowScheduler beta.d.ts +32 -0
- package/dist/reconciler/WindowScheduler beta.d.ts.map +1 -0
- package/dist/reconciler/WindowScheduler beta.js +416 -0
- package/dist/reconciler/WindowScheduler beta.js.map +1 -0
- package/dist/reconciler/WindowScheduler.d.ts +1 -0
- package/dist/reconciler/WindowScheduler.d.ts.map +1 -1
- package/dist/reconciler/WindowScheduler.js +56 -17
- package/dist/reconciler/WindowScheduler.js.map +1 -1
- package/package.json +7 -4
- package/dist/plugins/SyncPluginPolling.d.ts +0 -24
- package/dist/plugins/SyncPluginPolling.d.ts.map +0 -1
- package/dist/plugins/SyncPluginPolling.js +0 -266
- package/dist/plugins/SyncPluginPolling.js.map +0 -1
- package/dist/plugins/gamification/__tests__/hysteresis.spec.d.ts +0 -2
- package/dist/plugins/gamification/__tests__/hysteresis.spec.d.ts.map +0 -1
- package/dist/plugins/gamification/__tests__/hysteresis.spec.js +0 -22
- package/dist/plugins/gamification/__tests__/hysteresis.spec.js.map +0 -1
- package/dist/services/MedicationsServiceCompat.d.ts +0 -24
- package/dist/services/MedicationsServiceCompat.d.ts.map +0 -1
- package/dist/services/MedicationsServiceCompat.js +0 -98
- package/dist/services/MedicationsServiceCompat.js.map +0 -1
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SyncPluginPolling = void 0;
|
|
4
|
-
const ItemsRepository_1 = require("../database/repositories/ItemsRepository");
|
|
5
|
-
const PlansRepository_1 = require("../database/repositories/PlansRepository");
|
|
6
|
-
const MedicationsRepository_1 = require("../database/repositories/MedicationsRepository");
|
|
7
|
-
const OccurrencesRepository_1 = require("../database/repositories/OccurrencesRepository");
|
|
8
|
-
class SyncPluginPolling {
|
|
9
|
-
constructor(provider, cfg = {}) {
|
|
10
|
-
this.provider = provider;
|
|
11
|
-
this.name = 'SyncPlugin';
|
|
12
|
-
this.timer = null;
|
|
13
|
-
this.lastSyncAt = null;
|
|
14
|
-
this.intervalMs = Math.max(5000, cfg.intervalMs ?? 30000);
|
|
15
|
-
}
|
|
16
|
-
async bootstrap(context) {
|
|
17
|
-
this.ctx = context;
|
|
18
|
-
this.start();
|
|
19
|
-
}
|
|
20
|
-
async dispose() {
|
|
21
|
-
this.stop();
|
|
22
|
-
}
|
|
23
|
-
start() {
|
|
24
|
-
this.stop();
|
|
25
|
-
this.timer = setInterval(() => {
|
|
26
|
-
void this.syncNow().catch(() => { });
|
|
27
|
-
}, this.intervalMs);
|
|
28
|
-
}
|
|
29
|
-
stop() {
|
|
30
|
-
if (this.timer) {
|
|
31
|
-
clearInterval(this.timer);
|
|
32
|
-
this.timer = null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async syncNow() {
|
|
36
|
-
const { eventBus } = this.ctx;
|
|
37
|
-
const nowISO = new Date().toISOString();
|
|
38
|
-
try {
|
|
39
|
-
eventBus.emit('sync:started', { at: nowISO });
|
|
40
|
-
const since = this.getLastSyncAt() || new Date(0).toISOString();
|
|
41
|
-
const localDelta = await this.buildLocalChanges(since);
|
|
42
|
-
await this.provider.pushChanges(localDelta, { nowISO });
|
|
43
|
-
const remote = await this.provider.pullChanges(since, { nowISO });
|
|
44
|
-
await this.applyRemoteChanges(remote);
|
|
45
|
-
this.setLastSyncAt(nowISO);
|
|
46
|
-
eventBus.emit('sync:completed', { at: nowISO });
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
eventBus.emit('sync:error', { at: nowISO, error: String(error) });
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async buildLocalChanges(sinceISO) {
|
|
54
|
-
const out = {};
|
|
55
|
-
const { storage } = this.ctx;
|
|
56
|
-
const items = await storage.getAllAsync(`SELECT id, type, ean, name, dosage, meta, created_at, updated_at, deleted_at, version FROM items WHERE updated_at > ?`, [sinceISO]);
|
|
57
|
-
if (items.length) {
|
|
58
|
-
out.items = {
|
|
59
|
-
inserts: items,
|
|
60
|
-
updates: [],
|
|
61
|
-
deletes: items.filter((i) => i.deleted_at).map((i) => ({ id: i.id, deletedAt: i.deleted_at })),
|
|
62
|
-
since: sinceISO
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const plans = await storage.getAllAsync(`SELECT id, item_id, schedule_rule, tz, starts_at, ends_at, created_at, updated_at, deleted_at, version FROM plans WHERE updated_at > ?`, [sinceISO]);
|
|
66
|
-
if (plans.length) {
|
|
67
|
-
out.plans = {
|
|
68
|
-
inserts: plans,
|
|
69
|
-
updates: [],
|
|
70
|
-
deletes: plans.filter((p) => p.deleted_at).map((p) => ({ id: p.id, deletedAt: p.deleted_at })),
|
|
71
|
-
since: sinceISO
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const occurrences = await storage.getAllAsync(`SELECT id, plan_id, scheduled_at, kind, status, qty, created_at, updated_at, deleted_at, version FROM occurrences WHERE updated_at > ?`, [sinceISO]);
|
|
75
|
-
if (occurrences.length) {
|
|
76
|
-
out.occurrences = {
|
|
77
|
-
inserts: occurrences,
|
|
78
|
-
updates: [],
|
|
79
|
-
deletes: occurrences.filter((o) => o.deleted_at).map((o) => ({ id: o.id, deletedAt: o.deleted_at })),
|
|
80
|
-
since: sinceISO
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const events = await storage.getAllAsync(`SELECT id, occurrence_id, action, action_at, source, note, payload, updated_at, deleted_at, version FROM events WHERE updated_at > ?`, [sinceISO]);
|
|
84
|
-
if (events.length) {
|
|
85
|
-
out.events = {
|
|
86
|
-
inserts: events,
|
|
87
|
-
updates: [],
|
|
88
|
-
deletes: events.filter((e) => e.deleted_at).map((e) => ({ id: e.id, deletedAt: e.deleted_at })),
|
|
89
|
-
since: sinceISO
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const meds = await storage.getAllAsync(`SELECT id, ean, name, description, concentration, qty_label, current_qty_label, total_quantity, used_quantity, remaining, form, lab, active, complement, status, added_at, updated_at, deleted_at, version FROM medications WHERE updated_at > ?`, [sinceISO]);
|
|
93
|
-
if (meds.length) {
|
|
94
|
-
out.medications = {
|
|
95
|
-
inserts: meds,
|
|
96
|
-
updates: [],
|
|
97
|
-
deletes: meds.filter((m) => m.deleted_at).map((m) => ({ id: m.id, deletedAt: m.deleted_at })),
|
|
98
|
-
since: sinceISO
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
const deletes = await storage.getAllAsync(`SELECT entity, entity_id as id, deleted_at FROM sync_deletes WHERE deleted_at > ?`, [sinceISO]);
|
|
102
|
-
if (Array.isArray(deletes) && deletes.length) {
|
|
103
|
-
const byEntity = {};
|
|
104
|
-
for (const d of deletes) {
|
|
105
|
-
const arr = (byEntity[d.entity] = byEntity[d.entity] || []);
|
|
106
|
-
arr.push({ id: String(d.id), deletedAt: String(d.deleted_at) });
|
|
107
|
-
}
|
|
108
|
-
const entities = [
|
|
109
|
-
'items',
|
|
110
|
-
'plans',
|
|
111
|
-
'occurrences',
|
|
112
|
-
'events',
|
|
113
|
-
'medications'
|
|
114
|
-
];
|
|
115
|
-
for (const e of entities) {
|
|
116
|
-
const dels = byEntity[e];
|
|
117
|
-
if (!dels || dels.length === 0)
|
|
118
|
-
continue;
|
|
119
|
-
if (!out[e]) {
|
|
120
|
-
out[e] = { inserts: [], updates: [], deletes: dels, since: sinceISO };
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const existing = out[e];
|
|
124
|
-
existing.deletes = [...(existing.deletes || []), ...dels];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return out;
|
|
128
|
-
}
|
|
129
|
-
async applyRemoteChanges(changes) {
|
|
130
|
-
const { storage } = this.ctx;
|
|
131
|
-
const itemsSet = changes.items;
|
|
132
|
-
if (itemsSet) {
|
|
133
|
-
const repo = new ItemsRepository_1.ItemsRepository(storage);
|
|
134
|
-
for (const r of itemsSet.inserts || []) {
|
|
135
|
-
if (r && r.deleted_at)
|
|
136
|
-
continue;
|
|
137
|
-
await repo.upsert({
|
|
138
|
-
id: String(r.id),
|
|
139
|
-
type: String(r.type || 'MED'),
|
|
140
|
-
ean: r.ean ? String(r.ean) : undefined,
|
|
141
|
-
name: String(r.name || ''),
|
|
142
|
-
dosage: r.dosage ? String(r.dosage) : undefined,
|
|
143
|
-
meta: typeof r.meta === 'string' ? safelyParseJSON(r.meta) : (r.meta || null)
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
for (const d of itemsSet.deletes || []) {
|
|
147
|
-
if (!d?.id)
|
|
148
|
-
continue;
|
|
149
|
-
await storage.runAsync('DELETE FROM items WHERE id = ?', [d.id]);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const plansSet = changes.plans;
|
|
153
|
-
if (plansSet) {
|
|
154
|
-
const repo = new PlansRepository_1.PlansRepository(storage);
|
|
155
|
-
for (const r of plansSet.inserts || []) {
|
|
156
|
-
if (r && r.deleted_at)
|
|
157
|
-
continue;
|
|
158
|
-
await repo.upsert({
|
|
159
|
-
id: String(r.id),
|
|
160
|
-
item_id: String(r.item_id),
|
|
161
|
-
schedule_rule: typeof r.schedule_rule === 'string' ? safelyParseJSON(r.schedule_rule) : r.schedule_rule,
|
|
162
|
-
tz: String(r.tz || 'America/Sao_Paulo'),
|
|
163
|
-
starts_at: String(r.starts_at),
|
|
164
|
-
ends_at: r.ends_at ? String(r.ends_at) : undefined
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
for (const d of plansSet.deletes || []) {
|
|
168
|
-
if (!d?.id)
|
|
169
|
-
continue;
|
|
170
|
-
await storage.runAsync('DELETE FROM plans WHERE id = ?', [d.id]);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const occSet = changes.occurrences;
|
|
174
|
-
if (occSet) {
|
|
175
|
-
const repo = new OccurrencesRepository_1.OccurrencesRepository(storage);
|
|
176
|
-
const toInsert = (occSet.inserts || []).filter((r) => !r?.deleted_at).map((r) => ({
|
|
177
|
-
id: String(r.id),
|
|
178
|
-
plan_id: String(r.plan_id),
|
|
179
|
-
scheduled_at: String(r.scheduled_at),
|
|
180
|
-
kind: String(r.kind || 'MED'),
|
|
181
|
-
qty: Number(r.qty || 1)
|
|
182
|
-
}));
|
|
183
|
-
if (toInsert.length) {
|
|
184
|
-
await repo.insertMany(toInsert);
|
|
185
|
-
}
|
|
186
|
-
for (const r of occSet.inserts || []) {
|
|
187
|
-
if (r?.status && typeof r.status === 'string') {
|
|
188
|
-
try {
|
|
189
|
-
await repo.updateStatus(String(r.id), String(r.status));
|
|
190
|
-
}
|
|
191
|
-
catch { }
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
for (const d of occSet.deletes || []) {
|
|
195
|
-
if (!d?.id)
|
|
196
|
-
continue;
|
|
197
|
-
await storage.runAsync('DELETE FROM occurrences WHERE id = ?', [d.id]);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const evSet = changes.events;
|
|
201
|
-
if (evSet) {
|
|
202
|
-
for (const r of evSet.inserts || []) {
|
|
203
|
-
if (r && r.deleted_at)
|
|
204
|
-
continue;
|
|
205
|
-
try {
|
|
206
|
-
await storage.runAsync(`INSERT OR IGNORE INTO events (id, occurrence_id, action, action_at, source, note, payload) VALUES (?, ?, ?, ?, ?, ?, ?)`, [String(r.id), String(r.occurrence_id), String(r.action), String(r.action_at || new Date().toISOString()), String(r.source || 'screen'), r.note || null, typeof r.payload === 'string' ? r.payload : (r.payload ? JSON.stringify(r.payload) : null)]);
|
|
207
|
-
}
|
|
208
|
-
catch { }
|
|
209
|
-
}
|
|
210
|
-
for (const d of evSet.deletes || []) {
|
|
211
|
-
if (!d?.id)
|
|
212
|
-
continue;
|
|
213
|
-
await storage.runAsync('DELETE FROM events WHERE id = ?', [d.id]);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const medsSet = changes.medications;
|
|
217
|
-
if (medsSet) {
|
|
218
|
-
const repo = new MedicationsRepository_1.MedicationsRepository(storage);
|
|
219
|
-
for (const r of medsSet.inserts || []) {
|
|
220
|
-
if (r && r.deleted_at)
|
|
221
|
-
continue;
|
|
222
|
-
await repo.upsert({
|
|
223
|
-
id: String(r.id),
|
|
224
|
-
ean: r.ean ? String(r.ean) : undefined,
|
|
225
|
-
name: String(r.name || ''),
|
|
226
|
-
description: r.description || undefined,
|
|
227
|
-
concentration: r.concentration || undefined,
|
|
228
|
-
qty_label: r.qty_label || undefined,
|
|
229
|
-
current_qty_label: r.current_qty_label || undefined,
|
|
230
|
-
total_quantity: Number(r.total_quantity ?? 1),
|
|
231
|
-
used_quantity: Number(r.used_quantity ?? 0),
|
|
232
|
-
remaining: Number(r.remaining ?? 0),
|
|
233
|
-
form: r.form || undefined,
|
|
234
|
-
lab: r.lab || undefined,
|
|
235
|
-
active: r.active || undefined,
|
|
236
|
-
complement: r.complement || undefined
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
for (const d of medsSet.deletes || []) {
|
|
240
|
-
if (!d?.id)
|
|
241
|
-
continue;
|
|
242
|
-
await storage.runAsync('DELETE FROM medications WHERE id = ?', [d.id]);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
getLastSyncAt() {
|
|
247
|
-
return this.lastSyncAt;
|
|
248
|
-
}
|
|
249
|
-
setLastSyncAt(value) {
|
|
250
|
-
this.lastSyncAt = value;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
exports.SyncPluginPolling = SyncPluginPolling;
|
|
254
|
-
function safelyParseJSON(input) {
|
|
255
|
-
if (input == null)
|
|
256
|
-
return null;
|
|
257
|
-
if (typeof input !== 'string')
|
|
258
|
-
return input;
|
|
259
|
-
try {
|
|
260
|
-
return JSON.parse(String(input));
|
|
261
|
-
}
|
|
262
|
-
catch {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=SyncPluginPolling.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SyncPluginPolling.js","sourceRoot":"","sources":["../../src/plugins/SyncPluginPolling.ts"],"names":[],"mappings":";;;AAQA,8EAA2E;AAC3E,8EAA2E;AAC3E,0FAAuF;AACvF,0FAAuF;AAMvF,MAAa,iBAAiB;IAO5B,YAAoB,QAA2B,EAAE,MAA+B,EAAE;QAA9D,aAAQ,GAAR,QAAQ,CAAmB;QANtC,SAAI,GAAG,YAAY,CAAC;QAErB,UAAK,GAAQ,IAAI,CAAC;QAElB,eAAU,GAAkB,IAAI,CAAC;QAGvC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,IAAI,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAsB;QACpC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC;QACnB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC5B,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO;Q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,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;gBACtC,IAAI,CAAC,CAAC,EAAE,EAAE;oBAAE,SAAS;gBACrB,MAAM,OAAO,CAAC,QAAQ,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;IACH,CAAC;IAEO,aAAa;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAEO,aAAa,CAAC,KAAa;QACjC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC1B,CAAC;CACF;AAzSD,8CAySC;AAGD,SAAS,eAAe,CAAC,KAAU;IACjC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hysteresis.spec.d.ts","sourceRoot":"","sources":["../../../../src/plugins/gamification/__tests__/hysteresis.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_test_1 = require("node:test");
|
|
7
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
-
const levelsEngine_1 = require("../../gamification/levelsEngine");
|
|
9
|
-
(0, node_test_1.describe)('Levels hysteresis (concept)', () => {
|
|
10
|
-
(0, node_test_1.it)('keeps previous level if badDaysInRow <= tolerance', () => {
|
|
11
|
-
const levels = [
|
|
12
|
-
{ id: 'novice', name: 'Novato', range: [0, 6], tolerance: 0 },
|
|
13
|
-
{ id: 'bronze', name: 'Bronze', range: [7, 13], tolerance: 0 },
|
|
14
|
-
{ id: 'silver', name: 'Prata', range: [14, 29], tolerance: 0 },
|
|
15
|
-
{ id: 'gold', name: 'Ouro', range: [30, 59], tolerance: 1 },
|
|
16
|
-
];
|
|
17
|
-
const streak = 29;
|
|
18
|
-
const suggested = (0, levelsEngine_1.getLevelForStreak)(streak, levels);
|
|
19
|
-
node_assert_1.default.equal(suggested.levelId, 'silver');
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
//# sourceMappingURL=hysteresis.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hysteresis.spec.js","sourceRoot":"","sources":["../../../../src/plugins/gamification/__tests__/hysteresis.spec.ts"],"names":[],"mappings":";;;;;AAGA,yCAAyC;AACzC,8DAAiC;AACjC,kEAAoE;AAEpE,IAAA,oBAAQ,EAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,IAAA,cAAE,EAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG;YACb,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;YAC7D,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;YAC9D,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;YAC9D,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;SAC5D,CAAC;QAEF,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,MAAM,SAAS,GAAG,IAAA,gCAAiB,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACpD,qBAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { StorageDriver, ScheduleRule } from '../core/types';
|
|
2
|
-
import { EventBus } from '../core/EventBus';
|
|
3
|
-
export declare class MedicationsServiceCompat {
|
|
4
|
-
private meds;
|
|
5
|
-
private items;
|
|
6
|
-
private plans;
|
|
7
|
-
private eventBus;
|
|
8
|
-
constructor(storage: StorageDriver, eventBus: EventBus);
|
|
9
|
-
addMedication(medicationData: any, schedules?: string[], usedQuantity?: number): Promise<any>;
|
|
10
|
-
getMedications(): Promise<any[]>;
|
|
11
|
-
searchMedications(searchTerm: string): Promise<any[]>;
|
|
12
|
-
updateUsedQuantity(ean: string, newUsedQuantity: number): Promise<void>;
|
|
13
|
-
removeMedication(ean: string): Promise<void>;
|
|
14
|
-
clearMedications(): Promise<void>;
|
|
15
|
-
getStatusCounts(): Promise<Array<{
|
|
16
|
-
status: string;
|
|
17
|
-
count: number;
|
|
18
|
-
}>>;
|
|
19
|
-
convertToScheduleRule(routine: any, schedules: string[]): ScheduleRule | null;
|
|
20
|
-
syncToNotifications(medication: any, routine: any, schedules: string[]): Promise<void>;
|
|
21
|
-
removeOldPlans(medicationId: string): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export default MedicationsServiceCompat;
|
|
24
|
-
//# sourceMappingURL=MedicationsServiceCompat.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MedicationsServiceCompat.d.ts","sourceRoot":"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G1D;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MedicationsServiceCompat = void 0;
|
|
4
|
-
const repositories_1 = require("../database/repositories");
|
|
5
|
-
class MedicationsServiceCompat {
|
|
6
|
-
constructor(storage, eventBus) {
|
|
7
|
-
this.meds = new repositories_1.MedicationsRepository(storage);
|
|
8
|
-
this.items = new repositories_1.ItemsRepository(storage);
|
|
9
|
-
this.plans = new repositories_1.PlansRepository(storage);
|
|
10
|
-
this.eventBus = eventBus;
|
|
11
|
-
}
|
|
12
|
-
async addMedication(medicationData, schedules = ['08:00'], usedQuantity = 0) {
|
|
13
|
-
const id = medicationData.ean || `med:${Date.now()}`;
|
|
14
|
-
await this.meds.upsert({
|
|
15
|
-
id,
|
|
16
|
-
ean: medicationData.ean || id,
|
|
17
|
-
name: medicationData.name,
|
|
18
|
-
concentration: medicationData.concentration || null,
|
|
19
|
-
qty_label: medicationData.qty_label || null,
|
|
20
|
-
form: medicationData.form || null,
|
|
21
|
-
lab: medicationData.lab || null,
|
|
22
|
-
total_quantity: Number(medicationData.total_quantity ?? 1),
|
|
23
|
-
used_quantity: Number(usedQuantity || 0),
|
|
24
|
-
remaining: undefined,
|
|
25
|
-
status: 'normal'
|
|
26
|
-
});
|
|
27
|
-
await this.syncToNotifications({ ean: id, name: medicationData.name, concentration: medicationData.concentration, form: medicationData.form, lab: medicationData.lab, qty_label: medicationData.qty_label }, null, schedules);
|
|
28
|
-
return { ean: id };
|
|
29
|
-
}
|
|
30
|
-
async getMedications() {
|
|
31
|
-
return await this.meds.getAll();
|
|
32
|
-
}
|
|
33
|
-
async searchMedications(searchTerm) {
|
|
34
|
-
return await this.meds.searchByName(searchTerm);
|
|
35
|
-
}
|
|
36
|
-
async updateUsedQuantity(ean, newUsedQuantity) {
|
|
37
|
-
await this.meds.updateUsedQuantity(ean, newUsedQuantity);
|
|
38
|
-
}
|
|
39
|
-
async removeMedication(ean) {
|
|
40
|
-
await this.plans.endActiveByItem(ean);
|
|
41
|
-
await this.meds.removeByEan(ean);
|
|
42
|
-
this.eventBus.emit('plans:changed', { medicationId: ean, reason: 'removed' });
|
|
43
|
-
}
|
|
44
|
-
async clearMedications() {
|
|
45
|
-
await this.meds.clearAll();
|
|
46
|
-
}
|
|
47
|
-
async getStatusCounts() {
|
|
48
|
-
return await this.meds.getStatusCounts();
|
|
49
|
-
}
|
|
50
|
-
convertToScheduleRule(routine, schedules) {
|
|
51
|
-
try {
|
|
52
|
-
if (routine && routine.kind)
|
|
53
|
-
return routine;
|
|
54
|
-
if (schedules && schedules.length > 0) {
|
|
55
|
-
return { kind: 'TIMES', times: schedules, timesQtys: new Array(schedules.length).fill(1), daysOfWeek: [], defaultSnoozeMin: 5 };
|
|
56
|
-
}
|
|
57
|
-
return { kind: 'TIMES', times: ['08:00'], timesQtys: [1], daysOfWeek: [], defaultSnoozeMin: 5 };
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async syncToNotifications(medication, routine, schedules) {
|
|
64
|
-
const itemId = medication.ean;
|
|
65
|
-
await this.items.upsert({
|
|
66
|
-
id: itemId,
|
|
67
|
-
type: 'MED',
|
|
68
|
-
ean: medication.ean,
|
|
69
|
-
name: medication.name,
|
|
70
|
-
dosage: medication.concentration || null,
|
|
71
|
-
meta: {
|
|
72
|
-
ean: medication.ean,
|
|
73
|
-
concentration: medication.concentration,
|
|
74
|
-
form: medication.form,
|
|
75
|
-
lab: medication.lab,
|
|
76
|
-
qty_label: medication.qty_label
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
await this.plans.endActiveByItem(itemId);
|
|
80
|
-
const rule = this.convertToScheduleRule(routine, schedules);
|
|
81
|
-
if (rule) {
|
|
82
|
-
await this.plans.upsert({
|
|
83
|
-
id: `plan:${itemId}:${Date.now()}`,
|
|
84
|
-
item_id: itemId,
|
|
85
|
-
schedule_rule: rule,
|
|
86
|
-
starts_at: new Date().toISOString(),
|
|
87
|
-
ends_at: null,
|
|
88
|
-
tz: 'America/Sao_Paulo'
|
|
89
|
-
});
|
|
90
|
-
this.eventBus.emit('plans:changed', { medicationId: itemId });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async removeOldPlans(medicationId) {
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.MedicationsServiceCompat = MedicationsServiceCompat;
|
|
97
|
-
exports.default = MedicationsServiceCompat;
|
|
98
|
-
//# sourceMappingURL=MedicationsServiceCompat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MedicationsServiceCompat.js","sourceRoot":"","sources":["../../src/services/MedicationsServiceCompat.ts"],"names":[],"mappings":";;;AAMA,2DAAmG;AAInG,MAAa,wBAAwB;IAMnC,YAAY,OAAsB,EAAE,QAAkB;QACpD,IAAI,CAAC,IAAI,GAAG,IAAI,oCAAqB,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,GAAG,IAAI,8BAAe,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,8BAAe,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAGD,KAAK,CAAC,aAAa,CAAC,cAAmB,EAAE,YAAsB,CAAC,OAAO,CAAC,EAAE,eAAuB,CAAC;QAEhG,MAAM,EAAE,GAAG,cAAc,CAAC,GAAG,IAAI,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;YACrB,EAAE;YACF,GAAG,EAAE,cAAc,CAAC,GAAG,IAAI,EAAE;YAC7B,IAAI,EAAE,cAAc,CAAC,IAAI;YACzB,aAAa,EAAE,cAAc,CAAC,aAAa,IAAI,I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