CareMonth.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 mcp(){
  12. return $this->hasOne(Pro::class, 'id', 'mcp_pro_id');
  13. }
  14. public function cmPro(){
  15. return $this->hasOne(Pro::class, 'id', 'cm_pro_id');
  16. }
  17. public function rmmPro(){
  18. return $this->hasOne(Pro::class, 'id', 'rmm_pro_id');
  19. }
  20. public function rmePro(){
  21. return $this->hasOne(Pro::class, 'id', 'rme_pro_id');
  22. }
  23. public function entries() {
  24. return $this->hasMany(CareMonthEntry::class, 'care_month_id', 'id');
  25. }
  26. public function bills() {
  27. return $this->hasMany(Bill::class, 'care_month_id', 'id');
  28. }
  29. public function claims() {
  30. return $this->hasMany(Claim::class, 'cm_id', 'id');
  31. }
  32. public function getBillsOfType($_type) {
  33. $bills = $this->bills;
  34. $targetBills = new Collection();
  35. foreach ($bills as $bill) {
  36. if($bill->cm_or_rm === $_type) {
  37. $targetBills->add($bill);
  38. }
  39. }
  40. return $targetBills;
  41. }
  42. public function rmBill(){
  43. return $this->hasOne(Bill::class, 'id', 'rm_bill_id');
  44. }
  45. public function company()
  46. {
  47. return $this->hasOne(Company::class, 'id', 'company_id');
  48. }
  49. public function companyProPayer()
  50. {
  51. return $this->hasOne(CompanyProPayer::class, 'id', 'company_pro_payer_id');
  52. }
  53. public function companyLocation()
  54. {
  55. return $this->hasOne(CompanyLocation::class, 'id', 'company_location_id');
  56. }
  57. public function cmReasons()
  58. {
  59. return $this->hasMany(CareMonthCmRmReason::class, 'care_month_id', 'id')
  60. ->where('cm_or_rm', 'CM')
  61. ->orderBy('position_index', 'ASC')
  62. ->orderBy('code', 'ASC');
  63. }
  64. public function rmReasons()
  65. {
  66. return $this->hasMany(CareMonthCmRmReason::class, 'care_month_id', 'id')
  67. ->where('cm_or_rm', 'RM')
  68. ->orderBy('position_index', 'ASC')
  69. ->orderBy('code', 'ASC');
  70. }
  71. }