Mercurial > hg > orthanc-stone
comparison Framework/Loaders/DicomStructureSetLoader.cpp @ 964:91f827272c1f toa2019082701
Added cache-control headers for POST requests + #ifdef'd tracing logs + trace on context restored
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 27 Aug 2019 14:28:19 +0200 |
parents | bd979d435e9d |
children | e3234630df9c |
comparison
equal
deleted
inserted
replaced
962:e70d75f199c5 | 964:91f827272c1f |
---|---|
22 #include "DicomStructureSetLoader.h" | 22 #include "DicomStructureSetLoader.h" |
23 | 23 |
24 #include "../Scene2D/PolylineSceneLayer.h" | 24 #include "../Scene2D/PolylineSceneLayer.h" |
25 #include "../Toolbox/GeometryToolbox.h" | 25 #include "../Toolbox/GeometryToolbox.h" |
26 | 26 |
27 #if 0 | |
28 bool logbgo233 = false; | |
29 bool logbgo115 = false; | |
30 #endif | |
31 | |
27 namespace OrthancStone | 32 namespace OrthancStone |
28 { | 33 { |
34 | |
35 #if 0 | |
36 void DumpDicomMap(std::ostream& o, const Orthanc::DicomMap& dicomMap) | |
37 { | |
38 using namespace std; | |
39 //ios_base::fmtflags state = o.flags(); | |
40 //o.flags(ios::right | ios::hex); | |
41 //o << "(" << setfill('0') << setw(4) << tag.GetGroup() | |
42 // << "," << setw(4) << tag.GetElement() << ")"; | |
43 //o.flags(state); | |
44 Json::Value val; | |
45 dicomMap.Serialize(val); | |
46 o << val; | |
47 //return o; | |
48 } | |
49 #endif | |
50 | |
51 | |
29 class DicomStructureSetLoader::AddReferencedInstance : public LoaderStateMachine::State | 52 class DicomStructureSetLoader::AddReferencedInstance : public LoaderStateMachine::State |
30 { | 53 { |
31 private: | 54 private: |
32 std::string instanceId_; | 55 std::string instanceId_; |
33 | 56 |
39 { | 62 { |
40 } | 63 } |
41 | 64 |
42 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) | 65 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) |
43 { | 66 { |
67 #if 0 | |
68 if (logbgo115) | |
69 LOG(TRACE) << "DicomStructureSetLoader::AddReferencedInstance::Handle() (SUCCESS)"; | |
70 #endif | |
44 Json::Value tags; | 71 Json::Value tags; |
45 message.ParseJsonBody(tags); | 72 message.ParseJsonBody(tags); |
46 | 73 |
47 Orthanc::DicomMap dicom; | 74 Orthanc::DicomMap dicom; |
48 dicom.FromDicomAsJson(tags); | 75 dicom.FromDicomAsJson(tags); |
49 | 76 |
50 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); | 77 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); |
78 | |
79 #if 0 | |
80 { | |
81 std::stringstream ss; | |
82 //DumpDicomMap(ss, dicom); | |
83 std::string dicomMapStr = ss.str(); | |
84 if (logbgo115) | |
85 LOG(TRACE) << " DicomStructureSetLoader::AddReferencedInstance::Handle() about to call AddReferencedSlice on dicom = " << dicomMapStr; | |
86 } | |
87 #endif | |
88 | |
89 | |
51 loader.content_->AddReferencedSlice(dicom); | 90 loader.content_->AddReferencedSlice(dicom); |
52 | 91 |
53 loader.countProcessedInstances_ ++; | 92 loader.countProcessedInstances_ ++; |
54 assert(loader.countProcessedInstances_ <= loader.countReferencedInstances_); | 93 assert(loader.countProcessedInstances_ <= loader.countReferencedInstances_); |
55 | 94 |
78 { | 117 { |
79 } | 118 } |
80 | 119 |
81 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) | 120 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) |
82 { | 121 { |
122 #if 0 | |
123 LOG(TRACE) << "DicomStructureSetLoader::LookupInstance::Handle() (SUCCESS)"; | |
124 #endif | |
83 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); | 125 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); |
84 | 126 |
85 Json::Value lookup; | 127 Json::Value lookup; |
86 message.ParseJsonBody(lookup); | 128 message.ParseJsonBody(lookup); |
87 | 129 |
106 } | 148 } |
107 | 149 |
108 const std::string instanceId = lookup[0]["ID"].asString(); | 150 const std::string instanceId = lookup[0]["ID"].asString(); |
109 | 151 |
110 { | 152 { |
153 #if 0 | |
154 if(logbgo115) | |
155 LOG(TRACE) << "DicomStructureSetLoader::LookupInstance::Handle() (SUCCESS)"; | |
156 #endif | |
111 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); | 157 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
112 command->SetHttpHeader("Accept-Encoding", "gzip"); | 158 command->SetHttpHeader("Accept-Encoding", "gzip"); |
113 command->SetUri("/instances/" + instanceId + "/tags"); | 159 std::string uri = "/instances/" + instanceId + "/tags"; |
160 command->SetUri(uri); | |
114 command->SetPayload(new AddReferencedInstance(loader, instanceId)); | 161 command->SetPayload(new AddReferencedInstance(loader, instanceId)); |
162 #if 0 | |
163 if (logbgo115) | |
164 LOG(TRACE) << " DicomStructureSetLoader::LookupInstance::Handle() about to schedule request with AddReferencedInstance subsequent command on uri \"" << uri << "\""; | |
165 #endif | |
115 Schedule(command.release()); | 166 Schedule(command.release()); |
167 #if 0 | |
168 if (logbgo115) | |
169 LOG(TRACE) << " DicomStructureSetLoader::LookupInstance::Handle() request+command scheduled"; | |
170 #endif | |
116 } | 171 } |
117 } | 172 } |
118 }; | 173 }; |
119 | 174 |
120 | 175 |
124 LoadStructure(DicomStructureSetLoader& that) : | 179 LoadStructure(DicomStructureSetLoader& that) : |
125 State(that) | 180 State(that) |
126 { | 181 { |
127 } | 182 } |
128 | 183 |
184 | |
129 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) | 185 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) |
130 { | 186 { |
187 #if 0 | |
188 if (logbgo115) | |
189 LOG(TRACE) << "DicomStructureSetLoader::LoadStructure::Handle() (SUCCESS)"; | |
190 #endif | |
131 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); | 191 DicomStructureSetLoader& loader = GetLoader<DicomStructureSetLoader>(); |
132 | 192 |
133 { | 193 { |
134 OrthancPlugins::FullOrthancDataset dicom(message.GetAnswer()); | 194 OrthancPlugins::FullOrthancDataset dicom(message.GetAnswer()); |
135 loader.content_.reset(new DicomStructureSet(dicom)); | 195 loader.content_.reset(new DicomStructureSet(dicom)); |
142 | 202 |
143 for (std::set<std::string>::const_iterator | 203 for (std::set<std::string>::const_iterator |
144 it = instances.begin(); it != instances.end(); ++it) | 204 it = instances.begin(); it != instances.end(); ++it) |
145 { | 205 { |
146 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); | 206 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
207 #if 0 | |
208 if (logbgo115) | |
209 LOG(TRACE) << " DicomStructureSetLoader::LoadStructure::Handle() about to schedule /tools/lookup command with LookupInstance on result"; | |
210 #endif | |
147 command->SetUri("/tools/lookup"); | 211 command->SetUri("/tools/lookup"); |
148 command->SetMethod(Orthanc::HttpMethod_Post); | 212 command->SetMethod(Orthanc::HttpMethod_Post); |
149 command->SetBody(*it); | 213 command->SetBody(*it); |
214 command->SetHttpHeader("pragma", "no-cache"); | |
215 command->SetHttpHeader("cache-control", "no-cache"); | |
216 #if 0 | |
217 std::string itStr(*it); | |
218 if(itStr == "1.3.12.2.1107.5.1.4.66930.30000018062412550879500002198") { | |
219 if (logbgo115) | |
220 LOG(ERROR) << "******** BOGUS LOOKUPS FROM NOW ON ***********"; | |
221 logbgo233 = true; | |
222 } | |
223 #endif | |
150 command->SetPayload(new LookupInstance(loader, *it)); | 224 command->SetPayload(new LookupInstance(loader, *it)); |
151 //LOG(TRACE) << "About to schedule a /tools/lookup POST request. URI = " << command->GetUri() << " Body size = " << (*it).size() << " Body = " << (*it) << "\n"; | 225 //LOG(TRACE) << "About to schedule a /tools/lookup POST request. URI = " << command->GetUri() << " Body size = " << (*it).size() << " Body = " << (*it) << "\n"; |
152 Schedule(command.release()); | 226 Schedule(command.release()); |
227 #if 0 | |
228 if (logbgo115) | |
229 LOG(TRACE) << " DicomStructureSetLoader::LoadStructure::Handle() request scheduled. Command will be LookupInstance and post body is " << *it; | |
230 #endif | |
153 } | 231 } |
154 } | 232 } |
155 }; | 233 }; |
156 | 234 |
157 | 235 |
248 instanceId_ = instanceId; | 326 instanceId_ = instanceId; |
249 | 327 |
250 { | 328 { |
251 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); | 329 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
252 command->SetHttpHeader("Accept-Encoding", "gzip"); | 330 command->SetHttpHeader("Accept-Encoding", "gzip"); |
253 command->SetUri("/instances/" + instanceId + "/tags?ignore-length=3006-0050"); | 331 |
332 std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3006-0050"; | |
333 #if 0 | |
334 if (logbgo115) | |
335 LOG(TRACE) << "DicomStructureSetLoader::LoadInstance() instanceId = " << instanceId << " | uri = \"" << uri << "\""; | |
336 #endif | |
337 command->SetUri(uri); | |
254 command->SetPayload(new LoadStructure(*this)); | 338 command->SetPayload(new LoadStructure(*this)); |
255 Schedule(command.release()); | 339 Schedule(command.release()); |
340 #if 0 | |
341 if (logbgo115) | |
342 LOG(TRACE) << "DicomStructureSetLoader::LoadInstance() command (with LoadStructure) scheduled."; | |
343 #endif | |
256 } | 344 } |
257 } | 345 } |
258 | 346 |
259 | 347 |
260 IVolumeSlicer::IExtractedSlice* DicomStructureSetLoader::ExtractSlice(const CoordinateSystem3D& cuttingPlane) | 348 IVolumeSlicer::IExtractedSlice* DicomStructureSetLoader::ExtractSlice(const CoordinateSystem3D& cuttingPlane) |