Note.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 summary()
  42. {
  43. $parts = [];
  44. foreach ($this->sections as $section) {
  45. $parts[] = $section->summary_html;
  46. }
  47. $parts = array_map(function($_part) {
  48. return '<div class="note-section-summary">' . $_part . '</div>';
  49. }, $parts);
  50. return implode("", $parts);
  51. }
  52. }