<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use RxConnexionBundle\Entity\Base\BaseEntity;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ClinicmasterFileRepository")
 * @ORM\Table(name="clinicmaster_file")
 */

class ClinicmasterFileEntity extends BaseEntity
{
    /**
     * @ORM\Column(name="branch_name", type="string", nullable=true)
     */
    protected $branchName;

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

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

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

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

    /**
     * @ORM\ManyToOne(targetEntity="PatientEntity", inversedBy="clinicmasterFiles")
     * @ORM\JoinColumn(name="patient_id", referencedColumnName="id")
     */
    protected $patient;

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

    /**
     * Remove the photo from the disk
     *
     * @ORM\PreRemove
     */
    public function removeFile() {

        $file = $this->getUploadRootDir() . '/' . $this->parsedDescription;
        if(!empty($this->parsedDescription) && file_exists($file)) unlink($file);
    }

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

    /**
     * Get uploadDir
     *
     * @return string
     */
    public function getUploadDir() {

        return 'uploads/patient/files';
    }

    /**
     * Get uploadDir
     *
     * @return string
     */
    public function getUploadForBillingDir() {

        return 'uploads/patient/billing';
    }

    /**
     * Get uploadRootDir
     *
     * @return string
     */
    public function getUploadRootDir() {

        return __DIR__ . '/../../../web/' . $this->getUploadDir();
    }

    /**
     * get fileWebPath
     *
     * @return string
     */
    public function getFileWebPath() {

        $parsedDesc = $this->parsedDescription;
        $file = $this->getUploadRootDir() . '/' . $parsedDesc;

        if(!empty($parsedDesc) && file_exists($file)) {
            return '/' . $this->getUploadDir() . '/' . $parsedDesc;
        } else {
            return '';
        }
    }

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


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

        return $this;
    }

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

    /**
     * Set parsedDescription
     *
     * @param string $parsedDescription
     *
     * @return ClinicmasterFileEntity
     */
    public function setParsedDescription($parsedDescription)
    {
        $this->parsedDescription = $parsedDescription;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Set patient
     *
     * @param \RxConnexionBundle\Entity\PatientEntity $patient
     *
     * @return ClinicmasterFileEntity
     */
    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 patientName
     *
     * @param string $patientName
     *
     * @return ClinicmasterFileEntity
     */
    public function setPatientName($patientName)
    {
        $this->patientName = $patientName;

        return $this;
    }

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

    /**
     * Set branchName
     *
     * @param string $branchName
     *
     * @return ClinicmasterFileEntity
     */
    public function setBranchName($branchName)
    {
        $this->branchName = $branchName;

        return $this;
    }

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