/**
  * 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;
 }
 /**
  * Return a string representation of the class
  * 
  * @return string
  */
 function __toString()
 {
     return "<table>\n              <tr>\n                <th>Tag</th><th>Name</th><th>VR</th><th>Length</th><th>Value</th>\n              </tr>\n              <tr>" . $this->command_group_length->__toString() . "</tr>\n              <tr>" . $this->affected_sop_class->__toString() . "</tr>\n              <tr>" . $this->command_field->__toString() . "</tr>\n              <tr>" . $this->message_id->__toString() . "</tr>\n              <tr>" . $this->command_data_set->__toString() . "</tr>\n            </table>";
 }
 /**
  * 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();
     }
 }
Esempio n. 4
0
 /**
  * Decode the value
  * 
  * @param CDicomStreamReader $stream_reader The stream reader
  * @param string             $endianness    The endianness, must be equal to "BE" (Big Endian) or "LE" (Little Endian)
  * 
  * @return null
  * 
  * @todo traiter les cas FL, FD, OB, OW, OF, SQ
  */
 protected function decodeValue(CDicomStreamReader $stream_reader, $endianness)
 {
     switch ($this->vr) {
         case 'AE':
         case 'AS':
         case 'CS':
         case 'DA':
         case 'DS':
         case 'DT':
         case 'FL':
         case 'FD':
         case 'IS':
         case 'LO':
         case 'LT':
         case 'OB':
         case 'OF':
         case 'OX':
         case 'OW':
         case 'PN':
         case 'SH':
         case 'ST':
         case 'TM':
         case 'UN':
         case 'UT':
             $this->value = $stream_reader->readString($this->length);
             break;
         case 'AT':
             $this->value = array();
             $this->value[] = $stream_reader->readUInt16($endianness);
             $this->value[] = $stream_reader->readUInt16($endianness);
             break;
         case 'SL':
             $this->value = $stream_reader->readInt32($endianness);
             break;
         case 'SS':
             $this->value = $stream_reader->readInt16($endianness);
             break;
         case 'UI':
             $this->value = $stream_reader->readUID($this->length);
             break;
         case 'UL':
             $this->value = $stream_reader->readUInt32($endianness);
             break;
         case 'US':
             $this->value = $stream_reader->readUInt16($endianness);
             break;
         case 'SQ':
             $tmp_value = array();
             $value_stream = new CDicomStreamReader();
             /** Sequence of items with undefined length **/
             if ($this->length == 0xffffffff) {
                 $delimiter = new CDicomDataSet();
                 $delimiter->decode($stream_reader, $this->transfer_syntax);
                 while ($delimiter->group_number == 0xfffe && $delimiter->element_number != 0xe0dd) {
                     $sequence = array($delimiter);
                     if ($delimiter->length == 0xffffffff) {
                         $item_delimiter = new CDicomDataSet();
                         $item_delimiter->decode($stream_reader, $this->transfer_syntax);
                         $sequence[] = $item_delimiter;
                         while ($item_delimiter->group_number == 0xfffe && $item_delimiter->element_number != 0xe00d) {
                             $dataset = new CDicomDataSet();
                             $dataset->decode($value_stream, $this->transfer_syntax);
                             $sequence[] = $dataset;
                             $item_delimiter = new CDicomDataSet();
                             $item_delimiter->decode($stream_reader, $this->transfer_syntax);
                             $sequence[] = $item_delimiter;
                         }
                     } else {
                         $sequence_end = $value_stream->getPos();
                         // + $sequence_length;
                         while ($value_stream->getPos() < $sequence_end) {
                             $dataset = new CDicomDataSet();
                             $dataset->decode($value_stream, $this->transfer_syntax);
                             $sequence[] = $dataset;
                         }
                     }
                     $delimiter = new CDicomDataSet();
                     $delimiter->decode($stream_reader, $this->transfer_syntax);
                     $sequence[] = $delimiter;
                     $tmp_value[] = $sequence;
                 }
             } else {
                 $content = $stream_reader->read($this->length);
                 fwrite($value_stream->stream, $content, $this->length);
                 $value_stream->rewind();
                 while ($value_stream->getPos() < $this->length) {
                     $value_stream->skip(4);
                     $sequence_length = $value_stream->readUInt32($endianness);
                     $sequence = array();
                     $sequence_end = $value_stream->getPos() + $sequence_length;
                     while ($value_stream->getPos() < $sequence_end) {
                         $dataset = new CDicomDataSet();
                         $dataset->decode($value_stream, $this->transfer_syntax);
                         $sequence[] = $dataset;
                     }
                     $tmp_value[] = $sequence;
                 }
             }
             $this->value = $tmp_value;
             break;
         default:
             break;
     }
 }
 /**
  * Return a string representation of the class
  * 
  * @return string
  */
 function __toString()
 {
     return "C-Cancel-Find-RQ :\n            <table>\n              <tr>\n                <th>Tag</th><th>Name</th><th>VR</th><th>Length</th><th>Value</th>\n              </tr>\n              <tr>" . $this->command_group_length->__toString() . "</c>\n              <tr>" . $this->command_field->__toString() . "</tr>\n              <tr>" . $this->message_id_request->__toString() . "</tr>\n              <tr>" . $this->command_data_set->__toString() . "</tr>\n            </table>";
 }