Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#135 Add metadata for multi-frame images #141

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions lib/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public function __construct(IConfig $config,
$this->dataFolder = $this->config->getSystemValue('datadirectory');
}

private function detectMimeType($path) {
$mimeType = $this->mimeTypeDetector->detectPath($path);
if ($mimeType === 'application/octet-stream') {
if (pathinfo($path, PATHINFO_EXTENSION) === 'wasm') {
$mimeType = 'application/wasm';
} else {
$mimeType = mime_content_type($path);
}
}
return $mimeType;
}

private function getAppManager(): IAppManager {
if ($this->appManager !== null) {
return $this->appManager;
Expand Down Expand Up @@ -282,6 +294,7 @@ private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFi
$WindowCenter = $this->cleanDICOMTagValue($dicom->value(0x0028, 0x1050));
$WindowWidth = $this->cleanDICOMTagValue($dicom->value(0x0028, 0x1051));
$SeriesDate = $this->cleanDICOMTagValue($dicom->value(0x0008, 0x0021));
$NumberOfFrames = $this->cleanDICOMTagValue($dicom->value(0x0028, 0x0008));

if (!$StudyInstanceUID || !$SeriesInstanceUID || !$SOPInstanceUID) {
// Skip if any of the required tags are missing
Expand Down Expand Up @@ -351,10 +364,20 @@ private function generateDICOMJson($dicomFilePaths, $dicomFileNodes, $selectedFi
'WindowCenter' => $WindowCenter ? explode('\\', $WindowCenter)[0] : $WindowCenter,
'WindowWidth' => $WindowWidth ? explode('\\', $WindowWidth)[0] : $WindowWidth,
'SeriesDate' => $SeriesDate,
'NumberOfFrames' => $NumberOfFrames,
),
'url' => 'dicomweb:'.$fileUrl,
);
array_push($dicomJson['studies'][$studyIndex]['series'][$seriesIndex]['instances'], $instance);

if ($NumberOfFrames > 1) {
for ($i = 1; $i <= $NumberOfFrames; $i++) {
$instance['url'] = 'dicomweb:'.$fileUrl.'?frame='.$i;
array_push($dicomJson['studies'][$studyIndex]['series'][$seriesIndex]['instances'], $instance);
}
} else {
array_push($dicomJson['studies'][$studyIndex]['series'][$seriesIndex]['instances'], $instance);
}

$dicomJson['studies'][$studyIndex]['NumInstances']++;
if ($dicomJson['studies'][$studyIndex]['Modalities'] == '' || !in_array($Modality, explode(',', $dicomJson['studies'][$studyIndex]['Modalities']))) {
if ($dicomJson['studies'][$studyIndex]['Modalities'] == '') {
Expand Down Expand Up @@ -456,7 +479,7 @@ public function getDICOMViewerFile(string $filepath): StreamResponse {
$response = new StreamResponse($fpHandle);
$fileMimeType = mime_content_type($fullFilePath);
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($filename) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->detectPath($fullFilePath));
$response->addHeader('Content-Type', $this->detectMimeType($fullFilePath));
$response->setContentSecurityPolicy($this->getContentSecurityPolicy());
$response->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$response->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
Expand All @@ -477,7 +500,7 @@ public function getDICOMViewerAsset(string $assetpath): StreamResponse {

$response = new StreamResponse(fopen($fullFilePath, 'rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($filename) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->detectPath($fullFilePath));
$response->addHeader('Content-Type', $this->detectMimeType($fullFilePath));
$response->setContentSecurityPolicy($this->getContentSecurityPolicy());
$response->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$response->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
Expand All @@ -498,7 +521,7 @@ public function getDICOMViewerAssetSub(string $assetpath): StreamResponse {

$response = new StreamResponse(fopen($fullFilePath, 'rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($filename) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->detectPath($fullFilePath));
$response->addHeader('Content-Type', $this->detectMimeType($fullFilePath));
$response->setContentSecurityPolicy($this->getContentSecurityPolicy());
$response->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$response->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
Expand All @@ -519,7 +542,7 @@ public function getDICOMViewerAssetImages(string $assetpath): StreamResponse {

$response = new StreamResponse(fopen($fullFilePath, 'rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($filename) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->detectPath($fullFilePath));
$response->addHeader('Content-Type', $this->detectMimeType($fullFilePath));
$response->setContentSecurityPolicy($this->getContentSecurityPolicy());
$response->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$response->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
Expand All @@ -540,7 +563,7 @@ public function getDICOMViewerAssetSubImages(string $assetpath): StreamResponse

$response = new StreamResponse(fopen($fullFilePath, 'rb'));
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurldecode($filename) . '"');
$response->addHeader('Content-Type', $this->mimeTypeDetector->detectPath($fullFilePath));
$response->addHeader('Content-Type', $this->detectMimeType($fullFilePath));
$response->setContentSecurityPolicy($this->getContentSecurityPolicy());
$response->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$response->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
Expand Down
Loading