/**
  * @param integer $practoAccountId - Practo Account Id of User
  * @param bool    $viewed          - Notification already viewed or not
  * @param integer $limit           - limit of query
  * @param integer $offset          - offset of query
  * @param integer $sortBy          - Sort By query
  *
  * @return Array
  */
 public function findUserNotificationByFilters($practoAccountId, $viewed, $limit, $offset, $sortBy)
 {
     $qb = $this->_em->createQueryBuilder();
     $qb->select(array('un'))->from(ConsultConstants::USER_NOTIFICATION_ENTITY_NAME, 'un')->where('un.practoAccountId = :practoAccountId')->setParameter('practoAccountId', $practoAccountId)->setMaxResults($limit)->setFirstResult($offset);
     if (isset($viewed)) {
         $qb->andWhere('un.viewed = :viewed');
         if (Utility::toBool($viewed)) {
             $viewed = 1;
         } else {
             $viewed = 0;
         }
         $qb->setParameter('viewed', $viewed);
     }
     if (isset($sortBy)) {
         if ($sortBy == "modified_at") {
             $qb->orderBy('un.modifiedAt', 'DESC');
         }
         if ($sortBy == "created_at") {
             $qb->orderBy('un.createdAt', 'DESC');
         }
     }
     $notificationList = $qb->getQuery()->getResult();
     $paginator = new Paginator($qb->getQuery());
     $count = count($paginator);
     if (is_null($notificationList)) {
         return null;
     }
     return array($notificationList, $count);
 }
Example #2
0
 /**
  * @param array  $requestParams
  * @param string $profileToken
  *
  * @return \ConsultBundle\Entity\UserInfo|mixed
  * @throws \ConsultBundle\Manager\ValidationError
  */
 public function add($requestParams, $profileToken)
 {
     $error = array();
     if (!array_key_exists('practo_account_id', $requestParams)) {
         @($error['practo_account_id'] = 'This value cannot be blank');
         throw new ValidationError($error);
     }
     if (array_key_exists('id', $requestParams) and !empty($requestParams['id'])) {
         $userEntry = $this->helper->loadById($requestParams['id'], ConsultConstants::USER_ENTITY_NAME);
         if (empty($userEntry)) {
             @($error['error'] = 'Invalid user_info id');
             throw new ValidationError($error);
         }
         if ($userEntry->getPractoAccountId() != $requestParams['practo_account_id']) {
             @($error['error'] = 'This user_info id does not belong to this practo_account_id');
             throw new ValidationError($error);
         }
         if (!$userEntry->isIsRelative()) {
             $this->updateAccountsUtil->updateAccountDetails($profileToken, $requestParams);
         }
     } else {
         $userEntry = new UserInfo();
         if (array_key_exists('is_relative', $requestParams) and Utility::toBool($requestParams['is_relative'])) {
             if (!array_key_exists('name', $requestParams) or array_key_exists('name', $requestParams) and empty($requestParams['name'])) {
                 @($error['name'] = 'This value cannot be blank when a new profile is being created');
             }
             if (!array_key_exists('gender', $requestParams) or array_key_exists('gender', $requestParams) and empty($requestParams['gender'])) {
                 @($error['gender'] = 'This value cannot be blank when a new profile is being created');
             }
             if (!array_key_exists('age', $requestParams) or array_key_exists('age', $requestParams) and empty($requestParams['age'])) {
                 @($error['age'] = 'This value cannot be blank when a new profile is being created');
             }
             if (count($error) > 0) {
                 throw new ValidationError($error);
             }
         } else {
             $er = $this->helper->getRepository(ConsultConstants::USER_ENTITY_NAME);
             $entry = $er->findOneBy(array('practoAccountId' => $requestParams['practo_account_id'], 'isRelative' => 0));
             if (!empty($entry)) {
                 $userEntry = $entry;
             } else {
                 $userJson = $_SESSION['authenticated_user'];
                 if (empty($userJson['gender']) && (!array_key_exists('gender', $requestParams) or array_key_exists('gender', $requestParams) and empty($requestParams['gender']))) {
                     @($error['gender'] = 'This value cannot be blank when a new profile is being created');
                 }
                 if (empty($userJson['dob']) && (!array_key_exists('age', $requestParams) or array_key_exists('age', $requestParams) and empty($requestParams['age']))) {
                     @($error['age'] = 'This value cannot be blank when a new profile is being created');
                 }
                 if (count($error) > 0) {
                     throw new ValidationError($error);
                 }
             }
             $this->updateAccountsUtil->updateAccountDetails($profileToken, $requestParams);
         }
     }
     $this->updateFields($userEntry, $requestParams);
     $this->helper->persist($userEntry, true);
     return $userEntry;
 }
 /**
  * @param bool $throwException
  *
  * @return null
  */
 protected function authenticate($throwException = true)
 {
     if (Utility::toBool($_SESSION['validated'])) {
         return $_SESSION['authenticated_user']['id'];
     } elseif ($throwException) {
         throw new HttpException(Codes::HTTP_FORBIDDEN, "Unauthorised Access");
     }
     return null;
 }
Example #4
0
 /**
  * @param integer   $practoAccountId - User's id
  * @param bool      $bookmark        - require bookmark value
  * @param string    $state           - state of the question
  * @param string    $category        - category of question
  * @param \DateTime $modifiedAfter   - time for the filter
  * @param int       $limit           - limit
  * @param integer   $offset          - offset
  * @return array (Question,count) - list of question objects and the count
  */
 public function findQuestionsByFilters($practoAccountId, $bookmark, $state, $category, $modifiedAfter, $limit, $offset)
 {
     $qb = $this->_em->createQueryBuilder();
     $qb->select('q as question', 'count(b.id) AS bookmarkCount')->from(ConsultConstants::QUESTION_ENTITY_NAME, 'q')->leftJoin(ConsultConstants::QUESTION_BOOKMARK_ENTITY_NAME, 'b', 'WITH', 'q = b.question AND b.softDeleted = 0 ')->where('q.softDeleted = 0')->orderBy('q.createdAt', 'DESC')->groupBy('q')->setMaxResults($limit)->setFirstResult($offset);
     if (isset($modifiedAfter)) {
         $qb->andWhere('q.modifiedAt > :modifiedAt');
         $qb->setParameter('modifiedAt', $modifiedAfter);
     }
     if (isset($state)) {
         $qb->andWhere('q.state IN(:state)');
         $qb->setParameter('state', $state);
     }
     if (isset($category)) {
         $qb->innerJoin(ConsultConstants::QUESTION_TAG_ENTITY_NAME, 't', 'WITH', 'q = t.question');
         $qb->andWhere('t.tag IN(:category)');
         $qb->setParameter('category', $category);
     }
     if (isset($practoAccountId)) {
         if (isset($bookmark) and Utility::toBool($bookmark)) {
             $qb->innerJoin(ConsultConstants::USER_ENTITY_NAME, 'u', 'WITH', 'u = q.userInfo');
             $qb->andWhere('u.practoAccountId = :practoAccountID');
             $qb->andWhere('u.softDeleted = 0 ');
             $qb->setParameter('practoAccountID', $practoAccountId);
         } elseif (isset($bookmark) and $bookmark == "true") {
             //$qb->innerJoin(ConsultConstants::QUESTION_BOOKMARK_ENTITY_NAME, 'b', 'WITH', 'q = b.question AND b.softDeleted = 0 ');
             $qb->andWhere('b.practoAccountId = :practoAccountId');
             $qb->setParameter('practoAccountId', $practoAccountId);
         } else {
             $qb->leftJoin(ConsultConstants::USER_ENTITY_NAME, 'u', 'WITH', ' u=q.userInfo AND u.softDeleted = 0 ');
             //$qb->leftJoin(ConsultConstants::QUESTION_BOOKMARK_ENTITY_NAME, 'b', 'WITH', 'q = b.question AND b.softDeleted = 0 ');
             $qb->andWhere(' u.practoAccountId = :practoAccountId OR b.practoAccountId = :practoAccountId');
             $qb->setParameter('practoAccountId', $practoAccountId);
         }
     }
     $questionList = $qb->getQuery()->getArrayResult();
     $paginator = new Paginator($qb->getQuery(), $fetchJoinCollection = true);
     $count = count($paginator);
     if (is_null($questionList)) {
         return null;
     }
     return array("questions" => $questionList, "count" => $count);
 }
 /**
  * @param array $requestParams
  *
  * @return array|\ConsultBundle\Entity\QuestionCommentFlag|\ConsultBundle\Entity\QuestionCommentFlag[]
  * @throws \ConsultBundle\Manager\ValidationError
  */
 public function patch($requestParams)
 {
     if (!array_key_exists('question_comment_id', $requestParams)) {
         @($error['question_comment_id'] = 'This value cannot be blank');
         throw new ValidationError($error);
     }
     if (!array_key_exists('practo_account_id', $requestParams)) {
         @($error['practo_account_id'] = 'This value cannot be blank');
         throw new ValidationError($error);
     }
     $questionComment = $this->helper->loadById($requestParams['question_comment_id'], ConsultConstants::QUESTION_COMMENT_ENTITY_NAME);
     if (empty($questionComment)) {
         @($error['question_comment_id'] = 'Comment with this id doesnt exist');
         throw new ValidationError($error);
     }
     if ($requestParams['practo_account_id'] == $questionComment->getPractoAccountId()) {
         @($error['error'] = 'You cannot vote or flag your own comment!');
         throw new ValidationError($error);
     }
     if (array_key_exists('vote', $requestParams)) {
         $er = $this->helper->getRepository(ConsultConstants::QUESTION_COMMENT_VOTE_ENTITY_NAME);
         $vote = $er->findBy(array('questionComment' => $questionComment, 'practoAccountId' => $requestParams['practo_account_id'], 'softDeleted' => 0));
         if (!empty($vote[0])) {
             $vote = $vote[0];
         }
         if (!empty($vote) and $vote->getVote() == $requestParams['vote']) {
             @($error['error'] = 'The user has already voted on this comment');
             throw new ValidationError($error);
         } elseif (!empty($vote) and $vote->getVote() != $requestParams['vote']) {
             $vote->setVote($requestParams['vote']);
             $vote->setCount($vote->getCount() + 1);
             $this->helper->persist($vote, true);
             // return $vote;
         } else {
             $commentVote = new QuestionCommentVote();
             $commentVote->setQuestionComment($questionComment);
             $this->updateFields($commentVote, $requestParams);
             $this->helper->persist($commentVote, true);
             // return $commentVote;
         }
     }
     if (array_key_exists('flag', $requestParams) && Utility::toBool($requestParams['flag'])) {
         $er = $this->helper->getRepository(ConsultConstants::QUESTION_COMMENT_FLAG_ENTITY_NAME);
         $flag = $er->findBy(array('questionComment' => $questionComment, 'practoAccountId' => $requestParams['practo_account_id'], 'softDeleted' => 0));
         if (!empty($flag[0])) {
             @($error['error'] = 'The user has already flagged this comment');
             throw new ValidationError($error);
         }
         $flag = new QuestionCommentFlag();
         $flag->setQuestionComment($questionComment);
         $requestParams['flag_code'] = strtoupper($requestParams['flag_code']);
         $requestParams['flag_text'] = array_key_exists('text', $requestParams) ? $requestParams['text'] : null;
         unset($requestParams['flag']);
         if (array_key_exists('text', $requestParams)) {
             unset($requestParams['text']);
         }
         $this->updateFields($flag, $requestParams);
         $this->helper->persist($flag, true);
         //return $flag;
     }
     $er = $this->helper->getRepository(ConsultConstants::QUESTION_COMMENT_ENTITY_NAME);
     return $er->loadComment($requestParams['question_comment_id'], $requestParams['practo_account_id']);
 }
 /**
  * @param Array $updateData - data to be updated
  *
  * @return Question
  * @throws ValidationError
  */
 public function patch($updateData)
 {
     if (array_key_exists('id', $updateData) and array_key_exists('practo_account_id', $updateData)) {
         $practoAccountId = $updateData['practo_account_id'];
         /**
          * @var DoctorQuestion $question
          */
         $question = $this->helper->loadById($updateData['id'], ConsultConstants::DOCTOR_QUESTION_ENTITY_NAME);
         if (empty($question) || $question->getPractoAccountId() != $practoAccountId) {
             throw new ValidationError(array("error" => "Question is not mapped to this doctor."));
         }
     } else {
         throw new ValidationError(array("error" => "practo_account_id and question_id is required."));
     }
     if (array_key_exists('reject', $updateData) && Utility::toBool($updateData['reject'])) {
         if ($question->getState() != 'UNANSWERED') {
             throw new ValidationError(array("error" => "The question is not unanswered"));
         }
         if (array_key_exists('rejection_reason', $updateData)) {
             $question->setRejectionReason($updateData['rejection_reason']);
         }
         if (!$question->getRejectedAt()) {
             $question->setRejectedAt(new \DateTime());
             $question->setViewedAt(new \DateTime());
             $question->setState("REJECTED");
         } else {
             throw new ValidationError(array("error" => "Question is already rejected by this doctor"));
         }
     } elseif (array_key_exists('reject', $updateData) && $updateData['reject'] === false and array_key_exists('rejection_reason', $updateData)) {
         throw new ValidationError(array("error" => "Please dont pass rejection_reason if reject is false"));
     }
     if (array_key_exists('view', $updateData) && Utility::toBool($updateData['view'])) {
         if (empty($question->getViewedAt())) {
             $question->setViewedAt(new \DateTime());
         }
     }
     $this->helper->persist($question, true);
     return $this->fetchDetailDoctorQuestionObject($question, $practoAccountId);
 }
 /**
  * @param boolean $hasImages
  */
 public function setHasImages($hasImages)
 {
     $this->hasImages = Utility::toBool($hasImages);
 }
Example #8
0
 /**
  * @param array $requestParams
  * @param null  $practoAccountId
  *
  * @return \ConsultBundle\Response\DetailQuestionResponseObject|string
  * @throws \ConsultBundle\Manager\ValidationError
  * @throws \HttpException
  */
 public function patch($requestParams, $practoAccountId = null)
 {
     $error = array();
     if (array_key_exists('question_id', $requestParams)) {
         $question = $this->helper->loadById($requestParams['question_id'], ConsultConstants::QUESTION_ENTITY_NAME);
         if (null === $question) {
             @($error['question_id'] = 'Question with this id does not exist');
             throw new ValidationError($error);
         }
     } else {
         @($error['question_id'] = 'This value cannot be blank');
         throw new ValidationError($error);
     }
     if (array_key_exists('view', $requestParams) && Utility::toBool($requestParams['view'])) {
         $question->setViewCount($question->getViewCount() + 1);
         if (!empty($practoAccountId)) {
             $viewEntry = $this->helper->getRepository(ConsultConstants::QUESTION_VIEW_ENTITY_NAME)->findBy(array('question' => $question, 'practoAccountId' => $practoAccountId, 'softDeleted' => 0));
             if (empty($viewEntry)) {
                 $view = new QuestionView();
                 $view->setQuestion($question);
                 $view->setPractoAccountId($practoAccountId);
                 $question->addViews($view);
             }
             if ($practoAccountId == $question->getUserInfo()->getPractoAccountId()) {
                 $question->setViewedAt(new \DateTime('now'));
             }
         }
         $this->helper->persist($question, 'true');
     }
     if (array_key_exists('share', $requestParams)) {
         $question->setShareCount($question->getShareCount() + 1);
         $this->helper->persist($question, 'true');
     }
     if (array_key_exists('bookmark', $requestParams)) {
         if (empty($practoAccountId)) {
             throw new \HttpException('', Codes::HTTP_FORBIDDEN);
         }
         if (!$this->userManager->checkConsultEnabled($practoAccountId)) {
             throw new HttpException(Codes::HTTP_FORBIDDEN, "User has not consented to use Consult");
         }
         if (Utility::toBool($requestParams['bookmark'])) {
             try {
                 $questionBookmark = $this->questionBookmarkManager->add($requestParams);
             } catch (ValidationError $e) {
                 throw new ValidationError($e->getMessage());
             }
             //return $questionBookmark;
         } else {
             try {
                 $this->questionBookmarkManager->remove($requestParams);
             } catch (ValidationError $e) {
                 throw new ValidationError($e->getMessage());
             }
             return 'Bookmark Deleted';
         }
     }
     return $this->fetchDetailQuestionObject($question, $practoAccountId);
 }
Example #9
0
 /**
  * @param mixed $activated
  */
 public function setActivated($activated)
 {
     $this->activated = Utility::toBool($activated);
 }
 /**
  * @param boolean $isBookmarked
  */
 public function setIsBookmarked($isBookmarked)
 {
     $this->isBookmarked = Utility::toBool($isBookmarked);
 }
Example #11
0
 /**
  * @param array                                     $requestParams
  * @param int                                       $practoAccountId
  * @param \Symfony\Component\HttpFoundation\FileBag $files
  * @param null                                      $profileToken
  *
  * @return Object
  * @throws \ConsultBundle\Manager\ValidationError
  */
 public function add($requestParams, $practoAccountId, FileBag $files, $profileToken = null)
 {
     /**
      * @var PrivateThreadRepository $er
      */
     $er = $this->helper->getRepository(ConsultConstants::PRIVATE_THREAD_ENTITY_NAME);
     $privateThreadId = array_key_exists('private_thread_id', $requestParams) ? $requestParams['private_thread_id'] : null;
     if (!empty($privateThreadId)) {
         $privateThread = $this->helper->loadById($privateThreadId, ConsultConstants::PRIVATE_THREAD_ENTITY_NAME);
         if (empty($privateThread)) {
             @($error['error'] = 'Private thread with the provided id could not be found');
             throw new ValidationError($error);
         }
         if (array_key_exists('is_doc_reply', $requestParams) && Utility::toBool($requestParams['is_doc_reply'])) {
             if ($privateThread->getDoctorId() != $practoAccountId) {
                 throw new HttpException(Codes::HTTP_FORBIDDEN, 'You are not allowed to answer this question');
             }
         } else {
             if (!$this->userManager->checkConsultEnabled($practoAccountId)) {
                 throw new HttpException(Codes::HTTP_FORBIDDEN, "User has not consented to use Consult");
             }
             if ($privateThread->getUserInfo()->getPractoAccountId() != $practoAccountId) {
                 throw new HttpException(Codes::HTTP_FORBIDDEN, 'You are not allowed to ask any question here');
             }
             if ($er->checkFollowUpCount($practoAccountId, $privateThread) <= 0) {
                 @($error['error'] = 'You have exhausted your follow up questions limit');
                 throw new ValidationError($error);
             }
             /*   $lastConversation = $this->helper->getRepository(ConsultConstants::CONVERSATION_ENTITY_NAME)
                                       ->findBy(array(), array('createdAt' => 'DESC'), 1, 0);
                  if (!empty($lastConversation)) {
                       if (!Utility::toBool($lastConversation[0]->getIsDocReply())) {
                           @$error['error'] = 'Wait for doctor\'s reply before following up again';
                           throw new ValidationError($error);
                       }
                   }*/
             $userInfoParams = array();
             if (array_key_exists('user_info', $requestParams)) {
                 $userInfoParams = $requestParams['user_info'];
                 unset($requestParams['user_info']);
             }
             $userInfoParams['practo_account_id'] = $practoAccountId;
             $userEntry = $this->userManager->add($userInfoParams, $profileToken);
             $privateThread->setUserInfo($userEntry);
         }
         $conversation = new Conversation();
         $conversation->setPrivateThread($privateThread);
         $privateThread->setModifiedAt(new \DateTime('now'));
     } else {
         if (!array_key_exists('reply_id', $requestParams)) {
             @($error['error'] = 'Either id of previous reply or id of the private thread is required');
             throw new ValidationError($error);
         }
         if ($er->privateThreadExists($practoAccountId)) {
             @($error['error'] = 'You have already started a private thread. Cannot start another');
             throw new ValidationError($error);
         }
         $replyId = $requestParams['reply_id'];
         $reply = $this->helper->loadById($replyId, ConsultConstants::DOCTOR_REPLY_ENTITY_NAME);
         if (empty($reply)) {
             @($error['error'] = 'Reply with the provided id could not be found');
             throw new ValidationError($error);
         }
         $privateThread = new PrivateThread();
         $userInfoParams = array();
         if (array_key_exists('user_info', $requestParams)) {
             $userInfoParams = $requestParams['user_info'];
             unset($requestParams['user_info']);
         }
         $userInfoParams['practo_account_id'] = $practoAccountId;
         $userEntry = $this->userManager->add($userInfoParams, $profileToken);
         $privateThread->setUserInfo($userEntry);
         $privateThread->setQuestion($reply->getDoctorQuestion()->getQuestion());
         $privateThread->setDoctorId($reply->getDoctorQuestion()->getPractoAccountId());
         $subject = $reply->getDoctorQuestion()->getQuestion()->getSubject();
         $privateThread->setSubject($subject);
         $conversation = new Conversation();
         $conversation->setPrivateThread($privateThread);
         $privateThread->setModifiedAt(new \DateTime('now'));
         if (array_key_exists('is_doc_reply', $requestParams)) {
             unset($requestParams['is_doc_reply']);
         }
     }
     $this->updateFields($conversation, $requestParams);
     $this->helper->persist($conversation);
     $this->questionImageManager->addConversationImage($conversation, $files);
     $this->helper->persist($privateThread, 'true');
     $isDocReply = false;
     if (Utility::toBool($conversation->getIsDocReply())) {
         $isDocReply = true;
     }
     if (!$isDocReply) {
         $this->sendPrivateNotify('doctor', $privateThread->getDoctorId(), $privateThread->getId(), $privateThread->getSubject());
     } else {
         $this->sendPrivateNotify('patient', $privateThread->getUserInfo()->getPractoAccountId(), $privateThread->getId(), $privateThread->getSubject());
     }
     return $this->createThreadResponse($privateThread, $isDocReply);
 }
Example #12
0
 /**
  * @param string $localFile
  * @param string $uri
  */
 private function uploadAdditionalImages($localFile, $uri)
 {
     $image = new \Imagick($localFile);
     $image->scaleImage(640, 640, true);
     $fileLarge = Utility::strReplace(".", "-large.", $localFile);
     $image->writeImage($fileLarge);
     $this->uploadFile($uri . "/large", $fileLarge);
     unlink($fileLarge);
     $fileMed = Utility::strReplace(".", "-medium.", $localFile);
     $image->scaleImage(320, 320, true);
     $image->writeImage($fileMed);
     $this->uploadFile($uri . "/medium", $fileMed);
     unlink($fileMed);
     $fileThumb = Utility::strReplace(".", "-thumbnail.", $localFile);
     $image->scaleImage(150, 150, true);
     $image->writeImage($fileThumb);
     $this->uploadFile($uri . "/thumbnail", $fileThumb);
     unlink($fileThumb);
     $image->clear();
     $image->destroy();
 }
Example #13
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);
 }