From 56a385f5f040dd7287719ff7de9798f70c67944e Mon Sep 17 00:00:00 2001 From: Aysel Afsar Date: Mon, 23 Dec 2024 20:24:18 -0500 Subject: [PATCH] #136 Skip DICOM files without required uids (#138) - Encode url path segments --- lib/Controller/DisplayController.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Controller/DisplayController.php b/lib/Controller/DisplayController.php index c31f975..c83f6ae 100755 --- a/lib/Controller/DisplayController.php +++ b/lib/Controller/DisplayController.php @@ -174,6 +174,18 @@ private function isEncryptionEnabled() { return $encryptionEnabled === 'yes'; } + private function encodeUrlPathSegments($url) { + $segments = explode('/', $url); + + foreach ($segments as $index => $segment) { + if ($index > 2 && $segment !== '') { + $segments[$index] = rawurlencode($segment); + } + } + + return implode('/', $segments); + } + private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFileFullPath, $parentFullPath, $currentUserPathToFile, $downloadUrlPrefix, $isPublic, $singlePublicFileDownload) { $dicomJson = array('studies' => array()); @@ -271,6 +283,11 @@ private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFi $WindowWidth = $this->cleanDICOMTagValue($dicom->value(0x0028, 0x1051)); $SeriesDate = $this->cleanDICOMTagValue($dicom->value(0x0008, 0x0021)); + if (!$StudyInstanceUID || !$SeriesInstanceUID || !$SOPInstanceUID) { + // Skip if any of the required tags are missing + continue; + } + // STUDY $studyIndex = $this->arrayFindIndex($dicomJson['studies'], 'StudyInstanceUID', $StudyInstanceUID); if ($studyIndex < 0) { @@ -335,7 +352,7 @@ private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFi 'WindowWidth' => $WindowWidth ? explode('\\', $WindowWidth)[0] : $WindowWidth, 'SeriesDate' => $SeriesDate, ), - 'url' => 'dicomweb:'.$fileUrl, + 'url' => 'dicomweb:'.$this->encodeUrlPathSegments($fileUrl), ); array_push($dicomJson['studies'][$studyIndex]['series'][$seriesIndex]['instances'], $instance); $dicomJson['studies'][$studyIndex]['NumInstances']++;