Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/SimplifiedOrthancDataset.cpp @ 2097:a9e23ef9ee09 dicom-sr
preparing to extract dicom-sr annotations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 08 Nov 2023 16:31:49 +0100 |
parents | 07964689cb0b |
children | c23eef785569 |
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 | |
2077
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
07964689cb0b
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1504 | 7 * |
8 * 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
|
9 * modify it under the terms of the GNU Lesser General Public License |
1504 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * 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
|
15 * 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
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
1504 | 21 **/ |
22 | |
23 | |
24 #include "SimplifiedOrthancDataset.h" | |
25 | |
1571 | 26 #include <OrthancException.h> |
27 #include <DicomParsing/FromDcmtkBridge.h> | |
28 | |
1504 | 29 namespace OrthancStone |
30 { | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
31 const Json::Value* SimplifiedOrthancDataset::LookupPath(const Orthanc::DicomPath& path) const |
1504 | 32 { |
33 const Json::Value* content = &root_; | |
34 | |
35 for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++) | |
36 { | |
1571 | 37 const std::string name = Orthanc::FromDcmtkBridge::GetTagName( |
38 path.GetPrefixTag(depth), "" /* no private creator */); | |
1504 | 39 if (content->type() != Json::objectValue) |
40 { | |
41 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
42 } | |
43 | |
44 if (!content->isMember(name)) | |
45 { | |
46 return NULL; | |
47 } | |
48 | |
49 const Json::Value& sequence = (*content) [name]; | |
50 if (sequence.type() != Json::arrayValue) | |
51 { | |
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
53 } | |
54 | |
55 size_t index = path.GetPrefixIndex(depth); | |
56 if (index >= sequence.size()) | |
57 { | |
58 return NULL; | |
59 } | |
60 else | |
61 { | |
62 content = &sequence[static_cast<Json::Value::ArrayIndex>(index)]; | |
63 } | |
64 } | |
65 | |
1571 | 66 const std::string name = Orthanc::FromDcmtkBridge::GetTagName( |
67 path.GetFinalTag(), "" /* no private creator */); | |
1504 | 68 |
69 if (content->type() != Json::objectValue) | |
70 { | |
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
72 } | |
73 if (!content->isMember(name)) | |
74 { | |
75 return NULL; | |
76 } | |
77 else | |
78 { | |
79 return &((*content) [name]); | |
80 } | |
81 } | |
82 | |
83 | |
84 void SimplifiedOrthancDataset::CheckRoot() const | |
85 { | |
86 if (root_.type() != Json::objectValue) | |
87 { | |
88 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
89 } | |
90 } | |
91 | |
92 | |
93 SimplifiedOrthancDataset::SimplifiedOrthancDataset(IOrthancConnection& orthanc, | |
94 const std::string& uri) | |
95 { | |
96 IOrthancConnection::RestApiGet(root_, orthanc, uri); | |
97 CheckRoot(); | |
98 } | |
99 | |
100 | |
101 SimplifiedOrthancDataset::SimplifiedOrthancDataset(const std::string& content) | |
102 { | |
103 IOrthancConnection::ParseJson(root_, content); | |
104 CheckRoot(); | |
105 } | |
106 | |
107 | |
108 bool SimplifiedOrthancDataset::GetStringValue(std::string& result, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
109 const Orthanc::DicomPath& path) const |
1504 | 110 { |
111 const Json::Value* value = LookupPath(path); | |
112 | |
113 if (value == NULL) | |
114 { | |
115 return false; | |
116 } | |
117 else if (value->type() != Json::stringValue) | |
118 { | |
119 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
120 } | |
121 else | |
122 { | |
123 result = value->asString(); | |
124 return true; | |
125 } | |
126 } | |
127 | |
128 | |
129 bool SimplifiedOrthancDataset::GetSequenceSize(size_t& size, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
130 const Orthanc::DicomPath& path) const |
1504 | 131 { |
132 const Json::Value* sequence = LookupPath(path); | |
133 | |
134 if (sequence == NULL) | |
135 { | |
136 // Inexistent path | |
137 return false; | |
138 } | |
139 else if (sequence->type() != Json::arrayValue) | |
140 { | |
141 // Not a sequence | |
142 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
143 } | |
144 else | |
145 { | |
146 size = sequence->size(); | |
147 return true; | |
148 } | |
149 } | |
150 } |