annotate OrthancServer/Sources/ResourceFinder.cpp @ 5682:fd4c5e064cbe find-refactoring

started refactoring of ServerContext::Apply()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Jul 2024 11:17:34 +0200
parents b744a2cf408a
children 11575590e493
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
5641
3f13db27b399 integration mainline->find-refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5621
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
3f13db27b399 integration mainline->find-refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5621
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
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
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "PrecompiledHeadersServer.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "ResourceFinder.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
28 #include "../../OrthancFramework/Sources/Logging.h"
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../../OrthancFramework/Sources/OrthancException.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../../OrthancFramework/Sources/SerializationToolbox.h"
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
31 #include "OrthancConfiguration.h"
5682
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
32 #include "Search/DatabaseLookup.h"
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "ServerContext.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "ServerIndex.h"
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 namespace Orthanc
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
39 void ResourceFinder::ConfigureChildrenCountComputedTag(DicomTag tag,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
40 ResourceType parentLevel,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
41 ResourceType childLevel)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
42 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
43 if (request_.GetLevel() == parentLevel)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
44 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
45 requestedComputedTags_.insert(tag);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
46 hasRequestedTags_ = true;
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
47 request_.GetChildrenSpecification(childLevel).SetRetrieveIdentifiers(true);
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
48 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
49 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
50
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
51
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
52 void ResourceFinder::InjectChildrenCountComputedTag(DicomMap& requestedTags,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
53 DicomTag tag,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
54 const FindResponse::Resource& resource,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
55 ResourceType level) const
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
56 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
57 if (IsRequestedComputedTag(tag))
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
58 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
59 const std::set<std::string>& children = resource.GetChildrenIdentifiers(level);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
60 requestedTags.SetValue(tag, boost::lexical_cast<std::string>(children.size()), false);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
61 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
62 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
63
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
64
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
65 void ResourceFinder::InjectComputedTags(DicomMap& requestedTags,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
66 const FindResponse::Resource& resource) const
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
67 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
68 switch (resource.GetLevel())
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
69 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
70 case ResourceType_Patient:
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
71 InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_PATIENT_RELATED_STUDIES, resource, ResourceType_Study);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
72 InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_PATIENT_RELATED_SERIES, resource, ResourceType_Series);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
73 InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_PATIENT_RELATED_INSTANCES, resource, ResourceType_Instance);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
74 break;
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
75
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
76 case ResourceType_Study:
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
77 InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_STUDY_RELATED_SERIES, resource, ResourceType_Series);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
78 InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_STUDY_RELATED_INSTANCES, resource, ResourceType_Instance);
5672
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
79
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
80 if (IsRequestedComputedTag(DICOM_TAG_MODALITIES_IN_STUDY))
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
81 {
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
82 std::set<std::string> modalities;
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
83 resource.GetChildrenMainDicomTagValues(modalities, ResourceType_Series, DICOM_TAG_MODALITY);
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
84
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
85 std::string s;
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
86 Toolbox::JoinStrings(s, modalities, "\\");
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
87
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
88 requestedTags.SetValue(DICOM_TAG_MODALITIES_IN_STUDY, s, false);
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
89 }
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
90
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
91 if (IsRequestedComputedTag(DICOM_TAG_SOP_CLASSES_IN_STUDY))
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
92 {
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
93 std::set<std::string> classes;
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
94 resource.GetChildrenMetadataValues(classes, ResourceType_Instance, MetadataType_Instance_SopClassUid);
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
95
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
96 std::string s;
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
97 Toolbox::JoinStrings(s, classes, "\\");
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
98
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
99 requestedTags.SetValue(DICOM_TAG_SOP_CLASSES_IN_STUDY, s, false);
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
100 }
e300f22a46f0 implemented computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5668
diff changeset
101
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
102 break;
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
103
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
104 case ResourceType_Series:
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
105 InjectChildrenCountComputedTag(requestedTags, DICOM_TAG_NUMBER_OF_SERIES_RELATED_INSTANCES, resource, ResourceType_Instance);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
106 break;
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
107
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
108 case ResourceType_Instance:
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
109 if (IsRequestedComputedTag(DICOM_TAG_INSTANCE_AVAILABILITY))
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
110 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
111 requestedTags.SetValue(DICOM_TAG_INSTANCE_AVAILABILITY, "ONLINE", false);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
112 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
113 break;
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
114
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
115 default:
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
116 throw OrthancException(ErrorCode_InternalError);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
117 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
118 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
119
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
120
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 SeriesStatus ResourceFinder::GetSeriesStatus(uint32_t& expectedNumberOfInstances,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 const FindResponse::Resource& resource) const
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 if (request_.GetLevel() != ResourceType_Series)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 throw OrthancException(ErrorCode_BadParameterType);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::string s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 if (!resource.LookupMetadata(s, ResourceType_Series, MetadataType_Series_ExpectedNumberOfInstances) ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 !SerializationToolbox::ParseUnsignedInteger32(expectedNumberOfInstances, s))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 return SeriesStatus_Unknown;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
5674
74f3aab95886 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5672
diff changeset
136 std::set<std::string> values;
74f3aab95886 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5672
diff changeset
137 resource.GetChildrenMetadataValues(values, ResourceType_Instance, MetadataType_Instance_IndexInSeries);
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 std::set<int64_t> instances;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
5674
74f3aab95886 simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5672
diff changeset
141 for (std::set<std::string>::const_iterator
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 it = values.begin(); it != values.end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 int64_t index;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 if (!SerializationToolbox::ParseInteger64(index, *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 return SeriesStatus_Unknown;
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 if (index <= 0 ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 index > static_cast<int64_t>(expectedNumberOfInstances))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 // Out-of-range instance index
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 return SeriesStatus_Inconsistent;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 if (instances.find(index) != instances.end())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 // Twice the same instance index
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 return SeriesStatus_Inconsistent;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 instances.insert(index);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 if (instances.size() == static_cast<size_t>(expectedNumberOfInstances))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return SeriesStatus_Complete;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return SeriesStatus_Missing;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 void ResourceFinder::Expand(Json::Value& target,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 const FindResponse::Resource& resource,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 ServerIndex& index) const
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 /**
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 * This method closely follows "SerializeExpandedResource()" in
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 * "ServerContext.cpp" from Orthanc 1.12.3.
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 **/
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 if (resource.GetLevel() != request_.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 target = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 target["Type"] = GetResourceTypeText(resource.GetLevel(), false, true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 target["ID"] = resource.GetIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 switch (resource.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 case ResourceType_Patient:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 case ResourceType_Study:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 target["ParentPatient"] = resource.GetParentIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 case ResourceType_Series:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 target["ParentStudy"] = resource.GetParentIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 case ResourceType_Instance:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 target["ParentSeries"] = resource.GetParentIdentifier();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 default:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 if (resource.GetLevel() != ResourceType_Instance)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
220 const std::set<std::string>& children = resource.GetChildrenIdentifiers(GetChildResourceType(resource.GetLevel()));
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 Json::Value c = Json::arrayValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 for (std::set<std::string>::const_iterator
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 it = children.begin(); it != children.end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 c.append(*it);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 switch (resource.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 case ResourceType_Patient:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 target["Studies"] = c;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 case ResourceType_Study:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 target["Series"] = c;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 case ResourceType_Series:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 target["Instances"] = c;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 default:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 switch (resource.GetLevel())
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 case ResourceType_Patient:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 case ResourceType_Study:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 case ResourceType_Series:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 uint32_t expectedNumberOfInstances;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 SeriesStatus status = GetSeriesStatus(expectedNumberOfInstances, resource);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 target["Status"] = EnumerationToString(status);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
261 static const char* const EXPECTED_NUMBER_OF_INSTANCES = "ExpectedNumberOfInstances";
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 if (status == SeriesStatus_Unknown)
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[EXPECTED_NUMBER_OF_INSTANCES] = Json::nullValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 target[EXPECTED_NUMBER_OF_INSTANCES] = expectedNumberOfInstances;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 break;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 case ResourceType_Instance:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 FileInfo info;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 if (resource.LookupAttachment(info, FileContentType_Dicom))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 target["FileSize"] = static_cast<Json::UInt64>(info.GetUncompressedSize());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 target["FileUuid"] = info.GetUuid();
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
288 static const char* const INDEX_IN_SERIES = "IndexInSeries";
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 std::string s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 uint32_t index;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 if (resource.LookupMetadata(s, ResourceType_Instance, MetadataType_Instance_IndexInSeries) &&
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 SerializationToolbox::ParseUnsignedInteger32(index, s))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 target[INDEX_IN_SERIES] = index;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 else
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 target[INDEX_IN_SERIES] = Json::nullValue;
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 break;
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 default:
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 throw OrthancException(ErrorCode_InternalError);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 std::string s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_AnonymizedFrom))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 target["AnonymizedFrom"] = s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_ModifiedFrom))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 target["ModifiedFrom"] = s;
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 if (resource.GetLevel() == ResourceType_Patient ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 resource.GetLevel() == ResourceType_Study ||
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 resource.GetLevel() == ResourceType_Series)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 target["IsStable"] = !index.IsUnstableResource(resource.GetLevel(), resource.GetInternalId());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 if (resource.LookupMetadata(s, resource.GetLevel(), MetadataType_LastUpdate))
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 target["LastUpdate"] = s;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
333 DicomMap allMainDicomTags;
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
334 resource.GetMainDicomTags(allMainDicomTags, resource.GetLevel());
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
335
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
336 /**
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
337 * This section was part of "StatelessDatabaseOperations::ExpandResource()"
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
338 * in Orthanc <= 1.12.3
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
339 **/
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
340
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
341 // read all main sequences from DB
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
342 std::string serializedSequences;
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
343 if (resource.LookupMetadata(serializedSequences, resource.GetLevel(), MetadataType_MainDicomSequences))
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
344 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
345 Json::Value jsonMetadata;
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
346 Toolbox::ReadJson(jsonMetadata, serializedSequences);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
347
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
348 if (jsonMetadata["Version"].asInt() == 1)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
349 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
350 allMainDicomTags.FromDicomAsJson(jsonMetadata["Sequences"], true /* append */, true /* parseSequences */);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
351 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
352 else
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
353 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
354 throw OrthancException(ErrorCode_NotImplemented);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
355 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
356 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
357
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
358 /**
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
359 * End of section from StatelessDatabaseOperations
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
360 **/
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
361
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
362
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 static const char* const MAIN_DICOM_TAGS = "MainDicomTags";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 static const char* const PATIENT_MAIN_DICOM_TAGS = "PatientMainDicomTags";
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
366 // TODO-FIND : Ignore "null" values
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 DicomMap levelMainDicomTags;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 allMainDicomTags.ExtractResourceInformation(levelMainDicomTags, resource.GetLevel());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 target[MAIN_DICOM_TAGS] = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], levelMainDicomTags, format_);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 if (resource.GetLevel() == ResourceType_Study)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 DicomMap patientMainDicomTags;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 allMainDicomTags.ExtractPatientInformation(patientMainDicomTags);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format_);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 Json::Value labels = Json::arrayValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 for (std::set<std::string>::const_iterator
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 it = resource.GetLabels().begin(); it != resource.GetLabels().end(); ++it)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 labels.append(*it);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 target["Labels"] = labels;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 if (includeAllMetadata_) // new in Orthanc 1.12.4
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 const std::map<MetadataType, std::string>& m = resource.GetMetadata(resource.GetLevel());
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 Json::Value metadata = Json::objectValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 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
403 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 metadata[EnumerationToString(it->first)] = it->second;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 target["Metadata"] = metadata;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 ResourceFinder::ResourceFinder(ResourceType level,
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 bool expand) :
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 request_(level),
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 expand_(expand),
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 format_(DicomToJsonFormat_Human),
5617
8905ffa45fc2 started listing of children resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5616
diff changeset
417 allowStorageAccess_(true),
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
418 hasRequestedTags_(false),
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 includeAllMetadata_(false)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 if (expand)
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 {
5619
1864b16bc7b1 added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5617
diff changeset
423 request_.SetRetrieveMainDicomTags(true);
1864b16bc7b1 added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5617
diff changeset
424 request_.SetRetrieveMetadata(true);
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 request_.SetRetrieveLabels(true);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
427 switch (level)
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 {
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
429 case ResourceType_Patient:
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
430 request_.GetChildrenSpecification(ResourceType_Study).SetRetrieveIdentifiers(true);
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
431 break;
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
432
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
433 case ResourceType_Study:
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
434 request_.GetChildrenSpecification(ResourceType_Series).SetRetrieveIdentifiers(true);
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
435 request_.SetRetrieveParentIdentifier(true);
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
436 break;
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
438 case ResourceType_Series:
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
439 request_.GetChildrenSpecification(ResourceType_Instance).AddMetadata(MetadataType_Instance_IndexInSeries); // required for the SeriesStatus
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
440 request_.GetChildrenSpecification(ResourceType_Instance).SetRetrieveIdentifiers(true);
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
441 request_.SetRetrieveParentIdentifier(true);
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
442 break;
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
443
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
444 case ResourceType_Instance:
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
445 request_.SetRetrieveAttachments(true); // for FileSize & FileUuid
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
446 request_.SetRetrieveParentIdentifier(true);
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
447 break;
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
448
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
449 default:
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
450 throw OrthancException(ErrorCode_ParameterOutOfRange);
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
5682
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
456 void ResourceFinder::SetDatabaseLookup(const DatabaseLookup& lookup)
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
457 {
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
458 MainDicomTagsRegistry registry;
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
459 registry.NormalizeLookup(request_.GetDicomTagConstraints(), lookup, request_.GetLevel());
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
460 }
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
461
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
462
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
463 void ResourceFinder::AddRequestedTags(const DicomTag& tag)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
464 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
465 if (DicomMap::IsMainDicomTag(tag, ResourceType_Patient))
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
466 {
5620
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
467 if (request_.GetLevel() == ResourceType_Patient)
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
468 {
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
469 request_.GetParentSpecification(ResourceType_Patient).SetRetrieveMainDicomTags(true);
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
470 request_.GetParentSpecification(ResourceType_Patient).SetRetrieveMetadata(true);
5620
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
471 requestedPatientTags_.insert(tag);
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
472 }
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
473 else
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
474 {
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
475 /**
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
476 * This comes from the fact that patient-level tags are copied
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
477 * at the study level, as implemented by "ResourcesContent::AddResource()".
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
478 **/
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
479 request_.GetParentSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true);
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
480 request_.GetParentSpecification(ResourceType_Study).SetRetrieveMetadata(true);
5620
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
481 requestedStudyTags_.insert(tag);
4bfd885fb45f optimization as patient-level tags are copied at study level
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5619
diff changeset
482 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
483
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
484 hasRequestedTags_ = true;
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
485 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
486 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Study))
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
487 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
488 if (request_.GetLevel() == ResourceType_Patient)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
489 {
5612
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
490 LOG(WARNING) << "Requested tag " << tag.Format()
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
491 << " should only be read at the study, series, or instance level";
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
492 requestedTagsFromFileStorage_.insert(tag);
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
493 request_.SetRetrieveOneInstanceIdentifier(true);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
494 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
495 else
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
496 {
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
497 request_.GetParentSpecification(ResourceType_Study).SetRetrieveMainDicomTags(true);
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
498 request_.GetParentSpecification(ResourceType_Study).SetRetrieveMetadata(true);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
499 requestedStudyTags_.insert(tag);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
500 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
501
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
502 hasRequestedTags_ = true;
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
503 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
504 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Series))
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
505 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
506 if (request_.GetLevel() == ResourceType_Patient ||
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
507 request_.GetLevel() == ResourceType_Study)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
508 {
5612
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
509 LOG(WARNING) << "Requested tag " << tag.Format()
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
510 << " should only be read at the series or instance level";
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
511 requestedTagsFromFileStorage_.insert(tag);
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
512 request_.SetRetrieveOneInstanceIdentifier(true);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
513 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
514 else
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
515 {
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
516 request_.GetParentSpecification(ResourceType_Series).SetRetrieveMainDicomTags(true);
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
517 request_.GetParentSpecification(ResourceType_Series).SetRetrieveMetadata(true);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
518 requestedSeriesTags_.insert(tag);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
519 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
520
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
521 hasRequestedTags_ = true;
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
522 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
523 else if (DicomMap::IsMainDicomTag(tag, ResourceType_Instance))
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
524 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
525 if (request_.GetLevel() == ResourceType_Patient ||
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
526 request_.GetLevel() == ResourceType_Study ||
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
527 request_.GetLevel() == ResourceType_Series)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
528 {
5612
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
529 LOG(WARNING) << "Requested tag " << tag.Format()
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
530 << " should only be read at the instance level";
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
531 requestedTagsFromFileStorage_.insert(tag);
599ce5ed126c added more tolerance to behave like previous releases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5610
diff changeset
532 request_.SetRetrieveOneInstanceIdentifier(true);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
533 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
534 else
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
535 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
536 // Main DICOM tags from the instance level will be retrieved anyway
5619
1864b16bc7b1 added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5617
diff changeset
537 assert(request_.IsRetrieveMainDicomTags());
1864b16bc7b1 added FindRequest::ParentRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5617
diff changeset
538 assert(request_.IsRetrieveMetadata());
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
539 requestedInstanceTags_.insert(tag);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
540 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
541
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
542 hasRequestedTags_ = true;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
543 }
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
544 else if (tag == DICOM_TAG_NUMBER_OF_PATIENT_RELATED_STUDIES)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
545 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
546 ConfigureChildrenCountComputedTag(tag, ResourceType_Patient, ResourceType_Study);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
547 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
548 else if (tag == DICOM_TAG_NUMBER_OF_PATIENT_RELATED_SERIES)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
549 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
550 ConfigureChildrenCountComputedTag(tag, ResourceType_Patient, ResourceType_Series);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
551 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
552 else if (tag == DICOM_TAG_NUMBER_OF_PATIENT_RELATED_INSTANCES)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
553 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
554 ConfigureChildrenCountComputedTag(tag, ResourceType_Patient, ResourceType_Instance);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
555 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
556 else if (tag == DICOM_TAG_NUMBER_OF_STUDY_RELATED_SERIES)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
557 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
558 ConfigureChildrenCountComputedTag(tag, ResourceType_Study, ResourceType_Series);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
559 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
560 else if (tag == DICOM_TAG_NUMBER_OF_STUDY_RELATED_INSTANCES)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
561 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
562 ConfigureChildrenCountComputedTag(tag, ResourceType_Study, ResourceType_Instance);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
563 }
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
564 else if (tag == DICOM_TAG_NUMBER_OF_SERIES_RELATED_INSTANCES)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
565 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
566 ConfigureChildrenCountComputedTag(tag, ResourceType_Series, ResourceType_Instance);
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
567 }
5668
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
568 else if (tag == DICOM_TAG_SOP_CLASSES_IN_STUDY)
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
569 {
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
570 requestedComputedTags_.insert(tag);
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
571 hasRequestedTags_ = true;
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
572 request_.GetChildrenSpecification(ResourceType_Instance).AddMetadata(MetadataType_Instance_SopClassUid);
5668
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
573 }
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
574 else if (tag == DICOM_TAG_MODALITIES_IN_STUDY)
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
575 {
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
576 requestedComputedTags_.insert(tag);
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
577 hasRequestedTags_ = true;
5676
b744a2cf408a shorten ParentRetrieveSpecification/ChildrenRetrieveSpecification as ParentSpecification/ChildrenSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5674
diff changeset
578 request_.GetChildrenSpecification(ResourceType_Series).AddMainDicomTag(DICOM_TAG_MODALITY);
5668
bd1352bd9d82 configuring requests for ModalitiesInStudy and SOPClassesInStudy
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5667
diff changeset
579 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
580 else if (tag == DICOM_TAG_INSTANCE_AVAILABILITY)
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
581 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
582 requestedComputedTags_.insert(tag);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
583 hasRequestedTags_ = true;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
584 }
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
585 else
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
586 {
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
587 // This is neither a main DICOM tag, nor a computed DICOM tag:
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
588 // We will be forced to access the DICOM file anyway
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
589 requestedTagsFromFileStorage_.insert(tag);
5610
d4b570834d3a adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5609
diff changeset
590
d4b570834d3a adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5609
diff changeset
591 if (request_.GetLevel() != ResourceType_Instance)
d4b570834d3a adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5609
diff changeset
592 {
d4b570834d3a adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5609
diff changeset
593 request_.SetRetrieveOneInstanceIdentifier(true);
d4b570834d3a adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5609
diff changeset
594 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
595
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
596 hasRequestedTags_ = true;
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
597 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
598 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
599
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
600
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
601 void ResourceFinder::AddRequestedTags(const std::set<DicomTag>& tags)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
602 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
603 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it)
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
604 {
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
605 AddRequestedTags(*it);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
606 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
607 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
608
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
609
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
610 static void InjectRequestedTags(DicomMap& requestedTags,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
611 std::set<DicomTag>& missingTags /* out */,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
612 const FindResponse::Resource& resource,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
613 ResourceType level,
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
614 const std::set<DicomTag>& tags)
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
615 {
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
616 if (!tags.empty())
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
617 {
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
618 DicomMap m;
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
619 resource.GetMainDicomTags(m, level);
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
620
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
621 for (std::set<DicomTag>::const_iterator it = tags.begin(); it != tags.end(); ++it)
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
622 {
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
623 std::string value;
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
624 if (m.LookupStringValue(value, *it, false /* not binary */))
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
625 {
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
626 requestedTags.SetValue(*it, value, false /* not binary */);
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
627 }
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
628 else
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
629 {
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
630 // This is the case where the Housekeeper should be run
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
631 missingTags.insert(*it);
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
632 }
5666
aa231c18b9d2 adding computed tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5665
diff changeset
633 }
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
634 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
635 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
636
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
637
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
638 static void ReadMissingTagsFromStorageArea(DicomMap& requestedTags,
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
639 ServerContext& context,
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
640 const FindRequest& request,
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
641 const FindResponse::Resource& resource,
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
642 const std::set<DicomTag>& missingTags)
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
643 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
644 OrthancConfiguration::ReaderLock lock;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
645 if (lock.GetConfiguration().IsWarningEnabled(Warnings_001_TagsBeingReadFromStorage))
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
646 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
647 std::string missings;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
648 FromDcmtkBridge::FormatListOfTags(missings, missingTags);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
649
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
650 LOG(WARNING) << "W001: Accessing Dicom tags from storage when accessing "
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
651 << Orthanc::GetResourceTypeText(resource.GetLevel(), false, false)
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
652 << ": " << missings;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
653 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
654
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
655 std::string instancePublicId;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
656
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
657 if (request.IsRetrieveOneInstanceIdentifier())
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
658 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
659 instancePublicId = resource.GetOneInstanceIdentifier();
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
660 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
661 else if (request.GetLevel() == ResourceType_Instance)
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
662 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
663 instancePublicId = resource.GetIdentifier();
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
664 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
665 else
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
666 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
667 FindRequest requestDicomAttachment(request.GetLevel());
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
668 requestDicomAttachment.SetOrthancId(request.GetLevel(), resource.GetIdentifier());
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
669 requestDicomAttachment.SetRetrieveOneInstanceIdentifier(true);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
670
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
671 FindResponse responseDicomAttachment;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
672 context.GetIndex().ExecuteFind(responseDicomAttachment, requestDicomAttachment);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
673
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
674 if (responseDicomAttachment.GetSize() != 1 ||
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
675 !responseDicomAttachment.GetResourceByIndex(0).HasOneInstanceIdentifier())
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
676 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
677 throw OrthancException(ErrorCode_InexistentFile);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
678 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
679 else
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
680 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
681 instancePublicId = responseDicomAttachment.GetResourceByIndex(0).GetOneInstanceIdentifier();
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
682 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
683 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
684
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
685 LOG(INFO) << "Will retrieve missing DICOM tags from instance: " << instancePublicId;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
686
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
687 // TODO-FIND: What do we do if the DICOM has been removed since the request?
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
688 // Do we fail, or do we skip the resource?
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
689
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
690 Json::Value tmpDicomAsJson;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
691 context.ReadDicomAsJson(tmpDicomAsJson, instancePublicId, missingTags /* ignoreTagLength */);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
692
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
693 DicomMap tmpDicomMap;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
694 tmpDicomMap.FromDicomAsJson(tmpDicomAsJson, false /* append */, true /* parseSequences*/);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
695
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
696 for (std::set<DicomTag>::const_iterator it = missingTags.begin(); it != missingTags.end(); ++it)
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
697 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
698 assert(!requestedTags.HasTag(*it));
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
699 if (tmpDicomMap.HasTag(*it))
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
700 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
701 requestedTags.SetValue(*it, tmpDicomMap.GetValue(*it));
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
702 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
703 else
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
704 {
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
705 requestedTags.SetNullValue(*it); // TODO-FIND: Is this compatible with Orthanc <= 1.12.3?
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
706 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
707 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
708 }
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
709
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
710
5682
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
711 void ResourceFinder::Execute(FindResponse& response,
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
712 ServerIndex& index) const
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
713 {
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
714 if (hasRequestedTags_)
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
715 {
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
716 throw OrthancException(ErrorCode_BadSequenceOfCalls);
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
717 }
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
718 else
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
719 {
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
720 index.ExecuteFind(response, request_);
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
721 }
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
722 }
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
723
fd4c5e064cbe started refactoring of ServerContext::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5676
diff changeset
724
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 void ResourceFinder::Execute(Json::Value& target,
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
726 ServerContext& context) const
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 FindResponse response;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 context.GetIndex().ExecuteFind(response, request_);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 target = Json::arrayValue;
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
733 for (size_t i = 0; i < response.GetSize(); i++)
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 {
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
735 const FindResponse::Resource& resource = response.GetResourceByIndex(i);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
736
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
737 if (expand_)
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 {
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 Json::Value item;
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
740 Expand(item, resource, context.GetIndex());
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
741
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
742 if (hasRequestedTags_)
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
743 {
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
744 DicomMap requestedTags;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
745 InjectComputedTags(requestedTags, resource);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
746
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
747 std::set<DicomTag> missingTags = requestedTagsFromFileStorage_;
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
748 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Patient, requestedPatientTags_);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
749 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Study, requestedStudyTags_);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
750 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Series, requestedSeriesTags_);
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
751 InjectRequestedTags(requestedTags, missingTags, resource, ResourceType_Instance, requestedInstanceTags_);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
752
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
753 if (!missingTags.empty())
5610
d4b570834d3a adding safeguards around FindRequest::SetRetrieveOneInstanceIdentifier()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5609
diff changeset
754 {
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
755 if (!allowStorageAccess_)
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
756 {
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
757 throw OrthancException(ErrorCode_BadSequenceOfCalls,
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
758 "Cannot add missing requested tags, as access to file storage is disallowed");
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
759 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
760 else
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
761 {
5665
d8c86698110c implemented computed tag: Instance Availability
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5641
diff changeset
762 ReadMissingTagsFromStorageArea(requestedTags, context, request_, resource, missingTags);
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
763 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
764 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
765
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
766 static const char* const REQUESTED_TAGS = "RequestedTags";
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
767 item[REQUESTED_TAGS] = Json::objectValue;
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
768 FromDcmtkBridge::ToJson(item[REQUESTED_TAGS], requestedTags, format_);
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
769 }
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
770
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 target.append(item);
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 }
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
773 else
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 {
5609
4690a0d2b01e preliminary support of requestedTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5608
diff changeset
775 target.append(resource.GetIdentifier());
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 }
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 }
5615
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
779
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
780
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
781 bool ResourceFinder::ExecuteOneResource(Json::Value& target,
5621
732ec9feeea8 introduction of FindRequest::ChildrenRetrieveSpecification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5620
diff changeset
782 ServerContext& context) const
5615
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
783 {
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
784 Json::Value answer;
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
785 Execute(answer, context);
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
786
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
787 if (answer.type() != Json::arrayValue)
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
788 {
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
789 throw OrthancException(ErrorCode_InternalError);
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
790 }
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
791 else if (answer.size() > 1)
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
792 {
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
793 throw OrthancException(ErrorCode_DatabasePlugin);
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
794 }
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
795 else if (answer.empty())
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
796 {
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
797 // Inexistent resource (or was deleted between the first and second phases)
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
798 return false;
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
799 }
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
800 else
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
801 {
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
802 target = answer[0];
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
803 return true;
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
804 }
a10978a5e65c expansion of single resources using ResourceFinder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5612
diff changeset
805 }
5608
3d0aa94b44b3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 }