/** * Internal method for dumping * * @param object the dataset * @param string the spacer * @return string the dumped dataset */ protected function _dump($dataset, $spacer = '') { $out = ''; foreach ($dataset as $group => $elements) { // Load dictionaries (Forced loading) Nanodicom_Dictionary::load_dictionary($group, TRUE); foreach ($elements as $element => $indexes) { foreach ($indexes as $values) { $elem = $values; $elem['g'] = $group; $elem['e'] = $element; if (!isset($elem['done'])) { // Read value if not read yet $this->_read_value_from_blob($elem, $group, $element); } // Indent back when a delimiter was found. Must be done before dumping. if ($group == Nanodicom::ITEMS_GROUP and in_array($element, array(Nanodicom::ITEM_DELIMITER, Nanodicom::SEQUENCE_DELIMITER))) { $spacer = substr($spacer, 0, -1 * strlen($this->output['spacer'])); } // Start the dataset and dump the current element $out .= $this->output['dataset_begin'] . $this->_dump_element($elem, $spacer); if (count($elem['ds']) > 0) { // Take care of items $out .= $this->_dump($elem['ds'], $spacer . $this->output['spacer']); } // Close the dataset $out .= $this->output['dataset_end']; } unset($values); } unset($element, $indexes); } unset($group, $elements); return $out; }
/** * Create a new Nanodicom_Dictionary instance. There should be only 1 instance running at all times * * @return void */ function __construct() { if (self::$_loaded) { return; } // Load this class only once self::$_loaded = TRUE; // Group 0x0002 Nanodicom_Dictionary::$dict[0x2][0x0] = array('UL', '1', 'MetaElementGroupLength'); Nanodicom_Dictionary::$dict[0x2][0x1] = array('OB', '1', 'FileMetaInformationVersion'); Nanodicom_Dictionary::$dict[0x2][0x2] = array('UI', '1', 'MediaStorageSOPClassUID'); Nanodicom_Dictionary::$dict[0x2][0x3] = array('UI', '1', 'MediaStorageSOPInstanceUID'); Nanodicom_Dictionary::$dict[0x2][0x10] = array('UI', '1', 'TransferSyntaxUID'); Nanodicom_Dictionary::$dict[0x2][0x12] = array('UI', '1', 'ImplementationClassUID'); Nanodicom_Dictionary::$dict[0x2][0x13] = array('SH', '1', 'ImplementationVersionName'); Nanodicom_Dictionary::$dict[0x2][0x16] = array('AE', '1', 'SourceApplicationEntityTitle'); Nanodicom_Dictionary::$dict[0x2][0x100] = array('UI', '1', 'PrivateInformationCreatorUID'); Nanodicom_Dictionary::$dict[0x2][0x102] = array('OB', '1', 'PrivateInformation'); // Group 0xFFFE // IT = Item // DI = Delimitation Item Nanodicom_Dictionary::$dict[0xfffe][0xe000] = array('IT', '1', 'Item'); Nanodicom_Dictionary::$dict[0xfffe][0xe00d] = array('DI', '1', 'ItemDelimitationItem'); Nanodicom_Dictionary::$dict[0xfffe][0xe0dd] = array('DI', '1', 'SequenceDelimitationItem'); // Minimum set of groups loaded Nanodicom_Dictionary::$_loaded_dictionaries[0x2] = TRUE; Nanodicom_Dictionary::$_loaded_dictionaries[0xfffe] = TRUE; }
/** * Read the value from the blob * * @param object the element array * @param integer the group * @param integer the element * @return void */ protected function _read_value_from_blob(&$elem, $group, $element) { // Load dictionaries (Forced loading) Nanodicom_Dictionary::load_dictionary($group, TRUE); // Save current pointer $current_pointer = $this->_tell(); // Values have not been read $this->_rewind($elem['_off']); // Decode the right VR. list($elem['vr'], $multiplicity, $name) = $this->_decode_vr($group, $element, $elem['_vr'], $elem['len']); // Read the value list($elem['val'], $elem['vr'], $elem['bin'], $elem['ds']) = $this->_read_value($elem['_vr'], $elem['vr'], $elem['len'], $this->_transfer_syntax); // Element has been read. Set to true $elem['done'] = TRUE; // Rewind to previous pointer, we just read and returned everything back to normal $this->_rewind($current_pointer); }