From 01cd0e219ea92d74a77cac5a13d4fecc9e256509 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 18 Dec 2023 18:03:43 +0000 Subject: [PATCH] . --- atlas/models.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/atlas/models.py b/atlas/models.py index aa4b54c5..2ce9b44c 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -940,27 +940,26 @@ class UncategorisedDicom(models.Model): def get_basic_dicom_tags(self): try: - ds = pydicom.read_file(self.image) + with pydicom.read_file(self.image) as ds: + to_include = ( + "StudyDescription", + "Modality", + "ProtocolName", + "SeriesDescription", + "SeriesInstanceUID", + "BodyPartExamined", + "SliceThickness", + ) - to_include = ( - "StudyDescription", - "Modality", - "ProtocolName", - "SeriesDescription", - "SeriesInstanceUID", - "BodyPartExamined", - "SliceThickness", - ) + tags = {} - tags = {} + for tag in to_include: + if tag in ds: + tags[tag] = ds[tag].value + else: + tags[tag] = "" - for tag in to_include: - if tag in ds: - tags[tag] = ds[tag].value - else: - tags[tag] = "" - - return tags + return tags except pydicom.errors.InvalidDicomError: return None