ClientPrimaryCoverage.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class ClientPrimaryCoverage extends Model
  6. {
  7. protected $table = 'client_primary_coverage';
  8. public function getStatus() {
  9. $status = 'NO';
  10. // if medicare, check is_partbprimary
  11. if($this->plan_type === 'MEDICARE') {
  12. $status = $this->is_partbprimary;
  13. }
  14. else {
  15. if(!$this->is_manually_determined) {
  16. // AUTO determination of non-medicare not yet supported
  17. $status = 'NO';
  18. }
  19. else {
  20. switch($this->manual_determination_category) {
  21. case 'COVERED':
  22. $status = 'YES';
  23. break;
  24. case 'NOT_COVERED':
  25. case 'INVALID':
  26. $status = 'NO';
  27. break;
  28. default:
  29. $status = $this->manual_determination_category;
  30. break;
  31. }
  32. }
  33. }
  34. return $status;
  35. }
  36. public function toString() {
  37. $parts = [];
  38. $parts[] = $this->plan_type;
  39. if($this->plan_type === 'MEDICARE') {
  40. if($this->is_partbprimary === 'YES') {
  41. $parts[] = 'Part B';
  42. }
  43. }
  44. else {
  45. if(@$this->plan_name) $parts[] = ' / ' . $this->plan_name;
  46. if(@$this->plan_identifier) $parts[] = ' / ' . $this->plan_identifier;
  47. }
  48. return implode(" ", $parts);
  49. }
  50. public function payer(){
  51. return $this->hasOne(Payer::class, 'id', 'commercial_payer_id');
  52. }
  53. }