public function send($response, $inputs, $messageId = null)
 {
     if ($messageId === null) {
         $messageId = $this->messageId;
     }
     if (!isset($this->_validResponses[$response])) {
         $response = 'approved';
     }
     $messaging = new Messaging();
     $messaging->messagingId = $messageId;
     if (!$messaging->populate()) {
         trigger_error(__('Refill request messaging does not exists.'), E_USER_NOTICE);
         return false;
     }
     $refillRequest = new MedicationRefillRequest();
     $refillRequest->messageId = $messageId;
     if (!$refillRequest->populate()) {
         trigger_error(__('Refill request does not exists.'), E_USER_NOTICE);
         return false;
     }
     $data = array();
     //$data['writtenDate'] = date('Ymd',strtotime($inputs['datePrescribed']))
     $data['writtenDate'] = date('Ymd');
     // should be set to the date the prescriber authorized the renewal of the prescription
     $data['message'] = $messaging->rawMessage;
     if ($response == 'approved' && $refillRequest->medication->isScheduled()) {
         $response = 'denied';
         $inputs['note'] = 'This Refill Request is for a controlled substance (Schedule III - V). The approved controlled substance prescription is being faxed to your pharmacy';
         $inputs['refills'] = 0;
     }
     $arrResponse = array();
     switch ($response) {
         case 'approved':
             $this->response = 'Approved';
             $refills = $messaging->refills;
             $newRefills = (int) $inputs['refills'];
             if ($refills != $newRefills) {
                 if ($refills != 0) {
                     $this->response = 'ApprovedWithChanges';
                 }
                 //else {
                 $data['refills'] = $newRefills;
                 //}
             }
             $this->message = $inputs['note'];
             $arrResponse[$this->response] = array('Note' => $this->message);
             break;
         case 'denied':
             // quantity should be set to zero
             $data['refills'] = 0;
             if (isset($inputs['note'])) {
                 $this->response = 'DeniedNewPrescriptionToFollow';
                 $this->message = $inputs['note'];
                 $arrResponse[$this->response] = array('Note' => $this->message);
                 //$data['medicationId'] = (int)$inputs['medicationId'];
             } else {
                 $this->response = 'Denied';
                 //$this->message = $inputs['reasonCode'].':'.$inputs['reason']; // empty reason
                 $this->message = $inputs['reason'];
                 $arrResponse[$this->response] = array('DenialReasonCode' => $inputs['reasonCode'], 'DenialReason' => $inputs['reason']);
             }
             break;
     }
     $data['response'] = $arrResponse;
     $data['type'] = 'refill';
     $ret = ePrescribe::sendResponse($data, $messaging);
     if ($ret === true) {
         $this->dateTime = date('Y-m-d H:i:s');
         $this->persist();
         $refillRequest->action = $this->_validResponses[$response];
         $refillRequest->status = 'RESPONDED';
         $refillRequest->persist();
     }
     return $ret;
 }