Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test to check modalities not specified in project config are dropped #594

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion pixl_dcmd/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
add_private_tag,
create_private_tag,
)
from core.exceptions import PixlDiscardError
from core.exceptions import PixlDiscardError, PixlSkipInstanceError
from core.project_config import load_project_config, load_tag_operations
from core.project_config.pixl_config_model import load_config_and_validate
from decouple import config
Expand Down Expand Up @@ -244,6 +244,29 @@ def test_anonymisation_with_overrides(
assert mri_diffusion_dicom_image[(0x2001, 0x1003)] == original_private_tag


@pytest.mark.usefixtures()
def test_drop_unspecified_modalities(test_project_config: PixlConfig) -> None:
"""
GIVEN a project configuration and DICOM files
WHEN the modality tag in the DICOM files does not match the specified modalities in the configuration
THEN drop those DICOM files
"""
ds_dx = generate_dicom_dataset(Modality="DX")
ds_cr = generate_dicom_dataset(Modality="CR")
ds_mr = generate_dicom_dataset(Modality="MR") # not in config

anonymise_dicom(ds_dx, config=test_project_config)
anonymise_dicom(ds_cr, config=test_project_config)

assert ds_dx.Modality in test_project_config.project.modalities
assert ds_cr.Modality in test_project_config.project.modalities

with pytest.raises(PixlSkipInstanceError):
anonymise_dicom(ds_mr, config=test_project_config)

assert ds_mr.Modality not in test_project_config.project.modalities


@pytest.mark.usefixtures("rows_in_session")
def test_image_already_exported_throws(test_project_config, exported_dicom_dataset):
"""
Expand Down