]> Creatis software - gdcm.git/blob - src/gdcmDicomDirPatient.cxx
035f6492805d66dd078277320d037ebe74948652
[gdcm.git] / src / gdcmDicomDirPatient.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/20 11:09:23 $
7   Version:   $Revision: 1.29 $
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 "gdcmDicomDirPatient.h"
20 #include "gdcmDicomDirElement.h"
21 #include "gdcmGlobal.h"
22 #include "gdcmDicomDirStudy.h"
23 #include "gdcmSQItem.h"
24 #include "gdcmDebug.h"
25
26 namespace gdcm 
27 {
28
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
31 /**
32  * \brief   Constructor
33  */
34 DicomDirPatient::DicomDirPatient():
35    DicomDirObject()
36 {
37 }
38 /**
39  * \brief   Canonical destructor.
40  */
41 DicomDirPatient::~DicomDirPatient() 
42 {
43    for(ListDicomDirStudy::const_iterator cc = Studies.begin();
44                                          cc != Studies.end(); 
45                                        ++cc )
46    {
47       delete *cc;
48    }
49 }
50
51 //-----------------------------------------------------------------------------
52 // Print
53 /**
54  * \brief   Prints the Object
55  * @param os ostream to write to 
56  * @param   indent indent
57  */ 
58 void DicomDirPatient::Print(std::ostream &os, std::string const & )
59 {
60    os << "PATIENT" << std::endl;
61    DicomDirObject::Print(os);
62
63    for(ListDicomDirStudy::const_iterator cc = Studies.begin();
64                                          cc != Studies.end(); 
65                                        ++cc )
66    {
67       (*cc)->SetPrintLevel(PrintLevel);
68       (*cc)->Print(os);
69    }
70 }
71
72 //-----------------------------------------------------------------------------
73 // Public
74 /**
75  * \brief   Writes the Object
76  * @param fp ofstream to write to
77  * @param t Type of the File (explicit VR, implicitVR, ...) 
78  */ 
79 void DicomDirPatient::WriteContent(std::ofstream *fp, FileType t)
80 {
81    DicomDirObject::WriteContent(fp, t);
82
83    for(ListDicomDirStudy::iterator cc = Studies.begin();
84                                    cc!= Studies.end();
85                                  ++cc )
86    {
87       (*cc)->WriteContent( fp, t );
88    }
89 }
90
91 /**
92  * \brief   adds a new Patient at the begining of the PatientList
93  *          of a partially created DICOMDIR
94  */
95 DicomDirStudy* DicomDirPatient::NewStudy()
96 {
97    ListDicomDirStudyElem const &elemList = 
98       Global::GetDicomDirElements()->GetDicomDirStudyElements();
99       
100    DicomDirStudy *st = new DicomDirStudy();
101    st->FillObject(elemList);
102
103    Studies.push_back(st);
104    return st; 
105 }   
106
107 /**
108  * \brief   Get the first entry while visiting the DicomDirStudy
109  * \return  The first DicomDirStudy if found, otherwhise NULL
110  */ 
111 DicomDirStudy *DicomDirPatient::GetFirstStudy()
112 {
113    ItStudy = Studies.begin();
114    if (ItStudy != Studies.end())
115       return *ItStudy;
116    return NULL;
117 }
118
119 /**
120  * \brief   Get the next entry while visiting the DicomDirStudies
121  * \note : meaningfull only if GetFirstEntry already called
122  * \return  The next DicomDirStudies if found, otherwhise NULL
123  */
124 DicomDirStudy *DicomDirPatient::GetNextStudy()
125 {
126    gdcmAssertMacro (ItStudy != Studies.end())
127    {
128       ++ItStudy;
129       if (ItStudy != Studies.end())
130          return *ItStudy;
131    }
132    return NULL;
133 }
134
135 /**
136  * \brief   Get the first entry while visiting the DicomDirStudy
137  * \return  The first DicomDirStudy if found, otherwhise NULL
138  */ 
139 DicomDirStudy *DicomDirPatient::GetLastStudy()
140 {
141    ItStudy = Studies.end();
142    if (ItStudy != Studies.begin())
143    {
144       --ItStudy;
145       return *ItStudy;
146    }
147    return NULL;
148 }
149
150 //-----------------------------------------------------------------------------
151 // Protected
152
153 //-----------------------------------------------------------------------------
154 // Private
155
156 //-----------------------------------------------------------------------------
157
158 } // end namespace gdcm