annotate OrthancServer/Sources/ResourceFinder.cpp @ 5608:3d0aa94b44b3 find-refactoring

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 08 May 2024 13:37:23 +0200
parents
children 4690a0d2b01e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "PrecompiledHeadersServer.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "ResourceFinder.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../../OrthancFramework/Sources/OrthancException.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../../OrthancFramework/Sources/SerializationToolbox.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "ServerContext.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "ServerIndex.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 SeriesStatus ResourceFinder::GetSeriesStatus(uint32_t& expectedNumberOfInstances,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 const FindResponse::Resource& resource) const
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 if (request_.GetLevel() != ResourceType_Series)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 throw OrthancException(ErrorCode_BadParameterType);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 std::string s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 if (!resource.LookupMetadata(s, ResourceType_Series, MetadataType_Series_ExpectedNumberOfInstances) ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 !SerializationToolbox::ParseUnsignedInteger32(expectedNumberOfInstances, s))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 return SeriesStatus_Unknown;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 std::list<std::string> values;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 if (!resource.LookupChildrenMetadata(values, MetadataType_Instance_IndexInSeries))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 throw OrthancException(ErrorCode_BadSequenceOfCalls);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 std::set<int64_t> instances;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 for (std::list<std::string>::const_iterator
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 it = values.begin(); it != values.end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 int64_t index;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if (!SerializationToolbox::ParseInteger64(index, *it))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 return SeriesStatus_Unknown;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 if (index <= 0 ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 index > static_cast<int64_t>(expectedNumberOfInstances))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 // Out-of-range instance index
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 return SeriesStatus_Inconsistent;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 if (instances.find(index) != instances.end())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 // Twice the same instance index
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return SeriesStatus_Inconsistent;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 instances.insert(index);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if (instances.size() == static_cast<size_t>(expectedNumberOfInstances))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 return SeriesStatus_Complete;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return SeriesStatus_Missing;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 void ResourceFinder::Expand(Json::Value& target,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 const FindResponse::Resource& resource,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ServerIndex& index) const
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 /**
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 * This method closely follows "SerializeExpandedResource()" in
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 * "ServerContext.cpp" from Orthanc 1.12.3.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 **/
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 if (resource.GetLevel() != request_.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 if (!requestedTags_.empty())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 throw OrthancException(ErrorCode_NotImplemented);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 target = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 target["Type"] = GetResourceTypeText(resource.GetLevel(), false, true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 target["ID"] = resource.GetIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 switch (resource.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 case ResourceType_Patient:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 case ResourceType_Study:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 target["ParentPatient"] = resource.GetParentIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 case ResourceType_Series:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 target["ParentStudy"] = resource.GetParentIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 case ResourceType_Instance:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 target["ParentSeries"] = resource.GetParentIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 default:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 if (resource.GetLevel() != ResourceType_Instance)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 const std::set<std::string>& children = resource.GetChildrenIdentifiers();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 Json::Value c = Json::arrayValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 for (std::set<std::string>::const_iterator
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 it = children.begin(); it != children.end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 c.append(*it);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 switch (resource.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 case ResourceType_Patient:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 target["Studies"] = c;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 case ResourceType_Study:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 target["Series"] = c;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 case ResourceType_Series:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 target["Instances"] = c;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 default:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 switch (resource.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 case ResourceType_Patient:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 case ResourceType_Study:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 case ResourceType_Series:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 uint32_t expectedNumberOfInstances;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 SeriesStatus status = GetSeriesStatus(expectedNumberOfInstances, resource);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 target["Status"] = EnumerationToString(status);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 static const char* EXPECTED_NUMBER_OF_INSTANCES = "ExpectedNumberOfInstances";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 if (status == SeriesStatus_Unknown)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 target[EXPECTED_NUMBER_OF_INSTANCES] = Json::nullValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 target[EXPECTED_NUMBER_OF_INSTANCES] = expectedNumberOfInstances;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 case ResourceType_Instance:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 FileInfo info;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 if (resource.LookupAttachment(info, FileContentType_Dicom))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 target["FileSize"] = static_cast<Json::UInt64>(info.GetUncompressedSize());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 target["FileUuid"] = info.GetUuid();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 static const char* INDEX_IN_SERIES = "IndexInSeries";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 std::string s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 uint32_t index;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (resource.LookupMetadata(s, ResourceType_Instance, MetadataType_Instance_IndexInSeries) &&
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 SerializationToolbox::ParseUnsignedInteger32(index, s))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 target[INDEX_IN_SERIES] = index;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 target[INDEX_IN_SERIES] = Json::nullValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 default:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 std::string s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_AnonymizedFrom))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 target["AnonymizedFrom"] = s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_ModifiedFrom))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 target["ModifiedFrom"] = s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 if (resource.GetLevel() == ResourceType_Patient ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 resource.GetLevel() == ResourceType_Study ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 resource.GetLevel() == ResourceType_Series)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 target["IsStable"] = !index.IsUnstableResource(resource.GetLevel(), resource.GetInternalId());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_LastUpdate))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 target["LastUpdate"] = s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 static const char* const MAIN_DICOM_TAGS = "MainDicomTags";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 static const char* const PATIENT_MAIN_DICOM_TAGS = "PatientMainDicomTags";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 // TODO-FIND : (expandFlags & ExpandResourceFlags_IncludeMainDicomTags)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 DicomMap allMainDicomTags;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 resource.GetMainDicomTags(allMainDicomTags, resource.GetLevel());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 DicomMap levelMainDicomTags;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 allMainDicomTags.ExtractResourceInformation(levelMainDicomTags, resource.GetLevel());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 target[MAIN_DICOM_TAGS] = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format_);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 if (resource.GetLevel() == ResourceType_Study)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 DicomMap patientMainDicomTags;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 allMainDicomTags.ExtractPatientInformation(patientMainDicomTags);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format_);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 /*
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 TODO-FIND
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 if (!requestedTags_.empty())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 static const char* const REQUESTED_TAGS = "RequestedTags";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 DicomMap tags;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 resource.GetMainDicomTags().ExtractTags(tags, requestedTags);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 target[REQUESTED_TAGS] = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 */
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 Json::Value labels = Json::arrayValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 for (std::set<std::string>::const_iterator
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 it = resource.GetLabels().begin(); it != resource.GetLabels().end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 labels.append(*it);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 target["Labels"] = labels;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 if (includeAllMetadata_) // new in Orthanc 1.12.4
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 const std::map<MetadataType, std::string>& m = resource.GetMetadata(resource.GetLevel());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 Json::Value metadata = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 for (std::map<MetadataType, std::string>::const_iterator it = m.begin(); it != m.end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 metadata[EnumerationToString(it->first)] = it->second;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 target["Metadata"] = metadata;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 ResourceFinder::ResourceFinder(ResourceType level,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 bool expand) :
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 request_(level),
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 expand_(expand),
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 format_(DicomToJsonFormat_Human),
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 includeAllMetadata_(false)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 if (expand)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 request_.SetRetrieveMainDicomTags(level, true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 request_.SetRetrieveMetadata(level, true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 request_.SetRetrieveLabels(true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 if (level == ResourceType_Series)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 request_.AddRetrieveChildrenMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 if (level == ResourceType_Instance)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 request_.SetRetrieveAttachments(true); // for FileSize & FileUuid
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 request_.SetRetrieveChildrenIdentifiers(true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 if (level != ResourceType_Patient)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 request_.SetRetrieveParentIdentifier(true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 void ResourceFinder::Execute(Json::Value& target,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 ServerContext& context)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 FindResponse response;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 context.GetIndex().ExecuteFind(response, request_);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 target = Json::arrayValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 if (expand_)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 for (size_t i = 0; i < response.GetSize(); i++)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 Json::Value item;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 Expand(item, response.GetResource(i), context.GetIndex());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 target.append(item);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 for (size_t i = 0; i < response.GetSize(); i++)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 target.append(response.GetResource(i).GetIdentifier());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }