Skip to content

Add more integration tests for run_nifti_insertion.py #1266

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

Merged
merged 25 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion python/lib/db/models/mri_protocol_violated_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DbMriProtocolViolatedScan(Base):
dicom_archive_id : Mapped[int | None] = mapped_column('TarchiveID', ForeignKey('tarchive.TarchiveID'))
time_run : Mapped[datetime | None] = mapped_column('time_run')
series_description : Mapped[str | None] = mapped_column('series_description')
minc_location : Mapped[str | None] = mapped_column('minc_location')
file_rel_path : Mapped[str | None] = mapped_column('minc_location')
patient_name : Mapped[str | None] = mapped_column('PatientName')
tr_range : Mapped[str | None] = mapped_column('TR_range')
te_range : Mapped[str | None] = mapped_column('TE_range')
Expand Down
2 changes: 1 addition & 1 deletion python/lib/db/models/mri_violation_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DbMriViolationLog(Base):
series_uid : Mapped[str | None] = mapped_column('SeriesUID')
dicom_archive_id : Mapped[int | None] \
= mapped_column('TarchiveID', ForeignKey('tarchive.TarchiveID'))
minc_file : Mapped[str | None] = mapped_column('MincFile')
file_rel_path : Mapped[str | None] = mapped_column('MincFile')
patient_name : Mapped[str | None] = mapped_column('PatientName')
candidate_id : Mapped[int | None] = mapped_column('CandidateID', ForeignKey('candidate.ID'))
visit_label : Mapped[str | None] = mapped_column('Visit_label')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from collections.abc import Sequence

from sqlalchemy import select
from sqlalchemy.orm import Session as Database

from lib.db.models.mri_protocol_violated_scan import DbMriProtocolViolatedScan


def try_get_protocol_violated_scans_with_unique_series_combination(
def get_protocol_violated_scans_with_unique_series_combination(
db: Database,
series_uid: str,
echo_time: str | None,
echo_number: str | None,
phase_encoding_direction: str | None
) -> DbMriProtocolViolatedScan | None:
) -> Sequence[DbMriProtocolViolatedScan]:
"""
Get the protocol violated scans from the database using its SeriesInstanceUID, or return `None` if
no protocol violated scan was found.
Get all protocol violated scans from the database using the file's SeriesInstanceUID,
echo time, echo number and phase encoding direction.
"""

return db.execute(select(DbMriProtocolViolatedScan)
.where(DbMriProtocolViolatedScan.series_uid == series_uid)
.where(DbMriProtocolViolatedScan.te_range == echo_time)
.where(DbMriProtocolViolatedScan.echo_number == echo_number)
.where(DbMriProtocolViolatedScan.phase_encoding_direction == phase_encoding_direction)
).scalar_one_or_none()
).scalars().all()
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from collections.abc import Sequence

from sqlalchemy import select
from sqlalchemy.orm import Session as Database

from lib.db.models.mri_violation_log import DbMriViolationLog


def try_get_violations_log_with_unique_series_combination(
def get_violations_log_with_unique_series_combination(
db: Database,
series_uid: str,
echo_time: str | None,
echo_number: str | None,
phase_encoding_direction: str | None
) -> DbMriViolationLog | None:
) -> Sequence[DbMriViolationLog]:
"""
Get the violations log from the database using its SeriesInstanceUID, or return `None` if
no violations log was found.
Get all violations log from the database using the file's SeriesInstanceUID,
echo time, echo number and phase encoding direction.
"""

return db.execute(select(DbMriViolationLog)
.where(DbMriViolationLog.series_uid == series_uid)
.where(DbMriViolationLog.echo_time == echo_time)
.where(DbMriViolationLog.echo_number == echo_number)
.where(DbMriViolationLog.phase_encoding_direction == phase_encoding_direction)
).scalar_one_or_none()
).scalars().all()
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, loris_getopt_obj, script_name):
self.bvec_blake2 = compute_file_blake2b_hash(self.bvec_path) if self.bval_path else None
self.loris_scan_type = self.options_dict["loris_scan_type"]["value"]
self.bypass_extra_checks = self.options_dict["bypass_extra_checks"]["value"]
self.create_pic_bool = self.options_dict["create_pic"]["value"]

# ---------------------------------------------------------------------------------------------
# Set 'Inserting' flag to 1 in mri_upload
Expand Down Expand Up @@ -164,8 +165,8 @@ def __init__(self, loris_getopt_obj, script_name):
log_error_exit(
self.env,
(
f"{self.nifti_path} violates exclusionary checks listed in mri_protocol_checks. "
f" List of violations are: {self.exclude_violations_list}"
f"{self.nifti_path} violates exclusionary checks listed in mri_protocol_checks."
f" List of violations are: {self.exclude_violations_list}"
),
lib.exitcode.UNKNOWN_PROTOCOL,
)
Expand All @@ -175,7 +176,8 @@ def __init__(self, loris_getopt_obj, script_name):
# ---------------------------------------------------------------------------------------------
# Create the pic images
# ---------------------------------------------------------------------------------------------
self._create_pic_image()
if self.create_pic_bool:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug found when implementing the tests 🥳

self._create_pic_image()

# ---------------------------------------------------------------------------------------------
# Remove the tmp directory from the file system
Expand Down
Loading
Loading