@ovok/core 0.4.49-rc.6 → 0.4.49-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,9 @@ import { MeasurementField } from "./types/service/MeasurementField";
3
3
  /**
4
4
  * For each measurement type the SDK stores, its properties as their Observations store them: the
5
5
  * code (LOINC), unit and decimals of each, the main one first. Apps read codes and units here rather
6
- * than keeping their own table. Lipid panels, respiratory therapy and baby sleep list none: their
7
- * values are components rather than fixed properties (see `URINE_ANALYTE_DEFINITIONS` for urine).
6
+ * than keeping their own table. Lipid panels, spirometry, respiratory therapy and baby sleep list
7
+ * none: their values are components rather than fixed properties (see `URINE_ANALYTE_DEFINITIONS`
8
+ * for urine).
8
9
  */
9
10
  export declare const MEASUREMENT_FIELDS: Readonly<Partial<Record<MeasurementTypeKey, readonly MeasurementField[]>>>;
10
11
  export type { MeasurementField };
@@ -6,7 +6,8 @@ const services = creator_1.ObservationServiceCreator.getInstance();
6
6
  /**
7
7
  * For each measurement type the SDK stores, its properties as their Observations store them: the
8
8
  * code (LOINC), unit and decimals of each, the main one first. Apps read codes and units here rather
9
- * than keeping their own table. Lipid panels, respiratory therapy and baby sleep list none: their
10
- * values are components rather than fixed properties (see `URINE_ANALYTE_DEFINITIONS` for urine).
9
+ * than keeping their own table. Lipid panels, spirometry, respiratory therapy and baby sleep list
10
+ * none: their values are components rather than fixed properties (see `URINE_ANALYTE_DEFINITIONS`
11
+ * for urine).
11
12
  */
12
13
  exports.MEASUREMENT_FIELDS = Object.fromEntries(services.getTypes().map((type) => [type, services.getService(type).getFields()]));
@@ -20,7 +20,10 @@ const UCUM_CODES = {
20
20
  /** A quantity in `unit`, coded in UCUM when the unit has a UCUM code. */
21
21
  const ucumQuantity = (value, unit) => {
22
22
  const code = UCUM_CODES[unit];
23
- return code ? { value, unit, system: fhir_systems_1.UCUM_SYSTEM, code } : { value, unit };
23
+ if (code) {
24
+ return { value, unit, system: fhir_systems_1.UCUM_SYSTEM, code };
25
+ }
26
+ return unit ? { value, unit } : { value };
24
27
  };
25
28
  exports.ucumQuantity = ucumQuantity;
26
29
  const CATEGORY_BY_TYPE = {
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseObservationService = void 0;
4
+ const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
4
5
  const fhir_systems_1 = require("../fhir-systems");
5
6
  const observation_coding_1 = require("../observation-coding");
6
7
  const measurement_time_1 = require("./measurement-time");
8
+ /** Waveforms are coded in the ISO/IEEE 11073 nomenclature, everything else in LOINC. */
9
+ const MDC_CODES = new Set([MeasurementTypes_1.ObservationCode.ECG, MeasurementTypes_1.ObservationCode.PULSE_WAVE]);
10
+ const systemOf = (code) => (MDC_CODES.has(code) ? fhir_systems_1.MDC_SYSTEM : fhir_systems_1.LOINC_SYSTEM);
7
11
  class BaseObservationService {
8
12
  getFields() {
9
13
  return this.observationMetadata.map(({ valueKey, primaryCode, unit, toFixed, display }) => ({
@@ -41,12 +45,12 @@ class BaseObservationService {
41
45
  {
42
46
  code: metadata.primaryCode,
43
47
  display: metadata.display,
44
- system: fhir_systems_1.LOINC_SYSTEM,
48
+ system: systemOf(metadata.primaryCode),
45
49
  },
46
50
  ...metadata.additionalCodes.map((code) => ({
47
51
  code,
48
52
  display: metadata.display,
49
- system: fhir_systems_1.LOINC_SYSTEM,
53
+ system: systemOf(code),
50
54
  })),
51
55
  ],
52
56
  text: metadata.display,
@@ -25,6 +25,14 @@ class BloodOxygenService extends base_observation_service_1.BaseObservationServi
25
25
  valueKey: "pulseRate",
26
26
  toFixed: 0,
27
27
  },
28
+ {
29
+ primaryCode: MeasurementTypes_1.ObservationCode.PULSE_WAVE,
30
+ additionalCodes: [],
31
+ display: "Pulse wave",
32
+ unit: "",
33
+ valueKey: "pulseWave",
34
+ toFixed: 0,
35
+ },
28
36
  ];
29
37
  }
30
38
  getMeasurementDisplay(measurement) {
@@ -8,6 +8,7 @@ const component_observation_services_1 = require("./component-observation-servic
8
8
  const ecg_1 = require("./ecg");
9
9
  const lipid_panel_1 = require("./lipid-panel");
10
10
  const single_value_services_1 = require("./single-value-services");
11
+ const spirometry_1 = require("./spirometry");
11
12
  const step_count_1 = require("./step-count");
12
13
  const uric_acid_service_1 = require("./uric-acid-service");
13
14
  /**
@@ -25,6 +26,7 @@ class ObservationServiceCreator {
25
26
  [MeasurementTypes_1.MeasurementTypeKey.urineAnalysis, uricAcid],
26
27
  [MeasurementTypes_1.MeasurementTypeKey.uricAcid, uricAcid],
27
28
  [MeasurementTypes_1.MeasurementTypeKey.lipidPanel, new lipid_panel_1.LipidPanelService()],
29
+ [MeasurementTypes_1.MeasurementTypeKey.spirometryPanel, new spirometry_1.SpirometryService()],
28
30
  [MeasurementTypes_1.MeasurementTypeKey.respiratoryTherapy, (0, component_observation_services_1.respiratoryTherapyService)()],
29
31
  [MeasurementTypes_1.MeasurementTypeKey.babySleep, (0, component_observation_services_1.babySleepService)()],
30
32
  ]);
@@ -1,4 +1,4 @@
1
- import { CodeableConcept, Observation } from "@medplum/fhirtypes";
1
+ import { Observation } from "@medplum/fhirtypes";
2
2
  import { EcgMeasurement, Measurement, MeasurementTypeKey } from "../../../types/MeasurementTypes";
3
3
  import { ObservationFragment } from "../types/generate-observation-body/ObservationFragment";
4
4
  import { ObservationValue } from "../types/generate-observation-body/ObservationValue";
@@ -12,8 +12,6 @@ export declare class EcgService extends BaseObservationService<EcgMeasurement> {
12
12
  /** Expand long recordings into bounded, timestamped observations. */
13
13
  generateObservationFragments(measurement: Measurement): ObservationFragment[];
14
14
  getAdditionalProperties(measurement: Measurement): Partial<Observation>[];
15
- /** The waveform is coded in the ISO/IEEE 11073 nomenclature, not LOINC. */
16
- getObservationCodes(): CodeableConcept[];
17
15
  getMeasurementDisplay(measurement: Measurement): string;
18
16
  getObservationDisplay(observations: Observation[]): string | undefined;
19
17
  convertSamplesToMeasurement(): EcgMeasurement;
@@ -92,16 +92,6 @@ class EcgService extends base_observation_service_1.BaseObservationService {
92
92
  ];
93
93
  return additionalProperties;
94
94
  }
95
- /** The waveform is coded in the ISO/IEEE 11073 nomenclature, not LOINC. */
96
- getObservationCodes() {
97
- return super.getObservationCodes().map((concept) => {
98
- var _a;
99
- return ({
100
- ...concept,
101
- coding: (_a = concept.coding) === null || _a === void 0 ? void 0 : _a.map((coding) => coding.code === MeasurementTypes_1.ObservationCode.ECG ? { ...coding, system: fhir_systems_1.MDC_SYSTEM } : coding),
102
- });
103
- });
104
- }
105
95
  getMeasurementDisplay(measurement) {
106
96
  const castedMeasurement = this.getCastedMeasurement(measurement);
107
97
  return castedMeasurement.diagnosticResult || "Unknown";
@@ -0,0 +1,22 @@
1
+ import { CodeableConcept, Observation } from "@medplum/fhirtypes";
2
+ import { Measurement, MeasurementTypeKey, SpirometryMeasurement } from "../../../types/MeasurementTypes";
3
+ import { RecordResult, RecordType } from "../types/generate-measurement/HealthConnectTypes";
4
+ import { Sample } from "../types/generate-measurement/Sample";
5
+ import { ObservationFragment } from "../types/generate-observation-body/ObservationFragment";
6
+ import { ObservationValue } from "../types/generate-observation-body/ObservationValue";
7
+ import { ObservationMetadata } from "../types/service/ObservationMetadata";
8
+ import { BaseObservationService } from "./base-observation-service";
9
+ export declare class SpirometryService extends BaseObservationService<SpirometryMeasurement> {
10
+ protected measurementTypeKey: MeasurementTypeKey;
11
+ protected measurementTypeName: string;
12
+ protected observationMetadata: ObservationMetadata<SpirometryMeasurement>[];
13
+ generateObservationFragments(measurement: Measurement): ObservationFragment[];
14
+ getObservationCodes(): CodeableConcept[];
15
+ getAdditionalProperties(measurement: Measurement): Partial<Observation>[];
16
+ generateValues(_measurement: Measurement): ObservationValue[];
17
+ getUnits(): string[];
18
+ getMeasurementDisplay(measurement: Measurement): string;
19
+ getObservationDisplay(observations: Observation[]): string | undefined;
20
+ convertSamplesToMeasurement(_samples: Sample[]): SpirometryMeasurement;
21
+ convertRecordToMeasurement(_record: RecordResult<RecordType>): SpirometryMeasurement;
22
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpirometryService = void 0;
4
+ const MeasurementTypes_1 = require("../../../types/MeasurementTypes");
5
+ const fhir_systems_1 = require("../fhir-systems");
6
+ const base_observation_service_1 = require("./base-observation-service");
7
+ const measurement_time_1 = require("./measurement-time");
8
+ const LITRES = "L";
9
+ const LITRES_PER_SECOND = "L/s";
10
+ const PERCENT = "%";
11
+ const COMPONENTS = [
12
+ { key: "fvc", display: "FVC", code: MeasurementTypes_1.ObservationCode.FVC, unit: LITRES },
13
+ { key: "fev1", display: "FEV1", code: MeasurementTypes_1.ObservationCode.FEV1, unit: LITRES },
14
+ { key: "fev0.5", display: "FEV0.5", code: MeasurementTypes_1.ObservationCode.FEV0_5, unit: LITRES },
15
+ { key: "fev1/fvc", display: "FEV1/FVC", code: MeasurementTypes_1.ObservationCode.FEV1_FVC_RATIO, unit: PERCENT },
16
+ { key: "pef", display: "PEF", code: MeasurementTypes_1.ObservationCode.PEF, unit: LITRES_PER_SECOND },
17
+ { key: "fef25", display: "FEF25", code: MeasurementTypes_1.ObservationCode.FEF25, unit: LITRES_PER_SECOND },
18
+ { key: "fef50", display: "FEF50", code: MeasurementTypes_1.ObservationCode.FEF50, unit: LITRES_PER_SECOND },
19
+ { key: "fef75", display: "FEF75", code: MeasurementTypes_1.ObservationCode.FEF75, unit: LITRES_PER_SECOND },
20
+ { key: "fef2575", display: "FEF25-75", code: MeasurementTypes_1.ObservationCode.FEF25_75, unit: LITRES_PER_SECOND },
21
+ ];
22
+ const PANEL_CODE = {
23
+ coding: [{
24
+ code: MeasurementTypes_1.ObservationCode.SPIROMETRY_PANEL,
25
+ display: "Spirometry panel",
26
+ system: fhir_systems_1.LOINC_SYSTEM,
27
+ }],
28
+ };
29
+ class SpirometryService extends base_observation_service_1.BaseObservationService {
30
+ constructor() {
31
+ super(...arguments);
32
+ this.measurementTypeKey = MeasurementTypes_1.MeasurementTypeKey.spirometryPanel;
33
+ this.measurementTypeName = "spirometry";
34
+ this.observationMetadata = [];
35
+ }
36
+ generateObservationFragments(measurement) {
37
+ const spirometry = this.getCastedMeasurement(measurement);
38
+ const components = COMPONENTS.flatMap(({ key, display, code, unit }) => {
39
+ const value = spirometry[key];
40
+ if (typeof value !== "number" || !Number.isFinite(value)) {
41
+ return [];
42
+ }
43
+ return [{
44
+ code: { coding: [{ code, display, system: fhir_systems_1.LOINC_SYSTEM }], text: display },
45
+ valueQuantity: { value, unit, code: unit, system: fhir_systems_1.UCUM_SYSTEM },
46
+ }];
47
+ });
48
+ if (components.length === 0) {
49
+ return [];
50
+ }
51
+ return [{
52
+ code: PANEL_CODE,
53
+ additionalProperties: {
54
+ effectiveDateTime: (0, measurement_time_1.recordedAtOrNow)(spirometry).toISOString(),
55
+ component: components,
56
+ },
57
+ }];
58
+ }
59
+ getObservationCodes() {
60
+ return [PANEL_CODE];
61
+ }
62
+ getAdditionalProperties(measurement) {
63
+ return [{ effectiveDateTime: (0, measurement_time_1.recordedAtOrNow)(this.getCastedMeasurement(measurement)).toISOString() }];
64
+ }
65
+ generateValues(_measurement) {
66
+ return [];
67
+ }
68
+ getUnits() {
69
+ return [LITRES, LITRES_PER_SECOND, PERCENT];
70
+ }
71
+ getMeasurementDisplay(measurement) {
72
+ const spirometry = this.getCastedMeasurement(measurement);
73
+ return COMPONENTS.flatMap(({ key, display, unit }) => {
74
+ const value = spirometry[key];
75
+ return value === undefined ? [] : [`${display}: ${value} ${unit}`];
76
+ }).join(", ");
77
+ }
78
+ getObservationDisplay(observations) {
79
+ const components = observations.flatMap((observation) => { var _a; return (_a = observation.component) !== null && _a !== void 0 ? _a : []; });
80
+ const values = components.flatMap(({ code, valueQuantity }) => {
81
+ var _a, _b, _c;
82
+ const display = (_a = code.text) !== null && _a !== void 0 ? _a : (_c = (_b = code.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.display;
83
+ return display && typeof (valueQuantity === null || valueQuantity === void 0 ? void 0 : valueQuantity.value) === "number"
84
+ ? [`${display}: ${valueQuantity.value} ${valueQuantity.unit}`]
85
+ : [];
86
+ });
87
+ return values.length ? values.join(", ") : undefined;
88
+ }
89
+ convertSamplesToMeasurement(_samples) {
90
+ throw new Error("Spirometry samples are not supported.");
91
+ }
92
+ convertRecordToMeasurement(_record) {
93
+ throw new Error("Spirometry Health Connect records are not supported.");
94
+ }
95
+ }
96
+ exports.SpirometryService = SpirometryService;
@@ -38,10 +38,30 @@ export declare enum ObservationCode {
38
38
  BODY_TEMPERATURE = "8310-5",
39
39
  /** ECG waveform. */
40
40
  ECG = "131328",
41
+ /** A pulse oximeter's pulse wave (plethysmogram). */
42
+ PULSE_WAVE = "150452",
41
43
  /** Respiratory rate. */
42
44
  RESPIRATORY_RATE = "9279-1",
43
45
  /** Spirometry panel. */
44
- SPIROMETRY_PANEL = "62639-0",
46
+ SPIROMETRY_PANEL = "81459-0",
47
+ /** Forced vital capacity (FVC). */
48
+ FVC = "19870-5",
49
+ /** Forced expiratory volume in 1 second (FEV1). */
50
+ FEV1 = "20150-9",
51
+ /** Forced expiratory volume in 0.5 seconds (FEV0.5). */
52
+ FEV0_5 = "20148-3",
53
+ /** FEV1 to FVC ratio. */
54
+ FEV1_FVC_RATIO = "19926-5",
55
+ /** Peak expiratory flow (PEF). */
56
+ PEF = "33452-4",
57
+ /** Forced expiratory flow at 25% of FVC (FEF25). */
58
+ FEF25 = "65821-1",
59
+ /** Forced expiratory flow at 50% of FVC (FEF50). */
60
+ FEF50 = "65822-9",
61
+ /** Forced expiratory flow at 75% of FVC (FEF75). */
62
+ FEF75 = "65823-7",
63
+ /** Forced expiratory flow between 25% and 75% of FVC (FEF25-75). */
64
+ FEF25_75 = "19927-3",
45
65
  /** Heart rate variability. */
46
66
  HEART_RATE_VARIABILITY = "80404-7",
47
67
  /** VO2 max. */
@@ -42,10 +42,30 @@ var ObservationCode;
42
42
  ObservationCode["BODY_TEMPERATURE"] = "8310-5";
43
43
  /** ECG waveform. */
44
44
  ObservationCode["ECG"] = "131328";
45
+ /** A pulse oximeter's pulse wave (plethysmogram). */
46
+ ObservationCode["PULSE_WAVE"] = "150452";
45
47
  /** Respiratory rate. */
46
48
  ObservationCode["RESPIRATORY_RATE"] = "9279-1";
47
49
  /** Spirometry panel. */
48
- ObservationCode["SPIROMETRY_PANEL"] = "62639-0";
50
+ ObservationCode["SPIROMETRY_PANEL"] = "81459-0";
51
+ /** Forced vital capacity (FVC). */
52
+ ObservationCode["FVC"] = "19870-5";
53
+ /** Forced expiratory volume in 1 second (FEV1). */
54
+ ObservationCode["FEV1"] = "20150-9";
55
+ /** Forced expiratory volume in 0.5 seconds (FEV0.5). */
56
+ ObservationCode["FEV0_5"] = "20148-3";
57
+ /** FEV1 to FVC ratio. */
58
+ ObservationCode["FEV1_FVC_RATIO"] = "19926-5";
59
+ /** Peak expiratory flow (PEF). */
60
+ ObservationCode["PEF"] = "33452-4";
61
+ /** Forced expiratory flow at 25% of FVC (FEF25). */
62
+ ObservationCode["FEF25"] = "65821-1";
63
+ /** Forced expiratory flow at 50% of FVC (FEF50). */
64
+ ObservationCode["FEF50"] = "65822-9";
65
+ /** Forced expiratory flow at 75% of FVC (FEF75). */
66
+ ObservationCode["FEF75"] = "65823-7";
67
+ /** Forced expiratory flow between 25% and 75% of FVC (FEF25-75). */
68
+ ObservationCode["FEF25_75"] = "19927-3";
49
69
  /** Heart rate variability. */
50
70
  ObservationCode["HEART_RATE_VARIABILITY"] = "80404-7";
51
71
  /** VO2 max. */
@@ -16,4 +16,6 @@ export type PulseOximeterMeasurement = Measurement & {
16
16
  bloodOxygen?: number;
17
17
  /** Perfusion index. */
18
18
  perfusionIndex?: number;
19
+ /** One pulse wave sample, in the sensor's own units; a series holds the wave at the sensor's rate. */
20
+ pulseWave?: number;
19
21
  };
@@ -1,44 +1,29 @@
1
- import { CodeableConcept } from "@medplum/fhirtypes";
1
+ import { MeasurementTypeKey } from "../MeasurementTypeKey";
2
2
  import { Measurement } from "./Measurement";
3
3
  /**
4
- * Spirometry measurement.
4
+ * Spirometry measurement: volumes in L, flows in L/s and the FEV1/FVC ratio in %.
5
5
  *
6
6
  * @category measurements
7
7
  */
8
8
  export type SpirometryMeasurement = Measurement & {
9
- /** Forced vital capacity. */
10
- fvc?: string;
11
- /** Forced expiratory volume in 1 second. */
12
- fev1?: string;
13
- /** Forced expiratory volume in 0.5 seconds. */
14
- "fev0.5"?: string;
15
- /** FEV1 to FVC ratio. */
16
- "fev1/fvc"?: string;
17
- /** Peak expiratory flow. */
18
- pef?: string;
19
- /** Forced expiratory flow at 25% of FVC. */
20
- fef25?: string;
21
- /** Forced expiratory flow at 50% of FVC. */
22
- fef50?: string;
23
- /** Forced expiratory flow at 75% of FVC. */
24
- fef75?: string;
25
- /** Forced expiratory flow between 25% and 75% of FVC. */
26
- fef2575?: string;
27
- /** Coded spirometry values. */
28
- spirometryValues: SpirometerValue[];
9
+ /** Always `spirometryPanel`. */
10
+ measurementTypeKey: MeasurementTypeKey.spirometryPanel;
11
+ /** Forced vital capacity, in L. */
12
+ fvc?: number;
13
+ /** Forced expiratory volume in 1 second, in L. */
14
+ fev1?: number;
15
+ /** Forced expiratory volume in 0.5 seconds, in L. */
16
+ "fev0.5"?: number;
17
+ /** FEV1 to FVC ratio, in %. */
18
+ "fev1/fvc"?: number;
19
+ /** Peak expiratory flow, in L/s. */
20
+ pef?: number;
21
+ /** Forced expiratory flow at 25% of FVC, in L/s. */
22
+ fef25?: number;
23
+ /** Forced expiratory flow at 50% of FVC, in L/s. */
24
+ fef50?: number;
25
+ /** Forced expiratory flow at 75% of FVC, in L/s. */
26
+ fef75?: number;
27
+ /** Forced expiratory flow between 25% and 75% of FVC, in L/s. */
28
+ fef2575?: number;
29
29
  };
30
- /**
31
- * One coded spirometer value.
32
- *
33
- * @category measurements
34
- */
35
- type SpirometerValue = {
36
- /** Code identifying the value. */
37
- code: CodeableConcept;
38
- /** The value. */
39
- value?: {
40
- /** Value as a string. */
41
- string: string;
42
- };
43
- };
44
- export {};
@@ -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-rc.6",
29
+ version: "0.4.49-rc.8",
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-rc.6",
3
+ "version": "0.4.49-rc.8",
4
4
  "private": false,
5
5
  "main": "dist/next/index.js",
6
6
  "types": "dist/next/index.d.ts",