/** * Check if we can understand the message * * @param string $msg The message * * @param CInteropActor $actor The actor * * @param array $pres_contexts The presentation contexts * * @return boolean */ function understand($msg, CInteropActor $actor = null, $pres_contexts = null) { $this->_presentation_contexts = $pres_contexts; if (!$this->isWellFormed($msg)) { return false; } $pdu = CDicomPDUFactory::decodePDU($msg, $this->_presentation_contexts); $pdvs = $pdu->getPDVs(); $msg_types = array(); $msg_classes = array(); foreach ($pdvs as $pdv) { $msg = $pdv->getMessage(); $msg_types[] = $msg->type; $msg_classes[] = get_class($msg); } if ($msg_types[0] == "C-Find-RQ" || $msg_types[0] == "C-Echo-RQ") { if (!$this->_requests) { $this->_requests = array(); } $this->_requests[] = $pdu; } elseif ($msg_types[0] == "C-Echo-RSP" || $msg_types[0] == "C-Find-RSP") { if (!$this->_responses) { $this->_responses = array(); } $this->_responses[] = $pdu; } elseif ($msg_types[0] == "Datas") { if ($this->_responses) { $this->_responses[] = $pdu; } else { $this->_requests[] = $pdu; } } foreach ($this->getFamily() as $_family) { $family_class = new $_family(); $events = $family_class->getEvenements(); if (array_key_exists($msg_types[0], $events)) { $this->_family_message_class = $_family; $this->_family_message = $msg_classes[0]; $this->message_valide = 1; return true; } } return false; }
/** * The action AA-8 * * @param mixed $datas The datas * * @return string * * @see DICOM Standard PS 3.8 Section 9.2 */ protected function doAA8($datas) { $diagnostic = 0; if ($datas && is_integer($datas)) { $diagnostic = $datas; } $pdu = CDicomPDUFactory::encodePDU("07", array("source" => 2, "diagnostic" => $diagnostic)); $this->addMessage($pdu->type_str, $pdu); $this->status = "Aborted"; $this->state = self::STA13; return $pdu->getPacket(); }
/** * Handle a C-Data message, and return the answer * * @param CDicomPDV $find_rq_pdv The PDV who contains the C-Find-RQ message * @param CDicomPDV $find_data_pdv The PDV who contains the C-Find-Data message * @param CExchangeDicom $dicom_exchange The Exchange Dicom * * @todo Le code est spécifique à la Source, il faudrait le rendre générique * * @return array */ protected static function handleCDatas($find_rq_pdv, $find_data_pdv, $dicom_exchange) { $msg_rq = $find_rq_pdv->getMessage(); $msg_data = $find_data_pdv->getMessage(); /** If the message is a request : **/ if (is_null($dicom_exchange->_responses)) { $requested_datas = $msg_data->getRequestedDatas(); $sender = $dicom_exchange->loadRefSender(); if (!$sender->_id) { return array("event" => "AAbort_Prepared", "datas" => 5); } /* Loading the objects linked to the Dicom sender */ $linked_objects = CObjectToInteropSender::loadAllObjectsFor($sender->_id); $find_rsp_pending_datas = array("PDVs" => array(array("pres_context_id" => $find_data_pdv->getPresContextId(), "message_control_header" => 0x3, "message" => array("type" => 0x8020, "datas" => array("affected_sop_class" => $msg_rq->getAffectedSopClass()->getValue(), "command_field" => 0x8020, "message_id_request" => $msg_rq->getMessageId()->getValue(), "command_data_set" => 0xfefe, "status" => 0xff00))))); /* Encoding the PDU that separate the patients data */ $find_rsp_pending = CDicomPDUFactory::encodePDU(0x4, $find_rsp_pending_datas, $dicom_exchange->_presentation_contexts); $calling_ae_title = self::getRequestedAETitle($requested_datas); $modality = self::getRequestedModality($requested_datas, $dicom_exchange); /** Getting the requested encoding **/ $encoding = null; $rq_datasets = $find_data_pdv->getMessage()->getDatasets(); if (isset($rq_datasets[0x8][0x5])) { $encoding_dataset = $rq_datasets[0x8][0x5]; $encoding = $encoding_dataset->getValue(); } $responses = array(); /* Loading the objects (CSejour or COperation) from the linked objects */ $objects = self::loadObjectsFromLinkedObjects($linked_objects); if ($objects) { foreach ($objects as $_object) { $responses[] = $find_rsp_pending; $find_rsp_datas = array("PDVs" => array(array("pres_context_id" => $find_data_pdv->getPresContextId(), "message_control_header" => 0x2, "message" => array("type" => "data", "datas" => self::getDataFromObject($_object, $encoding, $modality, $calling_ae_title, $dicom_exchange->getConfigs()))))); $responses[] = CDicomPDUFactory::encodePDU(0x4, $find_rsp_datas, $dicom_exchange->_presentation_contexts); } } $find_rsp_success_datas = array("PDVs" => array(array("pres_context_id" => $find_data_pdv->getPresContextId(), "message_control_header" => 0x3, "message" => array("type" => 0x8020, "datas" => array("affected_sop_class" => $msg_rq->getAffectedSopClass()->getValue(), "command_field" => 0x8020, "message_id_request" => $msg_rq->getMessageId()->getValue(), "command_data_set" => 0x101, "status" => 0x0))))); $responses[] = CDicomPDUFactory::encodePDU(0x4, $find_rsp_success_datas, $dicom_exchange->_presentation_contexts); if (!$dicom_exchange->_responses) { $dicom_exchange->_responses = $responses; } else { array_merge($dicom_exchange->_responses, $responses); } return array("event" => "PDataTF_Prepared", "datas" => $responses); } else { /** The message is a response : **/ return array("event" => "AAbort_Prepared", "datas" => 5); } }