<?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\ChartStatusRepository")
 * @ORM\Table(name="chart_status", indexes={@ORM\Index(name="IDX_SEARCH_000", columns={"description"})})
 */

class ChartStatusEntity extends BaseEntity
{

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

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="AccountEntity", inversedBy="chartStatuses")
     * @ORM\JoinColumn(name="account_id", referencedColumnName="id")
     * @Groups("forAudit")
     * @MaxDepth(1)
     */
    protected $account;

    /**
     * @ORM\OneToMany(targetEntity="PatientChartEntity", mappedBy="chartStatus")
     */
    protected $patientCharts;

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

    /**
     * @ORM\OneToMany(targetEntity="ChartSubStatusEntity", mappedBy="chartStatus")
     */
    protected $chartSubStatuses;


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

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

    /*--------------------------------------------------------------------------------------------------------*/
    /*					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))) : '';
    }

    /**
     * Get accountAndDescription
     *
     * @return string
     */
    public function getAccountAndDescription() {

        return ($this->account ? $this->account->getIdAndDescription() . ' | ' : '') . $this->description;
    }

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


    /**
     * Set code
     *
     * @param string $code
     *
     * @return ChartStatusEntity
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set account
     *
     * @param \RxConnexionBundle\Entity\AccountEntity $account
     *
     * @return ChartStatusEntity
     */
    public function setAccount(\RxConnexionBundle\Entity\AccountEntity $account = null)
    {
        $this->account = $account;

        return $this;
    }

    /**
     * Get account
     *
     * @return \RxConnexionBundle\Entity\AccountEntity
     */
    public function getAccount()
    {
        return $this->account;
    }

    /**
     * Add patientChart
     *
     * @param \RxConnexionBundle\Entity\PatientChartEntity $patientChart
     *
     * @return ChartStatusEntity
     */
    public function addPatientChart(\RxConnexionBundle\Entity\PatientChartEntity $patientChart)
    {
        $this->patientCharts[] = $patientChart;

        return $this;
    }

    /**
     * Remove patientChart
     *
     * @param \RxConnexionBundle\Entity\PatientChartEntity $patientChart
     */
    public function removePatientChart(\RxConnexionBundle\Entity\PatientChartEntity $patientChart)
    {
        $this->patientCharts->removeElement($patientChart);
    }

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

    /**
     * Set chartType
     *
     * @param \RxConnexionBundle\Entity\ChartTypeEntity $chartType
     *
     * @return ChartStatusEntity
     */
    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 startDate
     *
     * @param \DateTime $startDate
     *
     * @return ChartStatusEntity
     */
    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 ChartStatusEntity
     */
    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 isActive
     *
     * @param boolean $isActive
     *
     * @return ChartStatusEntity
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set ordinal
     *
     * @param string $ordinal
     *
     * @return ChartStatusEntity
     */
    public function setOrdinal($ordinal)
    {
        $this->ordinal = $ordinal;

        return $this;
    }

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

    /**
     * Add chartSubStatus
     *
     * @param \RxConnexionBundle\Entity\ChartSubStatusEntity $chartSubStatus
     *
     * @return ChartStatusEntity
     */
    public function addChartSubStatus(\RxConnexionBundle\Entity\ChartSubStatusEntity $chartSubStatus)
    {
        $this->chartSubStatuses[] = $chartSubStatus;

        return $this;
    }

    /**
     * Remove chartSubStatus
     *
     * @param \RxConnexionBundle\Entity\ChartSubStatusEntity $chartSubStatus
     */
    public function removeChartSubStatus(\RxConnexionBundle\Entity\ChartSubStatusEntity $chartSubStatus)
    {
        $this->chartSubStatuses->removeElement($chartSubStatus);
    }

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