-
Notifications
You must be signed in to change notification settings - Fork 206
/
helper.tsx
108 lines (87 loc) · 2.65 KB
/
helper.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import styles from './result-panel.scss';
import { Concept, ConceptMeta, FHIRObservationResource, observationInterpretation } from '../../types';
import { OBSERVATION_INTERPRETATION } from '@openmrs/esm-patient-common-lib';
export const getConceptUuid = (obs: FHIRObservationResource) => obs?.code.coding[0].code;
export const getClass = (interpretation: OBSERVATION_INTERPRETATION) => {
switch (interpretation) {
case 'OFF_SCALE_HIGH':
return styles['off-scale-high'];
case 'CRITICALLY_HIGH':
return styles['critically-high'];
case 'HIGH':
return styles['high'];
case 'OFF_SCALE_LOW':
return styles['off-scale-low'];
case 'CRITICALLY_LOW':
return styles['critically-low'];
case 'LOW':
return styles['low'];
case 'NORMAL':
default:
return '';
}
};
export function exist(...args: any[]): boolean {
for (const y of args) {
if (y === null || y === undefined) {
return false;
}
}
return true;
}
export const assessValue: (any) => (value: string) => OBSERVATION_INTERPRETATION =
(meta) =>
(value: string): observationInterpretation => {
const valueQuantity = parseFloat(value);
if (isNaN(valueQuantity)) {
return observationInterpretation.NORMAL;
}
if (exist(meta.hiAbsolute) && valueQuantity > meta.hiAbsolute) {
return observationInterpretation.OFF_SCALE_HIGH;
}
if (exist(meta.hiCritical) && valueQuantity > meta.hiCritical) {
return observationInterpretation.CRITICALLY_HIGH;
}
if (exist(meta.hiNormal) && valueQuantity > meta.hiNormal) {
return observationInterpretation.HIGH;
}
if (exist(meta.lowAbsolute) && valueQuantity < meta.lowAbsolute) {
return observationInterpretation.OFF_SCALE_LOW;
}
if (exist(meta.lowCritical) && valueQuantity < meta.lowCritical) {
return observationInterpretation.CRITICALLY_LOW;
}
if (exist(meta.lowNormal) && valueQuantity < meta.lowNormal) {
return observationInterpretation.LOW;
}
return observationInterpretation.NORMAL;
};
export function extractMetaInformation(concept: Concept): ConceptMeta {
const { display, hiAbsolute, hiCritical, hiNormal, lowAbsolute, lowCritical, lowNormal, units } = concept;
let range = null;
if (exist(hiNormal, lowNormal)) {
range = `${lowNormal} – ${hiNormal}`;
}
const getInterpretation = assessValue({
hiAbsolute,
hiCritical,
hiNormal,
lowAbsolute,
lowCritical,
lowNormal,
units,
range,
});
return {
display,
hiAbsolute,
hiCritical,
hiNormal,
lowAbsolute,
lowCritical,
lowNormal,
units,
range,
getInterpretation,
};
}