CareMonth.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Collection;
  5. class CareMonth extends Model
  6. {
  7. protected $table = 'care_month';
  8. public function patient(){
  9. return $this->hasOne(Client::class, 'id', 'client_id');
  10. }
  11. public function client(){
  12. return $this->hasOne(Client::class, 'id', 'client_id');
  13. }
  14. public function mcp(){
  15. return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
  16. }
  17. public function cmPro(){
  18. return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
  19. }
  20. public function rmmPro(){
  21. return $this->hasOne(Pro::class, 'id', 'rmm_pro_id');
  22. }
  23. public function rmePro(){
  24. return $this->hasOne(Pro::class, 'id', 'rme_pro_id');
  25. }
  26. public function entries() {
  27. return $this->hasMany(CareMonthEntry::class, 'care_month_id', 'id');
  28. }
  29. public function bills() {
  30. return $this->hasMany(Bill::class, 'care_month_id', 'id');
  31. }
  32. public function claims() {
  33. return $this->hasMany(Claim::class, 'care_month_id', 'id');
  34. }
  35. public function getBillsOfType($_type) {
  36. $bills = $this->bills;
  37. $targetBills = new Collection();
  38. foreach ($bills as $bill) {
  39. if($bill->cm_or_rm === $_type) {
  40. $targetBills->add($bill);
  41. }
  42. }
  43. return $targetBills;
  44. }
  45. public function rmBill(){
  46. return $this->hasOne(Bill::class, 'id', 'rm_bill_id');
  47. }
  48. public function companyPro()
  49. {
  50. return $this->hasOne(CompanyPro::class, 'id', 'company_pro_id');
  51. }
  52. public function company()
  53. {
  54. return $this->hasOne(Company::class, 'id', 'company_id');
  55. }
  56. public function companyProPayer()
  57. {
  58. return $this->hasOne(CompanyProPayer::class, 'id', 'company_pro_payer_id');
  59. }
  60. public function companyLocation()
  61. {
  62. return $this->hasOne(CompanyLocation::class, 'id', 'company_location_id');
  63. }
  64. public function cmReasons()
  65. {
  66. return $this->hasMany(CareMonthCmRmReason::class, 'care_month_id', 'id')
  67. ->where('cm_or_rm', 'CM')
  68. ->orderBy('position_index', 'ASC')
  69. ->orderBy('code', 'ASC');
  70. }
  71. public function rmReasons()
  72. {
  73. return $this->hasMany(CareMonthCmRmReason::class, 'care_month_id', 'id')
  74. ->where('cm_or_rm', 'RM')
  75. ->orderBy('position_index', 'ASC')
  76. ->orderBy('code', 'ASC');
  77. }
  78. public function rmSetupClaim()
  79. {
  80. return $this->hasOne(Claim::class, 'id', 'rm_setup_claim_id')
  81. ->where('status', '<>', 'CANCELLED');
  82. }
  83. public function mostRecentMcpNote()
  84. {
  85. return $this->hasOne(Note::class, 'id', 'most_recent_mcp_note_id');
  86. }
  87. public function note()
  88. {
  89. return $this->hasOne(Note::class, 'id', 'note_id');
  90. }
  91. public function mcpRmGenericBill()
  92. {
  93. return $this->hasOne(Bill::class, 'id', 'mcp_rm_generic_bill_id');
  94. }
  95. public function rmmRmGenericBill()
  96. {
  97. return $this->hasOne(Bill::class, 'id', 'rmm_rm_generic_bill_id');
  98. }
  99. }