fw4spl
writer/ie/Document.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/Document.hpp"
8 
9 #include "fwGdcmIO/helper/DicomDataWriter.hxx"
10 #include "fwGdcmIO/helper/StructuredReport.hpp" // For graphviz dump
11 #include "fwGdcmIO/writer/tid/MeasurementReport.hpp"
12 
13 #include <fwData/PointList.hpp>
14 #include <fwData/String.hpp>
15 #include <fwData/Vector.hpp>
16 
17 #include <fwMedData/Series.hpp>
18 #include <fwMedData/types.hpp>
19 
20 #include <fwTools/dateAndTime.hpp>
21 
22 #include <boost/algorithm/string/split.hpp>
23 
24 #include <gdcmUIDGenerator.h>
25 
26 #include <sstream>
27 
28 namespace fwGdcmIO
29 {
30 namespace writer
31 {
32 namespace ie
33 {
34 
35 //------------------------------------------------------------------------------
36 
37 Document::Document(const SPTR(::gdcm::Writer)& writer,
38  const SPTR(::fwGdcmIO::container::DicomInstance)& instance,
39  const ::fwData::Image::csptr& image,
40  bool use3DSR,
41  const ::fwLog::Logger::sptr& logger,
42  ProgressCallback progress,
43  CancelRequestedCallback cancel) :
44  ::fwGdcmIO::writer::ie::InformationEntity< ::fwData::Image >(writer, instance, image, logger, progress, cancel),
45  m_use3DSR(use3DSR)
46 {
47 }
48 
49 //------------------------------------------------------------------------------
50 
52 {
53 }
54 
55 //------------------------------------------------------------------------------
56 
58 {
59  // Retrieve dataset
60  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
61 
62  ::boost::posix_time::ptime ptime = boost::posix_time::second_clock::local_time();
63 
64  // Instance Number - Type 1
65  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< int, 0x0020, 0x0013 >(0, dataset);
66 
67  // Content Date - Type 1 - FIXME: Keep series date ?
68  const std::string date = ::fwTools::getDate(ptime);
69  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0023 >(date, dataset);
70 
71  // Content Time - Type 1 - FIXME: Keep series time ?
72  const std::string time = ::fwTools::getTime(ptime);
73  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0033 >(time, dataset);
74 
75  // Performed Procedure Code Sequence (0040,A372) // Type 2 (FIXME: CID 7000 ?)
76  ::fwGdcmIO::helper::DicomDataWriter::createAndSetSequenceTagValue< 0x0040, 0xa372 >(dataset);
77 
78  // Completion flag - Type 1 - (FIXME: Set to COMPLETE ?)
79  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0040, 0xa491 >("PARTIAL", dataset);
80 
81  // Verification Flag - Type 1 - (FIXME: Set to VERIFIED ?)
82  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0040, 0xa493 >("UNVERIFIED", dataset);
83 
84  // Pertinent Other Evidence Sequence - Type 1C
86 
87 }
88 
89 //------------------------------------------------------------------------------
90 
92 {
93  // Retrieve dataset
94  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
95 
96  // Pertinent Other Evidence Sequence - Type 1C
97  ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sequence = new ::gdcm::SequenceOfItems();
98  sequence->SetLengthToUndefined();
99  ::fwGdcmIO::helper::DicomDataWriter::createAndSetSequenceTagValue< 0x0040, 0xa385 >(dataset);
100 
101  // Add new study to sequence
102  ::gdcm::Item studyItem;
103  studyItem.SetVLToUndefined();
104  ::gdcm::DataSet& studyItemDataset = studyItem.GetNestedDataSet();
105  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000D >(
106  m_instance->getStudyInstanceUID(), studyItemDataset);
107 
108  // Referenced Series Sequence - Type 1
109  ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > seriesSequence = new ::gdcm::SequenceOfItems();
110  seriesSequence->SetLengthToUndefined();
111  ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1115 >(seriesSequence, studyItemDataset);
112 
113  // Add new series to sequence
114  ::gdcm::Item seriesItem;
115  seriesItem.SetVLToUndefined();
116  ::gdcm::DataSet& seriesItemDataset = seriesItem.GetNestedDataSet();
117  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0020, 0x000E >(
118  m_instance->getSeriesInstanceUID(), seriesItemDataset);
119 
120  // Referenced SOP Sequence - Type 1
121  ::gdcm::SmartPointer< ::gdcm::SequenceOfItems > sopSequence = new ::gdcm::SequenceOfItems();
122  sopSequence->SetLengthToUndefined();
123  ::fwGdcmIO::helper::DicomDataWriter::setSequenceTagValue< 0x0008, 0x1199 >(sopSequence, seriesItemDataset);
124 
125  for(const std::string& instanceUID : m_instance->getSOPInstanceUIDContainer())
126  {
127  // Add new instance to sequence
128  ::gdcm::Item instanceItem;
129  instanceItem.SetVLToUndefined();
130  ::gdcm::DataSet& instanceItemDataset = instanceItem.GetNestedDataSet();
131 
132  // Referenced SOP Class UID - Type 1
133  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1150 >(
134  m_instance->getSOPClassUID(), instanceItemDataset);
135 
136  // Referenced SOP Instance UID - Type 1
137  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x1155 >(instanceUID, instanceItemDataset);
138 
139  sopSequence->AddItem(instanceItem);
140  }
141 
142  seriesSequence->AddItem(seriesItem);
143  sequence->AddItem(studyItem);
144 }
145 
146 //------------------------------------------------------------------------------
147 
149 {
150  // Retrieve dataset
151  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
152 
153  // Create SR Root node
156  root->write(dataset);
157 
158  // Dump SR
159  //::fwGdcmIO::helper::StructuredReport::dumpSR(root);
160 }
161 
162 //------------------------------------------------------------------------------
163 
165 {
166  // Retrieve dataset
167  ::gdcm::DataSet& dataset = m_writer->GetFile().GetDataSet();
168 
169  // SOP Class UID
170  std::string sopClassUID;
171  if(!m_use3DSR)
172  {
173  sopClassUID = ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::ComprehensiveSR);
174  }
175  else
176  {
177  // FIXME Remove hard coded string
178  // sopClassUID = ::gdcm::MediaStorage::GetMSString(::gdcm::MediaStorage::Comprehensive3DSR);
179  sopClassUID = "1.2.840.10008.5.1.4.1.1.88.34";
180  }
181  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0016 >(sopClassUID, dataset);
182 
183  // SOP Instance UID
184  ::gdcm::UIDGenerator uidGenerator;
185  std::string sopInstanceUID = uidGenerator.Generate();
186  ::fwGdcmIO::helper::DicomDataWriter::setTagValue< 0x0008, 0x0018 >(sopInstanceUID, dataset);
187 }
188 
189 //------------------------------------------------------------------------------
190 
191 } // namespace ie
192 } // namespace writer
193 } // namespace fwGdcmIO
FWGDCMIO_API Document(const std::shared_ptr< ::gdcm::Writer > &writer, const std::shared_ptr< ::fwGdcmIO::container::DicomInstance > &instance, const ::fwData::Image::csptr &image, bool use3DSR=false, const ::fwLog::Logger::sptr &logger=nullptr, ProgressCallback progress=nullptr, CancelRequestedCallback cancel=nullptr)
Constructor.
void writePertinentOtherEvidenceSequence()
Write Pertinent Other Evidence Sequence (0040,A385)
#define SPTR(_cls_)
InformationEntity base class used to write modules.
virtual FWGDCMIO_API std::shared_ptr< ::fwGdcmIO::container::sr::DicomSRNode > createRootNode(bool useSCoord3D=true)
Create Measurement Report template root node.
This class defines a DICOM SOP instance. It is useful during the whole writing process. This class allows to share data between module writers.
bool m_use3DSR
True if we must use 3DSR.
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
This class defines a node in a SR document.
Definition: DicomSRNode.hpp:27
std::shared_ptr< ::fwGdcmIO::container::DicomInstance > m_instance
DICOM Instance.
virtual FWGDCMIO_API void writeSRDocumentGeneralModule()
Write SR Document General Module tags.
Contains the representation of the data objects used in the framework.
virtual FWGDCMIO_API void writeSRDocumentContentModule()
Write SR Document Content Module tags.
std::shared_ptr< const ::fwData::Image > m_object
FW4SPL Object.
FWGDCMIO_API void writeSOPCommonModule()
Write SOP Common Module tags.
Measurement Report TID - This a root template.
virtual FWGDCMIO_API ~Document()
Destructor.