comparison OrthancFramework/Sources/DicomFormat/DicomSequencesMap.cpp @ 5043:ec5c203a97ea

returning sequences in MainDicomTags and RequestedTags
author Alain Mazy <am@osimis.io>
date Mon, 27 Jun 2022 15:22:19 +0200
parents
children
comparison
equal deleted inserted replaced
5042:120945ce48b6 5043:ec5c203a97ea
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * 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
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **/
21
22 #include "../PrecompiledHeaders.h"
23 #include "DicomSequencesMap.h"
24 #include "../Toolbox.h"
25
26 namespace Orthanc
27 {
28
29 #if ORTHANC_ENABLE_DCMTK == 1
30
31 // copy all tags from Json (used to read from metadata)
32 void DicomSequencesMap::Deserialize(const Json::Value& serialized)
33 {
34 Json::Value::Members members = serialized.getMemberNames();
35 for (size_t i = 0; i < members.size(); i++)
36 {
37 DicomTag tag(0, 0);
38 if (DicomTag::ParseHexadecimal(tag, members[i].c_str()))
39 {
40 sequences_[tag] = serialized[members[i]];
41 }
42 }
43 }
44
45 #endif
46
47 // serialize a subet of tags (used to store in the metadata)
48 void DicomSequencesMap::Serialize(Json::Value& target, const std::set<DicomTag>& tags) const
49 {
50 // add the sequences to "target"
51 for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin();
52 it != sequences_.end(); ++it)
53 {
54 if (tags.find(it->first) != tags.end())
55 {
56 target[it->first.Format()] = it->second;
57 }
58 }
59 }
60
61 // copy a subset of tags from Json
62 void DicomSequencesMap::FromDicomAsJson(const Json::Value& dicomAsJson, const std::set<DicomTag>& tags)
63 {
64 for (std::set<DicomTag>::const_iterator it = tags.begin();
65 it != tags.end(); ++it)
66 {
67 std::string tag = it->Format();
68 if (dicomAsJson.isMember(tag))
69 {
70 sequences_[*it] = dicomAsJson[tag];
71 }
72 }
73 }
74
75 void DicomSequencesMap::ToJson(Json::Value& target, DicomToJsonFormat format, const std::set<DicomTag>& tags) const
76 {
77 // add the sequences to "target"
78 for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin();
79 it != sequences_.end(); ++it)
80 {
81 Json::Value sequenceFullJson = Json::objectValue;
82 sequenceFullJson[it->first.Format()] = it->second;
83
84 Json::Value& requestedFormatJson = sequenceFullJson;
85 Json::Value convertedJson;
86
87 if (format != DicomToJsonFormat_Full)
88 {
89 Toolbox::SimplifyDicomAsJson(convertedJson, sequenceFullJson, format);
90 requestedFormatJson = convertedJson;
91 }
92
93 Json::Value::Members keys = requestedFormatJson.getMemberNames();
94 for (size_t i = 0; i < keys.size(); i++) // there should always be only one member in this JSON
95 {
96 target[keys[i]] = requestedFormatJson[keys[i]];
97 }
98 }
99 }
100 }