7 #include "fwMDSemanticPatch/V1/V2/fwData/Composite.hpp" 9 #include <fwAtoms/Blob.hpp> 10 #include <fwAtoms/Boolean.hpp> 11 #include <fwAtoms/Map.hpp> 12 #include <fwAtoms/Numeric.hpp> 13 #include <fwAtoms/Object.hpp> 14 #include <fwAtoms/Object.hxx> 15 #include <fwAtoms/Sequence.hpp> 16 #include <fwAtoms/String.hpp> 18 #include <fwAtomsPatch/helper/functions.hpp> 19 #include <fwAtomsPatch/StructuralCreatorDB.hpp> 21 #include <fwMedData/ActivitySeries.hpp> 23 #include <fwMemory/BufferObject.hpp> 25 #include <fwTools/UUID.hpp> 27 #include <boost/algorithm/string.hpp> 41 typedef std::map< ::fwAtoms::Object::sptr, ::fwAtoms::Object::sptr > Image2ModelType;
67 const ::fwAtoms::Map::sptr& oldCompositeMap,
68 const ::fwAtoms::Sequence::sptr& series,
69 const Image2ModelType& image2Model,
70 ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
72 ::fwAtoms::Object::sptr oldPlanningDB = ::fwAtoms::Object::dynamicCast( (*oldCompositeMap)[
"planningDB"] );
73 ::fwAtoms::Map::sptr oldPlannings = oldPlanningDB->getAttribute<
::fwAtoms::Map >(
"values");
77 ::fwAtoms::Map::sptr oldPlanning
78 = ::fwAtoms::Object::dynamicCast(oldPlanningAtom.second)->getAttribute<
::fwAtoms::Map >(
"values");
80 SLM_ASSERT(
"Didn't find 'acquisition' in planning",
81 oldPlanning->getValue().find(
"acquisition") != oldPlanning->getValue().end());
82 ::fwAtoms::Base::sptr acquisition = oldPlanning->getValue().find(
"acquisition")->second;
83 ::fwAtoms::Object::sptr acqObj = ::fwAtoms::Object::dynamicCast(acquisition);
84 SLM_ASSERT(
"Failed to cast acquisition to object", acqObj);
86 Image2ModelType::const_iterator it = image2Model.find(newVersions[acqObj]);
87 SLM_ASSERT(
"Didn't find image series related to acquisition", it != image2Model.end());
88 ::fwAtoms::Object::sptr imageSeries = it->first;
90 ::fwAtoms::Object::sptr resectionDB
91 = ::fwAtoms::Object::dynamicCast(oldPlanning->getValue().find(
"resectionDB")->second);
94 ::fwAtoms::Object::sptr expert
95 = ::fwAtoms::Object::dynamicCast(oldPlanning->getValue().find(
"expert")->second);
97 ::fwAtoms::Sequence::sptr experts = ::fwAtoms::Sequence::New();
98 experts->push_back( ::fwAtoms::String::dynamicCast(expert->getAttribute< ::
fwAtoms::String >(
"value")));
101 ::fwAtoms::Object::sptr information
102 = ::fwAtoms::Object::dynamicCast(oldPlanning->getValue().find(
"information")->second);
103 ::fwAtoms::String::sptr informationStr
104 = ::fwAtoms::String::dynamicCast(information->getAttribute< ::
fwAtoms::String >(
"value"));
107 ::fwAtoms::Object::sptr dateTimeObj
108 = ::fwAtoms::Object::dynamicCast(oldPlanning->getValue().find(
"startDateTime")->second);
109 ::fwAtoms::String::sptr dateTimeStr
110 = ::fwAtoms::String::dynamicCast(dateTimeObj->getAttribute< ::
fwAtoms::String >(
"value"));
115 std::string dateTimeStd = dateTimeStr->getString();
116 std::vector< std::string > strs;
117 ::boost::split(strs, dateTimeStd, ::boost::is_any_of(
" "));
121 date->setValue(strs[0]);
122 time->setValue(strs[1]);
126 ::fwAtoms::Object::sptr newActivitySeries = creators->create(
"::fwMedData::ActivitySeries",
"1");
128 ::fwAtoms::Object::sptr imgComposite = ::fwAtoms::Object::New();
129 ::fwAtomsPatch::helper::setClassname(imgComposite,
"::fwData::Composite");
130 ::fwAtomsPatch::helper::setVersion(imgComposite,
"1");
131 ::fwAtomsPatch::helper::generateID(imgComposite);
132 ::fwAtomsPatch::helper::cleanFields(imgComposite);
135 ::fwAtoms::Map::sptr compositeMap = ::fwAtoms::Map::New();
136 compositeMap->insert(
"OptionalInputImageKey", imageSeries->getAttribute< ::
fwAtoms::Object >(
"image"));
137 imgCompositeHelper.
addAttribute(
"values", compositeMap);
139 ::fwAtoms::Map::sptr activityDataMap = ::fwAtoms::Map::New();
140 activityDataMap->insert(
"resectionDB", resectionDB);
141 activityDataMap->insert(
"modelSeries", it->second);
142 activityDataMap->insert(
"imageSeries", imgComposite);
144 ::fwAtoms::Object::sptr mapObj = ::fwAtoms::Object::New();
145 ::fwAtomsPatch::helper::setClassname(mapObj,
"::fwData::Composite");
146 ::fwAtomsPatch::helper::setVersion(mapObj,
"1");
147 ::fwAtomsPatch::helper::generateID(mapObj);
148 ::fwAtomsPatch::helper::cleanFields(mapObj);
167 series->push_back(newActivitySeries);
174 void processProcessing(
175 const ::fwAtoms::Map::sptr& oldCompositeMap,
176 const ::fwAtoms::Sequence::sptr& series,
177 const Image2ModelType& image2Model,
178 ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
180 ::fwAtoms::Object::sptr oldProcessingDB = ::fwAtoms::Object::dynamicCast( (*oldCompositeMap)[
"processingDB"] );
182 ::fwAtoms::Map::sptr oldProcessings = oldProcessingDB->getAttribute<
::fwAtoms::Map >(
"values");
186 ::fwAtoms::Map::sptr oldProcessing
187 = ::fwAtoms::Object::dynamicCast(oldProcessingAtom.second)->getAttribute<
::fwAtoms::Map >(
"values");
190 ::fwAtoms::Object::sptr expert
191 = ::fwAtoms::Object::dynamicCast(oldProcessing->getValue().find(
"expert")->second);
193 ::fwAtoms::Sequence::sptr experts = ::fwAtoms::Sequence::New();
194 experts->push_back( ::fwAtoms::String::dynamicCast(expert->getAttribute< ::
fwAtoms::String >(
"value")));
197 ::fwAtoms::Object::sptr information
198 = ::fwAtoms::Object::dynamicCast(oldProcessing->getValue().find(
"information")->second);
199 ::fwAtoms::String::sptr informationStr
200 = ::fwAtoms::String::dynamicCast(information->getAttribute< ::
fwAtoms::String >(
"value"));
203 ::fwAtoms::Object::sptr dateTimeObj
204 = ::fwAtoms::Object::dynamicCast(oldProcessing->getValue().find(
"startDateTime")->second);
205 ::fwAtoms::String::sptr dateTimeStr
206 = ::fwAtoms::String::dynamicCast(dateTimeObj->getAttribute< ::
fwAtoms::String >(
"value"));
211 std::string dateTimeStd = dateTimeStr->getString();
212 std::vector< std::string > strs;
213 ::boost::split(strs, dateTimeStd, ::boost::is_any_of(
" "));
217 date->setValue(strs[0]);
218 time->setValue(strs[1]);
222 ::fwAtoms::Object::sptr newActivitySeries = creators->create(
"::fwMedData::ActivitySeries",
"1");
224 ::fwAtoms::Map::sptr activityDataMap = ::fwAtoms::Map::New();
225 activityDataMap->insert(
"processing", oldProcessingAtom.second);
227 ::fwAtoms::Object::sptr mapObj = ::fwAtoms::Object::New();
228 ::fwAtomsPatch::helper::setClassname(mapObj,
"::fwData::Composite");
229 ::fwAtomsPatch::helper::setVersion(mapObj,
"1");
230 ::fwAtomsPatch::helper::generateID(mapObj);
231 ::fwAtomsPatch::helper::cleanFields(mapObj);
248 ::fwAtoms::Base::sptr acquisitionSelection = oldProcessing->getValue().find(
"acquisitionSelection")->second;
249 ::fwAtoms::Object::sptr acqSelectionObj = ::fwAtoms::Object::dynamicCast(acquisitionSelection);
250 SLM_ASSERT(
"Failed to cast acquisition composite to object", acqSelectionObj);
252 ::fwAtoms::Map::sptr acqSelectionMap = acqSelectionObj->getAttribute<
::fwAtoms::Map >(
"values");
255 if (iter != acqSelectionMap->getValue().end() )
258 ::fwAtoms::Base::sptr acquisition = iter->second;
259 ::fwAtoms::Object::sptr acqObj = ::fwAtoms::Object::dynamicCast(acquisition);
260 SLM_ASSERT(
"Failed to cast acquisition to object", acqObj);
262 Image2ModelType::const_iterator it = image2Model.find(newVersions[acqObj]);
263 if(it != image2Model.end())
265 ::fwAtoms::Object::sptr imageSeries = it->first;
273 series->push_back(newActivitySeries);
281 const ::fwAtoms::Object::sptr& previous,
282 const ::fwAtoms::Object::sptr& current,
283 ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
285 Image2ModelType image2Model;
287 ISemanticPatch::apply(previous, current, newVersions);
293 if ( previous->getMetaInfo(
"compositeType") ==
"MedicalWorkspace" )
296 ::fwAtomsPatch::helper::setClassname( current,
"::fwMedData::SeriesDB" );
297 ::fwAtomsPatch::helper::setVersion( current,
"1" );
300 ::fwAtomsPatch::helper::cleanFields( current );
302 ::fwAtoms::Sequence::sptr series = ::fwAtoms::Sequence::New();
306 ::fwAtoms::Map::sptr oldCompositeMap = previous->getAttribute<
::fwAtoms::Map >(
"values");
307 ::fwAtoms::Object::sptr oldPatientDB =
308 ::fwAtoms::Object::dynamicCast( (*oldCompositeMap)[
"patientDB"] );
309 ::fwAtoms::Sequence::sptr oldPatients = oldPatientDB->getAttribute<
::fwAtoms::Sequence >(
"patients");
313 for( ::fwAtoms::Base::sptr oldPatientAtom : oldPatients->getValue() )
315 ::fwAtoms::Object::sptr oldPatient = ::fwAtoms::Object::dynamicCast( oldPatientAtom );
316 ::fwAtoms::Object::sptr newPatient = newVersions[oldPatient];
318 ::fwAtoms::Sequence::sptr oldStudies = oldPatient->getAttribute<
::fwAtoms::Sequence >(
"studies");
320 for( ::fwAtoms::Base::sptr oldStudyAtom : oldStudies->getValue() )
322 ::fwAtoms::Object::sptr oldStudy = ::fwAtoms::Object::dynamicCast( oldStudyAtom );
323 ::fwAtoms::Object::sptr newStudy = newVersions[oldStudy];
325 ::fwAtoms::Sequence::sptr oldAcquisitions =
328 for( ::fwAtoms::Base::sptr oldAcqAtom : oldAcquisitions->getValue() )
330 ::fwAtoms::Object::sptr oldAcq = ::fwAtoms::Object::dynamicCast( oldAcqAtom );
333 ::fwAtoms::Object::sptr newImgSeries = newVersions[oldAcq];
335 ::fwAtoms::Object::sptr clonedPatient = ::fwAtoms::Object::dynamicCast(newPatient->clone());
336 ::fwAtomsPatch::helper::changeUID(clonedPatient);
339 ::fwAtoms::Object::sptr clonedStudy = ::fwAtoms::Object::dynamicCast(newStudy->clone());
340 ::fwAtomsPatch::helper::changeUID(clonedStudy);
343 imgSeriesHelper.
replaceAttribute(
"modality", oldStudy->getAttribute(
"modality")->clone() );
345 ::fwAtoms::String::sptr institution;
347 ::fwAtoms::String::dynamicCast( oldStudy->getAttribute(
"hospital")->clone() );
348 ::fwAtoms::Object::sptr equipment = newImgSeries->getAttribute<
::fwAtoms::Object >(
"equipment");
350 equipmentHelper.replaceAttribute(
"institution_name", institution);
353 ::fwAtoms::String::sptr studyDate = newStudy->getAttribute<
::fwAtoms::String >(
"date");
356 if ( studyDate->getValue().empty() )
358 studyHelper.replaceAttribute(
"date", newImgSeries->getAttribute(
"date")->clone());
361 ::fwAtoms::String::sptr studyTime = newStudy->getAttribute<
::fwAtoms::String >(
"time");
362 if ( studyTime->getValue().empty() )
364 studyHelper.replaceAttribute(
"time", newImgSeries->getAttribute(
"time")->clone());
367 series->push_back( newImgSeries );
370 ::fwAtoms::Sequence::sptr oldReconstructions =
373 if ( oldReconstructions->size() > 0 )
376 ::fwAtoms::Object::sptr newModelSeries =
377 creators->create(
"::fwMedData::ModelSeries",
"1");
380 ::fwAtoms::Object::sptr msPatient = ::fwAtoms::Object::dynamicCast(clonedPatient->clone());
381 ::fwAtomsPatch::helper::changeUID(msPatient);
384 ::fwAtoms::Object::sptr msStudy = ::fwAtoms::Object::dynamicCast(clonedStudy->clone());
385 ::fwAtomsPatch::helper::changeUID(msStudy);
388 ::fwAtoms::Object::sptr msEquipment = ::fwAtoms::Object::dynamicCast(equipment->clone());
389 ::fwAtomsPatch::helper::changeUID(msEquipment);
395 msHelper.
replaceAttribute(
"date", newImgSeries->getAttribute(
"date")->clone() );
396 msHelper.
replaceAttribute(
"time", newImgSeries->getAttribute(
"time")->clone() );
398 newImgSeries->getAttribute(
"performing_physicians_name")->clone() );
399 msHelper.
replaceAttribute(
"description", newImgSeries->getAttribute(
"description")->clone() );
401 ::fwAtoms::Sequence::sptr newReconstructions =
403 for( ::fwAtoms::Base::sptr oldRecAtom : oldReconstructions->getValue() )
405 ::fwAtoms::Object::sptr oldRec = ::fwAtoms::Object::dynamicCast( oldRecAtom );
406 newReconstructions->push_back(newVersions[oldRec]);
409 image2Model[newImgSeries] = newModelSeries;
410 series->push_back( newModelSeries );
416 processPlanning(oldCompositeMap, series, image2Model, newVersions);
417 processProcessing(oldCompositeMap, series, image2Model, newVersions);
MapType::const_iterator const_iterator
Patch the composite describing a 'Medical workspace' from version 'V1' to 'V2' within 'MedicalData' c...
virtual FWMDSEMANTICPATCH_API void apply(const ::fwAtoms::Object::sptr &previous, const ::fwAtoms::Object::sptr ¤t,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies patch.
Contains the semantic patches within the context "MedicalData".
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
const MapType & getValue() const
returns atom's map
FWMDSEMANTICPATCH_API ~Composite()
Destructor.
Contains base functionalities used to transform objects from a version to another.
Class represented a fwData::Object.
std::string m_originClassname
Origin classname of the object.
virtual FWATOMSPATCH_API void addContext(const std::string &context, const std::string &originVersion, const std::string &targetVersion)
Add a context where the patch can be applied.
FWATOMSPATCH_API void replaceAttribute(const std::string &name,::fwAtoms::Base::sptr newValue, conditions::Abstract::sptr condition=conditions::Abstract::New())
Replaces an attribute.
Map is a container for mapping representation.
std::string m_originVersion
Origin version of the object.
FWATOMSPATCH_API ISemanticPatch()
Constructor.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWMDSEMANTICPATCH_API Composite()
Constructor.
FWATOMSPATCH_API void addAttribute(const std::string &name,::fwAtoms::Base::sptr value, conditions::Abstract::sptr condition=conditions::Abstract::New())
Adds a new attribute in the current object.
static StructuralCreatorDB::sptr getDefault()
Returns the default instance of StructuralCreatorDB.
Contains the representation of the data objects used in the framework.
MapType::value_type value_type
Class represented a String.
Sequence represented a list of meta object.