@ovok/core 0.4.49-rc.4 → 0.4.49-rc.6
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/dist/client/observation/bundle-entry-status.d.ts +3 -0
- package/dist/client/observation/bundle-entry-status.js +13 -0
- package/dist/client/observation/fhir-systems.d.ts +7 -0
- package/dist/client/observation/fhir-systems.js +8 -1
- package/dist/client/observation/methods/generateObservationBodiesByMeasurement.js +7 -65
- package/dist/client/observation/methods/observationsToMeasurements.js +64 -11
- package/dist/client/observation/observation-bundle-utils.d.ts +5 -7
- package/dist/client/observation/observation-bundle-utils.js +55 -71
- package/dist/client/observation/observation-coding.d.ts +12 -0
- package/dist/client/observation/observation-coding.js +69 -0
- package/dist/client/observation/observation-groups.d.ts +12 -0
- package/dist/client/observation/observation-groups.js +51 -0
- package/dist/client/observation/reading-group-backfill.d.ts +13 -0
- package/dist/client/observation/reading-group-backfill.js +79 -0
- package/dist/client/observation/reading-group.d.ts +14 -0
- package/dist/client/observation/reading-group.js +85 -0
- package/dist/client/observation/series.d.ts +3 -2
- package/dist/client/observation/series.js +10 -4
- package/dist/client/observation/services/base-observation-service.d.ts +1 -1
- package/dist/client/observation/services/base-observation-service.js +6 -12
- package/dist/client/observation/services/blood-pressure.d.ts +2 -0
- package/dist/client/observation/services/blood-pressure.js +9 -5
- package/dist/client/observation/services/component-observation-services.js +2 -2
- package/dist/client/observation/services/ecg-observation-fragments.d.ts +4 -0
- package/dist/client/observation/services/ecg-observation-fragments.js +30 -37
- package/dist/client/observation/services/ecg.d.ts +3 -1
- package/dist/client/observation/services/ecg.js +19 -19
- package/dist/client/observation/services/uric-acid-service.js +2 -12
- package/dist/client/observation/services/urine-analyte-values.d.ts +4 -0
- package/dist/client/observation/services/urine-analyte-values.js +27 -0
- package/dist/client/observation/types/UrineAnalytes.d.ts +15 -0
- package/dist/client/observation/types/UrineAnalytes.js +17 -9
- package/dist/client/observation/utils/getDeviceObject.js +15 -32
- package/dist/client/offline/offline-measurement-queue.js +2 -8
- package/dist/client/ovok-client.d.ts +1 -0
- package/dist/client/ovok-client.js +11 -6
- package/dist/conformance/capability-requirements.js +1 -1
- package/dist/hooks/observation-hooks.d.ts +2 -1
- package/dist/hooks/observation-hooks.js +4 -3
- package/dist/next/index.d.ts +1 -0
- package/dist/next/resources/auth/adopted-session.d.ts +30 -0
- package/dist/next/resources/auth/adopted-session.js +46 -0
- package/dist/next/resources/auth-resource.d.ts +16 -0
- package/dist/next/resources/auth-resource.js +21 -2
- package/dist/next/resources/cms/cms-resource.d.ts +8 -1
- package/dist/next/resources/cms/cms-resource.js +19 -6
- package/dist/next/resources/measurements/measurements-resource.d.ts +11 -2
- package/dist/next/resources/measurements/measurements-resource.js +31 -6
- package/dist/next/resources/measurements/observation-builder.d.ts +1 -1
- package/dist/next/resources/measurements/observation-builder.js +16 -7
- package/dist/next/resources/measurements/save-error.js +3 -4
- package/dist/next/resources/realtime/realtime-socket.js +12 -5
- package/dist/next/resources/realtime/realtime-types.d.ts +3 -1
- package/package.json +2 -2
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EcgService = void 0;
|
|
4
4
|
const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
|
|
5
5
|
const fhir_systems_1 = require("../fhir-systems");
|
|
6
|
+
const observation_coding_1 = require("../observation-coding");
|
|
6
7
|
const base_observation_service_1 = require("./base-observation-service");
|
|
7
8
|
const ecg_observation_fragments_1 = require("./ecg-observation-fragments");
|
|
9
|
+
const measurement_time_1 = require("./measurement-time");
|
|
8
10
|
class EcgService extends base_observation_service_1.BaseObservationService {
|
|
9
11
|
constructor() {
|
|
10
12
|
super(...arguments);
|
|
@@ -35,29 +37,18 @@ class EcgService extends base_observation_service_1.BaseObservationService {
|
|
|
35
37
|
const heartRate = castedMeasurement.heartRate;
|
|
36
38
|
const diagramPoints = castedMeasurement.diagramPoints;
|
|
37
39
|
if (diagramPoints === null || diagramPoints === void 0 ? void 0 : diagramPoints.length) {
|
|
38
|
-
const duration = castedMeasurement.duration;
|
|
39
|
-
const period = typeof duration === "number" && Number.isFinite(duration) && duration > 0
|
|
40
|
-
? (duration * 1000) / diagramPoints.length
|
|
41
|
-
: 1;
|
|
42
40
|
values.push({
|
|
43
41
|
valueSampledData: {
|
|
44
|
-
origin: { value: 0, unit: "mV" },
|
|
45
|
-
period,
|
|
42
|
+
origin: { value: 0, unit: "mV", system: fhir_systems_1.UCUM_SYSTEM, code: "mV" },
|
|
43
|
+
period: (0, ecg_observation_fragments_1.ecgSamplePeriodMs)(castedMeasurement),
|
|
46
44
|
dimensions: 1,
|
|
47
|
-
data:
|
|
45
|
+
data: (0, ecg_observation_fragments_1.sampledDataOf)(diagramPoints),
|
|
48
46
|
},
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
if (typeof heartRate === "number") {
|
|
52
50
|
const fixedValue = heartRate.toFixed(this.observationMetadata[1].toFixed);
|
|
53
|
-
values.push({
|
|
54
|
-
valueQuantity: {
|
|
55
|
-
value: Number(fixedValue),
|
|
56
|
-
unit: "bpm",
|
|
57
|
-
code: MeasurementTypes_1.ObservationCode.ECG_HEART_RATE,
|
|
58
|
-
system: fhir_systems_1.LOINC_SYSTEM,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
51
|
+
values.push({ valueQuantity: (0, observation_coding_1.ucumQuantity)(Number(fixedValue), "bpm") });
|
|
61
52
|
}
|
|
62
53
|
return values;
|
|
63
54
|
}
|
|
@@ -68,9 +59,10 @@ class EcgService extends base_observation_service_1.BaseObservationService {
|
|
|
68
59
|
}
|
|
69
60
|
getAdditionalProperties(measurement) {
|
|
70
61
|
const castedMeasurement = this.getCastedMeasurement(measurement);
|
|
62
|
+
const effectiveDateTime = (0, measurement_time_1.recordedAtOrNow)(castedMeasurement).toISOString();
|
|
71
63
|
const additionalProperties = [
|
|
72
64
|
{
|
|
73
|
-
effectiveDateTime
|
|
65
|
+
effectiveDateTime,
|
|
74
66
|
interpretation: [
|
|
75
67
|
{
|
|
76
68
|
text: castedMeasurement.diagnosticResult,
|
|
@@ -96,12 +88,20 @@ class EcgService extends base_observation_service_1.BaseObservationService {
|
|
|
96
88
|
},
|
|
97
89
|
],
|
|
98
90
|
},
|
|
99
|
-
{
|
|
100
|
-
effectiveDateTime: new Date().toISOString(),
|
|
101
|
-
},
|
|
91
|
+
{ effectiveDateTime },
|
|
102
92
|
];
|
|
103
93
|
return additionalProperties;
|
|
104
94
|
}
|
|
95
|
+
/** The waveform is coded in the ISO/IEEE 11073 nomenclature, not LOINC. */
|
|
96
|
+
getObservationCodes() {
|
|
97
|
+
return super.getObservationCodes().map((concept) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return ({
|
|
100
|
+
...concept,
|
|
101
|
+
coding: (_a = concept.coding) === null || _a === void 0 ? void 0 : _a.map((coding) => coding.code === MeasurementTypes_1.ObservationCode.ECG ? { ...coding, system: fhir_systems_1.MDC_SYSTEM } : coding),
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
105
|
getMeasurementDisplay(measurement) {
|
|
106
106
|
const castedMeasurement = this.getCastedMeasurement(measurement);
|
|
107
107
|
return castedMeasurement.diagnosticResult || "Unknown";
|
|
@@ -5,6 +5,7 @@ const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
|
|
|
5
5
|
const fhir_systems_1 = require("../fhir-systems");
|
|
6
6
|
const base_observation_service_1 = require("./base-observation-service");
|
|
7
7
|
const measurement_time_1 = require("./measurement-time");
|
|
8
|
+
const urine_analyte_values_1 = require("./urine-analyte-values");
|
|
8
9
|
class UricAcidService extends base_observation_service_1.BaseObservationService {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(...arguments);
|
|
@@ -82,18 +83,7 @@ class UricAcidService extends base_observation_service_1.BaseObservationService
|
|
|
82
83
|
],
|
|
83
84
|
text: analyte.display,
|
|
84
85
|
},
|
|
85
|
-
value:
|
|
86
|
-
valueQuantity: {
|
|
87
|
-
value,
|
|
88
|
-
...(analyte.unit ? { unit: analyte.unit } : {}),
|
|
89
|
-
...(analyte.unitCode
|
|
90
|
-
? {
|
|
91
|
-
code: analyte.unitCode,
|
|
92
|
-
system: fhir_systems_1.UCUM_SYSTEM,
|
|
93
|
-
}
|
|
94
|
-
: {}),
|
|
95
|
-
},
|
|
96
|
-
},
|
|
86
|
+
value: (0, urine_analyte_values_1.analyteValue)(analyte, value),
|
|
97
87
|
additionalProperties: {
|
|
98
88
|
effectiveDateTime,
|
|
99
89
|
},
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UrineAnalyteDefinition } from "../../../types/MeasurementTypes";
|
|
2
|
+
import { ObservationValue } from "../types/generate-observation-body/ObservationValue";
|
|
3
|
+
/** A strip analyte's value: coded positive or negative for a presence test, else a quantity. */
|
|
4
|
+
export declare const analyteValue: (analyte: UrineAnalyteDefinition, value: number) => ObservationValue;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyteValue = void 0;
|
|
4
|
+
const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
|
|
5
|
+
const fhir_systems_1 = require("../fhir-systems");
|
|
6
|
+
const presenceValue = (value) => {
|
|
7
|
+
const positive = value > 0;
|
|
8
|
+
return {
|
|
9
|
+
valueCodeableConcept: {
|
|
10
|
+
coding: [{
|
|
11
|
+
system: MeasurementTypes_1.UrinePresenceCoding.system,
|
|
12
|
+
code: positive ? MeasurementTypes_1.UrinePresenceCoding.positive : MeasurementTypes_1.UrinePresenceCoding.negative,
|
|
13
|
+
display: positive ? "Positive" : "Negative",
|
|
14
|
+
}],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const analyteQuantity = (analyte, value) => ({
|
|
19
|
+
valueQuantity: {
|
|
20
|
+
value,
|
|
21
|
+
...(analyte.unit ? { unit: analyte.unit } : {}),
|
|
22
|
+
...(analyte.unitCode ? { code: analyte.unitCode, system: fhir_systems_1.UCUM_SYSTEM } : {}),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
/** A strip analyte's value: coded positive or negative for a presence test, else a quantity. */
|
|
26
|
+
const analyteValue = (analyte, value) => analyte.presence ? presenceValue(value) : analyteQuantity(analyte, value);
|
|
27
|
+
exports.analyteValue = analyteValue;
|
|
@@ -20,6 +20,21 @@ export type UrineAnalyteDefinition = {
|
|
|
20
20
|
unit?: string;
|
|
21
21
|
/** UCUM code sent in Observation.valueQuantity.code. */
|
|
22
22
|
unitCode?: string;
|
|
23
|
+
/** A presence test, saved as a positive or negative coded value instead of a quantity. */
|
|
24
|
+
presence?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* SNOMED CT results of a urine presence test such as nitrite.
|
|
28
|
+
*
|
|
29
|
+
* @category measurements
|
|
30
|
+
*/
|
|
31
|
+
export declare const UrinePresenceCoding: {
|
|
32
|
+
/** Coding system URI (SNOMED CT). */
|
|
33
|
+
readonly system: "http://snomed.info/sct";
|
|
34
|
+
/** Positive. */
|
|
35
|
+
readonly positive: "10828004";
|
|
36
|
+
/** Negative. */
|
|
37
|
+
readonly negative: "260385009";
|
|
23
38
|
};
|
|
24
39
|
/**
|
|
25
40
|
* LOINC mappings for the analytes returned by Contec's BC401 strips.
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.URINE_ANALYTE_DEFINITIONS = void 0;
|
|
3
|
+
exports.URINE_ANALYTE_DEFINITIONS = exports.UrinePresenceCoding = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* SNOMED CT results of a urine presence test such as nitrite.
|
|
6
|
+
*
|
|
7
|
+
* @category measurements
|
|
8
|
+
*/
|
|
9
|
+
exports.UrinePresenceCoding = {
|
|
10
|
+
/** Coding system URI (SNOMED CT). */
|
|
11
|
+
system: "http://snomed.info/sct",
|
|
12
|
+
/** Positive. */
|
|
13
|
+
positive: "10828004",
|
|
14
|
+
/** Negative. */
|
|
15
|
+
negative: "260385009",
|
|
16
|
+
};
|
|
4
17
|
/**
|
|
5
18
|
* LOINC mappings for the analytes returned by Contec's BC401 strips.
|
|
6
19
|
* These are exported so Native declarations and consuming apps can describe
|
|
@@ -50,13 +63,8 @@ exports.URINE_ANALYTE_DEFINITIONS = [
|
|
|
50
63
|
unit: "mg/dL",
|
|
51
64
|
unitCode: "mg/dL",
|
|
52
65
|
},
|
|
53
|
-
{ key: "ph", code: "50560-2", display: "Urine pH" },
|
|
54
|
-
{
|
|
55
|
-
key: "nit",
|
|
56
|
-
code: "50558-6",
|
|
57
|
-
display: "Nitrite",
|
|
58
|
-
unit: "qualitative",
|
|
59
|
-
},
|
|
66
|
+
{ key: "ph", code: "50560-2", display: "Urine pH", unit: "[pH]", unitCode: "[pH]" },
|
|
67
|
+
{ key: "nit", code: "50558-6", display: "Nitrite", presence: true },
|
|
60
68
|
{
|
|
61
69
|
key: "leu",
|
|
62
70
|
code: "60026-2",
|
|
@@ -64,7 +72,7 @@ exports.URINE_ANALYTE_DEFINITIONS = [
|
|
|
64
72
|
unit: "WBC/µL",
|
|
65
73
|
unitCode: "/uL",
|
|
66
74
|
},
|
|
67
|
-
{ key: "sg", code: "53326-5", display: "Specific gravity" },
|
|
75
|
+
{ key: "sg", code: "53326-5", display: "Specific gravity", unitCode: "1" },
|
|
68
76
|
{
|
|
69
77
|
key: "vc",
|
|
70
78
|
code: "5768-7",
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDeviceObject = void 0;
|
|
4
4
|
const EXTENSION_BASE_URL = "http://ovok.com/fhir/StructureDefinition";
|
|
5
5
|
const LOCAL_NAME_URL = `${EXTENSION_BASE_URL}/device-local-name`;
|
|
6
|
-
const MANUFACTURER_DATA_URL = `${EXTENSION_BASE_URL}/device-manufacturer-data`;
|
|
7
6
|
const MANUFACTURER_NAME_URL = `${EXTENSION_BASE_URL}/device-manufacturer-name`;
|
|
8
7
|
const MODEL_URL = `${EXTENSION_BASE_URL}/device-model`;
|
|
9
8
|
const SERIAL_NUMBER_URL = `${EXTENSION_BASE_URL}/device-serial-number`;
|
|
@@ -39,7 +38,7 @@ const getOptionalStringExtension = (url, value) => {
|
|
|
39
38
|
return [{ url, valueString: value }];
|
|
40
39
|
};
|
|
41
40
|
const getDeviceObject = (measurementDevice) => {
|
|
42
|
-
var _a, _b, _c, _d
|
|
41
|
+
var _a, _b, _c, _d;
|
|
43
42
|
if (!measurementDevice) {
|
|
44
43
|
return {
|
|
45
44
|
identifier: {
|
|
@@ -47,37 +46,21 @@ const getDeviceObject = (measurementDevice) => {
|
|
|
47
46
|
},
|
|
48
47
|
};
|
|
49
48
|
}
|
|
49
|
+
const display = measurementDevice.variant
|
|
50
|
+
? variantDisplay(measurementDevice.variant)
|
|
51
|
+
: measurementDevice.name;
|
|
52
|
+
const extension = [
|
|
53
|
+
...getOptionalStringExtension(LOCAL_NAME_URL, measurementDevice.localName),
|
|
54
|
+
...getOptionalStringExtension(MANUFACTURER_NAME_URL, (_b = (_a = measurementDevice.variant) === null || _a === void 0 ? void 0 : _a.manufacturer) !== null && _b !== void 0 ? _b : measurementDevice.manufacturerName),
|
|
55
|
+
...getOptionalStringExtension(MODEL_URL, (_d = (_c = measurementDevice.variant) === null || _c === void 0 ? void 0 : _c.model) !== null && _d !== void 0 ? _d : measurementDevice.model),
|
|
56
|
+
...(measurementDevice.variant ? getOptionalStringExtension(PARSER_URL, measurementDevice.name) : []),
|
|
57
|
+
...getOptionalStringExtension(SERIAL_NUMBER_URL, measurementDevice.sn),
|
|
58
|
+
...getBatteryExtension(measurementDevice.batteryPercentage),
|
|
59
|
+
];
|
|
50
60
|
return {
|
|
51
|
-
...(measurementDevice.sn
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
value: measurementDevice.sn,
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
: {}),
|
|
58
|
-
display: measurementDevice.variant
|
|
59
|
-
? variantDisplay(measurementDevice.variant)
|
|
60
|
-
: (_a = measurementDevice.name) !== null && _a !== void 0 ? _a : "no-name",
|
|
61
|
-
extension: [
|
|
62
|
-
{
|
|
63
|
-
url: LOCAL_NAME_URL,
|
|
64
|
-
valueString: measurementDevice.localName || "no-local-name",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
url: MANUFACTURER_DATA_URL,
|
|
68
|
-
valueString: measurementDevice.manufacturerData || "no-manufacturer-data",
|
|
69
|
-
},
|
|
70
|
-
...getOptionalStringExtension(MANUFACTURER_NAME_URL, (_c = (_b = measurementDevice.variant) === null || _b === void 0 ? void 0 : _b.manufacturer) !== null && _c !== void 0 ? _c : measurementDevice.manufacturerName),
|
|
71
|
-
...getOptionalStringExtension(MODEL_URL, (_e = (_d = measurementDevice.variant) === null || _d === void 0 ? void 0 : _d.model) !== null && _e !== void 0 ? _e : measurementDevice.model),
|
|
72
|
-
...(measurementDevice.variant
|
|
73
|
-
? getOptionalStringExtension(PARSER_URL, measurementDevice.name)
|
|
74
|
-
: []),
|
|
75
|
-
{
|
|
76
|
-
url: SERIAL_NUMBER_URL,
|
|
77
|
-
valueString: measurementDevice.sn || "no-serial-number",
|
|
78
|
-
},
|
|
79
|
-
...getBatteryExtension(measurementDevice.batteryPercentage),
|
|
80
|
-
],
|
|
61
|
+
...(measurementDevice.sn ? { identifier: { value: measurementDevice.sn } } : {}),
|
|
62
|
+
...(display ? { display } : {}),
|
|
63
|
+
...(extension.length > 0 ? { extension } : {}),
|
|
81
64
|
};
|
|
82
65
|
};
|
|
83
66
|
exports.getDeviceObject = getDeviceObject;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stableMeasurementId = exports.entryForObservation = exports.OFFLINE_MEASUREMENT_IDENTIFIER_SYSTEM = exports.DEFAULT_OFFLINE_MEASUREMENT_QUEUE_KEY = exports.OfflineMeasurementQueue = exports.OFFLINE_MEASUREMENT_QUEUE_STORAGE_KEY = void 0;
|
|
4
|
+
const bundle_entry_status_1 = require("../observation/bundle-entry-status");
|
|
4
5
|
const fhir_systems_1 = require("../observation/fhir-systems");
|
|
5
6
|
const request_options_1 = require("../request-options");
|
|
6
7
|
/**
|
|
@@ -125,14 +126,7 @@ const entryForObservation = (observation, { identifierSystems = [], replace = fa
|
|
|
125
126
|
};
|
|
126
127
|
};
|
|
127
128
|
exports.entryForObservation = entryForObservation;
|
|
128
|
-
const isFailedResponse = (bundle) => {
|
|
129
|
-
var _a, _b;
|
|
130
|
-
return (_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a.some((entry) => {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
const status = (_b = (_a = entry.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : "";
|
|
133
|
-
return status.startsWith("4") || status.startsWith("5");
|
|
134
|
-
})) !== null && _b !== void 0 ? _b : false;
|
|
135
|
-
};
|
|
129
|
+
const isFailedResponse = (bundle) => { var _a, _b; return (_b = (_a = bundle.entry) === null || _a === void 0 ? void 0 : _a.some(bundle_entry_status_1.isFailedEntry)) !== null && _b !== void 0 ? _b : false; };
|
|
136
130
|
/** The stored failure: name, and code/status when present; never the message or payload. */
|
|
137
131
|
const summarizeFailure = (error) => {
|
|
138
132
|
const failure = error;
|
|
@@ -159,6 +159,7 @@ export declare class OvokClient extends MedplumClient {
|
|
|
159
159
|
* account differs from `account`: the rest of a reading is never written under someone else's sign-in.
|
|
160
160
|
*/
|
|
161
161
|
private executeObservationBundle;
|
|
162
|
+
private executeSave;
|
|
162
163
|
private mapError;
|
|
163
164
|
private bindMethods;
|
|
164
165
|
/**
|
|
@@ -57,6 +57,7 @@ const inviteMethods = __importStar(require("./invites/methods"));
|
|
|
57
57
|
const notificationMethods = __importStar(require("./notifications/methods"));
|
|
58
58
|
const observationMethods = __importStar(require("./observation/methods"));
|
|
59
59
|
const observation_bundle_utils_1 = require("./observation/observation-bundle-utils");
|
|
60
|
+
const observation_groups_1 = require("./observation/observation-groups");
|
|
60
61
|
const offline_1 = require("./offline");
|
|
61
62
|
const patientMethods = __importStar(require("./patient/methods"));
|
|
62
63
|
const patientSharingMethods = __importStar(require("./patient-sharing/methods"));
|
|
@@ -384,10 +385,11 @@ class OvokClient extends core_1.MedplumClient {
|
|
|
384
385
|
.filter((group) => group.length > 0)
|
|
385
386
|
.map((group) => (0, observation_bundle_utils_1.linkObservationMembers)(group).map((observation) => (0, offline_1.entryForObservation)(observation, entryOptions)));
|
|
386
387
|
const responses = [];
|
|
387
|
-
for (const request of (0,
|
|
388
|
-
// A reading alone keeps a single save's atomicity; several
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
for (const request of (0, observation_groups_1.packObservationGroups)(entryGroups)) {
|
|
389
|
+
// A reading alone keeps a single save's atomicity; several go main observations first.
|
|
390
|
+
responses.push(request.length === 1
|
|
391
|
+
? await this.executeObservationBundle({ resourceType: "Bundle", type: "transaction", entry: request.flat() }, requestOptions, account)
|
|
392
|
+
: await this.executeSave((execute) => (0, observation_groups_1.executeReadingsBatch)(request, execute), requestOptions, account));
|
|
391
393
|
}
|
|
392
394
|
return {
|
|
393
395
|
resourceType: "Bundle",
|
|
@@ -535,9 +537,12 @@ class OvokClient extends core_1.MedplumClient {
|
|
|
535
537
|
* Sends a save's bundle, over several requests when it must. A later request isn't sent once the signed-in
|
|
536
538
|
* account differs from `account`: the rest of a reading is never written under someone else's sign-in.
|
|
537
539
|
*/
|
|
538
|
-
|
|
540
|
+
executeObservationBundle(bundle, requestOptions, account = this.accountKey()) {
|
|
541
|
+
return this.executeSave((execute) => (0, observation_bundle_utils_1.executeObservationBundle)(bundle, execute), requestOptions, account);
|
|
542
|
+
}
|
|
543
|
+
async executeSave(run, requestOptions, account = this.accountKey()) {
|
|
539
544
|
try {
|
|
540
|
-
const response = await (
|
|
545
|
+
const response = await run((request) => {
|
|
541
546
|
if (this.accountKey() !== account) {
|
|
542
547
|
throw new Error("The signed-in account changed during the save; the rest of it was not sent.");
|
|
543
548
|
}
|
|
@@ -26,7 +26,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
|
|
|
26
26
|
description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
|
|
27
27
|
software: {
|
|
28
28
|
name: "@ovok/core",
|
|
29
|
-
version: "0.4.49-rc.
|
|
29
|
+
version: "0.4.49-rc.6",
|
|
30
30
|
},
|
|
31
31
|
fhirVersion: "4.0.1",
|
|
32
32
|
format: ["json"],
|
|
@@ -48,7 +48,8 @@ export declare const useObservations: <T extends readonly SupportedType[]>({ typ
|
|
|
48
48
|
*/
|
|
49
49
|
export declare const useSaveMeasurement: () => ((params: GenerateObservationBodyParams, requestOptions?: MedplumRequestOptions) => Promise<Awaited<ReturnType<OvokClient["saveMeasurement"]>>>);
|
|
50
50
|
/**
|
|
51
|
-
* Loads an ECG Observation, plus
|
|
51
|
+
* Loads an ECG Observation, plus the Observations it points at or that point at it, and maps them to one recording;
|
|
52
|
+
* without `id`, loads all ECG Observations.
|
|
52
53
|
*
|
|
53
54
|
* @param id - Id of the ECG Observation.
|
|
54
55
|
*/
|
|
@@ -84,7 +84,8 @@ const useSaveMeasurement = () => {
|
|
|
84
84
|
};
|
|
85
85
|
exports.useSaveMeasurement = useSaveMeasurement;
|
|
86
86
|
/**
|
|
87
|
-
* Loads an ECG Observation, plus
|
|
87
|
+
* Loads an ECG Observation, plus the Observations it points at or that point at it, and maps them to one recording;
|
|
88
|
+
* without `id`, loads all ECG Observations.
|
|
88
89
|
*
|
|
89
90
|
* @param id - Id of the ECG Observation.
|
|
90
91
|
*/
|
|
@@ -98,10 +99,10 @@ const useEcgRecording = (id) => {
|
|
|
98
99
|
return client.searchResources("Observation", query, { signal });
|
|
99
100
|
}
|
|
100
101
|
const [root, members] = await Promise.all([
|
|
101
|
-
client.searchResources("Observation", { ...query, _id: id }, { signal }),
|
|
102
|
+
client.searchResources("Observation", { ...query, _id: id, _include: "Observation:has-member" }, { signal }),
|
|
102
103
|
client.searchResources("Observation", { ...query, "has-member": `Observation/${id}` }, { signal }),
|
|
103
104
|
]);
|
|
104
|
-
return [...root, ...members];
|
|
105
|
+
return [...new Map([...root, ...members].map((observation) => [observation.id, observation])).values()];
|
|
105
106
|
}, id);
|
|
106
107
|
const recording = (0, observationsToMeasurements_1.observationsToMeasurements)(observations, [types_1.MeasurementTypeKey.ecg])[0];
|
|
107
108
|
return {
|
package/dist/next/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type { SessionChangeListener } from "./auth/user-session";
|
|
|
15
15
|
export type { LoginCredentials, LoginResult, MfaChallenge, ProfileType } from "./resources/auth-resource";
|
|
16
16
|
export type { CreateOptions, PatchOperation } from "./resources/fhir-resource";
|
|
17
17
|
export type { HealthCheck } from "./resources/health-resource";
|
|
18
|
+
export type { AdoptedSession } from "./resources/auth/adopted-session";
|
|
18
19
|
export type { PatientRegistration, PractitionerRegistration, RegisterResult } from "./resources/auth/registration";
|
|
19
20
|
export type { SocialCredentials, SocialProvider } from "./resources/auth/social-login";
|
|
20
21
|
export type { LastObservationsQuery, LastnQuery, LatestObservationsParams, MeasurementCodeTypes, SaveObservationsOptions, SaveObservationsResult, } from "./resources/measurements/measurements-resource";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LoginTokens } from "../../auth/session";
|
|
2
|
+
/**
|
|
3
|
+
* A sign-in made elsewhere, such as the session an earlier client stored, for `ovok.auth.adoptSession` to continue.
|
|
4
|
+
*
|
|
5
|
+
* @category auth
|
|
6
|
+
*/
|
|
7
|
+
export type AdoptedSession = {
|
|
8
|
+
/** Bearer token for API requests. */
|
|
9
|
+
accessToken: string;
|
|
10
|
+
/** Token that renews the session; null or omitted when there is none. */
|
|
11
|
+
refreshToken?: string | null;
|
|
12
|
+
/** Seconds until `accessToken` expires. Omit it when unknown: the first request then refreshes the session. */
|
|
13
|
+
expiresIn?: number;
|
|
14
|
+
/** The signed-in profile. */
|
|
15
|
+
profile: {
|
|
16
|
+
/** FHIR reference, such as `Patient/123`. */
|
|
17
|
+
reference: string;
|
|
18
|
+
/** Display name, if known. */
|
|
19
|
+
display?: string | null;
|
|
20
|
+
};
|
|
21
|
+
/** The project the session belongs to. Omit it when unknown. */
|
|
22
|
+
project?: {
|
|
23
|
+
/** FHIR reference, such as `Project/123`. */
|
|
24
|
+
reference: string;
|
|
25
|
+
/** Display name, if known. */
|
|
26
|
+
display?: string | null;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** Checks the input at the trust boundary: it is often parsed from storage, so its types are not given. */
|
|
30
|
+
export declare function loginTokensFromAdopted(adopted: AdoptedSession): LoginTokens;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loginTokensFromAdopted = loginTokensFromAdopted;
|
|
4
|
+
const ovok_errors_1 = require("../../errors/ovok-errors");
|
|
5
|
+
const FHIR_REFERENCE = /^[A-Za-z]+\/[A-Za-z0-9\-.]{1,64}$/;
|
|
6
|
+
const DUE_AT_ONCE_SECONDS = 0;
|
|
7
|
+
const NO_PROJECT = { reference: "" };
|
|
8
|
+
/** Checks the input at the trust boundary: it is often parsed from storage, so its types are not given. */
|
|
9
|
+
function loginTokensFromAdopted(adopted) {
|
|
10
|
+
const { accessToken, refreshToken, expiresIn, profile, project } = (adopted !== null && adopted !== void 0 ? adopted : {});
|
|
11
|
+
return {
|
|
12
|
+
accessToken: requiredText("accessToken", accessToken),
|
|
13
|
+
refreshToken: optionalText("refreshToken", refreshToken),
|
|
14
|
+
expiresIn: expiresInSeconds(expiresIn),
|
|
15
|
+
profile: checkedReference("profile", profile),
|
|
16
|
+
project: project === undefined ? NO_PROJECT : checkedReference("project", project),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function reject(problem) {
|
|
20
|
+
throw new ovok_errors_1.OvokValidationError((0, ovok_errors_1.detailsFor)(`Cannot adopt the session: ${problem}.`));
|
|
21
|
+
}
|
|
22
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
23
|
+
function requiredText(field, value) {
|
|
24
|
+
return isText(value) ? value : reject(`${field} must be a non-empty string`);
|
|
25
|
+
}
|
|
26
|
+
function optionalText(field, value) {
|
|
27
|
+
return value === undefined || value === null ? null : requiredText(field, value);
|
|
28
|
+
}
|
|
29
|
+
function expiresInSeconds(value) {
|
|
30
|
+
if (value === undefined) {
|
|
31
|
+
return DUE_AT_ONCE_SECONDS;
|
|
32
|
+
}
|
|
33
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0
|
|
34
|
+
? value
|
|
35
|
+
: reject("expiresIn must be a number of seconds, zero or more");
|
|
36
|
+
}
|
|
37
|
+
function checkedReference(field, value) {
|
|
38
|
+
const { reference, display = null } = (value !== null && value !== void 0 ? value : {});
|
|
39
|
+
if (typeof reference !== "string" || !FHIR_REFERENCE.test(reference)) {
|
|
40
|
+
reject(`${field}.reference must be a FHIR reference like ResourceType/id`);
|
|
41
|
+
}
|
|
42
|
+
if (display !== null && typeof display !== "string") {
|
|
43
|
+
reject(`${field}.display must be a string or null`);
|
|
44
|
+
}
|
|
45
|
+
return { reference, display };
|
|
46
|
+
}
|
|
@@ -10,6 +10,7 @@ import { Session } from "../auth/session";
|
|
|
10
10
|
import { UserSession } from "../auth/user-session";
|
|
11
11
|
import { HttpClient } from "../http/http-client";
|
|
12
12
|
import { RequestOptions } from "../http/transmit";
|
|
13
|
+
import { AdoptedSession } from "./auth/adopted-session";
|
|
13
14
|
import { AuthSessionsResource } from "./auth/auth-sessions-resource";
|
|
14
15
|
import { PatientRegistration, PractitionerRegistration, RegisterResult } from "./auth/registration";
|
|
15
16
|
import { SocialCredentials, SocialProvider } from "./auth/social-login";
|
|
@@ -96,6 +97,21 @@ export declare class AuthResource {
|
|
|
96
97
|
registerPractitioner(details: PractitionerRegistration, options?: RequestOptions): Promise<Session>;
|
|
97
98
|
/** Signs in with an Apple or Google token. Calls `POST auth/external/{provider}`. */
|
|
98
99
|
socialLogin<P extends SocialProvider>(provider: P, credential: SocialCredentials[P], options?: RequestOptions): Promise<Session>;
|
|
100
|
+
/**
|
|
101
|
+
* Continues a sign-in made elsewhere, such as the session an earlier client stored, as if the user had just signed in.
|
|
102
|
+
* It replaces any current session, is saved and announced like a login, and refreshes like one.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const session = await ovok.auth.adoptSession({
|
|
106
|
+
* accessToken,
|
|
107
|
+
* refreshToken,
|
|
108
|
+
* profile: { reference: "Patient/123" },
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* @throws OvokValidationError when the access token or profile reference is missing or malformed, or another field is invalid.
|
|
112
|
+
* @throws OvokConfigError when the client was created with `clientSecret`.
|
|
113
|
+
*/
|
|
114
|
+
adoptSession(adopted: AdoptedSession): Promise<Session>;
|
|
99
115
|
/** Returns the current session, or null when signed out. */
|
|
100
116
|
current(): Promise<Session | null>;
|
|
101
117
|
/** Fetches the signed-in user's profile. Calls `GET auth/me`. */
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AuthResource = exports.ME_PATH = void 0;
|
|
4
4
|
const generate_code_challenge_and_verifier_1 = require("../../client/auth/generate-code-challenge-and-verifier");
|
|
5
5
|
const ovok_errors_1 = require("../errors/ovok-errors");
|
|
6
|
+
const adopted_session_1 = require("./auth/adopted-session");
|
|
6
7
|
const auth_sessions_resource_1 = require("./auth/auth-sessions-resource");
|
|
7
8
|
const registration_1 = require("./auth/registration");
|
|
8
9
|
const social_login_1 = require("./auth/social-login");
|
|
@@ -39,7 +40,7 @@ class AuthResource {
|
|
|
39
40
|
const { profileType, email, password } = credentials;
|
|
40
41
|
const step = await this.http
|
|
41
42
|
.anonymous()
|
|
42
|
-
.post(loginPath(profileType, "start"), { email, password, codeChallenge }, options);
|
|
43
|
+
.post(loginPath(profileType, "start"), { email, password, codeChallenge, tenantCode: this.tenantCode }, options);
|
|
43
44
|
if (step.nextStep === "mfa") {
|
|
44
45
|
return { status: "mfa-required", challenge: { profileType, loginId: step.loginId, codeVerifier } };
|
|
45
46
|
}
|
|
@@ -51,7 +52,7 @@ class AuthResource {
|
|
|
51
52
|
const { profileType, loginId, codeVerifier } = challenge;
|
|
52
53
|
const step = await this.http
|
|
53
54
|
.anonymous()
|
|
54
|
-
.post(loginPath(profileType, "mfa"), { loginId, mfaToken: code }, options);
|
|
55
|
+
.post(loginPath(profileType, "mfa"), { loginId, mfaToken: code, tenantCode: this.tenantCode }, options);
|
|
55
56
|
return this.exchange(session, { profileType, sessionCode: step.sessionCode, codeVerifier }, options);
|
|
56
57
|
}
|
|
57
58
|
/** A project that routes the email to a clinician invitation signs no one in. */
|
|
@@ -81,6 +82,24 @@ class AuthResource {
|
|
|
81
82
|
const path = (0, social_login_1.socialLoginPath)(provider, this.socialLoginClientId(), internalId);
|
|
82
83
|
return session.begin(await this.http.anonymous().post(path, providerResult, options));
|
|
83
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Continues a sign-in made elsewhere, such as the session an earlier client stored, as if the user had just signed in.
|
|
87
|
+
* It replaces any current session, is saved and announced like a login, and refreshes like one.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* const session = await ovok.auth.adoptSession({
|
|
91
|
+
* accessToken,
|
|
92
|
+
* refreshToken,
|
|
93
|
+
* profile: { reference: "Patient/123" },
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* @throws OvokValidationError when the access token or profile reference is missing or malformed, or another field is invalid.
|
|
97
|
+
* @throws OvokConfigError when the client was created with `clientSecret`.
|
|
98
|
+
*/
|
|
99
|
+
async adoptSession(adopted) {
|
|
100
|
+
const session = this.userSession();
|
|
101
|
+
return session.begin((0, adopted_session_1.loginTokensFromAdopted)(adopted));
|
|
102
|
+
}
|
|
84
103
|
/** Returns the current session, or null when signed out. */
|
|
85
104
|
async current() {
|
|
86
105
|
return this.session === null ? null : this.session.current();
|
|
@@ -4,6 +4,8 @@ import { RequestOptions } from "../../http/transmit";
|
|
|
4
4
|
import { CmsReadParams } from "./cms-delivery";
|
|
5
5
|
import { CmsDocumentsResource } from "./cms-documents-resource";
|
|
6
6
|
import { ReleaseNotesResource } from "./release-notes-resource";
|
|
7
|
+
/** 25,000 documents: far beyond any real collection, so reaching it means the CMS never ends its pages. */
|
|
8
|
+
export declare const MAX_TRANSLATION_PAGES = 500;
|
|
7
9
|
/**
|
|
8
10
|
* Published CMS content: documents, legal pages, release notes and translations. Calls routes under `v1/public/cms`.
|
|
9
11
|
*
|
|
@@ -18,7 +20,12 @@ export declare class CmsResource {
|
|
|
18
20
|
constructor(http: HttpClient, tenantCode: string);
|
|
19
21
|
/** "terms-and-conditions", "data-privacy", …: readable before sign-in. */
|
|
20
22
|
legalPage(slug: string, params?: CmsReadParams, options?: RequestOptions): Promise<OvokCmsDocument>;
|
|
21
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* The `translations` collection as one tree, readable before sign-in; nothing is kept on the device.
|
|
25
|
+
* Reads every page of the collection.
|
|
26
|
+
*
|
|
27
|
+
* @throws OvokError with code `cms_translations_page_limit` when the CMS is still offering pages after 500, rather than return a partial tree.
|
|
28
|
+
*/
|
|
22
29
|
translations(locale?: string, options?: RequestOptions): Promise<OvokTranslations>;
|
|
23
30
|
private translationDocuments;
|
|
24
31
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CmsResource = void 0;
|
|
3
|
+
exports.CmsResource = exports.MAX_TRANSLATION_PAGES = void 0;
|
|
4
|
+
const ovok_errors_1 = require("../../errors/ovok-errors");
|
|
4
5
|
const cms_delivery_1 = require("./cms-delivery");
|
|
5
6
|
const cms_documents_resource_1 = require("./cms-documents-resource");
|
|
6
7
|
const release_notes_resource_1 = require("./release-notes-resource");
|
|
@@ -9,7 +10,9 @@ const LEGAL_PAGES = "legal-pages";
|
|
|
9
10
|
const TRANSLATIONS = "translations";
|
|
10
11
|
const FIRST_PAGE = 1;
|
|
11
12
|
const LARGEST_PAGE_SIZE = 50;
|
|
12
|
-
|
|
13
|
+
/** 25,000 documents: far beyond any real collection, so reaching it means the CMS never ends its pages. */
|
|
14
|
+
exports.MAX_TRANSLATION_PAGES = 500;
|
|
15
|
+
const TRANSLATION_PAGE_LIMIT_CODE = "cms_translations_page_limit";
|
|
13
16
|
/**
|
|
14
17
|
* Published CMS content: documents, legal pages, release notes and translations. Calls routes under `v1/public/cms`.
|
|
15
18
|
*
|
|
@@ -25,19 +28,29 @@ class CmsResource {
|
|
|
25
28
|
legalPage(slug, params = {}, options) {
|
|
26
29
|
return this.documents.retrieve(LEGAL_PAGES, slug, params, options);
|
|
27
30
|
}
|
|
28
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* The `translations` collection as one tree, readable before sign-in; nothing is kept on the device.
|
|
33
|
+
* Reads every page of the collection.
|
|
34
|
+
*
|
|
35
|
+
* @throws OvokError with code `cms_translations_page_limit` when the CMS is still offering pages after 500, rather than return a partial tree.
|
|
36
|
+
*/
|
|
29
37
|
async translations(locale, options) {
|
|
30
38
|
return (0, translation_tree_1.translationTree)(await this.translationDocuments(locale, options));
|
|
31
39
|
}
|
|
32
40
|
async translationDocuments(locale, options) {
|
|
33
41
|
const documents = [];
|
|
34
|
-
for (let page = FIRST_PAGE
|
|
42
|
+
for (let page = FIRST_PAGE; page <= exports.MAX_TRANSLATION_PAGES; page++) {
|
|
35
43
|
const params = { locale, page, limit: LARGEST_PAGE_SIZE };
|
|
36
44
|
const result = await this.delivery.listPage(TRANSLATIONS, params, options);
|
|
37
45
|
documents.push(...result.docs);
|
|
38
|
-
|
|
46
|
+
if (!result.hasNextPage) {
|
|
47
|
+
return documents;
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
|
-
|
|
50
|
+
throw new ovok_errors_1.OvokError({
|
|
51
|
+
...(0, ovok_errors_1.detailsFor)(`The CMS still had translation pages after ${exports.MAX_TRANSLATION_PAGES}; none were returned.`),
|
|
52
|
+
code: TRANSLATION_PAGE_LIMIT_CODE,
|
|
53
|
+
});
|
|
41
54
|
}
|
|
42
55
|
}
|
|
43
56
|
exports.CmsResource = CmsResource;
|