Segment.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, $getSummaryOnly = false){
  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. $editHtml = null;
  52. if(!in_array($segmentTemplate->internal_name, $wizardPowered) && !$getSummaryOnly) {
  53. $editHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/edit', $data)->render();
  54. }
  55. return [
  56. 'summaryHtml'=> $summaryHtml ,
  57. 'editHtml' => $editHtml
  58. ];
  59. }
  60. }