Skip to content

Commit

Permalink
Merged in feature/RAM-4043_patient_name_generator (pull request jrker…
Browse files Browse the repository at this point in the history
…ns#451)

RAM-4043 Pass patient id and patient name to generator

Approved-by: Randy Taylor
  • Loading branch information
jrkerns committed Oct 4, 2024
2 parents 66ff00c + e6bde1e commit c0d94a4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ General
* The minimum version of Python supported is now 3.9 as the end-of-life of Python 3.8 is October 2024.
* Along with this, minimum versions of numpy, scipy, and matplotlib have been bumped to versions that support Python 3.9.

Plan Generator
^^^^^^^^^^^^^^

* The patient name and patient ID can now be passed to the :class:`~pylinac.plan_generator.dicom.PlanGenerator` and :class:`~pylinac.plan_generator.dicom.HalcyonPlanGenerator` classes. This is useful for
setting the patient name and ID in the generated DICOM files.

Starshot
^^^^^^^^

Expand Down
25 changes: 22 additions & 3 deletions pylinac/plan_generator/dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ def __init__(
ds: Dataset,
plan_label: str,
plan_name: str,
patient_name: str | None = None,
patient_id: str | None = None,
x_width_mm: float = 400,
max_mlc_speed: float = 25,
max_gantry_speed: float = 4.8,
Expand All @@ -761,6 +763,10 @@ def __init__(
The label of the new plan.
plan_name : str
The name of the new plan.
patient_name : str, optional
The name of the patient. If not provided, it will be taken from the RTPLAN file.
patient_id : str, optional
The ID of the patient. If not provided, it will be taken from the RTPLAN file.
x_width_mm : float
The overall width of the MLC movement in the x-direction. Generally, this is the x field size.
max_mlc_speed : float
Expand All @@ -785,8 +791,16 @@ def __init__(
self.max_gantry_speed = max_gantry_speed
self.sacrificial_gap = sacrificial_gap_mm
self.max_sacrificial_move = max_sacrificial_move_mm
if not hasattr(ds, "PatientName") or not hasattr(ds, "PatientID"):
raise ValueError("RTPLAN file must have PatientName and PatientID")
patient_name = patient_name or getattr(ds, "PatientName", None)
if not patient_name:
raise ValueError(
"RTPLAN file must have PatientName or pass it via `patient_name`"
)
patient_id = patient_id or getattr(ds, "PatientID", None)
if not patient_id:
raise ValueError(
"RTPLAN file must have PatientID or pass it via `patient_id`"
)
if not hasattr(ds, "ToleranceTableSequence"):
raise ValueError("RTPLAN file must have ToleranceTableSequence")
if not hasattr(ds, "BeamSequence") or not hasattr(
Expand All @@ -797,7 +811,8 @@ def __init__(
self.ds = ds

###### Clear/initialize the metadata for the new plan

self.ds.PatientName = patient_name
self.ds.PatientID = patient_id
self.ds.RTPlanLabel = plan_label
self.ds.RTPlanName = plan_name
date = datetime.datetime.now().strftime("%Y%m%d")
Expand Down Expand Up @@ -1841,6 +1856,8 @@ def __init__(
ds: Dataset,
plan_label: str,
plan_name: str,
patient_name: str | None = None,
patient_id: str | None = None,
x_width_mm: float = 280,
max_mlc_speed: float = 25,
max_gantry_speed: float = 4.8,
Expand All @@ -1852,6 +1869,8 @@ def __init__(
ds,
plan_label,
plan_name,
patient_name,
patient_id,
x_width_mm,
max_mlc_speed,
max_gantry_speed,
Expand Down
16 changes: 16 additions & 0 deletions tests_basic/test_plan_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def test_no_patient_name(self):
with self.assertRaises(ValueError):
PlanGenerator(ds, plan_label="label", plan_name="my name")

def test_pass_patient_name(self):
ds = pydicom.dcmread(RT_PLAN_FILE)
pg = PlanGenerator(
ds, plan_label="label", plan_name="my name", patient_name="Jimbo Jones"
)
pg_dcm = pg.as_dicom()
self.assertEqual(pg_dcm.PatientName, "Jimbo Jones")

def test_pass_patient_id(self):
ds = pydicom.dcmread(RT_PLAN_FILE)
pg = PlanGenerator(
ds, plan_label="label", plan_name="my name", patient_id="12345"
)
pg_dcm = pg.as_dicom()
self.assertEqual(pg_dcm.PatientID, "12345")

def test_no_tolerance_table(self):
ds = pydicom.dcmread(RT_PLAN_FILE)
ds.pop("ToleranceTableSequence")
Expand Down

0 comments on commit c0d94a4

Please sign in to comment.