@ovok/core 0.4.49-dev.520 → 0.4.49-dev.522
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/fhir-systems.d.ts +2 -0
- package/dist/client/observation/fhir-systems.js +3 -1
- package/dist/client/observation/methods/observationsToMeasurements.js +31 -4
- package/dist/client/observation/observation-bundle-utils.d.ts +3 -2
- package/dist/client/observation/observation-bundle-utils.js +49 -37
- package/dist/client/observation/reading-group.d.ts +14 -0
- package/dist/client/observation/reading-group.js +86 -0
- package/dist/client/observation/series.d.ts +2 -1
- package/dist/client/observation/series.js +6 -2
- package/dist/client/observation/services/component-observation-services.js +2 -2
- package/dist/client/observation/services/urine-analyte-values.js +12 -8
- 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/resources/measurements/observation-builder.d.ts +1 -1
- package/dist/next/resources/measurements/observation-builder.js +6 -3
- package/package.json +1 -1
|
@@ -3,6 +3,8 @@ export declare const UCUM_SYSTEM = "http://unitsofmeasure.org";
|
|
|
3
3
|
export declare const SNOMED_SYSTEM = "http://snomed.info/sct";
|
|
4
4
|
/** ISO/IEEE 11073-10101 nomenclature, which codes waveforms such as MDC_ECG_ELEC_POTL. */
|
|
5
5
|
export declare const MDC_SYSTEM = "urn:oid:2.16.840.1.113883.6.24";
|
|
6
|
+
/** Ovok's own codes for a measurement type, used where no standard code fits. */
|
|
7
|
+
export declare const MEASUREMENT_TYPE_SYSTEM = "https://sdk.ovok.com/fhir/CodeSystem/measurement-type";
|
|
6
8
|
export declare const OBSERVATION_CATEGORY_SYSTEM = "http://terminology.hl7.org/CodeSystem/observation-category";
|
|
7
9
|
/** Identifier system of the device-side reading id that makes a save idempotent. */
|
|
8
10
|
export declare const DEVICE_READING_IDENTIFIER_SYSTEM = "https://api.ovok.com/fhir/StructureDefinition/device-reading-id";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OVOK_EXTENSION_BASE_URL = exports.DEVICE_READING_IDENTIFIER_SYSTEM = exports.OBSERVATION_CATEGORY_SYSTEM = exports.MDC_SYSTEM = exports.SNOMED_SYSTEM = exports.UCUM_SYSTEM = exports.LOINC_SYSTEM = void 0;
|
|
3
|
+
exports.OVOK_EXTENSION_BASE_URL = exports.DEVICE_READING_IDENTIFIER_SYSTEM = exports.OBSERVATION_CATEGORY_SYSTEM = exports.MEASUREMENT_TYPE_SYSTEM = exports.MDC_SYSTEM = exports.SNOMED_SYSTEM = exports.UCUM_SYSTEM = exports.LOINC_SYSTEM = void 0;
|
|
4
4
|
exports.LOINC_SYSTEM = "http://loinc.org";
|
|
5
5
|
exports.UCUM_SYSTEM = "http://unitsofmeasure.org";
|
|
6
6
|
exports.SNOMED_SYSTEM = "http://snomed.info/sct";
|
|
7
7
|
/** ISO/IEEE 11073-10101 nomenclature, which codes waveforms such as MDC_ECG_ELEC_POTL. */
|
|
8
8
|
exports.MDC_SYSTEM = "urn:oid:2.16.840.1.113883.6.24";
|
|
9
|
+
/** Ovok's own codes for a measurement type, used where no standard code fits. */
|
|
10
|
+
exports.MEASUREMENT_TYPE_SYSTEM = "https://sdk.ovok.com/fhir/CodeSystem/measurement-type";
|
|
9
11
|
exports.OBSERVATION_CATEGORY_SYSTEM = "http://terminology.hl7.org/CodeSystem/observation-category";
|
|
10
12
|
/** Identifier system of the device-side reading id that makes a save idempotent. */
|
|
11
13
|
exports.DEVICE_READING_IDENTIFIER_SYSTEM = "https://api.ovok.com/fhir/StructureDefinition/device-reading-id";
|
|
@@ -5,6 +5,7 @@ exports.observationsToMeasurements = exports.observationCodesForTypes = void 0;
|
|
|
5
5
|
const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
|
|
6
6
|
const fhir_systems_1 = require("../fhir-systems");
|
|
7
7
|
const observation_coding_1 = require("../observation-coding");
|
|
8
|
+
const reading_group_1 = require("../reading-group");
|
|
8
9
|
const blood_pressure_1 = require("../services/blood-pressure");
|
|
9
10
|
const single_value_services_1 = require("../services/single-value-services");
|
|
10
11
|
const DEFAULT_OBSERVATION_TIME_TOLERANCE_MS = 1000;
|
|
@@ -225,9 +226,17 @@ const groupObservations = (observations, options, legacyKey) => {
|
|
|
225
226
|
}
|
|
226
227
|
return [...groups.values()].sort((left, right) => left.firstIndex - right.firstIndex);
|
|
227
228
|
};
|
|
229
|
+
/** A value by its code: from the observation that holds it, else from a group that repeats it as a component. */
|
|
228
230
|
const firstValue = (observations, code) => {
|
|
229
231
|
const match = observations.find((observation) => codeOf(observation) === code);
|
|
230
|
-
return match ? valueOf(match) :
|
|
232
|
+
return match ? valueOf(match) : groupComponentValue(observations, code);
|
|
233
|
+
};
|
|
234
|
+
const groupComponentValue = (observations, code) => {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
return (_b = (_a = observations
|
|
237
|
+
.filter(reading_group_1.isReadingGroup)
|
|
238
|
+
.flatMap((group) => { var _a; return (_a = group.component) !== null && _a !== void 0 ? _a : []; })
|
|
239
|
+
.find((component) => { var _a, _b; return (_b = (_a = component.code) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b.some((coding) => coding.code === code); })) === null || _a === void 0 ? void 0 : _a.valueQuantity) === null || _b === void 0 ? void 0 : _b.value;
|
|
231
240
|
};
|
|
232
241
|
const LIPID_FIELDS = [
|
|
233
242
|
{ key: "totalCholesterol", codes: [MeasurementTypes_1.ObservationCode.TOTAL_CHOLESTEROL_MASS, MeasurementTypes_1.ObservationCode.TOTAL_CHOLESTEROL_MOLAR] },
|
|
@@ -404,17 +413,35 @@ const inverseGroup = (type, observations) => {
|
|
|
404
413
|
const COMPONENT_TYPES = new Set([MeasurementTypes_1.MeasurementTypeKey.respiratoryTherapy, MeasurementTypes_1.MeasurementTypeKey.babySleep]);
|
|
405
414
|
const codesForType = {
|
|
406
415
|
...Object.fromEntries([...single_value_services_1.singleValueFields].map(([type, { code }]) => [type, [code]])),
|
|
407
|
-
[MeasurementTypes_1.MeasurementTypeKey.bloodPressure]: [
|
|
408
|
-
|
|
416
|
+
[MeasurementTypes_1.MeasurementTypeKey.bloodPressure]: [
|
|
417
|
+
MeasurementTypes_1.ObservationCode.SYSTOLIC_BLOOD_PRESSURE,
|
|
418
|
+
MeasurementTypes_1.ObservationCode.DIASTOLIC_BLOOD_PRESSURE,
|
|
419
|
+
MeasurementTypes_1.ObservationCode.MEAN_BLOOD_PRESSURE,
|
|
420
|
+
MeasurementTypes_1.ObservationCode.BLOOD_PRESSURE_HEART_RATE,
|
|
421
|
+
MeasurementTypes_1.PulseRhythmCoding.observation,
|
|
422
|
+
(0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.bloodPressure),
|
|
423
|
+
],
|
|
424
|
+
[MeasurementTypes_1.MeasurementTypeKey.bloodOxygenPulseRate]: [
|
|
425
|
+
MeasurementTypes_1.ObservationCode.OXYGEN_SATURATION,
|
|
426
|
+
MeasurementTypes_1.ObservationCode.OXYGEN_SATURATION_HEART_RATE,
|
|
427
|
+
(0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.bloodOxygenPulseRate),
|
|
428
|
+
],
|
|
409
429
|
[MeasurementTypes_1.MeasurementTypeKey.stepCount]: [MeasurementTypes_1.ObservationCode.STEPS],
|
|
410
|
-
[MeasurementTypes_1.MeasurementTypeKey.ecg]: [
|
|
430
|
+
[MeasurementTypes_1.MeasurementTypeKey.ecg]: [
|
|
431
|
+
MeasurementTypes_1.ObservationCode.ECG,
|
|
432
|
+
MeasurementTypes_1.ObservationCode.ECG_HEART_RATE,
|
|
433
|
+
MeasurementTypes_1.ObservationCode.HEART_RATE,
|
|
434
|
+
(0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.ecg),
|
|
435
|
+
],
|
|
411
436
|
[MeasurementTypes_1.MeasurementTypeKey.uricAcid]: [
|
|
412
437
|
MeasurementTypes_1.ObservationCode.URIC_ACID,
|
|
413
438
|
...MeasurementTypes_1.URINE_ANALYTE_DEFINITIONS.map((analyte) => analyte.code),
|
|
439
|
+
(0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.uricAcid),
|
|
414
440
|
],
|
|
415
441
|
[MeasurementTypes_1.MeasurementTypeKey.urineAnalysis]: [
|
|
416
442
|
MeasurementTypes_1.ObservationCode.URIC_ACID,
|
|
417
443
|
...MeasurementTypes_1.URINE_ANALYTE_DEFINITIONS.map((analyte) => analyte.code),
|
|
444
|
+
(0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.urineAnalysis),
|
|
418
445
|
],
|
|
419
446
|
[MeasurementTypes_1.MeasurementTypeKey.lipidPanel]: [
|
|
420
447
|
MeasurementTypes_1.ObservationCode.LIPID_PANEL,
|
|
@@ -8,8 +8,9 @@ export declare const MAX_OBSERVATION_BUNDLE_BYTES = 900000;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const MAX_CONDITIONAL_OBSERVATION_ENTRIES = 8;
|
|
10
10
|
/**
|
|
11
|
-
* Points every observation after the first at the first, as the first `hasMember` (where readers look)
|
|
12
|
-
* own `id`, as ECG segments carry, is
|
|
11
|
+
* Points every observation after the first at the first, as the first `hasMember` (where readers look), and the
|
|
12
|
+
* reading's group, which comes last, at every other observation. A link to its own `id`, as ECG segments carry, is
|
|
13
|
+
* dropped: the server replaces that id on create.
|
|
13
14
|
*/
|
|
14
15
|
export declare const linkObservationMembers: (observations: Observation[]) => Observation[];
|
|
15
16
|
export declare const createdObservationReference: (response: Bundle, index: number) => string | undefined;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.executeObservationBundle = exports.splitObservationBundleEntries = exports.rewriteObservationReferences = exports.createdObservationReference = exports.linkObservationMembers = exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES = exports.MAX_OBSERVATION_BUNDLE_BYTES = void 0;
|
|
4
4
|
const offline_1 = require("../offline");
|
|
5
5
|
const bundle_entry_status_1 = require("./bundle-entry-status");
|
|
6
|
+
const reading_group_1 = require("./reading-group");
|
|
6
7
|
/**
|
|
7
8
|
* Maximum serialized size, in bytes, of one observation bundle request.
|
|
8
9
|
*/
|
|
@@ -12,10 +13,18 @@ exports.MAX_OBSERVATION_BUNDLE_BYTES = 900000;
|
|
|
12
13
|
*/
|
|
13
14
|
exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES = 8;
|
|
14
15
|
/**
|
|
15
|
-
* Points every observation after the first at the first, as the first `hasMember` (where readers look)
|
|
16
|
-
* own `id`, as ECG segments carry, is
|
|
16
|
+
* Points every observation after the first at the first, as the first `hasMember` (where readers look), and the
|
|
17
|
+
* reading's group, which comes last, at every other observation. A link to its own `id`, as ECG segments carry, is
|
|
18
|
+
* dropped: the server replaces that id on create.
|
|
17
19
|
*/
|
|
18
20
|
const linkObservationMembers = (observations) => {
|
|
21
|
+
const parts = linkedToFirst(observations.filter((observation) => !(0, reading_group_1.isReadingGroup)(observation)));
|
|
22
|
+
const groups = observations.filter(reading_group_1.isReadingGroup);
|
|
23
|
+
const partReferences = parts.map((part) => ({ reference: `urn:uuid:${(0, offline_1.stableMeasurementId)(part)}` }));
|
|
24
|
+
return [...parts, ...groups.map((group) => ({ ...group, hasMember: partReferences }))];
|
|
25
|
+
};
|
|
26
|
+
exports.linkObservationMembers = linkObservationMembers;
|
|
27
|
+
const linkedToFirst = (observations) => {
|
|
19
28
|
const main = observations[0];
|
|
20
29
|
if (!main) {
|
|
21
30
|
return observations;
|
|
@@ -35,7 +44,6 @@ const linkObservationMembers = (observations) => {
|
|
|
35
44
|
};
|
|
36
45
|
});
|
|
37
46
|
};
|
|
38
|
-
exports.linkObservationMembers = linkObservationMembers;
|
|
39
47
|
const createdObservationReference = (response, index) => {
|
|
40
48
|
var _a, _b, _c, _d;
|
|
41
49
|
const entry = (_a = response.entry) === null || _a === void 0 ? void 0 : _a[index];
|
|
@@ -50,21 +58,29 @@ const createdObservationReference = (response, index) => {
|
|
|
50
58
|
return match === null || match === void 0 ? void 0 : match[1];
|
|
51
59
|
};
|
|
52
60
|
exports.createdObservationReference = createdObservationReference;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
resource: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
/** The placeholder other entries of a save use to point at `entry` before the server gives it an id. */
|
|
62
|
+
const placeholderOf = (entry) => { var _a, _b; return (_a = entry.fullUrl) !== null && _a !== void 0 ? _a : (((_b = entry.resource) === null || _b === void 0 ? void 0 : _b.resourceType) === "Observation" ? `urn:uuid:${(0, offline_1.stableMeasurementId)(entry.resource)}` : undefined); };
|
|
63
|
+
/** Points `hasMember` links at the saved observations in `saved`, by placeholder, where an earlier request saved them. */
|
|
64
|
+
const rewriteSavedReferences = (entries, saved) => saved.size === 0
|
|
65
|
+
? entries
|
|
66
|
+
: entries.map((entry) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const resource = entry.resource;
|
|
69
|
+
if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) !== "Observation" || !((_a = resource.hasMember) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
70
|
+
return entry;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
...entry,
|
|
74
|
+
resource: {
|
|
75
|
+
...resource,
|
|
76
|
+
hasMember: resource.hasMember.map((member) => {
|
|
77
|
+
const reference = member.reference && saved.get(member.reference);
|
|
78
|
+
return reference ? { ...member, reference } : member;
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
const rewriteObservationReferences = (entries, from, to) => rewriteSavedReferences(entries, new Map([[from, to]]));
|
|
68
84
|
exports.rewriteObservationReferences = rewriteObservationReferences;
|
|
69
85
|
const splitObservationBundleEntries = (bundle) => {
|
|
70
86
|
var _a;
|
|
@@ -92,13 +108,11 @@ const splitObservationBundleEntries = (bundle) => {
|
|
|
92
108
|
};
|
|
93
109
|
exports.splitObservationBundleEntries = splitObservationBundleEntries;
|
|
94
110
|
const executeObservationBundle = async (bundle, executeBatch) => {
|
|
95
|
-
var _a, _b, _c, _d, _e, _f
|
|
111
|
+
var _a, _b, _c, _d, _e, _f;
|
|
96
112
|
const entries = (_a = bundle.entry) !== null && _a !== void 0 ? _a : [];
|
|
97
113
|
if (bundle.type === "transaction" &&
|
|
98
114
|
entries.length > exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES) {
|
|
99
|
-
const rootReference =
|
|
100
|
-
? `urn:uuid:${(0, offline_1.stableMeasurementId)(entries[0].resource)}`
|
|
101
|
-
: undefined);
|
|
115
|
+
const rootReference = entries[0] && placeholderOf(entries[0]);
|
|
102
116
|
const transactionResponse = await (0, exports.executeObservationBundle)({ ...bundle, entry: entries.slice(0, 1) }, executeBatch);
|
|
103
117
|
const savedRootReference = rootReference
|
|
104
118
|
? (0, exports.createdObservationReference)(transactionResponse, 0)
|
|
@@ -114,26 +128,24 @@ const executeObservationBundle = async (bundle, executeBatch) => {
|
|
|
114
128
|
resourceType: "Bundle",
|
|
115
129
|
type: "batch-response",
|
|
116
130
|
entry: [
|
|
117
|
-
...((
|
|
118
|
-
...((
|
|
131
|
+
...((_b = transactionResponse.entry) !== null && _b !== void 0 ? _b : []),
|
|
132
|
+
...((_c = batchResponse.entry) !== null && _c !== void 0 ? _c : []),
|
|
119
133
|
],
|
|
120
134
|
};
|
|
121
135
|
}
|
|
122
136
|
const chunks = (0, exports.splitObservationBundleEntries)(bundle);
|
|
123
137
|
if (chunks) {
|
|
124
138
|
const responses = [];
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
savedRootReference = (0, exports.createdObservationReference)(response, 0);
|
|
136
|
-
}
|
|
139
|
+
const saved = new Map();
|
|
140
|
+
for (const chunk of chunks) {
|
|
141
|
+
const response = await (0, exports.executeObservationBundle)({ ...bundle, entry: rewriteSavedReferences(chunk, saved) }, executeBatch);
|
|
142
|
+
chunk.forEach((entry, index) => {
|
|
143
|
+
const placeholder = placeholderOf(entry);
|
|
144
|
+
const reference = (0, exports.createdObservationReference)(response, index);
|
|
145
|
+
if (placeholder && reference) {
|
|
146
|
+
saved.set(placeholder, reference);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
137
149
|
responses.push(response);
|
|
138
150
|
}
|
|
139
151
|
return {
|
|
@@ -143,7 +155,7 @@ const executeObservationBundle = async (bundle, executeBatch) => {
|
|
|
143
155
|
};
|
|
144
156
|
}
|
|
145
157
|
const response = await executeBatch(bundle);
|
|
146
|
-
if (((
|
|
158
|
+
if (((_e = (_d = response.entry) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) !== entries.length || ((_f = response.entry) === null || _f === void 0 ? void 0 : _f.some(bundle_entry_status_1.isFailedEntry))) {
|
|
147
159
|
throw response;
|
|
148
160
|
}
|
|
149
161
|
return response;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Coding, Observation } from "@medplum/fhirtypes";
|
|
2
|
+
import { MeasurementTypeKey } from "./types/MeasurementTypeKey";
|
|
3
|
+
/** The code of a reading's group: its LOINC panel where one exists, else Ovok's measurement-type code. */
|
|
4
|
+
export declare const readingGroupCoding: (type: MeasurementTypeKey) => Coding;
|
|
5
|
+
/** The code a reading of `type` is grouped under, as a code search takes it. */
|
|
6
|
+
export declare const readingGroupCode: (type: MeasurementTypeKey) => string;
|
|
7
|
+
/** The observation that groups a multi-value reading: a group code and no value of its own. */
|
|
8
|
+
export declare const isReadingGroup: (observation: Observation) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The group observation of a reading made of several observations: it carries the reading's code, time and device,
|
|
11
|
+
* and its `hasMember` is filled with the parts when they are saved. A blood pressure's also holds the pressures as
|
|
12
|
+
* components, as the FHIR vital-signs blood-pressure profile expects. A reading of one observation has none.
|
|
13
|
+
*/
|
|
14
|
+
export declare const readingGroupOf: (type: MeasurementTypeKey, parts: readonly Observation[]) => Observation | undefined;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readingGroupOf = exports.isReadingGroup = exports.readingGroupCode = exports.readingGroupCoding = void 0;
|
|
4
|
+
const fhir_systems_1 = require("./fhir-systems");
|
|
5
|
+
const MeasurementTypeKey_1 = require("./types/MeasurementTypeKey");
|
|
6
|
+
const ObservationCode_1 = require("./types/ObservationCode");
|
|
7
|
+
const BLOOD_PRESSURE_PANEL = {
|
|
8
|
+
system: fhir_systems_1.LOINC_SYSTEM,
|
|
9
|
+
code: "85354-9",
|
|
10
|
+
display: "Blood pressure panel with all children optional",
|
|
11
|
+
};
|
|
12
|
+
const URINE_DIPSTICK_PANEL = {
|
|
13
|
+
system: fhir_systems_1.LOINC_SYSTEM,
|
|
14
|
+
code: "24357-6",
|
|
15
|
+
display: "Urinalysis macro (dipstick) panel - Urine",
|
|
16
|
+
};
|
|
17
|
+
const PANEL_BY_TYPE = {
|
|
18
|
+
[MeasurementTypeKey_1.MeasurementTypeKey.bloodPressure]: BLOOD_PRESSURE_PANEL,
|
|
19
|
+
[MeasurementTypeKey_1.MeasurementTypeKey.urineAnalysis]: URINE_DIPSTICK_PANEL,
|
|
20
|
+
[MeasurementTypeKey_1.MeasurementTypeKey.uricAcid]: URINE_DIPSTICK_PANEL,
|
|
21
|
+
};
|
|
22
|
+
const PANEL_CODES = new Set([BLOOD_PRESSURE_PANEL.code, URINE_DIPSTICK_PANEL.code]);
|
|
23
|
+
/** The blood-pressure values a panel repeats as components, so it reads on its own. */
|
|
24
|
+
const BLOOD_PRESSURE_COMPONENT_CODES = [
|
|
25
|
+
ObservationCode_1.ObservationCode.SYSTOLIC_BLOOD_PRESSURE,
|
|
26
|
+
ObservationCode_1.ObservationCode.DIASTOLIC_BLOOD_PRESSURE,
|
|
27
|
+
ObservationCode_1.ObservationCode.MEAN_BLOOD_PRESSURE,
|
|
28
|
+
];
|
|
29
|
+
/** The code of a reading's group: its LOINC panel where one exists, else Ovok's measurement-type code. */
|
|
30
|
+
const readingGroupCoding = (type) => { var _a; return (_a = PANEL_BY_TYPE[type]) !== null && _a !== void 0 ? _a : { system: fhir_systems_1.MEASUREMENT_TYPE_SYSTEM, code: type }; };
|
|
31
|
+
exports.readingGroupCoding = readingGroupCoding;
|
|
32
|
+
/** The code a reading of `type` is grouped under, as a code search takes it. */
|
|
33
|
+
const readingGroupCode = (type) => { var _a; return (_a = (0, exports.readingGroupCoding)(type).code) !== null && _a !== void 0 ? _a : type; };
|
|
34
|
+
exports.readingGroupCode = readingGroupCode;
|
|
35
|
+
const hasValue = (observation) => Object.keys(observation).some((key) => key.startsWith("value"));
|
|
36
|
+
const hasPanelCode = (observation) => { var _a, _b, _c; return (_c = (_b = (_a = observation.code) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b.some(({ system, code }) => system === fhir_systems_1.LOINC_SYSTEM && PANEL_CODES.has(code !== null && code !== void 0 ? code : ""))) !== null && _c !== void 0 ? _c : false; };
|
|
37
|
+
/** A measurement-type code without components; component readings such as baby sleep share the system. */
|
|
38
|
+
const hasTypeGroupCode = (observation) => {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
return !((_a = observation.component) === null || _a === void 0 ? void 0 : _a.length) &&
|
|
41
|
+
((_d = (_c = (_b = observation.code) === null || _b === void 0 ? void 0 : _b.coding) === null || _c === void 0 ? void 0 : _c.some(({ system }) => system === fhir_systems_1.MEASUREMENT_TYPE_SYSTEM)) !== null && _d !== void 0 ? _d : false);
|
|
42
|
+
};
|
|
43
|
+
/** The observation that groups a multi-value reading: a group code and no value of its own. */
|
|
44
|
+
const isReadingGroup = (observation) => !hasValue(observation) && (hasPanelCode(observation) || hasTypeGroupCode(observation));
|
|
45
|
+
exports.isReadingGroup = isReadingGroup;
|
|
46
|
+
const codeOf = (observation) => { var _a, _b, _c; return (_c = (_b = (_a = observation.code) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code; };
|
|
47
|
+
const bloodPressureComponents = (parts) => BLOOD_PRESSURE_COMPONENT_CODES.flatMap((code) => {
|
|
48
|
+
const part = parts.find((observation) => codeOf(observation) === code);
|
|
49
|
+
return (part === null || part === void 0 ? void 0 : part.valueQuantity) ? [{ code: part.code, valueQuantity: part.valueQuantity }] : [];
|
|
50
|
+
});
|
|
51
|
+
const spanOf = (parts) => {
|
|
52
|
+
const periods = parts.flatMap((part) => (part.effectivePeriod ? [part.effectivePeriod] : []));
|
|
53
|
+
if (periods.length === 0) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const starts = periods.flatMap(({ start }) => (start ? [start] : [])).sort();
|
|
57
|
+
const ends = periods.flatMap(({ end }) => (end ? [end] : [])).sort();
|
|
58
|
+
return { start: starts[0], end: ends[ends.length - 1] };
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The group observation of a reading made of several observations: it carries the reading's code, time and device,
|
|
62
|
+
* and its `hasMember` is filled with the parts when they are saved. A blood pressure's also holds the pressures as
|
|
63
|
+
* components, as the FHIR vital-signs blood-pressure profile expects. A reading of one observation has none.
|
|
64
|
+
*/
|
|
65
|
+
const readingGroupOf = (type, parts) => {
|
|
66
|
+
var _a;
|
|
67
|
+
const [first] = parts;
|
|
68
|
+
if (!first || parts.length < 2) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const period = spanOf(parts);
|
|
72
|
+
const components = type === MeasurementTypeKey_1.MeasurementTypeKey.bloodPressure ? bloodPressureComponents(parts) : [];
|
|
73
|
+
const interpretation = (_a = parts.find((part) => { var _a; return (_a = part.interpretation) === null || _a === void 0 ? void 0 : _a.length; })) === null || _a === void 0 ? void 0 : _a.interpretation;
|
|
74
|
+
return {
|
|
75
|
+
resourceType: "Observation",
|
|
76
|
+
status: first.status,
|
|
77
|
+
...(first.category ? { category: first.category } : {}),
|
|
78
|
+
code: { coding: [(0, exports.readingGroupCoding)(type)] },
|
|
79
|
+
subject: first.subject,
|
|
80
|
+
...(first.device ? { device: first.device } : {}),
|
|
81
|
+
...(period ? { effectivePeriod: period } : first.effectiveDateTime ? { effectiveDateTime: first.effectiveDateTime } : {}),
|
|
82
|
+
...(components.length > 0 ? { component: components } : {}),
|
|
83
|
+
...(interpretation ? { interpretation } : {}),
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
exports.readingGroupOf = readingGroupOf;
|
|
@@ -41,7 +41,8 @@ export type SeriesSummary = {
|
|
|
41
41
|
/**
|
|
42
42
|
* A series as observations: one per measured property, in `MEASUREMENT_FIELDS` order with the main one first, each
|
|
43
43
|
* holding its values as `valueSampledData` across the series' `effectivePeriod`. They carry the same codes as a
|
|
44
|
-
* single reading of that kind
|
|
44
|
+
* single reading of that kind, and a series of several properties ends with their group. Save them with
|
|
45
|
+
* `saveObservations`, which links the rest to the first. ECG recordings
|
|
45
46
|
* keep their own path, `generateObservationBodiesByMeasurement`.
|
|
46
47
|
*/
|
|
47
48
|
export declare const seriesObservations: ({ series, patientId, device, status, }: SeriesObservationParams) => Observation[];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.summarizeSeries = exports.readSeries = exports.seriesObservations = void 0;
|
|
4
4
|
const observation_coding_1 = require("./observation-coding");
|
|
5
|
+
const reading_group_1 = require("./reading-group");
|
|
5
6
|
const creator_1 = require("./services/creator");
|
|
6
7
|
const getDeviceObject_1 = require("./utils/getDeviceObject");
|
|
7
8
|
/** FHIR's mark for a slot with no value. */
|
|
@@ -12,7 +13,8 @@ const sampledData = (values, decimals) => values
|
|
|
12
13
|
/**
|
|
13
14
|
* A series as observations: one per measured property, in `MEASUREMENT_FIELDS` order with the main one first, each
|
|
14
15
|
* holding its values as `valueSampledData` across the series' `effectivePeriod`. They carry the same codes as a
|
|
15
|
-
* single reading of that kind
|
|
16
|
+
* single reading of that kind, and a series of several properties ends with their group. Save them with
|
|
17
|
+
* `saveObservations`, which links the rest to the first. ECG recordings
|
|
16
18
|
* keep their own path, `generateObservationBodiesByMeasurement`.
|
|
17
19
|
*/
|
|
18
20
|
const seriesObservations = ({ series, patientId, device, status = "final", }) => {
|
|
@@ -23,7 +25,7 @@ const seriesObservations = ({ series, patientId, device, status = "final", }) =>
|
|
|
23
25
|
start: series.start.toISOString(),
|
|
24
26
|
end: new Date(series.start.getTime() + slots * series.periodMs).toISOString(),
|
|
25
27
|
};
|
|
26
|
-
|
|
28
|
+
const parts = service.getFields().flatMap((field, index) => {
|
|
27
29
|
const values = series.values[field.key];
|
|
28
30
|
const code = codes[index];
|
|
29
31
|
if (!code || !(values === null || values === void 0 ? void 0 : values.some((value) => value !== null))) {
|
|
@@ -45,6 +47,8 @@ const seriesObservations = ({ series, patientId, device, status = "final", }) =>
|
|
|
45
47
|
},
|
|
46
48
|
}];
|
|
47
49
|
});
|
|
50
|
+
const group = (0, reading_group_1.readingGroupOf)(series.measurementTypeKey, parts);
|
|
51
|
+
return group ? [...parts, group] : parts;
|
|
48
52
|
};
|
|
49
53
|
exports.seriesObservations = seriesObservations;
|
|
50
54
|
/**
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.respiratoryTherapyService = exports.babySleepService = void 0;
|
|
4
4
|
const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
|
|
5
|
+
const fhir_systems_1 = require("../fhir-systems");
|
|
5
6
|
const base_observation_service_1 = require("./base-observation-service");
|
|
6
7
|
const measurement_time_1 = require("./measurement-time");
|
|
7
|
-
const MEASUREMENT_TYPE_SYSTEM = "https://sdk.ovok.com/fhir/CodeSystem/measurement-type";
|
|
8
8
|
/** One observation that carries the device adapter's coded components as they are. */
|
|
9
9
|
class ComponentObservationService extends base_observation_service_1.BaseObservationService {
|
|
10
10
|
constructor(measurementTypeKey, measurementTypeName, code) {
|
|
@@ -58,7 +58,7 @@ class ComponentObservationService extends base_observation_service_1.BaseObserva
|
|
|
58
58
|
coding: [{
|
|
59
59
|
code: this.code,
|
|
60
60
|
display: `${this.title} observation`,
|
|
61
|
-
system: MEASUREMENT_TYPE_SYSTEM,
|
|
61
|
+
system: fhir_systems_1.MEASUREMENT_TYPE_SYSTEM,
|
|
62
62
|
}],
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -3,14 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.analyteValue = void 0;
|
|
4
4
|
const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
|
|
5
5
|
const fhir_systems_1 = require("../fhir-systems");
|
|
6
|
-
const presenceValue = (value) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
};
|
|
14
18
|
const analyteQuantity = (analyte, value) => ({
|
|
15
19
|
valueQuantity: {
|
|
16
20
|
value,
|
|
@@ -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-dev.
|
|
29
|
+
version: "0.4.49-dev.522+9825307",
|
|
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 {
|
|
@@ -6,5 +6,5 @@ import type { Observation } from "@medplum/fhirtypes";
|
|
|
6
6
|
* @category measurements
|
|
7
7
|
*/
|
|
8
8
|
export type BuildObservationsParams = GenerateObservationBodyParams;
|
|
9
|
-
/** One measurement's Observations about `subject`, a reference such as `Patient/1
|
|
9
|
+
/** One measurement's Observations about `subject`, a reference such as `Patient/1`; several end with their group. */
|
|
10
10
|
export declare function buildObservations(params: BuildObservationsParams, subject: string): Observation[];
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildObservations = buildObservations;
|
|
4
4
|
const fhir_systems_1 = require("../../../client/observation/fhir-systems");
|
|
5
5
|
const observation_coding_1 = require("../../../client/observation/observation-coding");
|
|
6
|
+
const reading_group_1 = require("../../../client/observation/reading-group");
|
|
6
7
|
const creator_1 = require("../../../client/observation/services/creator");
|
|
7
8
|
const getDeviceObject_1 = require("../../../client/observation/utils/getDeviceObject");
|
|
8
|
-
/** One measurement's Observations about `subject`, a reference such as `Patient/1
|
|
9
|
+
/** One measurement's Observations about `subject`, a reference such as `Patient/1`; several end with their group. */
|
|
9
10
|
function buildObservations(params, subject) {
|
|
10
11
|
const measurement = timedMeasurement(params.measurement, params.effectiveDateTime);
|
|
11
12
|
const service = creator_1.ObservationServiceCreator.getInstance().getService(measurement.measurementTypeKey);
|
|
@@ -15,8 +16,10 @@ function buildObservations(params, subject) {
|
|
|
15
16
|
.map((fragment) => observationOf(fragment, subject, device, readingFields))
|
|
16
17
|
.filter(hasValue)
|
|
17
18
|
.map((observation) => datedAt(observation, params.effectiveDateTime));
|
|
18
|
-
const
|
|
19
|
-
|
|
19
|
+
const parts = (0, observation_coding_1.withDeviceUser)(observations, measurement.memorySlot);
|
|
20
|
+
const group = (0, reading_group_1.readingGroupOf)(measurement.measurementTypeKey, parts);
|
|
21
|
+
const reading = group ? [...parts, group] : parts;
|
|
22
|
+
return params.sourceId ? namedAfterSource(reading, subject, params.sourceId) : reading;
|
|
20
23
|
}
|
|
21
24
|
/** The caller's time stands in for a measurement that carries none, so every observation of it shares one time. */
|
|
22
25
|
const timedMeasurement = (measurement, effectiveDateTime) => measurement.recordedAt || !effectiveDateTime ? measurement : { ...measurement, recordedAt: effectiveDateTime };
|