fw4spl
io/fwGdcmIO/src/fwGdcmIO/writer/ie/Series.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 "fwGdcmIO/writer/ie/Series.hpp"
8 
9 #include "fwGdcmIO/helper/DicomDataWriter.hxx"
10 
11 #include <fwMedData/Series.hpp>
12 #include <fwMedData/types.hpp>
13 
14 #include <boost/date_time/posix_time/posix_time.hpp>
15 
16 #include <gdcmUIDGenerator.h>
17 
18 #include <sstream>
19 
20 namespace fwGdcmIO
21 {
22 namespace writer
23 {
24 namespace ie
25 {
26 
27 //------------------------------------------------------------------------------
28 
29 Series::Series(const SPTR(::gdcm::Writer)& writer,
30  const SPTR(::fwGdcmIO::container::DicomInstance)& instance,
31  const ::fwMedData::Series::csptr& series,
32  const ::fwLog::Logger::sptr& logger,
33  ProgressCallback progress,
34  CancelRequestedCallback cancel) :
35  ::fwGdcmIO::writer::ie::InformationEntity< ::fwMedData::Series >(writer, instance, series,
36  logger, progress, cancel)
37 {
38 }
39 
40 //------------------------------------------------------------------------------
41 
43 {
44 }
45 
46 //------------------------------------------------------------------------------
47 
49 {
50  // Retrieve dataset
51  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
52 
53  // Serie's instance UID - Type 1
54  // As the data may have been updated between two export, we regenerate an UID
55  ::gdcm::UIDGenerator uidGenerator;
56  const std::string instanceUID = uidGenerator.Generate();
57 
58  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000e >(instanceUID, dataset);
59 
60  // Series's modality - Type 1
61  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0060 >(m_object->getModality(), dataset);
62 
63  ::boost::posix_time::ptime ptime = ::boost::posix_time::second_clock::local_time();
64 
65  const std::string fulldate = ::boost::posix_time::to_iso_string(ptime);
66 
67  // Split iso time in YYYYMMDDTHHMMSS
68  ::boost::char_separator<char> sep("T");
69  ::boost::tokenizer< ::boost::char_separator<char> > tokens(fulldate, sep);
70 
71  ::boost::tokenizer< ::boost::char_separator<char> >::iterator tok_iter = tokens.begin();
72  const std::string date = *tok_iter;
73  tok_iter++;
74  const std::string time = *tok_iter;
75 
76  // Serie's date - Type 3
77  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0021 >(date, dataset);
78 
79  // Serie's time - Type 3
80  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0031 >(time, dataset);
81 
82  // Serie's description
83  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x103e >(m_object->getDescription(), dataset);
84 
85  // Serie's number - Type 2
86  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< int, 0x0020, 0x0011 >(0, dataset);
87 
88  // Performing physicians name - Type 3
89  ::fwMedData::DicomValuesType performingPhysicians = m_object->getPerformingPhysiciansName();
90  if (!performingPhysicians.empty())
91  {
92  ::gdcm::String< >* physicians = new ::gdcm::String< >[performingPhysicians.size()];
93  unsigned int count = 0;
94  for(std::string physician: performingPhysicians)
95  {
96  physicians[count++] = ::gdcm::String<>(physician);
97  }
98  ::fwGdcmIO::helper::DicomDataWriter::setTagValues< ::gdcm::String< >, 0x0008, 0x1050 >(physicians, count,
99  dataset);
100  }
101 
102  // Laterality - Type 2C - FIXME: Fake Value - Should be absent for the abdomen or chest
103  if(m_instance->getSOPClassUID() !=
104  ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::SurfaceSegmentationStorage))
105  {
106  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x0060 >("R", dataset);
107  }
108 
109  // Patient Position - Type 2C
110  ::gdcm::Attribute< 0x0018, 0x5100 > patientPositionAttribute;
111  dataset.Insert(patientPositionAttribute.GetAsDataElement());
112 }
113 
114 //------------------------------------------------------------------------------
115 
117 {
118  // Retrieve dataset
119  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
120 
121  // Series's modality - Type 1
122  dataset.Remove(::gdcm::Tag(0x0008, 0x0060));
123  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0060 >("SEG", dataset);
124 }
125 
126 //------------------------------------------------------------------------------
127 
129 {
130  // Retrieve dataset
131  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
132 
133  // Create generator
134  ::gdcm::UIDGenerator uidGenerator;
135 
136  // Series's modality - Type 1
137  dataset.Remove(::gdcm::Tag(0x0008, 0x0060));
138  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0060 >("SR", dataset);
139 
140  // Serie's instance UID - Type 1
141  dataset.Remove(::gdcm::Tag(0x0020, 0x000e));
142  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000e >(uidGenerator.Generate(), dataset);
143 
144  // Serie's number - Type 1
145  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< int, 0x0020, 0x0011 >(0, dataset);
146 
147  // Referenced Performed Procedure Step Sequence - Type 2
148  ::fwGdcmIO::helper::DicomDataWriter::createAndSetSequenceTagValue< 0x0008, 0x1111 >(dataset);
149 }
150 
151 //------------------------------------------------------------------------------
152 
154 {
155  // Retrieve dataset
156  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
157 
158  // Create uid generator
159  ::gdcm::UIDGenerator uidGenerator;
160 
161  // Serie's instance UID - Type 1
162  dataset.Remove(::gdcm::Tag(0x0020, 0x000e));
163  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000e >(uidGenerator.Generate(), dataset);
164 
165  // Series's modality - Type 1
166  dataset.Remove(::gdcm::Tag(0x0008, 0x0060));
167  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0060 >("FID", dataset);
168 
169 }
170 
171 //------------------------------------------------------------------------------
172 
173 } // namespace ie
174 } // namespace writer
175 } // namespace fwGdcmIO
#define SPTR(_cls_)
Namespace containing medical data.
InformationEntity base class used to write modules.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
virtual FWGDCMIO_API void writeGeneralSeriesModule()
Write General Series Module tags.
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_instance
DICOM Instance.
virtual FWGDCMIO_API void writeSegmentationSeriesModule()
Write Segmentation Series Module tags.
virtual FWGDCMIO_API void writeSpatialFiducialsSeriesModule()
Write Spatial Fiducials Series Module tags.
virtual FWGDCMIO_API void writeSRDocumentSeriesModule()
Write SR Document Series Module tags.
FWGDCMIO_API Series(const std::shared_ptr< ::gdcm::Writer > &writer, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwMedData::Series::csptr &series, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
std::shared_ptr< const ::fwMedData::Series > m_object
FW4SPL Object.