Mercurial > hg > orthanc
annotate OrthancServer/OrthancRestApi/OrthancRestArchive.cpp @ 2531:b7ed112ce56e
DownloadOrthancFramework.cmake
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Apr 2018 16:24:33 +0200 |
parents | 878b59270859 |
children | 00b6a7f935fc |
rev | line source |
---|---|
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1121
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2446
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "../PrecompiledHeadersServer.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "OrthancRestApi.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
37 #include "../../Core/DicomParsing/DicomDirWriter.h" |
1775 | 38 #include "../../Core/FileStorage/StorageAccessor.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include "../../Core/Compression/HierarchicalZipWriter.h" |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 #include "../../Core/HttpServer/FilesystemHttpSender.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1437
diff
changeset
|
41 #include "../../Core/Logging.h" |
2142 | 42 #include "../../Core/TemporaryFile.h" |
1437
02f5a3f5c0a0
access to the REST API from Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1315
diff
changeset
|
43 #include "../ServerContext.h" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
45 #include <stdio.h> |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 #if defined(_MSC_VER) |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 #define snprintf _snprintf |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 #endif |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 static const uint64_t MEGA_BYTES = 1024 * 1024; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 static const uint64_t GIGA_BYTES = 1024 * 1024 * 1024; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 namespace Orthanc |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 { |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 // Download of ZIP files ---------------------------------------------------- |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
58 static bool IsZip64Required(uint64_t uncompressedSize, |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
59 unsigned int countInstances) |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
61 static const uint64_t SAFETY_MARGIN = 64 * MEGA_BYTES; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
62 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 /** |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 * Determine whether ZIP64 is required. Original ZIP format can |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 * store up to 2GB of data (some implementation supporting up to |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 * 4GB of data), and up to 65535 files. |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 **/ |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
70 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN || |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 countInstances >= 65535); |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size " |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 << (uncompressedSize / MEGA_BYTES) << "MB using the " |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 << (isZip64 ? "ZIP64" : "ZIP32") << " file format"; |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
1121
82567bac5e25
Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
976
diff
changeset
|
77 return isZip64; |
82567bac5e25
Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
976
diff
changeset
|
78 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
79 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
80 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
81 namespace |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
82 { |
1776 | 83 class ResourceIdentifiers |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
84 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
85 private: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
86 ResourceType level_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
87 std::string patient_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
88 std::string study_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
89 std::string series_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
90 std::string instance_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
91 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
92 static void GoToParent(ServerIndex& index, |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
93 std::string& current) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
94 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
95 std::string tmp; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
96 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
97 if (index.LookupParent(tmp, current)) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
98 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
99 current = tmp; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
100 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
101 else |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
102 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
103 throw OrthancException(ErrorCode_UnknownResource); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
104 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
105 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
106 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
107 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
108 public: |
1776 | 109 ResourceIdentifiers(ServerIndex& index, |
110 const std::string& publicId) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
111 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
112 if (!index.LookupResourceType(level_, publicId)) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
113 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
114 throw OrthancException(ErrorCode_UnknownResource); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
115 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
116 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
117 std::string current = publicId;; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
118 switch (level_) // Do not add "break" below! |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
119 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
120 case ResourceType_Instance: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
121 instance_ = current; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
122 GoToParent(index, current); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
123 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
124 case ResourceType_Series: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
125 series_ = current; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
126 GoToParent(index, current); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
127 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
128 case ResourceType_Study: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
129 study_ = current; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
130 GoToParent(index, current); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
131 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
132 case ResourceType_Patient: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
133 patient_ = current; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
134 break; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
135 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
136 default: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
137 throw OrthancException(ErrorCode_InternalError); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
138 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
139 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
140 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
141 ResourceType GetLevel() const |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
142 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
143 return level_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
144 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
145 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
146 const std::string& GetIdentifier(ResourceType level) const |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
147 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
148 // Some sanity check to ensure enumerations are not altered |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
149 assert(ResourceType_Patient < ResourceType_Study); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
150 assert(ResourceType_Study < ResourceType_Series); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
151 assert(ResourceType_Series < ResourceType_Instance); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
152 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
153 if (level > level_) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
154 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
155 throw OrthancException(ErrorCode_InternalError); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
156 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
157 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
158 switch (level) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
159 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
160 case ResourceType_Patient: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
161 return patient_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
162 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
163 case ResourceType_Study: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
164 return study_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
165 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
166 case ResourceType_Series: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
167 return series_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
168 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
169 case ResourceType_Instance: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
170 return instance_; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
171 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
172 default: |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
173 throw OrthancException(ErrorCode_InternalError); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
174 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
175 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
176 }; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
177 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
178 |
1775 | 179 class IArchiveVisitor : public boost::noncopyable |
180 { | |
181 public: | |
182 virtual ~IArchiveVisitor() | |
183 { | |
184 } | |
185 | |
186 virtual void Open(ResourceType level, | |
187 const std::string& publicId) = 0; | |
188 | |
189 virtual void Close() = 0; | |
190 | |
191 virtual void AddInstance(const std::string& instanceId, | |
192 const FileInfo& dicom) = 0; | |
193 }; | |
194 | |
195 | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
196 class ArchiveIndex |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
197 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
198 private: |
1775 | 199 struct Instance |
200 { | |
201 std::string id_; | |
202 FileInfo dicom_; | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
203 |
1775 | 204 Instance(const std::string& id, |
205 const FileInfo& dicom) : | |
206 id_(id), dicom_(dicom) | |
207 { | |
208 } | |
209 }; | |
210 | |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
211 // A "NULL" value for ArchiveIndex indicates a non-expanded node |
1775 | 212 typedef std::map<std::string, ArchiveIndex*> Resources; |
213 | |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
214 ResourceType level_; |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
215 Resources resources_; // Only at patient/study/series level |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
216 std::list<Instance> instances_; // Only at instance level |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
217 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
218 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
219 void AddResourceToExpand(ServerIndex& index, |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
220 const std::string& id) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
221 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
222 if (level_ == ResourceType_Instance) |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
223 { |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
224 FileInfo tmp; |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
225 if (index.LookupAttachment(tmp, id, FileContentType_Dicom)) |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
226 { |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
227 instances_.push_back(Instance(id, tmp)); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
228 } |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
229 } |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
230 else |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
231 { |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
232 resources_[id] = NULL; |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
233 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
234 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
235 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
236 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
237 public: |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
238 ArchiveIndex(ResourceType level) : |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
239 level_(level) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
240 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
241 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
242 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
243 ~ArchiveIndex() |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
244 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
245 for (Resources::iterator it = resources_.begin(); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
246 it != resources_.end(); ++it) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
247 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
248 delete it->second; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
249 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
250 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
251 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
252 |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
253 void Add(ServerIndex& index, |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
254 const ResourceIdentifiers& resource) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
255 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
256 const std::string& id = resource.GetIdentifier(level_); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
257 Resources::iterator previous = resources_.find(id); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
258 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
259 if (level_ == ResourceType_Instance) |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
260 { |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
261 AddResourceToExpand(index, id); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
262 } |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
263 else if (resource.GetLevel() == level_) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
264 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
265 // Mark this resource for further expansion |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
266 if (previous != resources_.end()) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
267 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
268 delete previous->second; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
269 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
270 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
271 resources_[id] = NULL; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
272 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
273 else if (previous == resources_.end()) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
274 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
275 // This is the first time we meet this resource |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
276 std::auto_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
277 child->Add(index, resource); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
278 resources_[id] = child.release(); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
279 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
280 else if (previous->second != NULL) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
281 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
282 previous->second->Add(index, resource); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
283 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
284 else |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
285 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
286 // Nothing to do: This item is marked for further expansion |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
287 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
288 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
289 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
290 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
291 void Expand(ServerIndex& index) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
292 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
293 if (level_ == ResourceType_Instance) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
294 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
295 // Expanding an instance node makes no sense |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
296 return; |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
297 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
298 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
299 for (Resources::iterator it = resources_.begin(); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
300 it != resources_.end(); ++it) |
1775 | 301 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
302 if (it->second == NULL) |
1775 | 303 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
304 // This is resource is marked for expansion |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
305 std::list<std::string> children; |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
306 index.GetChildren(children, it->first); |
1775 | 307 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
308 std::auto_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_))); |
1775 | 309 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
310 for (std::list<std::string>::const_iterator |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
311 it2 = children.begin(); it2 != children.end(); ++it2) |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
312 { |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
313 child->AddResourceToExpand(index, *it2); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
314 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
315 |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
316 it->second = child.release(); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
317 } |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
318 |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
319 assert(it->second != NULL); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
320 it->second->Expand(index); |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
321 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
322 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
323 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
324 |
1775 | 325 void Apply(IArchiveVisitor& visitor) const |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
326 { |
1775 | 327 if (level_ == ResourceType_Instance) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
328 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
329 for (std::list<Instance>::const_iterator |
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
330 it = instances_.begin(); it != instances_.end(); ++it) |
1775 | 331 { |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
332 visitor.AddInstance(it->id_, it->dicom_); |
1775 | 333 } |
334 } | |
335 else | |
336 { | |
337 for (Resources::const_iterator it = resources_.begin(); | |
338 it != resources_.end(); ++it) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
339 { |
1775 | 340 assert(it->second != NULL); // There must have been a call to "Expand()" |
341 visitor.Open(level_, it->first); | |
342 it->second->Apply(visitor); | |
343 visitor.Close(); | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
344 } |
1775 | 345 } |
346 } | |
347 }; | |
348 | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
349 |
1775 | 350 class StatisticsVisitor : public IArchiveVisitor |
351 { | |
352 private: | |
353 uint64_t size_; | |
354 unsigned int instances_; | |
355 | |
356 public: | |
357 StatisticsVisitor() : size_(0), instances_(0) | |
358 { | |
359 } | |
360 | |
361 uint64_t GetUncompressedSize() const | |
362 { | |
363 return size_; | |
364 } | |
365 | |
366 unsigned int GetInstancesCount() const | |
367 { | |
368 return instances_; | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
369 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
370 |
1775 | 371 virtual void Open(ResourceType level, |
372 const std::string& publicId) | |
373 { | |
374 } | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
375 |
1775 | 376 virtual void Close() |
377 { | |
378 } | |
379 | |
380 virtual void AddInstance(const std::string& instanceId, | |
381 const FileInfo& dicom) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
382 { |
1775 | 383 instances_ ++; |
384 size_ += dicom.GetUncompressedSize(); | |
385 } | |
386 }; | |
387 | |
388 | |
389 class PrintVisitor : public IArchiveVisitor | |
390 { | |
391 private: | |
392 std::ostream& out_; | |
393 std::string indent_; | |
394 | |
395 public: | |
396 PrintVisitor(std::ostream& out) : out_(out) | |
397 { | |
398 } | |
399 | |
400 virtual void Open(ResourceType level, | |
401 const std::string& publicId) | |
402 { | |
403 switch (level) | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
404 { |
1775 | 405 case ResourceType_Patient: indent_ = ""; break; |
406 case ResourceType_Study: indent_ = " "; break; | |
407 case ResourceType_Series: indent_ = " "; break; | |
408 default: | |
409 throw OrthancException(ErrorCode_InternalError); | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
410 } |
1775 | 411 |
412 out_ << indent_ << publicId << std::endl; | |
413 } | |
414 | |
415 virtual void Close() | |
416 { | |
417 } | |
418 | |
419 virtual void AddInstance(const std::string& instanceId, | |
420 const FileInfo& dicom) | |
421 { | |
422 out_ << " " << instanceId << std::endl; | |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
423 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
424 }; |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
425 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
426 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
427 class ArchiveWriterVisitor : public IArchiveVisitor |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
428 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
429 private: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
430 HierarchicalZipWriter& writer_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
431 ServerContext& context_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
432 char instanceFormat_[24]; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
433 unsigned int countInstances_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
434 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
435 static std::string GetTag(const DicomMap& tags, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
436 const DicomTag& tag) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
437 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
438 const DicomValue* v = tags.TestAndGetValue(tag); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
439 if (v != NULL && |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
440 !v->IsBinary() && |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
441 !v->IsNull()) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
442 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
443 return v->GetContent(); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
444 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
445 else |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
446 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
447 return ""; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
448 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
449 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
450 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
451 public: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
452 ArchiveWriterVisitor(HierarchicalZipWriter& writer, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
453 ServerContext& context) : |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
454 writer_(writer), |
1847 | 455 context_(context), |
456 countInstances_(0) | |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
457 { |
1847 | 458 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
459 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
460 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
461 virtual void Open(ResourceType level, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
462 const std::string& publicId) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
463 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
464 std::string path; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
465 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
466 DicomMap tags; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
467 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level)) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
468 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
469 switch (level) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
470 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
471 case ResourceType_Patient: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
472 path = GetTag(tags, DICOM_TAG_PATIENT_ID) + " " + GetTag(tags, DICOM_TAG_PATIENT_NAME); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
473 break; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
474 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
475 case ResourceType_Study: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
476 path = GetTag(tags, DICOM_TAG_ACCESSION_NUMBER) + " " + GetTag(tags, DICOM_TAG_STUDY_DESCRIPTION); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
477 break; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
478 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
479 case ResourceType_Series: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
480 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
481 std::string modality = GetTag(tags, DICOM_TAG_MODALITY); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
482 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
483 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
484 if (modality.size() == 0) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
485 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
486 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
487 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
488 else if (modality.size() == 1) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
489 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
490 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm", |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
491 toupper(modality[0])); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
492 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
493 else if (modality.size() >= 2) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
494 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
495 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm", |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
496 toupper(modality[0]), toupper(modality[1])); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
497 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
498 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
499 countInstances_ = 0; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
500 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
501 break; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
502 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
503 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
504 default: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
505 throw OrthancException(ErrorCode_InternalError); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
506 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
507 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
508 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
509 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path)); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
510 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
511 if (path.empty()) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
512 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
513 path = std::string("Unknown ") + EnumerationToString(level); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
514 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
515 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
516 writer_.OpenDirectory(path.c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
517 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
518 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
519 virtual void Close() |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
520 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
521 writer_.CloseDirectory(); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
522 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
523 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
524 virtual void AddInstance(const std::string& instanceId, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
525 const FileInfo& dicom) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
526 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
527 std::string content; |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
528 context_.ReadAttachment(content, dicom); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
529 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
530 char filename[24]; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
531 snprintf(filename, sizeof(filename) - 1, instanceFormat_, countInstances_); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
532 countInstances_ ++; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
533 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
534 writer_.OpenFile(filename); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
535 writer_.Write(content); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
536 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
537 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
538 static void Apply(RestApiOutput& output, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
539 ServerContext& context, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
540 ArchiveIndex& archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
541 const std::string& filename) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
542 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
543 archive.Expand(context.GetIndex()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
544 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
545 StatisticsVisitor stats; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
546 archive.Apply(stats); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
547 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
548 const bool isZip64 = IsZip64Required(stats.GetUncompressedSize(), stats.GetInstancesCount()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
549 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
550 // Create a RAII for the temporary file to manage the ZIP file |
2140 | 551 TemporaryFile tmp; |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
552 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
553 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
554 // Create a ZIP writer |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
555 HierarchicalZipWriter writer(tmp.GetPath().c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
556 writer.SetZip64(isZip64); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
557 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
558 ArchiveWriterVisitor v(writer, context); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
559 archive.Apply(v); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
560 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
561 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
562 // Prepare the sending of the ZIP file |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
563 FilesystemHttpSender sender(tmp.GetPath()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
564 sender.SetContentType("application/zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
565 sender.SetContentFilename(filename); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
566 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
567 // Send the ZIP |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
568 output.AnswerStream(sender); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
569 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
570 // The temporary file is automatically removed thanks to the RAII |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
571 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
572 }; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
573 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
574 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
575 class MediaWriterVisitor : public IArchiveVisitor |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
576 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
577 private: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
578 HierarchicalZipWriter& writer_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
579 DicomDirWriter dicomDir_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
580 ServerContext& context_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
581 unsigned int countInstances_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
582 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
583 public: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
584 MediaWriterVisitor(HierarchicalZipWriter& writer, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
585 ServerContext& context) : |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
586 writer_(writer), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
587 context_(context), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
588 countInstances_(0) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
589 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
590 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
591 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
592 void EncodeDicomDir(std::string& result) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
593 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
594 dicomDir_.Encode(result); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
595 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
596 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
597 virtual void Open(ResourceType level, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
598 const std::string& publicId) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
599 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
600 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
601 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
602 virtual void Close() |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
603 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
604 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
605 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
606 virtual void AddInstance(const std::string& instanceId, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
607 const FileInfo& dicom) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
608 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
609 // "DICOM restricts the filenames on DICOM media to 8 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
610 // characters (some systems wrongly use 8.3, but this does not |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
611 // conform to the standard)." |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
612 std::string filename = "IM" + boost::lexical_cast<std::string>(countInstances_); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
613 writer_.OpenFile(filename.c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
614 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
615 std::string content; |
2128
9329ba17a069
Possibility to DELETE "dicom-as-json" attachments to reconstruct them
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
616 context_.ReadAttachment(content, dicom); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
617 writer_.Write(content); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
618 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
619 ParsedDicomFile parsed(content); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
620 dicomDir_.Add("IMAGES", filename, parsed); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
621 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
622 countInstances_ ++; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
623 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
624 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
625 static void Apply(RestApiOutput& output, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
626 ServerContext& context, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
627 ArchiveIndex& archive, |
2422
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
628 const std::string& filename, |
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
629 bool enableExtendedSopClass) |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
630 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
631 archive.Expand(context.GetIndex()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
632 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
633 StatisticsVisitor stats; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
634 archive.Apply(stats); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
635 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
636 const bool isZip64 = IsZip64Required(stats.GetUncompressedSize(), stats.GetInstancesCount()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
637 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
638 // Create a RAII for the temporary file to manage the ZIP file |
2140 | 639 TemporaryFile tmp; |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
640 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
641 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
642 // Create a ZIP writer |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
643 HierarchicalZipWriter writer(tmp.GetPath().c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
644 writer.SetZip64(isZip64); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
645 writer.OpenDirectory("IMAGES"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
646 |
2422
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
647 // Create a DICOMDIR writer |
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
648 MediaWriterVisitor v(writer, context); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
649 |
2422
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
650 // Request type-3 arguments to be added to the DICOMDIR |
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
651 v.dicomDir_.EnableExtendedSopClass(enableExtendedSopClass); |
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
652 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
653 archive.Apply(v); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
654 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
655 // Add the DICOMDIR |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
656 writer.CloseDirectory(); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
657 writer.OpenFile("DICOMDIR"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
658 std::string s; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
659 v.EncodeDicomDir(s); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
660 writer.Write(s); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
661 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
662 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
663 // Prepare the sending of the ZIP file |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
664 FilesystemHttpSender sender(tmp.GetPath()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
665 sender.SetContentType("application/zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
666 sender.SetContentFilename(filename); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
667 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
668 // Send the ZIP |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
669 output.AnswerStream(sender); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
670 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
671 // The temporary file is automatically removed thanks to the RAII |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
672 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
673 }; |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
674 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
675 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
676 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
677 static bool AddResourcesOfInterest(ArchiveIndex& archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
678 RestApiPostCall& call) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
679 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
680 ServerIndex& index = OrthancRestApi::GetIndex(call); |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
681 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
682 Json::Value resources; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
683 if (call.ParseJsonRequest(resources) && |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
684 resources.type() == Json::arrayValue) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
685 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
686 for (Json::Value::ArrayIndex i = 0; i < resources.size(); i++) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
687 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
688 if (resources[i].type() != Json::stringValue) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
689 { |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
690 return false; // Bad request |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
691 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
692 |
1776 | 693 ResourceIdentifiers resource(index, resources[i].asString()); |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
694 archive.Add(index, resource); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
695 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
696 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
697 return true; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
698 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
699 else |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
700 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
701 return false; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
702 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
703 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
704 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
705 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
706 static void CreateBatchArchive(RestApiPostCall& call) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
707 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
708 ArchiveIndex archive(ResourceType_Patient); // root |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
709 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
710 if (AddResourcesOfInterest(archive, call)) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
711 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
712 ArchiveWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
713 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
714 archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
715 "Archive.zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
716 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
717 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
718 |
2446
a894adc8bb03
/tools/create-media-extended to include type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2422
diff
changeset
|
719 |
a894adc8bb03
/tools/create-media-extended to include type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2422
diff
changeset
|
720 template <bool Extended> |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
721 static void CreateBatchMedia(RestApiPostCall& call) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
722 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
723 ArchiveIndex archive(ResourceType_Patient); // root |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
724 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
725 if (AddResourcesOfInterest(archive, call)) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
726 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
727 MediaWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
728 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
729 archive, |
2422
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
730 "Archive.zip", |
2446
a894adc8bb03
/tools/create-media-extended to include type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2422
diff
changeset
|
731 Extended); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
732 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
733 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
734 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
735 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
736 static void CreateArchive(RestApiGetCall& call) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
737 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
738 ServerIndex& index = OrthancRestApi::GetIndex(call); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
739 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
740 std::string id = call.GetUriComponent("id", ""); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
741 ResourceIdentifiers resource(index, id); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
742 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
743 ArchiveIndex archive(ResourceType_Patient); // root |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
744 archive.Add(OrthancRestApi::GetIndex(call), resource); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
745 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
746 ArchiveWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
747 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
748 archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
749 id + ".zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
750 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
751 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
752 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
753 static void CreateMedia(RestApiGetCall& call) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
754 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
755 ServerIndex& index = OrthancRestApi::GetIndex(call); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
756 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
757 std::string id = call.GetUriComponent("id", ""); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
758 ResourceIdentifiers resource(index, id); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
759 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
760 ArchiveIndex archive(ResourceType_Patient); // root |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
761 archive.Add(OrthancRestApi::GetIndex(call), resource); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
762 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
763 MediaWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
764 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
765 archive, |
2422
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
766 id + ".zip", |
b340f0a9022c
New argument "/.../media?extended" to include additional type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
767 call.HasArgument("extended")); |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
768 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
769 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
770 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
771 void OrthancRestApi::RegisterArchive() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
772 { |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
773 Register("/patients/{id}/archive", CreateArchive); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
774 Register("/studies/{id}/archive", CreateArchive); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
775 Register("/series/{id}/archive", CreateArchive); |
1121
82567bac5e25
Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
976
diff
changeset
|
776 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
777 Register("/patients/{id}/media", CreateMedia); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
778 Register("/studies/{id}/media", CreateMedia); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
779 Register("/series/{id}/media", CreateMedia); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
780 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
781 Register("/tools/create-archive", CreateBatchArchive); |
2446
a894adc8bb03
/tools/create-media-extended to include type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2422
diff
changeset
|
782 Register("/tools/create-media", CreateBatchMedia<false>); |
a894adc8bb03
/tools/create-media-extended to include type-3 tags in DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2422
diff
changeset
|
783 Register("/tools/create-media-extended", CreateBatchMedia<true>); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
784 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
785 } |