annotate OrthancServer/OrthancRestApi/OrthancRestArchive.cpp @ 1777:0f5c416969dc

more memory-efficient ArchiveIndex
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 13 Nov 2015 11:51:19 +0100
parents 3c28f5f6c9b7
children 776573e592da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 static std::string GetDirectoryNameInArchive(const Json::Value& resource,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 ResourceType resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
60 std::string s;
1315
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
61 const Json::Value& tags = resource["MainDicomTags"];
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
62
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 switch (resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 case ResourceType_Patient:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
1315
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
67 std::string p = tags["PatientID"].asString();
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
68 std::string n = tags["PatientName"].asString();
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
69 s = p + " " + n;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
70 break;
751
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
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 case ResourceType_Study:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
1315
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
75 std::string p;
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
76 if (tags.isMember("AccessionNumber"))
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
77 {
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
78 p = tags["AccessionNumber"].asString() + " ";
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
79 }
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
80
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
81 s = p + tags["StudyDescription"].asString();
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
82 break;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 case ResourceType_Series:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
1315
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
87 std::string d = tags["SeriesDescription"].asString();
0c735fed8953 ZIP archives now display the accession number of the studies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1303
diff changeset
88 std::string m = tags["Modality"].asString();
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
89 s = m + " " + d;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
90 break;
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 default:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 throw OrthancException(ErrorCode_InternalError);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
96
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
97 // Get rid of special characters
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
98 return Toolbox::ConvertToAscii(s);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 static bool CreateRootDirectoryInArchive(HierarchicalZipWriter& writer,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 ServerContext& context,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 const Json::Value& resource,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 ResourceType resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (resourceType == ResourceType_Patient)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ResourceType parentType = GetParentResourceType(resourceType);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 Json::Value parent;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 switch (resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 case ResourceType_Study:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 if (!context.GetIndex().LookupResource(parent, resource["ParentPatient"].asString(), parentType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 case ResourceType_Series:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (!context.GetIndex().LookupResource(parent, resource["ParentStudy"].asString(), parentType) ||
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 !CreateRootDirectoryInArchive(writer, context, parent, parentType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 default:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 throw OrthancException(ErrorCode_NotImplemented);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 writer.OpenDirectory(GetDirectoryNameInArchive(parent, parentType).c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 static bool ArchiveInstance(HierarchicalZipWriter& writer,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 ServerContext& context,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 const std::string& instancePublicId,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 const char* filename)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 writer.OpenFile(filename);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 std::string dicom;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 context.ReadFile(dicom, instancePublicId, FileContentType_Dicom);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 writer.Write(dicom);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 static bool ArchiveInternal(HierarchicalZipWriter& writer,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ServerContext& context,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 const std::string& publicId,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 ResourceType resourceType,
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 bool isFirstLevel)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 Json::Value resource;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 if (!context.GetIndex().LookupResource(resource, publicId, resourceType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 if (isFirstLevel &&
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 !CreateRootDirectoryInArchive(writer, context, resource, resourceType))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 writer.OpenDirectory(GetDirectoryNameInArchive(resource, resourceType).c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 switch (resourceType)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 case ResourceType_Patient:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 for (Json::Value::ArrayIndex i = 0; i < resource["Studies"].size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 std::string studyId = resource["Studies"][i].asString();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 if (!ArchiveInternal(writer, context, studyId, ResourceType_Study, false))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 case ResourceType_Study:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 for (Json::Value::ArrayIndex i = 0; i < resource["Series"].size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 std::string seriesId = resource["Series"][i].asString();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 if (!ArchiveInternal(writer, context, seriesId, ResourceType_Series, false))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 case ResourceType_Series:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 // Create a filename prefix, depending on the modality
1623
76ed4cf74bb5 Add ".dcm" suffix to files in ZIP archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
203 char format[24] = "%08d.dcm";
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (resource["MainDicomTags"].isMember("Modality"))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 std::string modality = resource["MainDicomTags"]["Modality"].asString();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 if (modality.size() == 1)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
1623
76ed4cf74bb5 Add ".dcm" suffix to files in ZIP archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
211 snprintf(format, sizeof(format) - 1, "%c%%07d.dcm", toupper(modality[0]));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 else if (modality.size() >= 2)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
1623
76ed4cf74bb5 Add ".dcm" suffix to files in ZIP archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
215 snprintf(format, sizeof(format) - 1, "%c%c%%06d.dcm", toupper(modality[0]), toupper(modality[1]));
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
1623
76ed4cf74bb5 Add ".dcm" suffix to files in ZIP archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1522
diff changeset
219 char filename[24];
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 for (Json::Value::ArrayIndex i = 0; i < resource["Instances"].size(); i++)
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 snprintf(filename, sizeof(filename) - 1, format, i);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 std::string publicId = resource["Instances"][i].asString();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 // This was the implementation up to Orthanc 0.7.0:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 // std::string filename = instance["MainDicomTags"]["SOPInstanceUID"].asString() + ".dcm";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (!ArchiveInstance(writer, context, publicId, filename))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 return false;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 break;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 default:
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 throw OrthancException(ErrorCode_InternalError);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 writer.CloseDirectory();
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 return true;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
247
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
248 static bool IsZip64Required(uint64_t uncompressedSize,
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
249 unsigned int countInstances)
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
251 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
252
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 /**
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 * Determine whether ZIP64 is required. Original ZIP format can
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 * store up to 2GB of data (some implementation supporting up to
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 * 4GB of data), and up to 65535 files.
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 * https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 **/
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
260 const bool isZip64 = (uncompressedSize >= 2 * GIGA_BYTES - SAFETY_MARGIN ||
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 countInstances >= 65535);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 LOG(INFO) << "Creating a ZIP file with " << countInstances << " files of size "
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 << (uncompressedSize / MEGA_BYTES) << "MB using the "
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 << (isZip64 ? "ZIP64" : "ZIP32") << " file format";
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
267 return isZip64;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
268 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
269
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
270
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
271 static bool IsZip64Required(ServerIndex& index,
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
272 const std::string& id)
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 uint64_t uncompressedSize;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
275 uint64_t compressedSize;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
276 unsigned int countStudies;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
277 unsigned int countSeries;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
278 unsigned int countInstances;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
279
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
280 index.GetStatistics(compressedSize, uncompressedSize,
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
281 countStudies, countSeries, countInstances, id);
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 return IsZip64Required(uncompressedSize, countInstances);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
284 }
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
285
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
286
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
287 template <enum ResourceType resourceType>
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
288 static void GetArchive(RestApiGetCall& call)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
289 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
290 ServerContext& context = OrthancRestApi::GetContext(call);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
291
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
292 std::string id = call.GetUriComponent("id", "");
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
293 bool isZip64 = IsZip64Required(context.GetIndex(), id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
294
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 // Create a RAII for the temporary file to manage the ZIP file
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 Toolbox::TemporaryFile tmp;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 // Create a ZIP writer
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 HierarchicalZipWriter writer(tmp.GetPath().c_str());
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 writer.SetZip64(isZip64);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 // Store the requested resource into the ZIP
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 if (!ArchiveInternal(writer, context, id, resourceType, true))
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 return;
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 // Prepare the sending of the ZIP file
1522
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
311 FilesystemHttpSender sender(tmp.GetPath());
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 sender.SetContentType("application/zip");
1522
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
313 sender.SetContentFilename(id + ".zip");
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 // Send the ZIP
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
316 call.GetOutput().AnswerStream(sender);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 // The temporary file is automatically removed thanks to the RAII
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
322 static void GetMediaArchive(RestApiGetCall& call)
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
323 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
324 ServerContext& context = OrthancRestApi::GetContext(call);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
325
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
326 std::string id = call.GetUriComponent("id", "");
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
327 bool isZip64 = IsZip64Required(context.GetIndex(), id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
328
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
329 // Create a RAII for the temporary file to manage the ZIP file
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
330 Toolbox::TemporaryFile tmp;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
331
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
332 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
333 // Create a ZIP writer
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
334 HierarchicalZipWriter writer(tmp.GetPath().c_str());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
335 writer.SetZip64(isZip64);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
336 writer.OpenDirectory("IMAGES");
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
337
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
338 // Create the DICOMDIR writer
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
339 DicomDirWriter dicomDir;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
340
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
341 // Retrieve the list of the instances
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
342 std::list<std::string> instances;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
343 context.GetIndex().GetChildInstances(instances, id);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
344
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
345 size_t pos = 0;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
346 for (std::list<std::string>::const_iterator
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
347 it = instances.begin(); it != instances.end(); ++it, ++pos)
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
348 {
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
349 // "DICOM restricts the filenames on DICOM media to 8
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
350 // characters (some systems wrongly use 8.3, but this does not
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
351 // conform to the standard)."
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
352 std::string filename = "IM" + boost::lexical_cast<std::string>(pos);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
353 writer.OpenFile(filename.c_str());
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
354
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
355 std::string dicom;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
356 context.ReadFile(dicom, *it, FileContentType_Dicom);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
357 writer.Write(dicom);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
358
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
359 ParsedDicomFile parsed(dicom);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
360 dicomDir.Add("IMAGES", filename, parsed);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
361 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
362
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
363 // Add the DICOMDIR
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
364 writer.CloseDirectory();
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
365 writer.OpenFile("DICOMDIR");
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
366 std::string s;
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
367 dicomDir.Encode(s);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
368 writer.Write(s);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
369 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
370
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
371 // Prepare the sending of the ZIP file
1522
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
372 FilesystemHttpSender sender(tmp.GetPath());
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
373 sender.SetContentType("application/zip");
1522
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1519
diff changeset
374 sender.SetContentFilename(id + ".zip");
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
375
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
376 // Send the ZIP
1519
8bd0d897763f refactoring: IHttpStreamAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
377 call.GetOutput().AnswerStream(sender);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
378
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
379 // The temporary file is automatically removed thanks to the RAII
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
380 }
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
381
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
382
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
383
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
384
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
385 namespace
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
386 {
1776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1775
diff changeset
387 class ResourceIdentifiers
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
388 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
389 private:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
390 ResourceType level_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
391 std::string patient_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
392 std::string study_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
393 std::string series_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
394 std::string instance_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
395
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
396 static void GoToParent(ServerIndex& index,
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
397 std::string& current)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
398 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
399 std::string tmp;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
400
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
401 if (index.LookupParent(tmp, current))
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
402 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
403 current = tmp;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
404 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
405 else
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
406 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
407 throw OrthancException(ErrorCode_UnknownResource);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
408 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
409 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
410
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
411
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
412 public:
1776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1775
diff changeset
413 ResourceIdentifiers(ServerIndex& index,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1775
diff changeset
414 const std::string& publicId)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
415 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
416 if (!index.LookupResourceType(level_, publicId))
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
417 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
418 throw OrthancException(ErrorCode_UnknownResource);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
419 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
420
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
421 std::string current = publicId;;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
422 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
423 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
424 case ResourceType_Instance:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
425 instance_ = current;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
426 GoToParent(index, current);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
427
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
428 case ResourceType_Series:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
429 series_ = current;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
430 GoToParent(index, current);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
431
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
432 case ResourceType_Study:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
433 study_ = current;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
434 GoToParent(index, current);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
435
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
436 case ResourceType_Patient:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
437 patient_ = current;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
438 break;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
439
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
440 default:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
441 throw OrthancException(ErrorCode_InternalError);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
442 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
443 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
444
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
445 ResourceType GetLevel() const
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
446 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
447 return level_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
448 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
449
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
450 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
451 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
452 // 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
453 assert(ResourceType_Patient < ResourceType_Study);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
454 assert(ResourceType_Study < ResourceType_Series);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
455 assert(ResourceType_Series < ResourceType_Instance);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
456
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
457 if (level > level_)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
458 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
459 throw OrthancException(ErrorCode_InternalError);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
460 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
461
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
462 switch (level)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
463 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
464 case ResourceType_Patient:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
465 return patient_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
466
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
467 case ResourceType_Study:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
468 return study_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
469
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
470 case ResourceType_Series:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
471 return series_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
472
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
473 case ResourceType_Instance:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
474 return instance_;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
475
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
476 default:
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
477 throw OrthancException(ErrorCode_InternalError);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
478 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
479 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
480 };
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
481
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
482
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
483 class IArchiveVisitor : public boost::noncopyable
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
484 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
485 public:
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
486 virtual ~IArchiveVisitor()
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
487 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
488 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
489
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
490 virtual void Open(ResourceType level,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
491 const std::string& publicId) = 0;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
492
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
493 virtual void Close() = 0;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
494
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
495 virtual void AddInstance(const std::string& instanceId,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
496 const FileInfo& dicom) = 0;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
497 };
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
498
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
499
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
500 class ArchiveIndex
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
501 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
502 private:
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
503 struct Instance
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
504 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
505 std::string id_;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
506 FileInfo dicom_;
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
507
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
508 Instance(const std::string& id,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
509 const FileInfo& dicom) :
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
510 id_(id), dicom_(dicom)
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
511 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
512 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
513 };
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
514
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
515 // A "NULL" value for ArchiveIndex indicates a non-expanded node
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
516 typedef std::map<std::string, ArchiveIndex*> Resources;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
517
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
518 ResourceType level_;
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
519 Resources resources_; // Only at patient/study/series level
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
520 std::list<Instance> instances_; // Only at instance level
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
521
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
522
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
523 void AddResourceToExpand(ServerIndex& index,
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
524 const std::string& id)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
525 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
526 if (level_ == ResourceType_Instance)
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
527 {
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
528 FileInfo tmp;
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
529 if (index.LookupAttachment(tmp, id, FileContentType_Dicom))
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
530 {
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
531 instances_.push_back(Instance(id, tmp));
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
532 }
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
533 }
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
534 else
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
535 {
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
536 resources_[id] = NULL;
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
537 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
538 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
539
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
540
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
541 public:
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
542 ArchiveIndex(ResourceType level) :
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
543 level_(level)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
544 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
545 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
546
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
547 ~ArchiveIndex()
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
548 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
549 for (Resources::iterator it = resources_.begin();
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
550 it != resources_.end(); ++it)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
551 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
552 delete it->second;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
553 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
554 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
555
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
556
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
557 void Add(ServerIndex& index,
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
558 const ResourceIdentifiers& resource)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
559 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
560 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
561 Resources::iterator previous = resources_.find(id);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
562
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
563 if (level_ == ResourceType_Instance)
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
564 {
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
565 AddResourceToExpand(index, id);
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
566 }
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
567 else if (resource.GetLevel() == level_)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
568 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
569 // Mark this resource for further expansion
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
570 if (previous != resources_.end())
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
571 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
572 delete previous->second;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
573 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
574
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
575 resources_[id] = NULL;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
576 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
577 else if (previous == resources_.end())
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
578 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
579 // 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
580 std::auto_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
581 child->Add(index, resource);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
582 resources_[id] = child.release();
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
583 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
584 else if (previous->second != NULL)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
585 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
586 previous->second->Add(index, resource);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
587 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
588 else
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
589 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
590 // 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
591 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
592 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
593
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
594
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
595 void Expand(ServerIndex& index)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
596 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
597 if (level_ == ResourceType_Instance)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
598 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
599 // Expanding an instance node makes no sense
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
600 return;
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
601 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
602
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
603 for (Resources::iterator it = resources_.begin();
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
604 it != resources_.end(); ++it)
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
605 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
606 if (it->second == NULL)
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
607 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
608 // This is resource is marked for expansion
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
609 std::list<std::string> children;
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
610 index.GetChildren(children, it->first);
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
611
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
612 std::auto_ptr<ArchiveIndex> child(new ArchiveIndex(GetChildResourceType(level_)));
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
613
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
614 for (std::list<std::string>::const_iterator
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
615 it2 = children.begin(); it2 != children.end(); ++it2)
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
616 {
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
617 child->AddResourceToExpand(index, *it2);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
618 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
619
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
620 it->second = child.release();
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
621 }
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
622
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
623 assert(it->second != NULL);
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
624 it->second->Expand(index);
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
625 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
626 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
627
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
628
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
629 void Apply(IArchiveVisitor& visitor) const
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
630 {
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
631 if (level_ == ResourceType_Instance)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
632 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
633 for (std::list<Instance>::const_iterator
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
634 it = instances_.begin(); it != instances_.end(); ++it)
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
635 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
636 visitor.AddInstance(it->id_, it->dicom_);
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
637 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
638 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
639 else
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
640 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
641 for (Resources::const_iterator it = resources_.begin();
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
642 it != resources_.end(); ++it)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
643 {
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
644 assert(it->second != NULL); // There must have been a call to "Expand()"
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
645 visitor.Open(level_, it->first);
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
646 it->second->Apply(visitor);
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
647 visitor.Close();
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
648 }
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
649 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
650 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
651 };
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
652
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
653
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
654 class StatisticsVisitor : public IArchiveVisitor
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
655 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
656 private:
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
657 uint64_t size_;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
658 unsigned int instances_;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
659
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
660 public:
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
661 StatisticsVisitor() : size_(0), instances_(0)
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
662 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
663 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
664
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
665 uint64_t GetUncompressedSize() const
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
666 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
667 return size_;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
668 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
669
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
670 unsigned int GetInstancesCount() const
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
671 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
672 return instances_;
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
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
675 virtual void Open(ResourceType level,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
676 const std::string& publicId)
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
677 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
678 }
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
679
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
680 virtual void Close()
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
681 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
682 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
683
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
684 virtual void AddInstance(const std::string& instanceId,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
685 const FileInfo& dicom)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
686 {
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
687 instances_ ++;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
688 size_ += dicom.GetUncompressedSize();
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
689 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
690 };
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
691
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
692
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
693 class PrintVisitor : public IArchiveVisitor
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
694 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
695 private:
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
696 std::ostream& out_;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
697 std::string indent_;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
698
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
699 public:
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
700 PrintVisitor(std::ostream& out) : out_(out)
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
701 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
702 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
703
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
704 virtual void Open(ResourceType level,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
705 const std::string& publicId)
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
706 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
707 switch (level)
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
708 {
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
709 case ResourceType_Patient: indent_ = ""; break;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
710 case ResourceType_Study: indent_ = " "; break;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
711 case ResourceType_Series: indent_ = " "; break;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
712 default:
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
713 throw OrthancException(ErrorCode_InternalError);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
714 }
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
715
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
716 out_ << indent_ << publicId << std::endl;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
717 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
718
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
719 virtual void Close()
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
720 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
721 }
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
722
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
723 virtual void AddInstance(const std::string& instanceId,
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
724 const FileInfo& dicom)
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
725 {
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
726 out_ << " " << instanceId << std::endl;
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
727 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
728 };
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
729 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
730
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
731
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
732 static void CreateBatchArchive(RestApiPostCall& call)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
733 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
734 ServerIndex& index = OrthancRestApi::GetIndex(call);
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
735
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
736 Json::Value resources;
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
737 if (call.ParseJsonRequest(resources) &&
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
738 resources.type() == Json::arrayValue)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
739 {
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
740 ArchiveIndex archive(ResourceType_Patient); // root
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
741
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
742 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
743 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
744 if (resources[i].type() != Json::stringValue)
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
745 {
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
746 return; // Bad request
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
747 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
748
1776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1775
diff changeset
749 ResourceIdentifiers resource(index, resources[i].asString());
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
750 archive.Add(index, resource);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
751 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
752
1777
0f5c416969dc more memory-efficient ArchiveIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1776
diff changeset
753 archive.Expand(index);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
754
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
755 PrintVisitor v(std::cout);
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
756 archive.Apply(v);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
757
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
758 StatisticsVisitor s;
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
759 archive.Apply(s);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
760
1775
1861e410a9d7 visitors
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1774
diff changeset
761 std::cout << s.GetUncompressedSize() << " " << s.GetInstancesCount() << std::endl;
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
762 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
763 }
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
764
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
765
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
766
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 void OrthancRestApi::RegisterArchive()
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 {
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 Register("/patients/{id}/archive", GetArchive<ResourceType_Patient>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 Register("/studies/{id}/archive", GetArchive<ResourceType_Study>);
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 Register("/series/{id}/archive", GetArchive<ResourceType_Series>);
1121
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
772
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
773 Register("/patients/{id}/media", GetMediaArchive);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
774 Register("/studies/{id}/media", GetMediaArchive);
82567bac5e25 Creation of ZIP archives for media storage, with DICOMDIR
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
775 Register("/series/{id}/media", GetMediaArchive);
1774
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
776
784a6b92d2f1 start of refactoring the creation of archives
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1623
diff changeset
777 Register("/tools/archive", CreateBatchArchive);
751
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 }
5197fd35333c refactoring of OrthancRestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 }