/**
  * Encode the message
  * 
  * @param CDicomStreamWriter $stream_writer   The stream writer
  * 
  * @param string             $transfer_syntax The UID of the transfer syntax
  * 
  * @return null
  */
 function encode(CDicomStreamWriter $stream_writer, $transfer_syntax)
 {
     $handle = fopen("php://temp", "w+");
     $group_stream = new CDicomStreamwriter($handle);
     $this->setAffectedSopClass();
     $this->setCommandField();
     $this->setCommandDataSet();
     $this->command_field->encode($group_stream, $transfer_syntax);
     $this->message_id_request->encode($group_stream, $transfer_syntax);
     $this->command_data_set->encode($group_stream, $transfer_syntax);
     $group_length = strlen($group_stream->buf);
     $this->setCommandGroupLength($group_length);
     $this->command_group_length->encode($stream_writer, $transfer_syntax);
     $this->setContent($group_stream->buf);
     $stream_writer->write($group_stream->buf);
     $group_stream->close();
 }
 /**
  * Encode the datas, depending on the transfer syntax
  * 
  * @param CDicomStreamWriter $stream_writer   The stream writer
  * 
  * @param string             $transfer_syntax The UID of the transfer syntax
  * 
  * @return null
  */
 function encode(CDicomStreamWriter $stream_writer, $transfer_syntax)
 {
     foreach ($this->attributes as $group_number => $group) {
         $this->datasets[$group_number] = array();
         $handle = fopen("php://temp", "w+");
         $group_writer = new CDicomStreamWriter($handle);
         foreach ($group as $element_number => $value) {
             $dataset = new CDicomDataSet(array("group_number" => $group_number, "element_number" => $element_number, "value" => $value));
             $dataset->encode($group_writer, $transfer_syntax);
             $this->datasets[$group_number][$element_number] = $dataset;
         }
         $length = strlen($group_writer->buf);
         $group_length_dataset = new CDicomDataSet(array("group_number" => $group_number, "element_number" => 0x0, "value" => $length));
         $group_length_dataset->encode($stream_writer, $transfer_syntax);
         $this->datasets[$group_number][0x0] = $group_length_dataset;
         $stream_writer->write($group_writer->buf);
         $group_writer->close();
     }
     $this->setContent($stream_writer->buf);
 }
예제 #3
0
 /**
  * Encode the value
  * 
  * @param CDicomStreamWriter $stream_writer The stream writer
  * 
  * @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 encodeValue(CDicomStreamWriter $stream_writer, $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':
             if ($this->length & 1) {
                 $this->value .= " ";
                 $this->length++;
             }
             $stream_writer->writeString($this->value, $this->length);
             break;
         case 'AT':
             $stream_writer->writeUInt16($this->value[0], $endianness);
             $stream_writer->writeUInt16($this->value[1], $endianness);
             break;
         case 'SL':
             $stream_writer->writeInt32($this->value, $endianness);
             break;
         case 'SS':
             $stream_writer->writeInt16($this->value, $endianness);
             break;
         case 'UI':
             $stream_writer->writeUID($this->value, $this->length);
             if ($this->length & 1) {
                 $stream_writer->writeUInt8(0x0);
                 $this->length++;
             }
             break;
         case 'UL':
             $stream_writer->writeUInt32($this->value, $endianness);
             break;
         case 'US':
             $stream_writer->writeUInt16($this->value, $endianness);
             break;
         case 'SQ':
             $value_stream = new CDicomStreamWriter();
             $value_tmp = array();
             if (is_array($this->value)) {
                 foreach ($this->value as $_sequence) {
                     $sequence = array();
                     $sequence_stream = new CDicomStreamWriter();
                     foreach ($_sequence as $_item) {
                         $dataset = new CDicomDataSet($_item);
                         $dataset->encode($sequence_stream, $this->transfer_syntax);
                         $sequence[] = $dataset;
                     }
                     $sequence_length = strlen($sequence_stream->buf);
                     $value_stream->writeUInt16(0xfffe, $endianness);
                     $value_stream->writeUInt16(0xe000, $endianness);
                     $value_stream->writeUInt32($sequence_length, $endianness);
                     $value_stream->write($sequence_stream->buf, $sequence_length);
                     $this->length += 8 + $sequence_length;
                     $value_tmp[] = $sequence;
                 }
                 $stream_writer->write($value_stream->buf, $this->length);
                 $this->value = $value_tmp;
             } else {
                 $this->length = 8;
                 $stream_writer->writeUInt16(0xfffe, $endianness);
                 $stream_writer->writeUInt16(0xe000, $endianness);
                 $stream_writer->writeUInt32(0, $endianness);
             }
             break;
         default:
             break;
     }
 }