Mercurial > hg > orthanc
annotate OrthancServer/OrthancRestApi/OrthancRestArchive.cpp @ 1799:4f01c9d73f02 worklists
calledAet made available to all the handlers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 20 Nov 2015 12:57:14 +0100 |
parents | 776573e592da |
children | 559956d5ceb2 |
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 |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1121
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
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" |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 #include "../../Core/Uuid.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), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
454 context_(context) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
455 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
456 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
457 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
458 virtual void Open(ResourceType level, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
459 const std::string& publicId) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
460 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
461 std::string path; |
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 DicomMap tags; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
464 if (context_.GetIndex().GetMainDicomTags(tags, publicId, level, level)) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
465 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
466 switch (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 case ResourceType_Patient: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
469 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
|
470 break; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
471 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
472 case ResourceType_Study: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
473 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
|
474 break; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
475 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
476 case ResourceType_Series: |
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 std::string modality = GetTag(tags, DICOM_TAG_MODALITY); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
479 path = modality + " " + GetTag(tags, DICOM_TAG_SERIES_DESCRIPTION); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
480 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
481 if (modality.size() == 0) |
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 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%%08d.dcm"); |
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 else if (modality.size() == 1) |
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 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%%07d.dcm", |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
488 toupper(modality[0])); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
489 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
490 else if (modality.size() >= 2) |
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 snprintf(instanceFormat_, sizeof(instanceFormat_) - 1, "%c%c%%06d.dcm", |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
493 toupper(modality[0]), toupper(modality[1])); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
494 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
495 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
496 countInstances_ = 0; |
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 break; |
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 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
501 default: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
502 throw OrthancException(ErrorCode_InternalError); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
503 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
504 } |
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 path = Toolbox::StripSpaces(Toolbox::ConvertToAscii(path)); |
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 if (path.empty()) |
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 path = std::string("Unknown ") + EnumerationToString(level); |
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 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
513 writer_.OpenDirectory(path.c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
514 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
515 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
516 virtual void Close() |
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 writer_.CloseDirectory(); |
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 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
521 virtual void AddInstance(const std::string& instanceId, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
522 const FileInfo& dicom) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
523 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
524 std::string content; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
525 context_.ReadFile(content, dicom); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
526 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
527 char filename[24]; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
528 snprintf(filename, sizeof(filename) - 1, instanceFormat_, countInstances_); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
529 countInstances_ ++; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
530 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
531 writer_.OpenFile(filename); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
532 writer_.Write(content); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
533 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
534 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
535 static void Apply(RestApiOutput& output, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
536 ServerContext& context, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
537 ArchiveIndex& archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
538 const std::string& filename) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
539 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
540 archive.Expand(context.GetIndex()); |
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 StatisticsVisitor stats; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
543 archive.Apply(stats); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
544 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
545 const bool isZip64 = IsZip64Required(stats.GetUncompressedSize(), stats.GetInstancesCount()); |
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 // Create a RAII for the temporary file to manage the ZIP file |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
548 Toolbox::TemporaryFile tmp; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
549 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
550 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
551 // Create a ZIP writer |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
552 HierarchicalZipWriter writer(tmp.GetPath().c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
553 writer.SetZip64(isZip64); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
554 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
555 ArchiveWriterVisitor v(writer, context); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
556 archive.Apply(v); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
557 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
558 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
559 // Prepare the sending of the ZIP file |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
560 FilesystemHttpSender sender(tmp.GetPath()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
561 sender.SetContentType("application/zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
562 sender.SetContentFilename(filename); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
563 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
564 // Send the ZIP |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
565 output.AnswerStream(sender); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
566 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
567 // The temporary file is automatically removed thanks to the RAII |
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 }; |
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 class MediaWriterVisitor : public IArchiveVisitor |
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 private: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
575 HierarchicalZipWriter& writer_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
576 DicomDirWriter dicomDir_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
577 ServerContext& context_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
578 unsigned int countInstances_; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
579 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
580 public: |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
581 MediaWriterVisitor(HierarchicalZipWriter& writer, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
582 ServerContext& context) : |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
583 writer_(writer), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
584 context_(context), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
585 countInstances_(0) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
586 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
587 } |
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 void EncodeDicomDir(std::string& result) |
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 dicomDir_.Encode(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 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
594 virtual void Open(ResourceType level, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
595 const std::string& publicId) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
596 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
597 } |
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 virtual void Close() |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
600 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
601 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
602 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
603 virtual void AddInstance(const std::string& instanceId, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
604 const FileInfo& dicom) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
605 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
606 // "DICOM restricts the filenames on DICOM media to 8 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
607 // 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
|
608 // conform to the standard)." |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
609 std::string filename = "IM" + boost::lexical_cast<std::string>(countInstances_); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
610 writer_.OpenFile(filename.c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
611 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
612 std::string content; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
613 context_.ReadFile(content, dicom); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
614 writer_.Write(content); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
615 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
616 ParsedDicomFile parsed(content); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
617 dicomDir_.Add("IMAGES", filename, parsed); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
618 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
619 countInstances_ ++; |
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 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
622 static void Apply(RestApiOutput& output, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
623 ServerContext& context, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
624 ArchiveIndex& archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
625 const std::string& filename) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
626 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
627 archive.Expand(context.GetIndex()); |
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 StatisticsVisitor stats; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
630 archive.Apply(stats); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
631 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
632 const bool isZip64 = IsZip64Required(stats.GetUncompressedSize(), stats.GetInstancesCount()); |
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 // Create a RAII for the temporary file to manage the ZIP file |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
635 Toolbox::TemporaryFile tmp; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
636 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
637 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
638 // Create a ZIP writer |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
639 HierarchicalZipWriter writer(tmp.GetPath().c_str()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
640 writer.SetZip64(isZip64); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
641 writer.OpenDirectory("IMAGES"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
642 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
643 // Create the DICOMDIR writer |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
644 DicomDirWriter dicomDir; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
645 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
646 MediaWriterVisitor v(writer, context); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
647 archive.Apply(v); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
648 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
649 // Add the DICOMDIR |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
650 writer.CloseDirectory(); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
651 writer.OpenFile("DICOMDIR"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
652 std::string s; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
653 v.EncodeDicomDir(s); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
654 writer.Write(s); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
655 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
656 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
657 // Prepare the sending of the ZIP file |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
658 FilesystemHttpSender sender(tmp.GetPath()); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
659 sender.SetContentType("application/zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
660 sender.SetContentFilename(filename); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
661 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
662 // Send the ZIP |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
663 output.AnswerStream(sender); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
664 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
665 // The temporary file is automatically removed thanks to the RAII |
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 }; |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
668 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
669 |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
670 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
671 static bool AddResourcesOfInterest(ArchiveIndex& archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
672 RestApiPostCall& call) |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
673 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
674 ServerIndex& index = OrthancRestApi::GetIndex(call); |
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 Json::Value resources; |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
677 if (call.ParseJsonRequest(resources) && |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
678 resources.type() == Json::arrayValue) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
679 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
680 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
|
681 { |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
682 if (resources[i].type() != Json::stringValue) |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
683 { |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
684 return false; // Bad request |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
685 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
686 |
1776 | 687 ResourceIdentifiers resource(index, resources[i].asString()); |
1777
0f5c416969dc
more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1776
diff
changeset
|
688 archive.Add(index, resource); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
689 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
690 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
691 return true; |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
692 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
693 else |
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 return false; |
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 } |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
698 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
699 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
700 static void CreateBatchArchive(RestApiPostCall& call) |
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 ArchiveIndex archive(ResourceType_Patient); // root |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
703 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
704 if (AddResourcesOfInterest(archive, call)) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
705 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
706 ArchiveWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
707 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
708 archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
709 "Archive.zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
710 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
711 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
712 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
713 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
714 static void CreateBatchMedia(RestApiPostCall& call) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
715 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
716 ArchiveIndex archive(ResourceType_Patient); // root |
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 if (AddResourcesOfInterest(archive, call)) |
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 MediaWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
721 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
722 archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
723 "Archive.zip"); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
724 } |
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
725 } |
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 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
728 static void CreateArchive(RestApiGetCall& call) |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
729 { |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
730 ServerIndex& index = OrthancRestApi::GetIndex(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 std::string id = call.GetUriComponent("id", ""); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
733 ResourceIdentifiers resource(index, id); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
734 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
735 ArchiveIndex archive(ResourceType_Patient); // root |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
736 archive.Add(OrthancRestApi::GetIndex(call), resource); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
737 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
738 ArchiveWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
739 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
740 archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
741 id + ".zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
742 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
743 |
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 static void CreateMedia(RestApiGetCall& call) |
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 ServerIndex& index = OrthancRestApi::GetIndex(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 std::string id = call.GetUriComponent("id", ""); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
750 ResourceIdentifiers resource(index, id); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
751 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
752 ArchiveIndex archive(ResourceType_Patient); // root |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
753 archive.Add(OrthancRestApi::GetIndex(call), resource); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
754 |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
755 MediaWriterVisitor::Apply(call.GetOutput(), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
756 OrthancRestApi::GetContext(call), |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
757 archive, |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
758 id + ".zip"); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
759 } |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
760 |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
761 |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
762 void OrthancRestApi::RegisterArchive() |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
763 { |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
764 Register("/patients/{id}/archive", CreateArchive); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
765 Register("/studies/{id}/archive", CreateArchive); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
766 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
|
767 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
768 Register("/patients/{id}/media", CreateMedia); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
769 Register("/studies/{id}/media", CreateMedia); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
770 Register("/series/{id}/media", CreateMedia); |
1774
784a6b92d2f1
start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1623
diff
changeset
|
771 |
1778
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
772 Register("/tools/create-archive", CreateBatchArchive); |
776573e592da
create media refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1777
diff
changeset
|
773 Register("/tools/create-media", CreateBatchMedia); |
751
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
774 } |
5197fd35333c
refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
775 } |