/**
  * @param InstitutionMedicalCenter $center
  */
 function updateInstitutionMedicalCenterListing(InstitutionMedicalCenter $center)
 {
     $institution = $center->getInstitution();
     $criteria = array('institution' => $institution->getId(), 'institutionMedicalCenter' => $center->getId());
     $recentlyApprovedListing = $this->em->getRepository('AdminBundle:RecentlyApprovedListing')->findOneBy($criteria);
     if ($recentlyApprovedListing) {
         if ($center->getStatus() == InstitutionMedicalCenterStatus::APPROVED) {
             $recentlyApprovedListing->setDateUpdated(new \DateTime());
             $this->em->persist($recentlyApprovedListing);
         } else {
             $this->em->remove($recentlyApprovedListing);
         }
         $this->em->flush();
     } else {
         if ($center->getStatus() == InstitutionMedicalCenterStatus::APPROVED) {
             $recentlyApprovedListingService = new RecentlyApprovedListingService();
             $recentlyApprovedListingService->setEntityManager($this->em);
             $recentlyApprovedListing = new RecentlyApprovedListing();
             $recentlyApprovedListing->setInstitution($institution);
             $recentlyApprovedListing->setInstitutionMedicalCenter($center);
             $recentlyApprovedListing->setDateUpdated(new \DateTime());
             $recentlyApprovedListing->setStatus(1);
             $this->em->persist($recentlyApprovedListing);
             $this->em->flush($recentlyApprovedListing);
         }
     }
 }
 public function getAvailableGlobalAwardsOfInstitutionMedicalCenter(InstitutionMedicalCenter $institutionMedicalCenter, QueryOptionBag $options)
 {
     $globalAwardPropertyType = $this->getEntityManager()->getRepository('InstitutionBundle:InstitutionPropertyType')->findOneBy(array('name' => InstitutionPropertyType::TYPE_GLOBAL_AWARD));
     $sql = "SELECT a.value  FROM institution_medical_center_properties a WHERE a.institution_property_type_id = :propertyType AND a.institution_medical_center_id = :institutionMedicalCenterId";
     $statement = $this->getEntityManager()->getConnection()->prepare($sql);
     $statement->execute(array('propertyType' => $globalAwardPropertyType->getId(), 'institutionMedicalCenterId' => $institutionMedicalCenter->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();
 }
 /**
  * This will group together all relevant links - clinic website, social media
  * sites, email, call us, etc in one variable. Its purpose is to make it easier
  * on the view side to display these links.
  *
  * NOTE: It is imperative that this return only the permitted links for each
  * paying status type. There will be no checking on the view side.
  *
  * Rules are here: https://basecamp.com/1876919/projects/3113924-health-care-abroad/todos/55796212-add-interface-to
  *
  */
 public function getCenterLinks(InstitutionMedicalCenter $center, $url)
 {
     $links = array();
     //Falls through; order of the elements in $links is significant
     switch ($center->getPayingClient()) {
         case PayingStatus::PHOTO_LISTING:
         case PayingStatus::LOGO_LISTING:
         case PayingStatus::LINKED_LISTING:
             $socialMediaSites = json_decode($center->getSocialMediaSites(), true);
             foreach ($socialMediaSites as $type => $value) {
                 if ($value) {
                     $links[$type] = array('tooltip' => "This hospital is on {$value}");
                 }
             }
             if ($website = $center->getWebsites()) {
                 $links['website'] = array('tooltip' => "Website: {$website}");
             }
             if ($number = $center->getContactNumber()) {
                 $links['contactnumber'] = array('tooltip' => 'Call Us', 'value' => $url);
             }
             break;
     }
     $links['email'] = array('tooltip' => 'Email Us', 'value' => $url . '#form_feedback');
     return $links;
 }
 public function ajaxEditGlobalAwardAction()
 {
     $globalAward = $this->getDoctrine()->getRepository('HelperBundle:GlobalAward')->find($this->request->get('globalAwardId', 0));
     if (!$globalAward) {
         throw $this->createNotFoundException('Invalid global award');
     }
     $propertyType = $this->get('services.institution_property')->getAvailablePropertyType(InstitutionPropertyType::TYPE_GLOBAL_AWARD);
     $imcProperty = $this->imcService->getPropertyValue($this->institutionMedicalCenter, $propertyType, $globalAward->getId(), $this->request->get('propertyId', 0));
     $imcProperty->setValueObject($globalAward);
     $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType(), $imcProperty);
     if ($this->request->isMethod('POST')) {
         $editGlobalAwardForm->bind($this->request);
         if ($editGlobalAwardForm->isValid()) {
             $imcProperty = $editGlobalAwardForm->getData();
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($imcProperty);
             $em->flush();
             // Invalidate InstitutionMedicalCenterProfile memcache
             $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId()));
             $output = array('status' => true, 'extraValue' => $imcProperty->getExtraValue());
             $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json'));
         } else {
             $response = new Response('Form error', 400);
         }
     }
     return $response;
 }
 public function checkIfExists(InstitutionProperty $institutionProperty, InstitutionMedicalCenter $center)
 {
     $this->doctrine = $this->getContainer()->get('doctrine');
     $qb = $this->doctrine->getEntityManager()->createQueryBuilder()->select('a')->from('InstitutionBundle:InstitutionMedicalCenterProperty', 'a')->where('a.institution = :institution')->andWhere('a.institutionMedicalCenter = :imc')->andWhere('a.institutionPropertyType = :insProperty')->andWhere('a.value = :value')->setParameter('institution', $institutionProperty->getInstitution()->getId())->setParameter('imc', $center->getId())->setParameter('insProperty', $institutionProperty->getInstitutionPropertyType()->getId())->setParameter('value', $institutionProperty->getValue())->getQuery();
     if (count($qb->getResult()) >= 1) {
         return true;
     }
     return false;
 }
 /**
  * Action page for Institution Profile Page
  *
  * @param Request $request
  */
 public function profileAction(Request $request)
 {
     $medicalProviderGroup = $this->getDoctrine()->getRepository('InstitutionBundle:MedicalProviderGroup')->getActiveMedicalGroups();
     $medicalProviderGroupArr = array();
     foreach ($medicalProviderGroup as $e) {
         $medicalProviderGroupArr[] = array('value' => $e->getName(), 'id' => $e->getId());
     }
     $this->get('services.contact_detail')->initializeContactDetails($this->institution, array(ContactDetailTypes::PHONE), $this->institution->getCountry());
     $form = $this->createForm(new InstitutionProfileFormType(), $this->institution, array(InstitutionProfileFormType::OPTION_BUBBLE_ALL_ERRORS => false));
     $currentGlobalAwards = $this->get('services.institution_property')->getGlobalAwardPropertiesByInstitution($this->institution);
     $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType());
     $params = array('institutionForm' => $form->createView(), 'institutionPhotos' => $this->get('services.institution.gallery')->getInstitutionPhotos($this->institution->getId()), 'currentGlobalAwards' => $currentGlobalAwards, 'editGlobalAwardForm' => $editGlobalAwardForm->createView(), 'medicalProvidersJSON' => \json_encode($medicalProviderGroupArr), 'ancillaryServicesData' => $this->get('services.helper.ancillary_service')->getActiveAncillaryServices());
     if ($this->isSingleCenter) {
         $doctor = new Doctor();
         $doctor->addInstitutionMedicalCenter($this->institutionMedicalCenter);
         $doctorForm = $this->createForm(new InstitutionMedicalCenterDoctorFormType(), $doctor);
         $editDoctor = new Doctor();
         $doctors = $this->getDoctrine()->getRepository('DoctorBundle:Doctor')->findByInstitutionMedicalCenter($this->institutionMedicalCenter->getId(), Query::HYDRATE_OBJECT);
         if (!empty($doctors)) {
             $editDoctor = $doctors[0];
         }
         $this->get('services.contact_detail')->initializeContactDetails($editDoctor, array(ContactDetailTypes::PHONE), $this->institution->getCountry());
         $editDoctorForm = $this->createForm(new InstitutionMedicalCenterDoctorFormType('editInstitutionMedicalCenterDoctorForm'), $editDoctor);
         $institutionMedicalCenterForm = $this->createForm(new InstitutionMedicalCenterFormType($this->institution), $this->institutionMedicalCenter, array(InstitutionMedicalCenterFormType::OPTION_BUBBLE_ALL_ERRORS => false));
         $params['editDoctorForm'] = $editDoctorForm->createView();
         $params['institutionMedicalCenter'] = $this->institutionMedicalCenter;
         $params['institutionMedicalCenterForm'] = $institutionMedicalCenterForm->createView();
         $params['commonDeleteForm'] = $this->createForm(new CommonDeleteFormType())->createView();
         $params['specializations'] = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionSpecialization')->getActiveSpecializationsByInstitutionMedicalCenter($this->institutionMedicalCenter);
         $params['doctors'] = $this->get('services.doctor')->doctorsObjectToArray($this->institutionMedicalCenter->getDoctors());
         $params['doctorForm'] = $doctorForm->createView();
     }
     return $this->render('InstitutionBundle:Institution:profile.html.twig', $params);
 }
 public function setupDoctorsAction(Request $request)
 {
     //TODO: check institution signupStepStatus
     $doctor = new Doctor();
     $doctor->addInstitutionMedicalCenter($this->institutionMedicalCenter);
     $form = $this->createForm(new InstitutionMedicalCenterDoctorFormType(), $doctor);
     $doctors = $this->getDoctrine()->getRepository('DoctorBundle:Doctor')->findByInstitutionMedicalCenter($this->institutionMedicalCenter->getId(), Query::HYDRATE_OBJECT);
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $doctor = $form->getData();
             $doctor->setStatus(Doctor::STATUS_ACTIVE);
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($doctor);
             $em->flush($doctor);
             $data = array('status' => true, 'message' => 'Doctor has been added to your clinic!', 'doctor' => $this->get('services.doctor')->toArrayDoctor($doctor), 'editDoctorUrl' => $this->generateUrl('institution_medicalCenter_ajaxUpdateDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())), 'removeDoctorUrl' => $this->generateUrl('institution_medicalCenter_removeDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())), 'uploadLogoUrl' => $this->generateUrl('institution_doctor_logo_upload', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())));
         } else {
             $data = array('status' => false, 'message' => $form->getErrorsAsString());
         }
         return new Response(json_encode($data), 200, array('Content-Type' => 'application/json'));
     }
     $params = array('doctorForm' => $form->createView(), 'institution' => $this->institution, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'thumbnailSize' => ImageSizes::DOCTOR_LOGO, 'doctors' => $this->get('services.doctor')->doctorsObjectToArray($doctors));
     $editDoctor = new Doctor();
     if (!empty($doctors)) {
         $editDoctor = $doctors[0];
     }
     $this->get('services.contact_detail')->initializeContactDetails($editDoctor, array(ContactDetailTypes::PHONE), $this->institution->getCountry());
     $editDoctorForm = $this->createForm(new InstitutionMedicalCenterDoctorFormType('editInstitutionMedicalCenterDoctorForm'), $editDoctor);
     $params['editDoctorForm'] = $editDoctorForm->createView();
     return $this->render('InstitutionBundle:SignUp:setupDoctors.html.twig', $params);
 }
 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 institution specialization
  *
  * @param Request $request
  */
 public function ajaxRemoveSpecializationAction(Request $request)
 {
     $institutionSpecialization = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionSpecialization')->find($request->get('isId', 0));
     if (!$institutionSpecialization) {
         throw $this->createNotFoundException('Invalid instituiton specialization');
     }
     if ($institutionSpecialization->getInstitutionMedicalCenter()->getId() != $this->institutionMedicalCenter->getId()) {
         return new Response("Cannot remove specialization that does not belong to this institution", 401);
     }
     $form = $this->createForm(new CommonDeleteFormType(), $institutionSpecialization);
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $_id = $institutionSpecialization->getId();
             $em = $this->getDoctrine()->getEntityManager();
             $em->remove($institutionSpecialization);
             $em->flush();
             // Invalidate InstitutionMedicalCenterProfile memcache
             $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId()));
             // Invalidate InstitutionProfile memcache
             $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institutionMedicalCenter->getInstitution()->getId()));
             $responseContent = array('id' => $_id);
             $response = new Response(\json_encode($responseContent), 200, array('content-type' => 'application/json'));
         } else {
             $response = new Response("Invalid form", 400);
         }
     }
     return $response;
 }
 private function migrateClinicLogo(InstitutionMedicalCenter $imc)
 {
     $this->output->write("LOGO of clinic {$imc->getId()}: ");
     $oldDirectory = $this->getWebRootDirectory() . '/' . $imc->getInstitution()->getId();
     if ($media = $imc->getLogo()) {
         $mediaFile = $oldDirectory . '/' . $media->getName();
         if (\file_exists($mediaFile)) {
             $this->doMove($imc->getInstitution(), $media, $this->logoSizes);
             $this->output->write('[OK]');
         } else {
             $this->output->write('[NOT FOUND]');
         }
         $this->output->writeln("");
     } else {
         $this->output->writeln("NO LOGO");
     }
 }
 public function saveContactDetail(InstitutionMedicalCenter $center)
 {
     $contactIdsArray = array();
     $contactNumber = $center->getContactNumber();
     $contactNumber = \json_decode($center->getContactNumber(), true);
     if (\is_array($contactNumber)) {
         if (isset($contactNumber['number'])) {
             $contactDetail = new ContactDetail();
             $contactDetail->setNumber(isset($contactNumber['country_code']) ? $contactNumber['country_code'] : '');
             $contactDetail->setAreaCode(isset($contactNumber['area_code']) ? $contactNumber['area_code'] : '');
             $contactDetail->setNumber($contactNumber['number']);
             $contactDetail->setType(ContactDetailTypes::PHONE);
             $center->addContactDetail($contactDetail);
         }
     }
     return $center;
 }
 public function preExecute()
 {
     $this->repository = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenter');
     $this->service = $this->get('services.institution_medical_center');
     if ($imcId = $this->getRequest()->get('imcId', 0)) {
         $this->institutionMedicalCenter = $this->repository->find($imcId);
         // non-existent medical center group
         if (!$this->institutionMedicalCenter) {
             if ($this->getRequest()->isXmlHttpRequest()) {
                 throw $this->createNotFoundException('Invalid medical center.');
             } else {
                 return $this->_redirectIndexWithFlashMessage('Invalid medical center.', 'error');
             }
         }
         // medical center group does not belong to this institution
         if ($this->institutionMedicalCenter->getInstitution()->getId() != $this->institution->getId()) {
             return $this->_redirectIndexWithFlashMessage('Invalid medical center.', 'error');
         }
     }
 }
 /**
  * Upload logo for Institution Medical Center
  * @param Request $request
  */
 public function uploadAction(Request $request)
 {
     if ($request->files->get('logo')) {
         $file = $request->files->get('logo');
         $media = $this->get('services.institution.media')->medicalCenterUploadLogo($file, $this->institutionMedicalCenter);
         if ($media->getName()) {
             $src = $this->get('services.institution')->mediaTwigExtension->getInstitutionMediaSrc($media->getName(), ImageSizes::MEDIUM);
             $data['mediaSrc'] = $src;
         }
         $data['status'] = true;
         // Invalidate InstitutionMedicalCenterProfile memcache
         $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId()));
         // Invalidate InstitutionProfile memcache
         $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institutionMedicalCenter->getInstitution()->getId()));
     }
     return new Response(\json_encode($data), 200, array('content-type' => 'application/json'));
 }
 public function getAvailableDoctors(InstitutionMedicalCenter $center, $searchKey)
 {
     $ids = array();
     foreach ($center->getDoctors() as $each) {
         $ids[] = $each->getId();
     }
     $exclodeExistingDoctorsId = !empty($ids) ? "a.id NOT IN (" . implode(", ", $ids) . ") AND " : '';
     $connection = $this->getEntityManager()->getConnection();
     $query = "SELECT a.*, s.name AS specialization_name FROM doctors a\n        LEFT JOIN doctor_specializations b ON a.id = b.doctor_id\n        LEFT JOIN specializations s ON s.id = b.specialization_id\n        WHERE {$exclodeExistingDoctorsId} (a.first_name LIKE :searchKey OR a.last_name LIKE :searchKey OR CONCAT(a.last_name, ' ', a.first_name) LIKE :searchKey) \n        AND a.status = :active ORDER BY a.last_name ASC";
     $stmt = $connection->prepare($query);
     $stmt->bindValue('imcId', $center->getId());
     $stmt->bindValue('searchKey', '%' . str_replace(',', '', $searchKey) . '%');
     $stmt->bindValue('active', Doctor::STATUS_ACTIVE);
     $stmt->execute();
     return $stmt->fetchAll();
 }
 /**
  * Create a PageMetaConfiguration for clinic page
  * 
  * @param InstitutionMedicalCenter $institutionMedicalCenter
  * @return \HealthCareAbroad\HelperBundle\Entity\PageMetaConfiguration
  */
 public function buildForInstitutionMedicalCenterPage(InstitutionMedicalCenter $institutionMedicalCenter)
 {
     $institution = $institutionMedicalCenter->getInstitution();
     $location = ($institution->getCity() ? $institution->getCity() . ', ' : '') . $institution->getCountry();
     $metaConfig = new PageMetaConfiguration();
     $metaConfig->setTitle("{$institutionMedicalCenter->getName()} - {$institution->getName()} {$location} - " . $this->siteName);
     $metaConfig->setDescription("{$institutionMedicalCenter->getName()} at {$institution->getName()} offers treatments in {" . PageMetaConfigurationService::SPECIALIZATIONS_LIST_VARIABLE . "} in {$location}. Get details at " . $this->siteName);
     $metaConfig->setKeywords("{$institution->getName()}, {$institutionMedicalCenter->getName()}, {$location}, {" . PageMetaConfigurationService::SPECIALIZATIONS_LIST_VARIABLE . "}, medical tourism, Doctor, Dentist");
     $metaConfig->setPageType(PageMetaConfiguration::PAGE_TYPE_INSTITUTION_MEDICAL_CENTER);
     return $metaConfig;
 }
 public function getInstitutionMedicalCenterByPropertyType(InstitutionMedicalCenter $institutionMedicalCenter, $propertyName)
 {
     if (isset(static::$institutionMedicalCenterPropertiesByType[$propertyName])) {
         return static::$institutionMedicalCenterPropertiesByType[$propertyName];
     }
     $propertyType = $this->getAvailablePropertyType($propertyName);
     $criteria = array('institutionMedicalCenter' => $institutionMedicalCenter->getId(), 'institutionPropertyType' => $propertyType);
     static::$institutionMedicalCenterPropertiesByType[$propertyName] = $this->propertyRepository->findBy($criteria);
     return static::$institutionMedicalCenterPropertiesByType[$propertyName];
 }
 function medicalCenterUploadToGallery($file, InstitutionMedicalCenter $medicalCenter, $flushObject = true)
 {
     $result = parent::uploadFile($file);
     if (is_object($result)) {
         $media = $result;
         $sizes = $this->getSizesByType(self::GALLERY_TYPE_IMAGE);
         $this->resize($media, $sizes);
         $gallery = $this->entityManager->getRepository('MediaBundle:Gallery')->findOneByInstitution($medicalCenter->getInstitution()->getId());
         if (!$gallery) {
             $gallery = new Gallery();
             $gallery->addMedia($media);
             $gallery->setInstitution($medicalCenter->getInstitution());
         } else {
             $gallery->addMedia($media);
         }
         $medicalCenter->addMedia($media);
         if ($flushObject) {
             $this->entityManager->persist($gallery);
             $this->entityManager->persist($medicalCenter);
             $this->entityManager->flush();
         }
         return $media;
     }
     return null;
 }
 public static function institutionMedicalCenterToArray(InstitutionMedicalCenter $institutionMedicalCenter)
 {
     $data = array('id' => $institutionMedicalCenter->getId(), 'name' => $institutionMedicalCenter->getName());
     return $data;
 }
 public function completeProfileOfInstitutionWithSingleCenter(Institution $institution, InstitutionMedicalCenter $institutionMedicalCenter)
 {
     // save the institution
     $this->institutionFactory->save($institution);
     // set medical center name and description to institution.name and institution.description
     $institutionMedicalCenter->setName($institution->getName());
     $institutionMedicalCenter->setDescription($institution->getDescription() ? $institution->getDescription() : '2');
     $institutionMedicalCenter->setInstitution($institution);
     $institutionMedicalCenter->setAddress($institution->getAddress1());
     $institutionMedicalCenter->setCoordinates($institution->getCoordinates());
     // save institution medical center as draft
     $this->institutionMedicalCenterService->saveAsDraft($institutionMedicalCenter);
 }
 public function getStatusLabel(InstitutionMedicalCenter $institutionMedicalCenter)
 {
     $statuses = InstitutionMedicalCenterStatus::getStatusList();
     return \array_key_exists($institutionMedicalCenter->getStatus(), $statuses) ? $statuses[$institutionMedicalCenter->getStatus()] : '';
 }
 public function institutionMedicalCenterWebsitesToArray(InstitutionMedicalCenter $institutionMedicalCenter)
 {
     return $this->jsonWebsitesToArray($institutionMedicalCenter->getSocialMediaSites());
 }