/** * Decode a message, and return the corresponding object * * @param CDicomStreamReader $stream_reader The stream reader * * @param integer $control_header The control header * * @param string $transfer_syntax The transfer syntax * * @return object */ static function decodeMessage(CDicomStreamReader $stream_reader, $control_header, $transfer_syntax) { if ($control_header == 0 || $control_header == 2) { $message_class = self::getMessageClass("data"); } else { $datasets = array(); $dataset = new CDicomDataSet(); $dataset->decode($stream_reader, $transfer_syntax); $datasets[$dataset->getElementNumber()] = $dataset; $dataset = new CDicomDataSet(); $dataset->decode($stream_reader, $transfer_syntax); $datasets[$dataset->getElementNumber()] = $dataset; $dataset = new CDicomDataSet(); $dataset->decode($stream_reader, $transfer_syntax); $datasets[$dataset->getElementNumber()] = $dataset; $stream_reader->rewind(); if (!array_key_exists(0x100, $datasets)) { return null; } $message_class = self::getMessageClass($datasets[0x100]->getValue()); } $message = new $message_class(); $message->decode($stream_reader, $transfer_syntax); return $message; }
/** * Check if the message is well formed * * @return boolean */ function isWellFormed() { if ($this->command_group_length->getGroupNumber() != 0x0 || $this->command_group_length->getElementNumber() != 0x0) { return false; } if ($this->command_field->getGroupNumber() != 0x0 || $this->command_field->getElementNumber() != 0x100) { return false; } if ($this->message_id_request->getGroupNumber() != 0x0 || $this->message_id_request->getElementNumber() != 0x120) { return false; } if ($this->command_data_set->getGroupNumber() != 0x0 || $this->command_data_set->getElementNumber() != 0x800) { return false; } return true; }
/** * Check if the message is well formed * * @return boolean */ function isWellFormed() { if ($this->command_group_length->getGroupNumber() != 0x0 || $this->command_group_length->getElementNumber() != 0x0) { return false; } if ($this->affected_sop_class->getGroupNumber() != 0x0 || $this->affected_sop_class->getElementNumber() != 0x2) { return false; } if ($this->command_field->getGroupNumber() != 0x0 || $this->command_field->getElementNumber() != 0x100) { return false; } if ($this->message_id->getGroupNumber() != 0x0 || $this->message_id->getElementNumber() != 0x110) { return false; } if ($this->command_data_set->getGroupNumber() != 0x0 || $this->command_data_set->getElementNumber() != 0x800) { return false; } return true; }
/** * Decode the datas, depending on the transfer syntax * * @param CDicomStreamReader $stream_reader The stream writer * * @param string $transfer_syntax The UID of the transfer syntax * * @return void */ function decode(CDicomStreamReader $stream_reader, $transfer_syntax) { if (!$transfer_syntax) { return; } $this->attributes = array(); $this->datasets = array(); $stream_length = $stream_reader->getStreamLength(); while ($stream_reader->getPos() < $stream_length) { $dataset = new CDicomDataSet(); $dataset->decode($stream_reader, $transfer_syntax); $group = $dataset->getGroupNumber(); $element = $dataset->getElementNumber(); if (!array_key_exists($group, $this->datasets)) { $this->datasets[$group] = array(); } if (!array_key_exists($group, $this->attributes)) { $this->attributes[$group] = array(); } $this->datasets[$group][$element] = $dataset; $this->attributes[$group][$element] = $dataset->getValue(); } }