Note.php 1.3 KB

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