Note.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. class Note extends Model
  5. {
  6. protected $table = "note";
  7. public function client()
  8. {
  9. return $this->hasOne(Client::class, 'id', 'client_id');
  10. }
  11. public function hcpPro()
  12. {
  13. return $this->hasOne(Pro::class, 'id', 'hcp_pro_id');
  14. }
  15. public function hcpCompanyPro()
  16. {
  17. return $this->hasOne(CompanyPro::class, 'id', 'hcp_company_pro_id');
  18. }
  19. public function noteTemplate()
  20. {
  21. return $this->hasOne(NoteTemplate::class, 'id', 'note_template_id');
  22. }
  23. public function createdSession()
  24. {
  25. return $this->hasOne(AppSession::class, 'id', 'created_by_session_id');
  26. }
  27. public function allyPro()
  28. {
  29. return $this->hasOne(Pro::class, 'id', 'ally_pro_id');
  30. }
  31. public function cmSetupClaim()
  32. {
  33. return $this->hasOne(Claim::class, 'id', 'cm_setup_claim_id')
  34. ->where('status', '<>', 'CANCELLED');
  35. }
  36. public function bills()
  37. {
  38. return $this->hasMany(Bill::class, 'note_id', 'id')
  39. ->where('bill_service_type', '<>', 'GENERIC')
  40. ->orderBy('id', 'asc');
  41. }
  42. public function addendums()
  43. {
  44. return $this->hasMany(NoteAddendum::class, 'note_id', 'id')->where('is_removed', false);
  45. }
  46. public function sections()
  47. {
  48. return $this->hasMany(Section::class, 'note_id', 'id')
  49. ->where('is_active', true)
  50. ->orderBy('position_index', 'asc');
  51. }
  52. public function segments()
  53. {
  54. return $this->hasMany(Segment::class, 'note_id', 'id')
  55. ->where('is_active', true)
  56. ->orderBy('position_index', 'asc');
  57. }
  58. public function reasons()
  59. {
  60. return $this->hasMany(NoteReason::class, 'note_id', 'id');
  61. }
  62. public function claims()
  63. {
  64. return $this->hasMany(Claim::class, 'note_id', 'id')->orderBy('created_at', 'DESC');
  65. }
  66. public function summary()
  67. {
  68. $parts = [];
  69. foreach ($this->sections as $section) {
  70. $parts[] = $section->summary_html;
  71. }
  72. $parts = array_map(function($_part) {
  73. return '<div class="note-section-summary">' . $_part . '</div>';
  74. }, $parts);
  75. return implode("", $parts);
  76. }
  77. public function hcpCompany()
  78. {
  79. return $this->hasOne(Company::class, 'id', 'hcp_company_id');
  80. }
  81. public function hcpCompanyProPayer()
  82. {
  83. return $this->hasOne(CompanyProPayer::class, 'id', 'hcp_company_pro_payer_id');
  84. }
  85. public function hcpCompanyLocation()
  86. {
  87. return $this->hasOne(CompanyLocation::class, 'id', 'hcp_company_location_id');
  88. }
  89. public function currentNotePickupForProcessing() {
  90. return $this->hasOne(NotePickupForProcessing::class, 'id', 'current_note_pickup_for_processing_id');
  91. }
  92. public function visitTemplate()
  93. {
  94. return $this->hasOne(VisitTemplate::class, 'id', 'visit_template_id');
  95. }
  96. public function hasTreatmentServicesBillByHCP()
  97. {
  98. $bills = Bill::where('note_id', $this->id)
  99. ->where('bill_service_type', '<>', 'GENERIC')
  100. ->where('code', 'Treatment Services')
  101. ->where('is_cancelled', false)
  102. ->count();
  103. return !!$bills;
  104. }
  105. }