<commit_before><?php

namespace HealthCareAbroad\InstitutionBundle\Services;

use HealthCareAbroad\HelperBundle\Entity\GlobalAward;

use HealthCareAbroad\HelperBundle\Entity\GlobalAwardTypes;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionSpecialization;

use HealthCareAbroad\DoctorBundle\Entity\Doctor;

use HealthCareAbroad\MediaBundle\Entity\Media;

use HealthCareAbroad\MediaBundle\Entity\Gallery;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterProperty;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionPropertyType;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionStatus;

use HealthCareAbroad\TreatmentBundle\Entity\Specialization;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenter;

use HealthCareAbroad\InstitutionBundle\Entity\Institution;

use Doctrine\Bundle\DoctrineBundle\Registry;

/**
 * Service class for InstitutionMedicalCenter. Accessible by services.institution_medical_center service id
 * 
 * @author <NAME>
 */
class InstitutionMedicalCenterService
{
    /**
     * @var Registry
     */
    private $doctrine;
    
    static private $institutionMedicalCenter;
    
    /**
     * @var InstitutionMedicalCenterPropertyService
     */
    private $institutionMedicalCenterPropertyService;
    
    public function setDoctrine(Registry $doctrine)
    {
        $this->doctrine = $doctrine;
    }
    
    public function getFullInstitutionMedicalCenterBySlug($slug = '')
    {
        if(!$slug) {
            return null;
        }

        static $isLoaded = false;

        if(!$isLoaded) {
            $qb = $this->doctrine->getEntityManager()->createQueryBuilder();
            $qb->select('a, b, c, d, e, f, g, h, i, j, k, l')->from('InstitutionBundle:InstitutionMedicalCenter', 'a')
            ->leftJoin('a.institution', 'b')
            ->leftJoin('b.country', 'c')
            ->leftJoin('b.city', 'd')
            ->leftJoin('a.institutionSpecializations', 'e')
            ->leftJoin('e.specialization', 'f')
            ->leftJoin('e.treatments', 'g')
            ->leftJoin('g.subSpecializations', 'h')
            ->leftJoin('a.media', 'i')
            ->leftJoin('a.logo', 'j')
            ->leftJoin('a.doctors', 'k')
            ->leftJoin('k.specializations', 'l')
            ->where('a.slug = :centerSlug')
            ->andWhere('a.status = :status')
            ->setParameter('centerSlug', $slug)
            ->setParameter('status', InstitutionMedicalCenterStatus::APPROVED);

            self::$institutionMedicalCenter = $qb->getQuery()->getOneOrNullResult();

            $isLoaded = true;
        }

        return self::$institutionMedicalCenter;
    }
    
    /**
     * Get active institution specializations of an institution medical center
     * 
     * @param InstitutionMedicalCenter $institutionMedicalCenter
     * @return array InstitutionSpecialization
     */
    public function getActiveSpecializations(InstitutionMedicalCenter $institutionMedicalCenter)
    {
        return $this->doctrine->getRepository('InstitutionBundle:InstitutionSpecialization')->getActiveSpecializationsByInstitutionMedicalCenter($institutionMedicalCenter);
    }
    
    /**
     * List active specializations of a medical center
     * Returns a flat array of specializationId => specializationName
     * 
     * @param InstitutionMedicalCenter $institutionMedicalCenter<commit_msg>Fixed clinic default logo from first specialization.<commit_after><?php

namespace HealthCareAbroad\InstitutionBundle\Services;

use HealthCareAbroad\HelperBundle\Entity\GlobalAward;

use HealthCareAbroad\HelperBundle\Entity\GlobalAwardTypes;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionSpecialization;

use HealthCareAbroad\DoctorBundle\Entity\Doctor;

use HealthCareAbroad\MediaBundle\Entity\Media;

use HealthCareAbroad\MediaBundle\Entity\Gallery;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterProperty;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionPropertyType;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionStatus;

use HealthCareAbroad\TreatmentBundle\Entity\Specialization;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenterStatus;

use HealthCareAbroad\InstitutionBundle\Entity\InstitutionMedicalCenter;

use HealthCareAbroad\InstitutionBundle\Entity\Institution;

use Doctrine\Bundle\DoctrineBundle\Registry;

/**
 * Service class for InstitutionMedicalCenter. Accessible by services.institution_medical_center service id
 * 
 * @author <NAME>
 */
class InstitutionMedicalCenterService
{
    /**
     * @var Registry
     */
    private $doctrine;
    
    static private $institutionMedicalCenter;
    
    /**
     * @var InstitutionMedicalCenterPropertyService
     */
    private $institutionMedicalCenterPropertyService;
    
    public function setDoctrine(Registry $doctrine)
    {
        $this->doctrine = $doctrine;
    }
    
    public function getFullInstitutionMedicalCenterBySlug($slug = '')
    {
        if(!$slug) {
            return null;
        }

        static $isLoaded = false;

        if(!$isLoaded) {
            $qb = $this->doctrine->getEntityManager()->createQueryBuilder();
            $qb->select('a, b, c, d, e, f, g, h, i, j, k, l')->from('InstitutionBundle:InstitutionMedicalCenter', 'a')
            ->leftJoin('a.institution', 'b')
            ->leftJoin('b.country', 'c')
            ->leftJoin('b.city', 'd')
            ->leftJoin('a.institutionSpecializations', 'e')
            ->leftJoin('e.specialization', 'f')
            ->leftJoin('e.treatments', 'g')
            ->leftJoin('g.subSpecializations', 'h')
            ->leftJoin('a.media', 'i')
            ->leftJoin('a.logo', 'j')
            ->leftJoin('a.doctors', 'k')
            ->leftJoin('k.specializations', 'l')
            ->where('a.slug = :centerSlug')
            ->andWhere('a.status = :status')
            ->orderBy('f.id', 'ASC')
            ->setParameter('centerSlug', $slug)
            ->setParameter('status', InstitutionMedicalCenterStatus::APPROVED);

            self::$institutionMedicalCenter = $qb->getQuery()->getOneOrNullResult();

            $isLoaded = true;
        }

        return self::$institutionMedicalCenter;
    }
    
    /**
     * Get active institution specializations of an institution medical center
     * 
     * @param InstitutionMedicalCenter $institutionMedicalCenter
     * @return array InstitutionSpecialization
     */
    public function getActiveSpecializations(InstitutionMedicalCenter $institutionMedicalCenter)
    {
        return $this->doctrine->getRepository('InstitutionBundle:InstitutionSpecialization')->getActiveSpecializationsByInstitutionMedicalCenter($institutionMedicalCenter);
    }
    
    /**
     * List active specializations of a medical center
     * Returns a flat array of specializationId => specializationName
     * 
     * @param InstitutionMedicalCenter $institutionMedicalCenter
{'fraction_non_alphanumeric': 0.11106382978723404, 'fraction_numerical': 0.0, 'mean_word_length': 3.4123904881101375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 60, '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': '6991227', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1901, 'n_words': 327}