+ // Pixel Spacing : defaulted to 1.0\1.0
+ CheckMandatoryEntry(0x0028,0x0030,"1.0\\1.0");
+
+ // Samples Per Pixel (type 1) : default to grayscale
+ CheckMandatoryEntry(0x0028,0x0002,"1");
+
+
+ // --- Check UID-related Entries ---
+
+ // If 'SOP Class UID' exists ('true DICOM' image)
+ // we create the 'Source Image Sequence' SeqEntry
+ // to hold informations about the Source Image
+
+ DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016);
+ if ( e_0008_0016 )
+ {
+ // Create 'Source Image Sequence' SeqEntry
+ SeqEntry *sis = SeqEntry::New (
+ Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) );
+ SQItem *sqi = SQItem::New(1);
+ // (we assume 'SOP Instance UID' exists too)
+ // create 'Referenced SOP Class UID'
+ DataEntry *e_0008_1150 = DataEntry::New(
+ Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) );
+ e_0008_1150->SetString( e_0008_0016->GetString());
+ sqi->AddEntry(e_0008_1150);
+ e_0008_1150->Delete();
+
+ // create 'Referenced SOP Instance UID'
+ DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018);
+ DataEntry *e_0008_1155 = DataEntry::New(
+ Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) );
+ e_0008_1155->SetString( e_0008_0018->GetString());
+ sqi->AddEntry(e_0008_1155);
+ e_0008_1155->Delete();
+
+ sis->AddSQItem(sqi,1);
+ sqi->Delete();
+
+ // temporarily replaces any previous 'Source Image Sequence'
+ Archive->Push(sis);
+ sis->Delete();
+
+ // FIXME : is 'Image Type' *really* depending on the presence of'SOP Class UID'?
+
+ // 'Image Type' (The written image is no longer an 'ORIGINAL' one)
+ CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY");
+ }
+
+ // At the end, not to overwrite the original ones,
+ // needed by 'Referenced SOP Instance UID', 'Referenced SOP Class UID'
+ // 'SOP Instance UID'
+ CopyMandatoryEntry(0x0008,0x0018,sop);
+
+ // whether a 'SOP Class UID' already exists or not in the original image
+ // the gdcm written image *is* a [Secondary Capture Image Storage] !
+ // 'SOP Class UID' : [Secondary Capture Image Storage]
+ CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7");
+
+// ---- The user will never have to take any action on the following ----.
+ // new value for 'SOP Instance UID'
+ //SetMandatoryEntry(0x0008,0x0018,Util::CreateUniqueUID());
+
+ // Instance Creation Date
+ const std::string &date = Util::GetCurrentDate();
+ CopyMandatoryEntry(0x0008,0x0012,date);
+
+ // Instance Creation Time
+ const std::string &time = Util::GetCurrentTime();
+ CopyMandatoryEntry(0x0008,0x0013,time);
+
+ // Study Date
+ CopyMandatoryEntry(0x0008,0x0020,date);
+ // Study Time
+ CopyMandatoryEntry(0x0008,0x0030,time);
+
+ // Accession Number
+ CopyMandatoryEntry(0x0008,0x0050,"");
+
+ // Conversion Type.
+ // Other possible values are :
+ // See PS 3.3, Page 408
+
+ // DV = Digitized Video
+ // DI = Digital Interface
+ // DF = Digitized Film
+ // WSD = Workstation
+ // SD = Scanned Document
+ // SI = Scanned Image
+ // DRW = Drawing
+ // SYN = Synthetic Image
+
+ // FIXME : Must we Force Value, or Default value ?
+ // Is it Type 1 for any Modality ?
+ // --> Answer seems to be NO :-(
+ CopyMandatoryEntry(0x0008,0x0064,"SYN");
+
+// ----- 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());
+
+ // '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 allowed him to do that
+ CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID());
+
+ // Study ID
+ CheckMandatoryEntry(0x0020,0x0010,"");
+
+ // Series Number
+ CheckMandatoryEntry(0x0020,0x0011,"");
+
+ // Instance Number
+ CheckMandatoryEntry(0x0020,0x0013,"");
+
+ // Patient Orientation FIXME 1\0\0\0\1\0 or empty ?
+ CheckMandatoryEntry(0x0020,0x0020,"");
+
+ // Modality : if missing we set it to 'OTher'
+ CheckMandatoryEntry(0x0008,0x0060,"OT");
+
+ // Manufacturer : if missing we set it to 'GDCM Factory'
+ CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory");
+
+ // Institution Name : if missing we set it to 'GDCM Hospital'
+ CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital");
+
+ // Patient's Name : if missing, we set it to 'GDCM^Patient'
+ CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient");
+
+ // Patient ID
+ CheckMandatoryEntry(0x0010,0x0020,"");
+
+ // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory
+ CheckMandatoryEntry(0x0010,0x0030,"");
+
+ // Patient's Sex :'type 2' entry -> must exist, value not mandatory
+ CheckMandatoryEntry(0x0010,0x0040,"");
+
+ // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory
+ CheckMandatoryEntry(0x0008,0x0090,"");
+
+ // Remove some inconstencies (probably some more will be added)
+
+ // if (0028 0008)Number of Frames exists
+ // Push out (0020 0052),Frame of Reference UID
+ // (only meaningfull within a Serie)
+ DataEntry *e_0028_0008 = FileInternal->GetDataEntry(0x0028, 0x0008);
+ if ( !e_0028_0008 )
+ {
+ Archive->Push(0x0020, 0x0052);
+ }
+}
+
+void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
+{
+ DataEntry *entry = FileInternal->GetDataEntry(group,elem);
+ if ( !entry )
+ {
+ entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
+ entry->SetString(value);
+ Archive->Push(entry);
+ entry->Delete();
+ }
+}
+
+void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
+{
+ DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem));
+ entry->SetString(value);
+ Archive->Push(entry);
+ entry->Delete();
+}
+
+void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value)
+{
+ DataEntry *entry = CopyDataEntry(group,elem);
+ 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);
+
+ 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);