Segment.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Models;
  3. # use Illuminate\Database\Eloquent\Model;
  4. class Segment extends Model
  5. {
  6. protected $table = 'segment';
  7. public function segmentTemplate() {
  8. return $this->hasOne(SegmentTemplate::class, 'id', 'segment_template_id');
  9. }
  10. public function note() {
  11. return $this->hasOne(Note::class, 'id', 'note_id');
  12. }
  13. public function client() {
  14. return $this->hasOne(Client::class, 'id', 'client_id');
  15. }
  16. public function shortName(){
  17. return trim(array_reverse(explode('>', $this->display_title))[0]);
  18. }
  19. public function summarySuggestions()
  20. {
  21. return $this->hasMany(SegmentSummarySuggestion::class, 'segment_id', 'id')->orderBy('created_at', 'DESC');
  22. }
  23. public function proposedSegmentSummarySuggestion() {
  24. return $this->hasOne(SegmentSummarySuggestion::class, 'id', 'proposed_segment_summary_suggestion_id');
  25. }
  26. public function acceptedSegmentSummarySuggestion() {
  27. return $this->hasOne(SegmentSummarySuggestion::class, 'id', 'accepted_segment_summary_suggestion_id');
  28. }
  29. public function getRecalculatedHtml($performer, $sessionKey){
  30. $pro = $performer->pro;
  31. $segment = $this;
  32. $segmentTemplate = $this->segmentTemplate;
  33. $note = $this->note;
  34. $patient = $note->client;
  35. $data = compact('performer', 'pro', 'segment', 'segmentTemplate', 'note', 'patient', 'sessionKey');
  36. $summaryHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/summary', $data)->render();
  37. $wizardPowered = [
  38. 'intake_medications',
  39. 'plan_medications',
  40. 'intake_problems',
  41. 'plan_problems',
  42. 'intake_goals',
  43. 'plan_goals',
  44. 'intake_allergies',
  45. 'plan_allergies',
  46. 'intake_care_team',
  47. 'plan_care_team',
  48. 'intake_supplements',
  49. 'plan_supplements'
  50. ];
  51. if(!in_array($segmentTemplate->internal_name, $wizardPowered)) {
  52. $editHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/edit', $data)->render();
  53. }
  54. return [
  55. 'summaryHtml'=> $summaryHtml ,
  56. 'editHtml' => $editHtml
  57. ];
  58. }
  59. }