diff --git a/README.md b/README.md index 07045d3..d1647ca 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Returns: ## Repersonalisation -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- +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- - PatientName - PatientID @@ -103,3 +103,20 @@ It is the process of copying over data regarding the identity of the encapsualte - ~~SOPInstanceUID~~ The fields `SeriesInstanceUID` and `SOPInstanceUID` have been removed from the repersonalization by copying as it violates the DICOM standards. + +You can set the fields to repersonalize by passing repersonalisation_fields into `Pdf2EncapsDCM()`, or `Pdf2RgbSC()` + +Example: + +```python +fields = [ + "PatientName", + "PatientID", + "PatientSex", + "StudyInstanceUID", + "AccessionNumber" +] +converter = Pdf2RgbSC(repersonalisation_fields=fields) +``` + +note: this will overwrite the default fields. \ No newline at end of file diff --git a/pdf2dcm/base.py b/pdf2dcm/base.py index ceba830..be53266 100644 --- a/pdf2dcm/base.py +++ b/pdf2dcm/base.py @@ -14,13 +14,16 @@ class BaseConverter(ABC): - def __init__(self): - self.repersonalisation_fields = [ - "PatientName", - "PatientID", - "PatientSex", - "StudyInstanceUID", - ] + def __init__(self, repersonalisation_fields=[]): + if len(repersonalisation_fields): + self.repersonalisation_fields = repersonalisation_fields + else: + self.repersonalisation_fields = [ + "PatientName", + "PatientID", + "PatientSex", + "StudyInstanceUID", + ] def personalize_dcm( self, template_dcm_path: Path, pdf_dcm: FileDataset diff --git a/pdf2dcm/pdf2encaps.py b/pdf2dcm/pdf2encaps.py index 96e3b52..1f405b1 100644 --- a/pdf2dcm/pdf2encaps.py +++ b/pdf2dcm/pdf2encaps.py @@ -7,9 +7,13 @@ class Pdf2EncapsDCM(BaseConverter): - def __init__(self): - """Class for Encapsulated PDF generation""" - super().__init__() + def __init__(self, repersonalisation_fields=[]): + """Class for Encapsulated PDF generation + + Args: + repersonalisation_fields (List, optional): fields to be copied to the new image + """ + super().__init__(repersonalisation_fields=repersonalisation_fields) def _get_encapspdf_meta(self) -> FileMetaDataset: """Get and set the file meta information for the pdf encaps dicom diff --git a/pdf2dcm/pdf2rgb.py b/pdf2dcm/pdf2rgb.py index f8c610a..033b810 100644 --- a/pdf2dcm/pdf2rgb.py +++ b/pdf2dcm/pdf2rgb.py @@ -11,16 +11,18 @@ class Pdf2RgbSC(BaseConverter): - def __init__(self, dpi=144, merge_pages=False): + def __init__(self, dpi=144, merge_pages=False, repersonalisation_fields=[]): """Class for the generation RGB Secondary capture Args: dpi (int, optional): dots per inch, set resolution of the image. Defaults to 144. merge_pages (bool, optional): multiple pgs must be put into 1 dicom. Defaults to False. + repersonalisation_fields (List, optional): fields to be copied to the new image + """ self.merge_pages_flag = merge_pages self.dpi = dpi - super().__init__() + super().__init__(repersonalisation_fields=repersonalisation_fields) def _get_rgbsc_meta(self) -> FileMetaDataset: """Get and set the file meta information for the rgb secondary capture dicom diff --git a/tests/conftest.py b/tests/conftest.py index aafd61a..d07512f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,3 +23,13 @@ def pdfencapsconverter(): @pytest.fixture def rgbscconverter(): yield Pdf2RgbSC() + +@pytest.fixture +def pdfrepersonconverter(): + yield Pdf2EncapsDCM(repersonalisation_fields=[ + "PatientName", + "PatientID", + "PatientSex", + "StudyInstanceUID", + "AccessionNumber" + ]) \ No newline at end of file diff --git a/tests/test_03_repersonalisation.py b/tests/test_03_repersonalisation.py index 97a5a2d..aa41f69 100644 --- a/tests/test_03_repersonalisation.py +++ b/tests/test_03_repersonalisation.py @@ -71,3 +71,26 @@ def test_03_2_name_missing(pdfencapsconverter): assert dcm_ds.PatientName == "" os.remove(stored_path) + +@pytest.mark.reperson +def test_03_4_additional_fields_personlisation(pdfrepersonconverter): + path_pdf = "tests/test_data/test_file.pdf" + ref_dicom = "tests/test_data/CT_small_accession_number.dcm" + + # with personalisation + stored_path = pdfrepersonconverter.run(path_pdf, ref_dicom)[0] + + assert os.path.exists(stored_path) + assert pdfrepersonconverter.check_valid_dcm(stored_path) + + dcm_ds = pydicom.dcmread(stored_path) + ref_dcm_ds = pydicom.dcmread(ref_dicom) + + # check repersonaliation attribute + assert len(dcm_ds.EncapsulatedDocument) == 898332 + assert dcm_ds.PatientName == ref_dcm_ds.PatientName + assert dcm_ds.PatientID == ref_dcm_ds.PatientID + assert dcm_ds.PatientSex == ref_dcm_ds.PatientSex + assert dcm_ds.AccessionNumber == ref_dcm_ds.AccessionNumber + + os.remove(stored_path) \ No newline at end of file diff --git a/tests/test_data/CT_small_accession_number.dcm b/tests/test_data/CT_small_accession_number.dcm new file mode 100644 index 0000000..fba03ed Binary files /dev/null and b/tests/test_data/CT_small_accession_number.dcm differ