@ovok/core 0.4.53 → 0.4.55

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.
@@ -126,6 +126,29 @@ export type RedeemPatientSharingInvite = {
126
126
  /** Code from the invite. */
127
127
  code: string;
128
128
  };
129
+ /**
130
+ * The clinician alert digest: one mail every few hours to each practitioner a patient shares their record with,
131
+ * listing the patients with new Signals alerts.
132
+ *
133
+ * @category sharing
134
+ */
135
+ export type PractitionerAlertDigest = {
136
+ /** Whether the digest goes out. */
137
+ enabled: boolean;
138
+ /** How many hours apart: 1, 6, 12 or 24. */
139
+ everyHours: number;
140
+ };
141
+ /**
142
+ * A change to the clinician alert digest.
143
+ *
144
+ * @category sharing
145
+ */
146
+ export type PractitionerAlertDigestUpdate = {
147
+ /** Whether the digest goes out. */
148
+ enabled: boolean;
149
+ /** How many hours apart: 1, 6, 12 or 24; left out keeps the saved hours. */
150
+ everyHours?: number;
151
+ };
129
152
  /**
130
153
  * Project settings for patient sharing.
131
154
  *
@@ -138,6 +161,8 @@ export type PatientSharingSettings = {
138
161
  accessPolicyId: string | null;
139
162
  /** Whether patients may share with practitioners. */
140
163
  practitionerSharingEnabled: boolean;
164
+ /** The clinician alert digest; off, every 6 hours, until an admin sets it. */
165
+ practitionerAlertDigest: PractitionerAlertDigest;
141
166
  };
142
167
  /**
143
168
  * Request to update patient sharing settings.
@@ -149,4 +174,9 @@ export type PatientSharingSettingsUpdate = {
149
174
  enabled: boolean;
150
175
  /** Whether patients may share with practitioners; null leaves it unchanged. */
151
176
  practitionerSharingEnabled?: boolean | null;
177
+ /**
178
+ * The clinician alert digest; null leaves it unchanged. Switching it on needs Signals annotations, patient sharing and
179
+ * practitioner sharing on, or the server answers 409.
180
+ */
181
+ practitionerAlertDigest?: PractitionerAlertDigestUpdate | null;
152
182
  };
@@ -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.53",
29
+ version: "0.4.55",
30
30
  },
31
31
  fhirVersion: "4.0.1",
32
32
  format: ["json"],
@@ -8,6 +8,7 @@ export { readMeasurementContext } from "../client/observation/measurement-contex
8
8
  export type { MeasurementBodyPosition, MeasurementContext, MeasurementFeeling, } from "../client/observation/measurement-context";
9
9
  export { IndexedDbOutboxStore } from "./outbox/indexed-db-outbox-store";
10
10
  export { MemoryOutboxStore } from "./outbox/memory-outbox-store";
11
+ export { GUEST_OWNER_KEY, GUEST_PATIENT_ID } from "./outbox/guest-items";
11
12
  export { outboxStoreContract } from "./outbox/store-contract";
12
13
  export { browserConnectivity, browserLifecycle } from "./outbox/outbox-triggers";
13
14
  export type { IndexedDbOutboxOptions } from "./outbox/indexed-db-outbox-store";
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.OvokAccountError = exports.OvokValidationError = exports.OvokTimeoutError = exports.OvokServiceError = exports.OvokRateLimitError = exports.OvokPermissionError = exports.OvokNotFoundError = exports.OvokError = exports.OvokConnectionError = exports.OvokConflictError = exports.OvokConfigError = exports.OvokAuthenticationError = exports.browserLifecycle = exports.browserConnectivity = exports.outboxStoreContract = exports.MemoryOutboxStore = exports.IndexedDbOutboxStore = exports.readMeasurementContext = exports.SERIES_IDENTIFIER_SYSTEM = exports.SEGMENT_IDENTIFIER_SYSTEM = exports.summarizeSeries = exports.readSeries = exports.seriesObservations = exports.MemoryStorage = exports.Ovok = void 0;
17
+ exports.OvokAccountError = exports.OvokValidationError = exports.OvokTimeoutError = exports.OvokServiceError = exports.OvokRateLimitError = exports.OvokPermissionError = exports.OvokNotFoundError = exports.OvokError = exports.OvokConnectionError = exports.OvokConflictError = exports.OvokConfigError = exports.OvokAuthenticationError = exports.browserLifecycle = exports.browserConnectivity = exports.outboxStoreContract = exports.GUEST_PATIENT_ID = exports.GUEST_OWNER_KEY = exports.MemoryOutboxStore = exports.IndexedDbOutboxStore = exports.readMeasurementContext = exports.SERIES_IDENTIFIER_SYSTEM = exports.SEGMENT_IDENTIFIER_SYSTEM = exports.summarizeSeries = exports.readSeries = exports.seriesObservations = exports.MemoryStorage = exports.Ovok = void 0;
18
18
  var ovok_1 = require("./ovok");
19
19
  Object.defineProperty(exports, "Ovok", { enumerable: true, get: function () { return ovok_1.Ovok; } });
20
20
  var ovok_storage_1 = require("./storage/ovok-storage");
@@ -32,6 +32,9 @@ var indexed_db_outbox_store_1 = require("./outbox/indexed-db-outbox-store");
32
32
  Object.defineProperty(exports, "IndexedDbOutboxStore", { enumerable: true, get: function () { return indexed_db_outbox_store_1.IndexedDbOutboxStore; } });
33
33
  var memory_outbox_store_1 = require("./outbox/memory-outbox-store");
34
34
  Object.defineProperty(exports, "MemoryOutboxStore", { enumerable: true, get: function () { return memory_outbox_store_1.MemoryOutboxStore; } });
35
+ var guest_items_1 = require("./outbox/guest-items");
36
+ Object.defineProperty(exports, "GUEST_OWNER_KEY", { enumerable: true, get: function () { return guest_items_1.GUEST_OWNER_KEY; } });
37
+ Object.defineProperty(exports, "GUEST_PATIENT_ID", { enumerable: true, get: function () { return guest_items_1.GUEST_PATIENT_ID; } });
35
38
  var store_contract_1 = require("./outbox/store-contract");
36
39
  Object.defineProperty(exports, "outboxStoreContract", { enumerable: true, get: function () { return store_contract_1.outboxStoreContract; } });
37
40
  var outbox_triggers_1 = require("./outbox/outbox-triggers");
@@ -0,0 +1,18 @@
1
+ import type { OutboxStore } from "./outbox-store";
2
+ /**
3
+ * The owner of what is saved while nobody is signed in. A guest's items are never sent; `adopt` hands them to a patient.
4
+ *
5
+ * @category outbox
6
+ */
7
+ export declare const GUEST_OWNER_KEY = "guest";
8
+ /**
9
+ * The patient a guest's observations name until `adopt` names the real one.
10
+ *
11
+ * @category outbox
12
+ */
13
+ export declare const GUEST_PATIENT_ID = "guest";
14
+ export declare const GUEST_SUBJECT = "Patient/guest";
15
+ /** The account an owner's items are sent for; a guest's wait for `adopt`. */
16
+ export declare const sendingOwner: (ownerKey: string | null) => string | null;
17
+ /** Hands every guest item to `ownerKey`, its observations naming `patient`, a reference such as `Patient/1`; returns how many. */
18
+ export declare const adoptGuestItems: (store: OutboxStore, ownerKey: string, patient: string) => Promise<number>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adoptGuestItems = exports.sendingOwner = exports.GUEST_SUBJECT = exports.GUEST_PATIENT_ID = exports.GUEST_OWNER_KEY = void 0;
4
+ const entry_observation_1 = require("./entry-observation");
5
+ /**
6
+ * The owner of what is saved while nobody is signed in. A guest's items are never sent; `adopt` hands them to a patient.
7
+ *
8
+ * @category outbox
9
+ */
10
+ exports.GUEST_OWNER_KEY = "guest";
11
+ /**
12
+ * The patient a guest's observations name until `adopt` names the real one.
13
+ *
14
+ * @category outbox
15
+ */
16
+ exports.GUEST_PATIENT_ID = "guest";
17
+ exports.GUEST_SUBJECT = `Patient/${exports.GUEST_PATIENT_ID}`;
18
+ const GUEST_IDENTIFIER_PREFIX = `${exports.GUEST_SUBJECT}/`;
19
+ const ENCODED_GUEST_SUBJECT = encodeURIComponent(exports.GUEST_SUBJECT);
20
+ /** A reading identifier starts with its subject, so the server tells two patients' readings apart. */
21
+ const adoptedIdentifier = (identifier, patient) => {
22
+ var _a;
23
+ return ((_a = identifier.value) === null || _a === void 0 ? void 0 : _a.startsWith(GUEST_IDENTIFIER_PREFIX))
24
+ ? { ...identifier, value: `${patient}/${identifier.value.slice(GUEST_IDENTIFIER_PREFIX.length)}` }
25
+ : identifier;
26
+ };
27
+ const adoptedObservation = (observation, patient) => {
28
+ var _a;
29
+ return ({
30
+ ...observation,
31
+ ...(((_a = observation.subject) === null || _a === void 0 ? void 0 : _a.reference) === exports.GUEST_SUBJECT && { subject: { reference: patient } }),
32
+ ...(observation.identifier && { identifier: observation.identifier.map((identifier) => adoptedIdentifier(identifier, patient)) }),
33
+ });
34
+ };
35
+ /** The searches that create an observation once hold its subject and reading identifiers URI-encoded. */
36
+ const adoptedSearch = (search, patient) => search.split(ENCODED_GUEST_SUBJECT).join(encodeURIComponent(patient));
37
+ const adoptedRequest = (request, patient) => ({
38
+ ...request,
39
+ url: adoptedSearch(request.url, patient),
40
+ ...(request.ifNoneExist && { ifNoneExist: adoptedSearch(request.ifNoneExist, patient) }),
41
+ });
42
+ const adoptedEntry = (entry, patient) => {
43
+ const observation = (0, entry_observation_1.observationOf)(entry);
44
+ return {
45
+ ...entry,
46
+ ...(observation && { resource: adoptedObservation(observation, patient) }),
47
+ ...(entry.request && { request: adoptedRequest(entry.request, patient) }),
48
+ };
49
+ };
50
+ const adoptedItem = (item, ownerKey, patient) => ({
51
+ ...item,
52
+ ownerKey,
53
+ entries: item.entries.map((entry) => adoptedEntry(entry, patient)),
54
+ });
55
+ /** The account an owner's items are sent for; a guest's wait for `adopt`. */
56
+ const sendingOwner = (ownerKey) => (ownerKey === exports.GUEST_OWNER_KEY ? null : ownerKey);
57
+ exports.sendingOwner = sendingOwner;
58
+ /** Hands every guest item to `ownerKey`, its observations naming `patient`, a reference such as `Patient/1`; returns how many. */
59
+ const adoptGuestItems = async (store, ownerKey, patient) => {
60
+ const guestItems = await store.summaries(exports.GUEST_OWNER_KEY);
61
+ for (const { id } of guestItems) {
62
+ const item = await store.get(id);
63
+ if (item) {
64
+ await store.put(adoptedItem(item, ownerKey, patient));
65
+ }
66
+ }
67
+ return guestItems.length;
68
+ };
69
+ exports.adoptGuestItems = adoptGuestItems;
@@ -60,6 +60,11 @@ export declare class OutboxResource {
60
60
  pendingObservations(): Promise<Observation[]>;
61
61
  /** Queues the deletion of the observations with an identifier, for readings that were saved before. */
62
62
  enqueueDelete(target: OutboxDeleteTarget): Promise<void>;
63
+ /**
64
+ * Hands every item saved while nobody was signed in to the signed-in account, naming the patient, the signed-in
65
+ * profile by default, as the subject of its observations, then sends them. Returns how many items it handed over.
66
+ */
67
+ adopt(patientId?: string): Promise<number>;
63
68
  /** @internal Stores items for sending; a newer version of a series or segment replaces the stored one. */
64
69
  enqueue(ownerKey: string, drafts: OutboxDraft[]): Promise<void>;
65
70
  /** @internal Sends what is due now and reports what happened to each item. */
@@ -4,6 +4,7 @@ exports.OutboxResource = void 0;
4
4
  const ovok_errors_1 = require("../errors/ovok-errors");
5
5
  const ovok_logger_1 = require("../logging/ovok-logger");
6
6
  const entry_observation_1 = require("./entry-observation");
7
+ const guest_items_1 = require("./guest-items");
7
8
  const legacy_queue_import_1 = require("./legacy-queue-import");
8
9
  const memory_outbox_store_1 = require("./memory-outbox-store");
9
10
  const outbox_items_1 = require("./outbox-items");
@@ -33,7 +34,7 @@ class OutboxResource {
33
34
  this.runner = new outbox_runner_1.OutboxRunner({
34
35
  store: this.store,
35
36
  transport: settings.transport,
36
- ownerKey: settings.ownerKey,
37
+ ownerKey: async () => (0, guest_items_1.sendingOwner)(await settings.ownerKey()),
37
38
  budget: new request_budget_1.RequestBudget(settings.requestBudget),
38
39
  logger: this.log,
39
40
  now: this.now,
@@ -101,10 +102,31 @@ class OutboxResource {
101
102
  if (ownerKey === null) {
102
103
  throw new ovok_errors_1.OvokValidationError((0, ovok_errors_1.detailsFor)("No user is signed in; the outbox keeps items per account."));
103
104
  }
104
- const subject = target.patientId ? `Patient/${target.patientId}` : await this.settings.signedInProfile();
105
105
  await (0, pending_saves_1.cancelPendingSaves)(this.store, ownerKey, target, (id) => this.runner.supersede(id));
106
+ if (ownerKey === guest_items_1.GUEST_OWNER_KEY) {
107
+ // A guest's readings never reached the server, so there is nothing to delete there.
108
+ return this.notify();
109
+ }
110
+ const subject = target.patientId ? `Patient/${target.patientId}` : await this.settings.signedInProfile();
106
111
  await this.enqueue(ownerKey, [(0, outbox_items_1.deleteDraft)(target, subject, ownerKey, this.now())]);
107
112
  }
113
+ /**
114
+ * Hands every item saved while nobody was signed in to the signed-in account, naming the patient, the signed-in
115
+ * profile by default, as the subject of its observations, then sends them. Returns how many items it handed over.
116
+ */
117
+ async adopt(patientId) {
118
+ await this.ready;
119
+ const ownerKey = (0, guest_items_1.sendingOwner)(await this.settings.ownerKey());
120
+ if (ownerKey === null) {
121
+ throw new ovok_errors_1.OvokValidationError((0, ovok_errors_1.detailsFor)("No user is signed in; sign in to adopt a guest's readings."));
122
+ }
123
+ const patient = patientId ? `Patient/${patientId}` : await this.settings.signedInProfile();
124
+ const adopted = await (0, guest_items_1.adoptGuestItems)(this.store, ownerKey, patient);
125
+ this.log.info("outbox.adopted", { items: adopted });
126
+ this.runner.wake(0);
127
+ this.notify();
128
+ return adopted;
129
+ }
108
130
  /** @internal Stores items for sending; a newer version of a series or segment replaces the stored one. */
109
131
  async enqueue(ownerKey, drafts) {
110
132
  await this.ready;
@@ -110,7 +110,8 @@ export declare class MeasurementsResource {
110
110
  /**
111
111
  * One reading, main observation first, created conditionally so a retry cannot duplicate it. A series is written
112
112
  * over by its identifier, and a recording of several segments goes up one segment at a time. It throws the server's
113
- * error when the server refuses the reading, which then waits in the outbox as rejected.
113
+ * error when the server refuses the reading, which then waits in the outbox as rejected. While nobody is signed in,
114
+ * the reading is kept for the guest and says queued.
114
115
  */
115
116
  saveObservations(observations: Observation[], options?: SaveObservationsOptions): Promise<SaveObservationsResult>;
116
117
  /**
@@ -121,7 +122,7 @@ export declare class MeasurementsResource {
121
122
  * first: if it fails, some readings may be saved and others not, and saving them again is safe.
122
123
  */
123
124
  saveObservationGroups(groups: Observation[][], options?: SaveObservationsOptions): Promise<Bundle>;
124
- /** Builds the Observations for a measurement without saving them. */
125
+ /** Builds the Observations for a measurement without saving them; while nobody is signed in, they name the guest. */
125
126
  build(params: BuildObservationsParams): Promise<Observation[]>;
126
127
  /** Reads the latest observation of each code for a patient. Calls `GET fhir/Observation/$lastn`. */
127
128
  latest(params: LatestObservationsParams, options?: RequestOptions): Promise<Bundle<Observation>>;
@@ -136,5 +137,7 @@ export declare class MeasurementsResource {
136
137
  private saveDirectly;
137
138
  /** Stores the items, then sends what is due; a refusal of one of these items is thrown, nobody else's. */
138
139
  private sendThroughOutbox;
140
+ /** A user client with nobody signed in saves for the guest, whose items stay on the device until `adopt`. */
139
141
  private currentOwnerKey;
142
+ private ownSubject;
140
143
  }
@@ -6,6 +6,7 @@ const observation_bundle_utils_1 = require("../../../client/observation/observat
6
6
  const offline_measurement_queue_1 = require("../../../client/offline/offline-measurement-queue");
7
7
  const query_string_1 = require("../../../client/query-string");
8
8
  const url_1 = require("../../http/url");
9
+ const guest_items_1 = require("../../outbox/guest-items");
9
10
  const outbox_items_1 = require("../../outbox/outbox-items");
10
11
  const outbox_resource_1 = require("../../outbox/outbox-resource");
11
12
  const measurement_sender_1 = require("./measurement-sender");
@@ -48,7 +49,8 @@ class MeasurementsResource {
48
49
  /**
49
50
  * One reading, main observation first, created conditionally so a retry cannot duplicate it. A series is written
50
51
  * over by its identifier, and a recording of several segments goes up one segment at a time. It throws the server's
51
- * error when the server refuses the reading, which then waits in the outbox as rejected.
52
+ * error when the server refuses the reading, which then waits in the outbox as rejected. While nobody is signed in,
53
+ * the reading is kept for the guest and says queued.
52
54
  */
53
55
  async saveObservations(observations, options = {}) {
54
56
  const { identifierSystems, replace, ...requestOptions } = options;
@@ -88,9 +90,9 @@ class MeasurementsResource {
88
90
  entry: [...responses].flatMap((response) => { var _a; return (_a = response.entry) !== null && _a !== void 0 ? _a : []; }),
89
91
  };
90
92
  }
91
- /** Builds the Observations for a measurement without saving them. */
93
+ /** Builds the Observations for a measurement without saving them; while nobody is signed in, they name the guest. */
92
94
  async build(params) {
93
- const subject = params.patientId ? `Patient/${params.patientId}` : await this.account.profileReference();
95
+ const subject = params.patientId ? `Patient/${params.patientId}` : await this.ownSubject();
94
96
  return (0, observation_builder_1.buildObservations)(params, subject);
95
97
  }
96
98
  /** Reads the latest observation of each code for a patient. Calls `GET fhir/Observation/$lastn`. */
@@ -140,12 +142,19 @@ class MeasurementsResource {
140
142
  }
141
143
  return report;
142
144
  }
145
+ /** A user client with nobody signed in saves for the guest, whose items stay on the device until `adopt`. */
143
146
  async currentOwnerKey() {
144
147
  const accountKey = await this.account.key();
145
148
  if (accountKey) {
146
149
  return `user:${accountKey}`;
147
150
  }
148
- return this.session === null && this.machineClientId ? `machine:${this.machineClientId}` : null;
151
+ if (this.session !== null) {
152
+ return guest_items_1.GUEST_OWNER_KEY;
153
+ }
154
+ return this.machineClientId ? `machine:${this.machineClientId}` : null;
155
+ }
156
+ async ownSubject() {
157
+ return (await this.currentOwnerKey()) === guest_items_1.GUEST_OWNER_KEY ? guest_items_1.GUEST_SUBJECT : this.account.profileReference();
149
158
  }
150
159
  }
151
160
  exports.MeasurementsResource = MeasurementsResource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.53",
3
+ "version": "0.4.55",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",