# HG changeset patch # User Sebastien Jodogne # Date 1448015878 -3600 # Node ID 23722a191e4eb1cfaa8e0378c8e448628a406a80 # Parent 5e08a5fe6b27efe7eb9fba2280944a53341c2cc3 worklists are working diff -r 5e08a5fe6b27 -r 23722a191e4e OrthancServer/DicomProtocol/DicomFindAnswers.cpp --- a/OrthancServer/DicomProtocol/DicomFindAnswers.cpp Thu Nov 19 18:32:00 2015 +0100 +++ b/OrthancServer/DicomProtocol/DicomFindAnswers.cpp Fri Nov 20 11:37:58 2015 +0100 @@ -48,12 +48,22 @@ private: ParsedDicomFile* dicom_; DicomMap* map_; - + + void CleanupDicom() + { + if (dicom_ != NULL) + { + dicom_->Remove(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID); + dicom_->Remove(DICOM_TAG_SOP_INSTANCE_UID); + } + } + public: Answer(ParsedDicomFile& dicom) : dicom_(dicom.Clone()), map_(NULL) { + CleanupDicom(); } Answer(const char* dicom, @@ -61,6 +71,7 @@ dicom_(new ParsedDicomFile(dicom, size)), map_(NULL) { + CleanupDicom(); } Answer(const DicomMap& map) : diff -r 5e08a5fe6b27 -r 23722a191e4e OrthancServer/Search/HierarchicalMatcher.cpp --- a/OrthancServer/Search/HierarchicalMatcher.cpp Thu Nov 19 18:32:00 2015 +0100 +++ b/OrthancServer/Search/HierarchicalMatcher.cpp Fri Nov 20 11:37:58 2015 +0100 @@ -235,7 +235,7 @@ if (!item.findAndGetSequence(tag, sequence).good() || sequence == NULL) { - return false; + return true; } bool match = false; @@ -260,10 +260,10 @@ } - DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& item, + DcmDataset* HierarchicalMatcher::ExtractInternal(DcmItem& source, Encoding encoding) const { - std::auto_ptr dataset(new DcmDataset); + std::auto_ptr target(new DcmDataset); for (Constraints::const_iterator it = constraints_.begin(); it != constraints_.end(); ++it) @@ -271,12 +271,12 @@ DcmTagKey tag = ToDcmtkBridge::Convert(it->first); DcmElement* element = NULL; - if (item.findAndGetElement(tag, element).good() && + if (source.findAndGetElement(tag, element).good() && element != NULL) { std::auto_ptr cloned(FromDcmtkBridge::CreateElementForTag(it->first)); cloned->copyFrom(*element); - dataset->insert(cloned.release()); + target->insert(cloned.release()); } } @@ -286,7 +286,7 @@ DcmTagKey tag = ToDcmtkBridge::Convert(it->first); DcmSequenceOfItems* sequence = NULL; - if (item.findAndGetSequence(tag, sequence).good() && + if (source.findAndGetSequence(tag, sequence).good() && sequence != NULL) { std::auto_ptr cloned(new DcmSequenceOfItems(tag)); @@ -297,17 +297,22 @@ { cloned->append(new DcmItem(*sequence->getItem(i))); } - else if (it->second->MatchInternal(*sequence->getItem(i), encoding)) + else if (it->second->MatchInternal(*sequence->getItem(i), encoding)) // TODO Might be optimized { - cloned->append(it->second->ExtractInternal(*sequence->getItem(i), encoding)); + // It is necessary to encapsulate the child dataset into a + // "DcmItem" object before it can be included in a + // sequence. Otherwise, "dciodvfy" reports an error "Bad + // tag in sequence - Expecting Item or Sequence Delimiter." + std::auto_ptr child(it->second->ExtractInternal(*sequence->getItem(i), encoding)); + cloned->append(new DcmItem(*child)); } } - dataset->insert(cloned.release()); + target->insert(cloned.release()); } } - return dataset.release(); + return target.release(); } diff -r 5e08a5fe6b27 -r 23722a191e4e OrthancServer/main.cpp --- a/OrthancServer/main.cpp Thu Nov 19 18:32:00 2015 +0100 +++ b/OrthancServer/main.cpp Fri Nov 20 11:37:58 2015 +0100 @@ -57,6 +57,9 @@ using namespace Orthanc; + + + class OrthancStoreRequestHandler : public IStoreRequestHandler { private: @@ -91,6 +94,8 @@ }; + + class OrthancWorklistRequestHandler : public IWorklistRequestHandler { private: @@ -107,33 +112,42 @@ const std::string& remoteIp, const std::string& remoteAet) { - printf("=====================================================================\n"); - printf("Worklist\n"); - bool caseSensitivePN = Configuration::GetGlobalBoolParameter("CaseSensitivePN", false); HierarchicalMatcher matcher(query, caseSensitivePN); - std::cout << matcher.Format(); + boost::filesystem::path source("/tmp/worklists/db/ORTHANCTEST"); + boost::filesystem::directory_iterator end; - for (unsigned int i = 1; i <= 10; i++) + try { - std::string p = "/tmp/worklists/db/OFFIS/item" + boost::lexical_cast(i) + ".wl"; - std::string s; - Toolbox::ReadFile(s, p); - ParsedDicomFile f(s); - std::cout << p << " => " << matcher.Match(f) << std::endl; + for (boost::filesystem::directory_iterator it(source); it != end; ++it) + { + if (is_regular_file(it->status())) + { + std::string extension = boost::filesystem::extension(it->path()); + Toolbox::ToLowerCase(extension); - if (matcher.Match(f)) - { - std::auto_ptr e(matcher.Extract(f)); + if (extension == ".wl") + { + std::string s; + Toolbox::ReadFile(s, it->path().string()); + ParsedDicomFile f(s); - Json::Value v; - e->ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_Default, 0); - std::cout << v; + if (matcher.Match(f)) + { + std::auto_ptr e(matcher.Extract(f)); + answers.Add(*e); + } + } + } } } + catch (boost::filesystem::filesystem_error&) + { + LOG(ERROR) << "Inexistent folder while scanning for worklists: " << source; + } - return true; + return true; // All the worklists have been returned } };