<?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\ReferringProviderChartRepository")
 * @ORM\Table(name="referring_provider_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 ReferringProviderChartEntity 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="ReferringProviderEntity", inversedBy="referringProviderCharts")
     * @ORM\JoinColumn(name="referring_provider_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $referringProvider;

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

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

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

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

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

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

    /**
     * @ORM\OneToMany(targetEntity="ReferringProviderChartNoteEntity", mappedBy="referringProviderChart", cascade={"remove"})
     */
    protected $referringProviderChartNotes;

    /**
     * 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->referringProviderChartNotes = 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 referringProviderChartIdWithLink
     *
     * @return string
     */
    public function getReferringProviderChartIdWithLink() {

        $result = '<a target="_blank" href="/main/referring_provider/chart/form/' . base64_encode($this->getReferringProvider()->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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    public function setOldSysId($oldSysId)
    {
        $this->oldSysId = $oldSysId;

        return $this;
    }

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

    /**
     * Set referringProvider
     *
     * @param \RxConnexionBundle\Entity\ReferringProviderEntity $referringProvider
     *
     * @return ReferringProviderChartEntity
     */
    public function setReferringProvider(\RxConnexionBundle\Entity\ReferringProviderEntity $referringProvider = null)
    {
        $this->referringProvider = $referringProvider;

        return $this;
    }

    /**
     * Get referringProvider
     *
     * @return \RxConnexionBundle\Entity\ReferringProviderEntity
     */
    public function getReferringProvider()
    {
        return $this->referringProvider;
    }

    /**
     * Set healthFacility
     *
     * @param \RxConnexionBundle\Entity\HealthFacilityEntity $healthFacility
     *
     * @return ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 ReferringProviderChartEntity
     */
    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 referringProviderChartNote
     *
     * @param \RxConnexionBundle\Entity\ReferringProviderChartNoteEntity $referringProviderChartNote
     *
     * @return ReferringProviderChartEntity
     */
    public function addReferringProviderChartNote(\RxConnexionBundle\Entity\ReferringProviderChartNoteEntity $referringProviderChartNote)
    {
        $this->referringProviderChartNotes[] = $referringProviderChartNote;

        return $this;
    }

    /**
     * Remove referringProviderChartNote
     *
     * @param \RxConnexionBundle\Entity\ReferringProviderChartNoteEntity $referringProviderChartNote
     */
    public function removeReferringProviderChartNote(\RxConnexionBundle\Entity\ReferringProviderChartNoteEntity $referringProviderChartNote)
    {
        $this->referringProviderChartNotes->removeElement($referringProviderChartNote);
    }

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

    /**
     * Set noteTemplate
     *
     * @param \RxConnexionBundle\Entity\NoteTemplateEntity $noteTemplate
     *
     * @return ReferringProviderChartEntity
     */
    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;
    }
}
