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

class ChartProcedureEntity extends BaseEntity
{

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

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

    /**
     * @ORM\Column(name="amount", type="decimal", precision=10, scale=2, nullable=true)
     */
    protected $amount;

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

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

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

    /**
     * @ORM\OneToMany(targetEntity="PatientChartProcedureEntity", mappedBy="chartProcedure")
     */
    protected $patientChartProcedures;

    /**
     * @ORM\OneToMany(targetEntity="PatientBillingBreakdownEntity", mappedBy="chartProcedure")
     */
    protected $patientBillingBreakdowns;

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

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

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

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

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

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


    /**
     * Set code
     *
     * @param string $code
     *
     * @return ChartProcedureEntity
     */
    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 ChartProcedureEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set amount
     *
     * @param string $amount
     *
     * @return ChartProcedureEntity
     */
    public function setAmount($amount)
    {
        $this->amount = str_replace(',' ,'',$amount);

        return $this;
    }

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

    /**
     * Set account
     *
     * @param \RxConnexionBundle\Entity\AccountEntity $account
     *
     * @return ChartProcedureEntity
     */
    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 patientChartProcedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartProcedure
     *
     * @return ChartProcedureEntity
     */
    public function addPatientChartProcedure(\RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartProcedure)
    {
        $this->patientChartProcedures[] = $patientChartProcedure;

        return $this;
    }

    /**
     * Remove patientChartProcedure
     *
     * @param \RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartProcedure
     */
    public function removePatientChartProcedure(\RxConnexionBundle\Entity\PatientChartProcedureEntity $patientChartProcedure)
    {
        $this->patientChartProcedures->removeElement($patientChartProcedure);
    }

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

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

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

        return $this;
    }

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

    /**
     * Set chartType
     *
     * @param \RxConnexionBundle\Entity\ChartTypeEntity $chartType
     *
     * @return ChartProcedureEntity
     */
    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;
    }

    /**
     * Add patientBillingBreakdown
     *
     * @param \RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown
     *
     * @return ChartProcedureEntity
     */
    public function addPatientBillingBreakdown(\RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown)
    {
        $this->patientBillingBreakdowns[] = $patientBillingBreakdown;

        return $this;
    }

    /**
     * Remove patientBillingBreakdown
     *
     * @param \RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown
     */
    public function removePatientBillingBreakdown(\RxConnexionBundle\Entity\PatientBillingBreakdownEntity $patientBillingBreakdown)
    {
        $this->patientBillingBreakdowns->removeElement($patientBillingBreakdown);
    }

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

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

        return $this;
    }

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