fw4spl
V1ToFwMedDataImageSeriesV1.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 <iostream>
8 #include <sstream>
9 
10 #include <boost/date_time/posix_time/posix_time.hpp>
11 
12 #include <fwTools/dateAndTime.hpp>
13 
14 #include <fwAtoms/Numeric.hpp>
15 #include <fwAtoms/String.hpp>
16 #include <fwAtoms/Sequence.hpp>
17 #include <fwAtomsPatch/StructuralCreatorDB.hpp>
18 #include <fwAtomsPatch/helper/Object.hpp>
19 #include <fwAtomsPatch/infos/Logger.hpp>
20 
21 #include "fwStructuralPatch/fwData/Acquisition/V1ToFwMedDataImageSeriesV1.hpp"
22 
23 namespace fwStructuralPatch
24 {
25 
26 namespace fwData
27 {
28 
29 namespace Acquisition
30 {
31 
33 {
34  m_originClassname = "::fwData::Acquisition";
35  m_targetClassname = "::fwMedData::ImageSeries";
36  m_originVersion = "1";
37  m_targetVersion = "1";
38 
39 }
40 
41 // ----------------------------------------------------------------------------
42 
44 {
45 }
46 
47 // ----------------------------------------------------------------------------
48 
50  IStructuralPatch(cpy)
51 {
52 }
53 
54 // ----------------------------------------------------------------------------
55 
56 void V1ToFwMedDataImageSeriesV1::apply(const ::fwAtoms::Object::sptr& previous,
57  const ::fwAtoms::Object::sptr& current,
58  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
59 {
60  IStructuralPatch::apply(previous, current, newVersions);
61 
62  //Update object version
63  this->updateVersion(current);
64 
65  //Create helper
66  ::fwAtomsPatch::helper::Object helper(current);
67 
68  helper.removeAttribute("bits_per_pixel");
69  helper.removeAttribute("slice_thickness");
70  helper.removeAttribute("axe");
71  helper.removeAttribute("unsigned_flag");
72  helper.removeAttribute("acquisition_index");
73  helper.removeAttribute("image_type");
74  helper.removeAttribute("image_format");
75  helper.removeAttribute("is_main");
76  helper.removeAttribute("is_normal_dir");
77  helper.removeAttribute("db_id");
78  helper.removeAttribute("labo_id");
79  helper.removeAttribute("net_id");
80  helper.removeAttribute("date_send_to_labo");
81  helper.removeAttribute("date_receive_from_labo");
82  helper.removeAttribute("date_send_to_dbt");
83  helper.removeAttribute("date_disponibility");
84  helper.removeAttribute("patient_size");
85  helper.removeAttribute("patient_weight");
86  helper.removeAttribute("radiations");
87  helper.removeAttribute("medical_printer");
88  helper.removeAttribute("medical_printer_corp");
89  helper.removeAttribute("patient_position");
90  helper.removeAttribute("dicom_file_list");
91  helper.removeAttribute("path_to_files");
92  helper.removeAttribute("struct_anat");
93  helper.removeAttribute("creation_date");
94  helper.removeAttribute("reconstructions");
95 
96  helper.renameAttribute("uid", "instance_uid");
97 
98  helper.addAttribute("modality", ::fwAtoms::String::New(""));
99 
100  ::fwAtomsPatch::StructuralCreatorDB::sptr creators = ::fwAtomsPatch::StructuralCreatorDB::getDefault();
101 
102  // Create Patient
103  helper.addAttribute("patient", creators->create( "::fwMedData::Patient", "1") );
104 
105  // Create Equipment
106  helper.addAttribute("equipment", creators->create( "::fwMedData::Equipment", "1") );
107 
108  // Create Study
109  helper.addAttribute("study", creators->create( "::fwMedData::Study", "1") );
110 
111  // Create performing_physicians_name
112  helper.addAttribute("performing_physicians_name", ::fwAtoms::Sequence::New());
113 
114  //===========================================
115  // Update time format
116  //===========================================
117 
118  std::string creationDate = previous->getAttribute("creation_date")->getString();
119 
120  // Date and time
121  ::boost::posix_time::ptime pdate =
122  ::boost::posix_time::time_from_string(creationDate);
123  const std::string date = ::fwTools::getDate(pdate);
124  const std::string time = ::fwTools::getTime(pdate);
125 
126  helper.addAttribute("date", ::fwAtoms::String::New(date));
127  helper.addAttribute("time", ::fwAtoms::String::New(time));
128 }
129 
130 } // namespace Acquisition
131 
132 } // namespace fwData
133 
134 } // namespace fwStructuralPatch
135 
136 
Transforms an acquisition in version &#39;1&#39; to an image series in version &#39;1&#39;.
FWATOMSPATCH_API void updateVersion(std::shared_ptr< ::fwAtoms::Object > current)
Updates the version of the patched object.
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
FWATOMSPATCH_API void renameAttribute(const std::string &name, const std::string &newName, conditions::Abstract::sptr condition=conditions::Abstract::New())
Renames an attribute.
FWATOMSPATCH_API void removeAttribute(const std::string &name, conditions::Abstract::sptr condition=conditions::Abstract::New())
Removes an attribute.
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
virtual FWSTRUCTURALPATCH_API void apply(const ::fwAtoms::Object::sptr &previous, const ::fwAtoms::Object::sptr &current,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies patch.
std::string m_targetClassname
Target type.
FWATOMSPATCH_API IStructuralPatch()
Constructor.
std::string m_originClassname
Origin classname of the object.
Definition: IPatch.hpp:64
Contains creators and structural patches.
Definition: Landmarks1.hpp:13
std::string m_originVersion
Origin version of the object.
Definition: IPatch.hpp:67
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.
std::string m_targetVersion
Target version.
static StructuralCreatorDB::sptr getDefault()
Returns the default instance of StructuralCreatorDB.
Contains the representation of the data objects used in the framework.