]> Creatis software - gdcm.git/blob - src/gdcmDicomDirPatient.cxx
Fix mistypings
[gdcm.git] / src / gdcmDicomDirPatient.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/10/08 15:20:17 $
7   Version:   $Revision: 1.44 $
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_NAME_SPACE 
27 {
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief   Constructor
32  * \note End user must use : DicomDir::NewPatient()
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 // 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  */ 
60 void DicomDirPatient::WriteContent(std::ofstream *fp, FileType t, bool , bool )
61 {
62    DicomDirObject::WriteContent(fp, t, false, true);
63
64    for(ListDicomDirStudy::iterator cc = Studies.begin();
65                                    cc!= Studies.end();
66                                  ++cc )
67    {
68       (*cc)->WriteContent( fp, t, false, true );
69    }
70 }
71
72 /**
73  * \brief   adds a new Patient at the beginning of the PatientList
74  *          of a partially created DICOMDIR
75  */
76 DicomDirStudy* DicomDirPatient::NewStudy()
77 {
78    DicomDirStudy *dd = DicomDirStudy::New();
79    Studies.push_back(dd);
80    return dd; 
81 }   
82
83 /**
84  * \brief  Remove all studies in the patient 
85  */
86 void DicomDirPatient::ClearStudy()
87 {
88    for(ListDicomDirStudy::const_iterator cc = Studies.begin();
89                                          cc != Studies.end(); 
90                                        ++cc )
91    {
92       (*cc)->Delete();
93    }
94    Studies.clear();
95 }
96
97 /**
98  * \brief   Get the first entry while visiting the DicomDirStudy
99  * \return  The first DicomDirStudy if found, otherwhise NULL
100  */ 
101 DicomDirStudy *DicomDirPatient::GetFirstStudy()
102 {
103    ItStudy = Studies.begin();
104    if (ItStudy != Studies.end())
105       return *ItStudy;
106    return NULL;
107 }
108
109 /**
110  * \brief   Get the next entry while visiting the DicomDirStudies
111  * \note : meaningfull only if GetFirstEntry already called
112  * \return  The next DicomDirStudies if found, otherwhise NULL
113  */
114 DicomDirStudy *DicomDirPatient::GetNextStudy()
115 {
116    gdcmAssertMacro (ItStudy != Studies.end())
117
118    ++ItStudy;
119    if (ItStudy != Studies.end())
120       return *ItStudy;
121    return NULL;
122 }
123
124 /**
125  * \brief   Get the first entry while visiting the DicomDirStudy
126  * \return  The first DicomDirStudy if found, otherwhise NULL
127  */ 
128 DicomDirStudy *DicomDirPatient::GetLastStudy()
129 {
130    ItStudy = Studies.end();
131    if (ItStudy != Studies.begin())
132    {
133       --ItStudy;
134       return *ItStudy;
135    }
136    return NULL;
137 }
138
139 /**
140  * \brief Copies all the attributes from an other DocEntrySet 
141  * @param set entry to copy from
142  * @remarks The contained DocEntries a not copied, only referenced
143  */
144 void DicomDirPatient::Copy(DocEntrySet *set)
145 {
146    // Remove all previous childs
147    ClearStudy();
148
149    DicomDirObject::Copy(set);
150
151    DicomDirPatient *ddEntry = dynamic_cast<DicomDirPatient *>(set);
152    if( ddEntry )
153    {
154       Studies = ddEntry->Studies;
155       for(ItStudy = Studies.begin();ItStudy != Studies.end();++ItStudy)
156          (*ItStudy)->Register();
157    }
158 }
159
160 //-----------------------------------------------------------------------------
161 // Protected
162
163 //-----------------------------------------------------------------------------
164 // Private
165
166 //-----------------------------------------------------------------------------
167 // Print
168 /**
169  * \brief   Prints the Object
170  * @param os ostream to write to 
171  * @param indent Indentation string to be prepended during printing
172  */ 
173 void DicomDirPatient::Print(std::ostream &os, std::string const & )
174 {
175    os << "PATIENT" << std::endl;
176    DicomDirObject::Print(os);
177
178    for(ListDicomDirStudy::const_iterator cc = Studies.begin();
179                                          cc != Studies.end(); 
180                                        ++cc )
181    {
182       (*cc)->SetPrintLevel(PrintLevel);
183       (*cc)->Print(os);
184    }
185 }
186
187 //-----------------------------------------------------------------------------
188 } // end namespace gdcm