1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Models;
- # use Illuminate\Database\Eloquent\Model;
- class McpPatient extends Model
- {
- protected $table = 'mcp_patient_list';
- public function nextMcpAppointment()
- {
- return $this->hasOne(Appointment::class, 'id', 'next_mcp_appointment_id');
- }
- public function effectiveClientPrimaryCoverage(){
- return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'effective_client_primary_coverage_id');
- }
- public function companyClients()
- {
- return $this->hasMany(CompanyClient::class, 'client_id', 'id')
- ->where('is_active', true)
- ->orderBy('created_at', 'asc');
- }
- public function getCoverageStatus() {
- $status = 'NO';
- // if medicare, check is_partbprimary
- if($this->plan_type === 'MEDICARE') {
- $status = $this->is_partbprimary;
- }
- else {
- if(!$this->is_manually_determined) {
- // AUTO determination of non-medicare not yet supported
- $status = 'NO';
- }
- else {
- switch($this->manual_determination_category) {
- case 'COVERED':
- $status = 'YES';
- break;
- case 'NOT_COVERED':
- case 'INVALID':
- $status = 'NO';
- break;
- default:
- $status = $this->manual_determination_category;
- break;
- }
- }
- }
- return $status;
- }
- public function insuranceDisplayName(){
- $coverageName = $this->coverageToString();
- if(stripos($coverageName, 'medicare') !== false) return 'Medicare';
- if(stripos($coverageName, 'medicaid') !== false) return 'Medicaid';
- if(stripos($coverageName, 'commercial') !== false) return 'Commercial';
- return null;
- }
- public function insuranceDisplayPayerName(){
- if($this->plan_type === 'MEDICAID'){
- if($this->mcd_payer_name) return $this->mcd_payer_name;
- }
- if($this->plan_type === 'COMMERCIAL'){
- if($this->commercial_payer_name) return $this->commercial_payer_name; else $this->carrier_free_text ?: '-';
- }
- return $this->insuranceDisplayName();
- }
- public function coverageToString() {
- $parts = [];
- $parts[] = $this->plan_type;
- if($this->plan_type === 'MEDICARE') {
- if($this->is_partbprimary === 'YES') {
- $parts[] = 'Part B';
- }
- }
- else {
- if(@$this->plan_name) $parts[] = ' / ' . $this->plan_name;
- if(@$this->plan_identifier) $parts[] = ' / ' . $this->plan_identifier;
- }
- return implode(" ", $parts);
- }
- }
|