Note.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  31. public function addendums()
  32. {
  33. return $this->hasMany(NoteAddendum::class, 'note_id', 'id')->where('is_removed', false);
  34. }
  35. public function sections()
  36. {
  37. return $this->hasMany(Section::class, 'note_id', 'id')
  38. ->where('is_active', true)
  39. ->orderBy('position_index', 'asc');
  40. }
  41. public function reasons()
  42. {
  43. return $this->hasMany(NoteReason::class, 'note_id', 'id');
  44. }
  45. public function summary()
  46. {
  47. $parts = [];
  48. foreach ($this->sections as $section) {
  49. $parts[] = $section->summary_html;
  50. }
  51. $parts = array_map(function($_part) {
  52. return '<div class="note-section-summary">' . $_part . '</div>';
  53. }, $parts);
  54. return implode("", $parts);
  55. }
  56. }