comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.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 120945ce48b6
children 6fed78e13233
comparison
equal deleted inserted replaced
5042:120945ce48b6 5043:ec5c203a97ea
43 #include <stack> 43 #include <stack>
44 44
45 45
46 namespace Orthanc 46 namespace Orthanc
47 { 47 {
48 // copy all tags from Json (used to read from metadata)
49 void DicomSequencesMap::Deserialize(const Json::Value& serialized)
50 {
51 Json::Value::Members members = serialized.getMemberNames();
52 for (size_t i = 0; i < members.size(); i++)
53 {
54 DicomTag tag = FromDcmtkBridge::ParseTag(members[i].c_str());
55 sequences_[tag] = serialized[members[i]];
56 }
57 }
58
59 // serialize a subet of tags (used to store in the metadata)
60 void DicomSequencesMap::Serialize(Json::Value& target, const std::set<DicomTag>& tags) const
61 {
62 // add the sequences to "target"
63 for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin();
64 it != sequences_.end(); ++it)
65 {
66 if (tags.find(it->first) != tags.end())
67 {
68 target[it->first.Format()] = it->second;
69 }
70 }
71 }
72
73 // copy a subset of tags from Json
74 void DicomSequencesMap::FromDicomAsJson(const Json::Value& dicomAsJson, const std::set<DicomTag>& tags)
75 {
76 for (std::set<DicomTag>::const_iterator it = tags.begin();
77 it != tags.end(); ++it)
78 {
79 std::string tag = it->Format();
80 if (dicomAsJson.isMember(tag))
81 {
82 sequences_[*it] = dicomAsJson[tag];
83 }
84 }
85 }
86
87 void DicomSequencesMap::ToJson(Json::Value& target, DicomToJsonFormat format) const
88 {
89 // add the sequences to "target"
90 for (std::map<DicomTag, Json::Value>::const_iterator it = sequences_.begin();
91 it != sequences_.end(); ++it)
92 {
93 Json::Value sequenceForConversion = Json::objectValue;
94 sequenceForConversion[it->first.Format()] = it->second;
95
96 Json::Value& requestedFormatJson = sequenceForConversion;
97 Json::Value convertedJson;
98
99 if (format != DicomToJsonFormat_Full)
100 {
101 Toolbox::SimplifyDicomAsJson(convertedJson, sequenceForConversion, format);
102 requestedFormatJson = convertedJson;
103 }
104
105 Json::Value::Members keys = requestedFormatJson.getMemberNames();
106 for (size_t i = 0; i < keys.size(); i++) // there should always be only one member in this JSON
107 {
108 target[keys[i]] = requestedFormatJson[keys[i]];
109 }
110 }
111 }
112
113 namespace 48 namespace
114 { 49 {
115 /** 50 /**
116 * Some handy templates to reduce the verbosity in the definitions 51 * Some handy templates to reduce the verbosity in the definitions
117 * of the internal classes. 52 * of the internal classes.