+ // Instance Creation Time
+ const std::string &time = Util::GetCurrentTime();
+ CopyMandatoryEntry(0x0008,0x0013,time,"TM");
+
+ // Study Date
+ CheckMandatoryEntry(0x0008,0x0020,date,"DA");
+ // Study Time
+ CheckMandatoryEntry(0x0008,0x0030,time,"TM");
+
+ // Accession Number
+ //CopyMandatoryEntry(0x0008,0x0050,"");
+ CheckMandatoryEntry(0x0008,0x0050,"","SH");
+
+
+ // ----- Add Mandatory Entries if missing ---
+ // Entries whose type is 1 are mandatory, with a mandatory value
+ // Entries whose type is 1c are mandatory-inside-a-Sequence,
+ // with a mandatory value
+ // Entries whose type is 2 are mandatory, with an optional value
+ // Entries whose type is 2c are mandatory-inside-a-Sequence,
+ // with an optional value
+ // Entries whose type is 3 are optional
+
+ // 'Study Instance UID'
+ // Keep the value if exists
+ // The user is allowed to create his own Study,
+ // keeping the same 'Study Instance UID' for various images
+ // The user may add images to a 'Manufacturer Study',
+ // adding new Series to an already existing Study
+ CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID(),"UI");
+
+ // 'Serie Instance UID'
+ // Keep the value if exists
+ // The user is allowed to create his own Series,
+ // keeping the same 'Serie Instance UID' for various images
+ // The user shouldn't add any image to a 'Manufacturer Serie'
+ // but there is no way no to prevent him for doing that
+ CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID(),"UI");
+
+ // Study ID
+ CheckMandatoryEntry(0x0020,0x0010,"","SH");
+
+ // Series Number
+ CheckMandatoryEntry(0x0020,0x0011,"","IS");
+
+ // Instance Number
+ CheckMandatoryEntry(0x0020,0x0013,"","IS");
+
+ // Patient Orientation
+ // Can be computed from (0020|0037) : Image Orientation (Patient)
+ gdcm::Orientation *o = gdcm::Orientation::New();
+ std::string ori = o->GetOrientation ( FileInternal );
+ o->Delete();
+ if (ori != "\\" && ori != GDCM_UNFOUND)
+ CheckMandatoryEntry(0x0020,0x0020,ori,"CS");
+ else
+ CheckMandatoryEntry(0x0020,0x0020,"","CS");
+
+ // Default Patient Position to HFS
+ CheckMandatoryEntry(0x0018,0x5100,"HFS","CS");
+
+ // Modality : if missing we set it to 'OTher'
+ CheckMandatoryEntry(0x0008,0x0060,"OT","CS");
+
+ // Manufacturer : if missing we set it to 'GDCM Factory'
+ CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory","LO");
+
+ // Institution Name : if missing we set it to 'GDCM Hospital'
+ CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital","LO");
+
+ // Patient's Name : if missing, we set it to 'GDCM^Patient'
+ CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient","PN");
+
+ // Patient ID : some clinical softwares *demand* it although it's a 'type 2' entry.
+ CheckMandatoryEntry(0x0010,0x0020,"gdcm ID","LO");
+
+ // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
+ CheckMandatoryEntry(0x0010,0x0030,"","DA");
+
+ // Patient's Sex :'type 2' entry -> must exist, value not mandatory
+ CheckMandatoryEntry(0x0010,0x0040,"","CS");
+
+ // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
+ CheckMandatoryEntry(0x0008,0x0090,"","PN");
+
+ /*
+ // Deal with element 0x0000 (group length) of each group.
+ // First stage : get all the different Groups
+
+ GroupHT grHT;
+ DocEntry *d = FileInternal->GetFirstEntry();
+ while(d)
+ {
+ grHT[d->GetGroup()] = 0;
+ d=FileInternal->GetNextEntry();
+ }
+ // Second stage : add the missing ones (if any)
+ for (GroupHT::iterator it = grHT.begin(); it != grHT.end(); ++it)
+ {
+ CheckMandatoryEntry(it->first, 0x0000, "0");
+ }
+ // Third stage : update all 'zero level' groups length
+*/
+
+}
+
+void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr )
+{
+ DataEntry *entry = FileInternal->GetDataEntry(group,elem);
+ if ( !entry )
+ {
+ //entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
+ entry = DataEntry::New(group,elem,vr);
+ entry->SetString(value);
+ Archive->Push(entry);
+ entry->Delete();
+ }
+}
+
+/// \todo : what is it used for ? (FileHelper::SetMandatoryEntry)
+void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr)
+{
+ //DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
+ DataEntry *entry = DataEntry::New(group,elem,vr);
+ entry->SetString(value);
+ Archive->Push(entry);
+ entry->Delete();
+}
+
+void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr)
+{
+ DataEntry *entry = CopyDataEntry(group,elem,vr);
+ entry->SetString(value);
+ Archive->Push(entry);
+ entry->Delete();
+}
+
+/**
+ * \brief Restore in the File the initial group 0002
+ */
+void FileHelper::RestoreWriteMandatory()
+{
+ // group 0002 may be pushed out for ACR-NEMA writting purposes
+ Archive->Restore(0x0002,0x0000);
+ Archive->Restore(0x0002,0x0001);
+ Archive->Restore(0x0002,0x0002);
+ Archive->Restore(0x0002,0x0003);
+ Archive->Restore(0x0002,0x0010);
+ Archive->Restore(0x0002,0x0012);
+ Archive->Restore(0x0002,0x0013);
+ Archive->Restore(0x0002,0x0016);
+ Archive->Restore(0x0002,0x0100);
+ Archive->Restore(0x0002,0x0102);
+
+ // FIXME : Check if none is missing !
+
+ Archive->Restore(0x0008,0x0012);
+ Archive->Restore(0x0008,0x0013);
+ Archive->Restore(0x0008,0x0016);
+ Archive->Restore(0x0008,0x0018);
+ Archive->Restore(0x0008,0x0060);
+ Archive->Restore(0x0008,0x0070);
+ Archive->Restore(0x0008,0x0080);
+ Archive->Restore(0x0008,0x0090);
+ Archive->Restore(0x0008,0x2112);
+
+ Archive->Restore(0x0010,0x0010);
+ Archive->Restore(0x0010,0x0030);
+ Archive->Restore(0x0010,0x0040);
+
+ Archive->Restore(0x0020,0x000d);
+ Archive->Restore(0x0020,0x000e);
+}
+
+
+/**
+ * \brief CallStartMethod
+ */
+void FileHelper::CallStartMethod()
+{
+ Progress = 0.0f;
+ Abort = false;
+ CommandManager::ExecuteCommand(this,CMD_STARTPROGRESS);
+}
+
+/**
+ * \brief CallProgressMethod
+ */
+void FileHelper::CallProgressMethod()
+{
+ CommandManager::ExecuteCommand(this,CMD_PROGRESS);
+}
+
+/**
+ * \brief CallEndMethod
+ */
+void FileHelper::CallEndMethod()
+{
+ Progress = 1.0f;
+ CommandManager::ExecuteCommand(this,CMD_ENDPROGRESS);
+}
+