123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace App\Models;
- # use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Collection;
- class CareMonth extends Model
- {
- protected $table = 'care_month';
- public function patient(){
- return $this->hasOne(Client::class, 'id', 'client_id');
- }
- public function client(){
- return $this->hasOne(Client::class, 'id', 'client_id');
- }
- public function mcp(){
- return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
- }
- public function cmPro(){
- return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
- }
- public function rmmPro(){
- return $this->hasOne(Pro::class, 'id', 'rmm_pro_id');
- }
- public function rmePro(){
- return $this->hasOne(Pro::class, 'id', 'rme_pro_id');
- }
- public function entries() {
- return $this->hasMany(CareMonthEntry::class, 'care_month_id', 'id');
- }
- public function bills() {
- return $this->hasMany(Bill::class, 'care_month_id', 'id');
- }
- public function claims() {
- return $this->hasMany(Claim::class, 'care_month_id', 'id');
- }
- public function getBillsOfType($_type) {
- $bills = $this->bills;
- $targetBills = new Collection();
- foreach ($bills as $bill) {
- if($bill->cm_or_rm === $_type) {
- $targetBills->add($bill);
- }
- }
- return $targetBills;
- }
- public function rmBill(){
- return $this->hasOne(Bill::class, 'id', 'rm_bill_id');
- }
- public function companyPro()
- {
- return $this->hasOne(CompanyPro::class, 'id', 'company_pro_id');
- }
- public function company()
- {
- return $this->hasOne(Company::class, 'id', 'company_id');
- }
- public function companyProPayer()
- {
- return $this->hasOne(CompanyProPayer::class, 'id', 'company_pro_payer_id');
- }
- public function companyLocation()
- {
- return $this->hasOne(CompanyLocation::class, 'id', 'company_location_id');
- }
- public function cmReasons()
- {
- return $this->hasMany(CareMonthCmRmReason::class, 'care_month_id', 'id')
- ->where('cm_or_rm', 'CM')
- ->orderBy('position_index', 'ASC')
- ->orderBy('code', 'ASC');
- }
- public function rmReasons()
- {
- return $this->hasMany(CareMonthCmRmReason::class, 'care_month_id', 'id')
- ->where('cm_or_rm', 'RM')
- ->orderBy('position_index', 'ASC')
- ->orderBy('code', 'ASC');
- }
- public function rmSetupClaim()
- {
- return $this->hasOne(Claim::class, 'id', 'rm_setup_claim_id')
- ->where('status', '<>', 'CANCELLED');
- }
- public function mostRecentMcpNote()
- {
- return $this->hasOne(Note::class, 'id', 'most_recent_mcp_note_id');
- }
- public function note()
- {
- return $this->hasOne(Note::class, 'id', 'note_id');
- }
- }
|