diff --git a/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py b/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py index 90358a177..6cd93eea9 100644 --- a/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py +++ b/src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py @@ -64,14 +64,27 @@ def create(data: SeriesData) -> RawMeasurement: if BELOW_TEST_RANGE in error else data.get(float, "concentration value", NaN) ) + + value, unit = RawMeasurement._get_value_and_unit( + concentration_value, data[str, "concentration unit"] + ) + return RawMeasurement( data[str, "analyte name"], data[str, "measurement time"], - concentration_value, - data[str, "concentration unit"], + value, + unit, error or None, ) + @staticmethod + def _get_value_and_unit(value: JsonFloat, unit: str) -> tuple[JsonFloat, str]: + if isinstance(value, int | float): + if unit == "mg/L": + return value / 1000, "g/L" + + return value, unit + def create_measurements(data: pd.DataFrame) -> dict[str, dict[str, RawMeasurement]]: measurements = sorted( diff --git a/tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.json b/tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.json new file mode 100644 index 000000000..b8a84662c --- /dev/null +++ b/tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.json @@ -0,0 +1,285 @@ +{ + "$asm.manifest": "http://purl.allotrope.org/manifests/solution-analyzer/REC/2024/09/solution-analyzer.manifest", + "solution analyzer aggregate document": { + "solution analyzer document": [ + { + "measurement aggregate document": { + "measurement document": [ + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_0", + "measurement time": "2023-09-15T16:55:51+00:00", + "sample document": { + "sample identifier": "SMPL1" + }, + "absorbance": { + "value": 6.32, + "unit": "mAU" + } + }, + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_1", + "measurement time": "2023-09-15T16:55:51+00:00", + "sample document": { + "sample identifier": "SMPL1" + }, + "analyte aggregate document": { + "analyte document": [ + { + "analyte name": "ammonia", + "molar concentration": { + "value": 1.846, + "unit": "mmol/L" + } + }, + { + "analyte name": "glutamine", + "molar concentration": { + "value": 2.45, + "unit": "mmol/L" + } + }, + { + "analyte name": "lactate", + "mass concentration": { + "value": 2e-05, + "unit": "g/L" + } + }, + { + "analyte name": "ldh", + "molar concentration": { + "value": 1.471103, + "unit": "mmol/L" + } + }, + { + "analyte name": "total protein", + "mass concentration": { + "value": 0.0046, + "unit": "g/L" + } + } + ] + } + } + ], + "data processing time": "2023-09-17T13:04:06+00:00" + }, + "analyst": "ADMIN" + }, + { + "measurement aggregate document": { + "measurement document": [ + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_2", + "measurement time": "2023-09-15T16:56:58+00:00", + "sample document": { + "sample identifier": "SMPL2" + }, + "analyte aggregate document": { + "analyte document": [ + { + "analyte name": "ammonia", + "molar concentration": { + "value": 1.87, + "unit": "mmol/L" + } + }, + { + "analyte name": "glutamine", + "molar concentration": { + "value": 2.4, + "unit": "mmol/L" + } + }, + { + "analyte name": "total protein", + "mass concentration": { + "value": 0.0047, + "unit": "g/L" + } + } + ] + } + } + ], + "data processing time": "2023-09-17T13:04:06+00:00" + }, + "analyst": "ADMIN" + }, + { + "measurement aggregate document": { + "measurement document": [ + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_3", + "measurement time": "2023-09-15T16:58:34+00:00", + "sample document": { + "sample identifier": "SMPL3" + }, + "absorbance": { + "value": 6.71, + "unit": "mAU" + } + }, + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_4", + "measurement time": "2023-09-15T16:58:34+00:00", + "sample document": { + "sample identifier": "SMPL3" + }, + "analyte aggregate document": { + "analyte document": [ + { + "analyte name": "ammonia", + "molar concentration": { + "value": 1.817, + "unit": "mmol/L" + } + }, + { + "analyte name": "glutamine", + "molar concentration": { + "value": 2.43, + "unit": "mmol/L" + } + }, + { + "analyte name": "total protein", + "mass concentration": { + "value": 4.8, + "unit": "g/L" + } + } + ] + } + } + ], + "data processing time": "2023-09-17T13:04:06+00:00" + }, + "analyst": "ADMIN" + }, + { + "measurement aggregate document": { + "measurement document": [ + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_5", + "measurement time": "2023-09-16T10:12:10+00:00", + "sample document": { + "sample identifier": "SMPL4" + }, + "absorbance": { + "value": 4.09, + "unit": "mAU" + } + }, + { + "device control aggregate document": { + "device control document": [ + { + "device type": "solution-analyzer" + } + ] + }, + "measurement identifier": "ROCHE_CEDEX_BIOHT_TEST_ID_6", + "measurement time": "2023-09-16T10:12:10+00:00", + "sample document": { + "sample identifier": "SMPL4" + }, + "analyte aggregate document": { + "analyte document": [ + { + "analyte name": "ammonia", + "molar concentration": { + "value": 3.788, + "unit": "mmol/L" + } + }, + { + "analyte name": "glutamine", + "molar concentration": { + "value": 2.07, + "unit": "mmol/L" + } + }, + { + "analyte name": "lactate", + "mass concentration": { + "value": 0.00189, + "unit": "g/L" + } + }, + { + "analyte name": "ldh", + "molar concentration": { + "value": 5.591828, + "unit": "mmol/L" + } + } + ] + } + } + ], + "data processing time": "2023-09-17T13:04:06+00:00" + }, + "analyst": "ADMIN" + } + ], + "data system document": { + "ASM file identifier": "roche_cedex_bioht_example_with_mg_L.json", + "data system instance identifier": "N/A", + "file name": "roche_cedex_bioht_example_with_mg_L.txt", + "UNC path": "tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.txt", + "ASM converter name": "allotropy_roche_cedex_bioht", + "ASM converter version": "0.1.97", + "software name": "CEDEX BIO HT", + "software version": "6.0.0.1905 (1905)" + }, + "device system document": { + "device identifier": "N/A", + "equipment serial number": "123456", + "model number": "CEDEX BIO HT" + } + } +} diff --git a/tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.txt b/tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.txt new file mode 100644 index 000000000..481e65dea --- /dev/null +++ b/tests/parsers/roche_cedex_bioht/testdata/roche_cedex_bioht_example_with_mg_L.txt @@ -0,0 +1,27 @@ +0 2023-09-17 13:04:06 #ARC-FILE# 1.1a 2021-05-01 2023-09-17 CEDEX BIO HT 123456 6.0.0.1905 (1905) ADMIN +40 2023-09-15 16:55:51 SMPL1 SAM GLN2B mmol/L 2.45 0.17138 R +40 2023-09-15 16:55:53 SMPL1 SAM ODB OD 6.32 1.05394 R +40 2023-09-15 16:56:18 SMPL1 SAM LDH2B U/L 88.09 0.00728 R +40 2023-09-15 16:56:26 SMPL1 SAM NH3B mmol/L 1.846 0.05333 R +40 2023-09-15 16:56:37 SMPL1 SAM LAC2B mg/L 0.02 0.01567 R +40 2023-09-15 16:56:48 SMPL1 SAM TP2LB mg/L 4.6 0.14883 R +40 2023-09-15 16:56:58 SMPL2 SAM GLN2B mmol/L 2.40 0.16787 R +40 2023-09-15 16:57:09 SMPL2 SAM ODB OD < TEST RNG 6.71 1.11766 R +40 2023-09-15 16:57:19 SMPL2 SAM LDH2B U/L < TEST RNG < 20.00 0.00060 R +40 2023-09-15 16:57:30 SMPL2 SAM NH3B mmol/L 1.870 0.05408 R +40 2023-09-15 16:57:41 SMPL2 SAM LAC2B mg/L < TEST RNG < 0.00 0.00310 R +40 2023-09-15 16:57:51 SMPL2 SAM TP2B mg/L < TEST RNG < 4.0 0.03322 R +40 2023-09-15 16:58:02 SMPL2 SAM TP2D mg/L < TEST RNG < 40.0 0.02653 R +40 2023-09-15 16:58:23 SMPL2 SAM TP2LB mg/L 4.7 0.15217 R +40 2023-09-15 16:58:34 SMPL3 SAM GLN2B mmol/L 2.43 0.17049 R +40 2023-09-15 16:58:45 SMPL3 SAM ODB OD 6.71 1.11813 R +40 2023-09-15 16:58:55 SMPL3 SAM LDH2B U/L < TEST RNG < 20.00 0.00076 R +40 2023-09-15 16:59:06 SMPL3 SAM NH3B mmol/L 1.817 0.05242 R +40 2023-09-15 16:59:16 SMPL3 SAM LAC2B mg/L < TEST RNG < 0.00 0.00329 R +40 2023-09-15 16:59:38 SMPL3 SAM TP2D mg/L < TEST RNG < 40.0 0.02702 R +40 2023-09-15 17:00:52 SMPL3 SAM TP2LB g/L 4.8 0.15436 R +40 2023-09-16 10:12:10 SMPL4 SAM GLN2B mmol/L 2.07 0.14503 R +40 2023-09-16 10:12:12 SMPL4 SAM ODB OD 4.09 0.68160 R +40 2023-09-16 10:13:29 SMPL4 SAM LDH2B U/L 334.84 0.02665 R +40 2023-09-16 10:13:37 SMPL4 SAM NH3B mmol/L 3.788 0.11415 R +40 2023-09-16 10:22:55 SMPL4 SAM LAC2B mg/L v 1.89 0.15187 R