]> Creatis software - gdcm.git/blob - src/gdcmDicomDirStudy.cxx
Fix mistypings
[gdcm.git] / src / gdcmDicomDirStudy.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/10/08 15:20:17 $
7   Version:   $Revision: 1.46 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmDicomDirStudy.h"
20 #include "gdcmDicomDirElement.h"
21 #include "gdcmGlobal.h"
22 #include "gdcmDicomDirSerie.h"
23 #include "gdcmDicomDirVisit.h"
24 #include "gdcmDebug.h"
25
26 namespace GDCM_NAME_SPACE 
27 {
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief  Constructor 
32  * \note End user must use : DicomDirPatient::NewStudy()
33  */
34 DicomDirStudy::DicomDirStudy(bool empty)
35               :DicomDirObject()
36 {
37    if ( !empty )
38    {
39       ListDicomDirStudyElem const &elemList = 
40          Global::GetDicomDirElements()->GetDicomDirStudyElements();
41       FillObject(elemList);
42    }
43 }
44
45 /**
46  * \brief   Canonical destructor.
47  */
48 DicomDirStudy::~DicomDirStudy() 
49 {
50    ClearSerie();
51 }
52
53 //-----------------------------------------------------------------------------
54 // Public
55 /**
56  * \brief   Writes the Object
57  * @param fp ofstream to write to
58  * @param t Type of the File (explicit VR, implicitVR, ...) 
59  * @return
60  */ 
61 void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t, bool , bool )
62 {
63    DicomDirObject::WriteContent(fp, t, false, true);
64
65    for(ListDicomDirSerie::iterator cc = Series.begin();
66                                    cc!= Series.end();
67                                  ++cc )
68    {
69       (*cc)->WriteContent( fp, t, false, true );
70    }
71
72    for(ListDicomDirVisit::iterator icc = Visits.begin();
73                                    icc!= Visits.end();
74                                  ++icc )
75    {
76       (*icc)->WriteContent( fp, t, false, true );
77    }
78 }
79
80 /**
81  * \brief   adds a new Serie at the beginning of the SerieList
82  *          of a partially created DICOMDIR
83  */
84 DicomDirSerie *DicomDirStudy::NewSerie()
85 {
86    DicomDirSerie *dd = DicomDirSerie::New();
87    Series.push_back(dd);
88    return dd;
89
90
91 /**
92  * \brief  Remove all series in the study 
93  */
94 void DicomDirStudy::ClearSerie()
95 {
96    for(ListDicomDirSerie::iterator cc = Series.begin();
97                                    cc != Series.end();
98                                  ++cc )
99    {
100       (*cc)->Delete();
101    }
102    Series.clear();
103 }
104
105 /**
106  * \brief   Get the first entry while visiting the DicomDirSeries
107  * \return  The first DicomDirSerie if found, otherwhise NULL
108  */
109 DicomDirSerie *DicomDirStudy::GetFirstSerie()
110 {
111    ItSerie = Series.begin();
112    if (ItSerie != Series.end())
113       return *ItSerie;
114    return NULL;
115 }
116
117 /**
118  * \brief   Get the next entry while visiting the DicomDirSeries
119  * \note : meaningfull only if GetFirstEntry already called
120  * \return  The next DicomDirSerie if found, otherwhise NULL
121  */
122 DicomDirSerie *DicomDirStudy::GetNextSerie()
123 {
124    gdcmAssertMacro (ItSerie != Series.end());
125
126    ++ItSerie;
127    if (ItSerie != Series.end())
128       return *ItSerie;
129    return NULL;
130 }  
131
132 /**
133  * \brief   Get the last entry while visiting the DicomDirSeries
134  * \return  The last DicomDirSerie if found, otherwhise NULL
135  */
136 DicomDirSerie *DicomDirStudy::GetLastSerie()
137 {
138    ItSerie = Series.end();
139    if (ItSerie != Series.begin())
140    {
141      --ItSerie;
142       return *ItSerie;
143    }
144    return NULL;
145 }
146
147
148 /**
149  * \brief   adds a new Visit at the beginning of the VisitList
150  *          of a partially created DICOMDIR
151  */
152 DicomDirVisit *DicomDirStudy::NewVisit()
153 {
154    DicomDirVisit *dd = DicomDirVisit::New();
155    Visits.push_back(dd);
156    dd->Delete();
157    return dd;
158
159
160 /**
161  * \brief  Remove all visits in the study 
162  */
163 void DicomDirStudy::ClearVisit()
164 {
165    for(ListDicomDirVisit::iterator cc =  Visits.begin();
166                                    cc != Visits.end();
167                                  ++cc )
168    {
169       (*cc)->Delete();
170    }
171    Visits.clear();
172 }
173
174 /**
175  * \brief   Get the first entry while visiting the DicomDirVisit
176  * \return  The first DicomDirVisit if found, otherwhise NULL
177  */
178 DicomDirVisit *DicomDirStudy::GetFirstVisit()
179 {
180    ItVisit = Visits.begin();
181    if (ItVisit != Visits.end())
182       return *ItVisit;
183    return NULL;
184 }
185
186 /**
187  * \brief   Get the next entry while visiting the DicomDirVisit
188  * \note : meaningfull only if GetFirstEntry already called
189  * \return  The next DicomDirVisit if found, otherwhise NULL
190  */
191 DicomDirVisit *DicomDirStudy::GetNextVisit()
192 {
193    gdcmAssertMacro (ItVisit != Visits.end());
194
195    ++ItVisit;
196    if (ItVisit != Visits.end())
197       return *ItVisit;
198    return NULL;
199 }
200
201 /**
202  * \brief   Get the last entry while visiting the DicomDirVisit
203  * \return  The last DicomDirVisit if found, otherwhise NULL
204  */
205 DicomDirVisit *DicomDirStudy::GetLastVisit()
206 {
207    ItVisit = Visits.end();
208    if (ItVisit != Visits.begin())
209    {
210      --ItVisit;
211       return *ItVisit;
212    }
213    return NULL;
214 }
215
216 /**
217  * \brief Copies all the attributes from an other DocEntrySet 
218  * @param set entry to copy from
219  * @remarks The contained DocEntries a not copied, only referenced
220  */
221 void DicomDirStudy::Copy(DocEntrySet *set)
222 {
223    // Remove all previous childs
224    ClearSerie();
225    ClearVisit();
226
227    DicomDirObject::Copy(set);
228
229    DicomDirStudy *ddEntry = dynamic_cast<DicomDirStudy *>(set);
230    if( ddEntry )
231    {
232       Series = ddEntry->Series;
233       for(ItSerie = Series.begin();ItSerie != Series.end();++ItSerie)
234          (*ItSerie)->Register();
235
236       Visits = ddEntry->Visits;
237       for(ItVisit = Visits.begin();ItVisit != Visits.end();++ItVisit)
238          (*ItVisit)->Register();
239    }
240 }
241
242 //-----------------------------------------------------------------------------
243 // Protected
244
245 //-----------------------------------------------------------------------------
246 // Private
247
248 //-----------------------------------------------------------------------------
249 // Print
250 /**
251  * \brief   Prints the Object
252  * @param os ostream to write to 
253  * @param indent Indentation string to be prepended during printing
254  * @return
255  */ 
256 void DicomDirStudy::Print(std::ostream &os, std::string const & )
257 {
258    os << "STUDY" << std::endl;
259    DicomDirObject::Print(os);
260
261    for(ListDicomDirSerie::iterator cc = Series.begin();
262                                    cc != Series.end();
263                                    ++cc)
264    {
265       (*cc)->SetPrintLevel(PrintLevel);
266       (*cc)->Print(os);
267    }
268
269    for(ListDicomDirVisit::iterator cc2 =  Visits.begin();
270                                    cc2 != Visits.end();
271                                    ++cc2)
272    {
273       (*cc2)->SetPrintLevel(PrintLevel);
274       (*cc2)->Print(os);
275    }
276
277 }
278
279 //-----------------------------------------------------------------------------
280 } // end namespace gdcm