Skip to content

Commit c966787

Browse files
a-parida12ashrude
andauthored
feat(repersonlization): add customizable fields (#59)
* feat: add customize repersonalization fields * update readme * Added file with accession number * Add test for custom fields --------- Co-authored-by: Ashley Rudelsheim <[email protected]> Co-authored-by: Ashley Rudelsheim <[email protected]> Co-authored-by: Ashley Rudelsheim <[email protected]>
1 parent a59ca10 commit c966787

File tree

7 files changed

+72
-13
lines changed

7 files changed

+72
-13
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Returns:
9393

9494
## Repersonalisation
9595

96-
It is the process of copying over data regarding the identity of the encapsualted pdf from a template dicom. Currently, the fileds that are repersonalised are-
96+
It is the process of copying over data regarding the identity of the encapsualted pdf from a template dicom. Currently, the fields that are repersonalised by default are-
9797

9898
- PatientName
9999
- PatientID
@@ -103,3 +103,20 @@ It is the process of copying over data regarding the identity of the encapsualte
103103
- ~~SOPInstanceUID~~
104104

105105
The fields `SeriesInstanceUID` and `SOPInstanceUID` have been removed from the repersonalization by copying as it violates the DICOM standards.
106+
107+
You can set the fields to repersonalize by passing repersonalisation_fields into `Pdf2EncapsDCM()`, or `Pdf2RgbSC()`
108+
109+
Example:
110+
111+
```python
112+
fields = [
113+
"PatientName",
114+
"PatientID",
115+
"PatientSex",
116+
"StudyInstanceUID",
117+
"AccessionNumber"
118+
]
119+
converter = Pdf2RgbSC(repersonalisation_fields=fields)
120+
```
121+
122+
note: this will overwrite the default fields.

pdf2dcm/base.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515

1616
class BaseConverter(ABC):
17-
def __init__(self):
18-
self.repersonalisation_fields = [
19-
"PatientName",
20-
"PatientID",
21-
"PatientSex",
22-
"StudyInstanceUID",
23-
]
17+
def __init__(self, repersonalisation_fields=[]):
18+
if len(repersonalisation_fields):
19+
self.repersonalisation_fields = repersonalisation_fields
20+
else:
21+
self.repersonalisation_fields = [
22+
"PatientName",
23+
"PatientID",
24+
"PatientSex",
25+
"StudyInstanceUID",
26+
]
2427

2528
def personalize_dcm(
2629
self, template_dcm_path: Path, pdf_dcm: FileDataset

pdf2dcm/pdf2encaps.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88

99
class Pdf2EncapsDCM(BaseConverter):
10-
def __init__(self):
11-
"""Class for Encapsulated PDF generation"""
12-
super().__init__()
10+
def __init__(self, repersonalisation_fields=[]):
11+
"""Class for Encapsulated PDF generation
12+
13+
Args:
14+
repersonalisation_fields (List<String>, optional): fields to be copied to the new image
15+
"""
16+
super().__init__(repersonalisation_fields=repersonalisation_fields)
1317

1418
def _get_encapspdf_meta(self) -> FileMetaDataset:
1519
"""Get and set the file meta information for the pdf encaps dicom

pdf2dcm/pdf2rgb.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111

1212

1313
class Pdf2RgbSC(BaseConverter):
14-
def __init__(self, dpi=144, merge_pages=False):
14+
def __init__(self, dpi=144, merge_pages=False, repersonalisation_fields=[]):
1515
"""Class for the generation RGB Secondary capture
1616
1717
Args:
1818
dpi (int, optional): dots per inch, set resolution of the image. Defaults to 144.
1919
merge_pages (bool, optional): multiple pgs must be put into 1 dicom. Defaults to False.
20+
repersonalisation_fields (List<String>, optional): fields to be copied to the new image
21+
2022
"""
2123
self.merge_pages_flag = merge_pages
2224
self.dpi = dpi
23-
super().__init__()
25+
super().__init__(repersonalisation_fields=repersonalisation_fields)
2426

2527
def _get_rgbsc_meta(self) -> FileMetaDataset:
2628
"""Get and set the file meta information for the rgb secondary capture dicom

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ def pdfencapsconverter():
2323
@pytest.fixture
2424
def rgbscconverter():
2525
yield Pdf2RgbSC()
26+
27+
@pytest.fixture
28+
def pdfrepersonconverter():
29+
yield Pdf2EncapsDCM(repersonalisation_fields=[
30+
"PatientName",
31+
"PatientID",
32+
"PatientSex",
33+
"StudyInstanceUID",
34+
"AccessionNumber"
35+
])

tests/test_03_repersonalisation.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,26 @@ def test_03_2_name_missing(pdfencapsconverter):
7171
assert dcm_ds.PatientName == ""
7272

7373
os.remove(stored_path)
74+
75+
@pytest.mark.reperson
76+
def test_03_4_additional_fields_personlisation(pdfrepersonconverter):
77+
path_pdf = "tests/test_data/test_file.pdf"
78+
ref_dicom = "tests/test_data/CT_small_accession_number.dcm"
79+
80+
# with personalisation
81+
stored_path = pdfrepersonconverter.run(path_pdf, ref_dicom)[0]
82+
83+
assert os.path.exists(stored_path)
84+
assert pdfrepersonconverter.check_valid_dcm(stored_path)
85+
86+
dcm_ds = pydicom.dcmread(stored_path)
87+
ref_dcm_ds = pydicom.dcmread(ref_dicom)
88+
89+
# check repersonaliation attribute
90+
assert len(dcm_ds.EncapsulatedDocument) == 898332
91+
assert dcm_ds.PatientName == ref_dcm_ds.PatientName
92+
assert dcm_ds.PatientID == ref_dcm_ds.PatientID
93+
assert dcm_ds.PatientSex == ref_dcm_ds.PatientSex
94+
assert dcm_ds.AccessionNumber == ref_dcm_ds.AccessionNumber
95+
96+
os.remove(stored_path)
38.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)