public function bypassClientAdminLoginAction(Request $request)
 {
     $user = $this->get('services.institution_user')->findById($request->get('accountId'));
     if ($this->institution->getId() != $user->getInstitution()->getId()) {
         return new Response(\sprintf('User %s does not belong to institution %s', $user->getAccountId(), $this->institution->getId()), 401);
     }
     return $this->render('AdminBundle:InstitutionUser:bypassClientAdminLogin.html.twig', array('user' => $user, 'institution' => $this->institution));
 }
 /**
  * Added/Updated recentlyApproved institution type listing. Removed when updated from APPROVED to INACTIVE, SUSPENDED or INACTIVE
  * @param Institution $institution
  */
 function updateInstitutionListing(Institution $institution)
 {
     $criteria = array('institution' => $institution->getId(), 'institutionMedicalCenter' => null);
     $recentlyApprovedListing = $this->em->getRepository('AdminBundle:RecentlyApprovedListing')->findOneBy($criteria);
     if ($recentlyApprovedListing) {
         if ($institution->getStatus() == InstitutionStatus::getBitValueForActiveAndApprovedStatus()) {
             $recentlyApprovedListing->setDateUpdated(new \DateTime());
             $this->em->persist($recentlyApprovedListing);
         } else {
             $this->em->remove($recentlyApprovedListing);
         }
         $this->em->flush();
     } else {
         if ($institution->getStatus() == InstitutionStatus::getBitValueForActiveAndApprovedStatus()) {
             $recentlyApprovedListingService = new RecentlyApprovedListingService();
             $recentlyApprovedListingService->setEntityManager($this->em);
             $recentlyApprovedListing = new RecentlyApprovedListing();
             $recentlyApprovedListing->setInstitution($institution);
             $recentlyApprovedListing->setInstitutionMedicalCenter(null);
             $recentlyApprovedListing->setDateUpdated(new \DateTime());
             $recentlyApprovedListing->setStatus(1);
             $this->em->persist($recentlyApprovedListing);
             $this->em->flush($recentlyApprovedListing);
         }
     }
 }
 public function getAvailableGlobalAwardsOfInstitution(Institution $institution, QueryOptionBag $options)
 {
     $globalAwardPropertyType = $this->getEntityManager()->getRepository('InstitutionBundle:InstitutionPropertyType')->findOneBy(array('name' => InstitutionPropertyType::TYPE_GLOBAL_AWARD));
     $sql = "SELECT a.value  FROM institution_properties a WHERE a.institution_property_type_id = :propertyType AND a.institution_id = :institutionId";
     $statement = $this->getEntityManager()->getConnection()->prepare($sql);
     $statement->execute(array('propertyType' => $globalAwardPropertyType->getId(), 'institutionId' => $institution->getId()));
     $result = array();
     $ids = array();
     if ($statement->rowCount() > 0) {
         while ($row = $statement->fetch(Query::HYDRATE_ARRAY)) {
             $ids[] = $row['value'];
         }
     }
     $qb = $this->getEntityManager()->createQueryBuilder()->select('a,b')->from('HelperBundle:GlobalAward', 'a')->innerJoin('a.awardingBody', 'b')->where('a.status = :globalAwardActiveStatus')->setParameter('globalAwardActiveStatus', GlobalAward::STATUS_ACTIVE)->orderBy('a.name', 'ASC');
     if ($options->has('globalAward.name')) {
         $qb->andWhere('a.name LIKE :globalAwardName')->setParameter('globalAwardName', '%' . $options->get('globalAward.name') . '%');
     }
     if ($options->has('globalAward.type')) {
         $qb->andWhere('a.type = :globalAwardType')->setParameter('globalAwardType', $options->get('globalAward.type'));
     }
     if (\count($ids)) {
         $qb->andWhere($qb->expr()->notIn('a.id', ':globalAwardIds'))->setParameter('globalAwardIds', $ids);
     }
     //echo $qb->getQuery()->getSQL(); exit;
     return $qb->getQuery()->getResult();
 }
 public function preExecute()
 {
     $this->request = $this->getRequest();
     $this->institution = $this->get('services.institution.factory')->findById($this->request->get('institutionId'));
     $this->institutionService = $this->get('services.institution');
     if (!$this->institution) {
         throw $this->createNotFoundException("Invalid institution");
     }
     if ($imcId = $this->getRequest()->get('imcId', 0)) {
         $this->institutionMedicalCenter = $this->get('services.institution_medical_center')->findById($imcId);
         // institution medical center does not belong to institution
         if ($this->institutionMedicalCenter && $this->institutionMedicalCenter->getInstitution()->getId() != $this->institution->getId()) {
             return new Response('Medical center does not belong to institution', 401);
         }
     }
 }
 /**
  * Remove an ancillary service to institution medical center
  * Required parameters:
  *     - institutionId
  *     - imcId institution medical center id
  *     - asId ancillary service id
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @author acgvelarde
  */
 public function ajaxRemoveInstitutionMedicalCenterAncillaryServiceAction(Request $request)
 {
     $property = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenterProperty')->find($request->get('id', 0));
     if (!$property) {
         throw $this->createNotFoundException('Invalid property.');
     }
     // get global,current and selcted ancillary services
     $ancillaryService = $this->getDoctrine()->getRepository('AdminBundle:OfferedService')->find($property->getValue());
     $ancillaryServicesData = array('globalList' => $this->get('services.helper.ancillary_service')->getActiveAncillaryServices(), 'selected' => array(), 'currentAncillaryData' => array());
     $ancillaryServicesData = $this->get('services.institution_medical_center_property')->getCurrentAndSelectedAncillaryServicesByPropertyType($this->institutionMedicalCenter, InstitutionPropertyType::TYPE_ANCILLIARY_SERVICE, $ancillaryServicesData);
     try {
         $em = $this->getDoctrine()->getEntityManager();
         $em->remove($property);
         $em->flush();
         // Invalidate InstitutionMedicalCenter Profile cache
         $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($request->get('imcId')));
         $output = array('label' => 'Add Service', 'href' => $this->generateUrl('admin_institution_medicalCenter_ajaxAddAncillaryService', array('institutionId' => $this->institution->getId(), 'imcId' => $this->institutionMedicalCenter->getId(), 'id' => $ancillaryService->getId())), 'ancillaryServicesData' => $ancillaryServicesData, '_isSelected' => false);
         $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json'));
     } catch (\Exception $e) {
         $response = new Response($e->getMessage(), 500);
     }
     return $response;
 }
 /**
  * Get global awards of an institution
  *
  * @param Institution $institution
  * @return array GlobalAward
  */
 public function getAllGlobalAwardsByInstitution($institution, $hydrationMode = Query::HYDRATE_OBJECT)
 {
     $institutionId = $institution;
     if ($institution instanceof Institution) {
         $institutionId = $institution->getId();
     }
     //$globalAwardPropertyType = $this->getEntityManager()->getRepository('InstitutionBundle:InstitutionPropertyType')->findOneBy(array('name' => InstitutionPropertyType::TYPE_GLOBAL_AWARD));
     $sql = "SELECT a.value  FROM institution_properties a " . "WHERE a.institution_property_type_id = :propertyType AND a.institution_id = :institutionId";
     $statement = $this->getEntityManager()->getConnection()->prepare($sql);
     $statement->bindValue('propertyType', InstitutionPropertyType::GLOBAL_AWARD_ID);
     $statement->bindValue('institutionId', $institutionId);
     $statement->execute();
     $result = array();
     if ($statement->rowCount() > 0) {
         $ids = array();
         while ($row = $statement->fetch(Query::HYDRATE_ARRAY)) {
             $ids[] = $row['value'];
         }
         $dql = "SELECT a, b FROM HelperBundle:GlobalAward a INNER JOIN a.awardingBody as b WHERE a.id IN (?1)";
         $query = $this->getEntityManager()->createQuery($dql)->setParameter(1, $ids);
         $result = $query->getResult($hydrationMode);
     }
     return $result;
 }
 public static function institutionToArray(Institution $institution)
 {
     $data = array('id' => $institution->getId(), 'name' => $institution->getName());
     return $data;
 }
 public function findByTypeName(Institution $institution, $userTypeName)
 {
     $query = $this->getEntityManager()->createQueryBuilder()->select('u')->from('UserBundle:InstitutionUser', 'u')->join('u.institutionUserType', 't', Join::WITH, 't.name LIKE :userTypeName')->where('u.institution = :institutionId')->andWhere('u.status = :status')->setParameter('userTypeName', '%' . $userTypeName . '%')->setParameter('institutionId', $institution->getId())->setParameter('status', SiteUser::STATUS_ACTIVE)->getQuery();
     return $query->getResult();
 }
 /**
  * Get medicaCenter count by Institution
  *
  * @param Institution $institution
  * @return int
  */
 public function getCountByInstitution(Institution $institution)
 {
     $qb = $this->getEntityManager()->createQueryBuilder()->select('count(a)')->from('InstitutionBundle:InstitutionMedicalCenter', 'a')->where('a.institution = :institutionId')->setParameter('institutionId', $institution->getId());
     $count = $qb->getQuery()->getSingleScalarResult();
     return $count;
 }
 private function doMove(Institution $institution, Media $media, $sizes)
 {
     // point file system to new path
     $this->fileSystem->rename($institution->getId() . '/' . $media->getName(), $media->getName());
     // do resize
     $this->institutionMediaService->resize($media, $sizes);
 }
 /**
  * 
  * @param Institution $institution
  * @return array
  */
 function getAlertsByInstitution(Institution $institution, $groupByType = false)
 {
     $params = array('keys' => array(array($institution->getId(), AlertRecipient::INSTITUTION), array(null, AlertRecipient::ALL_ACTIVE_INSTITUTION)));
     return $this->getAlerts(self::RECIPIENT_ALERT_VIEW_URI, $params, $groupByType);
 }
 public function uploadToGallery($file, Institution $institution, $flushObject = true)
 {
     $result = parent::uploadFile($file);
     if (is_object($result)) {
         $media = $result;
         $sizes = $this->getSizesByType(self::GALLERY_TYPE_IMAGE);
         $gallery = $this->entityManager->getRepository('MediaBundle:Gallery')->findOneByInstitution($institution->getId());
         if (!$gallery) {
             $gallery = new Gallery();
             $gallery->addMedia($media);
             $gallery->setInstitution($institution);
         } else {
             $gallery->addMedia($media);
         }
         $this->resize($media, $sizes);
         if ($flushObject) {
             $this->entityManager->persist($gallery);
             $this->entityManager->flush($gallery);
         }
         return $media;
     }
     return null;
 }
 /**
  * @depends testSave
  */
 public function testFindById(Institution $institution)
 {
     $inst2 = $this->factory->findById($institution->getId());
     $this->assertEquals($institution->getId(), $inst2->getId());
 }
 /**
  * Get values of institution $institution for property type $propertyType
  *
  * @param Institution $institution
  * @param InstitutionPropertyType $propertyType
  * @return array InstitutionProperty
  */
 public function getPropertyValues(Institution $institution, InstitutionPropertyType $propertyType)
 {
     $dql = "SELECT a FROM InstitutionBundle:InstitutionProperty a WHERE a.institution = :institutionId AND a.institutionPropertyType = :institutionPropertyTypeId";
     $result = $this->doctrine->getEntityManager()->createQuery($dql)->setParameter('institutionId', $institution->getId())->setParameter('institutionPropertyTypeId', $propertyType->getId())->getResult();
     return $result;
 }