Commit 7918761f authored by Gabriel Couture's avatar Gabriel Couture

Add apply_layer function

parent 73a64028
{
"BrachyTreatmentType": "HDR",
"TreatmentSites": "Prostate",
"RTPlanName": "Live",
"FractionGroupSequence": {
"ReferencedBrachyApplicationSetupSequence": {
"BrachyApplicationSetupDose": 12.0
}
}
}
\ No newline at end of file
......@@ -7,10 +7,15 @@ from pydicom import FileDataset
def apply_layer(layer: Dict, dataset: FileDataset) -> FileDataset:
# for item in dataset:
# print(item)
for key, value in layer.items():
if type(value) is list or type(value) is dict:
pass
if type(value) is dict:
for dataset_item in eval(f'dataset.{key}'):
apply_layer(value, dataset_item)
dataset[key] = value
else:
exec(f'dataset.{key} = value')
return dataset
# coding: utf-8
# author: Gabriel Couture
import unittest
from dicomgenerator import dao, layer
A_LAYER_NAME = 'HDQID'
A_COMPLEX_LAYER_NAME = 'OCP_HDR_live_prostate'
class TestLayer(unittest.TestCase):
def setUp(self) -> None:
self.layer = dao.get_layer(A_LAYER_NAME)
self.dataset = dao.get_rtplan()
def tearDown(self) -> None:
del self.layer
del self.dataset
def test_givenADatasetAndALayer_whenApplyingLayer_thenResultExpectedDataset(self):
expected_patient_id = '03HDQ000'
result = layer.apply_layer(self.layer, self.dataset)
self.assertEqual(result.PatientID, expected_patient_id)
def test_givenARtplanDatasetAndAComplexLayer_whenApplyingLayer_thenResultExpectedDataset(self):
expected_brachy_application_setup_sequence = 99
a_complex_layer = dao.get_layer(A_COMPLEX_LAYER_NAME)
a_complex_layer['FractionGroupSequence']['ReferencedBrachyApplicationSetupSequence']['BrachyApplicationSetupDose'] = expected_brachy_application_setup_sequence
result = layer.apply_layer(a_complex_layer, self.dataset)
self.assertEqual(
result.FractionGroupSequence[0].ReferencedBrachyApplicationSetupSequence[0].BrachyApplicationSetupDose,
expected_brachy_application_setup_sequence
)
......@@ -20,8 +20,8 @@ class TestWriter(unittest.TestCase):
shutil.rmtree(A_TARGET_DIRECTORY)
def tearDown(self) -> None:
# shutil.rmtree(A_TARGET_DIRECTORY)
pass
if os.path.exists(A_TARGET_DIRECTORY):
shutil.rmtree(A_TARGET_DIRECTORY)
def test_givenATargetDirectoryAndASetOfValidParameters_whenWritingDicomRt_thenDirectoryWithDicomFilesAndDVHAndMetadataIsWorte(self):
writer.write_dicom_rt(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment