]> Creatis software - gdcm.git/blob - src/gdcmDicomDirStudy.cxx
9a5dd26551e40cf08bc9d9014681e7621c178592
[gdcm.git] / src / gdcmDicomDirStudy.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/07/11 08:20:25 $
7   Version:   $Revision: 1.40 $
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 
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)
62 {
63    DicomDirObject::WriteContent(fp, t);
64
65    for(ListDicomDirSerie::iterator cc = Series.begin();
66                                    cc!= Series.end();
67                                  ++cc )
68    {
69       (*cc)->WriteContent( fp, t );
70    }
71
72    for(ListDicomDirVisit::iterator icc = Visits.begin();
73                                    icc!= Visits.end();
74                                  ++icc )
75    {
76       (*icc)->WriteContent( fp, t );
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 *st = new DicomDirSerie();
87    Series.push_back(st);
88    return st;
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       delete *cc;
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 *st = new DicomDirVisit();
155    Visits.push_back(st);
156    return st;
157
158
159 /**
160  * \brief  Remove all visits in the study 
161  */
162 void DicomDirStudy::ClearVisit()
163 {
164    for(ListDicomDirVisit::iterator cc =  Visits.begin();
165                                    cc != Visits.end();
166                                  ++cc )
167    {
168       delete *cc;
169    }
170    Visits.clear();
171 }
172
173 /**
174  * \brief   Get the first entry while visiting the DicomDirVisit
175  * \return  The first DicomDirVisit if found, otherwhise NULL
176  */
177 DicomDirVisit *DicomDirStudy::GetFirstVisit()
178 {
179    ItVisit = Visits.begin();
180    if (ItVisit != Visits.end())
181       return *ItVisit;
182    return NULL;
183 }
184
185 /**
186  * \brief   Get the next entry while visiting the DicomDirVisit
187  * \note : meaningfull only if GetFirstEntry already called
188  * \return  The next DicomDirVisit if found, otherwhise NULL
189  */
190 DicomDirVisit *DicomDirStudy::GetNextVisit()
191 {
192    gdcmAssertMacro (ItVisit != Visits.end());
193
194    ++ItVisit;
195    if (ItVisit != Visits.end())
196       return *ItVisit;
197    return NULL;
198 }
199
200 /**
201  * \brief   Get the last entry while visiting the DicomDirVisit
202  * \return  The last DicomDirVisit if found, otherwhise NULL
203  */
204 DicomDirVisit *DicomDirStudy::GetLastVisit()
205 {
206    ItVisit = Visits.end();
207    if (ItVisit != Visits.begin())
208    {
209      --ItVisit;
210       return *ItVisit;
211    }
212    return NULL;
213 }
214
215 //-----------------------------------------------------------------------------
216 // Protected
217
218 //-----------------------------------------------------------------------------
219 // Private
220
221 //-----------------------------------------------------------------------------
222 // Print
223 /**
224  * \brief   Prints the Object
225  * @param os ostream to write to 
226  * @param indent Indentation string to be prepended during printing
227  * @return
228  */ 
229 void DicomDirStudy::Print(std::ostream &os, std::string const & )
230 {
231    os << "STUDY" << std::endl;
232    DicomDirObject::Print(os);
233
234    for(ListDicomDirSerie::iterator cc = Series.begin();
235                                    cc != Series.end();
236                                    ++cc)
237    {
238       (*cc)->SetPrintLevel(PrintLevel);
239       (*cc)->Print(os);
240    }
241
242    for(ListDicomDirVisit::iterator cc2 =  Visits.begin();
243                                    cc2 != Visits.end();
244                                    ++cc2)
245    {
246       (*cc2)->SetPrintLevel(PrintLevel);
247       (*cc2)->Print(os);
248    }
249
250 }
251
252 //-----------------------------------------------------------------------------
253 } // end namespace gdcm