diff --git a/src/library/SmiServices/DicomText.py b/src/library/SmiServices/DicomText.py index 3213c20..33eb911 100644 --- a/src/library/SmiServices/DicomText.py +++ b/src/library/SmiServices/DicomText.py @@ -91,6 +91,16 @@ def __init__( def __repr__(self) -> str: return f'' + def enableTag(self, tagname: str) -> None: + """ Enable the redation of a specific DICOM tag, + by turning redact=True for the tag in sr_keys_to_extract. + NOTE: this modifies the global variable, so all subsequent + instances of DicomText will use the new value. + """ + for entry in sr_keys_to_extract: + if entry['tag']==tagname: + entry['redact']=True + def setRedactChar(self, rchar: str) -> None: """ Change the character used to anonymise/redact text. Can be a single character or an empty string. @@ -476,6 +486,7 @@ def test_DicomText() -> None: [[Patient Birth Date]] 19781024 [[Patient Sex]] M [[Referring Physician Name]] +[[ImageComments]] 19/02/20180.82680-1.51140.75.086.15 [[Other Names]] John R Walz [[ContentSequence]] # Request @@ -493,6 +504,43 @@ def test_DicomText() -> None: . +There is bruising of the medial femoral condyle with some intrasubstance injury to the medial collateral ligament. The lateral collateral ligament in intact. The Baker's cruciate ligament is irregular and slightly lax suggesting a partial tear. It does not appear to be completely torn. The posterior cruciate ligament is intact. The suprapatellar tendons are normal. +# Finding +There is a tear of the posterior limb of the medial meniscus which communicates with the superior articular surface. The lateral meniscus is intact. There is a Baker's cyst and moderate joint effusion. +# Finding +Internal derangement of the right knee with marked injury and with partial tear of the ACL; there is a tear of the posterior limb of the medial meniscus. There is a Baker's Cyst and joint effusion and intrasubstance injury to the medial collateral ligament. +# Best illustration of finding +[[EndContentSequence]] +""" + expected_with_header_and_imagecomments = """[[Study Description]] OFFIS Structured Reporting Samples +[[Study Date]] +[[Series Description]] RSNA '95, Picker, MR +[[Content Date]] 20050530 +[[Patient ID]] PIKR752962 +[[Patient Name]] John R Walz +[[Patient Birth Date]] 19781024 +[[Patient Sex]] M +[[Referring Physician Name]] +[[Other Names]] John R Walz +[[ImageComments]] +................................................19/02/2018.....................................................................................................0.826................................80.............................-1.5.......................................114.............................0.7....................................5.08................................6.15.................................. +[[EndImageComments]] +[[ContentSequence]] +# Request +MRI: Knee +# History +16 year old with right knee pain after an injury playing basketball. +# Findings +# Finding +...... +.................................. + +. + +.. + +. + There is bruising of the medial femoral condyle with some intrasubstance injury to the medial collateral ligament. The lateral collateral ligament in intact. The Baker's cruciate ligament is irregular and slightly lax suggesting a partial tear. It does not appear to be completely torn. The posterior cruciate ligament is intact. The suprapatellar tendons are normal. # Finding There is a tear of the posterior limb of the medial meniscus which communicates with the superior articular surface. The lateral meniscus is intact. There is a Baker's cyst and moderate joint effusion. @@ -696,7 +744,8 @@ def test_DicomText() -> None: } } ] - } + }, + "ImageComments": { "vr": "LT", "Value": [ "19/02/20180.82680-1.51140.75.086.15" ]} } """ @@ -724,3 +773,9 @@ def test_DicomText() -> None: dt = DicomText(dcm, include_header = False, replace_HTML_entities = False) dt.parse() assert(dt.text() == expected_without_header_with_html) + + # Parse with the normal header tags included - and enable ImageComments + dt = DicomText(dcm) + dt.enableTag('ImageComments') + dt.parse() + assert(dt.text() == expected_with_header_and_imagecomments)