@ovok/core 0.4.5 → 0.4.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/README.md CHANGED
@@ -265,6 +265,15 @@ const acked = await client.acknowledgeSignalsRawAlert(alert.id);
265
265
  // acked.acknowledgedAt and acked.acknowledgedActor record when and by whom.
266
266
  ```
267
267
 
268
+ The alert hooks take the same switch: `episodes` is optional and defaults to episodes, so existing
269
+ calls are unchanged; `episodes: false` reads and acknowledges raw alerts, typed as `SignalsRawAlert`.
270
+
271
+ ```tsx
272
+ const worklist = useSignalsAlerts({ episodes: false, acknowledged: false, codes: ["8867-4"] });
273
+ const one = useSignalsAlert(alertId, { episodes: false });
274
+ const { mutate: acknowledge } = useAcknowledgeSignalsAlert({ episodes: false });
275
+ ```
276
+
268
277
  Each `SignalsRawAlert` carries Signals' own `id`, `createdAt` and `resolvedAt`. `status` is Signals'
269
278
  state of the reading: `ACTIVE` while it breaches, `RESOLVED` once it recovered or the alert was
270
279
  acknowledged. An alert stays open for the practitioner until it is acknowledged, so list the
@@ -48,7 +48,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
48
48
  description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
49
49
  software: {
50
50
  name: "@ovok/core",
51
- version: "0.4.5",
51
+ version: "0.4.6",
52
52
  },
53
53
  fhirVersion: "4.0.1",
54
54
  format: ["json"],
@@ -0,0 +1,37 @@
1
+ import { SignalsAlert, SignalsAlertsQuery, SignalsRawAlert, SignalsRawAlertsQuery } from "../client/signals";
2
+ import { OvokMutationState, OvokRequestState } from "./api-hooks";
3
+ type SignalsAlertsHookQuery = Omit<SignalsAlertsQuery, "cursor"> & {
4
+ episodes?: true;
5
+ };
6
+ type SignalsRawAlertsHookQuery = Omit<SignalsRawAlertsQuery, "cursor"> & {
7
+ episodes: false;
8
+ };
9
+ /** Which grain an alert hook reads: episodes unless `episodes` is `false`. */
10
+ export type SignalsAlertGrain = {
11
+ episodes?: boolean;
12
+ };
13
+ export type SignalsAlertsHookState<TAlert = SignalsAlert> = {
14
+ items: TAlert[];
15
+ loading: boolean;
16
+ error: Error | undefined;
17
+ reload: () => void;
18
+ hasMore: boolean;
19
+ loadMore: () => Promise<void>;
20
+ };
21
+ export declare function useSignalsAlerts(query: SignalsRawAlertsHookQuery): SignalsAlertsHookState<SignalsRawAlert>;
22
+ export declare function useSignalsAlerts(query?: SignalsAlertsHookQuery): SignalsAlertsHookState<SignalsAlert>;
23
+ /** One episode by id, or one raw alert with `{ episodes: false }`. */
24
+ export declare function useSignalsAlert(id: string | undefined, grain: {
25
+ episodes: false;
26
+ }): OvokRequestState<SignalsRawAlert>;
27
+ export declare function useSignalsAlert(id?: string, grain?: {
28
+ episodes?: true;
29
+ }): OvokRequestState<SignalsAlert>;
30
+ /** Acknowledges an episode, or a raw alert with `{ episodes: false }`. */
31
+ export declare function useAcknowledgeSignalsAlert(grain: {
32
+ episodes: false;
33
+ }): OvokMutationState<string, SignalsRawAlert>;
34
+ export declare function useAcknowledgeSignalsAlert(grain?: {
35
+ episodes?: true;
36
+ }): OvokMutationState<string, SignalsAlert>;
37
+ export {};
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ "use client";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.useSignalsAlerts = useSignalsAlerts;
38
+ exports.useSignalsAlert = useSignalsAlert;
39
+ exports.useAcknowledgeSignalsAlert = useAcknowledgeSignalsAlert;
40
+ const React = __importStar(require("react"));
41
+ const api_hooks_1 = require("./api-hooks");
42
+ const index_1 = require("./index");
43
+ function useSignalsAlerts(query = {}) {
44
+ const client = (0, index_1.useClient)();
45
+ const queryKey = JSON.stringify(query);
46
+ const querySnapshot = React.useMemo(() => JSON.parse(queryKey), [queryKey]);
47
+ const listPage = React.useCallback((cursor) => {
48
+ const at = cursor === undefined ? {} : { cursor };
49
+ if (querySnapshot.episodes === false) {
50
+ const { episodes: _grain, ...filters } = querySnapshot;
51
+ return client.listSignalsRawAlerts({ ...filters, ...at });
52
+ }
53
+ const { episodes: _grain, ...filters } = querySnapshot;
54
+ return client.listSignalsAlerts({ ...filters, ...at });
55
+ }, [client, querySnapshot]);
56
+ const [items, setItems] = React.useState([]);
57
+ const [nextCursor, setNextCursor] = React.useState(null);
58
+ const [loading, setLoading] = React.useState(true);
59
+ const [error, setError] = React.useState();
60
+ const [revision, setRevision] = React.useState(0);
61
+ const generation = React.useRef(0);
62
+ const loadingRef = React.useRef(false);
63
+ React.useEffect(() => {
64
+ const requestGeneration = generation.current + 1;
65
+ generation.current = requestGeneration;
66
+ loadingRef.current = true;
67
+ setItems([]);
68
+ setNextCursor(null);
69
+ setError(undefined);
70
+ setLoading(true);
71
+ listPage()
72
+ .then((page) => {
73
+ if (generation.current === requestGeneration) {
74
+ setItems(page.items);
75
+ setNextCursor(page.nextCursor);
76
+ }
77
+ })
78
+ .catch((reason) => {
79
+ if (generation.current === requestGeneration) {
80
+ setError(toError(reason));
81
+ }
82
+ })
83
+ .finally(() => {
84
+ if (generation.current === requestGeneration) {
85
+ loadingRef.current = false;
86
+ setLoading(false);
87
+ }
88
+ });
89
+ return () => {
90
+ generation.current += 1;
91
+ };
92
+ }, [listPage, revision]);
93
+ const loadMore = React.useCallback(async () => {
94
+ if (nextCursor === null || loadingRef.current) {
95
+ return;
96
+ }
97
+ const requestGeneration = generation.current;
98
+ loadingRef.current = true;
99
+ setLoading(true);
100
+ setError(undefined);
101
+ try {
102
+ const page = await listPage(nextCursor);
103
+ if (generation.current === requestGeneration) {
104
+ setItems((current) => [...current, ...page.items]);
105
+ setNextCursor(page.nextCursor);
106
+ }
107
+ }
108
+ catch (reason) {
109
+ if (generation.current === requestGeneration) {
110
+ setError(toError(reason));
111
+ }
112
+ }
113
+ finally {
114
+ if (generation.current === requestGeneration) {
115
+ loadingRef.current = false;
116
+ setLoading(false);
117
+ }
118
+ }
119
+ }, [listPage, nextCursor]);
120
+ const reload = React.useCallback(() => {
121
+ setRevision((current) => current + 1);
122
+ }, []);
123
+ return {
124
+ items,
125
+ loading,
126
+ error,
127
+ reload,
128
+ hasMore: nextCursor !== null,
129
+ loadMore,
130
+ };
131
+ }
132
+ function useSignalsAlert(id, grain = {}) {
133
+ const client = (0, index_1.useClient)();
134
+ const episodes = grain.episodes !== false;
135
+ const load = React.useCallback(() => episodes
136
+ ? client.getSignalsAlert(id)
137
+ : client.getSignalsRawAlert(id), [client, id, episodes]);
138
+ return (0, api_hooks_1.useOvokRequest)(load, id !== undefined);
139
+ }
140
+ function useAcknowledgeSignalsAlert(grain = {}) {
141
+ const episodes = grain.episodes !== false;
142
+ return (0, api_hooks_1.useOvokMutation)((client, id) => episodes
143
+ ? client.acknowledgeSignalsAlert(id)
144
+ : client.acknowledgeSignalsRawAlert(id));
145
+ }
146
+ const toError = (error) => error instanceof Error ? error : new Error(String(error));
@@ -1,5 +1,7 @@
1
- import { EnableSignalsResponse, SetSignalsThresholdBody, SignalsAlert, SignalsAlertsQuery, SignalsSettingsPatch, SignalsSettingsResponse, SignalsThreshold, SignalsThresholds } from "../client/signals";
1
+ import { EnableSignalsResponse, SetSignalsThresholdBody, SignalsSettingsPatch, SignalsSettingsResponse, SignalsThreshold, SignalsThresholds } from "../client/signals";
2
2
  import { OvokMutationState, OvokRequestState } from "./api-hooks";
3
+ export { useAcknowledgeSignalsAlert, useSignalsAlert, useSignalsAlerts, } from "./signals-alert-hooks";
4
+ export type { SignalsAlertGrain, SignalsAlertsHookState } from "./signals-alert-hooks";
3
5
  type SetSignalsThresholdParams = {
4
6
  patientId: string;
5
7
  code: string;
@@ -14,22 +16,9 @@ type UpdateSignalsSettingsParams = {
14
16
  patch: SignalsSettingsPatch;
15
17
  reason?: string | null;
16
18
  };
17
- type SignalsAlertsHookQuery = Omit<SignalsAlertsQuery, "cursor">;
18
- export type SignalsAlertsHookState = {
19
- items: SignalsAlert[];
20
- loading: boolean;
21
- error: Error | undefined;
22
- reload: () => void;
23
- hasMore: boolean;
24
- loadMore: () => Promise<void>;
25
- };
26
19
  export declare const useEnableSignalsForPatient: () => OvokMutationState<string, EnableSignalsResponse>;
27
20
  export declare const useSignalsThresholds: (patientId?: string) => OvokRequestState<SignalsThresholds>;
28
21
  export declare const useSetSignalsThreshold: () => OvokMutationState<SetSignalsThresholdParams, SignalsThreshold>;
29
22
  export declare const useRemoveSignalsThreshold: () => OvokMutationState<RemoveSignalsThresholdParams, void>;
30
- export declare const useSignalsAlerts: (query?: SignalsAlertsHookQuery) => SignalsAlertsHookState;
31
- export declare const useSignalsAlert: (episodeId?: string) => OvokRequestState<SignalsAlert>;
32
- export declare const useAcknowledgeSignalsAlert: () => OvokMutationState<string, SignalsAlert>;
33
23
  export declare const useSignalsSettings: () => OvokRequestState<SignalsSettingsResponse>;
34
24
  export declare const useUpdateSignalsSettings: () => OvokMutationState<UpdateSignalsSettingsParams, SignalsSettingsResponse>;
35
- export {};
@@ -34,10 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.useUpdateSignalsSettings = exports.useSignalsSettings = exports.useAcknowledgeSignalsAlert = exports.useSignalsAlert = exports.useSignalsAlerts = exports.useRemoveSignalsThreshold = exports.useSetSignalsThreshold = exports.useSignalsThresholds = exports.useEnableSignalsForPatient = void 0;
37
+ exports.useUpdateSignalsSettings = exports.useSignalsSettings = exports.useRemoveSignalsThreshold = exports.useSetSignalsThreshold = exports.useSignalsThresholds = exports.useEnableSignalsForPatient = exports.useSignalsAlerts = exports.useSignalsAlert = exports.useAcknowledgeSignalsAlert = void 0;
38
38
  const React = __importStar(require("react"));
39
39
  const api_hooks_1 = require("./api-hooks");
40
40
  const index_1 = require("./index");
41
+ var signals_alert_hooks_1 = require("./signals-alert-hooks");
42
+ Object.defineProperty(exports, "useAcknowledgeSignalsAlert", { enumerable: true, get: function () { return signals_alert_hooks_1.useAcknowledgeSignalsAlert; } });
43
+ Object.defineProperty(exports, "useSignalsAlert", { enumerable: true, get: function () { return signals_alert_hooks_1.useSignalsAlert; } });
44
+ Object.defineProperty(exports, "useSignalsAlerts", { enumerable: true, get: function () { return signals_alert_hooks_1.useSignalsAlerts; } });
41
45
  const useEnableSignalsForPatient = () => (0, api_hooks_1.useOvokMutation)((client, patientId) => client.enableSignalsForPatient(patientId));
42
46
  exports.useEnableSignalsForPatient = useEnableSignalsForPatient;
43
47
  const useSignalsThresholds = (patientId) => {
@@ -50,99 +54,6 @@ const useSetSignalsThreshold = () => (0, api_hooks_1.useOvokMutation)((client, p
50
54
  exports.useSetSignalsThreshold = useSetSignalsThreshold;
51
55
  const useRemoveSignalsThreshold = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.removeSignalsThreshold(params.patientId, params.code, params.reason));
52
56
  exports.useRemoveSignalsThreshold = useRemoveSignalsThreshold;
53
- const useSignalsAlerts = (query = {}) => {
54
- const client = (0, index_1.useClient)();
55
- const queryKey = JSON.stringify(query);
56
- const querySnapshot = React.useMemo(() => JSON.parse(queryKey), [queryKey]);
57
- const [items, setItems] = React.useState([]);
58
- const [nextCursor, setNextCursor] = React.useState(null);
59
- const [loading, setLoading] = React.useState(true);
60
- const [error, setError] = React.useState();
61
- const [revision, setRevision] = React.useState(0);
62
- const generation = React.useRef(0);
63
- const loadingRef = React.useRef(false);
64
- React.useEffect(() => {
65
- const requestGeneration = generation.current + 1;
66
- generation.current = requestGeneration;
67
- loadingRef.current = true;
68
- setItems([]);
69
- setNextCursor(null);
70
- setError(undefined);
71
- setLoading(true);
72
- client
73
- .listSignalsAlerts(querySnapshot)
74
- .then((page) => {
75
- if (generation.current === requestGeneration) {
76
- setItems(page.items);
77
- setNextCursor(page.nextCursor);
78
- }
79
- })
80
- .catch((reason) => {
81
- if (generation.current === requestGeneration) {
82
- setError(toError(reason));
83
- }
84
- })
85
- .finally(() => {
86
- if (generation.current === requestGeneration) {
87
- loadingRef.current = false;
88
- setLoading(false);
89
- }
90
- });
91
- return () => {
92
- generation.current += 1;
93
- };
94
- }, [client, queryKey, querySnapshot, revision]);
95
- const loadMore = React.useCallback(async () => {
96
- if (nextCursor === null || loadingRef.current) {
97
- return;
98
- }
99
- const requestGeneration = generation.current;
100
- loadingRef.current = true;
101
- setLoading(true);
102
- setError(undefined);
103
- try {
104
- const page = await client.listSignalsAlerts({
105
- ...querySnapshot,
106
- cursor: nextCursor,
107
- });
108
- if (generation.current === requestGeneration) {
109
- setItems((current) => [...current, ...page.items]);
110
- setNextCursor(page.nextCursor);
111
- }
112
- }
113
- catch (reason) {
114
- if (generation.current === requestGeneration) {
115
- setError(toError(reason));
116
- }
117
- }
118
- finally {
119
- if (generation.current === requestGeneration) {
120
- loadingRef.current = false;
121
- setLoading(false);
122
- }
123
- }
124
- }, [client, nextCursor, querySnapshot]);
125
- const reload = React.useCallback(() => {
126
- setRevision((current) => current + 1);
127
- }, []);
128
- return {
129
- items,
130
- loading,
131
- error,
132
- reload,
133
- hasMore: nextCursor !== null,
134
- loadMore,
135
- };
136
- };
137
- exports.useSignalsAlerts = useSignalsAlerts;
138
- const useSignalsAlert = (episodeId) => {
139
- const client = (0, index_1.useClient)();
140
- const load = React.useCallback(() => client.getSignalsAlert(episodeId), [client, episodeId]);
141
- return (0, api_hooks_1.useOvokRequest)(load, episodeId !== undefined);
142
- };
143
- exports.useSignalsAlert = useSignalsAlert;
144
- const useAcknowledgeSignalsAlert = () => (0, api_hooks_1.useOvokMutation)((client, episodeId) => client.acknowledgeSignalsAlert(episodeId));
145
- exports.useAcknowledgeSignalsAlert = useAcknowledgeSignalsAlert;
146
57
  const useSignalsSettings = () => {
147
58
  const client = (0, index_1.useClient)();
148
59
  const load = React.useCallback(() => client.getSignalsSettings(), [client]);
@@ -151,4 +62,3 @@ const useSignalsSettings = () => {
151
62
  exports.useSignalsSettings = useSignalsSettings;
152
63
  const useUpdateSignalsSettings = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.updateSignalsSettings(params.patch, params.reason));
153
64
  exports.useUpdateSignalsSettings = useUpdateSignalsSettings;
154
- const toError = (error) => error instanceof Error ? error : new Error(String(error));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",