<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RxConnexionBundle\Entity\Base\BaseEntity;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\MaxDepth;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ReferringProviderRepository")
 * @ORM\Table(name="referring_provider")
 */

class ReferringProviderEntity extends BaseEntity
{
    const GENDER_MALE = 'Male';
    const GENDER_FEMALE = 'Female';
    const HONORIFIC_DR = 'Dr.';

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

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

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

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

    /**
     * @ORM\Column(name="full_name", type="string", nullable=true)
     */
    protected $fullName;

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

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

    /**
     * @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="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="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="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="note", type="text", nullable=true)
     * @Groups("forAudit")
     */
    protected $note;

    /**
     * @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="referringProviders")
     * @ORM\JoinColumn(name="city_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $city;

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

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

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

    /**
     * @ORM\OneToMany(targetEntity="PatientReferringProviderEntity", mappedBy="referringProvider")
     */
    protected $patientReferringProvider;

    public function __construct()
    {
        $this->referringHealthFacilityProviders = new ArrayCollection();
        $this->referrals = new ArrayCollection();
    }
    /**
     * Set createdAt
     *
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        parent::setCreatedAtValue();
        $this->fullName = ucfirst($this->firstName) . ' ' . ucfirst($this->lastName);
        $this->updateAddress();
        $this->isDeleted = 0;
    }

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        parent::setUpdatedAtValue();
        $this->fullName = ucfirst($this->firstName) . ' ' . ucfirst($this->lastName);
        $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() : '');
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					Use Defined Setters and Getters														  */
    /*--------------------------------------------------------------------------------------------------------*/
    

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

    /**
     * Set firstName
     *
     * @param string $firstName
     *
     * @return ReferringProviderEntity
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;

        return $this;
    }

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

    /**
     * Set middleName
     *
     * @param string $middleName
     *
     * @return ReferringProviderEntity
     */
    public function setMiddleName($middleName)
    {
        $this->middleName = $middleName;

        return $this;
    }

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

    /**
     * Set lastName
     *
     * @param string $lastName
     *
     * @return ReferringProviderEntity
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;

        return $this;
    }

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

    /**
     * Set fullName
     *
     * @param string $fullName
     *
     * @return ReferringProviderEntity
     */
    public function setFullName($fullName)
    {
        $this->fullName = $fullName;

        return $this;
    }

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

    /**
     * Set gender
     *
     * @param string $gender
     *
     * @return ReferringProviderEntity
     */
    public function setGender($gender)
    {
        $this->gender = $gender;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set street
     *
     * @param string $street
     *
     * @return ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    public function setMobileNo($mobileNo)
    {
        $this->mobileNo = $mobileNo;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set note
     *
     * @param string $note
     *
     * @return ReferringProviderEntity
     */
    public function setNote($note)
    {
        $this->note = $note;

        return $this;
    }

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

    /**
     * Set city
     *
     * @param \RxConnexionBundle\Entity\CityEntity $city
     *
     * @return ReferringProviderEntity
     */
    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;
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Add referringHealthFacilityProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityProviderEntity $referringHealthFacilityProvider
     *
     * @return ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 patientReferringProvider
     *
     * @param \RxConnexionBundle\Entity\PatientReferringProviderEntity $patientReferringProvider
     *
     * @return ReferringProviderEntity
     */
    public function addPatientReferringProvider(\RxConnexionBundle\Entity\PatientReferringProviderEntity $patientReferringProvider)
    {
        $this->patientReferringProvider[] = $patientReferringProvider;

        return $this;
    }

    /**
     * Remove patientReferringProvider
     *
     * @param \RxConnexionBundle\Entity\PatientReferringProviderEntity $patientReferringProvider
     */
    public function removePatientReferringProvider(\RxConnexionBundle\Entity\PatientReferringProviderEntity $patientReferringProvider)
    {
        $this->patientReferringProvider->removeElement($patientReferringProvider);
    }

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

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

    /**
     * Set createdBy
     *
     * @param string $createdBy
     *
     * @return ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    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 ReferringProviderEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set honorific
     *
     * @param string $honorific
     *
     * @return ReferringProviderEntity
     */
    public function setHonorific($honorific)
    {
        $this->honorific = $honorific;

        return $this;
    }

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

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

        return $this;
    }

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