annotate OrthancStone/Sources/Toolbox/OrthancDatasets/SimplifiedOrthancDataset.cpp @ 1653:2e3b2ed239b9

Fixed usage of object cookie
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 16 Nov 2020 22:17:01 +0100
parents 8563ea5d8ae4
children 9ac2a65d4172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "SimplifiedOrthancDataset.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
25 #include <OrthancException.h>
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
26 #include <DicomParsing/FromDcmtkBridge.h>
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
27
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 const Json::Value* SimplifiedOrthancDataset::LookupPath(const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 const Json::Value* content = &root_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
36 const std::string name = Orthanc::FromDcmtkBridge::GetTagName(
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
37 path.GetPrefixTag(depth), "" /* no private creator */);
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 if (content->type() != Json::objectValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 if (!content->isMember(name))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 return NULL;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 const Json::Value& sequence = (*content) [name];
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if (sequence.type() != Json::arrayValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 size_t index = path.GetPrefixIndex(depth);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (index >= sequence.size())
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 return NULL;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 content = &sequence[static_cast<Json::Value::ArrayIndex>(index)];
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
65 const std::string name = Orthanc::FromDcmtkBridge::GetTagName(
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
66 path.GetFinalTag(), "" /* no private creator */);
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 if (content->type() != Json::objectValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if (!content->isMember(name))
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return NULL;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return &((*content) [name]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 void SimplifiedOrthancDataset::CheckRoot() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 if (root_.type() != Json::objectValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 SimplifiedOrthancDataset::SimplifiedOrthancDataset(IOrthancConnection& orthanc,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const std::string& uri)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 IOrthancConnection::RestApiGet(root_, orthanc, uri);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 CheckRoot();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 SimplifiedOrthancDataset::SimplifiedOrthancDataset(const std::string& content)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 IOrthancConnection::ParseJson(root_, content);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 CheckRoot();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 bool SimplifiedOrthancDataset::GetStringValue(std::string& result,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const Json::Value* value = LookupPath(path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 if (value == NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 else if (value->type() != Json::stringValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 result = value->asString();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 bool SimplifiedOrthancDataset::GetSequenceSize(size_t& size,
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const DicomPath& path) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 const Json::Value* sequence = LookupPath(path);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 if (sequence == NULL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 // Inexistent path
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 return false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 else if (sequence->type() != Json::arrayValue)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 // Not a sequence
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 size = sequence->size();
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }