]> Creatis software - gdcm.git/blob - src/gdcmDicomDirPatient.cxx
2005-01-15 Jean-Pierre Roux <jpr@creatis.univ-lyon1.fr>
[gdcm.git] / src / gdcmDicomDirPatient.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/17 10:59:52 $
7   Version:   $Revision: 1.25 $
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
25 namespace gdcm 
26 {
27
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 /**
31  * \brief   Constructor
32  */
33 DicomDirPatient::DicomDirPatient():
34    DicomDirObject()
35 {
36 }
37 /**
38  * \brief   Canonical destructor.
39  */
40 DicomDirPatient::~DicomDirPatient() 
41 {
42    for(ListDicomDirStudy::const_iterator cc = Studies.begin();
43                                          cc != Studies.end(); 
44                                        ++cc )
45    {
46       delete *cc;
47    }
48 }
49
50 //-----------------------------------------------------------------------------
51 // Print
52 /**
53  * \brief   Prints the Object
54  * @param os ostream to write to 
55  */ 
56 void DicomDirPatient::Print(std::ostream &os, std::string const & )
57 {
58    os << "PATIENT" << std::endl;
59    DicomDirObject::Print(os);
60
61    for(ListDicomDirStudy::const_iterator cc = Studies.begin();
62                                          cc != Studies.end(); 
63                                        ++cc )
64    {
65       (*cc)->SetPrintLevel(PrintLevel);
66       (*cc)->Print(os);
67    }
68 }
69
70 /**
71  * \brief   Writes the Object
72  * @param fp ofstream to write to
73  * @param t Type of the File (explicit VR, implicitVR, ...) 
74  */ 
75 void DicomDirPatient::WriteContent(std::ofstream *fp, FileType t)
76 {
77    DicomDirObject::WriteContent(fp, t);
78
79    for(ListDicomDirStudy::iterator cc = Studies.begin();
80                                    cc!= Studies.end();
81                                  ++cc )
82    {
83       (*cc)->WriteContent( fp, t );
84    }
85 }
86 //-----------------------------------------------------------------------------
87 // Public
88
89 /**
90  * \brief   adds a new Patient at the begining of the PatientList
91  *          of a partially created DICOMDIR
92  */
93 DicomDirStudy* DicomDirPatient::NewStudy()
94 {
95    ListDicomDirStudyElem const &elemList = 
96       Global::GetDicomDirElements()->GetDicomDirStudyElements();
97       
98    DicomDirStudy *st = new DicomDirStudy();
99    st->FillObject(elemList);
100
101    Studies.push_front(st);
102    return st; 
103 }   
104
105 /**
106  * \brief   Initialise the visit of the DicomDirPatients
107  */
108 void DicomDirPatient::InitTraversal()
109 {
110    ItDicomDirStudy = Studies.begin();
111 }
112
113 /**
114  * \brief   Get the next entry while visiting the DicomDirStudies
115  * \return  The next DicomDirStudies if found, otherwhise NULL
116  */
117 DicomDirStudy *DicomDirPatient::GetNextEntry()
118 {
119    if (ItDicomDirStudy != Studies.end())
120    {
121       DicomDirStudy *tmp = *ItDicomDirStudy;
122       ++ItDicomDirStudy;
123       return tmp;
124    }
125    else
126    {
127       return NULL;
128    }
129 }
130 //-----------------------------------------------------------------------------
131 // Protected
132
133 //-----------------------------------------------------------------------------
134 // Private
135
136 //-----------------------------------------------------------------------------
137
138 } // end namespace gdcm