DnaPatient.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. class DnaPatient extends Model
  5. {
  6. protected $table = 'dna_patient_list';
  7. public function nextMcpAppointment()
  8. {
  9. return $this->hasOne(Appointment::class, 'id', 'next_mcp_appointment_id');
  10. }
  11. public function effectiveClientPrimaryCoverage(){
  12. return $this->hasOne(ClientPrimaryCoverage::class, 'id', 'effective_client_primary_coverage_id');
  13. }
  14. public function companyClients()
  15. {
  16. return $this->hasMany(CompanyClient::class, 'client_id', 'id')
  17. ->where('is_active', true)
  18. ->orderBy('created_at', 'asc');
  19. }
  20. public function getCoverageStatus() {
  21. $status = 'NO';
  22. // if medicare, check is_partbprimary
  23. if($this->plan_type === 'MEDICARE') {
  24. $status = $this->is_partbprimary;
  25. }
  26. else {
  27. if(!$this->is_manually_determined) {
  28. // AUTO determination of non-medicare not yet supported
  29. $status = 'NO';
  30. }
  31. else {
  32. switch($this->manual_determination_category) {
  33. case 'COVERED':
  34. $status = 'YES';
  35. break;
  36. case 'NOT_COVERED':
  37. case 'INVALID':
  38. $status = 'NO';
  39. break;
  40. default:
  41. $status = $this->manual_determination_category;
  42. break;
  43. }
  44. }
  45. }
  46. return $status;
  47. }
  48. public function insuranceDisplayName(){
  49. $coverageName = $this->coverageToString();
  50. if(stripos($coverageName, 'medicare') !== false) return 'Medicare';
  51. if(stripos($coverageName, 'medicaid') !== false) return 'Medicaid';
  52. if(stripos($coverageName, 'commercial') !== false) return 'Commercial';
  53. return null;
  54. }
  55. public function insuranceDisplayPayerName(){
  56. if($this->plan_type === 'MEDICAID'){
  57. if($this->mcd_payer_name) return $this->mcd_payer_name;
  58. }
  59. if($this->plan_type === 'COMMERCIAL'){
  60. if($this->commercial_payer_name) return $this->commercial_payer_name; else $this->carrier_free_text ?: '-';
  61. }
  62. return $this->insuranceDisplayName();
  63. }
  64. public function coverageToString() {
  65. $parts = [];
  66. $parts[] = $this->plan_type;
  67. if($this->plan_type === 'MEDICARE') {
  68. if($this->is_partbprimary === 'YES') {
  69. $parts[] = 'Part B';
  70. }
  71. }
  72. else {
  73. if(@$this->plan_name) $parts[] = ' / ' . $this->plan_name;
  74. if(@$this->plan_identifier) $parts[] = ' / ' . $this->plan_identifier;
  75. }
  76. return implode(" ", $parts);
  77. }
  78. }