示例#1
0
 /**
  * @param DoctorQuestion $question        - Question Object
  * @param integer  $practoAccountId - Practo Account Id of Doctor
  * @param string   $text            - Message to be sent to doctor
  */
 public function createDoctorNotification($question, $practoAccountId, $text = "A question has been assigned to you")
 {
     $doctorNotification = new DoctorNotification();
     $doctorNotification->setQuestion($question);
     $doctorNotification->setPractoAccountId($practoAccountId);
     $doctorNotification->setText($text);
     $this->helper->persist($doctorNotification, true);
 }
示例#2
0
 /**
  * @param array $postData
  *
  * @return \ConsultBundle\Response\ReplyResponseObject
  * @throws \ConsultBundle\Manager\ValidationError
  * @throws \HttpException
  */
 public function patchDoctorReply($postData)
 {
     $practoAccountId = $postData['practo_account_id'];
     if (array_key_exists("doctor_reply", $postData)) {
         $doctorReply = $postData['doctor_reply'];
     } else {
         throw new \HttpException("doctor_reply is mandatory", Codes::HTTP_BAD_REQUEST);
     }
     $changed = false;
     $this->helper->checkForMandatoryFields(self::$mandatoryFields, $doctorReply);
     //Fetch Doctor Reply
     $id = $doctorReply['id'];
     /**
      * @var DoctorReply $doctorReplyEntity
      */
     $doctorReplyEntity = $this->helper->loadById($id, ConsultConstants::DOCTOR_REPLY_ENTITY_NAME);
     if (empty($doctorReplyEntity)) {
         throw new \HttpException("Not a valid Doctor Reply Id", Codes::HTTP_BAD_REQUEST);
     }
     $ownerId = $doctorReplyEntity->getDoctorQuestion()->getQuestion()->getUserInfo()->getPractoAccountId();
     //Mark As Best Answer
     if (array_key_exists("rating", $doctorReply)) {
         if ($ownerId != $practoAccountId) {
             throw new \HttpException("Only the one who has asked the question can rate it", Codes::HTTP_BAD_REQUEST);
         }
         $doctorReplyEntity->setRating($doctorReply['rating']);
         $changed = true;
         $this->queue->setQueueName(Queue::CONSULT_GCM)->sendMessage(json_encode(array("type" => "consult", "message" => array('text' => "Your answer has been rated by the Asker", 'question_id' => $doctorReplyEntity->getDoctorQuestion()->getId(), 'subject' => $doctorReplyEntity->getDoctorQuestion()->getQuestion()->getSubject(), 'consult_type' => ConsultConstants::PUBLIC_QUESTION_NOTIFICATION_TYPE), "send_to" => "synapse", "account_ids" => array($doctorReplyEntity->getDoctorQuestion()->getPractoAccountId()))));
         $doctorNotification = new DoctorNotification();
         $doctorNotification->setPractoAccountId($doctorReplyEntity->getDoctorQuestion()->getPractoAccountId());
         $doctorNotification->setQuestion($doctorReplyEntity->getDoctorQuestion());
         $doctorNotification->setText("Your answer has been rated by the Asker");
         $this->helper->persist($doctorNotification);
     }
     //Mark the answer as viewed
     if (array_key_exists("viewed", $doctorReply)) {
         if ($ownerId != $practoAccountId) {
             throw new \HttpException("Not the owner of the question", Codes::HTTP_BAD_REQUEST);
         }
         if (!$doctorReplyEntity->getViewedAt()) {
             $doctorReplyEntity->setViewedAt(new \DateTime());
             $changed = true;
         }
     }
     //Vote
     if (array_key_exists("vote", $doctorReply)) {
         $vote = $doctorReply['vote'];
         $er = $this->helper->getRepository(ConsultConstants::DOCTOR_REPLY_VOTE_ENTITY);
         $doctorReplyVoteEntity = $er->findOneBy(array("practoAccountId" => $practoAccountId, "reply" => $doctorReplyEntity));
         if (!$doctorReplyVoteEntity) {
             $doctorReplyVoteEntity = new DoctorReplyVote();
             $doctorReplyVoteEntity->setPractoAccountId($practoAccountId);
             $doctorReplyVoteEntity->setReply($doctorReplyEntity);
             $doctorReplyVoteEntity->setVote($vote);
             $doctorReplyEntity->addVote($doctorReplyVoteEntity);
             $changed = true;
         } else {
             $doctorReplyVoteEntity->setVote($vote);
             $this->helper->persist($doctorReplyVoteEntity);
             $changed = true;
         }
     }
     if (array_key_exists('flag', $doctorReply) && Utility::toBool($doctorReply['flag'])) {
         $er = $this->helper->getRepository(ConsultConstants::DOCTOR_REPLY_FLAG_ENTITY_NAME);
         $flag = $er->findOneBy(array('doctorReply' => $doctorReplyEntity, 'practoAccountId' => $_SESSION['authenticated_user']['id'], 'softDeleted' => 0));
         if (!empty($flag)) {
             @($error['error'] = 'The user has already flagged this comment');
             throw new ValidationError($error);
         }
         $flag = new DoctorReplyFlag();
         $flag->setDoctorReply($doctorReplyEntity);
         if (array_key_exists('flag_code', $doctorReply) && !empty($doctorReply['flag_code'])) {
             $flag->setFlagCode(trim($doctorReply['flag_code']));
         } else {
             @($error['error'] = 'flag_code is mandatory');
             throw new ValidationError($error);
         }
         if (array_key_exists('flag_text', $doctorReply) && !empty($doctorReply['flag_text'])) {
             if ($doctorReply['flag_code'] != 'OTH') {
                 @($error['error'] = 'Flag Text is required only for code Other');
                 throw new ValidationError($error);
             }
             $flag->setFlagText($doctorReply['flag_text']);
         } else {
             if ($doctorReply['flag_code'] === 'OTH') {
                 @($error['error'] = 'flag_text is mandatory for code OTH');
                 throw new ValidationError($error);
             }
         }
         $flag->setPractoAccountId($practoAccountId);
         // $this->validate($flag);
         $this->helper->persist($flag);
         $changed = true;
         //return $flag;
     } elseif (array_key_exists('flag', $doctorReply) && !Utility::toBool($doctorReply['flag'])) {
         $er = $this->helper->getRepository(ConsultConstants::DOCTOR_REPLY_FLAG_ENTITY_NAME);
         $flag = $er->findOneBy(array('doctorReply' => $doctorReplyEntity, 'practoAccountId' => $_SESSION['authenticated_user']['id'], 'softDeleted' => 0));
         if (empty($flag)) {
             @($error['error'] = 'The user has not flagged the reply');
             throw new ValidationError($error);
         }
         $flag->setBoolean('softDeleted', true);
         $this->helper->persist($flag);
         $changed = true;
     } elseif (array_key_exists('flag', $doctorReply)) {
         @($error['error'] = 'Not a correct value for flag');
         throw new ValidationError($error);
     }
     if ($changed) {
         $this->validate($doctorReplyEntity);
         $this->helper->persist($doctorReplyEntity, true);
     }
     return $this->getReplyById($id, $practoAccountId);
 }