Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/SimplifiedOrthancDataset.cpp @ 1812:db341679dc9f
ViewerViewport::StoneAnnotationsRegistry
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 25 May 2021 12:32:11 +0200 |
parents | 9ac2a65d4172 |
children | 126522623e20 |
rev | line source |
---|---|
1504 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
1504 | 6 * |
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 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
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 | 20 **/ |
21 | |
22 | |
23 #include "SimplifiedOrthancDataset.h" | |
24 | |
1571 | 25 #include <OrthancException.h> |
26 #include <DicomParsing/FromDcmtkBridge.h> | |
27 | |
1504 | 28 namespace OrthancStone |
29 { | |
30 const Json::Value* SimplifiedOrthancDataset::LookupPath(const DicomPath& path) const | |
31 { | |
32 const Json::Value* content = &root_; | |
33 | |
34 for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++) | |
35 { | |
1571 | 36 const std::string name = Orthanc::FromDcmtkBridge::GetTagName( |
37 path.GetPrefixTag(depth), "" /* no private creator */); | |
1504 | 38 if (content->type() != Json::objectValue) |
39 { | |
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
41 } | |
42 | |
43 if (!content->isMember(name)) | |
44 { | |
45 return NULL; | |
46 } | |
47 | |
48 const Json::Value& sequence = (*content) [name]; | |
49 if (sequence.type() != Json::arrayValue) | |
50 { | |
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
52 } | |
53 | |
54 size_t index = path.GetPrefixIndex(depth); | |
55 if (index >= sequence.size()) | |
56 { | |
57 return NULL; | |
58 } | |
59 else | |
60 { | |
61 content = &sequence[static_cast<Json::Value::ArrayIndex>(index)]; | |
62 } | |
63 } | |
64 | |
1571 | 65 const std::string name = Orthanc::FromDcmtkBridge::GetTagName( |
66 path.GetFinalTag(), "" /* no private creator */); | |
1504 | 67 |
68 if (content->type() != Json::objectValue) | |
69 { | |
70 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
71 } | |
72 if (!content->isMember(name)) | |
73 { | |
74 return NULL; | |
75 } | |
76 else | |
77 { | |
78 return &((*content) [name]); | |
79 } | |
80 } | |
81 | |
82 | |
83 void SimplifiedOrthancDataset::CheckRoot() const | |
84 { | |
85 if (root_.type() != Json::objectValue) | |
86 { | |
87 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
88 } | |
89 } | |
90 | |
91 | |
92 SimplifiedOrthancDataset::SimplifiedOrthancDataset(IOrthancConnection& orthanc, | |
93 const std::string& uri) | |
94 { | |
95 IOrthancConnection::RestApiGet(root_, orthanc, uri); | |
96 CheckRoot(); | |
97 } | |
98 | |
99 | |
100 SimplifiedOrthancDataset::SimplifiedOrthancDataset(const std::string& content) | |
101 { | |
102 IOrthancConnection::ParseJson(root_, content); | |
103 CheckRoot(); | |
104 } | |
105 | |
106 | |
107 bool SimplifiedOrthancDataset::GetStringValue(std::string& result, | |
108 const DicomPath& path) const | |
109 { | |
110 const Json::Value* value = LookupPath(path); | |
111 | |
112 if (value == NULL) | |
113 { | |
114 return false; | |
115 } | |
116 else if (value->type() != Json::stringValue) | |
117 { | |
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
119 } | |
120 else | |
121 { | |
122 result = value->asString(); | |
123 return true; | |
124 } | |
125 } | |
126 | |
127 | |
128 bool SimplifiedOrthancDataset::GetSequenceSize(size_t& size, | |
129 const DicomPath& path) const | |
130 { | |
131 const Json::Value* sequence = LookupPath(path); | |
132 | |
133 if (sequence == NULL) | |
134 { | |
135 // Inexistent path | |
136 return false; | |
137 } | |
138 else if (sequence->type() != Json::arrayValue) | |
139 { | |
140 // Not a sequence | |
141 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
142 } | |
143 else | |
144 { | |
145 size = sequence->size(); | |
146 return true; | |
147 } | |
148 } | |
149 } |