mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
fix(labs): never present a converted reading's printed range in the wrong unit
A converted reading's bounds move with its value, but the printed range text stays in the unit the report used, and every reader preferred that text: the list showed "Report range 3.9 to 5.5" beside 100.9 mg/dL, and the doctor report and the FHIR referenceRange.text did the same. The text is still stored verbatim. The range resolver now takes the reading's sourceUnit (as a required field, so no reader can forget to select it) and, for a converted reading, leaves the window's text empty so every surface states the converted bounds in the marker's unit, and hands the printed text over separately with its unit. The lab DTO carries it as printedReferenceText, and the note beside a reading shows it as "as printed in mmol/L: ...".
This commit is contained in:
1 parent
cc0313c955
commit
47a91d6922
29 files changed
+365
-20
No files matched your search
@@ -65,11 +65,23 @@ export function formatReferenceRange(
|
||||
/**
|
||||
* The reference range a lab report printed beside ONE reading, as stored on
|
||||
* `LabResult.sourceReference*`.
|
||||
*
|
||||
* `sourceUnit` is set when the reading was converted into its marker's unit:
|
||||
* the bounds were converted with the value, but the text is the report's own
|
||||
* and stays in the unit the report printed. It is required, so a reader cannot
|
||||
* forget to select it and present that text beside numbers in another unit.
|
||||
*/
|
||||
export interface SourceReferenceRange {
|
||||
sourceReferenceLow: number | null;
|
||||
sourceReferenceHigh: number | null;
|
||||
sourceReferenceText: string | null;
|
||||
sourceUnit: string | null;
|
||||
}
|
||||
|
||||
/** A converted reading's printed range text, with the unit it is written in. */
|
||||
export interface PrintedReferenceRange {
|
||||
text: string;
|
||||
unit: string;
|
||||
}
|
||||
|
||||
/** Where the bounds a reading is judged against came from. */
|
||||
@@ -84,8 +96,19 @@ export interface EffectiveReferenceRange {
|
||||
/** The catalog band, kept alongside so a surface can show both. */
|
||||
catalogLow: number | null;
|
||||
catalogHigh: number | null;
|
||||
/** The printed window, kept verbatim. Null when the report stated none. */
|
||||
/**
|
||||
* The printed window, kept verbatim, in the reading's unit. Null when the
|
||||
* report stated none, and null for a converted reading: its text is in the
|
||||
* unit the report printed, not the unit of the value and bounds beside it,
|
||||
* and moves to `printed`.
|
||||
*/
|
||||
sourceText: string | null;
|
||||
/**
|
||||
* For a converted reading only: the window as the report printed it and the
|
||||
* unit it is in. Evidence, never a statement about the stored numbers; a
|
||||
* surface that shows it names the unit with it.
|
||||
*/
|
||||
printed: PrintedReferenceRange | null;
|
||||
/**
|
||||
* True when the source window is in force AND the catalog states a window
|
||||
* that differs from it. This is the case a reader must be told about: the
|
||||
@@ -132,7 +155,15 @@ export function resolveEffectiveReferenceRange(
|
||||
const cHigh = catalogHigh ?? null;
|
||||
const sLow = source?.sourceReferenceLow ?? null;
|
||||
const sHigh = source?.sourceReferenceHigh ?? null;
|
||||
const sourceText = source?.sourceReferenceText ?? null;
|
||||
const verbatim = source?.sourceReferenceText ?? null;
|
||||
const sourceUnit = source?.sourceUnit ?? null;
|
||||
// A converted reading's text is in the printed unit; it is never presented as
|
||||
// the window of the converted value.
|
||||
const sourceText = sourceUnit === null ? verbatim : null;
|
||||
const printed: PrintedReferenceRange | null =
|
||||
sourceUnit !== null && verbatim !== null
|
||||
? { text: verbatim, unit: sourceUnit }
|
||||
: null;
|
||||
|
||||
if (sLow !== null || sHigh !== null) {
|
||||
return {
|
||||
@@ -142,6 +173,7 @@ export function resolveEffectiveReferenceRange(
|
||||
catalogLow: cLow,
|
||||
catalogHigh: cHigh,
|
||||
sourceText,
|
||||
printed,
|
||||
divergesFromCatalog:
|
||||
(cLow !== null || cHigh !== null) &&
|
||||
!sameWindow(sLow, sHigh, cLow, cHigh),
|
||||
@@ -155,6 +187,7 @@ export function resolveEffectiveReferenceRange(
|
||||
catalogLow: cLow,
|
||||
catalogHigh: cHigh,
|
||||
sourceText,
|
||||
printed,
|
||||
divergesFromCatalog: false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user