Ejemplo n.º 1
0
 /**
  * Get the type of the PDU, and create the corresponding CDicomPDU
  * 
  * @param string $pdu_content           The datas sent by the client
  * 
  * @param array  $presentation_contexts The presentation contexts
  * 
  * @return CDicomPDU The PDU
  */
 static function decodePDU($pdu_content, $presentation_contexts = null)
 {
     $stream = fopen("php://temp", 'w+');
     fwrite($stream, $pdu_content);
     $stream_reader = new CDicomStreamReader($stream);
     $stream_reader->rewind();
     $pdu_class = self::readType($stream_reader);
     if ($pdu_class === false) {
         return null;
     }
     $length = self::readLength($stream_reader);
     $pdu = new $pdu_class(array("length" => $length));
     if ($pdu_class == "CDicomPDUPDataTF") {
         $pdu->setPresentationContexts($presentation_contexts);
     }
     $pdu->decodePDU($stream_reader);
     $stream_reader->close();
     $pdu->setPacket($stream_reader->buf);
     return $pdu;
 }
Ejemplo n.º 2
0
 /**
  * Decode the PDU
  * 
  * @param CDicomStreamReader $stream_reader The stream reader
  *  
  * @return null
  */
 function decodePDU(CDicomStreamReader $stream_reader)
 {
     $this->pdvs = array();
     $stream_reader->setStreamLength($this->getTotalLength());
     while ($stream_reader->getPos() < $stream_reader->getStreamLength()) {
         $pdv_length = $stream_reader->readUInt32();
         // + 4;
         //$stream_reader->seek(-4);
         $pdv_content = $stream_reader->read($pdv_length);
         $pdv_handle = fopen('php://temp', 'w+');
         fwrite($pdv_handle, $pdv_content, $pdv_length);
         $pdv_stream = new CDicomStreamReader($pdv_handle);
         $pdv_stream->rewind();
         $pdv = new CDicomPDV(array("presentation_contexts" => $this->presentation_contexts, "length" => $pdv_length));
         $pdv->decode($pdv_stream);
         $this->pdvs[] = $pdv;
     }
 }
Ejemplo n.º 3
0
 /**
  * Check if the message is well formed
  * 
  * @param string        $msg   The message
  * 
  * @param CInteropActor $actor The actor who sent the message
  * 
  * @return boolean
  */
 function isWellFormed($msg, CInteropActor $actor = null)
 {
     $stream = fopen("php://temp", 'w+');
     fwrite($stream, $msg);
     $stream_reader = new CDicomStreamReader($stream);
     $stream_reader->rewind();
     $type = $stream_reader->readHexByte();
     if ($type != "04") {
         $stream_reader->close();
         return false;
     }
     $stream_reader->skip(1);
     $length = $stream_reader->readUInt32();
     $stream_reader->close();
     if (strlen($msg) != $length + 6) {
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Decode the PDV
  * 
  * @param CDicomStreamReader $stream_reader The stream reader
  * 
  * @return null
  */
 function decode(CDicomStreamReader $stream_reader)
 {
     // On fait un stream temp pour le message
     //$this->length = $stream_reader->readUInt32();
     $this->pres_context_id = $stream_reader->readUInt8();
     $this->message_control_header = $stream_reader->readUInt8();
     $message_length = $this->length - 2;
     $message_content = $stream_reader->read($message_length);
     $handle = fopen("php://temp", "w+");
     fwrite($handle, $message_content);
     $message_stream = new CDicomStreamReader($handle);
     $message_stream->rewind();
     $message_stream->setStreamLength($message_length);
     if (!($this->transfer_syntax = $this->getTransferSyntax())) {
         /** @todo throw exception **/
     }
     $this->message = CDicomMessageFactory::decodeMessage($message_stream, $this->message_control_header, $this->transfer_syntax);
     $message_stream->close();
     $content = substr($stream_reader->buf, 13) . $message_stream->buf;
     $this->setBinaryContent($content);
 }