<?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\PatientReferringHealthFacilityRepository")
 * @ORM\Table(name="patient_referring_health_facility")
 */

class PatientReferringHealthFacilityEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="start_date", type="datetime")
     * @Groups("forAudit")
     */
    protected $startDate;

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

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

    /**
     * @ORM\ManyToOne(targetEntity="PatientEntity", inversedBy="patientReferringHealthFacilities")
     * @ORM\JoinColumn(name="patient_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $patient;

    /**
     * @ORM\ManyToOne(targetEntity="ReferringHealthFacilityEntity", inversedBy="patientReferringHealthFacilities")
     * @ORM\JoinColumn(name="referring_health_facility_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $referringHealthFacility;

    /**
     * @ORM\OneToMany(targetEntity="PatientLetterEntity", mappedBy="patientReferringHealthFacility")
     */
    protected $patientLetters;

    /**
     * @ORM\OneToMany(targetEntity="PatientLetterCcEntity", mappedBy="patientReferringHealthFacility")
     */
    protected $patientLetterCcs;

    /**
     * @ORM\OneToMany(targetEntity="AppointmentNoticeFaxEntity", mappedBy="patientReferringHealthFacility")
     */
    protected $appointmentNoticeFaxes;

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

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->patientLetters = new ArrayCollection();
        $this->appointmentNoticeFaxes = new ArrayCollection();
    }

    /*--------------------------------------------------------------------------------------------------------*/
    /*					Use Defined Setters and Getters														  */
    /*--------------------------------------------------------------------------------------------------------*/
    /**
     * Get startDateAsString
     *
     * @return string
     */
    public function getStartDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->startDate) ? date('m/d/Y', strtotime($dttst->transform($this->startDate))) : '';
    }
    /**
     * Get endDateAsString
     *
     * @return string
     */
    public function getEndDateAsString() {

        $dttst = new DateTimeToStringTransformer();
        return !empty($this->endDate) ? date('m/d/Y', strtotime($dttst->transform($this->endDate))) : '';
    }
    /*--------------------------------------------------------------------------------------------------------*/
    /*					Setters and Getters																	  */
    /*--------------------------------------------------------------------------------------------------------*/

    /**
     * Set startDate
     *
     * @param \DateTime $startDate
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function setStartDate($startDate)
    {

        $this->startDate = empty($startDate) ? NULL : new \DateTime($startDate);

        return $this;
    }

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

    /**
     * Set endDate
     *
     * @param \DateTime $endDate
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function setEndDate($endDate)
    {
        $this->endDate = empty($endDate) ? NULL : new \DateTime($endDate);

        return $this;
    }

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

    /**
     * Set patient
     *
     * @param \RxConnexionBundle\Entity\PatientEntity $patient
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function setPatient(\RxConnexionBundle\Entity\PatientEntity $patient = null)
    {
        $this->patient = $patient;

        return $this;
    }

    /**
     * Get patient
     *
     * @return \RxConnexionBundle\Entity\PatientEntity
     */
    public function getPatient()
    {
        return $this->patient;
    }

    /**
     * Set referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityEntity $referringHealthFacility
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function setReferringHealthFacility(\RxConnexionBundle\Entity\ReferringHealthFacilityEntity $referringHealthFacility = null)
    {
        $this->referringHealthFacility = $referringHealthFacility;

        return $this;
    }

    /**
     * Get referringHealthFacility
     *
     * @return \RxConnexionBundle\Entity\ReferringHealthFacilityEntity
     */
    public function getReferringHealthFacility()
    {
        return $this->referringHealthFacility;
    }

    /**
     * Add patientLetter
     *
     * @param \RxConnexionBundle\Entity\PatientLetterEntity $patientLetter
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function addPatientLetter(\RxConnexionBundle\Entity\PatientLetterEntity $patientLetter)
    {
        $this->patientLetters[] = $patientLetter;

        return $this;
    }

    /**
     * Remove patientLetter
     *
     * @param \RxConnexionBundle\Entity\PatientLetterEntity $patientLetter
     */
    public function removePatientLetter(\RxConnexionBundle\Entity\PatientLetterEntity $patientLetter)
    {
        $this->patientLetters->removeElement($patientLetter);
    }

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

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

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

        return $this;
    }

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

    /**
     * Add patientAppointment
     *
     * @param \RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $patientAppointment
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function addPatientAppointment(\RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $patientAppointment)
    {
        $this->patientAppointment[] = $patientAppointment;

        return $this;
    }

    /**
     * Remove patientAppointment
     *
     * @param \RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $patientAppointment
     */
    public function removePatientAppointment(\RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $patientAppointment)
    {
        $this->patientAppointment->removeElement($patientAppointment);
    }

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

    /**
     * Add appointmentNoticeFax
     *
     * @param \RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function addAppointmentNoticeFax(\RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax)
    {
        $this->appointmentNoticeFaxes[] = $appointmentNoticeFax;

        return $this;
    }

    /**
     * Remove appointmentNoticeFax
     *
     * @param \RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax
     */
    public function removeAppointmentNoticeFax(\RxConnexionBundle\Entity\AppointmentNoticeFaxEntity $appointmentNoticeFax)
    {
        $this->appointmentNoticeFaxes->removeElement($appointmentNoticeFax);
    }

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

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

        return $this;
    }

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

    /**
     * Add patientLetterCc
     *
     * @param \RxConnexionBundle\Entity\PatientLetterCcEntity $patientLetterCc
     *
     * @return PatientReferringHealthFacilityEntity
     */
    public function addPatientLetterCc(\RxConnexionBundle\Entity\PatientLetterCcEntity $patientLetterCc)
    {
        $this->patientLetterCcs[] = $patientLetterCc;

        return $this;
    }

    /**
     * Remove patientLetterCc
     *
     * @param \RxConnexionBundle\Entity\PatientLetterCcEntity $patientLetterCc
     */
    public function removePatientLetterCc(\RxConnexionBundle\Entity\PatientLetterCcEntity $patientLetterCc)
    {
        $this->patientLetterCcs->removeElement($patientLetterCc);
    }

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