@ovok/core 0.4.36 → 0.4.38

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.
Files changed (127) hide show
  1. package/dist/client/auth/account-storage.d.ts +1 -0
  2. package/dist/client/auth/account-storage.js +2 -1
  3. package/dist/{utils → client}/auth/exchange-code.d.ts +1 -1
  4. package/dist/{utils → client}/auth/generate-code-challenge-and-verifier.js +5 -17
  5. package/dist/{utils → client}/auth/handle-tenant-code.d.ts +1 -1
  6. package/dist/{utils → client}/auth/handle-tenant-code.js +1 -1
  7. package/dist/client/auth/methods/appleLogin.js +2 -6
  8. package/dist/client/auth/methods/changePassword.js +2 -1
  9. package/dist/client/auth/methods/getSessions.js +2 -1
  10. package/dist/client/auth/methods/googleLogin.js +2 -6
  11. package/dist/client/auth/methods/login.js +26 -44
  12. package/dist/client/auth/methods/logout.js +2 -1
  13. package/dist/client/auth/methods/requestDeleteUser.js +5 -4
  14. package/dist/client/auth/methods/revokeSessions.js +2 -1
  15. package/dist/client/auth/methods/socialLogin.d.ts +7 -0
  16. package/dist/client/auth/methods/socialLogin.js +11 -0
  17. package/dist/client/auth/session-fetch.d.ts +35 -0
  18. package/dist/client/auth/session-fetch.js +206 -0
  19. package/dist/client/auth/session-http.d.ts +11 -0
  20. package/dist/client/auth/session-http.js +169 -0
  21. package/dist/client/auth/sha256.d.ts +2 -0
  22. package/dist/client/auth/sha256.js +65 -0
  23. package/dist/{utils → client}/auth/start-login.d.ts +2 -2
  24. package/dist/client/change-history/methods.js +2 -1
  25. package/dist/client/cms/methods.js +16 -28
  26. package/dist/client/consent/methods.js +3 -2
  27. package/dist/client/email/methods.js +2 -1
  28. package/dist/client/errors/ovok-error-utils.d.ts +6 -0
  29. package/dist/client/errors/ovok-error-utils.js +10 -1
  30. package/dist/client/errors/ovok-error.js +6 -13
  31. package/dist/client/errors/rate-limit-error.js +2 -6
  32. package/dist/client/experience/methods.js +28 -37
  33. package/dist/client/invites/methods.js +8 -12
  34. package/dist/client/notifications/methods.js +5 -5
  35. package/dist/client/observation/fhir-systems.d.ts +4 -0
  36. package/dist/client/observation/fhir-systems.js +7 -0
  37. package/dist/client/observation/methods/generateObservationBodiesByMeasurement.js +23 -29
  38. package/dist/client/observation/methods/getLatestObservationsByCodes.js +6 -9
  39. package/dist/client/observation/methods/observationsToMeasurements.js +44 -91
  40. package/dist/client/observation/services/base-observation-service.js +4 -3
  41. package/dist/client/observation/services/blood-pressure.js +1 -4
  42. package/dist/client/observation/services/{baby-sleep.d.ts → component-observation-services.d.ts} +18 -13
  43. package/dist/client/observation/services/component-observation-services.js +69 -0
  44. package/dist/client/observation/services/creator.d.ts +1 -2
  45. package/dist/client/observation/services/creator.js +15 -33
  46. package/dist/client/observation/services/ecg-observation-fragments.js +5 -6
  47. package/dist/client/observation/services/ecg.js +3 -2
  48. package/dist/client/observation/services/lipid-panel.js +8 -12
  49. package/dist/client/observation/services/measurement-time.d.ts +4 -0
  50. package/dist/client/observation/services/measurement-time.js +6 -0
  51. package/dist/client/observation/services/single-value-services.d.ts +36 -0
  52. package/dist/client/observation/services/single-value-services.js +100 -0
  53. package/dist/client/observation/services/uric-acid-service.js +6 -7
  54. package/dist/client/observation/types/generate-measurement/HealthConnectTypes.d.ts +2 -458
  55. package/dist/client/observation/types/generate-measurement/HealthConnectTypes.js +0 -6
  56. package/dist/client/offline/offline-measurement-queue.js +31 -28
  57. package/dist/client/ovok-client.d.ts +7 -15
  58. package/dist/client/ovok-client.js +54 -398
  59. package/dist/client/patient/methods.js +27 -36
  60. package/dist/client/patient-sharing/methods.js +4 -4
  61. package/dist/client/platform/methods.js +21 -30
  62. package/dist/client/platform/types.d.ts +3 -6
  63. package/dist/client/query-string.d.ts +3 -0
  64. package/dist/client/query-string.js +15 -0
  65. package/dist/client/questionnaire-response/methods/createQuestionnaireResponseWithObservations.js +2 -1
  66. package/dist/client/questionnaire-response/methods/extractQuestionnaireObservations.js +1 -2
  67. package/dist/client/questionnaire-response/methods/populateQuestionnaire.js +1 -2
  68. package/dist/client/questionnaire-response/methods/submitQuestionnaireResponse.js +2 -1
  69. package/dist/client/request-options.d.ts +2 -0
  70. package/dist/client/request-options.js +6 -0
  71. package/dist/client/signals/errors.js +2 -6
  72. package/dist/client/signals/methods.js +22 -22
  73. package/dist/client/slim/live-read.d.ts +4 -0
  74. package/dist/client/slim/live-read.js +87 -0
  75. package/dist/client/slim/methods.d.ts +3 -0
  76. package/dist/client/slim/methods.js +73 -166
  77. package/dist/client/storage.js +3 -2
  78. package/dist/conformance/capability-requirements.js +1 -1
  79. package/dist/conformance/capability.js +8 -7
  80. package/dist/hooks/account-hooks.js +6 -68
  81. package/dist/hooks/api-hooks.d.ts +10 -6
  82. package/dist/hooks/api-hooks.js +29 -88
  83. package/dist/hooks/cms-hooks.js +8 -13
  84. package/dist/hooks/email-hooks.js +1 -40
  85. package/dist/hooks/experience-hooks.js +4 -60
  86. package/dist/hooks/index.d.ts +2 -2
  87. package/dist/hooks/index.js +4 -4
  88. package/dist/hooks/invites-hooks.js +0 -1
  89. package/dist/hooks/notification-hooks.d.ts +4 -1
  90. package/dist/hooks/notification-hooks.js +29 -86
  91. package/dist/hooks/notification-invalidation.d.ts +6 -0
  92. package/dist/hooks/notification-invalidation.js +52 -0
  93. package/dist/hooks/notification-note-hooks.js +13 -28
  94. package/dist/hooks/observation-hooks.js +2 -4
  95. package/dist/hooks/patient-hooks.js +13 -113
  96. package/dist/hooks/patient-sharing-hooks.js +2 -7
  97. package/dist/hooks/platform-hooks.js +3 -51
  98. package/dist/hooks/poll-hooks.js +10 -8
  99. package/dist/hooks/signals-alert-hooks.js +4 -6
  100. package/dist/hooks/signals-hooks.js +2 -45
  101. package/package.json +1 -1
  102. package/dist/client/observation/services/baby-sleep.js +0 -69
  103. package/dist/client/observation/services/blood-glucose.d.ts +0 -12
  104. package/dist/client/observation/services/blood-glucose.js +0 -36
  105. package/dist/client/observation/services/body-temperature.d.ts +0 -13
  106. package/dist/client/observation/services/body-temperature.js +0 -36
  107. package/dist/client/observation/services/body-weight.d.ts +0 -13
  108. package/dist/client/observation/services/body-weight.js +0 -36
  109. package/dist/client/observation/services/heart-rate-variability.d.ts +0 -13
  110. package/dist/client/observation/services/heart-rate-variability.js +0 -38
  111. package/dist/client/observation/services/heart-rate.d.ts +0 -13
  112. package/dist/client/observation/services/heart-rate.js +0 -39
  113. package/dist/client/observation/services/respiratory-rate.d.ts +0 -13
  114. package/dist/client/observation/services/respiratory-rate.js +0 -38
  115. package/dist/client/observation/services/respiratory-therapy.d.ts +0 -28
  116. package/dist/client/observation/services/respiratory-therapy.js +0 -69
  117. package/dist/client/observation/services/resting-heart-rate.d.ts +0 -13
  118. package/dist/client/observation/services/resting-heart-rate.js +0 -38
  119. package/dist/client/observation/services/vo2-max.d.ts +0 -13
  120. package/dist/client/observation/services/vo2-max.js +0 -38
  121. package/dist/client/observation/services/walking-heart-rate-average.d.ts +0 -12
  122. package/dist/client/observation/services/walking-heart-rate-average.js +0 -38
  123. package/dist/utils/auth/sha256.d.ts +0 -8
  124. package/dist/utils/auth/sha256.js +0 -300
  125. /package/dist/{utils → client}/auth/exchange-code.js +0 -0
  126. /package/dist/{utils → client}/auth/generate-code-challenge-and-verifier.d.ts +0 -0
  127. /package/dist/{utils → client}/auth/start-login.js +0 -0
@@ -1,8 +1,43 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.subscribeToNotificationChanges = subscribeToNotificationChanges;
4
37
  exports.notifyNotificationChanges = notifyNotificationChanges;
5
38
  exports.mergeSlimNotification = mergeSlimNotification;
39
+ exports.useSlimNotificationSync = useSlimNotificationSync;
40
+ const React = __importStar(require("react"));
6
41
  const listeners = new WeakMap();
7
42
  function subscribeToNotificationChanges(client, listener) {
8
43
  var _a;
@@ -35,3 +70,20 @@ function mergeSlimNotification(item, notification) {
35
70
  ? { ...item, ...notification }
36
71
  : item;
37
72
  }
73
+ /**
74
+ * Keeps a mounted Slim notification list current: a full invalidation reloads it, a single
75
+ * Slim change is merged into the matching rows of `field`.
76
+ */
77
+ function useSlimNotificationSync(client, reload, updateData, field) {
78
+ React.useEffect(() => subscribeToNotificationChanges(client, (change) => {
79
+ if (!change) {
80
+ reload();
81
+ }
82
+ else if (change.type === "slim") {
83
+ updateData((current) => current && {
84
+ ...current,
85
+ [field]: current[field].map((item) => mergeSlimNotification(item, change.notification)),
86
+ });
87
+ }
88
+ }), [client, reload, updateData, field]);
89
+ }
@@ -39,18 +39,23 @@ const React = __importStar(require("react"));
39
39
  const api_hooks_1 = require("./api-hooks");
40
40
  const notification_invalidation_1 = require("./notification-invalidation");
41
41
  const index_1 = require("./index");
42
- const useNotificationNotes = (kind, id) => {
42
+ /**
43
+ * A note list that reloads on a full notification invalidation. The revision is part of the
44
+ * loader on purpose: a new loader clears the mounted notes before the reload.
45
+ */
46
+ function useNoteList(id, idName, request, scope) {
43
47
  const client = (0, index_1.useClient)();
44
48
  const [revision, setRevision] = React.useState(0);
45
- const load = React.useCallback((signal) => (id ? client.listNotificationNotes(kind, id, { signal }) : Promise.reject(new Error("id is required"))), [client, kind, id, revision]);
46
- const state = (0, api_hooks_1.useOvokRequest)(load, id !== undefined);
49
+ // `request` is rebuilt every render; `scope` and `id` are everything it depends on.
50
+ const load = React.useCallback((signal) => (id ? request(client, id, signal) : Promise.reject(new Error(`${idName} is required`))), [client, scope, id, revision]);
47
51
  React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
48
52
  if (!change) {
49
53
  setRevision((value) => value + 1);
50
54
  }
51
- }), [client, kind, id]);
52
- return state;
53
- };
55
+ }), [client, scope, id]);
56
+ return (0, api_hooks_1.useOvokRequest)(load, id !== undefined);
57
+ }
58
+ const useNotificationNotes = (kind, id) => useNoteList(id, "id", (client, noteId, signal) => client.listNotificationNotes(kind, noteId, { signal }), kind);
54
59
  exports.useNotificationNotes = useNotificationNotes;
55
60
  function useNoteMutation(request) {
56
61
  return (0, api_hooks_1.useOvokMutation)(async (client, params) => {
@@ -65,29 +70,9 @@ const useUpdateNotificationNote = () => useNoteMutation((client, params) => clie
65
70
  exports.useUpdateNotificationNote = useUpdateNotificationNote;
66
71
  const useDeleteNotificationNote = () => useNoteMutation((client, noteId) => client.deleteNotificationNote(noteId));
67
72
  exports.useDeleteNotificationNote = useDeleteNotificationNote;
68
- const useSignalsAlertNotes = (episodeId) => {
69
- const client = (0, index_1.useClient)();
70
- const [revision, setRevision] = React.useState(0);
71
- const load = React.useCallback((signal) => (episodeId ? client.listSignalsAlertNotes(episodeId, { signal }) : Promise.reject(new Error("episodeId is required"))), [client, episodeId, revision]);
72
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
73
- if (!change) {
74
- setRevision((value) => value + 1);
75
- }
76
- }), [client, episodeId]);
77
- return (0, api_hooks_1.useOvokRequest)(load, episodeId !== undefined);
78
- };
73
+ const useSignalsAlertNotes = (episodeId) => useNoteList(episodeId, "episodeId", (client, id, signal) => client.listSignalsAlertNotes(id, { signal }));
79
74
  exports.useSignalsAlertNotes = useSignalsAlertNotes;
80
- const useSignalsRawAlertNotes = (alertId) => {
81
- const client = (0, index_1.useClient)();
82
- const [revision, setRevision] = React.useState(0);
83
- const load = React.useCallback((signal) => (alertId ? client.listSignalsRawAlertNotes(alertId, { signal }) : Promise.reject(new Error("alertId is required"))), [client, alertId, revision]);
84
- React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
85
- if (!change) {
86
- setRevision((value) => value + 1);
87
- }
88
- }), [client, alertId]);
89
- return (0, api_hooks_1.useOvokRequest)(load, alertId !== undefined);
90
- };
75
+ const useSignalsRawAlertNotes = (alertId) => useNoteList(alertId, "alertId", (client, id, signal) => client.listSignalsRawAlertNotes(id, { signal }));
91
76
  exports.useSignalsRawAlertNotes = useSignalsRawAlertNotes;
92
77
  const useCreateSignalsAlertNote = () => useNoteMutation((client, params) => client.createSignalsAlertNote(params.episodeId, { text: params.text }));
93
78
  exports.useCreateSignalsAlertNote = useCreateSignalsAlertNote;
@@ -76,8 +76,7 @@ const useSaveMeasurement = () => {
76
76
  };
77
77
  exports.useSaveMeasurement = useSaveMeasurement;
78
78
  const useEcgRecording = (id) => {
79
- const client = (0, index_1.useClient)();
80
- const load = React.useCallback(async (signal) => {
79
+ const { data: observations = [], ...state } = (0, api_hooks_1.useOvokClientRequest)(async (client, signal) => {
81
80
  const query = {
82
81
  code: (0, observationsToMeasurements_1.observationCodesForTypes)([types_1.MeasurementTypeKey.ecg]),
83
82
  _elements: "id,effectivePeriod,code,device,component,interpretation,valueSampledData,hasMember",
@@ -90,8 +89,7 @@ const useEcgRecording = (id) => {
90
89
  client.searchResources("Observation", { ...query, "has-member": `Observation/${id}` }, { signal }),
91
90
  ]);
92
91
  return [...root, ...members];
93
- }, [client, id]);
94
- const { data: observations = [], ...state } = (0, api_hooks_1.useOvokRequest)(load);
92
+ }, id);
95
93
  const recording = (0, observationsToMeasurements_1.observationsToMeasurements)(observations, [types_1.MeasurementTypeKey.ecg])[0];
96
94
  return { ...state, recording, measurements: observations };
97
95
  };
@@ -1,133 +1,33 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.useExtractQuestionnaireObservations = exports.useSubmitQuestionnaireResponse = exports.usePopulateQuestionnaire = exports.usePatientNotifications = exports.usePatientDevices = exports.usePatientQuestionnaireResponses = exports.usePatientQuestionnaires = exports.usePatientCarePlans = exports.usePatientMeasurement = exports.usePatientMeasurementHistory = exports.usePatientSlots = exports.usePatientSchedules = exports.usePatientAppointments = exports.usePatientLatestObservations = exports.usePatientDashboard = exports.useCurrentPatientProfile = void 0;
38
- const React = __importStar(require("react"));
39
5
  const api_hooks_1 = require("./api-hooks");
40
- const index_1 = require("./index");
41
- const useCurrentPatientProfile = () => {
42
- const client = (0, index_1.useClient)();
43
- const load = React.useCallback((signal) => client.getCurrentPatientProfile({ signal }), [client]);
44
- return (0, api_hooks_1.useOvokRequest)(load);
45
- };
6
+ const useCurrentPatientProfile = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getCurrentPatientProfile({ signal }));
46
7
  exports.useCurrentPatientProfile = useCurrentPatientProfile;
47
- const usePatientDashboard = (params = {}) => {
48
- const client = (0, index_1.useClient)();
49
- const serialized = JSON.stringify(params);
50
- const load = React.useCallback((signal) => client.getPatientDashboard(params, { signal }), [client, serialized]);
51
- return (0, api_hooks_1.useOvokRequest)(load);
52
- };
8
+ const usePatientDashboard = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getPatientDashboard(params, { signal }), params);
53
9
  exports.usePatientDashboard = usePatientDashboard;
54
- const usePatientLatestObservations = (params = {}) => {
55
- const client = (0, index_1.useClient)();
56
- const serialized = JSON.stringify(params);
57
- const load = React.useCallback((signal) => client.getPatientLatestObservations(params, { signal }), [client, serialized]);
58
- return (0, api_hooks_1.useOvokRequest)(load);
59
- };
10
+ const usePatientLatestObservations = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getPatientLatestObservations(params, { signal }), params);
60
11
  exports.usePatientLatestObservations = usePatientLatestObservations;
61
- const usePatientAppointments = (params = {}) => {
62
- const client = (0, index_1.useClient)();
63
- const serialized = JSON.stringify(params);
64
- const load = React.useCallback((signal) => client.listPatientAppointments(params, { signal }), [client, serialized]);
65
- return (0, api_hooks_1.useOvokRequest)(load);
66
- };
12
+ const usePatientAppointments = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientAppointments(params, { signal }), params);
67
13
  exports.usePatientAppointments = usePatientAppointments;
68
- const usePatientSchedules = (params = {}) => {
69
- const client = (0, index_1.useClient)();
70
- const serialized = JSON.stringify(params);
71
- const load = React.useCallback((signal) => client.listPatientSchedules(params, { signal }), [client, serialized]);
72
- return (0, api_hooks_1.useOvokRequest)(load);
73
- };
14
+ const usePatientSchedules = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientSchedules(params, { signal }), params);
74
15
  exports.usePatientSchedules = usePatientSchedules;
75
- const usePatientSlots = (params = {}) => {
76
- const client = (0, index_1.useClient)();
77
- const serialized = JSON.stringify(params);
78
- const load = React.useCallback((signal) => client.listPatientSlots(params, { signal }), [client, serialized]);
79
- return (0, api_hooks_1.useOvokRequest)(load);
80
- };
16
+ const usePatientSlots = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientSlots(params, { signal }), params);
81
17
  exports.usePatientSlots = usePatientSlots;
82
- const usePatientMeasurementHistory = (params = {}) => {
83
- const client = (0, index_1.useClient)();
84
- const serialized = JSON.stringify(params);
85
- const load = React.useCallback((signal) => client.listPatientMeasurementHistory(params, { signal }), [client, serialized]);
86
- return (0, api_hooks_1.useOvokRequest)(load);
87
- };
18
+ const usePatientMeasurementHistory = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientMeasurementHistory(params, { signal }), params);
88
19
  exports.usePatientMeasurementHistory = usePatientMeasurementHistory;
89
- const usePatientMeasurement = (measurementId) => {
90
- const client = (0, index_1.useClient)();
91
- const load = React.useCallback((signal) => measurementId
92
- ? client.getPatientMeasurement(measurementId, { signal })
93
- : Promise.reject(new Error("measurementId is required")), [client, measurementId]);
94
- return (0, api_hooks_1.useOvokRequest)(load, measurementId !== undefined);
95
- };
20
+ const usePatientMeasurement = (measurementId) => (0, api_hooks_1.useOvokClientRequestFor)("measurementId", measurementId, (client, id, signal) => client.getPatientMeasurement(id, { signal }));
96
21
  exports.usePatientMeasurement = usePatientMeasurement;
97
- const usePatientCarePlans = (params = {}) => {
98
- const client = (0, index_1.useClient)();
99
- const serialized = JSON.stringify(params);
100
- const load = React.useCallback((signal) => client.listPatientCarePlans(params, { signal }), [client, serialized]);
101
- return (0, api_hooks_1.useOvokRequest)(load);
102
- };
22
+ const usePatientCarePlans = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientCarePlans(params, { signal }), params);
103
23
  exports.usePatientCarePlans = usePatientCarePlans;
104
- const usePatientQuestionnaires = (params = {}) => {
105
- const client = (0, index_1.useClient)();
106
- const serialized = JSON.stringify(params);
107
- const load = React.useCallback((signal) => client.listPatientQuestionnaires(params, { signal }), [client, serialized]);
108
- return (0, api_hooks_1.useOvokRequest)(load);
109
- };
24
+ const usePatientQuestionnaires = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientQuestionnaires(params, { signal }), params);
110
25
  exports.usePatientQuestionnaires = usePatientQuestionnaires;
111
- const usePatientQuestionnaireResponses = (params = {}) => {
112
- const client = (0, index_1.useClient)();
113
- const serialized = JSON.stringify(params);
114
- const load = React.useCallback((signal) => client.listPatientQuestionnaireResponses(params, { signal }), [client, serialized]);
115
- return (0, api_hooks_1.useOvokRequest)(load);
116
- };
26
+ const usePatientQuestionnaireResponses = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientQuestionnaireResponses(params, { signal }), params);
117
27
  exports.usePatientQuestionnaireResponses = usePatientQuestionnaireResponses;
118
- const usePatientDevices = (params = {}) => {
119
- const client = (0, index_1.useClient)();
120
- const serialized = JSON.stringify(params);
121
- const load = React.useCallback((signal) => client.listPatientDevices(params, { signal }), [client, serialized]);
122
- return (0, api_hooks_1.useOvokRequest)(load);
123
- };
28
+ const usePatientDevices = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientDevices(params, { signal }), params);
124
29
  exports.usePatientDevices = usePatientDevices;
125
- const usePatientNotifications = (params = {}) => {
126
- const client = (0, index_1.useClient)();
127
- const serialized = JSON.stringify(params);
128
- const load = React.useCallback((signal) => client.listPatientNotifications(params, { signal }), [client, serialized]);
129
- return (0, api_hooks_1.useOvokRequest)(load);
130
- };
30
+ const usePatientNotifications = (params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listPatientNotifications(params, { signal }), params);
131
31
  exports.usePatientNotifications = usePatientNotifications;
132
32
  const usePopulateQuestionnaire = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.populateQuestionnaire(params.questionnaireId, params.parameters));
133
33
  exports.usePopulateQuestionnaire = usePopulateQuestionnaire;
@@ -41,8 +41,7 @@ const notification_invalidation_1 = require("./notification-invalidation");
41
41
  const index_1 = require("./index");
42
42
  const usePatientSharing = () => {
43
43
  const client = (0, index_1.useClient)();
44
- const load = React.useCallback((signal) => client.listPatientSharing({ signal }), [client]);
45
- const state = (0, api_hooks_1.useOvokRequestWithUpdater)(load);
44
+ const state = (0, api_hooks_1.useOvokClientRequest)((current, signal) => current.listPatientSharing({ signal }));
46
45
  React.useEffect(() => (0, notification_invalidation_1.subscribeToNotificationChanges)(client, (change) => {
47
46
  if ((change === null || change === void 0 ? void 0 : change.type) === "patient-sharing") {
48
47
  state.reload();
@@ -64,11 +63,7 @@ const useRevokePatientSharing = () => (0, api_hooks_1.useOvokMutation)(async (cl
64
63
  (0, notification_invalidation_1.notifyNotificationChanges)(client, { type: "patient-sharing" });
65
64
  });
66
65
  exports.useRevokePatientSharing = useRevokePatientSharing;
67
- const usePatientSharingSettings = () => {
68
- const client = (0, index_1.useClient)();
69
- const load = React.useCallback((signal) => client.getPatientSharingSettings({ signal }), [client]);
70
- return (0, api_hooks_1.useOvokRequest)(load);
71
- };
66
+ const usePatientSharingSettings = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getPatientSharingSettings({ signal }));
72
67
  exports.usePatientSharingSettings = usePatientSharingSettings;
73
68
  const useUpdatePatientSharingSettings = () => (0, api_hooks_1.useOvokMutation)((client, settings) => client.updatePatientSharingSettings(settings));
74
69
  exports.useUpdatePatientSharingSettings = useUpdatePatientSharingSettings;
@@ -1,61 +1,13 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.useUpdateProjectTextSetting = exports.useUpdateI18nextDocument = exports.useUpdateLocalization = exports.useI18nextDocument = exports.useLocalizations = exports.useLocales = void 0;
38
- const React = __importStar(require("react"));
39
5
  const api_hooks_1 = require("./api-hooks");
40
- const index_1 = require("./index");
41
- const useLocales = () => {
42
- const client = (0, index_1.useClient)();
43
- const load = React.useCallback((signal) => client.getLocales({ signal }), [client]);
44
- return (0, api_hooks_1.useOvokRequest)(load);
45
- };
6
+ const useLocales = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getLocales({ signal }));
46
7
  exports.useLocales = useLocales;
47
- const useLocalizations = (language, params = {}) => {
48
- const client = (0, index_1.useClient)();
49
- const serialized = JSON.stringify(params);
50
- const load = React.useCallback((signal) => client.listLocalizations(language, params, { signal }), [client, language, serialized]);
51
- return (0, api_hooks_1.useOvokRequest)(load, language.length > 0);
52
- };
8
+ const useLocalizations = (language, params = {}) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.listLocalizations(language, params, { signal }), [language, params], language.length > 0);
53
9
  exports.useLocalizations = useLocalizations;
54
- const useI18nextDocument = (language) => {
55
- const client = (0, index_1.useClient)();
56
- const load = React.useCallback((signal) => client.getI18nextDocument(language, { signal }), [client, language]);
57
- return (0, api_hooks_1.useOvokRequest)(load, language.length > 0);
58
- };
10
+ const useI18nextDocument = (language) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getI18nextDocument(language, { signal }), language, language.length > 0);
59
11
  exports.useI18nextDocument = useI18nextDocument;
60
12
  const useUpdateLocalization = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.updateLocalization(params.language, params.key, params.body));
61
13
  exports.useUpdateLocalization = useUpdateLocalization;
@@ -37,6 +37,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.useOvokPoll = useOvokPoll;
38
38
  const React = __importStar(require("react"));
39
39
  const ovok_error_1 = require("../client/errors/ovok-error");
40
+ const ovok_error_utils_1 = require("../client/errors/ovok-error-utils");
41
+ /** Failed polls wait at most 2^4 = 16 intervals. */
42
+ const MAX_BACKOFF_EXPONENT = 4;
43
+ /** The wait after a failed poll: doubled per failure when backing off, and never shorter than Retry-After. */
44
+ const nextDelayMs = (intervalMs, failureCount, backoff, retryAfterMs) => {
45
+ const delay = backoff ? intervalMs * 2 ** Math.min(failureCount, MAX_BACKOFF_EXPONENT) : intervalMs;
46
+ return retryAfterMs === undefined ? delay : Math.max(delay, retryAfterMs);
47
+ };
40
48
  /** Polls after each completed request, pausing hidden tabs and aborting replaced work. */
41
49
  function useOvokPoll(load, options) {
42
50
  const { intervalMs, whenHidden = true, backoff = true, honorRetryAfter = true } = options;
@@ -81,14 +89,8 @@ function useOvokPoll(load, options) {
81
89
  .catch((reason) => {
82
90
  if (!stopped && !controller.signal.aborted) {
83
91
  failureCount += 1;
84
- setError(reason instanceof Error ? reason : new Error(String(reason)));
85
- const retryAfter = honorRetryAfter ? (0, ovok_error_1.readOvokError)(reason).retryAfterMs : undefined;
86
- nextDelay = backoff
87
- ? Math.min(intervalMs * (2 ** Math.min(failureCount, 4)), intervalMs * 16)
88
- : intervalMs;
89
- if (retryAfter !== undefined) {
90
- nextDelay = Math.max(nextDelay, retryAfter);
91
- }
92
+ setError((0, ovok_error_utils_1.toError)(reason));
93
+ nextDelay = nextDelayMs(intervalMs, failureCount, backoff, honorRetryAfter ? (0, ovok_error_1.readOvokError)(reason).retryAfterMs : undefined);
92
94
  }
93
95
  })
94
96
  .finally(() => {
@@ -37,6 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.useSignalsAlert = exports.useAcknowledgeSignalsAlert = void 0;
38
38
  exports.useSignalsAlerts = useSignalsAlerts;
39
39
  const React = __importStar(require("react"));
40
+ const ovok_error_utils_1 = require("../client/errors/ovok-error-utils");
40
41
  const notification_invalidation_1 = require("./notification-invalidation");
41
42
  const index_1 = require("./index");
42
43
  var signals_alert_item_hooks_1 = require("./signals-alert-item-hooks");
@@ -69,10 +70,7 @@ function useSignalsAlerts(query = {}) {
69
70
  if (!change) {
70
71
  setRevision((value) => value + 1);
71
72
  }
72
- else if (querySnapshot.episodes === false && change.type === "signals-raw-alert") {
73
- setItems((current) => current.map((item) => item.id === change.alert.id ? { ...item, ...change.alert } : item));
74
- }
75
- else if (querySnapshot.episodes !== false && change.type === "signals-alert") {
73
+ else if (change.type === (querySnapshot.episodes === false ? "signals-raw-alert" : "signals-alert")) {
76
74
  setItems((current) => current.map((item) => item.id === change.alert.id ? { ...item, ...change.alert } : item));
77
75
  }
78
76
  }), [client, querySnapshot.episodes]);
@@ -100,7 +98,7 @@ function useSignalsAlerts(query = {}) {
100
98
  })
101
99
  .catch((reason) => {
102
100
  if (generation.current === requestGeneration) {
103
- setError(reason instanceof Error ? reason : new Error(String(reason)));
101
+ setError((0, ovok_error_utils_1.toError)(reason));
104
102
  }
105
103
  })
106
104
  .finally(() => {
@@ -138,7 +136,7 @@ function useSignalsAlerts(query = {}) {
138
136
  }
139
137
  catch (reason) {
140
138
  if (generation.current === requestGeneration) {
141
- setError(reason instanceof Error ? reason : new Error(String(reason)));
139
+ setError((0, ovok_error_utils_1.toError)(reason));
142
140
  }
143
141
  }
144
142
  finally {
@@ -1,64 +1,21 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true });
37
4
  exports.useUpdateSignalsSettings = exports.useSignalsSettings = exports.useRemoveSignalsThreshold = exports.useSetSignalsThreshold = exports.useSignalsThresholds = exports.useEnableSignalsForPatient = exports.useSignalsAlerts = exports.useSignalsAlert = exports.useAcknowledgeSignalsAlert = void 0;
38
- const React = __importStar(require("react"));
39
5
  const api_hooks_1 = require("./api-hooks");
40
- const index_1 = require("./index");
41
6
  var signals_alert_hooks_1 = require("./signals-alert-hooks");
42
7
  Object.defineProperty(exports, "useAcknowledgeSignalsAlert", { enumerable: true, get: function () { return signals_alert_hooks_1.useAcknowledgeSignalsAlert; } });
43
8
  Object.defineProperty(exports, "useSignalsAlert", { enumerable: true, get: function () { return signals_alert_hooks_1.useSignalsAlert; } });
44
9
  Object.defineProperty(exports, "useSignalsAlerts", { enumerable: true, get: function () { return signals_alert_hooks_1.useSignalsAlerts; } });
45
10
  const useEnableSignalsForPatient = () => (0, api_hooks_1.useOvokMutation)((client, patientId) => client.enableSignalsForPatient(patientId));
46
11
  exports.useEnableSignalsForPatient = useEnableSignalsForPatient;
47
- const useSignalsThresholds = (patientId) => {
48
- const client = (0, index_1.useClient)();
49
- const load = React.useCallback((signal) => client.getSignalsThresholds(patientId, { signal }), [client, patientId]);
50
- return (0, api_hooks_1.useOvokRequest)(load, patientId !== undefined);
51
- };
12
+ const useSignalsThresholds = (patientId) => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getSignalsThresholds(patientId, { signal }), patientId, patientId !== undefined);
52
13
  exports.useSignalsThresholds = useSignalsThresholds;
53
14
  const useSetSignalsThreshold = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.setSignalsThreshold(params.patientId, params.code, params.body));
54
15
  exports.useSetSignalsThreshold = useSetSignalsThreshold;
55
16
  const useRemoveSignalsThreshold = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.removeSignalsThreshold(params.patientId, params.code, params.reason));
56
17
  exports.useRemoveSignalsThreshold = useRemoveSignalsThreshold;
57
- const useSignalsSettings = () => {
58
- const client = (0, index_1.useClient)();
59
- const load = React.useCallback((signal) => client.getSignalsSettings({ signal }), [client]);
60
- return (0, api_hooks_1.useOvokRequest)(load);
61
- };
18
+ const useSignalsSettings = () => (0, api_hooks_1.useOvokClientRequest)((client, signal) => client.getSignalsSettings({ signal }));
62
19
  exports.useSignalsSettings = useSignalsSettings;
63
20
  const useUpdateSignalsSettings = () => (0, api_hooks_1.useOvokMutation)((client, params) => client.updateSignalsSettings(params.patch, params.reason));
64
21
  exports.useUpdateSignalsSettings = useUpdateSignalsSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.36",
3
+ "version": "0.4.38",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BabySleepService = void 0;
4
- const types_1 = require("../../../types");
5
- const base_observation_service_1 = require("./base-observation-service");
6
- const BABY_SLEEP_SYSTEM = "https://sdk.ovok.com/fhir/CodeSystem/measurement-type";
7
- const recordedAt = (measurement) => measurement.recordedAt instanceof Date &&
8
- !Number.isNaN(measurement.recordedAt.getTime())
9
- ? measurement.recordedAt.toISOString()
10
- : new Date().toISOString();
11
- class BabySleepService extends base_observation_service_1.BaseObservationService {
12
- constructor() {
13
- super(...arguments);
14
- this.measurementTypeKey = types_1.MeasurementTypeKey.babySleep;
15
- this.measurementTypeName = "baby sleep";
16
- this.observationMetadata = [];
17
- }
18
- generateObservationFragments(measurement) {
19
- const babySleep = this.getCastedMeasurement(measurement);
20
- if (babySleep.components.length === 0) {
21
- return [];
22
- }
23
- return [{
24
- code: {
25
- coding: [{
26
- code: types_1.ObservationCode.BABY_SLEEP,
27
- display: "Baby sleep observation",
28
- system: BABY_SLEEP_SYSTEM,
29
- }],
30
- },
31
- additionalProperties: {
32
- effectiveDateTime: recordedAt(babySleep),
33
- component: babySleep.components,
34
- },
35
- }];
36
- }
37
- getObservationCodes() {
38
- return [{
39
- coding: [{
40
- code: types_1.ObservationCode.BABY_SLEEP,
41
- display: "Baby sleep observation",
42
- system: BABY_SLEEP_SYSTEM,
43
- }],
44
- }];
45
- }
46
- getAdditionalProperties(measurement) {
47
- return [{ effectiveDateTime: recordedAt(this.getCastedMeasurement(measurement)) }];
48
- }
49
- generateValues(_measurement) {
50
- return [];
51
- }
52
- getUnits() {
53
- return [];
54
- }
55
- getMeasurementDisplay(measurement) {
56
- return `${this.getCastedMeasurement(measurement).components.length} baby sleep metrics`;
57
- }
58
- getObservationDisplay(observations) {
59
- const count = observations.reduce((total, observation) => { var _a, _b; return total + ((_b = (_a = observation.component) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); }, 0);
60
- return count ? `${count} baby sleep metrics` : undefined;
61
- }
62
- convertSamplesToMeasurement(_samples) {
63
- throw new Error("Baby sleep samples are not supported.");
64
- }
65
- convertRecordToMeasurement(_record) {
66
- throw new Error("Baby sleep Health Connect records are not supported.");
67
- }
68
- }
69
- exports.BabySleepService = BabySleepService;
@@ -1,12 +0,0 @@
1
- import { BloodGlucoseMeasurement, MeasurementTypeKey } from "../../../types";
2
- import { RecordResult, RecordType } from "../types/generate-measurement/HealthConnectTypes";
3
- import { Sample } from "../types/generate-measurement/Sample";
4
- import { ObservationMetadata } from "../types/service/ObservationMetadata";
5
- import { BaseObservationService } from "./base-observation-service";
6
- export declare class BloodGlucoseService extends BaseObservationService<BloodGlucoseMeasurement> {
7
- protected measurementTypeKey: MeasurementTypeKey;
8
- protected measurementTypeName: string;
9
- protected observationMetadata: ObservationMetadata<BloodGlucoseMeasurement>[];
10
- convertSamplesToMeasurement(samples: Sample[]): BloodGlucoseMeasurement;
11
- convertRecordToMeasurement(record: RecordResult<RecordType>): BloodGlucoseMeasurement;
12
- }