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