Skip to content

Commit

Permalink
Add tests for test_should_exclude_manufacturer
Browse files Browse the repository at this point in the history
  • Loading branch information
p-j-smith committed Jan 27, 2025
1 parent 6b707cb commit a7c5917
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions pixl_dcmd/src/pixl_dcmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _should_exclude_manufacturer(dataset: Dataset, cfg: PixlConfig) -> bool:
manufacturer = dataset.get("Manufacturer")
if manufacturer is None:
logger.debug("FILTERING out as manufacturer tag is missing")
return True

should_exclude = not cfg.is_manufacturer_allowed(manufacturer=manufacturer)
if should_exclude:
Expand Down
25 changes: 23 additions & 2 deletions pixl_dcmd/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
anonymise_dicom,
_enforce_allowlist,
_should_exclude_series,
_should_exclude_manufacturer,
)
from pytest_pixl.dicom import generate_dicom_dataset
from pytest_pixl.helpers import run_subprocess
Expand Down Expand Up @@ -407,7 +408,11 @@ def test_no_pseudo_patient_id_processing(
)


def _make_dicom(series_description, manufacturer, series_number) -> pydicom.Dataset:
def _make_dicom(
series_description="mri_sequence",
manufacturer="Company",
series_number="901",
) -> pydicom.Dataset:
return generate_dicom_dataset(
SeriesDescription=series_description,
Manufacturer=manufacturer,
Expand Down Expand Up @@ -438,10 +443,26 @@ def test_should_exclude_series(
config = load_project_config(TEST_PROJECT_SLUG)
ds = _make_dicom(series_description, manufacturer, series_number)
series_number = ds.get("SeriesNumber")
print(f"{series_number=}", type(series_number), str(series_number))
assert _should_exclude_series(ds, config) == expect_exclude


@pytest.mark.parametrize(
("manufacturer", "expect_exclude"),
[
("Company", False),
("DifferentCompany", True),
(None, True),
],
)
def test_should_exclude_manufacturer(manufacturer, expect_exclude):
config = load_project_config(TEST_PROJECT_SLUG)
ds = _make_dicom(manufacturer=manufacturer)
if manufacturer is None:
# the Manufacturer tag is sometimes missing in real data
delattr(ds, "Manufacturer")
assert _should_exclude_manufacturer(ds, config) == expect_exclude


def test_can_nifti_convert_post_anonymisation(
tmp_path,
directory_of_mri_dicoms,
Expand Down

0 comments on commit a7c5917

Please sign in to comment.