fw4spl
V1ToFwMedDataPatientV1.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 <string>
8 #include <sstream>
9 
10 #include <boost/date_time/posix_time/posix_time.hpp>
11 
12 #include <fwTools/dateAndTime.hpp>
13 
14 #include <fwAtoms/String.hpp>
15 
16 #include "fwStructuralPatch/fwData/Patient/V1ToFwMedDataPatientV1.hpp"
17 
18 namespace fwStructuralPatch
19 {
20 
21 namespace fwData
22 {
23 
24 namespace Patient
25 {
26 
28 {
29  m_originClassname = "::fwData::Patient";
30  m_targetClassname = "::fwMedData::Patient";
31  m_originVersion = "1";
32  m_targetVersion = "1";
33 }
34 
35 // ----------------------------------------------------------------------------
36 
38 {
39 }
40 
41 // ----------------------------------------------------------------------------
42 
45 {
46 }
47 
48 // ----------------------------------------------------------------------------
49 
50 void V1ToFwMedDataPatientV1::apply(const ::fwAtoms::Object::sptr& previous,
51  const ::fwAtoms::Object::sptr& current,
52  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
53 {
54  IStructuralPatch::apply(previous, current, newVersions);
55 
56  // Update object version
57  this->updateVersion(current);
58 
59  // Create helper
60  ::fwAtomsPatch::helper::Object helper(current);
61 
62  helper.removeAttribute("firstname");
63  helper.removeAttribute("db_id");
64  helper.removeAttribute("studies");
65 
66  helper.renameAttribute("id_dicom", "patient_id");
67  helper.renameAttribute("birthdate", "birth_date");
68  helper.renameAttribute("is_male", "sex");
69 
70  // Update Name
71  std::string nameSeperation = "^";
72  if( previous->getAttribute("name")->getString().empty() ||
73  previous->getAttribute("firstname")->getString().empty() )
74  {
75  nameSeperation = "";
76  }
77 
78  std::string newName = previous->getAttribute("name")->getString()
79  + nameSeperation
80  + previous->getAttribute("firstname")->getString();
81  helper.replaceAttribute( "name", ::fwAtoms::String::New(newName) );
82 
83  // Update Birthdate
84  ::boost::posix_time::ptime bithdate =
85  ::boost::posix_time::time_from_string(previous->getAttribute("birthdate")->getString());
86  helper.replaceAttribute("birth_date", ::fwAtoms::String::New(::fwTools::getDate(bithdate)));
87 
88  // Update Sex
89  helper.replaceAttribute("sex", ::fwAtoms::String::New(
90  !(previous->getAttribute("is_male")->getString().compare("true")) ? "M" : "F"));
91 }
92 
93 } // namespace Patient
94 
95 } // namespace fwData
96 
97 } // namespace fwStructuralPatch
98 
This class contains helper to generate Medical Data (SeriesDB, ImageSeries, ...). ...
virtual FWSTRUCTURALPATCH_API void apply(const ::fwAtoms::Object::sptr &previous, const ::fwAtoms::Object::sptr &current,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies patch.
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
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
FWATOMSPATCH_API void replaceAttribute(const std::string &name,::fwAtoms::Base::sptr newValue, conditions::Abstract::sptr condition=conditions::Abstract::New())
Replaces an attribute.
std::string m_originVersion
Origin version of the object.
Definition: IPatch.hpp:67
std::string m_targetVersion
Target version.
Contains the representation of the data objects used in the framework.
FWTOOLS_API std::string getDate(const ::boost::posix_time::ptime &dateAndTime)
Convert a boost time to a string date.
Transforms a ::fwData::Patient to a fwMedData::Patient.