@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
|
@@ -99,7 +99,11 @@ export declare class MeasurementsResource {
|
|
|
99
99
|
save(params: BuildObservationsParams, options?: SaveObservationsOptions): Promise<SaveObservationsResult>;
|
|
100
100
|
/** One reading, main observation first, created conditionally so a retry cannot duplicate it. */
|
|
101
101
|
saveObservations(observations: Observation[], options?: SaveObservationsOptions): Promise<SaveObservationsResult>;
|
|
102
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Many readings, each main observation first, in as few requests as fit. A request holding one reading is a
|
|
104
|
+
* transaction, atomic when the project enables FHIR transactions. A request holding several is two batches, main
|
|
105
|
+
* observations first: if it fails, some readings may be saved and others not, and saving them again is safe.
|
|
106
|
+
*/
|
|
103
107
|
saveObservationGroups(groups: Observation[][], options?: SaveObservationsOptions): Promise<Bundle>;
|
|
104
108
|
/** Builds the Observations for a measurement without saving them. */
|
|
105
109
|
build(params: BuildObservationsParams): Promise<Observation[]>;
|
|
@@ -112,8 +116,13 @@ export declare class MeasurementsResource {
|
|
|
112
116
|
/** The comma-joined codes the types are saved under, as `latest` and FHIR `code` searches take them. */
|
|
113
117
|
codesFor(types: MeasurementCodeTypes): string;
|
|
114
118
|
private latestPatientId;
|
|
115
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* A reading split over several requests stops once another account signs in, so none of it lands elsewhere. A
|
|
121
|
+
* transaction refused because its main observation matched several saved copies is sent again as batches.
|
|
122
|
+
*/
|
|
116
123
|
private send;
|
|
124
|
+
private sendReadings;
|
|
125
|
+
private guarded;
|
|
117
126
|
private currentOwnerKey;
|
|
118
127
|
private requireOwner;
|
|
119
128
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MeasurementsResource = void 0;
|
|
4
4
|
const observationsToMeasurements_1 = require("../../../client/observation/methods/observationsToMeasurements");
|
|
5
5
|
const observation_bundle_utils_1 = require("../../../client/observation/observation-bundle-utils");
|
|
6
|
+
const observation_groups_1 = require("../../../client/observation/observation-groups");
|
|
6
7
|
const offline_measurement_queue_1 = require("../../../client/offline/offline-measurement-queue");
|
|
7
8
|
const query_string_1 = require("../../../client/query-string");
|
|
8
9
|
const ovok_errors_1 = require("../../errors/ovok-errors");
|
|
@@ -13,6 +14,7 @@ const save_error_1 = require("./save-error");
|
|
|
13
14
|
const signed_in_account_1 = require("./signed-in-account");
|
|
14
15
|
const LATEST_OBSERVATIONS_PATH = "fhir/Observation/$lastn";
|
|
15
16
|
const LATEST_PER_CODE = 1;
|
|
17
|
+
const PRECONDITION_FAILED = 412;
|
|
16
18
|
/**
|
|
17
19
|
* Builds, saves and reads measurements as FHIR Observations, with an offline queue.
|
|
18
20
|
*
|
|
@@ -54,7 +56,11 @@ class MeasurementsResource {
|
|
|
54
56
|
? { status: "saved", response }
|
|
55
57
|
: { status: "queued", queueId: queued.id };
|
|
56
58
|
}
|
|
57
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Many readings, each main observation first, in as few requests as fit. A request holding one reading is a
|
|
61
|
+
* transaction, atomic when the project enables FHIR transactions. A request holding several is two batches, main
|
|
62
|
+
* observations first: if it fails, some readings may be saved and others not, and saving them again is safe.
|
|
63
|
+
*/
|
|
58
64
|
async saveObservationGroups(groups, options = {}) {
|
|
59
65
|
const { identifierSystems, replace, ...requestOptions } = options;
|
|
60
66
|
const entryGroups = groups
|
|
@@ -62,9 +68,10 @@ class MeasurementsResource {
|
|
|
62
68
|
.map((group) => (0, observation_bundle_utils_1.linkObservationMembers)(group).map((observation) => (0, offline_measurement_queue_1.entryForObservation)(observation, { identifierSystems, replace })));
|
|
63
69
|
const owner = await this.currentOwnerKey();
|
|
64
70
|
const responses = [];
|
|
65
|
-
for (const request of (0,
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
for (const request of (0, observation_groups_1.packObservationGroups)(entryGroups)) {
|
|
72
|
+
responses.push(request.length === 1
|
|
73
|
+
? await this.send({ resourceType: "Bundle", type: "transaction", entry: request.flat() }, requestOptions, owner)
|
|
74
|
+
: await this.sendReadings(request, requestOptions, owner));
|
|
68
75
|
}
|
|
69
76
|
return { resourceType: "Bundle", type: "batch-response", entry: responses.flatMap((response) => { var _a; return (_a = response.entry) !== null && _a !== void 0 ? _a : []; }) };
|
|
70
77
|
}
|
|
@@ -101,10 +108,28 @@ class MeasurementsResource {
|
|
|
101
108
|
}
|
|
102
109
|
return params.patientId;
|
|
103
110
|
}
|
|
104
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* A reading split over several requests stops once another account signs in, so none of it lands elsewhere. A
|
|
113
|
+
* transaction refused because its main observation matched several saved copies is sent again as batches.
|
|
114
|
+
*/
|
|
105
115
|
async send(bundle, options, owner) {
|
|
116
|
+
var _a;
|
|
117
|
+
try {
|
|
118
|
+
return await this.guarded((execute) => (0, observation_bundle_utils_1.executeObservationBundle)(bundle, execute), options, owner);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (bundle.type === "transaction" && error instanceof ovok_errors_1.OvokError && error.status === PRECONDITION_FAILED) {
|
|
122
|
+
return this.sendReadings([(_a = bundle.entry) !== null && _a !== void 0 ? _a : []], options, owner);
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
sendReadings(groups, options, owner) {
|
|
128
|
+
return this.guarded((execute) => (0, observation_groups_1.executeReadingsBatch)(groups, execute), options, owner);
|
|
129
|
+
}
|
|
130
|
+
async guarded(run, options, owner) {
|
|
106
131
|
try {
|
|
107
|
-
return await (
|
|
132
|
+
return await run(async (request) => {
|
|
108
133
|
await this.requireOwner(owner);
|
|
109
134
|
return this.fhir.batch(request, options);
|
|
110
135
|
});
|
|
@@ -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[];
|
|
@@ -2,18 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildObservations = buildObservations;
|
|
4
4
|
const fhir_systems_1 = require("../../../client/observation/fhir-systems");
|
|
5
|
+
const observation_coding_1 = require("../../../client/observation/observation-coding");
|
|
6
|
+
const reading_group_1 = require("../../../client/observation/reading-group");
|
|
5
7
|
const creator_1 = require("../../../client/observation/services/creator");
|
|
6
8
|
const getDeviceObject_1 = require("../../../client/observation/utils/getDeviceObject");
|
|
7
|
-
/** 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. */
|
|
8
10
|
function buildObservations(params, subject) {
|
|
9
|
-
const
|
|
11
|
+
const measurement = timedMeasurement(params.measurement, params.effectiveDateTime);
|
|
12
|
+
const service = creator_1.ObservationServiceCreator.getInstance().getService(measurement.measurementTypeKey);
|
|
10
13
|
const device = (0, getDeviceObject_1.getDeviceObject)(params.device);
|
|
11
|
-
const
|
|
12
|
-
|
|
14
|
+
const readingFields = (0, observation_coding_1.readingStatusAndCategory)(measurement.measurementTypeKey);
|
|
15
|
+
const observations = fragmentsOf(service, measurement)
|
|
16
|
+
.map((fragment) => observationOf(fragment, subject, device, readingFields))
|
|
13
17
|
.filter(hasValue)
|
|
14
18
|
.map((observation) => datedAt(observation, params.effectiveDateTime));
|
|
15
|
-
|
|
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;
|
|
16
23
|
}
|
|
24
|
+
/** The caller's time stands in for a measurement that carries none, so every observation of it shares one time. */
|
|
25
|
+
const timedMeasurement = (measurement, effectiveDateTime) => measurement.recordedAt || !effectiveDateTime ? measurement : { ...measurement, recordedAt: effectiveDateTime };
|
|
17
26
|
/** Services without fragments describe their observations as parallel code, value and property lists. */
|
|
18
27
|
const fragmentsOf = (service, measurement) => { var _a, _b; return (_b = (_a = service.generateObservationFragments) === null || _a === void 0 ? void 0 : _a.call(service, measurement)) !== null && _b !== void 0 ? _b : codeValueFragments(service, measurement); };
|
|
19
28
|
const codeValueFragments = (service, measurement) => {
|
|
@@ -25,9 +34,9 @@ const codeValueFragments = (service, measurement) => {
|
|
|
25
34
|
additionalProperties: additionalProperties[index],
|
|
26
35
|
}));
|
|
27
36
|
};
|
|
28
|
-
const observationOf = (fragment, subject, device) => ({
|
|
37
|
+
const observationOf = (fragment, subject, device, readingFields) => ({
|
|
29
38
|
resourceType: "Observation",
|
|
30
|
-
|
|
39
|
+
...readingFields,
|
|
31
40
|
subject: { reference: subject },
|
|
32
41
|
device,
|
|
33
42
|
...fragment.value,
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBundle = void 0;
|
|
4
4
|
exports.saveErrorFrom = saveErrorFrom;
|
|
5
|
+
const bundle_entry_status_1 = require("../../../client/observation/bundle-entry-status");
|
|
5
6
|
const ovok_errors_1 = require("../../errors/ovok-errors");
|
|
6
|
-
const FAILED_STATUS = /^[45]/;
|
|
7
7
|
const isBundle = (value) => typeof value === "object" && value !== null && value.resourceType === "Bundle";
|
|
8
8
|
exports.isBundle = isBundle;
|
|
9
9
|
/** A save's response that refused or left out an observation; a refused one gives its own status. */
|
|
10
10
|
function saveErrorFrom(response) {
|
|
11
|
-
var _a;
|
|
12
|
-
const
|
|
13
|
-
const refused = statuses.find((status) => FAILED_STATUS.test(status));
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
const refused = (_c = (_b = ((_a = response.entry) !== null && _a !== void 0 ? _a : []).find(bundle_entry_status_1.isFailedEntry)) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.status;
|
|
14
13
|
const message = refused
|
|
15
14
|
? `The server refused an observation of the reading: ${refused}.`
|
|
16
15
|
: "The server's response left out an observation of the reading.";
|
|
@@ -77,20 +77,21 @@ class RealtimeSocket {
|
|
|
77
77
|
this.waitingForPong = false;
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
if (!
|
|
80
|
+
if (!isStatusBundle(message)) {
|
|
81
81
|
socket.close();
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
const [{ resource: status }, ...changes] = message.entry;
|
|
85
|
+
if (status.type === "handshake") {
|
|
85
86
|
this.clearHandshakeTimer();
|
|
86
87
|
this.onHandshake();
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
|
-
if (
|
|
90
|
+
if (status.type === "heartbeat") {
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
|
-
if (
|
|
93
|
-
this.handler({ ...
|
|
93
|
+
if (status.type === "event-notification") {
|
|
94
|
+
this.handler({ ...status, type: "event-notification", resources: changedResources(changes) });
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
socketClosed(socket) {
|
|
@@ -150,3 +151,9 @@ const isSubscriptionStatus = (value) => {
|
|
|
150
151
|
typeof value.type === "string" &&
|
|
151
152
|
typeof value.subscription.reference === "string");
|
|
152
153
|
};
|
|
154
|
+
const isStatusBundle = (value) => value.resourceType === "Bundle" &&
|
|
155
|
+
Array.isArray(value.entry) &&
|
|
156
|
+
isRecord(value.entry[0]) &&
|
|
157
|
+
isSubscriptionStatus(value.entry[0].resource);
|
|
158
|
+
const isResource = (value) => isRecord(value) && typeof value.resourceType === "string";
|
|
159
|
+
const changedResources = (entries) => entries.flatMap((entry) => (isRecord(entry) && isResource(entry.resource) ? [entry.resource] : []));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SubscriptionStatus } from "@medplum/fhirtypes";
|
|
1
|
+
import type { Resource, SubscriptionStatus } from "@medplum/fhirtypes";
|
|
2
2
|
/**
|
|
3
3
|
* A notification that a resource matching a subscription changed.
|
|
4
4
|
*
|
|
@@ -7,6 +7,8 @@ import type { SubscriptionStatus } from "@medplum/fhirtypes";
|
|
|
7
7
|
export type RealtimeNotification = SubscriptionStatus & {
|
|
8
8
|
/** Always `"event-notification"`. */
|
|
9
9
|
type: "event-notification";
|
|
10
|
+
/** The changed resources sent with the notification, in the order the server sent them. */
|
|
11
|
+
resources: Resource[];
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
14
|
* Callback invoked for each realtime notification.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ovok/core",
|
|
3
|
-
"version": "0.4.49-rc.
|
|
3
|
+
"version": "0.4.49-rc.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/next/index.js",
|
|
6
6
|
"types": "dist/next/index.d.ts",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"bugs": {
|
|
66
66
|
"url": "https://github.com/Actimi/ovok-react-sdk/issues"
|
|
67
67
|
},
|
|
68
|
-
"homepage": "https://
|
|
68
|
+
"homepage": "https://docs.ovok.com/web-sdk",
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"registry": "https://registry.npmjs.org",
|
|
71
71
|
"access": "public"
|