fw4spl
io/fwPacsIO/src/fwPacsIO/helper/Series.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 "fwPacsIO/helper/Series.hpp"
8 #include "fwPacsIO/exceptions/TagMissing.hpp"
9 
10 #include <fwCore/spyLog.hpp>
11 #include <fwMedData/DicomSeries.hpp>
12 #include <fwMedData/Equipment.hpp>
13 #include <fwMedData/ImageSeries.hpp>
14 #include <fwMedData/ModelSeries.hpp>
15 #include <fwMedData/Patient.hpp>
16 #include <fwMedData/Study.hpp>
17 
18 #include <boost/foreach.hpp>
19 
20 namespace fwPacsIO
21 {
22 namespace helper
23 {
24 
25 void Series::releaseResponses(OFList< QRResponse* > responses)
26 {
27  while (!responses.empty())
28  {
29  delete responses.front();
30  responses.pop_front();
31  }
32 }
33 
34 // ----------------------------------------------------------------------------
35 
36 Series::DicomSeriesContainer Series::toFwMedData(OFList< QRResponse* > responses)
37 {
38  DicomSeriesContainer seriesContainer;
39 
40  OFIterator< QRResponse* > it;
41  OFCondition result;
42 
43  // Every while loop run will get all image for a specific study
44  for (it = responses.begin(); it != responses.end(); ++it)
45  {
46  // Be sure we are not in the last response which does not have a dataset
47  if ((*it)->m_dataset != NULL)
48  {
49  OFString data;
50 
51  // Create series
52  ::fwMedData::DicomSeries::sptr series = ::fwMedData::DicomSeries::New();
53  ::fwMedData::Patient::sptr patient = ::fwMedData::Patient::New();
54  ::fwMedData::Study::sptr study = ::fwMedData::Study::New();
55  ::fwMedData::Equipment::sptr equipment = ::fwMedData::Equipment::New();
56 
57  // Set informations to series
58  series->setPatient(patient);
59  series->setStudy(study);
60  series->setEquipment(equipment);
61 
62  // ==================================
63  // Series
64  // ==================================
65 
66  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_SeriesInstanceUID, data);
67  series->setInstanceUID(data.c_str());
68 
69  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_Modality, data);
70  series->setModality(data.c_str());
71 
72  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_SeriesDate, data);
73  series->setDate(data.c_str());
74 
75  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_SeriesTime, data);
76  series->setTime(data.c_str());
77 
78  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_SeriesDescription, data);
79  series->setDescription(data.c_str());
80 
81  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_PerformingPhysicianName, data);
82  ::fwMedData::DicomValuesType performingPhysiciansName;
83  performingPhysiciansName.push_back(data.c_str());
84  series->setPerformingPhysiciansName(performingPhysiciansName);
85 
86  // ==================================
87  // Patient
88  // ==================================
89  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_PatientName, data);
90  patient->setName(data.c_str());
91 
92  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_PatientID, data);
93  patient->setPatientId(data.c_str());
94 
95  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_PatientBirthDate, data);
96  patient->setBirthdate(data.c_str());
97 
98  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_PatientSex, data);
99  patient->setSex(data.c_str());
100 
101 
102  // ==================================
103  // Study
104  // ==================================
105  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_StudyInstanceUID, data);
106  study->setInstanceUID(data.c_str());
107 
108  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_StudyDate, data);
109  study->setDate(data.c_str());
110 
111  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_StudyTime, data);
112  study->setTime(data.c_str());
113 
114  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_ReferringPhysicianName, data);
115  study->setReferringPhysicianName(data.c_str());
116 
117  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_StudyDescription, data);
118  study->setDescription(data.c_str());
119 
120  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_PatientAge, data);
121  study->setPatientAge(data.c_str());
122 
123  // ==================================
124  // Equipment
125  // ==================================
126  (*it)->m_dataset->findAndGetOFStringArray(DCM_InstitutionName, data);
127  equipment->setInstitutionName(data.c_str());
128 
129 
130 
131  // ==================================
132  // Number of instances
133  // ==================================
134  long int nbinstances;
135  (*it)->m_dataset->findAndGetLongInt(DCM_NumberOfSeriesRelatedInstances, nbinstances);
136  series->setNumberOfInstances(nbinstances);
137 
138  // Add series to container
139  seriesContainer.push_back(series);
140 
141  }
142 
143  }
144 
145  return seriesContainer;
146 }
147 
148 // ----------------------------------------------------------------------------
149 
150 Series::InstanceUIDContainer Series::toSeriesInstanceUIDContainer(DicomSeriesContainer series)
151 {
152  InstanceUIDContainer result;
153 
154  for(const ::fwMedData::Series::sptr& s: series )
155  {
156  result.push_back(s->getInstanceUID());
157  }
158 
159  return result;
160 }
161 
162 // ----------------------------------------------------------------------------
163 
164 Series::InstanceUIDContainer Series::toSeriesInstanceUIDContainer(OFList< QRResponse* > responses)
165 {
166  InstanceUIDContainer instanceUIDContainer;
167 
168  OFIterator< QRResponse* > it;
169  DcmDataset dataset;
170  OFCondition result;
171  // Every while loop run will get all image for a specific study
172  for (it = responses.begin(); it != responses.end(); ++it)
173  {
174  // Be sure we are not in the last response which does not have a dataset
175  if ((*it)->m_dataset != NULL)
176  {
177  OFString seriesInstanceUID;
178  result = (*it)->m_dataset->findAndGetOFStringArray(DCM_SeriesInstanceUID, seriesInstanceUID);
179  // Only try to get study if we actually have study instance uid, otherwise skip it
180  if (result.good())
181  {
182  instanceUIDContainer.push_back(seriesInstanceUID.c_str());
183  }
184  else
185  {
186  const std::string msg = "There is no \"SeriersInstanceUID\" tag in the selected series :"
187  + std::string(result.text());
188  throw ::fwPacsIO::exceptions::TagMissing(msg);
189  }
190  }
191  }
192 
193 
194  return instanceUIDContainer;
195 }
196 
197 } //helper
198 } //fwPacsIO
static FWPACSIO_API DicomSeriesContainer toFwMedData(OFList< QRResponse * > responses)
Convert DCMTK series to fwMedData::DicomSeries.
fwPacsIO contains classes used to communicate with a PACS.
static FWPACSIO_API InstanceUIDContainer toSeriesInstanceUIDContainer(OFList< QRResponse * > responses)
Convert DCMTK series to instance uid vector.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...
static FWPACSIO_API void releaseResponses(OFList< QRResponse * > responses)
Release the responses.