fw4spl
RelatedStudy.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwActivities/validator/RelatedStudy.hpp"
8 
9 #include "fwActivities/validator/registry/macros.hpp"
10 
11 #include <fwData/Vector.hpp>
12 
13 #include <fwMedData/Series.hpp>
14 #include <fwMedData/Study.hpp>
15 
16 #include <boost/algorithm/string.hpp>
17 
18 namespace fwActivities
19 {
20 namespace validator
21 {
22 
23 fwActivitiesValidatorRegisterMacro(
24  ::fwActivities::validator::RelatedStudy, "::fwActivities::validator::RelatedStudy");
25 
26 //-----------------------------------------------------------------------------
27 
29 {
30 }
31 
32 //-----------------------------------------------------------------------------
33 
35 {
36 }
37 
38 //-----------------------------------------------------------------------------
39 
41  const ::fwActivities::registry::ActivityInfo& activityInfo,
42  const ::fwData::Vector::csptr& currentSelection ) const
43 {
44  IValidator::ValidationType validation;
45 
46  if(currentSelection->size() > 1)
47  {
48  validation.first = true;
49  validation.second = "Selected series refers to the same study.";
50 
51  ::fwMedData::Series::sptr seriesRef = ::fwMedData::Series::dynamicCast((*currentSelection)[0]);
52  ::fwMedData::Study::sptr studyRef = seriesRef->getStudy();
53 
54  std::string instanceUIDRef = studyRef->getInstanceUID();
55  ::boost::algorithm::trim(instanceUIDRef);
56 
57  ::fwData::Vector::ContainerType::const_iterator it;
58  for(it = currentSelection->begin() + 1; it != currentSelection->end(); ++it)
59  {
60  ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(*it);
61  ::fwMedData::Study::sptr study = series->getStudy();
62 
63  std::string instanceUID = study->getInstanceUID();
64  ::boost::algorithm::trim(instanceUID);
65 
66  if(instanceUIDRef != instanceUID)
67  {
68  validation.first = false;
69  validation.second = "Selected series do not refer to the same study.";
70 
71  break;
72  }
73  }
74  }
75  else
76  {
77  validation.first = true;
78  validation.second = "Only one series provided to check study affiliation, assuming validation as ok.";
79  }
80 
81  return validation;
82 }
83 
84 //-----------------------------------------------------------------------------
85 
86 } // namespace validator
87 } // namespace fwActivities
std::pair< bool, std::string > ValidationType
Defines validation result of an activity. First element tells if the activity is validated or not by ...
Definition: IValidator.hpp:39
FWACTIVITIES_API RelatedStudy(::fwActivities::IValidator::Key key)
Constructor. Do nothing.
virtual FWACTIVITIES_API ~RelatedStudy()
Destructor. Do nothing.
Namespace containing activities data and builder.
Defines a validator which checks that given series refer to the same study.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWACTIVITIES_API IValidator::ValidationType validate(const ::fwActivities::registry::ActivityInfo &activityInfo, const std::shared_ptr< const ::fwData::Vector > &currentSelection) const override