Skip to content

Commit a79a7c0

Browse files
feat: Roche Cedex BioHT - Add support for mM unit (mmol/L) (#1119)
current issue: <img width="911" height="96" alt="image" src="https://github.com/user-attachments/assets/a5d66eea-417a-4fb9-b88e-9258e4a7dbdd" /> Fix: add support for _mM_ unit
1 parent c1bcdc6 commit a79a7c0

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
from allotropy.parsers.utils.pandas import map_rows, SeriesData
2929
from allotropy.parsers.utils.uuids import random_uuid_str
3030

31+
# Maps source units to (target_unit, conversion_multiplier)
32+
UNIT_CONVERSIONS: dict[str, tuple[str, float]] = {
33+
"mg/L": ("g/L", 0.001),
34+
"mM": ("mmol/L", 1.0),
35+
}
36+
3137

3238
@dataclass(frozen=True)
3339
class Title:
@@ -111,15 +117,18 @@ def create(data: SeriesData) -> RawMeasurement:
111117

112118
@staticmethod
113119
def _get_value_and_unit(value: JsonFloat, unit: str) -> tuple[JsonFloat, str]:
114-
multiplier = 1.0
115-
if unit == "mg/L":
116-
unit = "g/L"
117-
multiplier = 1 / 1000
118-
119-
if isinstance(value, int | float):
120-
value = value * multiplier
121-
122-
return value, unit
120+
normalized_unit = unit.strip()
121+
122+
# Check if unit needs conversion
123+
if normalized_unit in UNIT_CONVERSIONS:
124+
target_unit, multiplier = UNIT_CONVERSIONS[normalized_unit]
125+
if isinstance(value, int | float):
126+
converted_value: JsonFloat = value * multiplier
127+
else:
128+
converted_value = value
129+
return converted_value, target_unit
130+
131+
return value, normalized_unit
123132

124133

125134
def create_measurements(data: pd.DataFrame) -> dict[str, dict[str, RawMeasurement]]:

tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example01.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
40 2023-09-15 16:55:51 SMPL1 SAM GLN2B mmol/L 2.45 0.17138 R
33
40 2023-09-15 16:55:53 SMPL1 SAM ODB OD 6.32 1.05394 R
44
40 2023-09-15 16:56:18 SMPL1 SAM LDH2B U/L 88.09 0.00728 R
5-
40 2023-09-15 16:56:26 SMPL1 SAM NH3B mmol/L 1.846 0.05333 R
5+
40 2023-09-15 16:56:26 SMPL1 SAM NH3B mM 1.846 0.05333 R
66
40 2023-09-15 16:56:37 SMPL1 SAM LAC2B g/L 0.02 0.01567 R
77
40 2023-09-15 16:56:48 SMPL1 SAM TP2LB g/L 4.6 0.14883 R
88
40 2023-09-15 16:56:58 SMPL2 SAM GLN2B mmol/L 2.40 0.16787 R
@@ -20,7 +20,7 @@
2020
40 2023-09-15 16:59:16 SMPL3 SAM LAC2B g/L < TEST RNG < 0.00 0.00329 R
2121
40 2023-09-15 16:59:38 SMPL3 SAM TP2D g/L < TEST RNG < 40.0 0.02702 R
2222
40 2023-09-15 17:00:52 SMPL3 SAM TP2LB g/L 4.8 0.15436 R
23-
40 2023-09-16 10:12:10 SMPL4 SAM GLN2B mmol/L 2.07 0.14503 R
23+
40 2023-09-16 10:12:10 SMPL4 SAM GLN2B mM 2.07 0.14503 R
2424
40 2023-09-16 10:12:12 SMPL4 SAM ODB OD 4.09 0.68160 R
2525
40 2023-09-16 10:13:29 SMPL4 SAM LDH2B U/L 334.84 0.02665 R
2626
40 2023-09-16 10:13:37 SMPL4 SAM NH3B mmol/L 3.788 0.11415 R

0 commit comments

Comments
 (0)