@ovok/core 0.3.7 → 0.3.8

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
@@ -89,6 +89,24 @@ const alerts = await client.listCarehubMedicalNotifications({ count: 25 });
89
89
  CareHub is intentionally represented as typed application APIs rather than changing the FHIR
90
90
  observation save/offline behavior used by native integrations.
91
91
 
92
+ ## React hooks
93
+
94
+ The package exports additive hooks for capability discovery, project configuration, CareHub lists,
95
+ telemetry, and notifications. Every request hook returns `data`, `loading`, `error`, and `reload`.
96
+
97
+ ```tsx
98
+ const { data: patients, loading, error } = useCarehubPatients({
99
+ residentState: "active",
100
+ });
101
+
102
+ const saveSettings = useOvokMutation((client, settings: OvokProjectSettings) =>
103
+ client.updateProjectSetting("PATIENT_LOGIN_ENABLED", settings.settings.PATIENT_LOGIN_ENABLED),
104
+ );
105
+ ```
106
+
107
+ Hooks are additive to the existing `OvokProvider`, observation hooks, auth methods, and offline
108
+ queue. Billing remains outside the SDK contract.
109
+
92
110
  ## Offline measurements
93
111
 
94
112
  Pass a durable Medplum storage adapter and opt in to queue measurements while offline:
@@ -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.3.6",
51
+ version: "0.3.7",
52
52
  },
53
53
  fhirVersion: "4.0.1",
54
54
  format: ["json"],
@@ -0,0 +1,39 @@
1
+ import { CapabilityStatement } from "@medplum/fhirtypes";
2
+ import { CarehubDeviceListItem, CarehubDeviceListQuery, CarehubDeviceTelemetry, CarehubNotificationsQuery, CarehubNotificationsResponse, CarehubPage, CarehubPatientListItem, CarehubPatientListQuery, CarehubRecentNotificationsResponse } from "../client/carehub/types";
3
+ import { OvokClient, OvokFhirVersion } from "../client/ovok-client";
4
+ import { OvokAdministeredProject, OvokProjectFeatures, OvokProjectSettings } from "../client/platform/types";
5
+ import { OvokPublicApiEndpoint } from "../conformance/capability";
6
+ export type OvokRequestState<T> = {
7
+ data: T | undefined;
8
+ loading: boolean;
9
+ error: Error | undefined;
10
+ reload: () => void;
11
+ };
12
+ export type OvokMutationState<TParams, TData> = {
13
+ data: TData | undefined;
14
+ loading: boolean;
15
+ error: Error | undefined;
16
+ mutate: (params: TParams) => Promise<TData>;
17
+ reset: () => void;
18
+ };
19
+ /**
20
+ * Small request primitive for the typed Ovok hooks. It deliberately does not
21
+ * add a cache or retry policy: MedplumClient already owns request caching and
22
+ * the host app owns the retry policy appropriate to its screen.
23
+ */
24
+ export declare function useOvokRequest<T>(load: () => Promise<T>, enabled?: boolean): OvokRequestState<T>;
25
+ /** Generic mutation hook for any typed OvokClient method. */
26
+ export declare function useOvokMutation<TParams, TData>(mutateRequest: (client: OvokClient, params: TParams) => Promise<TData>): OvokMutationState<TParams, TData>;
27
+ export declare const useCapabilityStatement: (version?: OvokFhirVersion) => OvokRequestState<CapabilityStatement>;
28
+ export declare const usePublicApiEndpoints: (version?: OvokFhirVersion) => OvokRequestState<OvokPublicApiEndpoint[]>;
29
+ export declare const useAdministeredProjects: (params?: {
30
+ page?: number;
31
+ count?: number;
32
+ }) => OvokRequestState<CarehubPage<OvokAdministeredProject>>;
33
+ export declare const useProjectSettings: () => OvokRequestState<OvokProjectSettings>;
34
+ export declare const useProjectFeatures: () => OvokRequestState<OvokProjectFeatures>;
35
+ export declare const useCarehubPatients: (params?: CarehubPatientListQuery) => OvokRequestState<CarehubPage<CarehubPatientListItem>>;
36
+ export declare const useCarehubDevices: (params?: CarehubDeviceListQuery) => OvokRequestState<CarehubPage<CarehubDeviceListItem>>;
37
+ export declare const useCarehubDeviceTelemetry: (deviceId?: string) => OvokRequestState<CarehubDeviceTelemetry>;
38
+ export declare const useCarehubNotifications: (params?: CarehubNotificationsQuery) => OvokRequestState<CarehubNotificationsResponse>;
39
+ export declare const useRecentCarehubNotifications: (count?: number) => OvokRequestState<CarehubRecentNotificationsResponse>;
@@ -0,0 +1,179 @@
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.useRecentCarehubNotifications = exports.useCarehubNotifications = exports.useCarehubDeviceTelemetry = exports.useCarehubDevices = exports.useCarehubPatients = exports.useProjectFeatures = exports.useProjectSettings = exports.useAdministeredProjects = exports.usePublicApiEndpoints = exports.useCapabilityStatement = void 0;
38
+ exports.useOvokRequest = useOvokRequest;
39
+ exports.useOvokMutation = useOvokMutation;
40
+ const React = __importStar(require("react"));
41
+ const index_1 = require("./index");
42
+ const toError = (error) => error instanceof Error ? error : new Error(String(error));
43
+ /**
44
+ * Small request primitive for the typed Ovok hooks. It deliberately does not
45
+ * add a cache or retry policy: MedplumClient already owns request caching and
46
+ * the host app owns the retry policy appropriate to its screen.
47
+ */
48
+ function useOvokRequest(load, enabled = true) {
49
+ const [data, setData] = React.useState();
50
+ const [error, setError] = React.useState();
51
+ const [loading, setLoading] = React.useState(enabled);
52
+ const [revision, setRevision] = React.useState(0);
53
+ React.useEffect(() => {
54
+ let disposed = false;
55
+ if (!enabled) {
56
+ setLoading(false);
57
+ setError(undefined);
58
+ return () => {
59
+ disposed = true;
60
+ };
61
+ }
62
+ setLoading(true);
63
+ setError(undefined);
64
+ load()
65
+ .then((value) => {
66
+ if (!disposed) {
67
+ setData(value);
68
+ setLoading(false);
69
+ }
70
+ })
71
+ .catch((reason) => {
72
+ if (!disposed) {
73
+ setError(toError(reason));
74
+ setLoading(false);
75
+ }
76
+ });
77
+ return () => {
78
+ disposed = true;
79
+ };
80
+ }, [enabled, load, revision]);
81
+ const reload = React.useCallback(() => setRevision((value) => value + 1), []);
82
+ return { data, loading, error, reload };
83
+ }
84
+ /** Generic mutation hook for any typed OvokClient method. */
85
+ function useOvokMutation(mutateRequest) {
86
+ const client = (0, index_1.useClient)();
87
+ const [data, setData] = React.useState();
88
+ const [error, setError] = React.useState();
89
+ const [loading, setLoading] = React.useState(false);
90
+ const mutate = React.useCallback(async (params) => {
91
+ setLoading(true);
92
+ setError(undefined);
93
+ try {
94
+ const value = await mutateRequest(client, params);
95
+ setData(value);
96
+ return value;
97
+ }
98
+ catch (reason) {
99
+ const requestError = toError(reason);
100
+ setError(requestError);
101
+ throw requestError;
102
+ }
103
+ finally {
104
+ setLoading(false);
105
+ }
106
+ }, [client, mutateRequest]);
107
+ const reset = React.useCallback(() => {
108
+ setData(undefined);
109
+ setError(undefined);
110
+ setLoading(false);
111
+ }, []);
112
+ return { data, loading, error, mutate, reset };
113
+ }
114
+ const useCapabilityStatement = (version = "R4") => {
115
+ const client = (0, index_1.useClient)();
116
+ const load = React.useCallback(() => client.getCapabilityStatement(version), [client, version]);
117
+ return useOvokRequest(load);
118
+ };
119
+ exports.useCapabilityStatement = useCapabilityStatement;
120
+ const usePublicApiEndpoints = (version = "R4") => {
121
+ const client = (0, index_1.useClient)();
122
+ const load = React.useCallback(() => client.getPublicApiEndpoints(version), [client, version]);
123
+ return useOvokRequest(load);
124
+ };
125
+ exports.usePublicApiEndpoints = usePublicApiEndpoints;
126
+ const useAdministeredProjects = (params = {}) => {
127
+ const client = (0, index_1.useClient)();
128
+ const serialized = JSON.stringify(params);
129
+ const load = React.useCallback(() => client.listAdministeredProjects(params), [client, serialized]);
130
+ return useOvokRequest(load);
131
+ };
132
+ exports.useAdministeredProjects = useAdministeredProjects;
133
+ const useProjectSettings = () => {
134
+ const client = (0, index_1.useClient)();
135
+ const load = React.useCallback(() => client.getProjectSettings(), [client]);
136
+ return useOvokRequest(load);
137
+ };
138
+ exports.useProjectSettings = useProjectSettings;
139
+ const useProjectFeatures = () => {
140
+ const client = (0, index_1.useClient)();
141
+ const load = React.useCallback(() => client.getProjectFeatures(), [client]);
142
+ return useOvokRequest(load);
143
+ };
144
+ exports.useProjectFeatures = useProjectFeatures;
145
+ const useCarehubPatients = (params = {}) => {
146
+ const client = (0, index_1.useClient)();
147
+ const serialized = JSON.stringify(params);
148
+ const load = React.useCallback(() => client.listCarehubPatients(params), [client, serialized]);
149
+ return useOvokRequest(load);
150
+ };
151
+ exports.useCarehubPatients = useCarehubPatients;
152
+ const useCarehubDevices = (params = {}) => {
153
+ const client = (0, index_1.useClient)();
154
+ const serialized = JSON.stringify(params);
155
+ const load = React.useCallback(() => client.listCarehubDevices(params), [client, serialized]);
156
+ return useOvokRequest(load);
157
+ };
158
+ exports.useCarehubDevices = useCarehubDevices;
159
+ const useCarehubDeviceTelemetry = (deviceId) => {
160
+ const client = (0, index_1.useClient)();
161
+ const load = React.useCallback(() => deviceId
162
+ ? client.getCarehubDeviceTelemetry(deviceId)
163
+ : Promise.reject(new Error("deviceId is required")), [client, deviceId]);
164
+ return useOvokRequest(load, deviceId !== undefined);
165
+ };
166
+ exports.useCarehubDeviceTelemetry = useCarehubDeviceTelemetry;
167
+ const useCarehubNotifications = (params = {}) => {
168
+ const client = (0, index_1.useClient)();
169
+ const serialized = JSON.stringify(params);
170
+ const load = React.useCallback(() => client.listCarehubNotifications(params), [client, serialized]);
171
+ return useOvokRequest(load);
172
+ };
173
+ exports.useCarehubNotifications = useCarehubNotifications;
174
+ const useRecentCarehubNotifications = (count) => {
175
+ const client = (0, index_1.useClient)();
176
+ const load = React.useCallback(() => client.getRecentCarehubNotifications(count), [client, count]);
177
+ return useOvokRequest(load);
178
+ };
179
+ exports.useRecentCarehubNotifications = useRecentCarehubNotifications;
@@ -6,3 +6,4 @@ export declare const OvokProvider: (props: React.PropsWithChildren<{
6
6
  client: OvokClient;
7
7
  }>) => React.JSX.Element;
8
8
  export { observationsToMeasurements, useEcgRecording, useObservations, useSaveMeasurement, useUrineTests, } from "./observation-hooks";
9
+ export { useAdministeredProjects, useCarehubDeviceTelemetry, useCarehubDevices, useCarehubNotifications, useCarehubPatients, useCapabilityStatement, useOvokMutation, useOvokRequest, useProjectFeatures, useProjectSettings, usePublicApiEndpoints, useRecentCarehubNotifications, } from "./api-hooks";
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.useUrineTests = exports.useSaveMeasurement = exports.useObservations = exports.useEcgRecording = exports.observationsToMeasurements = exports.OvokProvider = exports.useClient = exports.useCachedBinaryUrl = exports.reactContext = exports.useSubscription = exports.useSearchResources = exports.useSearchOne = exports.useSearch = exports.useResource = exports.usePrevious = exports.useMedplumProfile = exports.useMedplumNavigate = exports.useMedplumContext = void 0;
37
+ exports.useRecentCarehubNotifications = exports.usePublicApiEndpoints = exports.useProjectSettings = exports.useProjectFeatures = exports.useOvokRequest = exports.useOvokMutation = exports.useCapabilityStatement = exports.useCarehubPatients = exports.useCarehubNotifications = exports.useCarehubDevices = exports.useCarehubDeviceTelemetry = exports.useAdministeredProjects = exports.useUrineTests = exports.useSaveMeasurement = exports.useObservations = exports.useEcgRecording = exports.observationsToMeasurements = exports.OvokProvider = exports.useClient = exports.useCachedBinaryUrl = exports.reactContext = exports.useSubscription = exports.useSearchResources = exports.useSearchOne = exports.useSearch = exports.useResource = exports.usePrevious = exports.useMedplumProfile = exports.useMedplumNavigate = exports.useMedplumContext = void 0;
38
38
  /*
39
39
  * The only React-dependent module in the package.
40
40
  *
@@ -76,3 +76,16 @@ Object.defineProperty(exports, "useEcgRecording", { enumerable: true, get: funct
76
76
  Object.defineProperty(exports, "useObservations", { enumerable: true, get: function () { return observation_hooks_1.useObservations; } });
77
77
  Object.defineProperty(exports, "useSaveMeasurement", { enumerable: true, get: function () { return observation_hooks_1.useSaveMeasurement; } });
78
78
  Object.defineProperty(exports, "useUrineTests", { enumerable: true, get: function () { return observation_hooks_1.useUrineTests; } });
79
+ var api_hooks_1 = require("./api-hooks");
80
+ Object.defineProperty(exports, "useAdministeredProjects", { enumerable: true, get: function () { return api_hooks_1.useAdministeredProjects; } });
81
+ Object.defineProperty(exports, "useCarehubDeviceTelemetry", { enumerable: true, get: function () { return api_hooks_1.useCarehubDeviceTelemetry; } });
82
+ Object.defineProperty(exports, "useCarehubDevices", { enumerable: true, get: function () { return api_hooks_1.useCarehubDevices; } });
83
+ Object.defineProperty(exports, "useCarehubNotifications", { enumerable: true, get: function () { return api_hooks_1.useCarehubNotifications; } });
84
+ Object.defineProperty(exports, "useCarehubPatients", { enumerable: true, get: function () { return api_hooks_1.useCarehubPatients; } });
85
+ Object.defineProperty(exports, "useCapabilityStatement", { enumerable: true, get: function () { return api_hooks_1.useCapabilityStatement; } });
86
+ Object.defineProperty(exports, "useOvokMutation", { enumerable: true, get: function () { return api_hooks_1.useOvokMutation; } });
87
+ Object.defineProperty(exports, "useOvokRequest", { enumerable: true, get: function () { return api_hooks_1.useOvokRequest; } });
88
+ Object.defineProperty(exports, "useProjectFeatures", { enumerable: true, get: function () { return api_hooks_1.useProjectFeatures; } });
89
+ Object.defineProperty(exports, "useProjectSettings", { enumerable: true, get: function () { return api_hooks_1.useProjectSettings; } });
90
+ Object.defineProperty(exports, "usePublicApiEndpoints", { enumerable: true, get: function () { return api_hooks_1.usePublicApiEndpoints; } });
91
+ Object.defineProperty(exports, "useRecentCarehubNotifications", { enumerable: true, get: function () { return api_hooks_1.useRecentCarehubNotifications; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",