Note.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 noteTemplate()
  16. {
  17. return $this->hasOne(NoteTemplate::class, 'id', 'note_template_id');
  18. }
  19. public function createdSession()
  20. {
  21. return $this->hasOne(AppSession::class, 'id', 'created_by_session_id');
  22. }
  23. public function allyPro()
  24. {
  25. return $this->hasOne(Pro::class, 'id', 'ally_pro_id');
  26. }
  27. public function bills()
  28. {
  29. return $this->hasMany(Bill::class, 'note_id', 'id')
  30. ->orderBy('id', 'asc');
  31. }
  32. public function addendums()
  33. {
  34. return $this->hasMany(NoteAddendum::class, 'note_id', 'id')->where('is_removed', false);
  35. }
  36. public function sections()
  37. {
  38. return $this->hasMany(Section::class, 'note_id', 'id')
  39. ->where('is_active', true)
  40. ->orderBy('position_index', 'asc');
  41. }
  42. public function reasons()
  43. {
  44. return $this->hasMany(NoteReason::class, 'note_id', 'id');
  45. }
  46. public function claims()
  47. {
  48. return $this->hasMany(Claim::class, 'note_id', 'id');
  49. }
  50. public function summary()
  51. {
  52. $parts = [];
  53. foreach ($this->sections as $section) {
  54. $parts[] = $section->summary_html;
  55. }
  56. $parts = array_map(function($_part) {
  57. return '<div class="note-section-summary">' . $_part . '</div>';
  58. }, $parts);
  59. return implode("", $parts);
  60. }
  61. }