mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
feat(fhir): code a lab value without a unit as the UCUM unity
A value stored with unit "1" carries system and code on its quantity even when the analyte map knows no coding for it: the unity is UCUM by definition. Refs #1313
This commit is contained in:
1 parent
79ac5670c7
commit
5405ce053d
2 files changed
+20
-1
No files matched your search
@@ -276,6 +276,16 @@ describe("lab-result LOINC + canonical UCUM coding (v1.18.8)", () => {
|
||||
expect(o?.valueQuantity?.unit).toBe("mg/dL");
|
||||
});
|
||||
|
||||
it("codes a value without a unit as the UCUM unity", () => {
|
||||
const o = labOf("Cholesterol/HDL ratio", "1", 3.6);
|
||||
expect(o?.valueQuantity).toEqual({
|
||||
value: 3.6,
|
||||
unit: "1",
|
||||
system: "http://unitsofmeasure.org",
|
||||
code: "1",
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves analyte aliases to the same canonical LOINC", () => {
|
||||
// "LDL", "LDL-C", "LDL Cholesterol" all fold to 2089-1.
|
||||
for (const name of ["LDL-C", "LDL Cholesterol", "ldl_c"]) {
|
||||
|
||||
@@ -21,6 +21,10 @@ import type { DoctorReportData } from "@/lib/doctor-report-data";
|
||||
import { LOINC_SYSTEM, UCUM_SYSTEM } from "@/lib/fhir/loinc-map";
|
||||
import { resolveLabCoding } from "@/lib/fhir/lab-loinc";
|
||||
import { qualitativeValueConcept } from "@/lib/fhir/lab-qualitative";
|
||||
import {
|
||||
DIMENSIONLESS_UNIT,
|
||||
isDimensionlessUnit,
|
||||
} from "@/lib/labs/dimensionless";
|
||||
|
||||
import type {
|
||||
FhirObservation,
|
||||
@@ -84,10 +88,15 @@ export function labObservations(
|
||||
// the code system while withholding the code claims a coding the bundle
|
||||
// does not carry, and leaves a receiver unable to machine-compare the
|
||||
// value it is attached to.
|
||||
// A value without a unit is the UCUM unity by definition, so it carries
|
||||
// the code even for an analyte the map does not know.
|
||||
const ucum = isDimensionlessUnit(lab.unit)
|
||||
? DIMENSIONLESS_UNIT
|
||||
: coding?.ucum;
|
||||
const quantity = (value: number) => ({
|
||||
value,
|
||||
unit: lab.unit,
|
||||
...(coding?.ucum ? { system: UCUM_SYSTEM, code: coding.ucum } : {}),
|
||||
...(ucum ? { system: UCUM_SYSTEM, code: ucum } : {}),
|
||||
});
|
||||
// The bounds are stated in the SAME unit as the value, so they carry the
|
||||
// SAME coding — a bare unit beside a coded value leaves a receiver unable
|
||||
|
||||
Reference in new issue
Block a user