Exemplo n.º 1
0
 public static function handlereFaxAct(Audit $audit, array $sourceData)
 {
     if ($audit->objectClass != 'ESignature') {
         return false;
     }
     $eSignature = new ESignature();
     $eSignature->eSignatureId = $audit->objectId;
     $eSignature->populate();
     if ($eSignature->objectClass != 'Medication') {
         return false;
     }
     $medication = new Medication();
     $medication->medicationId = $eSignature->objectId;
     $medication->populate();
     $audit = $sourceData['_audit'];
     $messaging = new Messaging(Messaging::TYPE_OUTBOUND_FAX);
     $messaging->messagingId = (int) $sourceData['transmissionId'];
     $messaging->transmissionId = $messaging->messagingId;
     $messaging->populate();
     $messaging->objectId = $messaging->messagingId;
     $messaging->objectClass = $audit->objectClass;
     $messaging->status = 'Faxed';
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->auditId = $audit->auditId;
     // this must be required for retransmission in case of error
     $messaging->persist();
     $efax = new eFaxOutbound();
     $url = Zend_Registry::get('config')->healthcloud->eFax->outboundUrl;
     $url .= '?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey;
     $efax->setUrl($url);
     $efax->setTransmissionId($sourceData['transmissionId']);
     $efax->setNoDuplicate(eFaxOutbound::NO_DUPLICATE_ENABLE);
     $efax->setDispositionMethod('POST');
     // use the default disposition URL
     $dispositionUrl = Zend_Registry::get('config')->healthcloud->eFax->dispositionUrl;
     $efax->setDispositionUrl($dispositionUrl);
     //$efax->setDispositionMethod('EMAIL');
     //$efax->addDispositionEmail('Arthur Layese','*****@*****.**');
     foreach ($sourceData['recipients'] as $recipient) {
         if ($messaging->resend && strlen($messaging->faxNumber) > 9) {
             // supersedes fax number from messaging
             $recipient['fax'] = $messaging->faxNumber;
         }
         $efax->addRecipient($recipient['fax'], $recipient['name'], $recipient['company']);
     }
     foreach ($sourceData['files'] as $file) {
         $efax->addFile($file['contents'], $file['type']);
     }
     $ret = $efax->send();
     if (!$ret) {
         $messaging->status = 'Fax Error';
         $messaging->note = implode(PHP_EOL, $efax->getErrors());
     } else {
         $messaging->docid = $efax->getDocId();
         $messaging->status = 'Fax Sent';
         $messaging->note = '';
     }
     if ($messaging->resend) {
         $messaging->resend = 0;
     }
     $messaging->retries++;
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->persist();
     return true;
 }