@ovok/core 0.4.49-dev.522 → 0.4.49-dev.524

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.
@@ -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>[];
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readingGroupEntries = exports.missingReadingGroups = exports.GROUPED_MEASUREMENT_TYPES = exports.READING_GROUP_OF_SYSTEM = void 0;
4
+ const observation_coding_1 = require("./observation-coding");
5
+ const reading_group_1 = require("./reading-group");
6
+ const MeasurementTypeKey_1 = require("./types/MeasurementTypeKey");
7
+ const ObservationCode_1 = require("./types/ObservationCode");
8
+ const UrineAnalytes_1 = require("./types/UrineAnalytes");
9
+ /** Identifies a group created for a reading saved before groups existed, by its first observation's id. */
10
+ exports.READING_GROUP_OF_SYSTEM = "https://sdk.ovok.com/fhir/reading-group-of";
11
+ const TYPE_BY_FIRST_CODE = new Map([
12
+ [ObservationCode_1.ObservationCode.SYSTOLIC_BLOOD_PRESSURE, MeasurementTypeKey_1.MeasurementTypeKey.bloodPressure],
13
+ [ObservationCode_1.ObservationCode.OXYGEN_SATURATION, MeasurementTypeKey_1.MeasurementTypeKey.bloodOxygenPulseRate],
14
+ [ObservationCode_1.ObservationCode.ECG, MeasurementTypeKey_1.MeasurementTypeKey.ecg],
15
+ ...UrineAnalytes_1.URINE_ANALYTE_DEFINITIONS.map(({ code }) => [code, MeasurementTypeKey_1.MeasurementTypeKey.urineAnalysis]),
16
+ ]);
17
+ /** The measurement types whose readings get a group, for the code search that loads them. */
18
+ exports.GROUPED_MEASUREMENT_TYPES = [...new Set(TYPE_BY_FIRST_CODE.values())];
19
+ const referencedId = (reference) => { var _a; return (_a = reference === null || reference === void 0 ? void 0 : reference.match(/^Observation\/(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]; };
20
+ const firstIdOf = (observation) => { var _a, _b; return referencedId((_b = (_a = observation.hasMember) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.reference); };
21
+ const codeOf = (observation) => { var _a, _b, _c; return (_c = (_b = (_a = observation.code) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code; };
22
+ /** The ids of first observations a group already points at. */
23
+ const groupedFirstIds = (observations) => new Set(observations
24
+ .filter(reading_group_1.isReadingGroup)
25
+ .flatMap((group) => { var _a; return (_a = group.hasMember) !== null && _a !== void 0 ? _a : []; })
26
+ .flatMap(({ reference }) => { var _a; return (_a = referencedId(reference)) !== null && _a !== void 0 ? _a : []; }));
27
+ /** Each first observation that later parts point at, with those parts, in saved order. */
28
+ const readingsByFirst = (observations) => {
29
+ var _a, _b;
30
+ const byId = new Map(observations.flatMap((observation) => (observation.id ? [[observation.id, observation]] : [])));
31
+ const readings = new Map();
32
+ for (const observation of observations) {
33
+ const first = byId.get((_a = firstIdOf(observation)) !== null && _a !== void 0 ? _a : "");
34
+ if (first && !(0, reading_group_1.isReadingGroup)(observation)) {
35
+ readings.set(first, [...((_b = readings.get(first)) !== null && _b !== void 0 ? _b : [first]), observation]);
36
+ }
37
+ }
38
+ return readings;
39
+ };
40
+ const groupFor = (type, parts) => {
41
+ var _a;
42
+ const group = (0, reading_group_1.readingGroupOf)(type, parts);
43
+ const firstId = (_a = parts[0]) === null || _a === void 0 ? void 0 : _a.id;
44
+ return group && firstId
45
+ ? {
46
+ ...group,
47
+ ...(0, observation_coding_1.readingStatusAndCategory)(type),
48
+ identifier: [{ system: exports.READING_GROUP_OF_SYSTEM, value: firstId }],
49
+ hasMember: parts.map(({ id }) => ({ reference: `Observation/${id}` })),
50
+ }
51
+ : undefined;
52
+ };
53
+ /**
54
+ * The groups that readings saved before groups existed are missing: one for each first observation that later parts
55
+ * point at, that no group covers yet, and whose type has a group. Pass every observation of one patient's readings.
56
+ */
57
+ const missingReadingGroups = (observations) => {
58
+ const grouped = groupedFirstIds(observations);
59
+ return [...readingsByFirst(observations)].flatMap(([first, parts]) => {
60
+ var _a;
61
+ const type = TYPE_BY_FIRST_CODE.get((_a = codeOf(first)) !== null && _a !== void 0 ? _a : "");
62
+ const group = type && first.id && !grouped.has(first.id) ? groupFor(type, parts) : undefined;
63
+ return group ? [group] : [];
64
+ });
65
+ };
66
+ exports.missingReadingGroups = missingReadingGroups;
67
+ /** Bundle entries that create each group only if none was created for its reading before. */
68
+ const readingGroupEntries = (groups) => groups.map((group) => {
69
+ var _a, _b, _c;
70
+ return ({
71
+ request: {
72
+ method: "POST",
73
+ url: "Observation",
74
+ ifNoneExist: `identifier=${encodeURIComponent(`${exports.READING_GROUP_OF_SYSTEM}|${(_c = (_b = (_a = group.identifier) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : ""}`)}`,
75
+ },
76
+ resource: group,
77
+ });
78
+ });
79
+ exports.readingGroupEntries = readingGroupEntries;
@@ -20,11 +20,10 @@ const PANEL_BY_TYPE = {
20
20
  [MeasurementTypeKey_1.MeasurementTypeKey.uricAcid]: URINE_DIPSTICK_PANEL,
21
21
  };
22
22
  const PANEL_CODES = new Set([BLOOD_PRESSURE_PANEL.code, URINE_DIPSTICK_PANEL.code]);
23
- /** The blood-pressure values a panel repeats as components, so it reads on its own. */
23
+ /** The pressures a panel repeats as components, as the vital-signs profile requires; a share must cover both. */
24
24
  const BLOOD_PRESSURE_COMPONENT_CODES = [
25
25
  ObservationCode_1.ObservationCode.SYSTOLIC_BLOOD_PRESSURE,
26
26
  ObservationCode_1.ObservationCode.DIASTOLIC_BLOOD_PRESSURE,
27
- ObservationCode_1.ObservationCode.MEAN_BLOOD_PRESSURE,
28
27
  ];
29
28
  /** The code of a reading's group: its LOINC panel where one exists, else Ovok's measurement-type code. */
30
29
  const readingGroupCoding = (type) => { var _a; return (_a = PANEL_BY_TYPE[type]) !== null && _a !== void 0 ? _a : { system: fhir_systems_1.MEASUREMENT_TYPE_SYSTEM, code: type }; };
@@ -26,7 +26,7 @@ exports.OVOK_CORE_REQUIREMENTS = {
26
26
  description: "The FHIR surface a server must provide for the @ovok/core client library's own methods to function.",
27
27
  software: {
28
28
  name: "@ovok/core",
29
- version: "0.4.49-dev.522+9825307",
29
+ version: "0.4.49-dev.524+a989d15",
30
30
  },
31
31
  fhirVersion: "4.0.1",
32
32
  format: ["json"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ovok/core",
3
- "version": "0.4.49-dev.522+9825307",
3
+ "version": "0.4.49-dev.524+a989d15",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",