00001 /*========================================================================= 00002 00003 Program: gdcm 00004 Module: $RCSfile: gdcmDicomDirPatient.cxx,v $ 00005 Language: C++ 00006 Date: $Date: 2007/07/26 08:36:49 $ 00007 Version: $Revision: 1.42 $ 00008 00009 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00010 l'Image). All rights reserved. See Doc/License.txt or 00011 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. 00012 00013 This software is distributed WITHOUT ANY WARRANTY; without even 00014 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 PURPOSE. See the above copyright notices for more information. 00016 00017 =========================================================================*/ 00018 00019 #include "gdcmDicomDirPatient.h" 00020 #include "gdcmDicomDirElement.h" 00021 #include "gdcmGlobal.h" 00022 #include "gdcmDicomDirStudy.h" 00023 #include "gdcmSQItem.h" 00024 #include "gdcmDebug.h" 00025 00026 namespace GDCM_NAME_SPACE 00027 { 00028 //----------------------------------------------------------------------------- 00029 // Constructor / Destructor 00034 DicomDirPatient::DicomDirPatient(bool empty) 00035 :DicomDirObject() 00036 { 00037 if ( !empty ) 00038 { 00039 ListDicomDirStudyElem const &elemList = 00040 Global::GetDicomDirElements()->GetDicomDirPatientElements(); 00041 FillObject(elemList); 00042 } 00043 } 00044 00048 DicomDirPatient::~DicomDirPatient() 00049 { 00050 ClearStudy(); 00051 } 00052 00053 //----------------------------------------------------------------------------- 00054 // Public 00060 void DicomDirPatient::WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements) 00061 { 00062 DicomDirObject::WriteContent(fp, t, false); 00063 00064 for(ListDicomDirStudy::iterator cc = Studies.begin(); 00065 cc!= Studies.end(); 00066 ++cc ) 00067 { 00068 (*cc)->WriteContent( fp, t, false ); 00069 } 00070 } 00071 00076 DicomDirStudy* DicomDirPatient::NewStudy() 00077 { 00078 DicomDirStudy *dd = DicomDirStudy::New(); 00079 Studies.push_back(dd); 00080 return dd; 00081 } 00082 00086 void DicomDirPatient::ClearStudy() 00087 { 00088 for(ListDicomDirStudy::const_iterator cc = Studies.begin(); 00089 cc != Studies.end(); 00090 ++cc ) 00091 { 00092 (*cc)->Delete(); 00093 } 00094 Studies.clear(); 00095 } 00096 00101 DicomDirStudy *DicomDirPatient::GetFirstStudy() 00102 { 00103 ItStudy = Studies.begin(); 00104 if (ItStudy != Studies.end()) 00105 return *ItStudy; 00106 return NULL; 00107 } 00108 00114 DicomDirStudy *DicomDirPatient::GetNextStudy() 00115 { 00116 gdcmAssertMacro (ItStudy != Studies.end()) 00117 00118 ++ItStudy; 00119 if (ItStudy != Studies.end()) 00120 return *ItStudy; 00121 return NULL; 00122 } 00123 00128 DicomDirStudy *DicomDirPatient::GetLastStudy() 00129 { 00130 ItStudy = Studies.end(); 00131 if (ItStudy != Studies.begin()) 00132 { 00133 --ItStudy; 00134 return *ItStudy; 00135 } 00136 return NULL; 00137 } 00138 00144 void DicomDirPatient::Copy(DocEntrySet *set) 00145 { 00146 // Remove all previous childs 00147 ClearStudy(); 00148 00149 DicomDirObject::Copy(set); 00150 00151 DicomDirPatient *ddEntry = dynamic_cast<DicomDirPatient *>(set); 00152 if( ddEntry ) 00153 { 00154 Studies = ddEntry->Studies; 00155 for(ItStudy = Studies.begin();ItStudy != Studies.end();++ItStudy) 00156 (*ItStudy)->Register(); 00157 } 00158 } 00159 00160 //----------------------------------------------------------------------------- 00161 // Protected 00162 00163 //----------------------------------------------------------------------------- 00164 // Private 00165 00166 //----------------------------------------------------------------------------- 00167 // Print 00173 void DicomDirPatient::Print(std::ostream &os, std::string const & ) 00174 { 00175 os << "PATIENT" << std::endl; 00176 DicomDirObject::Print(os); 00177 00178 for(ListDicomDirStudy::const_iterator cc = Studies.begin(); 00179 cc != Studies.end(); 00180 ++cc ) 00181 { 00182 (*cc)->SetPrintLevel(PrintLevel); 00183 (*cc)->Print(os); 00184 } 00185 } 00186 00187 //----------------------------------------------------------------------------- 00188 } // end namespace gdcm