comparison OrthancStone/Sources/Toolbox/ParsedDicomDataset.cpp @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Toolbox/ParsedDicomDataset.cpp@d8af188ab545
children 4fb8fdf03314
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
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
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "ParsedDicomDataset.h"
23
24 #include <dcmtk/dcmdata/dcfilefo.h>
25
26 namespace OrthancStone
27 {
28 static DcmItem* LookupPath(Orthanc::ParsedDicomFile& dicom,
29 const DicomPath& path)
30 {
31 DcmItem* node = dicom.GetDcmtkObject().getDataset();
32
33 for (size_t i = 0; i < path.GetPrefixLength(); i++)
34 {
35 const Orthanc::DicomTag& tmp = path.GetPrefixTag(i);
36 DcmTagKey tag(tmp.GetGroup(), tmp.GetElement());
37
38 DcmSequenceOfItems* sequence = NULL;
39 if (!node->findAndGetSequence(tag, sequence).good() ||
40 sequence == NULL)
41 {
42 return NULL;
43 }
44
45 unsigned long pos = path.GetPrefixIndex(i);
46 if (pos >= sequence->card())
47 {
48 return NULL;
49 }
50
51 node = sequence->getItem(pos);
52 if (node == NULL)
53 {
54 return NULL;
55 }
56 }
57
58 return node;
59 }
60
61
62 bool ParsedDicomDataset::GetStringValue(std::string& result,
63 const DicomPath& path) const
64 {
65 DcmItem* node = LookupPath(dicom_, path);
66
67 if (node != NULL)
68 {
69 DcmTagKey tag(path.GetFinalTag().GetGroup(), path.GetFinalTag().GetElement());
70
71 const char* s = NULL;
72 if (node->findAndGetString(tag, s).good() &&
73 s != NULL)
74 {
75 result.assign(s);
76 return true;
77 }
78 }
79
80 return false;
81 }
82
83
84 bool ParsedDicomDataset::GetSequenceSize(size_t& size,
85 const DicomPath& path) const
86 {
87 DcmItem* node = LookupPath(dicom_, path);
88
89 if (node != NULL)
90 {
91 DcmTagKey tag(path.GetFinalTag().GetGroup(), path.GetFinalTag().GetElement());
92
93 DcmSequenceOfItems* s = NULL;
94 if (node->findAndGetSequence(tag, s).good() &&
95 s != NULL)
96 {
97 size = s->card();
98 return true;
99 }
100 }
101
102 return false;
103 }
104 }