Skip to content

Commit b1e8573

Browse files
chore: Refactor custom data block in roche bioht parser (#1089)
1 parent fdb8daf commit b1e8573

2 files changed

Lines changed: 34 additions & 42 deletions

File tree

src/allotropy/parsers/roche_cedex_bioht/roche_cedex_bioht_structure.py

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,48 +75,40 @@ def create(data: SeriesData) -> RawMeasurement:
7575
if error == BELOW_TEST_RANGE:
7676
error = data.get(str, "original concentration value", error)
7777

78-
custom_info = data.get_custom_keys(
79-
{"detection kit", "detection kit range", "analyte code"}
80-
)
81-
custom_info["record type"] = data.get(str, "row type", None)
82-
data.mark_read(
83-
{
84-
"sample identifier",
85-
"batch identifier",
86-
"col4",
87-
"col5",
88-
"col6",
89-
"col8",
90-
"col10",
91-
"col11",
92-
"col12",
93-
"col13",
94-
"original concentration value",
95-
"sample role type",
96-
}
97-
)
98-
99-
if error:
100-
custom_info["flag"] = error
101-
102-
measurement = RawMeasurement(
78+
return RawMeasurement(
10379
data[str, "analyte name"],
10480
data[str, "measurement time"],
10581
value,
10682
unit,
10783
data[str, "analyte code"],
10884
error,
109-
{},
85+
custom_info=dict(
86+
sorted(
87+
{
88+
**{
89+
# analyte code is read to generate the analyte id, but is not saved to a field, so include in custom data.
90+
"analyte code": data.get(str, "analyte code"),
91+
"record type": data.get(str, "row type"),
92+
"flag": error or None,
93+
},
94+
**data.get_unread(
95+
skip={
96+
# Sample and batch identifier are read in groupby operation.
97+
"sample identifier",
98+
"batch identifier",
99+
# Read by reader
100+
"sample role type",
101+
# Only read if there is an error.
102+
"original concentration value",
103+
# Skip unidentified columns (col1, col2, etc)
104+
r"col[\d]+",
105+
}
106+
),
107+
}.items()
108+
)
109+
),
110110
)
111111

112-
if isinstance(measurement.custom_info, dict):
113-
custom_info.update(data.get_unread())
114-
custom_info_sorted = dict(sorted(custom_info.items()))
115-
116-
measurement.custom_info.update(custom_info_sorted)
117-
118-
return measurement
119-
120112
@staticmethod
121113
def _get_value_and_unit(value: JsonFloat, unit: str) -> tuple[JsonFloat, str]:
122114
multiplier = 1.0

tests/parsers/roche_cedex_bioht/roche_cedex_bioht_structure_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_create_measurements() -> None:
113113
"g/L",
114114
"LAC2B",
115115
None,
116-
{"analyte code": "LAC2B", "record type": None},
116+
{"analyte code": "LAC2B", "record type": None, "flag": None},
117117
),
118118
"glutamine_GLN2B": RawMeasurement(
119119
"glutamine",
@@ -122,7 +122,7 @@ def test_create_measurements() -> None:
122122
"mmol/L",
123123
"GLN2B",
124124
None,
125-
{"analyte code": "GLN2B", "record type": None},
125+
{"analyte code": "GLN2B", "record type": None, "flag": None},
126126
),
127127
"osmolality_OSM2B": RawMeasurement(
128128
"osmolality",
@@ -131,7 +131,7 @@ def test_create_measurements() -> None:
131131
"mosm/kg",
132132
"OSM2B",
133133
None,
134-
{"analyte code": "OSM2B", "record type": None},
134+
{"analyte code": "OSM2B", "record type": None, "flag": None},
135135
),
136136
}
137137
}
@@ -162,7 +162,7 @@ def test_create_measurements_more_than_one_measurement_docs() -> None:
162162
"g/L",
163163
"LAC2B",
164164
None,
165-
{"analyte code": "LAC2B", "record type": None},
165+
{"analyte code": "LAC2B", "record type": None, "flag": None},
166166
),
167167
"glutamine_GLN2B": RawMeasurement(
168168
"glutamine",
@@ -171,7 +171,7 @@ def test_create_measurements_more_than_one_measurement_docs() -> None:
171171
"mmol/L",
172172
"GLN2B",
173173
None,
174-
{"analyte code": "GLN2B", "record type": None},
174+
{"analyte code": "GLN2B", "record type": None, "flag": None},
175175
),
176176
},
177177
"2021-05-21T16:57:51+00:00": {
@@ -182,7 +182,7 @@ def test_create_measurements_more_than_one_measurement_docs() -> None:
182182
"mmol/L",
183183
"GLN2B",
184184
None,
185-
{"analyte code": "GLN2B", "record type": None},
185+
{"analyte code": "GLN2B", "record type": None, "flag": None},
186186
),
187187
},
188188
}
@@ -242,7 +242,7 @@ def test_create_sample() -> None:
242242
"g/L",
243243
"LAC2B",
244244
None,
245-
{"analyte code": "LAC2B", "record type": None},
245+
{"analyte code": "LAC2B", "record type": None, "flag": None},
246246
),
247247
"glutamine_GLN2B": RawMeasurement(
248248
"glutamine",
@@ -251,7 +251,7 @@ def test_create_sample() -> None:
251251
"mmol/L",
252252
"GLN2B",
253253
None,
254-
{"analyte code": "GLN2B", "record type": None},
254+
{"analyte code": "GLN2B", "record type": None, "flag": None},
255255
),
256256
}
257257
}

0 commit comments

Comments
 (0)