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