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