@ovok/core 0.4.49-rc.3 → 0.4.49-rc.5

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 (421) hide show
  1. package/README.md +23 -666
  2. package/dist/client/ai-fhir/methods/AIFhirResources.d.ts +3 -1
  3. package/dist/client/ai-fhir/methods/AIFhirResources.js +3 -1
  4. package/dist/client/ai-fhir/types/AIFhirPlan.d.ts +8 -0
  5. package/dist/client/ai-fhir/types/AIFhirPlanRequest.d.ts +8 -0
  6. package/dist/client/ai-fhir/types/AIFhirRequest.d.ts +5 -0
  7. package/dist/client/ai-fhir/types/AIFhirResponse.d.ts +6 -0
  8. package/dist/client/auth/errors.d.ts +15 -2
  9. package/dist/client/auth/errors.js +12 -2
  10. package/dist/client/auth/methods/appleLogin.d.ts +1 -0
  11. package/dist/client/auth/methods/appleLogin.js +1 -0
  12. package/dist/client/auth/methods/changePassword.d.ts +1 -0
  13. package/dist/client/auth/methods/changePassword.js +1 -0
  14. package/dist/client/auth/methods/googleLogin.d.ts +1 -0
  15. package/dist/client/auth/methods/googleLogin.js +1 -0
  16. package/dist/client/auth/methods/login.d.ts +6 -0
  17. package/dist/client/auth/methods/login.js +6 -0
  18. package/dist/client/auth/methods/register.d.ts +5 -0
  19. package/dist/client/auth/methods/register.js +5 -0
  20. package/dist/client/auth/methods/registerPractitioner.d.ts +5 -0
  21. package/dist/client/auth/methods/registerPractitioner.js +5 -0
  22. package/dist/client/auth/methods/reloadSession.d.ts +3 -0
  23. package/dist/client/auth/methods/requestDeleteUser.d.ts +4 -5
  24. package/dist/client/auth/methods/requestDeleteUser.js +4 -5
  25. package/dist/client/auth/methods/setPasswordFromReset.d.ts +1 -0
  26. package/dist/client/auth/methods/setPasswordFromReset.js +1 -0
  27. package/dist/client/auth/session-fetch.d.ts +11 -0
  28. package/dist/client/auth/types/Account.d.ts +8 -1
  29. package/dist/client/auth/types/AppleLoginBody.d.ts +16 -0
  30. package/dist/client/auth/types/AppleLoginBody.js +5 -0
  31. package/dist/client/auth/types/AuthResponse.d.ts +12 -0
  32. package/dist/client/auth/types/ChangePasswordBody.d.ts +7 -0
  33. package/dist/client/auth/types/ChangePasswordResponse.d.ts +5 -0
  34. package/dist/client/auth/types/CompletePasswordResetBody.d.ts +8 -0
  35. package/dist/client/auth/types/GoogleLoginBody.d.ts +5 -0
  36. package/dist/client/auth/types/LoginBody.d.ts +15 -1
  37. package/dist/client/auth/types/LoginError.d.ts +21 -2
  38. package/dist/client/auth/types/LoginError.js +8 -2
  39. package/dist/client/auth/types/LoginResponse.d.ts +8 -1
  40. package/dist/client/auth/types/RegisterBody.d.ts +12 -0
  41. package/dist/client/auth/types/RegisterPractitionerBody.d.ts +5 -0
  42. package/dist/client/auth/types/RegisterResponse.d.ts +7 -0
  43. package/dist/client/auth/types/RequestDeleteUserBody.d.ts +7 -7
  44. package/dist/client/auth/types/RequestDeleteUserResponse.d.ts +14 -0
  45. package/dist/client/auth/types/ResetPasswordBody.d.ts +5 -0
  46. package/dist/client/auth/types/Session.d.ts +14 -2
  47. package/dist/client/change-history/methods.d.ts +6 -0
  48. package/dist/client/change-history/methods.js +6 -0
  49. package/dist/client/change-history/types.d.ts +82 -0
  50. package/dist/client/chat/ai/methods/createAiSession.d.ts +6 -0
  51. package/dist/client/chat/ai/methods/createAiSession.js +6 -0
  52. package/dist/client/chat/ai/types/CreateAiSessionResponse.d.ts +17 -0
  53. package/dist/client/chat/ai/types/SessionMessagesResponse.d.ts +9 -0
  54. package/dist/client/cms/locale.d.ts +12 -2
  55. package/dist/client/cms/locale.js +9 -2
  56. package/dist/client/cms/methods.d.ts +6 -2
  57. package/dist/client/cms/methods.js +7 -3
  58. package/dist/client/cms/types.d.ts +44 -4
  59. package/dist/client/consent/methods.d.ts +16 -0
  60. package/dist/client/consent/methods.js +16 -0
  61. package/dist/client/consent/types.d.ts +53 -1
  62. package/dist/client/consent/types.js +10 -1
  63. package/dist/client/email/methods.d.ts +3 -0
  64. package/dist/client/email/methods.js +3 -0
  65. package/dist/client/email/types.d.ts +33 -0
  66. package/dist/client/errors/field-errors.d.ts +3 -0
  67. package/dist/client/errors/field-errors.js +3 -0
  68. package/dist/client/errors/ovok-error-utils.d.ts +6 -0
  69. package/dist/client/errors/ovok-error-utils.js +6 -0
  70. package/dist/client/errors/ovok-error.d.ts +36 -4
  71. package/dist/client/errors/ovok-error.js +15 -4
  72. package/dist/client/errors/rate-limit-error.d.ts +11 -2
  73. package/dist/client/errors/rate-limit-error.js +10 -2
  74. package/dist/client/errors/sign-in-required-error.d.ts +5 -2
  75. package/dist/client/errors/sign-in-required-error.js +5 -2
  76. package/dist/client/experience/methods.d.ts +38 -0
  77. package/dist/client/experience/methods.js +35 -0
  78. package/dist/client/experience/types.d.ts +316 -0
  79. package/dist/client/experience/types.js +1 -0
  80. package/dist/client/invites/methods.d.ts +27 -9
  81. package/dist/client/invites/methods.js +27 -9
  82. package/dist/client/invites/parse-accept-invite-link.d.ts +3 -1
  83. package/dist/client/invites/parse-accept-invite-link.js +3 -1
  84. package/dist/client/invites/types.d.ts +55 -0
  85. package/dist/client/invites/types.js +12 -0
  86. package/dist/client/notifications/methods.d.ts +15 -0
  87. package/dist/client/notifications/methods.js +15 -0
  88. package/dist/client/notifications/types.d.ts +249 -2
  89. package/dist/client/observation/bundle-entry-status.d.ts +3 -0
  90. package/dist/client/observation/bundle-entry-status.js +13 -0
  91. package/dist/client/observation/fhir-systems.d.ts +7 -0
  92. package/dist/client/observation/fhir-systems.js +8 -1
  93. package/dist/client/observation/methods/generateObservationBodiesByMeasurement.d.ts +3 -0
  94. package/dist/client/observation/methods/generateObservationBodiesByMeasurement.js +10 -65
  95. package/dist/client/observation/methods/getLatestObservationsByCodes.d.ts +3 -0
  96. package/dist/client/observation/methods/getLatestObservationsByCodes.js +3 -0
  97. package/dist/client/observation/methods/observationsToMeasurements.d.ts +23 -1
  98. package/dist/client/observation/methods/observationsToMeasurements.js +72 -12
  99. package/dist/client/observation/methods/saveMeasurement.d.ts +3 -1
  100. package/dist/client/observation/methods/saveMeasurement.js +3 -1
  101. package/dist/client/observation/observation-bundle-utils.d.ts +11 -7
  102. package/dist/client/observation/observation-bundle-utils.js +61 -71
  103. package/dist/client/observation/observation-coding.d.ts +12 -0
  104. package/dist/client/observation/observation-coding.js +69 -0
  105. package/dist/client/observation/observation-groups.d.ts +12 -0
  106. package/dist/client/observation/observation-groups.js +51 -0
  107. package/dist/client/observation/reading-group-backfill.d.ts +13 -0
  108. package/dist/client/observation/reading-group-backfill.js +79 -0
  109. package/dist/client/observation/reading-group.d.ts +14 -0
  110. package/dist/client/observation/reading-group.js +85 -0
  111. package/dist/client/observation/series.d.ts +28 -5
  112. package/dist/client/observation/series.js +16 -6
  113. package/dist/client/observation/services/base-observation-service.d.ts +1 -1
  114. package/dist/client/observation/services/base-observation-service.js +6 -12
  115. package/dist/client/observation/services/blood-pressure.d.ts +2 -0
  116. package/dist/client/observation/services/blood-pressure.js +9 -5
  117. package/dist/client/observation/services/component-observation-services.js +2 -2
  118. package/dist/client/observation/services/creator.d.ts +5 -0
  119. package/dist/client/observation/services/creator.js +5 -0
  120. package/dist/client/observation/services/ecg-observation-fragments.d.ts +4 -0
  121. package/dist/client/observation/services/ecg-observation-fragments.js +30 -37
  122. package/dist/client/observation/services/ecg.d.ts +3 -1
  123. package/dist/client/observation/services/ecg.js +19 -19
  124. package/dist/client/observation/services/uric-acid-service.js +2 -13
  125. package/dist/client/observation/services/urine-analyte-values.d.ts +4 -0
  126. package/dist/client/observation/services/urine-analyte-values.js +27 -0
  127. package/dist/client/observation/types/GetLatestObservationsByCodeParams.d.ts +10 -0
  128. package/dist/client/observation/types/MeasurementTypeKey.d.ts +26 -0
  129. package/dist/client/observation/types/MeasurementTypeKey.js +26 -0
  130. package/dist/client/observation/types/ObservationCode.d.ts +64 -1
  131. package/dist/client/observation/types/ObservationCode.js +64 -1
  132. package/dist/client/observation/types/UrineAnalytes.d.ts +29 -0
  133. package/dist/client/observation/types/UrineAnalytes.js +18 -9
  134. package/dist/client/observation/types/generate-measurement/Sample.d.ts +33 -0
  135. package/dist/client/observation/types/generate-observation-body/GenerateObservationBodyParams.d.ts +9 -0
  136. package/dist/client/observation/types/measurement/BabySleepMeasurement.d.ts +3 -0
  137. package/dist/client/observation/types/measurement/BloodGlucoseMeasurement.d.ts +7 -0
  138. package/dist/client/observation/types/measurement/BloodPressureMeasurement.d.ts +10 -0
  139. package/dist/client/observation/types/measurement/BloodPressureStates.d.ts +10 -0
  140. package/dist/client/observation/types/measurement/BloodPressureStates.js +10 -0
  141. package/dist/client/observation/types/measurement/BodyTemperatureMeasurement.d.ts +7 -0
  142. package/dist/client/observation/types/measurement/BodyWeightMeasurmement.d.ts +8 -0
  143. package/dist/client/observation/types/measurement/EcgDiagnosticFlag.d.ts +18 -0
  144. package/dist/client/observation/types/measurement/EcgDiagnosticFlag.js +18 -0
  145. package/dist/client/observation/types/measurement/EcgMeasurement.d.ts +9 -0
  146. package/dist/client/observation/types/measurement/HeartRateMeasurement.d.ts +7 -0
  147. package/dist/client/observation/types/measurement/HeartRateVariabilityMeasurement.d.ts +7 -0
  148. package/dist/client/observation/types/measurement/LipidPanelMeasurement.d.ts +12 -0
  149. package/dist/client/observation/types/measurement/Measurement.d.ts +9 -0
  150. package/dist/client/observation/types/measurement/MeasurementDevice.d.ts +10 -0
  151. package/dist/client/observation/types/measurement/MeasurementSeries.d.ts +2 -0
  152. package/dist/client/observation/types/measurement/PulseOximeterMeasurement.d.ts +10 -0
  153. package/dist/client/observation/types/measurement/RespiratoryRateMeasurement.d.ts +7 -0
  154. package/dist/client/observation/types/measurement/RespiratoryTherapyMeasurement.d.ts +3 -0
  155. package/dist/client/observation/types/measurement/RestingHeartRateMeasurement.d.ts +7 -0
  156. package/dist/client/observation/types/measurement/SpirometryMeasurement.d.ts +23 -0
  157. package/dist/client/observation/types/measurement/StepCountMeasurement.d.ts +9 -0
  158. package/dist/client/observation/types/measurement/UrineAnalyzeMeasurement.d.ts +29 -0
  159. package/dist/client/observation/types/measurement/Vo2MaxMeasurement.d.ts +7 -0
  160. package/dist/client/observation/types/measurement/WalkingHeartRateAverageMeasurement.d.ts +7 -0
  161. package/dist/client/observation/types/service/MeasurementField.d.ts +5 -1
  162. package/dist/client/observation/utils/getDeviceObject.js +15 -32
  163. package/dist/client/observation/utils/getObservationValueDisplay.d.ts +2 -0
  164. package/dist/client/offline/offline-measurement-queue.d.ts +56 -1
  165. package/dist/client/offline/offline-measurement-queue.js +23 -8
  166. package/dist/client/offline/shared-measurement-queue.d.ts +16 -1
  167. package/dist/client/offline/shared-measurement-queue.js +3 -1
  168. package/dist/client/ovok-client.d.ts +28 -6
  169. package/dist/client/ovok-client.js +19 -11
  170. package/dist/client/patient/methods.d.ts +21 -0
  171. package/dist/client/patient/methods.js +21 -0
  172. package/dist/client/patient/types.d.ts +131 -0
  173. package/dist/client/patient-sharing/methods.d.ts +18 -0
  174. package/dist/client/patient-sharing/methods.js +18 -0
  175. package/dist/client/patient-sharing/types.d.ts +89 -1
  176. package/dist/client/platform/methods.d.ts +22 -0
  177. package/dist/client/platform/methods.js +20 -0
  178. package/dist/client/platform/types.d.ts +194 -1
  179. package/dist/client/platform/types.js +24 -0
  180. package/dist/client/questionnaire-response/methods/createQuestionnaireResponseWithObservations.d.ts +3 -0
  181. package/dist/client/questionnaire-response/methods/createQuestionnaireResponseWithObservations.js +3 -0
  182. package/dist/client/questionnaire-response/methods/extractQuestionnaireObservations.d.ts +3 -0
  183. package/dist/client/questionnaire-response/methods/extractQuestionnaireObservations.js +3 -0
  184. package/dist/client/questionnaire-response/methods/populateQuestionnaire.d.ts +3 -0
  185. package/dist/client/questionnaire-response/methods/populateQuestionnaire.js +3 -0
  186. package/dist/client/questionnaire-response/methods/submitQuestionnaireResponse.d.ts +3 -0
  187. package/dist/client/questionnaire-response/methods/submitQuestionnaireResponse.js +3 -0
  188. package/dist/client/questionnaire-response/types.d.ts +6 -0
  189. package/dist/client/signals/errors.d.ts +13 -2
  190. package/dist/client/signals/errors.js +9 -2
  191. package/dist/client/signals/methods.d.ts +9 -0
  192. package/dist/client/signals/methods.js +9 -0
  193. package/dist/client/signals/types.d.ts +31 -0
  194. package/dist/client/slim/methods.d.ts +268 -21
  195. package/dist/client/slim/methods.js +264 -21
  196. package/dist/client/slim/paging.d.ts +22 -2
  197. package/dist/client/slim/paging.js +6 -2
  198. package/dist/client/slim/types.d.ts +920 -1
  199. package/dist/client/storage.d.ts +15 -1
  200. package/dist/client/storage.js +7 -1
  201. package/dist/client/wearables/methods.d.ts +24 -0
  202. package/dist/client/wearables/methods.js +24 -0
  203. package/dist/client/wearables/types.d.ts +74 -0
  204. package/dist/conformance/api-requirements.d.ts +31 -5
  205. package/dist/conformance/api-requirements.js +47 -10
  206. package/dist/conformance/capability-requirements.d.ts +4 -26
  207. package/dist/conformance/capability-requirements.js +5 -27
  208. package/dist/conformance/capability.d.ts +9 -1
  209. package/dist/conformance/capability.js +3 -1
  210. package/dist/hooks/account-hooks.d.ts +35 -0
  211. package/dist/hooks/account-hooks.js +33 -0
  212. package/dist/hooks/api-hooks.d.ts +74 -4
  213. package/dist/hooks/api-hooks.js +56 -4
  214. package/dist/hooks/cms-hooks.d.ts +9 -3
  215. package/dist/hooks/cms-hooks.js +9 -3
  216. package/dist/hooks/email-hooks.d.ts +3 -0
  217. package/dist/hooks/email-hooks.js +3 -0
  218. package/dist/hooks/experience-hooks.d.ts +26 -0
  219. package/dist/hooks/experience-hooks.js +24 -0
  220. package/dist/hooks/index.d.ts +18 -0
  221. package/dist/hooks/index.js +18 -0
  222. package/dist/hooks/invites-hooks.d.ts +21 -2
  223. package/dist/hooks/invites-hooks.js +21 -2
  224. package/dist/hooks/notification-ack-hooks.d.ts +6 -2
  225. package/dist/hooks/notification-ack-hooks.js +6 -2
  226. package/dist/hooks/notification-hooks.d.ts +27 -3
  227. package/dist/hooks/notification-hooks.js +27 -3
  228. package/dist/hooks/notification-note-hooks.d.ts +41 -0
  229. package/dist/hooks/notification-note-hooks.js +33 -0
  230. package/dist/hooks/observation-hooks.d.ts +30 -0
  231. package/dist/hooks/observation-hooks.js +26 -3
  232. package/dist/hooks/patient-hooks.d.ts +53 -0
  233. package/dist/hooks/patient-hooks.js +48 -0
  234. package/dist/hooks/patient-sharing-hooks.d.ts +18 -0
  235. package/dist/hooks/patient-sharing-hooks.js +18 -0
  236. package/dist/hooks/platform-hooks.d.ts +32 -0
  237. package/dist/hooks/platform-hooks.js +23 -0
  238. package/dist/hooks/poll-hooks.d.ts +17 -1
  239. package/dist/hooks/poll-hooks.js +3 -1
  240. package/dist/hooks/signals-hooks.d.ts +3 -0
  241. package/dist/hooks/signals-hooks.js +3 -0
  242. package/dist/hooks/wearables-hooks.d.ts +23 -0
  243. package/dist/hooks/wearables-hooks.js +21 -0
  244. package/dist/index.d.ts +1 -965
  245. package/dist/index.js +1 -71
  246. package/dist/next/auth/saved-accounts-store.d.ts +10 -0
  247. package/dist/next/auth/session.d.ts +17 -0
  248. package/dist/next/auth/user-session.d.ts +5 -0
  249. package/dist/next/config/ovok-config.d.ts +45 -0
  250. package/dist/next/errors/ovok-account-error.d.ts +14 -1
  251. package/dist/next/errors/ovok-account-error.js +8 -1
  252. package/dist/next/errors/ovok-errors.d.ts +88 -0
  253. package/dist/next/errors/ovok-errors.js +67 -0
  254. package/dist/next/http/http-client.d.ts +5 -0
  255. package/dist/next/http/transmit.d.ts +7 -0
  256. package/dist/next/http/url.d.ts +10 -0
  257. package/dist/next/ovok.d.ts +31 -1
  258. package/dist/next/ovok.js +5 -1
  259. package/dist/next/paging/page.d.ts +13 -1
  260. package/dist/next/react/context.d.ts +7 -0
  261. package/dist/next/react/context.js +7 -0
  262. package/dist/next/react/index.d.ts +24 -0
  263. package/dist/next/react/index.js +18 -0
  264. package/dist/next/react/query-hooks.d.ts +69 -0
  265. package/dist/next/react/query-hooks.js +31 -0
  266. package/dist/next/resources/accounts/accounts-resource.d.ts +6 -0
  267. package/dist/next/resources/accounts/accounts-resource.js +6 -0
  268. package/dist/next/resources/ai/ai-chat-resource.d.ts +7 -0
  269. package/dist/next/resources/ai/ai-chat-resource.js +5 -0
  270. package/dist/next/resources/ai/ai-resource.d.ts +13 -0
  271. package/dist/next/resources/ai/ai-resource.js +6 -0
  272. package/dist/next/resources/ai/chat-messages-resource.d.ts +7 -0
  273. package/dist/next/resources/ai/chat-messages-resource.js +7 -0
  274. package/dist/next/resources/ai/chat-sessions-resource.d.ts +14 -0
  275. package/dist/next/resources/ai/chat-sessions-resource.js +8 -0
  276. package/dist/next/resources/auth/auth-sessions-resource.d.ts +6 -1
  277. package/dist/next/resources/auth/auth-sessions-resource.js +6 -1
  278. package/dist/next/resources/auth/registration.d.ts +18 -1
  279. package/dist/next/resources/auth/social-login.d.ts +12 -0
  280. package/dist/next/resources/auth-resource.d.ts +54 -1
  281. package/dist/next/resources/auth-resource.js +23 -0
  282. package/dist/next/resources/bots/bots-resource.d.ts +15 -0
  283. package/dist/next/resources/bots/bots-resource.js +5 -0
  284. package/dist/next/resources/cms/cms-delivery.d.ts +14 -2
  285. package/dist/next/resources/cms/cms-documents-resource.d.ts +7 -1
  286. package/dist/next/resources/cms/cms-documents-resource.js +7 -1
  287. package/dist/next/resources/cms/cms-resource.d.ts +7 -0
  288. package/dist/next/resources/cms/cms-resource.js +5 -0
  289. package/dist/next/resources/cms/release-notes-resource.d.ts +6 -0
  290. package/dist/next/resources/cms/release-notes-resource.js +6 -0
  291. package/dist/next/resources/consent/consent-resource.d.ts +22 -0
  292. package/dist/next/resources/consent/consent-resource.js +20 -0
  293. package/dist/next/resources/content/content-resource.d.ts +18 -0
  294. package/dist/next/resources/content/content-resource.js +12 -0
  295. package/dist/next/resources/documents/documents-resource.d.ts +24 -0
  296. package/dist/next/resources/documents/documents-resource.js +10 -0
  297. package/dist/next/resources/email/email-resource.d.ts +6 -0
  298. package/dist/next/resources/email/email-resource.js +5 -0
  299. package/dist/next/resources/email/email-templates-resource.d.ts +6 -0
  300. package/dist/next/resources/email/email-templates-resource.js +6 -0
  301. package/dist/next/resources/fhir-resource.d.ts +36 -0
  302. package/dist/next/resources/fhir-resource.js +21 -0
  303. package/dist/next/resources/health-resource.d.ts +16 -0
  304. package/dist/next/resources/health-resource.js +5 -0
  305. package/dist/next/resources/invites/invite-flow-resource.d.ts +7 -1
  306. package/dist/next/resources/invites/invite-flow-resource.js +7 -1
  307. package/dist/next/resources/invites/invites-resource.d.ts +15 -0
  308. package/dist/next/resources/invites/invites-resource.js +5 -0
  309. package/dist/next/resources/localization/i18next-resource.d.ts +6 -0
  310. package/dist/next/resources/localization/i18next-resource.js +6 -0
  311. package/dist/next/resources/localization/locales-resource.d.ts +7 -0
  312. package/dist/next/resources/localization/locales-resource.js +7 -0
  313. package/dist/next/resources/localization/localizations-resource.d.ts +17 -0
  314. package/dist/next/resources/localization/localizations-resource.js +9 -0
  315. package/dist/next/resources/measurements/measurements-resource.d.ts +64 -3
  316. package/dist/next/resources/measurements/measurements-resource.js +45 -6
  317. package/dist/next/resources/measurements/observation-builder.d.ts +6 -1
  318. package/dist/next/resources/measurements/observation-builder.js +16 -7
  319. package/dist/next/resources/measurements/offline-measurement-queue-types.d.ts +32 -0
  320. package/dist/next/resources/measurements/save-error.js +3 -4
  321. package/dist/next/resources/patient/fhir-records.d.ts +19 -1
  322. package/dist/next/resources/patient/fhir-records.js +19 -1
  323. package/dist/next/resources/patient/patient-resource.d.ts +15 -0
  324. package/dist/next/resources/patient/patient-resource.js +6 -0
  325. package/dist/next/resources/projects/project-features-resource.d.ts +7 -0
  326. package/dist/next/resources/projects/project-features-resource.js +7 -0
  327. package/dist/next/resources/projects/project-members-resource.d.ts +19 -0
  328. package/dist/next/resources/projects/project-members-resource.js +9 -0
  329. package/dist/next/resources/projects/project-settings-resource.d.ts +8 -0
  330. package/dist/next/resources/projects/project-settings-resource.js +8 -0
  331. package/dist/next/resources/projects/projects-resource.d.ts +15 -0
  332. package/dist/next/resources/projects/projects-resource.js +5 -0
  333. package/dist/next/resources/questionnaires/questionnaires-resource.d.ts +13 -0
  334. package/dist/next/resources/questionnaires/questionnaires-resource.js +13 -0
  335. package/dist/next/resources/realtime/realtime-resource.d.ts +11 -0
  336. package/dist/next/resources/realtime/realtime-resource.js +11 -0
  337. package/dist/next/resources/realtime/realtime-socket.js +12 -5
  338. package/dist/next/resources/realtime/realtime-types.d.ts +19 -1
  339. package/dist/next/resources/session/saved-accounts-resource.d.ts +16 -0
  340. package/dist/next/resources/session/saved-accounts-resource.js +16 -0
  341. package/dist/next/resources/session/session-resource.d.ts +8 -0
  342. package/dist/next/resources/session/session-resource.js +7 -0
  343. package/dist/next/resources/sharing/sharing-invites-resource.d.ts +7 -0
  344. package/dist/next/resources/sharing/sharing-invites-resource.js +7 -0
  345. package/dist/next/resources/sharing/sharing-resource.d.ts +8 -0
  346. package/dist/next/resources/sharing/sharing-resource.js +5 -0
  347. package/dist/next/resources/sharing/sharing-settings-resource.d.ts +7 -0
  348. package/dist/next/resources/sharing/sharing-settings-resource.js +7 -0
  349. package/dist/next/resources/sharing/sharing-shares-resource.d.ts +7 -0
  350. package/dist/next/resources/sharing/sharing-shares-resource.js +7 -0
  351. package/dist/next/resources/signals/signals-gateway-resource.d.ts +15 -0
  352. package/dist/next/resources/signals/signals-gateway-resource.js +6 -0
  353. package/dist/next/resources/signals/signals-resource.d.ts +7 -0
  354. package/dist/next/resources/signals/signals-resource.js +5 -0
  355. package/dist/next/resources/signals/undeliverable-resource.d.ts +35 -0
  356. package/dist/next/resources/signals/undeliverable-resource.js +6 -0
  357. package/dist/next/resources/slim/slim-alarms-resource.d.ts +7 -0
  358. package/dist/next/resources/slim/slim-alarms-resource.js +7 -0
  359. package/dist/next/resources/slim/slim-change-history-resource.d.ts +6 -0
  360. package/dist/next/resources/slim/slim-change-history-resource.js +6 -0
  361. package/dist/next/resources/slim/slim-child-projects-resource.d.ts +21 -0
  362. package/dist/next/resources/slim/slim-child-projects-resource.js +8 -0
  363. package/dist/next/resources/slim/slim-devices-resource.d.ts +31 -0
  364. package/dist/next/resources/slim/slim-devices-resource.js +16 -0
  365. package/dist/next/resources/slim/slim-exports-resource.d.ts +6 -0
  366. package/dist/next/resources/slim/slim-exports-resource.js +6 -0
  367. package/dist/next/resources/slim/slim-locations-resource.d.ts +9 -0
  368. package/dist/next/resources/slim/slim-locations-resource.js +9 -0
  369. package/dist/next/resources/slim/slim-medical-notifications-resource.d.ts +6 -0
  370. package/dist/next/resources/slim/slim-medical-notifications-resource.js +6 -0
  371. package/dist/next/resources/slim/slim-notification-notes-resource.d.ts +10 -0
  372. package/dist/next/resources/slim/slim-notification-notes-resource.js +10 -0
  373. package/dist/next/resources/slim/slim-notifications-resource.d.ts +10 -0
  374. package/dist/next/resources/slim/slim-notifications-resource.js +6 -0
  375. package/dist/next/resources/slim/slim-organizations-resource.d.ts +9 -0
  376. package/dist/next/resources/slim/slim-organizations-resource.js +9 -0
  377. package/dist/next/resources/slim/slim-out-of-bed-resource.d.ts +12 -0
  378. package/dist/next/resources/slim/slim-out-of-bed-resource.js +7 -0
  379. package/dist/next/resources/slim/slim-patient-thresholds-resource.d.ts +6 -0
  380. package/dist/next/resources/slim/slim-patient-thresholds-resource.js +6 -0
  381. package/dist/next/resources/slim/slim-patients-resource.d.ts +11 -0
  382. package/dist/next/resources/slim/slim-patients-resource.js +10 -0
  383. package/dist/next/resources/slim/slim-policies-resource.d.ts +10 -0
  384. package/dist/next/resources/slim/slim-policies-resource.js +10 -0
  385. package/dist/next/resources/slim/slim-practitioners-resource.d.ts +6 -0
  386. package/dist/next/resources/slim/slim-practitioners-resource.js +6 -0
  387. package/dist/next/resources/slim/slim-projects-resource.d.ts +12 -0
  388. package/dist/next/resources/slim/slim-projects-resource.js +11 -0
  389. package/dist/next/resources/slim/slim-queries.d.ts +51 -0
  390. package/dist/next/resources/slim/slim-resource.d.ts +21 -0
  391. package/dist/next/resources/slim/slim-resource.js +6 -0
  392. package/dist/next/resources/slim/slim-sleep-resource.d.ts +6 -0
  393. package/dist/next/resources/slim/slim-sleep-resource.js +6 -0
  394. package/dist/next/resources/slim/slim-thresholds-resource.d.ts +5 -0
  395. package/dist/next/resources/slim/slim-thresholds-resource.js +5 -0
  396. package/dist/next/resources/slim/slim-trends-resource.d.ts +6 -0
  397. package/dist/next/resources/slim/slim-trends-resource.js +6 -0
  398. package/dist/next/resources/slim/slim-users-resource.d.ts +12 -0
  399. package/dist/next/resources/slim/slim-users-resource.js +6 -0
  400. package/dist/next/resources/slim/slim-zones-resource.d.ts +8 -0
  401. package/dist/next/resources/slim/slim-zones-resource.js +8 -0
  402. package/dist/next/resources/video-calls/video-call-access-resource.d.ts +13 -0
  403. package/dist/next/resources/video-calls/video-call-access-resource.js +8 -0
  404. package/dist/next/resources/video-calls/video-call-appointments-resource.d.ts +8 -0
  405. package/dist/next/resources/video-calls/video-call-appointments-resource.js +8 -0
  406. package/dist/next/resources/video-calls/video-call-emails-resource.d.ts +8 -0
  407. package/dist/next/resources/video-calls/video-call-emails-resource.js +8 -0
  408. package/dist/next/resources/video-calls/video-calls-resource.d.ts +14 -0
  409. package/dist/next/resources/video-calls/video-calls-resource.js +6 -0
  410. package/dist/next/resources/wearables/wearable-connections-resource.d.ts +8 -0
  411. package/dist/next/resources/wearables/wearable-connections-resource.js +8 -0
  412. package/dist/next/resources/wearables/wearable-providers-resource.d.ts +10 -0
  413. package/dist/next/resources/wearables/wearable-providers-resource.js +10 -0
  414. package/dist/next/resources/wearables/wearables-resource.d.ts +7 -0
  415. package/dist/next/resources/wearables/wearables-resource.js +5 -0
  416. package/dist/next/storage/ovok-storage.d.ts +16 -0
  417. package/dist/next/storage/ovok-storage.js +8 -0
  418. package/dist/types/ValidationError.d.ts +9 -0
  419. package/dist/utils/patch/getPatchOperationType.d.ts +3 -0
  420. package/dist/utils/patch/getPatchOperationType.js +3 -0
  421. package/package.json +52 -13
@@ -4,15 +4,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.observationsToMeasurements = exports.observationCodesForTypes = void 0;
5
5
  const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
6
6
  const fhir_systems_1 = require("../fhir-systems");
7
+ const observation_coding_1 = require("../observation-coding");
8
+ const reading_group_1 = require("../reading-group");
9
+ const blood_pressure_1 = require("../services/blood-pressure");
7
10
  const single_value_services_1 = require("../services/single-value-services");
8
11
  const DEFAULT_OBSERVATION_TIME_TOLERANCE_MS = 1000;
9
12
  const codeOf = (observation) => {
10
13
  var _a, _b, _c, _d, _e, _f, _g;
11
14
  return (_d = (_c = (_b = (_a = observation.code) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b.find((coding) => coding.system === fhir_systems_1.LOINC_SYSTEM)) === null || _c === void 0 ? void 0 : _c.code) !== null && _d !== void 0 ? _d : (_g = (_f = (_e = observation.code) === null || _e === void 0 ? void 0 : _e.coding) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.code;
12
15
  };
16
+ const PRESENCE_VALUES = {
17
+ [MeasurementTypes_1.UrinePresenceCoding.positive]: 1,
18
+ [MeasurementTypes_1.UrinePresenceCoding.negative]: 0,
19
+ };
13
20
  const valueOf = (observation) => {
14
- var _a;
15
- const value = (_a = observation.valueQuantity) === null || _a === void 0 ? void 0 : _a.value;
21
+ var _a, _b, _c, _d, _e, _f;
22
+ const value = (_b = (_a = observation.valueQuantity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : PRESENCE_VALUES[(_f = (_e = (_d = (_c = observation.valueCodeableConcept) === null || _c === void 0 ? void 0 : _c.coding) === null || _d === void 0 ? void 0 : _d.find((coding) => coding.system === MeasurementTypes_1.UrinePresenceCoding.system)) === null || _e === void 0 ? void 0 : _e.code) !== null && _f !== void 0 ? _f : ""];
16
23
  return typeof value === "number" ? value : undefined;
17
24
  };
18
25
  const irregularHeartbeatOf = (observations) => {
@@ -30,6 +37,13 @@ const irregularHeartbeatOf = (observations) => {
30
37
  }
31
38
  return result === MeasurementTypes_1.PulseRhythmCoding.regular ? false : undefined;
32
39
  };
40
+ const bloodPressureStatusOf = (observations) => {
41
+ var _a;
42
+ const status = (_a = observations
43
+ .flatMap((observation) => { var _a; return (_a = observation.extension) !== null && _a !== void 0 ? _a : []; })
44
+ .find((extension) => extension.url === blood_pressure_1.BLOOD_PRESSURE_STATUS_URL)) === null || _a === void 0 ? void 0 : _a.valueString;
45
+ return status ? { status: status } : {};
46
+ };
33
47
  const recordedAtOf = (observation) => {
34
48
  var _a, _b;
35
49
  const value = (_a = observation.effectiveDateTime) !== null && _a !== void 0 ? _a : (_b = observation.effectivePeriod) === null || _b === void 0 ? void 0 : _b.start;
@@ -45,6 +59,13 @@ const groupKey = (observation) => {
45
59
  const recordingId = ((_b = observation.hasMember) === null || _b === void 0 ? void 0 : _b.length) ? id.replace(/-\d+$/, "") : id;
46
60
  return recordingId || ((_c = recordedAtOf(observation)) === null || _c === void 0 ? void 0 : _c.toISOString()) || "unknown";
47
61
  };
62
+ /** A recording id the SDK assigns before saving; older saves kept it in `hasMember`, where it matches nothing. */
63
+ const UNSAVED_RECORDING_ID = /^ecg-\d+-\d+$/;
64
+ /** The id of the first observation a later segment or the heart rate points at. */
65
+ const mainIdOf = (observation) => {
66
+ var _a;
67
+ return (_a = observation.hasMember) === null || _a === void 0 ? void 0 : _a.map((member) => { var _a, _b; return (_b = (_a = member.reference) === null || _a === void 0 ? void 0 : _a.match(/^Observation\/(.+)$/)) === null || _b === void 0 ? void 0 : _b[1]; }).find(Boolean);
68
+ };
48
69
  const ecgGroupKey = (observation, observations) => {
49
70
  const parent = observations.find((candidate) => candidate.id &&
50
71
  observation.id &&
@@ -53,6 +74,10 @@ const ecgGroupKey = (observation, observations) => {
53
74
  if (parent) {
54
75
  return groupKey(parent);
55
76
  }
77
+ const mainId = mainIdOf(observation);
78
+ if (mainId && !UNSAVED_RECORDING_ID.test(mainId)) {
79
+ return mainId;
80
+ }
56
81
  if (codeOf(observation) === MeasurementTypes_1.ObservationCode.ECG) {
57
82
  return groupKey(observation);
58
83
  }
@@ -201,9 +226,17 @@ const groupObservations = (observations, options, legacyKey) => {
201
226
  }
202
227
  return [...groups.values()].sort((left, right) => left.firstIndex - right.firstIndex);
203
228
  };
229
+ /** A value by its code: from the observation that holds it, else from a group that repeats it as a component. */
204
230
  const firstValue = (observations, code) => {
205
231
  const match = observations.find((observation) => codeOf(observation) === code);
206
- return match ? valueOf(match) : undefined;
232
+ return match ? valueOf(match) : groupComponentValue(observations, code);
233
+ };
234
+ const groupComponentValue = (observations, code) => {
235
+ var _a, _b;
236
+ return (_b = (_a = observations
237
+ .filter(reading_group_1.isReadingGroup)
238
+ .flatMap((group) => { var _a; return (_a = group.component) !== null && _a !== void 0 ? _a : []; })
239
+ .find((component) => { var _a, _b; return (_b = (_a = component.code) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b.some((coding) => coding.code === code); })) === null || _a === void 0 ? void 0 : _a.valueQuantity) === null || _b === void 0 ? void 0 : _b.value;
207
240
  };
208
241
  const LIPID_FIELDS = [
209
242
  { key: "totalCholesterol", codes: [MeasurementTypes_1.ObservationCode.TOTAL_CHOLESTEROL_MASS, MeasurementTypes_1.ObservationCode.TOTAL_CHOLESTEROL_MOLAR] },
@@ -269,13 +302,14 @@ const baseMeasurement = (measurementTypeKey, observation) => ({
269
302
  ...(recordedAtOf(observation) ? { recordedAt: recordedAtOf(observation) } : {}),
270
303
  });
271
304
  const inverseGroup = (type, observations) => {
272
- var _a, _b, _c, _d, _e, _f, _g;
305
+ var _a, _b, _c, _d, _e, _f, _g, _h;
273
306
  const first = [...observations].sort((left, right) => {
274
307
  var _a, _b, _c, _d;
275
308
  return ((_b = (_a = recordedAtOf(left)) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER) -
276
309
  ((_d = (_c = recordedAtOf(right)) === null || _c === void 0 ? void 0 : _c.getTime()) !== null && _d !== void 0 ? _d : Number.MAX_SAFE_INTEGER);
277
310
  })[0];
278
- const measurement = baseMeasurement(type, first);
311
+ const deviceUser = (0, observation_coding_1.deviceUserOf)(observations);
312
+ const measurement = { ...baseMeasurement(type, first), ...(deviceUser === undefined ? {} : { memorySlot: deviceUser }) };
279
313
  const value = (code) => firstValue(observations, code);
280
314
  const single = single_value_services_1.singleValueFields.get(type);
281
315
  if (single) {
@@ -291,6 +325,7 @@ const inverseGroup = (type, observations) => {
291
325
  meanArterialPressure: value(MeasurementTypes_1.ObservationCode.MEAN_BLOOD_PRESSURE),
292
326
  heartRate: value(MeasurementTypes_1.ObservationCode.BLOOD_PRESSURE_HEART_RATE),
293
327
  irregularHeartbeat: irregularHeartbeatOf(observations),
328
+ ...bloodPressureStatusOf(observations),
294
329
  };
295
330
  case MeasurementTypes_1.MeasurementTypeKey.bloodOxygenPulseRate:
296
331
  return {
@@ -317,7 +352,7 @@ const inverseGroup = (type, observations) => {
317
352
  ? observation.valueSampledData.data.split(/\s+/).filter(Boolean).map(Number)
318
353
  : [];
319
354
  });
320
- const diagnosticResult = (_d = (_c = first.interpretation) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text;
355
+ const diagnosticResult = (_e = (_d = (_c = observations.find((observation) => { var _a, _b; return (_b = (_a = observation.interpretation) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text; })) === null || _c === void 0 ? void 0 : _c.interpretation) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.text;
321
356
  const duration = observations.reduce((total, observation) => {
322
357
  var _a, _b, _c, _d;
323
358
  return total +
@@ -327,7 +362,7 @@ const inverseGroup = (type, observations) => {
327
362
  ...measurement,
328
363
  measurementTypeKey: type,
329
364
  diagramPoints: points,
330
- heartRate: (_e = value(MeasurementTypes_1.ObservationCode.ECG_HEART_RATE)) !== null && _e !== void 0 ? _e : value(MeasurementTypes_1.ObservationCode.HEART_RATE),
365
+ heartRate: (_f = value(MeasurementTypes_1.ObservationCode.ECG_HEART_RATE)) !== null && _f !== void 0 ? _f : value(MeasurementTypes_1.ObservationCode.HEART_RATE),
331
366
  ...(diagnosticResult ? { diagnosticResult } : {}),
332
367
  ...(duration > 0 ? { duration } : {}),
333
368
  };
@@ -342,7 +377,7 @@ const inverseGroup = (type, observations) => {
342
377
  };
343
378
  for (const observation of observations) {
344
379
  const analyteCode = codeOf(observation);
345
- const component = (_g = (_f = first.code) === null || _f === void 0 ? void 0 : _f.coding) === null || _g === void 0 ? void 0 : _g.find((coding) => coding.code === analyteCode);
380
+ const component = (_h = (_g = first.code) === null || _g === void 0 ? void 0 : _g.coding) === null || _h === void 0 ? void 0 : _h.find((coding) => coding.code === analyteCode);
346
381
  const value = valueOf(observation);
347
382
  const key = analyteByCode[analyteCode !== null && analyteCode !== void 0 ? analyteCode : ""];
348
383
  if (key && typeof value === "number") {
@@ -378,17 +413,35 @@ const inverseGroup = (type, observations) => {
378
413
  const COMPONENT_TYPES = new Set([MeasurementTypes_1.MeasurementTypeKey.respiratoryTherapy, MeasurementTypes_1.MeasurementTypeKey.babySleep]);
379
414
  const codesForType = {
380
415
  ...Object.fromEntries([...single_value_services_1.singleValueFields].map(([type, { code }]) => [type, [code]])),
381
- [MeasurementTypes_1.MeasurementTypeKey.bloodPressure]: [MeasurementTypes_1.ObservationCode.SYSTOLIC_BLOOD_PRESSURE, MeasurementTypes_1.ObservationCode.DIASTOLIC_BLOOD_PRESSURE, MeasurementTypes_1.ObservationCode.MEAN_BLOOD_PRESSURE, MeasurementTypes_1.ObservationCode.BLOOD_PRESSURE_HEART_RATE, MeasurementTypes_1.PulseRhythmCoding.observation],
382
- [MeasurementTypes_1.MeasurementTypeKey.bloodOxygenPulseRate]: [MeasurementTypes_1.ObservationCode.OXYGEN_SATURATION, MeasurementTypes_1.ObservationCode.OXYGEN_SATURATION_HEART_RATE],
416
+ [MeasurementTypes_1.MeasurementTypeKey.bloodPressure]: [
417
+ MeasurementTypes_1.ObservationCode.SYSTOLIC_BLOOD_PRESSURE,
418
+ MeasurementTypes_1.ObservationCode.DIASTOLIC_BLOOD_PRESSURE,
419
+ MeasurementTypes_1.ObservationCode.MEAN_BLOOD_PRESSURE,
420
+ MeasurementTypes_1.ObservationCode.BLOOD_PRESSURE_HEART_RATE,
421
+ MeasurementTypes_1.PulseRhythmCoding.observation,
422
+ (0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.bloodPressure),
423
+ ],
424
+ [MeasurementTypes_1.MeasurementTypeKey.bloodOxygenPulseRate]: [
425
+ MeasurementTypes_1.ObservationCode.OXYGEN_SATURATION,
426
+ MeasurementTypes_1.ObservationCode.OXYGEN_SATURATION_HEART_RATE,
427
+ (0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.bloodOxygenPulseRate),
428
+ ],
383
429
  [MeasurementTypes_1.MeasurementTypeKey.stepCount]: [MeasurementTypes_1.ObservationCode.STEPS],
384
- [MeasurementTypes_1.MeasurementTypeKey.ecg]: [MeasurementTypes_1.ObservationCode.ECG, MeasurementTypes_1.ObservationCode.ECG_HEART_RATE, MeasurementTypes_1.ObservationCode.HEART_RATE],
430
+ [MeasurementTypes_1.MeasurementTypeKey.ecg]: [
431
+ MeasurementTypes_1.ObservationCode.ECG,
432
+ MeasurementTypes_1.ObservationCode.ECG_HEART_RATE,
433
+ MeasurementTypes_1.ObservationCode.HEART_RATE,
434
+ (0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.ecg),
435
+ ],
385
436
  [MeasurementTypes_1.MeasurementTypeKey.uricAcid]: [
386
437
  MeasurementTypes_1.ObservationCode.URIC_ACID,
387
438
  ...MeasurementTypes_1.URINE_ANALYTE_DEFINITIONS.map((analyte) => analyte.code),
439
+ (0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.uricAcid),
388
440
  ],
389
441
  [MeasurementTypes_1.MeasurementTypeKey.urineAnalysis]: [
390
442
  MeasurementTypes_1.ObservationCode.URIC_ACID,
391
443
  ...MeasurementTypes_1.URINE_ANALYTE_DEFINITIONS.map((analyte) => analyte.code),
444
+ (0, reading_group_1.readingGroupCode)(MeasurementTypes_1.MeasurementTypeKey.urineAnalysis),
392
445
  ],
393
446
  [MeasurementTypes_1.MeasurementTypeKey.lipidPanel]: [
394
447
  MeasurementTypes_1.ObservationCode.LIPID_PANEL,
@@ -397,9 +450,16 @@ const codesForType = {
397
450
  [MeasurementTypes_1.MeasurementTypeKey.respiratoryTherapy]: [MeasurementTypes_1.ObservationCode.RESPIRATORY_THERAPY],
398
451
  [MeasurementTypes_1.MeasurementTypeKey.babySleep]: [MeasurementTypes_1.ObservationCode.BABY_SLEEP],
399
452
  };
453
+ /**
454
+ * Returns the comma-separated observation codes to search for the given measurement types.
455
+ *
456
+ * @category measurements
457
+ */
400
458
  const observationCodesForTypes = (types) => [...new Set(types.flatMap((type) => { var _a; return (_a = codesForType[type]) !== null && _a !== void 0 ? _a : []; }))].join(",");
401
459
  exports.observationCodesForTypes = observationCodesForTypes;
402
- /** Converts FHIR observations back into SDK measurements without patient/app assumptions. */
460
+ /**
461
+ * Converts FHIR observations back into SDK measurements without patient/app assumptions.
462
+ */
403
463
  const observationsToMeasurements = (observations, types, options = {}) => {
404
464
  const output = [];
405
465
  types.forEach((type) => {
@@ -1,4 +1,6 @@
1
1
  import type { OvokClient, SaveObservationsOptions, SaveObservationsResult } from "../../ovok-client";
2
2
  import { GenerateObservationBodyParams } from "../types/generate-observation-body/GenerateObservationBodyParams";
3
- /** Framework-free save helper for apps that do not use React hooks. */
3
+ /**
4
+ * Framework-free save helper for apps that do not use React hooks.
5
+ */
4
6
  export declare const saveMeasurement: (client: OvokClient, params: GenerateObservationBodyParams, options?: SaveObservationsOptions) => Promise<SaveObservationsResult>;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.saveMeasurement = void 0;
4
- /** Framework-free save helper for apps that do not use React hooks. */
4
+ /**
5
+ * Framework-free save helper for apps that do not use React hooks.
6
+ */
5
7
  const saveMeasurement = (client, params, options) => client.saveMeasurement(params, options);
6
8
  exports.saveMeasurement = saveMeasurement;
@@ -1,15 +1,19 @@
1
1
  import { Bundle, BundleEntry, Observation } from "@medplum/fhirtypes";
2
+ /**
3
+ * Maximum serialized size, in bytes, of one observation bundle request.
4
+ */
2
5
  export declare const MAX_OBSERVATION_BUNDLE_BYTES = 900000;
6
+ /**
7
+ * Maximum entries of a transaction bundle before it is split into a transaction and a batch.
8
+ */
3
9
  export declare const MAX_CONDITIONAL_OBSERVATION_ENTRIES = 8;
4
10
  /**
5
- * Points every observation after the first at the first, as the first `hasMember` (where readers look). A link to its
6
- * own `id`, as ECG segments carry, is dropped: the server replaces that id on create.
11
+ * Points every observation after the first at the first, as the first `hasMember` (where readers look), and the
12
+ * reading's group, which comes last, at every other observation. A link to its own `id`, as ECG segments carry, is
13
+ * dropped: the server replaces that id on create.
7
14
  */
8
15
  export declare const linkObservationMembers: (observations: Observation[]) => Observation[];
16
+ export declare const createdObservationReference: (response: Bundle, index: number) => string | undefined;
17
+ export declare const rewriteObservationReferences: (entries: BundleEntry[], from: string, to: string) => BundleEntry[];
9
18
  export declare const splitObservationBundleEntries: (bundle: Bundle) => BundleEntry[][] | undefined;
10
19
  export declare const executeObservationBundle: (bundle: Bundle, executeBatch: (bundle: Bundle) => Promise<Bundle>) => Promise<Bundle>;
11
- /**
12
- * Readings' entries packed into as few requests as fit `MAX_OBSERVATION_BUNDLE_BYTES`, each reading whole. A reading
13
- * too big for one request is a request by itself, which `executeObservationBundle` splits.
14
- */
15
- export declare const packObservationGroups: (groups: BundleEntry[][]) => BundleEntry[][][];
@@ -1,14 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packObservationGroups = exports.executeObservationBundle = exports.splitObservationBundleEntries = exports.linkObservationMembers = exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES = exports.MAX_OBSERVATION_BUNDLE_BYTES = void 0;
3
+ exports.executeObservationBundle = exports.splitObservationBundleEntries = exports.rewriteObservationReferences = exports.createdObservationReference = exports.linkObservationMembers = exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES = exports.MAX_OBSERVATION_BUNDLE_BYTES = void 0;
4
4
  const offline_1 = require("../offline");
5
+ const bundle_entry_status_1 = require("./bundle-entry-status");
6
+ const reading_group_1 = require("./reading-group");
7
+ /**
8
+ * Maximum serialized size, in bytes, of one observation bundle request.
9
+ */
5
10
  exports.MAX_OBSERVATION_BUNDLE_BYTES = 900000;
11
+ /**
12
+ * Maximum entries of a transaction bundle before it is split into a transaction and a batch.
13
+ */
6
14
  exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES = 8;
7
15
  /**
8
- * Points every observation after the first at the first, as the first `hasMember` (where readers look). A link to its
9
- * own `id`, as ECG segments carry, is dropped: the server replaces that id on create.
16
+ * Points every observation after the first at the first, as the first `hasMember` (where readers look), and the
17
+ * reading's group, which comes last, at every other observation. A link to its own `id`, as ECG segments carry, is
18
+ * dropped: the server replaces that id on create.
10
19
  */
11
20
  const linkObservationMembers = (observations) => {
21
+ const parts = linkedToFirst(observations.filter((observation) => !(0, reading_group_1.isReadingGroup)(observation)));
22
+ const groups = observations.filter(reading_group_1.isReadingGroup);
23
+ const partReferences = parts.map((part) => ({ reference: `urn:uuid:${(0, offline_1.stableMeasurementId)(part)}` }));
24
+ return [...parts, ...groups.map((group) => ({ ...group, hasMember: partReferences }))];
25
+ };
26
+ exports.linkObservationMembers = linkObservationMembers;
27
+ const linkedToFirst = (observations) => {
12
28
  const main = observations[0];
13
29
  if (!main) {
14
30
  return observations;
@@ -28,7 +44,6 @@ const linkObservationMembers = (observations) => {
28
44
  };
29
45
  });
30
46
  };
31
- exports.linkObservationMembers = linkObservationMembers;
32
47
  const createdObservationReference = (response, index) => {
33
48
  var _a, _b, _c, _d;
34
49
  const entry = (_a = response.entry) === null || _a === void 0 ? void 0 : _a[index];
@@ -42,21 +57,31 @@ const createdObservationReference = (response, index) => {
42
57
  const match = location === null || location === void 0 ? void 0 : location.match(/(?:^|\/)(Observation\/[^/]+)(?:\/_history\/[^/]+)?$/);
43
58
  return match === null || match === void 0 ? void 0 : match[1];
44
59
  };
45
- const rewriteObservationReference = (entry, from, to) => {
46
- var _a;
47
- const resource = entry.resource;
48
- if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) !== "Observation" || !((_a = resource.hasMember) === null || _a === void 0 ? void 0 : _a.length)) {
49
- return entry;
50
- }
51
- return {
52
- ...entry,
53
- resource: {
54
- ...resource,
55
- hasMember: resource.hasMember.map((reference) => reference.reference === from ? { ...reference, reference: to } : reference),
56
- },
57
- };
58
- };
59
- const rewriteObservationReferences = (entries, from, to) => entries.map((entry) => rewriteObservationReference(entry, from, to));
60
+ exports.createdObservationReference = createdObservationReference;
61
+ /** The placeholder other entries of a save use to point at `entry` before the server gives it an id. */
62
+ const placeholderOf = (entry) => { var _a, _b; return (_a = entry.fullUrl) !== null && _a !== void 0 ? _a : (((_b = entry.resource) === null || _b === void 0 ? void 0 : _b.resourceType) === "Observation" ? `urn:uuid:${(0, offline_1.stableMeasurementId)(entry.resource)}` : undefined); };
63
+ /** Points `hasMember` links at the saved observations in `saved`, by placeholder, where an earlier request saved them. */
64
+ const rewriteSavedReferences = (entries, saved) => saved.size === 0
65
+ ? entries
66
+ : entries.map((entry) => {
67
+ var _a;
68
+ const resource = entry.resource;
69
+ if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) !== "Observation" || !((_a = resource.hasMember) === null || _a === void 0 ? void 0 : _a.length)) {
70
+ return entry;
71
+ }
72
+ return {
73
+ ...entry,
74
+ resource: {
75
+ ...resource,
76
+ hasMember: resource.hasMember.map((member) => {
77
+ const reference = member.reference && saved.get(member.reference);
78
+ return reference ? { ...member, reference } : member;
79
+ }),
80
+ },
81
+ };
82
+ });
83
+ const rewriteObservationReferences = (entries, from, to) => rewriteSavedReferences(entries, new Map([[from, to]]));
84
+ exports.rewriteObservationReferences = rewriteObservationReferences;
60
85
  const splitObservationBundleEntries = (bundle) => {
61
86
  var _a;
62
87
  const entries = (_a = bundle.entry) !== null && _a !== void 0 ? _a : [];
@@ -83,48 +108,44 @@ const splitObservationBundleEntries = (bundle) => {
83
108
  };
84
109
  exports.splitObservationBundleEntries = splitObservationBundleEntries;
85
110
  const executeObservationBundle = async (bundle, executeBatch) => {
86
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
111
+ var _a, _b, _c, _d, _e, _f;
87
112
  const entries = (_a = bundle.entry) !== null && _a !== void 0 ? _a : [];
88
113
  if (bundle.type === "transaction" &&
89
114
  entries.length > exports.MAX_CONDITIONAL_OBSERVATION_ENTRIES) {
90
- const rootReference = (_c = (_b = entries[0]) === null || _b === void 0 ? void 0 : _b.fullUrl) !== null && _c !== void 0 ? _c : (((_e = (_d = entries[0]) === null || _d === void 0 ? void 0 : _d.resource) === null || _e === void 0 ? void 0 : _e.resourceType) === "Observation"
91
- ? `urn:uuid:${(0, offline_1.stableMeasurementId)(entries[0].resource)}`
92
- : undefined);
115
+ const rootReference = entries[0] && placeholderOf(entries[0]);
93
116
  const transactionResponse = await (0, exports.executeObservationBundle)({ ...bundle, entry: entries.slice(0, 1) }, executeBatch);
94
117
  const savedRootReference = rootReference
95
- ? createdObservationReference(transactionResponse, 0)
118
+ ? (0, exports.createdObservationReference)(transactionResponse, 0)
96
119
  : undefined;
97
120
  const batchResponse = await (0, exports.executeObservationBundle)({
98
121
  ...bundle,
99
122
  type: "batch",
100
123
  entry: savedRootReference
101
- ? rewriteObservationReferences(entries.slice(1), rootReference, savedRootReference)
124
+ ? (0, exports.rewriteObservationReferences)(entries.slice(1), rootReference, savedRootReference)
102
125
  : entries.slice(1),
103
126
  }, executeBatch);
104
127
  return {
105
128
  resourceType: "Bundle",
106
129
  type: "batch-response",
107
130
  entry: [
108
- ...((_f = transactionResponse.entry) !== null && _f !== void 0 ? _f : []),
109
- ...((_g = batchResponse.entry) !== null && _g !== void 0 ? _g : []),
131
+ ...((_b = transactionResponse.entry) !== null && _b !== void 0 ? _b : []),
132
+ ...((_c = batchResponse.entry) !== null && _c !== void 0 ? _c : []),
110
133
  ],
111
134
  };
112
135
  }
113
136
  const chunks = (0, exports.splitObservationBundleEntries)(bundle);
114
137
  if (chunks) {
115
138
  const responses = [];
116
- const rootReference = (_j = (_h = entries[0]) === null || _h === void 0 ? void 0 : _h.fullUrl) !== null && _j !== void 0 ? _j : (((_l = (_k = entries[0]) === null || _k === void 0 ? void 0 : _k.resource) === null || _l === void 0 ? void 0 : _l.resourceType) === "Observation"
117
- ? `urn:uuid:${(0, offline_1.stableMeasurementId)(entries[0].resource)}`
118
- : undefined);
119
- let savedRootReference;
120
- for (const [index, entry] of chunks.entries()) {
121
- const chunkEntries = index > 0 && rootReference && savedRootReference
122
- ? rewriteObservationReferences(entry, rootReference, savedRootReference)
123
- : entry;
124
- const response = await (0, exports.executeObservationBundle)({ ...bundle, entry: chunkEntries }, executeBatch);
125
- if (index === 0 && rootReference) {
126
- savedRootReference = createdObservationReference(response, 0);
127
- }
139
+ const saved = new Map();
140
+ for (const chunk of chunks) {
141
+ const response = await (0, exports.executeObservationBundle)({ ...bundle, entry: rewriteSavedReferences(chunk, saved) }, executeBatch);
142
+ chunk.forEach((entry, index) => {
143
+ const placeholder = placeholderOf(entry);
144
+ const reference = (0, exports.createdObservationReference)(response, index);
145
+ if (placeholder && reference) {
146
+ saved.set(placeholder, reference);
147
+ }
148
+ });
128
149
  responses.push(response);
129
150
  }
130
151
  return {
@@ -134,40 +155,9 @@ const executeObservationBundle = async (bundle, executeBatch) => {
134
155
  };
135
156
  }
136
157
  const response = await executeBatch(bundle);
137
- if (((_o = (_m = response.entry) === null || _m === void 0 ? void 0 : _m.length) !== null && _o !== void 0 ? _o : 0) !== entries.length ||
138
- ((_p = response.entry) === null || _p === void 0 ? void 0 : _p.some((entry) => {
139
- var _a, _b;
140
- const status = (_b = (_a = entry.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : "";
141
- return status.startsWith("4") || status.startsWith("5");
142
- }))) {
158
+ if (((_e = (_d = response.entry) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) !== entries.length || ((_f = response.entry) === null || _f === void 0 ? void 0 : _f.some(bundle_entry_status_1.isFailedEntry))) {
143
159
  throw response;
144
160
  }
145
161
  return response;
146
162
  };
147
163
  exports.executeObservationBundle = executeObservationBundle;
148
- /**
149
- * Readings' entries packed into as few requests as fit `MAX_OBSERVATION_BUNDLE_BYTES`, each reading whole. A reading
150
- * too big for one request is a request by itself, which `executeObservationBundle` splits.
151
- */
152
- const packObservationGroups = (groups) => {
153
- const envelope = JSON.stringify({ resourceType: "Bundle", type: "batch", entry: [] }).length;
154
- const requests = [];
155
- let request = [];
156
- let size = envelope;
157
- for (const group of groups) {
158
- // Each entry adds its JSON and a separating comma.
159
- const groupSize = group.reduce((total, entry) => total + JSON.stringify(entry).length + 1, 0);
160
- if (request.length > 0 && size + groupSize > exports.MAX_OBSERVATION_BUNDLE_BYTES) {
161
- requests.push(request);
162
- request = [];
163
- size = envelope;
164
- }
165
- request.push(group);
166
- size += groupSize;
167
- }
168
- if (request.length > 0) {
169
- requests.push(request);
170
- }
171
- return requests;
172
- };
173
- exports.packObservationGroups = packObservationGroups;
@@ -0,0 +1,12 @@
1
+ import { CodeableConcept, Observation, Quantity } from "@medplum/fhirtypes";
2
+ import { MeasurementTypeKey } from "./types/MeasurementTypeKey";
3
+ /** A quantity in `unit`, coded in UCUM when the unit has a UCUM code. */
4
+ export declare const ucumQuantity: (value: number, unit: string) => Quantity;
5
+ /** The FHIR observation category of a measurement type; vital signs unless it is a test, procedure or activity. */
6
+ export declare const observationCategory: (type: MeasurementTypeKey) => CodeableConcept[] | undefined;
7
+ /** The status and category every saved reading carries: a device result is final. */
8
+ export declare const readingStatusAndCategory: (type: MeasurementTypeKey) => Pick<Observation, "status" | "category">;
9
+ /** Marks a reading's first observation with the device user (the monitor's memory slot) who took it. */
10
+ export declare const withDeviceUser: (observations: Observation[], memorySlot: unknown) => Observation[];
11
+ /** The device user a reading was saved with, from whichever of its observations carries it. */
12
+ export declare const deviceUserOf: (observations: readonly Observation[]) => number | undefined;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deviceUserOf = exports.withDeviceUser = exports.readingStatusAndCategory = exports.observationCategory = exports.ucumQuantity = void 0;
4
+ const fhir_systems_1 = require("./fhir-systems");
5
+ const MeasurementTypeKey_1 = require("./types/MeasurementTypeKey");
6
+ const UCUM_CODES = {
7
+ "%": "%",
8
+ "°C": "Cel",
9
+ bpm: "/min",
10
+ "breaths/min": "/min",
11
+ kg: "kg",
12
+ "mg/dL": "mg/dL",
13
+ "mL/kg/min": "mL/kg/min",
14
+ mmHg: "mm[Hg]",
15
+ ms: "ms",
16
+ mV: "mV",
17
+ s: "s",
18
+ steps: "{steps}",
19
+ };
20
+ /** A quantity in `unit`, coded in UCUM when the unit has a UCUM code. */
21
+ const ucumQuantity = (value, unit) => {
22
+ const code = UCUM_CODES[unit];
23
+ return code ? { value, unit, system: fhir_systems_1.UCUM_SYSTEM, code } : { value, unit };
24
+ };
25
+ exports.ucumQuantity = ucumQuantity;
26
+ const CATEGORY_BY_TYPE = {
27
+ [MeasurementTypeKey_1.MeasurementTypeKey.bloodGlucose]: "laboratory",
28
+ [MeasurementTypeKey_1.MeasurementTypeKey.urineAnalysis]: "laboratory",
29
+ [MeasurementTypeKey_1.MeasurementTypeKey.uricAcid]: "laboratory",
30
+ [MeasurementTypeKey_1.MeasurementTypeKey.lipidPanel]: "laboratory",
31
+ [MeasurementTypeKey_1.MeasurementTypeKey.ecg]: "procedure",
32
+ [MeasurementTypeKey_1.MeasurementTypeKey.spirometryPanel]: "procedure",
33
+ [MeasurementTypeKey_1.MeasurementTypeKey.stepCount]: "activity",
34
+ [MeasurementTypeKey_1.MeasurementTypeKey.babySleep]: "activity",
35
+ [MeasurementTypeKey_1.MeasurementTypeKey.symptomQuestionnaire]: "survey",
36
+ [MeasurementTypeKey_1.MeasurementTypeKey.respiratoryTherapy]: "therapy",
37
+ [MeasurementTypeKey_1.MeasurementTypeKey.photoUpload]: undefined,
38
+ };
39
+ /** The FHIR observation category of a measurement type; vital signs unless it is a test, procedure or activity. */
40
+ const observationCategory = (type) => {
41
+ const code = type in CATEGORY_BY_TYPE ? CATEGORY_BY_TYPE[type] : "vital-signs";
42
+ return code ? [{ coding: [{ system: fhir_systems_1.OBSERVATION_CATEGORY_SYSTEM, code }] }] : undefined;
43
+ };
44
+ exports.observationCategory = observationCategory;
45
+ const DEVICE_USER_URL = `${fhir_systems_1.OVOK_EXTENSION_BASE_URL}/device-user`;
46
+ /** The status and category every saved reading carries: a device result is final. */
47
+ const readingStatusAndCategory = (type) => {
48
+ const category = (0, exports.observationCategory)(type);
49
+ return { status: "final", ...(category ? { category } : {}) };
50
+ };
51
+ exports.readingStatusAndCategory = readingStatusAndCategory;
52
+ /** Marks a reading's first observation with the device user (the monitor's memory slot) who took it. */
53
+ const withDeviceUser = (observations, memorySlot) => typeof memorySlot === "number" && Number.isInteger(memorySlot)
54
+ ? observations.map((observation, index) => {
55
+ var _a;
56
+ return index === 0
57
+ ? { ...observation, extension: [...((_a = observation.extension) !== null && _a !== void 0 ? _a : []), { url: DEVICE_USER_URL, valueInteger: memorySlot }] }
58
+ : observation;
59
+ })
60
+ : observations;
61
+ exports.withDeviceUser = withDeviceUser;
62
+ /** The device user a reading was saved with, from whichever of its observations carries it. */
63
+ const deviceUserOf = (observations) => {
64
+ var _a;
65
+ return (_a = observations
66
+ .flatMap((observation) => { var _a; return (_a = observation.extension) !== null && _a !== void 0 ? _a : []; })
67
+ .find((extension) => extension.url === DEVICE_USER_URL)) === null || _a === void 0 ? void 0 : _a.valueInteger;
68
+ };
69
+ exports.deviceUserOf = deviceUserOf;
@@ -0,0 +1,12 @@
1
+ import { Bundle, BundleEntry } from "@medplum/fhirtypes";
2
+ /**
3
+ * Readings' entries packed into as few requests as fit `MAX_OBSERVATION_BUNDLE_BYTES`, each reading whole. A reading
4
+ * too big for one request is a request by itself, which `executeObservationBundle` splits.
5
+ */
6
+ export declare const packObservationGroups: (groups: BundleEntry[][]) => BundleEntry[][][];
7
+ /**
8
+ * Saves several readings as two batches, every main observation first, so a reading's other observations only ever
9
+ * point at a main observation the server saved. A main that matched several saved copies keeps the members saved
10
+ * with them.
11
+ */
12
+ export declare const executeReadingsBatch: (groups: BundleEntry[][], executeBatch: (bundle: Bundle) => Promise<Bundle>) => Promise<Bundle>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeReadingsBatch = exports.packObservationGroups = void 0;
4
+ const observation_bundle_utils_1 = require("./observation-bundle-utils");
5
+ /**
6
+ * Readings' entries packed into as few requests as fit `MAX_OBSERVATION_BUNDLE_BYTES`, each reading whole. A reading
7
+ * too big for one request is a request by itself, which `executeObservationBundle` splits.
8
+ */
9
+ const packObservationGroups = (groups) => {
10
+ const envelope = JSON.stringify({ resourceType: "Bundle", type: "batch", entry: [] }).length;
11
+ const requests = [];
12
+ let request = [];
13
+ let size = envelope;
14
+ for (const group of groups) {
15
+ // Each entry adds its JSON and a separating comma.
16
+ const groupSize = group.reduce((total, entry) => total + JSON.stringify(entry).length + 1, 0);
17
+ if (request.length > 0 && size + groupSize > observation_bundle_utils_1.MAX_OBSERVATION_BUNDLE_BYTES) {
18
+ requests.push(request);
19
+ request = [];
20
+ size = envelope;
21
+ }
22
+ request.push(group);
23
+ size += groupSize;
24
+ }
25
+ if (request.length > 0) {
26
+ requests.push(request);
27
+ }
28
+ return requests;
29
+ };
30
+ exports.packObservationGroups = packObservationGroups;
31
+ /**
32
+ * Saves several readings as two batches, every main observation first, so a reading's other observations only ever
33
+ * point at a main observation the server saved. A main that matched several saved copies keeps the members saved
34
+ * with them.
35
+ */
36
+ const executeReadingsBatch = async (groups, executeBatch) => {
37
+ var _a, _b;
38
+ const mains = await (0, observation_bundle_utils_1.executeObservationBundle)({ resourceType: "Bundle", type: "batch", entry: groups.flatMap((group) => group.slice(0, 1)) }, executeBatch);
39
+ const members = groups.flatMap((group, index) => {
40
+ var _a;
41
+ const placeholder = (_a = group[0]) === null || _a === void 0 ? void 0 : _a.fullUrl;
42
+ const saved = (0, observation_bundle_utils_1.createdObservationReference)(mains, index);
43
+ return placeholder && saved ? (0, observation_bundle_utils_1.rewriteObservationReferences)(group.slice(1), placeholder, saved) : [];
44
+ });
45
+ if (members.length === 0) {
46
+ return mains;
47
+ }
48
+ const rest = await (0, observation_bundle_utils_1.executeObservationBundle)({ resourceType: "Bundle", type: "batch", entry: members }, executeBatch);
49
+ return { resourceType: "Bundle", type: "batch-response", entry: [...((_a = mains.entry) !== null && _a !== void 0 ? _a : []), ...((_b = rest.entry) !== null && _b !== void 0 ? _b : [])] };
50
+ };
51
+ exports.executeReadingsBatch = executeReadingsBatch;
@@ -0,0 +1,13 @@
1
+ import { BundleEntry, Observation } from "@medplum/fhirtypes";
2
+ import { MeasurementTypeKey } from "./types/MeasurementTypeKey";
3
+ /** Identifies a group created for a reading saved before groups existed, by its first observation's id. */
4
+ export declare const READING_GROUP_OF_SYSTEM = "https://sdk.ovok.com/fhir/reading-group-of";
5
+ /** The measurement types whose readings get a group, for the code search that loads them. */
6
+ export declare const GROUPED_MEASUREMENT_TYPES: MeasurementTypeKey[];
7
+ /**
8
+ * The groups that readings saved before groups existed are missing: one for each first observation that later parts
9
+ * point at, that no group covers yet, and whose type has a group. Pass every observation of one patient's readings.
10
+ */
11
+ export declare const missingReadingGroups: (observations: readonly Observation[]) => Observation[];
12
+ /** Bundle entries that create each group only if none was created for its reading before. */
13
+ export declare const readingGroupEntries: (groups: readonly Observation[]) => BundleEntry<Observation>[];