<commit_before><?php

namespace HealthCareAbroad\InstitutionBundle\Repository;

use Doctrine\ORM\Query;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionPropertyType;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterGroupStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenter;

use HealthCareAbroad\HelperBundle\Classes\QueryOptionBag;

use HealthCareAbroad\InstitutionBundle\Entity\Institution;

use Doctrine\ORM\EntityRepository;

/**
 * InstitutionRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class InstitutionRepository extends EntityRepository
{
    public function search($term = '', $limit = 10)
    {
        $dql = "
            SELECT i
            FROM InstitutionBundle:Institution AS i
            WHERE i.name LIKE :term
            ORDER BY i.name ASC"
        ;

        $query = $this->_em->createQuery($dql);
        $query->setParameter('term', "%$term%");
        $query->setMaxResults($limit);

        return $query->getResult();
    }

    /**
     * Get active institution medical centers
     *
     * @param Institution $institution
     * @param QueryOptionBag $queryOptions
     * @return InstitutionMedicalCenter
     */
    public function getActiveInstitutionMedicalCenters(Institution $institution, QueryOptionBag $queryOptions=null)
    {
        $dql = "SELECT a FROM InstitutionBundle:InstitutionMedicalCenter a WHERE a.institution = :institutionId AND a.status != :inActive ";
        $query = $this->_em->createQuery($dql)
            ->setParameter('institutionId', $institution->getId())
            ->setParameter('inActive', InstitutionMedicalCenterStatus::INACTIVE);

        return $query->getResult();
    }

    /**
     * Get draft institution specializations
     *
     * @param Institution $institution
     * @param QueryOptionBag $queryOptions
     * @return InstitutionMedicalCenter
     */

    public function getDraftInstitutionMedicalCenters(Institution $institution, QueryOptionBag $queryOptions=null)
    {
        $dql = "SELECT a FROM InstitutionBundle:InstitutionMedicalCenter a WHERE a.institution = :institutionId AND a.status = :active ";
        $query = $this->_em->createQuery($dql)
        ->setParameter('institutionId', $institution->getId())
        ->setParameter('active', InstitutionMedicalCenterGroupStatus::DRAFT);

        return $query->getResult();
    }

    public function getQueryBuilderForApprovedInstitutions()
    {
        $qb = $this->createQueryBuilder('a')
            ->where('a.status = :approved_status')
            ->setParameter('approved_status', InstitutionStatus::getBitValueForApprovedStatus());

        return $qb;
    }

    //TODO: paging
    public function getInstitutionsByCountry($country)
    {
        $dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.country = :country AND a.status = :status ";
        //$dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.country = :country ";

        $query = $this->_em->createQuery($dql)
            ->setParameter('status', InstitutionStatus::APPROVED)
            ->setParameter('country', $country);


        return $query->getResult();
    }

    public function getInstitutionsByCity($city)
    {
        $dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.country = :country AND a.status = :status ";
        $dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.city = :city ";

        $query = $this->_em->createQuery($dql)
            ->setParameter('status', InstitutionStatus::APPROVED)
            ->setParameter('city', $city);


        return $query->getResult();
    }

    /**
     * Get global awards of an institution
     *
     * @param Institution $institution
     * @return array GlobalAward
     */
    public function getAllGlobalAwardsByInstitution(Institution $institution)
    {
        $globalAwardPropertyType = $this->getEntityManager()->getRepository('InstitutionBundle:InstitutionPropertyType')->findOneBy(array('name' => InstitutionPropertyType::TYPE_GLOBAL_AWARD));<commit_msg>set publicly viewable institutions as those that have inactive status<commit_after><?php

namespace HealthCareAbroad\InstitutionBundle\Repository;

use Doctrine\ORM\Query;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionPropertyType;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterGroupStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenter;

use HealthCareAbroad\HelperBundle\Classes\QueryOptionBag;

use HealthCareAbroad\InstitutionBundle\Entity\Institution;

use Doctrine\ORM\EntityRepository;

/**
 * InstitutionRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class InstitutionRepository extends EntityRepository
{
    public function search($term = '', $limit = 10)
    {
        $dql = "
            SELECT i
            FROM InstitutionBundle:Institution AS i
            WHERE i.name LIKE :term
            ORDER BY i.name ASC"
        ;

        $query = $this->_em->createQuery($dql);
        $query->setParameter('term', "%$term%");
        $query->setMaxResults($limit);

        return $query->getResult();
    }

    /**
     * Get active institution medical centers
     *
     * @param Institution $institution
     * @param QueryOptionBag $queryOptions
     * @return InstitutionMedicalCenter
     */
    public function getActiveInstitutionMedicalCenters(Institution $institution, QueryOptionBag $queryOptions=null)
    {
        $dql = "SELECT a FROM InstitutionBundle:InstitutionMedicalCenter a WHERE a.institution = :institutionId AND a.status != :inActive ";
        $query = $this->_em->createQuery($dql)
            ->setParameter('institutionId', $institution->getId())
            ->setParameter('inActive', InstitutionMedicalCenterStatus::INACTIVE);

        return $query->getResult();
    }

    /**
     * Get draft institution specializations
     *
     * @param Institution $institution
     * @param QueryOptionBag $queryOptions
     * @return InstitutionMedicalCenter
     */

    public function getDraftInstitutionMedicalCenters(Institution $institution, QueryOptionBag $queryOptions=null)
    {
        $dql = "SELECT a FROM InstitutionBundle:InstitutionMedicalCenter a WHERE a.institution = :institutionId AND a.status = :active ";
        $query = $this->_em->createQuery($dql)
        ->setParameter('institutionId', $institution->getId())
        ->setParameter('active', InstitutionMedicalCenterGroupStatus::DRAFT);

        return $query->getResult();
    }

    public function getQueryBuilderForApprovedInstitutions()
    {
        $qb = $this->createQueryBuilder('a')
            ->where('a.status = :approved_status')
            ->setParameter('approved_status', InstitutionStatus::getBitValueForApprovedStatus());

        return $qb;
    }

    //TODO: paging
    public function getInstitutionsByCountry($country)
    {
        $dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.country = :country AND a.status <> :status ";
        //$dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.country = :country ";

        $query = $this->_em->createQuery($dql)
            ->setParameter('status', InstitutionStatus::INACTIVE)
            ->setParameter('country', $country);


        return $query->getResult();
    }

    public function getInstitutionsByCity($city)
    {
        $dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.country = :country AND a.status <> :status ";
        //$dql = "SELECT a FROM InstitutionBundle:Institution a WHERE a.city = :city ";

        $query = $this->_em->createQuery($dql)
            ->setParameter('status', InstitutionStatus::INACTIVE)
            ->setParameter('city', $city);


        return $query->getResult();
    }

    /**
     * Get global awards of an institution
     *
     * @param Institution $institution
     * @return array GlobalAward
     */
    public function getAllGlobalAwardsByInstitution(Institution $institution)
    {
        $globalAwardPropertyType = $this->getEntityManager()->getRepository('InstitutionBundle:InstitutionPropertyType')->findOneBy(array('name' => InstitutionPropertyType::TYPE_GLOBAL_AWARD));
{'fraction_non_alphanumeric': 0.10793871866295264, 'fraction_numerical': 0.00046425255338904364, 'mean_word_length': 3.4463364293085657, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1921039', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2261, 'n_words': 490}