@ovok/native 1.17.0-dev.2260 → 1.17.0-dev.2264
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/lib/commonjs/modules/next/bluetooth/adapters/chosen-patient.js +12 -5
- package/lib/commonjs/modules/next/bluetooth/adapters/chosen-patient.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/adapters/ovok-reading-sink.js +27 -119
- package/lib/commonjs/modules/next/bluetooth/adapters/ovok-reading-sink.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/adapters/reading-measurements.js +118 -0
- package/lib/commonjs/modules/next/bluetooth/adapters/reading-measurements.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/adapters/series-saving.js +14 -8
- package/lib/commonjs/modules/next/bluetooth/adapters/series-saving.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/core/bluetooth.js +2 -1
- package/lib/commonjs/modules/next/bluetooth/core/bluetooth.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/core/kept-stream.js +50 -0
- package/lib/commonjs/modules/next/bluetooth/core/kept-stream.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/core/live-ledger.js +3 -2
- package/lib/commonjs/modules/next/bluetooth/core/live-ledger.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/core/series-book.js +75 -0
- package/lib/commonjs/modules/next/bluetooth/core/series-book.js.map +1 -0
- package/lib/commonjs/modules/next/bluetooth/core/series-slots.js +8 -1
- package/lib/commonjs/modules/next/bluetooth/core/series-slots.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/core/stream-recorder.js +15 -15
- package/lib/commonjs/modules/next/bluetooth/core/stream-recorder.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/index.js +9 -1
- package/lib/commonjs/modules/next/bluetooth/index.js.map +1 -1
- package/lib/commonjs/modules/next/bluetooth/web/index.js +9 -1
- package/lib/commonjs/modules/next/bluetooth/web/index.js.map +1 -1
- package/lib/module/modules/next/bluetooth/adapters/chosen-patient.js +11 -5
- package/lib/module/modules/next/bluetooth/adapters/chosen-patient.js.map +1 -1
- package/lib/module/modules/next/bluetooth/adapters/ovok-reading-sink.js +28 -120
- package/lib/module/modules/next/bluetooth/adapters/ovok-reading-sink.js.map +1 -1
- package/lib/module/modules/next/bluetooth/adapters/reading-measurements.js +115 -0
- package/lib/module/modules/next/bluetooth/adapters/reading-measurements.js.map +1 -0
- package/lib/module/modules/next/bluetooth/adapters/series-saving.js +13 -8
- package/lib/module/modules/next/bluetooth/adapters/series-saving.js.map +1 -1
- package/lib/module/modules/next/bluetooth/core/bluetooth.js +2 -1
- package/lib/module/modules/next/bluetooth/core/bluetooth.js.map +1 -1
- package/lib/module/modules/next/bluetooth/core/kept-stream.js +45 -0
- package/lib/module/modules/next/bluetooth/core/kept-stream.js.map +1 -0
- package/lib/module/modules/next/bluetooth/core/live-ledger.js +3 -2
- package/lib/module/modules/next/bluetooth/core/live-ledger.js.map +1 -1
- package/lib/module/modules/next/bluetooth/core/series-book.js +72 -0
- package/lib/module/modules/next/bluetooth/core/series-book.js.map +1 -0
- package/lib/module/modules/next/bluetooth/core/series-slots.js +8 -1
- package/lib/module/modules/next/bluetooth/core/series-slots.js.map +1 -1
- package/lib/module/modules/next/bluetooth/core/stream-recorder.js +16 -16
- package/lib/module/modules/next/bluetooth/core/stream-recorder.js.map +1 -1
- package/lib/module/modules/next/bluetooth/index.js +1 -0
- package/lib/module/modules/next/bluetooth/index.js.map +1 -1
- package/lib/module/modules/next/bluetooth/web/index.js +1 -0
- package/lib/module/modules/next/bluetooth/web/index.js.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/chosen-patient.d.ts +13 -5
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/chosen-patient.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/ovok-reading-sink.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/ovok-reading-sink.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/reading-measurements.d.ts +7 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/reading-measurements.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/series-saving.d.ts +3 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/series-saving.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/bluetooth.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/kept-stream.d.ts +13 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/kept-stream.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/live-ledger.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/live-ledger.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/series-book.d.ts +29 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/series-book.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/series-slots.d.ts +3 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/series-slots.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/stream-recorder.d.ts +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/core/stream-recorder.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/index.d.ts +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/next/bluetooth/web/index.d.ts +1 -0
- package/lib/typescript/commonjs/src/modules/next/bluetooth/web/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/chosen-patient.d.ts +13 -5
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/chosen-patient.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/ovok-reading-sink.d.ts +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/ovok-reading-sink.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/reading-measurements.d.ts +7 -0
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/reading-measurements.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/series-saving.d.ts +3 -1
- package/lib/typescript/module/src/modules/next/bluetooth/adapters/series-saving.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/bluetooth.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/kept-stream.d.ts +13 -0
- package/lib/typescript/module/src/modules/next/bluetooth/core/kept-stream.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/core/live-ledger.d.ts +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/live-ledger.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/series-book.d.ts +29 -0
- package/lib/typescript/module/src/modules/next/bluetooth/core/series-book.d.ts.map +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/core/series-slots.d.ts +3 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/series-slots.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/stream-recorder.d.ts +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/core/stream-recorder.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/index.d.ts +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/next/bluetooth/web/index.d.ts +1 -0
- package/lib/typescript/module/src/modules/next/bluetooth/web/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -25,6 +25,7 @@ const coveredBy = ({
|
|
|
25
25
|
from: waveform.firstSampleAt.getTime(),
|
|
26
26
|
to: waveform.firstSampleAt.getTime() + (waveform.samples[0]?.length ?? 0) / waveform.sampleRateHz * MS_PER_SECOND
|
|
27
27
|
}] : [])];
|
|
28
|
+
const isSameRecording = (a, b) => a.metric === b.metric && a.channel === b.channel && a.from.getTime() === b.from.getTime();
|
|
28
29
|
const isInside = ({
|
|
29
30
|
from,
|
|
30
31
|
to
|
|
@@ -34,9 +35,9 @@ const isInside = ({
|
|
|
34
35
|
class LiveLedger {
|
|
35
36
|
spans = [];
|
|
36
37
|
|
|
37
|
-
/** Remembers a recording that was saved whole. */
|
|
38
|
+
/** Remembers a recording that was saved whole; a longer save of the same recording takes the place of the shorter. */
|
|
38
39
|
add(span) {
|
|
39
|
-
this.spans = [...this.spans, span].slice(-MAX_KEPT_SPANS);
|
|
40
|
+
this.spans = [...this.spans.filter(kept => !isSameRecording(kept, span)), span].slice(-MAX_KEPT_SPANS);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/** The recordings of the same metric that lie inside what a stored record covers. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MAX_KEPT_SPANS","EDGE_TOLERANCE_MS","MS_PER_SECOND","coveredBy","series","waveform","metric","from","start","getTime","to","values","length","intervalMs","firstSampleAt","samples","sampleRateHz","isInside","covered","LiveLedger","spans","add","span","slice","inside","record","covers","
|
|
1
|
+
{"version":3,"names":["MAX_KEPT_SPANS","EDGE_TOLERANCE_MS","MS_PER_SECOND","coveredBy","series","waveform","metric","from","start","getTime","to","values","length","intervalMs","firstSampleAt","samples","sampleRateHz","isSameRecording","a","b","channel","isInside","covered","LiveLedger","spans","add","span","filter","kept","slice","inside","record","covers","some","remove","replaced","includes","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/core/live-ledger.ts"],"mappings":";;;;;;AAEA,MAAMA,cAAc,GAAG,GAAG;;AAE1B;AACA,MAAMC,iBAAiB,GAAG,KAAK;AAE/B,MAAMC,aAAa,GAAG,KAAK;;AAE3B;;AAGA;AACA,MAAMC,SAAS,GAAGA,CAAC;EAAEC,MAAM;EAAEC;AAAyB,CAAC,KAAgB,CACr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B,IAAI,CAACF,KAAK,GAAG,CAAC,GAAG,IAAI,CAACA,KAAK,CAACG,MAAM,CAAEC,IAAI,IAAK,CAACX,eAAe,CAACW,IAAI,EAAEF,IAAI,CAAC,CAAC,EAAEA,IAAI,CAAC,CAACG,KAAK,CAAC,CAAC7B,cAAc,CAAC;EAC1G;;EAEA;EACO8B,MAAMA,CAACC,MAAsB,EAAc;IAChD,MAAMC,MAAM,GAAG7B,SAAS,CAAC4B,MAAM,CAAC;IAEhC,OAAO,IAAI,CAACP,KAAK,CAACG,MAAM,CAAED,IAAI,IAAKM,MAAM,CAACC,IAAI,CAAEX,OAAO,IAAKA,OAAO,CAAChB,MAAM,KAAKoB,IAAI,CAACpB,MAAM,IAAIe,QAAQ,CAACK,IAAI,EAAEJ,OAAO,CAAC,CAAC,CAAC;EACzH;;EAEA;EACOY,MAAMA,CAACC,QAA6B,EAAQ;IACjD,IAAI,CAACX,KAAK,GAAG,IAAI,CAACA,KAAK,CAACG,MAAM,CAAED,IAAI,IAAK,CAACS,QAAQ,CAACC,QAAQ,CAACV,IAAI,CAAC,CAAC;EACpE;AACF;AAACW,OAAA,CAAAd,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SeriesBook = void 0;
|
|
7
|
+
var _seriesSlots = require("./series-slots.js");
|
|
8
|
+
/** Where a value goes: the series it is put in, and the open series of its metric that it ended, to be saved. */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Each metric's open series and the one it last closed. A value that still belongs to the closed series carries it
|
|
12
|
+
* on, so screen changes, backgrounding and reconnects within the quiet window keep one recording under one name.
|
|
13
|
+
*/
|
|
14
|
+
class SeriesBook {
|
|
15
|
+
open = new Map();
|
|
16
|
+
closed = new Map();
|
|
17
|
+
|
|
18
|
+
/** The series a value of `kind` taken at `at` goes in: carried on when it still belongs there, otherwise a new one. */
|
|
19
|
+
place(kind, at) {
|
|
20
|
+
const carried = this.carriedOn(kind, at);
|
|
21
|
+
if (carried) {
|
|
22
|
+
this.open.set(kind.metric, carried);
|
|
23
|
+
return {
|
|
24
|
+
series: carried
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const ended = this.close(kind.metric);
|
|
28
|
+
const series = new _seriesSlots.SlotSeries(kind, at);
|
|
29
|
+
this.closed.delete(kind.metric);
|
|
30
|
+
this.open.set(kind.metric, series);
|
|
31
|
+
return {
|
|
32
|
+
series,
|
|
33
|
+
ended
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Closes the metric's open series and keeps it, so a value soon after carries it on; the series closed, if any. */
|
|
38
|
+
close(metric) {
|
|
39
|
+
const series = this.open.get(metric);
|
|
40
|
+
this.open.delete(metric);
|
|
41
|
+
if (series) {
|
|
42
|
+
this.closed.set(metric, series);
|
|
43
|
+
}
|
|
44
|
+
return series;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The open series, by metric. */
|
|
48
|
+
openSeries() {
|
|
49
|
+
return [...this.open];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Whether any series is open. */
|
|
53
|
+
get hasOpen() {
|
|
54
|
+
return this.open.size > 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A stored record replaced this recording, so it is never carried on and saved again. */
|
|
58
|
+
forget(span) {
|
|
59
|
+
[...this.closed].forEach(([metric, series]) => {
|
|
60
|
+
if (series.began(span)) {
|
|
61
|
+
this.closed.delete(metric);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
carriedOn(kind, at) {
|
|
66
|
+
const series = this.open.get(kind.metric) ?? this.closed.get(kind.metric);
|
|
67
|
+
if (!series?.takes(kind.unit, at)) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
this.closed.delete(kind.metric);
|
|
71
|
+
return series;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.SeriesBook = SeriesBook;
|
|
75
|
+
//# sourceMappingURL=series-book.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_seriesSlots","require","SeriesBook","open","Map","closed","place","kind","at","carried","carriedOn","set","metric","series","ended","close","SlotSeries","delete","get","openSeries","hasOpen","size","forget","span","forEach","began","takes","unit","undefined","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/core/series-book.ts"],"mappings":";;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AAEA;;AAGA;AACA;AACA;AACA;AACA,MAAMC,UAAU,CAAC;EACEC,IAAI,GAAG,IAAIC,GAAG,CAAyB,CAAC;EACxCC,MAAM,GAAG,IAAID,GAAG,CAAyB,CAAC;;EAE3D;EACOE,KAAKA,CAACC,IAAgB,EAAEC,EAAU,EAAa;IACpD,MAAMC,OAAO,GAAG,IAAI,CAACC,SAAS,CAACH,IAAI,EAAEC,EAAE,CAAC;IAExC,IAAIC,OAAO,EAAE;MACX,IAAI,CAACN,IAAI,CAACQ,GAAG,CAACJ,IAAI,CAACK,MAAM,EAAEH,OAAO,CAAC;MAEnC,OAAO;QAAEI,MAAM,EAAEJ;MAAQ,CAAC;IAC5B;IAEA,MAAMK,KAAK,GAAG,IAAI,CAACC,KAAK,CAACR,IAAI,CAACK,MAAM,CAAC;IACrC,MAAMC,MAAM,GAAG,IAAIG,uBAAU,CAACT,IAAI,EAAEC,EAAE,CAAC;IAEvC,IAAI,CAACH,MAAM,CAACY,MAAM,CAACV,IAAI,CAACK,MAAM,CAAC;IAC/B,IAAI,CAACT,IAAI,CAACQ,GAAG,CAACJ,IAAI,CAACK,MAAM,EAAEC,MAAM,CAAC;IAElC,OAAO;MAAEA,MAAM;MAAEC;IAAM,CAAC;EAC1B;;EAEA;EACOC,KAAKA,CAACH,MAAkB,EAA0B;IACvD,MAAMC,MAAM,GA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|
6
6
|
exports.SlotSeries = exports.RECORDED_METRICS = void 0;
|
|
7
7
|
const SLOT_MS = 1_000;
|
|
8
8
|
const SLOTS_PER_SERIES = 3_600;
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
/** A gap this long ends a series; anything shorter, a stream restart or a reconnect included, carries it on. */
|
|
11
|
+
const IDLE_CLOSE_MS = 60_000;
|
|
10
12
|
|
|
11
13
|
/** The streamed numbers worth recording as a series, each with the measurement it belongs to. */
|
|
12
14
|
const RECORDED_METRICS = exports.RECORDED_METRICS = {
|
|
@@ -46,6 +48,11 @@ class SlotSeries {
|
|
|
46
48
|
this.changed = true;
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/** Whether this series is the recording `span` was saved from. */
|
|
52
|
+
began(span) {
|
|
53
|
+
return span.metric === this.kind.metric && span.channel === null && span.from.getTime() === this.start;
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
/** Whether no value arrived for as long as a series waits before it closes. */
|
|
50
57
|
isQuiet(now) {
|
|
51
58
|
return now - this.lastAt >= IDLE_CLOSE_MS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SLOT_MS","SLOTS_PER_SERIES","IDLE_CLOSE_MS","RECORDED_METRICS","exports","heart_rate","pulse_rate","spo2","perfusion_index","respiration_rate","body_temperature","SlotSeries","values","changed","constructor","kind","firstAt","start","Math","floor","lastAt","takes","unit","at","slotOf","put","value","slot","length","push","isQuiet","now","unsaved","markSaved","reading","origin","
|
|
1
|
+
{"version":3,"names":["SLOT_MS","SLOTS_PER_SERIES","IDLE_CLOSE_MS","RECORDED_METRICS","exports","heart_rate","pulse_rate","spo2","perfusion_index","respiration_rate","body_temperature","SlotSeries","values","changed","constructor","kind","firstAt","start","Math","floor","lastAt","takes","unit","at","slotOf","put","value","slot","length","push","began","span","metric","channel","from","getTime","isQuiet","now","unsaved","markSaved","reading","origin","type","takenAt","deviceFlags","series","intervalMs","live","source","Date","to"],"sourceRoot":"../../../../../../src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B,IAAI,CAACiB,MAAM;MACxBC,OAAO,EAAE,IAAI;MACbC,IAAI,EAAE,IAAIe,IAAI,CAAC,IAAI,CAAChC,KAAK,CAAC;MAC1BiC,EAAE,EAAE,IAAID,IAAI,CAAC,IAAI,CAAChC,KAAK,GAAG,IAAI,CAACL,MAAM,CAACgB,MAAM,GAAG5B,OAAO;IACxD,CAAC;EACH;EAEQwB,MAAMA,CAACD,EAAU,EAAU;IACjC,OAAOL,IAAI,CAACC,KAAK,CAAC,CAACI,EAAE,GAAG,IAAI,CAACN,KAAK,IAAIjB,OAAO,CAAC;EAChD;AACF;AAACI,OAAA,CAAAO,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.StreamRecorder = void 0;
|
|
7
7
|
var _errors = require("./errors.js");
|
|
8
8
|
var _liveLedger = require("./live-ledger.js");
|
|
9
|
+
var _seriesBook = require("./series-book.js");
|
|
9
10
|
var _seriesSlots = require("./series-slots.js");
|
|
10
11
|
var _waveformSegments = require("./waveform-segments.js");
|
|
11
12
|
const MS_PER_SECOND = 1_000;
|
|
@@ -18,7 +19,7 @@ const SAVE_OPEN_EVERY_MS = 60_000;
|
|
|
18
19
|
* as segments of five minutes at the waveform's own sample rate. It does the same for every device.
|
|
19
20
|
*/
|
|
20
21
|
class StreamRecorder {
|
|
21
|
-
|
|
22
|
+
book = new _seriesBook.SeriesBook();
|
|
22
23
|
segments = new Map();
|
|
23
24
|
ledger = new _liveLedger.LiveLedger();
|
|
24
25
|
replacing = new Map();
|
|
@@ -68,14 +69,16 @@ class StreamRecorder {
|
|
|
68
69
|
|
|
69
70
|
/** The record was saved, so the recordings it replaced are gone for good. */
|
|
70
71
|
acknowledged(recordId) {
|
|
71
|
-
this.
|
|
72
|
+
const replaced = this.replacing.get(recordId) ?? [];
|
|
73
|
+
this.ledger.remove(replaced);
|
|
72
74
|
this.replacing.delete(recordId);
|
|
75
|
+
replaced.forEach(span => this.book.forget(span));
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
/** Saves everything still open, and resolves once every save has finished. */
|
|
76
79
|
close() {
|
|
77
80
|
this.stopTimer();
|
|
78
|
-
|
|
81
|
+
this.book.openSeries().forEach(([metric]) => this.finish(metric));
|
|
79
82
|
this.segments.forEach(segment => segment.flush().forEach(reading => this.saveSettled(reading)));
|
|
80
83
|
this.segments.clear();
|
|
81
84
|
return this.saving;
|
|
@@ -112,15 +115,13 @@ class StreamRecorder {
|
|
|
112
115
|
});
|
|
113
116
|
}
|
|
114
117
|
seriesFor(kind, at) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (
|
|
120
|
-
this.
|
|
118
|
+
const {
|
|
119
|
+
series,
|
|
120
|
+
ended
|
|
121
|
+
} = this.book.place(kind, at);
|
|
122
|
+
if (ended) {
|
|
123
|
+
this.saveSettled(ended.reading(this.origin));
|
|
121
124
|
}
|
|
122
|
-
const series = new _seriesSlots.SlotSeries(kind, at);
|
|
123
|
-
this.open.set(kind.metric, series);
|
|
124
125
|
this.timer ??= setInterval(() => this.saveOpenSeries(), SAVE_OPEN_EVERY_MS);
|
|
125
126
|
return series;
|
|
126
127
|
}
|
|
@@ -159,7 +160,7 @@ class StreamRecorder {
|
|
|
159
160
|
/** The 60-second save: an open series that grew goes out again under its own name, so the outbox keeps one copy. */
|
|
160
161
|
saveOpenSeries() {
|
|
161
162
|
const now = this.deps.now().getTime();
|
|
162
|
-
|
|
163
|
+
this.book.openSeries().forEach(([metric, series]) => {
|
|
163
164
|
if (series.isQuiet(now)) {
|
|
164
165
|
this.finish(metric);
|
|
165
166
|
} else if (series.unsaved) {
|
|
@@ -167,13 +168,12 @@ class StreamRecorder {
|
|
|
167
168
|
series.markSaved();
|
|
168
169
|
}
|
|
169
170
|
});
|
|
170
|
-
if (this.
|
|
171
|
+
if (!this.book.hasOpen) {
|
|
171
172
|
this.stopTimer();
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
finish(metric) {
|
|
175
|
-
const series = this.
|
|
176
|
-
this.open.delete(metric);
|
|
176
|
+
const series = this.book.close(metric);
|
|
177
177
|
if (series) {
|
|
178
178
|
this.saveSettled(series.reading(this.origin));
|
|
179
179
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_errors","require","_liveLedger","_seriesSlots","_waveformSegments","MS_PER_SECOND","SAVE_OPEN_EVERY_MS","StreamRecorder","
|
|
1
|
+
{"version":3,"names":["_errors","require","_liveLedger","_seriesBook","_seriesSlots","_waveformSegments","MS_PER_SECOND","SAVE_OPEN_EVERY_MS","StreamRecorder","book","SeriesBook","segments","Map","ledger","LiveLedger","replacing","unsupported","Set","saving","Promise","resolve","streaming","constructor","device","sink","deps","origin","modelId","model","id","protocolId","protocol","address","recordId","follow","events","add","event","observe","kind","followStream","snapshot","live","recording","recordNumbers","values","recordWaveform","waveform","supersede","record","spans","inside","length","set","supersedes","acknowledged","replaced","get","remove","delete","forEach","span","forget","close","stopTimer","openSeries","metric","finish","segment","flush","reading","saveSettled","clear","measuringSince","at","Object","entries","quantity","type","RECORDED_METRICS","Number","isFinite","value","has","takenAt","getTime","seriesFor","unit","put","series","ended","place","timer","setInterval","saveOpenSeries","sampleRateHz","arrivedAt","now","channels","channel","index","samples","firstAt","firstSampleAt","segmentFor","scale","key","join","ChannelSegment","isQuiet","unsaved","enqueue","undefined","markSaved","hasOpen","onSaved","then","save","error","failed","DeviceError","code","logger","warn","clearInterval","exports"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/core/stream-recorder.ts"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAIA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAEA,MAAMK,aAAa,GAAG,KAAK;AAC3B,MAAMC,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E,mBAAW,IAAIF,KAAK,CAACG,IAAI,KAAK,aAAa,IAAInD,OAAO,CAAC5B,IAAI,EAAE;MAChF,IAAI,CAAC1B,WAAW,CAACoB,GAAG,CAACkC,OAAO,CAAC5B,IAAI,CAACwB,MAAM,CAAC;MACzC,IAAI,CAACzC,IAAI,CAACiG,MAAM,CAACC,IAAI,CAAC,8BAA8B,EAAE;QAAE5F,QAAQ;QAAEmC;MAAO,CAAC,CAAC;IAC7E,CAAC,MAAM;MACL,IAAI,CAACzC,IAAI,CAACiG,MAAM,CAACJ,KAAK,CAAC,8BAA8B,EAAE;QAAEvF,QAAQ;QAAEmC,MAAM;QAAEuD,IAAI,EAAEH,KAAK,YAAYE,mBAAW,GAAGF,KAAK,CAACG,IAAI,GAAG;MAAK,CAAC,CAAC;IACtI;EACF;EAEQzD,SAASA,CAAA,EAAS;IACxB4D,aAAa,CAAC,IAAI,CAAChC,KAAK,CAAC;IACzB,IAAI,CAACA,KAAK,GAAGoB,SAAS;EACxB;AACF;AAACa,OAAA,CAAArH,cAAA,GAAAA,cAAA","ignoreList":[]}
|
|
@@ -8,8 +8,15 @@ var _exportNames = {
|
|
|
8
8
|
blePlxCentral: true,
|
|
9
9
|
osBluetoothPermissions: true,
|
|
10
10
|
reactNativeLifecycle: true,
|
|
11
|
-
createBluetooth: true
|
|
11
|
+
createBluetooth: true,
|
|
12
|
+
HOLD: true
|
|
12
13
|
};
|
|
14
|
+
Object.defineProperty(exports, "HOLD", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _chosenPatient.HOLD;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
13
20
|
Object.defineProperty(exports, "androidForegroundService", {
|
|
14
21
|
enumerable: true,
|
|
15
22
|
get: function () {
|
|
@@ -57,4 +64,5 @@ var _blePlxCentral = require("./adapters/ble-plx-central.js");
|
|
|
57
64
|
var _osPermissions = require("./adapters/os-permissions.js");
|
|
58
65
|
var _reactNativeLifecycle = require("./adapters/react-native-lifecycle.js");
|
|
59
66
|
var _createBluetooth = require("./create-bluetooth.js");
|
|
67
|
+
var _chosenPatient = require("./adapters/chosen-patient.js");
|
|
60
68
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_shared","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_androidForegroundService","_blePlxCentral","_osPermissions","_reactNativeLifecycle","_createBluetooth"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_shared","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_androidForegroundService","_blePlxCentral","_osPermissions","_reactNativeLifecycle","_createBluetooth","_chosenPatient"],"sourceRoot":"../../../../../src","sources":["modules/next/bluetooth/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,yBAAA,GAAAb,OAAA;AAEA,IAAAc,cAAA,GAAAd,OAAA;AACA,IAAAe,cAAA,GAAAf,OAAA;AACA,IAAAgB,qBAAA,GAAAhB,OAAA;AACA,IAAAiB,gBAAA,GAAAjB,OAAA;AACA,IAAAkB,cAAA,GAAAlB,OAAA","ignoreList":[]}
|
|
@@ -5,8 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
webBluetoothCentral: true,
|
|
8
|
-
createWebBluetooth: true
|
|
8
|
+
createWebBluetooth: true,
|
|
9
|
+
HOLD: true
|
|
9
10
|
};
|
|
11
|
+
Object.defineProperty(exports, "HOLD", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return _chosenPatient.HOLD;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
10
17
|
Object.defineProperty(exports, "createWebBluetooth", {
|
|
11
18
|
enumerable: true,
|
|
12
19
|
get: function () {
|
|
@@ -33,4 +40,5 @@ Object.keys(_shared).forEach(function (key) {
|
|
|
33
40
|
});
|
|
34
41
|
var _webBluetoothCentral = require("../adapters/web-bluetooth-central.js");
|
|
35
42
|
var _createWebBluetooth = require("./create-web-bluetooth.js");
|
|
43
|
+
var _chosenPatient = require("../adapters/chosen-patient.js");
|
|
36
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_shared","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_webBluetoothCentral","_createWebBluetooth"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/web/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_shared","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_webBluetoothCentral","_createWebBluetooth","_chosenPatient"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/web/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,oBAAA,GAAAb,OAAA;AAEA,IAAAc,mBAAA,GAAAd,OAAA;AACA,IAAAe,cAAA,GAAAf,OAAA","ignoreList":[]}
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { DeviceError } from "../core/errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* What `savesFor` returns to keep a reading on the device, unsent, until `ovok.outbox.assign` names who was measured:
|
|
6
|
+
* for a shared monitor set to ask each time.
|
|
7
|
+
*/
|
|
8
|
+
const HOLD = Symbol("ovok.hold");
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Names the patient a reading is saved for, when the person measuring isn't the patient (a clinician): read at every
|
|
7
|
-
* save, so it follows whoever is chosen now. `
|
|
12
|
+
* save, so it follows whoever is chosen now. `HOLD` keeps the reading until a patient is assigned, and `undefined`
|
|
13
|
+
* means nobody is chosen, so the reading is not saved.
|
|
8
14
|
*/
|
|
9
15
|
|
|
10
|
-
/** The patient `savesFor` names, or `undefined` for the signed-in patient or guest; throws when nobody is chosen. */
|
|
11
|
-
const chosenPatientOf = savesFor => {
|
|
16
|
+
/** The patient `savesFor` names, `HOLD`, or `undefined` for the signed-in patient or guest; throws when nobody is chosen. */
|
|
17
|
+
const chosenPatientOf = (savesFor, reading, device) => {
|
|
12
18
|
if (!savesFor) {
|
|
13
19
|
return undefined;
|
|
14
20
|
}
|
|
15
|
-
const patientId = savesFor();
|
|
21
|
+
const patientId = savesFor(reading, device);
|
|
16
22
|
if (!patientId) {
|
|
17
23
|
throw new DeviceError("save-failed", "Choose the patient being measured before saving a reading");
|
|
18
24
|
}
|
|
19
25
|
return patientId;
|
|
20
26
|
};
|
|
21
|
-
export { chosenPatientOf };
|
|
27
|
+
export { chosenPatientOf, HOLD };
|
|
22
28
|
//# sourceMappingURL=chosen-patient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DeviceError","chosenPatientOf","savesFor","undefined","patientId"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/chosen-patient.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["DeviceError","HOLD","Symbol","chosenPatientOf","savesFor","reading","device","undefined","patientId"],"sourceRoot":"../../../../../../src","sources":["modules/next/bluetooth/adapters/chosen-patient.ts"],"mappings":";;AACA,SAASA,WAAW,QAAQ,mBAAgB;AAG5C;AACA;AACA;AACA;AACA,MAAMC,IAAI,GAAGC,MAAM,CAAC,WAAW,CAAC;;AAEhC;AACA;AACA;AACA;AACA;;AAGA;AACA,MAAMC,eAAe,GAAGA,CAACC,QAA8B,EAAEC,OAAgB,EAAEC,MAAsB,KAAuC;EACtI,IAAI,CAACF,QAAQ,EAAE;IACb,OAAOG,SAAS;EAClB;EAEA,MAAMC,SAAS,GAAGJ,QAAQ,CAACC,OAAO,EAAEC,MAAM,CAAC;EAE3C,IAAI,CAACE,SAAS,EAAE;IACd,MAAM,IAAIR,WAAW,CAAC,aAAa,EAAE,2DAA2D,CAAC;EACnG;EAEA,OAAOQ,SAAS;AAClB,CAAC;AAED,SAASL,eAAe,EAAEF,IAAI","ignoreList":[]}
|
|
@@ -1,121 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { MeasurementTypeKey } from "@ovok/core/next";
|
|
4
3
|
import { DeviceError } from "../core/errors.js";
|
|
5
|
-
import { chosenPatientOf } from "./chosen-patient.js";
|
|
6
|
-
import { ecgMeasurements } from "./ecg-measurements.js";
|
|
4
|
+
import { chosenPatientOf, HOLD } from "./chosen-patient.js";
|
|
7
5
|
import { replaceLiveRecordings } from "./live-supersession.js";
|
|
6
|
+
import { MEASUREMENTS } from "./reading-measurements.js";
|
|
8
7
|
import { sourceIdsOf } from "./reading-source-id.js";
|
|
9
|
-
import {
|
|
10
|
-
import { isSeriesReading, saveSeries } from "./series-saving.js";
|
|
11
|
-
import { urineAnalysis } from "./urine-measurements.js";
|
|
12
|
-
const flagSet = (reading, code) => reading.deviceFlags.some(flag => flag.code === code && flag.raw !== 0) ? true : undefined;
|
|
13
|
-
const bloodPressure = reading => ({
|
|
14
|
-
measurementTypeKey: MeasurementTypeKey.bloodPressure,
|
|
15
|
-
systolic: ovokValueOf(reading, "systolic"),
|
|
16
|
-
diastolic: ovokValueOf(reading, "diastolic"),
|
|
17
|
-
meanArterialPressure: ovokValueOf(reading, "mean_arterial_pressure"),
|
|
18
|
-
heartRate: valueOf(reading, "pulse_rate"),
|
|
19
|
-
irregularHeartbeat: flagSet(reading, "irregular_pulse"),
|
|
20
|
-
recordedAt: reading.takenAt ?? undefined
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
/** A reading without its main value, or with it in an unconvertible unit, cannot be saved. */
|
|
24
|
-
const bloodGlucose = reading => {
|
|
25
|
-
const bloodGlucoseValue = ovokValueOf(reading, "blood_glucose");
|
|
26
|
-
return bloodGlucoseValue === undefined ? undefined : {
|
|
27
|
-
measurementTypeKey: MeasurementTypeKey.bloodGlucose,
|
|
28
|
-
bloodGlucose: bloodGlucoseValue,
|
|
29
|
-
recordedAt: reading.takenAt ?? undefined
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
const bodyWeight = reading => {
|
|
33
|
-
const weight = ovokValueOf(reading, "body_weight");
|
|
34
|
-
return weight === undefined ? undefined : {
|
|
35
|
-
measurementTypeKey: MeasurementTypeKey.bodyWeight,
|
|
36
|
-
bodyWeight: weight,
|
|
37
|
-
recordedAt: reading.takenAt ?? undefined
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const bodyTemperature = reading => {
|
|
41
|
-
const temperature = ovokValueOf(reading, "body_temperature");
|
|
42
|
-
return temperature === undefined ? undefined : {
|
|
43
|
-
measurementTypeKey: MeasurementTypeKey.temperature,
|
|
44
|
-
bodyTemp: temperature,
|
|
45
|
-
recordedAt: reading.takenAt ?? undefined
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
const pulseOximetry = reading => ({
|
|
49
|
-
measurementTypeKey: MeasurementTypeKey.bloodOxygenPulseRate,
|
|
50
|
-
bloodOxygen: valueOf(reading, "spo2"),
|
|
51
|
-
pulseRate: valueOf(reading, "pulse_rate"),
|
|
52
|
-
perfusionIndex: valueOf(reading, "perfusion_index"),
|
|
53
|
-
recordedAt: reading.takenAt ?? undefined
|
|
54
|
-
});
|
|
55
|
-
const heartRate = reading => ({
|
|
56
|
-
measurementTypeKey: MeasurementTypeKey.heartRate,
|
|
57
|
-
heartRate: valueOf(reading, "heart_rate"),
|
|
58
|
-
recordedAt: reading.takenAt ?? undefined
|
|
59
|
-
});
|
|
60
|
-
const respiratoryRate = reading => ({
|
|
61
|
-
measurementTypeKey: MeasurementTypeKey.respiratoryRate,
|
|
62
|
-
respiratoryRate: valueOf(reading, "respiration_rate"),
|
|
63
|
-
recordedAt: reading.takenAt ?? undefined
|
|
64
|
-
});
|
|
65
|
-
const LIPID_METRICS = ["blood_cholesterol", "hdl_cholesterol", "ldl_cholesterol", "triglycerides"];
|
|
66
|
-
const LIPID_UNITS = ["mg/dL", "mmol/L"];
|
|
67
|
-
const isLipidUnit = unit => LIPID_UNITS.some(lipidUnit => lipidUnit === unit);
|
|
68
|
-
|
|
69
|
-
/** Ovok keeps a panel in one unit, so a reading whose values use two units, or a unit it has no codes for, cannot be saved. */
|
|
70
|
-
const lipidPanel = reading => {
|
|
71
|
-
const units = new Set(LIPID_METRICS.flatMap(metric => reading.values[metric]?.unit ?? []));
|
|
72
|
-
const [unit] = units;
|
|
73
|
-
return units.size === 1 && isLipidUnit(unit) ? {
|
|
74
|
-
measurementTypeKey: MeasurementTypeKey.lipidPanel,
|
|
75
|
-
totalCholesterol: valueOf(reading, "blood_cholesterol"),
|
|
76
|
-
hdlCholesterol: valueOf(reading, "hdl_cholesterol"),
|
|
77
|
-
ldlCholesterol: valueOf(reading, "ldl_cholesterol"),
|
|
78
|
-
triglycerides: valueOf(reading, "triglycerides"),
|
|
79
|
-
unit,
|
|
80
|
-
recordedAt: reading.takenAt ?? undefined
|
|
81
|
-
} : undefined;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/** A spirometry test without any value in Ovok's units cannot be saved. */
|
|
85
|
-
const spirometry = reading => {
|
|
86
|
-
const values = {
|
|
87
|
-
fvc: ovokValueOf(reading, "fvc"),
|
|
88
|
-
fev1: ovokValueOf(reading, "fev1"),
|
|
89
|
-
"fev1/fvc": ovokValueOf(reading, "fev1_fvc_ratio"),
|
|
90
|
-
pef: ovokValueOf(reading, "pef"),
|
|
91
|
-
fef2575: ovokValueOf(reading, "fef25_75")
|
|
92
|
-
};
|
|
93
|
-
return Object.values(values).some(value => value !== undefined) ? {
|
|
94
|
-
measurementTypeKey: MeasurementTypeKey.spirometryPanel,
|
|
95
|
-
...values,
|
|
96
|
-
recordedAt: reading.takenAt ?? undefined
|
|
97
|
-
} : undefined;
|
|
98
|
-
};
|
|
99
|
-
const single = measure => reading => {
|
|
100
|
-
const measurement = measure(reading);
|
|
101
|
-
return measurement ? [measurement] : [];
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/** How each reading type becomes Ovok measurements, one for most and one per channel for an ECG; a type missing here cannot be saved yet. */
|
|
105
|
-
const MEASUREMENTS = {
|
|
106
|
-
blood_pressure: single(bloodPressure),
|
|
107
|
-
blood_glucose: single(bloodGlucose),
|
|
108
|
-
blood_cholesterol: single(lipidPanel),
|
|
109
|
-
ecg: ecgMeasurements,
|
|
110
|
-
heart_rate: single(heartRate),
|
|
111
|
-
oxygen_saturation: single(pulseOximetry),
|
|
112
|
-
respiration_rate: single(respiratoryRate),
|
|
113
|
-
spirometry: single(spirometry),
|
|
114
|
-
temperature: single(bodyTemperature),
|
|
115
|
-
triglycerides: single(lipidPanel),
|
|
116
|
-
urine_test: single(urineAnalysis),
|
|
117
|
-
weight: single(bodyWeight)
|
|
118
|
-
};
|
|
8
|
+
import { holdSeries, isSeriesReading, saveSeries } from "./series-saving.js";
|
|
119
9
|
const deviceOf = (reading, device) => ({
|
|
120
10
|
id: reading.source.address,
|
|
121
11
|
name: device.model.id,
|
|
@@ -138,14 +28,17 @@ const unsupported = what => new DeviceError("unsupported", `Ovok cannot save ${w
|
|
|
138
28
|
/** Live numbers are saved as series and a live ECG as a recording; any other live trace has no place in Ovok yet. */
|
|
139
29
|
const isUnsavableLive = reading => reading.live !== undefined && reading.series === undefined && reading.type !== "ecg";
|
|
140
30
|
const hasValues = reading => Object.keys(reading.values).length > 0;
|
|
141
|
-
|
|
31
|
+
|
|
32
|
+
/** Stores one measurement's observations: saves them, or holds them. */
|
|
33
|
+
|
|
34
|
+
const storeMeasurements = async (store, reading, device, patientId) => {
|
|
142
35
|
const measurements = MEASUREMENTS[reading.type]?.(reading) ?? [];
|
|
143
36
|
if (measurements.length === 0) {
|
|
144
37
|
throw unsupported(`a ${reading.type} reading of this shape`);
|
|
145
38
|
}
|
|
146
39
|
const results = [];
|
|
147
40
|
for (const [index, measurement] of measurements.entries()) {
|
|
148
|
-
results.push(await
|
|
41
|
+
results.push(await store({
|
|
149
42
|
measurement,
|
|
150
43
|
...sourceIdsOf(reading, device.sn, index),
|
|
151
44
|
effectiveDateTime: reading.takenAt ?? undefined,
|
|
@@ -169,9 +62,21 @@ const receiptOf = results => {
|
|
|
169
62
|
};
|
|
170
63
|
};
|
|
171
64
|
|
|
65
|
+
/** Keeps a reading on the device for the guest, until `ovok.outbox.assign` names the patient; its live recordings stay. */
|
|
66
|
+
const holdReading = async (client, reading, device) => {
|
|
67
|
+
const results = [];
|
|
68
|
+
if (isSeriesReading(reading)) {
|
|
69
|
+
results.push(await holdSeries(client, reading, device));
|
|
70
|
+
}
|
|
71
|
+
if (!isSeriesReading(reading) || hasValues(reading)) {
|
|
72
|
+
results.push(...(await storeMeasurements(params => client.measurements.hold(params), reading, device, undefined)));
|
|
73
|
+
}
|
|
74
|
+
return results;
|
|
75
|
+
};
|
|
76
|
+
|
|
172
77
|
/**
|
|
173
78
|
* Saves readings through the Ovok measurements API, queueing them offline: for the signed-in account, or for the
|
|
174
|
-
* patient `savesFor` names
|
|
79
|
+
* patient `savesFor` names, or holds them when it returns `HOLD`. A reading with a series also saves it; a stored record then removes the live recordings it
|
|
175
80
|
* replaces, once it is saved.
|
|
176
81
|
*/
|
|
177
82
|
const ovokReadingSink = (client, savesFor) => ({
|
|
@@ -179,16 +84,19 @@ const ovokReadingSink = (client, savesFor) => ({
|
|
|
179
84
|
if (isUnsavableLive(reading)) {
|
|
180
85
|
throw unsupported(`a live ${reading.live?.metric} recording`);
|
|
181
86
|
}
|
|
182
|
-
const
|
|
87
|
+
const chosen = chosenPatientOf(savesFor, reading, device);
|
|
183
88
|
const target = deviceOf(reading, device);
|
|
89
|
+
if (chosen === HOLD) {
|
|
90
|
+
return receiptOf(await holdReading(client, reading, target));
|
|
91
|
+
}
|
|
184
92
|
const results = [];
|
|
185
93
|
if (isSeriesReading(reading)) {
|
|
186
|
-
results.push(await saveSeries(client, reading, target,
|
|
94
|
+
results.push(await saveSeries(client, reading, target, chosen));
|
|
187
95
|
}
|
|
188
96
|
if (!isSeriesReading(reading) || hasValues(reading)) {
|
|
189
|
-
results.push(...(await
|
|
97
|
+
results.push(...(await storeMeasurements(params => client.measurements.save(params), reading, target, chosen)));
|
|
190
98
|
}
|
|
191
|
-
await replaceLiveRecordings(client, reading,
|
|
99
|
+
await replaceLiveRecordings(client, reading, chosen);
|
|
192
100
|
return receiptOf(results);
|
|
193
101
|
}
|
|
194
102
|
});
|