<?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\ReferringHealthFacilityChartRepository")
 * @ORM\Table(name="referring_health_facility_chart", indexes={
 *     @ORM\Index(name="IDX_000AAA", columns={"chart_date", "is_deleted"}),
 *     @ORM\Index(name="IDX_000BBB", columns={"chart_date", "is_deleted"}),
 *     @ORM\Index(name="IDX_000CCC", columns={"is_deleted"}),
 *     @ORM\Index(name="IDX_000DDD", columns={"created_at"})
 *     })
 */

class ReferringHealthFacilityChartEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="chart_date", type="datetime", nullable=true)
     * @Groups("forAudit")
     */
    protected $chartDate;

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

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

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="HealthFacilityEntity", inversedBy="referringHealthFacilityCharts")
     * @ORM\JoinColumn(name="health_facility_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $healthFacility;

    /**
     * @ORM\ManyToOne(targetEntity="ChartTypeEntity", inversedBy="referringHealthFacilityCharts")
     * @ORM\JoinColumn(name="chart_type_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $chartType;

    /**
     * @ORM\ManyToOne(targetEntity="ChartStatusEntity", inversedBy="referringHealthFacilityCharts")
     * @ORM\JoinColumn(name="chart_status_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $chartStatus;

    /**
     * @ORM\OneToOne(targetEntity="RxConnexionBundle\Entity\MarketingStaffScheduleEntity", inversedBy="referringHealthFacilityChart")
     * @ORM\JoinColumn(name="marketing_staff_schedule_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $marketingStaffSchedule;

    /**
     * @ORM\ManyToOne(targetEntity="RxConnexionBundle\Entity\MarketingStaffEntity", inversedBy="referringHealthFacilityCharts")
     * @ORM\JoinColumn(name="marketing_staff_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $marketingStaff;

    /**
     * @ORM\ManyToOne(targetEntity="NoteTemplateEntity", inversedBy="referringHealthFacilityCharts")
     * @ORM\JoinColumn(name="note_template_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $noteTemplate;

    /**
     * @ORM\OneToMany(targetEntity="ReferringHealthFacilityChartNoteEntity", mappedBy="referringHealthFacilityChart", cascade={"remove"})
     */
    protected $referringHealthFacilityChartNotes;

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

    /**
     * Set updatedAt
     *
     * @ORM\PreUpdate
     */
    public function setUpdatedAtValue()
    {
        parent::setUpdatedAtValue();
    }

    /**
     * @ORM\PreFlush
     */
    public function preFlush() {
    }

    public function __construct()
    {
        $this->referringHealthFacilityChartNotes = new ArrayCollection();
    }

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

    /**
     * Get chartDateAsString
     *
     * @return string
     */
    public function getChartDateAsString() {

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

    /**
     * Get referringHealthFacilityChartIdWithLink
     *
     * @return string
     */
    public function getReferringHealthFacilityChartIdWithLink() {

        $result = '<a target="_blank" href="/main/referring_health_facility/chart/form/' . base64_encode($this->getReferringHealthFacility()->getId()) . '/u/' . base64_encode($this->id) . '">' . $this->id . '</a>';
        return $result;
    }

    /**
     * Get idAndChartDateAndChartType
     *
     * @return string
     */
    public function getIdAndChartDateAndChartType() {

        return $this->id . ' - ' . $this->getChartDateAsString() . ' - ' . $this->chartType->getDescription();
    }

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


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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set isEndorsed
     *
     * @param boolean $isEndorsed
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setIsEndorsed($isEndorsed)
    {
        $this->isEndorsed = $isEndorsed;

        return $this;
    }

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

    /**
     * Set endorsedBy
     *
     * @param string $endorsedBy
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setEndorsedBy($endorsedBy)
    {
        $this->endorsedBy = $endorsedBy;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set referringHealthFacility
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityEntity $referringHealthFacility
     *
     * @return ReferringHealthFacilityChartEntity
     */
    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;
    }

    /**
     * Set healthFacility
     *
     * @param \RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setHealthFacility(\RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility = null)
    {
        $this->healthFacility = $healthFacility;

        return $this;
    }

    /**
     * Get healthFacility
     *
     * @return \RxConnexionBundle\Entity\HealthFacilityEntity
     */
    public function getHealthFacility()
    {
        return $this->healthFacility;
    }

    /**
     * Set chartType
     *
     * @param \RxConnexionBundle\Entity\ChartTypeEntity $chartType
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setChartType(\RxConnexionBundle\Entity\ChartTypeEntity $chartType = null)
    {
        $this->chartType = $chartType;

        return $this;
    }

    /**
     * Get chartType
     *
     * @return \RxConnexionBundle\Entity\ChartTypeEntity
     */
    public function getChartType()
    {
        return $this->chartType;
    }

    /**
     * Set chartStatus
     *
     * @param \RxConnexionBundle\Entity\ChartStatusEntity $chartStatus
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setChartStatus(\RxConnexionBundle\Entity\ChartStatusEntity $chartStatus = null)
    {
        $this->chartStatus = $chartStatus;

        return $this;
    }

    /**
     * Get chartStatus
     *
     * @return \RxConnexionBundle\Entity\ChartStatusEntity
     */
    public function getChartStatus()
    {
        return $this->chartStatus;
    }

    /**
     * Set marketingStaffSchedule
     *
     * @param \RxConnexionBundle\Entity\MarketingStaffScheduleEntity $marketingStaffSchedule
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setMarketingStaffSchedule(\RxConnexionBundle\Entity\MarketingStaffScheduleEntity $marketingStaffSchedule = null)
    {
        $this->marketingStaffSchedule = $marketingStaffSchedule;

        return $this;
    }

    /**
     * Get marketingStaffSchedule
     *
     * @return \RxConnexionBundle\Entity\MarketingStaffScheduleEntity
     */
    public function getMarketingStaffSchedule()
    {
        return $this->marketingStaffSchedule;
    }

    /**
     * Set marketingStaff
     *
     * @param \RxConnexionBundle\Entity\MarketingStaffEntity $marketingStaff
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setMarketingStaff(\RxConnexionBundle\Entity\MarketingStaffEntity $marketingStaff = null)
    {
        $this->marketingStaff = $marketingStaff;

        return $this;
    }

    /**
     * Get marketingStaff
     *
     * @return \RxConnexionBundle\Entity\MarketingStaffEntity
     */
    public function getMarketingStaff()
    {
        return $this->marketingStaff;
    }

    /**
     * Add referringHealthFacilityChartNote
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityChartNoteEntity $referringHealthFacilityChartNote
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function addReferringHealthFacilityChartNote(\RxConnexionBundle\Entity\ReferringHealthFacilityChartNoteEntity $referringHealthFacilityChartNote)
    {
        $this->referringHealthFacilityChartNotes[] = $referringHealthFacilityChartNote;

        return $this;
    }

    /**
     * Remove referringHealthFacilityChartNote
     *
     * @param \RxConnexionBundle\Entity\ReferringHealthFacilityChartNoteEntity $referringHealthFacilityChartNote
     */
    public function removeReferringHealthFacilityChartNote(\RxConnexionBundle\Entity\ReferringHealthFacilityChartNoteEntity $referringHealthFacilityChartNote)
    {
        $this->referringHealthFacilityChartNotes->removeElement($referringHealthFacilityChartNote);
    }

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

    /**
     * Set noteTemplate
     *
     * @param \RxConnexionBundle\Entity\NoteTemplateEntity $noteTemplate
     *
     * @return ReferringHealthFacilityChartEntity
     */
    public function setNoteTemplate(\RxConnexionBundle\Entity\NoteTemplateEntity $noteTemplate = null)
    {
        $this->noteTemplate = $noteTemplate;

        return $this;
    }

    /**
     * Get noteTemplate
     *
     * @return \RxConnexionBundle\Entity\NoteTemplateEntity
     */
    public function getNoteTemplate()
    {
        return $this->noteTemplate;
    }
}
