comparison OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 5060:e69a3ff39bc5

fix reuse of DicomAsJson between lookup and answers
author Alain Mazy <am@osimis.io>
date Mon, 08 Aug 2022 12:42:48 +0200
parents d4e5ca0c9307
children d7274e43ea7c 0ea402b4d901
comparison
equal deleted inserted replaced
5059:5c997c72603c 5060:e69a3ff39bc5
129 static void AnswerListOfResources(RestApiOutput& output, 129 static void AnswerListOfResources(RestApiOutput& output,
130 ServerContext& context, 130 ServerContext& context,
131 const std::list<std::string>& resources, 131 const std::list<std::string>& resources,
132 const std::map<std::string, std::string>& instancesIds, // optional: the id of an instance for each found resource. 132 const std::map<std::string, std::string>& instancesIds, // optional: the id of an instance for each found resource.
133 const std::map<std::string, boost::shared_ptr<DicomMap> >& resourcesMainDicomTags, // optional: all tags read from DB for a resource (current level and upper levels) 133 const std::map<std::string, boost::shared_ptr<DicomMap> >& resourcesMainDicomTags, // optional: all tags read from DB for a resource (current level and upper levels)
134 const std::map<std::string, const Json::Value*>& resourcesDicomAsJson, // optional: the dicom-as-json for each resource 134 const std::map<std::string, boost::shared_ptr<Json::Value> >& resourcesDicomAsJson, // optional: the dicom-as-json for each resource
135 ResourceType level, 135 ResourceType level,
136 bool expand, 136 bool expand,
137 DicomToJsonFormat format, 137 DicomToJsonFormat format,
138 const std::set<DicomTag>& requestedTags, 138 const std::set<DicomTag>& requestedTags,
139 bool allowStorageAccess) 139 bool allowStorageAccess)
150 std::map<std::string, std::string>::const_iterator instanceId = instancesIds.find(*resource); 150 std::map<std::string, std::string>::const_iterator instanceId = instancesIds.find(*resource);
151 if (instanceId != instancesIds.end()) // if it is found in instancesIds, it is also in resourcesDicomAsJson and mainDicomTags 151 if (instanceId != instancesIds.end()) // if it is found in instancesIds, it is also in resourcesDicomAsJson and mainDicomTags
152 { 152 {
153 // reuse data already collected before (e.g during lookup) 153 // reuse data already collected before (e.g during lookup)
154 std::map<std::string, boost::shared_ptr<DicomMap> >::const_iterator mainDicomTags = resourcesMainDicomTags.find(*resource); 154 std::map<std::string, boost::shared_ptr<DicomMap> >::const_iterator mainDicomTags = resourcesMainDicomTags.find(*resource);
155 std::map<std::string, const Json::Value*>::const_iterator dicomAsJson = resourcesDicomAsJson.find(*resource); 155 std::map<std::string, boost::shared_ptr<Json::Value> >::const_iterator dicomAsJson = resourcesDicomAsJson.find(*resource);
156 156
157 context.ExpandResource(expanded, *resource, 157 context.ExpandResource(expanded, *resource,
158 *(mainDicomTags->second.get()), 158 *(mainDicomTags->second.get()),
159 instanceId->second, 159 instanceId->second,
160 dicomAsJson->second, 160 dicomAsJson->second.get(),
161 level, format, requestedTags, allowStorageAccess); 161 level, format, requestedTags, allowStorageAccess);
162 } 162 }
163 else 163 else
164 { 164 {
165 context.ExpandResource(expanded, *resource, level, format, requestedTags, allowStorageAccess); 165 context.ExpandResource(expanded, *resource, level, format, requestedTags, allowStorageAccess);
189 const std::set<DicomTag>& requestedTags, 189 const std::set<DicomTag>& requestedTags,
190 bool allowStorageAccess) 190 bool allowStorageAccess)
191 { 191 {
192 std::map<std::string, std::string> unusedInstancesIds; 192 std::map<std::string, std::string> unusedInstancesIds;
193 std::map<std::string, boost::shared_ptr<DicomMap> > unusedResourcesMainDicomTags; 193 std::map<std::string, boost::shared_ptr<DicomMap> > unusedResourcesMainDicomTags;
194 std::map<std::string, const Json::Value* > unusedResourcesDicomAsJson; 194 std::map<std::string, boost::shared_ptr<Json::Value> > unusedResourcesDicomAsJson;
195 195
196 AnswerListOfResources(output, context, resources, unusedInstancesIds, unusedResourcesMainDicomTags, unusedResourcesDicomAsJson, level, expand, format, requestedTags, allowStorageAccess); 196 AnswerListOfResources(output, context, resources, unusedInstancesIds, unusedResourcesMainDicomTags, unusedResourcesDicomAsJson, level, expand, format, requestedTags, allowStorageAccess);
197 } 197 }
198 198
199 199
2873 FindStorageAccessMode findStorageAccessMode_; 2873 FindStorageAccessMode findStorageAccessMode_;
2874 2874
2875 // cache the data we used during lookup and that we could reuse when building the answers 2875 // cache the data we used during lookup and that we could reuse when building the answers
2876 std::map<std::string, std::string> instancesIds_; // the id of an instance for each found resource. 2876 std::map<std::string, std::string> instancesIds_; // the id of an instance for each found resource.
2877 std::map<std::string, boost::shared_ptr<DicomMap> > resourcesMainDicomTags_; // all tags read from DB for a resource (current level and upper levels) 2877 std::map<std::string, boost::shared_ptr<DicomMap> > resourcesMainDicomTags_; // all tags read from DB for a resource (current level and upper levels)
2878 std::map<std::string, const Json::Value* > resourcesDicomAsJson_; // the dicom-as-json for a resource 2878 std::map<std::string, boost::shared_ptr<Json::Value> > resourcesDicomAsJson_; // the dicom-as-json for a resource
2879 2879
2880 DicomToJsonFormat format_; 2880 DicomToJsonFormat format_;
2881 2881
2882 public: 2882 public:
2883 explicit FindVisitor(DicomToJsonFormat format, FindStorageAccessMode findStorageAccessMode) : 2883 explicit FindVisitor(DicomToJsonFormat format, FindStorageAccessMode findStorageAccessMode) :
2903 const Json::Value* dicomAsJson) ORTHANC_OVERRIDE 2903 const Json::Value* dicomAsJson) ORTHANC_OVERRIDE
2904 { 2904 {
2905 resources_.push_back(publicId); 2905 resources_.push_back(publicId);
2906 instancesIds_[publicId] = instanceId; 2906 instancesIds_[publicId] = instanceId;
2907 resourcesMainDicomTags_[publicId].reset(mainDicomTags.Clone()); 2907 resourcesMainDicomTags_[publicId].reset(mainDicomTags.Clone());
2908 resourcesDicomAsJson_[publicId] = dicomAsJson; 2908 if (dicomAsJson != NULL)
2909 {
2910 resourcesDicomAsJson_[publicId].reset(new Json::Value(*dicomAsJson)); // keep our own copy because we might reuse it between lookup and answers
2911 }
2912 else
2913 {
2914 resourcesDicomAsJson_[publicId] = boost::shared_ptr<Json::Value>();
2915 }
2909 } 2916 }
2910 2917
2911 void Answer(RestApiOutput& output, 2918 void Answer(RestApiOutput& output,
2912 ServerContext& context, 2919 ServerContext& context,
2913 ResourceType level, 2920 ResourceType level,