<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RxConnexionBundle\Entity\Base\BaseEntity;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\MaxDepth;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ReferringHealthFacilityRepository")
 * @ORM\Table(name="referring_health_facility")
 */

class ReferringHealthFacilityEntity extends BaseEntity
{

    /**
     * @ORM\Column(name="company_description", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $companyDescription;

    /**
     * @ORM\Column(name="branch_description", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $branchDescription;

    /**
     * @ORM\Column(type="string")
     * @Groups("forAudit")
     */
    protected $description;

    /**
     * @ORM\Column(type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $address;

    /**
     * @ORM\Column(name="geo_latitude", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $geoLatitude;

    /**
     * @ORM\Column(name="geo_longitude", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $geoLongitude;

    /**
     * @ORM\Column(type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $street;

    /**
     * @ORM\Column(name="mobile_no", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $mobileNo;

    /**
     * @ORM\Column(name="mobile_no_two", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $mobileNoTwo;

    /**
     * @ORM\Column(name="phone_no", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $phoneNo;

    /**
     * @ORM\Column(name="phone_no_two", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $phoneNoTwo;

    /**
     * @ORM\Column(name="fax_no", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $faxNo;

    /**
     * @ORM\Column(name="fax_no_two", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $faxNoTwo;

    /**
     * @ORM\Column(name="email", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $email;

    /**
     * @ORM\Column(name="email_two", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $emailTwo;

    /**
     * @ORM\Column(name="old_sys_id", type="string", nullable=true)
     * @Groups("forAudit")
     */
    protected $oldSysId;

    /**
     * @ORM\Column(name="is_deleted", type="boolean")
     */
    protected $isDeleted;

    /**
     * @ORM\Column(name="is_active", type="boolean", nullable=true)
     */
    protected $isActive;

    /**
     * @ORM\ManyToOne(targetEntity="CityEntity", inversedBy="referringHealthFacilities")
     * @ORM\JoinColumn(name="city_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $city;

    /**
     * @ORM\ManyToOne(targetEntity="PostalCodeEntity", inversedBy="referringHealthFacilities")
     * @ORM\JoinColumn(name="postal_code_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $postalCode;

    /**
     * @ORM\OneToMany(targetEntity="ReferringHealthFacilityProviderEntity", mappedBy="referringHealthFacility")
     */
    protected $referringHealthFacilityProviders;


    /**
     * @ORM\OneToMany(targetEntity="PatientReferringHealthFacilityEntity", mappedBy="referringHealthFacility")
     */
    protected $patientReferringHealthFacilities;

    /**
     * @ORM\OneToMany(targetEntity="ReferralEntity", mappedBy="referringHealthFacility")
     */
    protected $referrals;

    /**
     * @ORM\OneToMany(targetEntity="SalesAgentReferringHealthFacilityEntity", mappedBy="referringHealthFacility")
     */
    protected $referringHealthFacilities;

    /**
     * @ORM\OneToMany(targetEntity="RxConnexionBundle\Entity\FaxingOptionEntity", mappedBy="referringHealthFacility")
     */
    protected $faxingOptions;

    public function __construct()
    {

        $this->referringHealthFacilityProviders = new ArrayCollection();
        $this->referrals = new ArrayCollection();
        $this->faxingOptions = new ArrayCollection();
    }

    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        parent::setCreatedAtValue();
        $this->updateAddress();
        $this->isDeleted = 0;
    }

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        parent::setUpdatedAtValue();
        $this->updateAddress();
    }

    /**
     * Concatenate address
     */
    public function updateAddress() {
        $this->address = $this->street . ' ' . ($this->city ? $this->city->getDescription() . ', ' . ($this->city->getProvince() != null ? $this->city->getProvince()->getDescription() : '') . ' ' . ($this->city->getProvince() != null ? $this->city->getProvince()->getCountry()->getDescription() : '')  . ' ' : '') . ($this->getPostalCode() ? $this->getPostalCode()->getDescription() : '');
    }

    //PATIENT LETTER ADDRESS
    public function getReferringAffiliateAddress() {
        $city = isset($this->city) ? $this->city->getDescription() : '';
        $province = isset($this->city) ? $this->city->getProvince()->getDescription() : '';
        $postal = isset($this->postalCode) ? $this->getPostalCode()->getDescription() : '';

        $address = $this->street.','.'<br>'.$city.' '.$province.' '.$postal;

        return $address;
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					User Defined Setters and Getters													  */
    /*--------------------------------------------------------------------------------------------------------*/


    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/


    /**
     * Set companyDescription
     *
     * @param string $companyDescription
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setCompanyDescription($companyDescription)
    {
        $this->companyDescription = $companyDescription;

        return $this;
    }

    /**
     * Get companyDescription
     *
     * @return string
     */
    public function getCompanyDescription()
    {
        return $this->companyDescription;
    }

    /**
     * Set branchDescription
     *
     * @param string $branchDescription
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setBranchDescription($branchDescription)
    {
        $this->branchDescription = $branchDescription;

        return $this;
    }

    /**
     * Get branchDescription
     *
     * @return string
     */
    public function getBranchDescription()
    {
        return $this->branchDescription;
    }

    /**
     * Set description
     *
     * @param string $description
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set address
     *
     * @param string $address
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setAddress($address)
    {
        $this->address = $address;

        return $this;
    }

    /**
     * Get address
     *
     * @return string
     */
    public function getAddress()
    {
        return $this->address;
    }

    /**
     * Set geoLatitude
     *
     * @param string $geoLatitude
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setGeoLatitude($geoLatitude)
    {
        $this->geoLatitude = $geoLatitude;

        return $this;
    }

    /**
     * Get geoLatitude
     *
     * @return string
     */
    public function getGeoLatitude()
    {
        return $this->geoLatitude;
    }

    /**
     * Set geoLongitude
     *
     * @param string $geoLongitude
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setGeoLongitude($geoLongitude)
    {
        $this->geoLongitude = $geoLongitude;

        return $this;
    }

    /**
     * Get geoLongitude
     *
     * @return string
     */
    public function getGeoLongitude()
    {
        return $this->geoLongitude;
    }

    /**
     * Set street
     *
     * @param string $street
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setStreet($street)
    {
        $this->street = $street;

        return $this;
    }

    /**
     * Get street
     *
     * @return string
     */
    public function getStreet()
    {
        return $this->street;
    }

    /**
     * Set mobileNo
     *
     * @param string $mobileNo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setMobileNo($mobileNo)
    {
        $this->mobileNo = $mobileNo;

        return $this;
    }

    /**
     * Get mobileNo
     *
     * @return string
     */
    public function getMobileNo()
    {
        return $this->mobileNo;
    }

    /**
     * Set mobileNoTwo
     *
     * @param string $mobileNoTwo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setMobileNoTwo($mobileNoTwo)
    {
        $this->mobileNoTwo = $mobileNoTwo;

        return $this;
    }

    /**
     * Get mobileNoTwo
     *
     * @return string
     */
    public function getMobileNoTwo()
    {
        return $this->mobileNoTwo;
    }

    /**
     * Set phoneNo
     *
     * @param string $phoneNo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setPhoneNo($phoneNo)
    {
        $this->phoneNo = $phoneNo;

        return $this;
    }

    /**
     * Get phoneNo
     *
     * @return string
     */
    public function getPhoneNo()
    {
        return $this->phoneNo;
    }

    /**
     * Set phoneNoTwo
     *
     * @param string $phoneNoTwo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setPhoneNoTwo($phoneNoTwo)
    {
        $this->phoneNoTwo = $phoneNoTwo;

        return $this;
    }

    /**
     * Get phoneNoTwo
     *
     * @return string
     */
    public function getPhoneNoTwo()
    {
        return $this->phoneNoTwo;
    }

    /**
     * Set email
     *
     * @param string $email
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set emailTwo
     *
     * @param string $emailTwo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setEmailTwo($emailTwo)
    {
        $this->emailTwo = $emailTwo;

        return $this;
    }

    /**
     * Get emailTwo
     *
     * @return string
     */
    public function getEmailTwo()
    {
        return $this->emailTwo;
    }

    /**
     * Set city
     *
     * @param \RxConnexionBundle\Entity\CityEntity $city
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setCity(\RxConnexionBundle\Entity\CityEntity $city = null)
    {
        $this->city = $city;

        return $this;
    }

    /**
     * Get city
     *
     * @return \RxConnexionBundle\Entity\CityEntity
     */
    public function getCity()
    {
        return $this->city;
    }


    /**
     * Add referringHealthFacilityProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider
     *
     * @return ReferringHealthFacilityEntity
     */
    public function addReferringProviderHealthFacility(\RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider)
    {
        $this->referringHealthFacilityProviders[] = $referringHealthFacilityProvider;

        return $this;
    }

    /**
     * Remove referringHealthFacilityProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider
     */
    public function removeReferringProviderHealthFacility(\RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider)
    {
        $this->referringHealthFacilityProviders->removeElement($referringHealthFacilityProvider);
    }

    /**
     * Get referringHealthFacilityProviders
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getReferringProviderHealthFacilities()
    {
        return $this->referringHealthFacilityProviders;
    }

    /**
     * Add referringHealthFacilityProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider
     *
     * @return ReferringHealthFacilityEntity
     */
    public function addReferringHealthFacilityProvider(\RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider)
    {
        $this->referringHealthFacilityProviders[] = $referringHealthFacilityProvider;

        return $this;
    }

    /**
     * Remove referringHealthFacilityProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider
     */
    public function removeReferringHealthFacilityProvider(\RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider)
    {
        $this->referringHealthFacilityProviders->removeElement($referringHealthFacilityProvider);
    }

    /**
     * Get referringHealthFacilityProviders
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getReferringHealthFacilityProviders()
    {
        return $this->referringHealthFacilityProviders;
    }

    /**
     * Add referral
     *
     * @param \RxConnexionBundle\Entity\ReferralEntity $referral
     *
     * @return ReferringHealthFacilityEntity
     */
    public function addReferral(\RxConnexionBundle\Entity\ReferralEntity $referral)
    {
        $this->referrals[] = $referral;

        return $this;
    }

    /**
     * Remove referral
     *
     * @param \RxConnexionBundle\Entity\ReferralEntity $referral
     */
    public function removeReferral(\RxConnexionBundle\Entity\ReferralEntity $referral)
    {
        $this->referrals->removeElement($referral);
    }

    /**
     * Get referrals
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getReferrals()
    {
        return $this->referrals;
    }

    /**
     * Set postalCode
     *
     * @param \RxConnexionBundle\Entity\PostalCodeEntity $postalCode
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setPostalCode(\RxConnexionBundle\Entity\PostalCodeEntity $postalCode = null)
    {
        $this->postalCode = $postalCode;

        return $this;
    }

    /**
     * Get postalCode
     *
     * @return \RxConnexionBundle\Entity\PostalCodeEntity
     */
    public function getPostalCode()
    {
        return $this->postalCode;
    }

    /**
     * Set oldSysId
     *
     * @param string $oldSysId
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setOldSysId($oldSysId)
    {
        $this->oldSysId = $oldSysId;

        return $this;
    }

    /**
     * Get oldSysId
     *
     * @return string
     */
    public function getOldSysId()
    {
        return $this->oldSysId;
    }

    /**
     * Set faxNo
     *
     * @param string $faxNo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setFaxNo($faxNo)
    {
        $this->faxNo = $faxNo;

        return $this;
    }

    /**
     * Get faxNo
     *
     * @return string
     */
    public function getFaxNo()
    {
        return $this->faxNo;
    }

    /**
     * Set faxNoTwo
     *
     * @param string $faxNoTwo
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setFaxNoTwo($faxNoTwo)
    {
        $this->faxNoTwo = $faxNoTwo;

        return $this;
    }

    /**
     * Get faxNoTwo
     *
     * @return string
     */
    public function getFaxNoTwo()
    {
        return $this->faxNoTwo;
    }

//    /**
//     * Get allFaxNo
//     *
//     * @return string
//     */
//    public function getAllFaxNo()
//    {
//        $arrFax = array(preg_replace("/[^0-9]/", "", $this->faxNo ),preg_replace("/[^0-9]/", "", $this->faxNoTwo ));
//        $fax = implode('|',array_filter($arrFax));
//        return $fax;
//    }

    /**
     * Add patientReferringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\PatientReferringHealthFacilityEntity $patientReferringHealthFacility
     *
     * @return ReferringHealthFacilityEntity
     */
    public function addPatientReferringHealthFacility(\RxConnexionBundle\Entity\PatientReferringHealthFacilityEntity $patientReferringHealthFacility)
    {
        $this->patientReferringHealthFacilities[] = $patientReferringHealthFacility;

        return $this;
    }

    /**
     * Remove patientReferringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\PatientReferringHealthFacilityEntity $patientReferringHealthFacility
     */
    public function removePatientReferringHealthFacility(\RxConnexionBundle\Entity\PatientReferringHealthFacilityEntity $patientReferringHealthFacility)
    {
        $this->patientReferringHealthFacilities->removeElement($patientReferringHealthFacility);
    }

    /**
     * Get patientReferringHealthFacilities
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getPatientReferringHealthFacilities()
    {
        return $this->patientReferringHealthFacilities;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set createdBy
     *
     * @param string $createdBy
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setCreatedBy($createdBy)
    {
        $this->createdBy = $createdBy;

        return $this;
    }

    /**
     * Get createdBy
     *
     * @return string
     */
    public function getCreatedBy()
    {
        return $this->createdBy;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedBy
     *
     * @param string $updatedBy
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setUpdatedBy($updatedBy)
    {
        $this->updatedBy = $updatedBy;

        return $this;
    }

    /**
     * Get updatedBy
     *
     * @return string
     */
    public function getUpdatedBy()
    {
        return $this->updatedBy;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Add referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility
     *
     * @return ReferringHealthFacilityEntity
     */
    public function addReferringHealthFacility(\RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility)
    {
        $this->referringHealthFacilities[] = $referringHealthFacility;

        return $this;
    }

    /**
     * Remove referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility
     */
    public function removeReferringHealthFacility(\RxConnexionBundle\Entity\SalesAgentReferringHealthFacilityEntity $referringHealthFacility)
    {
        $this->referringHealthFacilities->removeElement($referringHealthFacility);
    }

    /**
     * Get referringHealthFacilities
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getReferringHealthFacilities()
    {
        return $this->referringHealthFacilities;
    }

    /**
     * Set isDeleted
     *
     * @param boolean $isDeleted
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setIsDeleted($isDeleted)
    {
        $this->isDeleted = $isDeleted;

        return $this;
    }

    /**
     * Get isDeleted
     *
     * @return boolean
     */
    public function getIsDeleted()
    {
        return $this->isDeleted;
    }

    /**
     * Set isActive
     *
     * @param boolean $isActive
     *
     * @return ReferringHealthFacilityEntity
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }

    /**
     * Get isActive
     *
     * @return boolean
     */
    public function getIsActive()
    {
        return $this->isActive;
    }

    /**
     * Add faxingOption
     *
     * @param \RxConnexionBundle\Entity\FaxingOptionEntity $faxingOption
     *
     * @return ReferringHealthFacilityEntity
     */
    public function addFaxingOption(\RxConnexionBundle\Entity\FaxingOptionEntity $faxingOption)
    {
        $this->faxingOptions[] = $faxingOption;

        return $this;
    }

    /**
     * Remove faxingOption
     *
     * @param \RxConnexionBundle\Entity\FaxingOptionEntity $faxingOption
     */
    public function removeFaxingOption(\RxConnexionBundle\Entity\FaxingOptionEntity $faxingOption)
    {
        $this->faxingOptions->removeElement($faxingOption);
    }

    /**
     * Get faxingOptions
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getFaxingOptions()
    {
        return $this->faxingOptions;
    }
}
