Samson Mutunga 3 жил өмнө
parent
commit
05b1b3cf00
49 өөрчлөгдсөн 2643 нэмэгдсэн , 1327 устгасан
  1. 3 2
      app/Http/Controllers/HomeController.php
  2. 16 0
      app/Http/Controllers/NoteController.php
  3. 4 4
      app/Http/Controllers/PracticeManagementController.php
  4. 1 0
      app/Models/Note.php
  5. 11 0
      app/Models/NotePoint.php
  6. 10 0
      app/Models/Point.php
  7. 1 1
      config/app.php
  8. 34 16
      public/css/style.css
  9. 3 3
      public/js/stag-popup.js
  10. 669 0
      resources/views/app/patient/goals-center.blade.php
  11. 561 0
      resources/views/app/patient/medications-center.blade.php
  12. 175 2
      resources/views/app/patient/note/dashboard.blade.php
  13. 0 2
      resources/views/app/patient/note/dashboard_script.blade.php
  14. 3 1
      resources/views/app/patient/note/note-segment-list.blade.php
  15. 11 12
      resources/views/app/patient/note/segment.blade.php
  16. 44 2
      resources/views/app/patient/note/segment_script.blade.php
  17. 13 6
      resources/views/app/patient/note/sign-confirmation.blade.php
  18. 31 21
      resources/views/app/patient/notes.blade.php
  19. 537 0
      resources/views/app/patient/problems-center.blade.php
  20. 33 3
      resources/views/app/patient/segment-templates/_child_plan/edit-plan.php
  21. 37 3
      resources/views/app/patient/segment-templates/_child_review/edit-review.php
  22. 2 2
      resources/views/app/patient/segment-templates/_common_actions/remove-undo.php
  23. 17 69
      resources/views/app/patient/segment-templates/intake_allergies/edit.blade.php
  24. 4 14
      resources/views/app/patient/segment-templates/intake_allergies/summary.blade.php
  25. 17 71
      resources/views/app/patient/segment-templates/intake_care_team/edit.blade.php
  26. 4 14
      resources/views/app/patient/segment-templates/intake_care_team/summary.blade.php
  27. 17 69
      resources/views/app/patient/segment-templates/intake_goals/edit.blade.php
  28. 6 16
      resources/views/app/patient/segment-templates/intake_goals/summary.blade.php
  29. 0 7
      resources/views/app/patient/segment-templates/intake_interventions/edit.blade.php
  30. 17 70
      resources/views/app/patient/segment-templates/intake_medications/edit.blade.php
  31. 0 7
      resources/views/app/patient/segment-templates/intake_medications/edit_old.blade.php
  32. 5 15
      resources/views/app/patient/segment-templates/intake_medications/summary.blade.php
  33. 17 71
      resources/views/app/patient/segment-templates/intake_problems/edit.blade.php
  34. 4 13
      resources/views/app/patient/segment-templates/intake_problems/summary.blade.php
  35. 30 12
      resources/views/app/patient/segment-templates/medrisk_vigilence/summary.blade.php
  36. 17 68
      resources/views/app/patient/segment-templates/plan_allergies/edit.blade.php
  37. 4 14
      resources/views/app/patient/segment-templates/plan_allergies/summary.blade.php
  38. 17 68
      resources/views/app/patient/segment-templates/plan_care_team/edit.blade.php
  39. 4 14
      resources/views/app/patient/segment-templates/plan_care_team/summary.blade.php
  40. 17 75
      resources/views/app/patient/segment-templates/plan_goals/edit.blade.php
  41. 4 14
      resources/views/app/patient/segment-templates/plan_goals/summary.blade.php
  42. 1 54
      resources/views/app/patient/segment-templates/plan_interventions/edit.blade.php
  43. 1 12
      resources/views/app/patient/segment-templates/plan_interventions/summary.blade.php
  44. 17 69
      resources/views/app/patient/segment-templates/plan_medications/edit.blade.php
  45. 4 14
      resources/views/app/patient/segment-templates/plan_medications/summary.blade.php
  46. 17 68
      resources/views/app/patient/segment-templates/plan_problems/edit.blade.php
  47. 14 14
      resources/views/app/patient/segment-templates/plan_problems/summary.blade.php
  48. 185 315
      resources/views/layouts/patient.blade.php
  49. 4 0
      routes/web.php

+ 3 - 2
app/Http/Controllers/HomeController.php

@@ -575,7 +575,7 @@ WHERE ((client.mcp_pro_id = {$performer->pro->id}) OR (client.rmm_pro_id = {$per
             $keyNumbers['patientsWithoutCoverageInformation'] = DB::select(DB::raw("
 SELECT count(DISTINCT (cl.id)) as cnt
 FROM client cl
-WHERE cl.latest_client_primary_coverage_id IS NULL -- no coverage record"
+WHERE cl.shadow_pro_id IS NULL AND cl.latest_client_primary_coverage_id IS NULL -- no coverage record"
             ))[0]->cnt;
 
             // patients pending coverage verification
@@ -583,7 +583,8 @@ WHERE cl.latest_client_primary_coverage_id IS NULL -- no coverage record"
 SELECT count(DISTINCT (cl.id)) as cnt
 FROM client cl
          LEFT JOIN client_primary_coverage cpc ON cl.latest_client_primary_coverage_id = cpc.id
-WHERE (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
+WHERE cl.shadow_pro_id IS NULL 
+    AND (cl.latest_client_primary_coverage_id IS NOT NULL -- coverage exists, but status is null or unknown
     AND (
                (cpc.plan_type = 'MEDICARE' AND (cpc.is_partbprimary = 'UNKNOWN' OR cpc.is_partbprimary IS NULL))
                OR

+ 16 - 0
app/Http/Controllers/NoteController.php

@@ -304,6 +304,22 @@ class NoteController extends Controller
         }
     }
 
+    public function segmentSummary(Request $request, Segment $segment) {
+        return '<div class="mrv-content border-top px-3 pt-2 mt-3">' . @$segment->summary_html . '</div>';
+    }
+
+    public function medicationsCenter(Request $request, Client $patient, Note $note) {
+        return view('app.patient.medications-center', compact('patient', 'note'));
+    }
+
+    public function problemsCenter(Request $request, Client $patient, Note $note) {
+        return view('app.patient.problems-center', compact('patient', 'note'));
+    }
+
+    public function goalsCenter(Request $request, Client $patient, Note $note) {
+        return view('app.patient.goals-center', compact('patient', 'note'));
+    }
+
     // TODO move to utility
     private function callJava($request, $endPoint, $data, $guestAccessCode = null)
     {

+ 4 - 4
app/Http/Controllers/PracticeManagementController.php

@@ -391,16 +391,16 @@ class PracticeManagementController extends Controller
 
         switch ($filter) {
             case 'without-coverage-information':
-                $sql .= 'WHERE ';
+                $sql .= 'WHERE cl.shadow_pro_id IS NULL AND ';
                 $sql .= $withoutCondition;
                 break;
             case 'pending-coverage-verification':
-                $sql .= $joinClause . 'WHERE ';
+                $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
                 $sql .= $pendingCondition;
                 break;
             default:
-                $sql .= $joinClause . 'WHERE ';
-                $sql .= $withoutCondition . ' OR ' . $pendingCondition;
+                $sql .= $joinClause . 'WHERE cl.shadow_pro_id IS NULL AND ';
+                $sql .= '(' . $withoutCondition . ' OR ' . $pendingCondition . ')';
                 break;
         }
 

+ 1 - 0
app/Models/Note.php

@@ -66,6 +66,7 @@ class Note extends Model
     public function segments()
     {
         return $this->hasMany(Segment::class, 'note_id', 'id')
+            ->where('id', '!=', $this->core_segment_id) // dont include core-segment
             ->where('is_active', true)
             ->orderBy('position_index', 'asc');
     }

+ 11 - 0
app/Models/NotePoint.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class NotePoint extends Model
+{
+    protected $table = 'note_point';
+
+}

+ 10 - 0
app/Models/Point.php

@@ -78,6 +78,14 @@ class Point extends Model
         return $this->hasOne(Note::class, 'id', 'added_in_note_id');
     }
 
+    public function relevanceToNote($_note) {
+        return NotePoint
+            ::where('is_active', true)
+            ->where('note_id', $_note->id)
+            ->where('point_id', $this->id)
+            ->first();
+    }
+
     public static function getGlobalSingletonOfCategory(Client $_patient, String $_category, $_assoc = false) {
         $point = Point
             ::where('client_id', $_patient->id)
@@ -94,6 +102,7 @@ class Point extends Model
         $points = Point
             ::where('client_id', $_patient->id)
             ->where('category', $_category)
+            ->where('is_removed_due_to_entry_error', false)
             ->where(function ($query1) use ($_note) {
                 $query1
                     ->where('addition_reason_category', 'ON_INTAKE')
@@ -124,6 +133,7 @@ class Point extends Model
         $points = Point
             ::where('client_id', $_patient->id)
             ->where('category', $_category)
+            ->where('is_removed_due_to_entry_error', false)
             ->where(function ($query1) use ($_note) {
                 $query1
                     ->where('is_removed', false)

+ 1 - 1
config/app.php

@@ -65,7 +65,7 @@ return [
 
     'hrm2_url' => env('HRM2_URL'),
 
-    'asset_version' => 13,
+    'asset_version' => 14,
 
     'temp_dir' => env('TEMP_DIR'),
 

+ 34 - 16
public/css/style.css

@@ -260,7 +260,7 @@ body>nav.navbar {
 .mcp-theme-1 [large] .form-control.form-control-sm {
     min-width: unset;
 }
-[wide] .form-control.form-control-sm {
+[wide] .form-control.form-control-sm:not(.min-width-unset) {
     min-width: 480px;
 }
 [moe][center] [url]:not([show]) {
@@ -565,6 +565,12 @@ input.search_field, textarea.search_field {
     min-width: calc(100% - 0.5rem);
     right: 0.5rem;
 }
+[stag-suggest-bottom-left]~.stag-suggestions-container .suggestions-outer {
+    bottom: 30px;
+    left: 0;
+    top: auto;
+    right: auto;
+}
 .suggestions-outer .suggest-item, .suggestions-outer .no-suggest-items {
     padding: 0.25rem 0.5rem;
     text-decoration: none;
@@ -1037,6 +1043,9 @@ body .node input[type="number"] {
     padding: 0.75rem;
     min-height: 220px;
 }
+.stag-popup.overflow-visible>.stag-popup-content {
+    overflow: visible;
+}
 .stag-popup.min-height-unset>form {
     min-height: unset !important;
 }
@@ -2031,13 +2040,19 @@ body.in-iframe .main-row > .sidebar {
     right: 0;
     z-index: 1;
 }
+.on-click-menu [menu][bottom] {
+    bottom: 100%;
+    top: auto;
+    left: 0;
+    right: auto;
+}
 .zero-height {
     height: 0 !important;
     padding: 0 !important;
     border: 0 !important;
     overflow: hidden;
 }
-.note-section[data-segment-template-name="medrisk_vigilence"] {
+/*.note-section[data-segment-template-name="medrisk_vigilence"] {
     position: fixed;
     right: 0;
     top: 55px;
@@ -2047,21 +2062,14 @@ body.in-iframe .main-row > .sidebar {
     padding: 0 !important;
     border-left: 1px solid #ddd;
     transition: width 0.1s ease;
+}*/
+.on-trigger-only,
+.on-content-only {
+    display: none !important;
 }
-.note-section[data-segment-template-name="medrisk_vigilence"] .on-hover-only {
-    display: none;
-}
-.note-section[data-segment-template-name="medrisk_vigilence"]:hover {
-    padding: 1rem !important;
-    width: 550px;
-    border-left: 1px solid #ddd;
-    overflow: auto;
-}
-.note-section[data-segment-template-name="medrisk_vigilence"]:hover .on-hover-only {
-    display: block;
-}
-.note-section[data-segment-template-name="medrisk_vigilence"]:hover .on-hover-hide {
-    display: none;
+.mrv-trigger .on-trigger-only,
+.mrv-content .on-content-only {
+    display: inherit !important;
 }
 .mrv-badge {
     border-radius: 100%;
@@ -2083,3 +2091,13 @@ body.in-iframe .main-row > .sidebar {
 .mrv-badge>span {
     font-size: 10px !important;
 }
+.note-bottom-toolbar {
+    bottom: 0;
+}
+.note-bottom-toolbar .nbt-container:hover {
+    cursor: pointer;
+    background: #fff !important;
+}
+[open-in-stag-popup] * {
+    pointer-events: none;
+}

+ 3 - 3
public/js/stag-popup.js

@@ -160,11 +160,11 @@ function hasResponseError(_data) {
             });
 
         $(document)
-            .off('click.open-in-stag-popup', 'a[open-in-stag-popup]')
-            .on('click.open-in-stag-popup', 'a[open-in-stag-popup]', function() {
+            .off('click.open-in-stag-popup', '[open-in-stag-popup]')
+            .on('click.open-in-stag-popup', '[open-in-stag-popup]', function() {
                 let trig = $(this);
                 openDynamicStagPopup(
-                    this.href,
+                    trig.attr('href'),
                     trig.attr('mc-initer'),
                     trig.attr('title'),
                     trig.is('[update-parent]'),

+ 669 - 0
resources/views/app/patient/goals-center.blade.php

@@ -0,0 +1,669 @@
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+
+$points = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'GOAL')
+    ->where('is_removed_due_to_entry_error', false)
+    ->orderBy('category')
+    ->orderBy('is_removed')
+    ->orderBy('removal_effective_date', 'DESC')
+    ->orderBy('created_at')
+    ->get();
+foreach ($points as $point) {
+    if ($point->data) {
+        $point->data = json_decode($point->data);
+    }
+}
+$goals = $points;
+
+?>
+
+<div class="mt-3 p-3 border-top min-height-500px" id="goals-center-{{$note->id}}">
+    <div>
+
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white mb-2">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0 text-secondary">Goal</th>
+                <th class="border-bottom-0 text-secondary">Category</th>
+                <th class="border-bottom-0 text-secondary">Active?</th>
+                <th class="border-bottom-0 text-secondary">Edit</th>
+                <th class="border-bottom-0 text-secondary">Delete</th>
+                <th class="border-bottom-0 text-secondary">Started</th>
+                <th class="border-bottom-0 text-secondary">Ended</th>
+                <th class="border-bottom-0 text-secondary">Last Review</th>
+                <th class="border-bottom-0 text-secondary">Last Plan</th>
+            </tr>
+            </thead>
+            <?php foreach($goals as $goal): ?>
+            <?php $point = $goal; ?>
+            <tr class="{{$goal->is_removed ? 'on-hover-opaque' : ''}}">
+                <td>
+                    <div class="d-flex align-items-baseline">
+                        @if($goal->is_removed)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @else
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @endif
+                        <div>
+                            <b><?= !!@($goal->data->goal) ? @($goal->data->goal) : '-' ?></b>
+                            @if(!$goal->is_removed && $goal->added_in_note_id === $note->id)
+                                <div class="mt-1 text-sm text-secondary">Added during this visit
+                                    @if($goal->addition_reason_category === 'ON_INTAKE')
+                                        (existing)
+                                    @elseif($goal->addition_reason_category === 'DURING_VISIT')
+                                        (new)
+                                    @endif
+                                </div>
+                            @endif
+                            @if($goal->is_removed && ($goal->added_in_note_id !== $note->id && $goal->removed_in_note_id === $note->id))
+                                <div class="mt-1 text-sm text-secondary">Discontinued during this visit</div>
+                            @endif
+                        </div>
+                    </div>
+                </td>
+                <td>
+                    <?= !!@($goal->data->category) ? @($goal->data->category) : '-' ?>
+                </td>
+                <td>
+                    @if($goal->is_removed)
+                        NO
+                    @else
+                        <b>YES</b>
+                    @endif
+                </td>
+                <td>
+                    @if($goal->added_in_note_id === $note->id)
+                        <div moe wide>
+                            <a start show href="#" title="Edit">Edit</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1 frm-edit-goal">
+                                <input type="hidden" name="uid" value="<?= $goal->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <p class="mb-2"><b>Update Goal</b></p>
+
+                                <input type="hidden" name="data">
+
+                                <input type="hidden" name="additionReasonCategory" value="{{@$goal->addition_reason_category}}">
+                                <input type="hidden" name="isRemoved" value="{{@$goal->is_removed}}">
+                                <input type="hidden" name="removalReasonCategory" value="{{@$goal->removal_reason_category}}">
+                                <input type="hidden" name="isRemovedDueToEntryError" value="{{@$goal->is_removed_due_to_entry_error}}">
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Category</label>
+                                    <select type="text" data-name="category" class="form-control form-control-sm">
+                                        <option value="">-- select --</option>
+                                        <option {{ @($goal->data->category) === 'NUTRITION' ? 'selected' : '' }} value="NUTRITION">NUTRITION</option>
+                                        <option {{ @($goal->data->category) === 'ACTIVITY' ? 'selected' : '' }} value="ACTIVITY">ACTIVITY</option>
+                                        <option {{ @($goal->data->category) === 'SLEEP' ? 'selected' : '' }} value="SLEEP">SLEEP</option>
+                                        <option {{ @($goal->data->category) === 'SOCIAL CONNECTION' ? 'selected' : '' }} value="SOCIAL CONNECTION">SOCIAL CONNECTION</option>
+                                        <option {{ @($goal->data->category) === 'STRESS REDUCTION' ? 'selected' : '' }} value="STRESS REDUCTION">STRESS REDUCTION</option>
+                                        <option {{ @($goal->data->category) === 'RISKY SUBSTANCE AVOIDANCE' ? 'selected' : '' }} value="RISKY SUBSTANCE AVOIDANCE">RISKY SUBSTANCE AVOIDANCE</option>
+                                        <option {{ @($goal->data->category) === 'OTHER' ? 'selected' : '' }} value="OTHER">OTHER</option>
+                                    </select>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="NUTRITION">
+                                    <div class="mb-1">Specific - What specific food would you like to add/change?</div>
+                                    <div class="mb-1">Measurable - How much or how many will you add or change?</div>
+                                    <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                    <div class="mb-1">Realistic - What can you do? (improvement over perfection)</div>
+                                    <div class="mb-2">Time-Connected - How often or for how long will you make this change?</div>
+                                    <div class="font-italic"><b>Example:</b> "I will add 1 cup of berries to breakfast and a small apple or orange as an afternoon snack at least five days this week."</div>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="ACTIVITY">
+                                    <div class="mb-1">Specific - What specific activity would you like to add/change?</div>
+                                    <div class="mb-1">Measurable - How much activity, how many sessions?</div>
+                                    <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                    <div class="mb-1">Realistic - What can you actually do? (know your limits, start small, build)</div>
+                                    <div class="mb-2">Time-Connected - How frequent or how long will you do the activity?</div>
+                                    <div class="font-italic"><b>Example:</b> "I will walk with a friend or family member for at least 20 minutes after dinner, every weekday for the next two months."</div>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="SLEEP">
+                                    <div class="mb-1">Specific - What are you going to do to improve your sleep quality/quantity?</div>
+                                    <div class="mb-1">Measurable - How much time, how many sessions?</div>
+                                    <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                    <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                    <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                    <div class="font-italic"><b>Example:</b> "I will begin a new bedtime routine of shutting off the television and instead, read a book for at least 30 minutes before bed, four nights this week."</div>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="SOCIAL CONNECTION">
+                                    <div class="mb-1">Specific - What are you going to do to improve feelings of connectedness?</div>
+                                    <div class="mb-1">Measurable - How much time, how many sessions?</div>
+                                    <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                    <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                    <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                    <div class="font-italic"><b>Example:</b> "I will increase my feeling of social connectedness by joining a group fitness class that meets for an hour, three nights of the week."</div>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="STRESS REDUCTION">
+                                    <div class="mb-1">Specific - What are you going to do to manage your stress?</div>
+                                    <div class="mb-1">Measurable - How much time, how many sessions?</div>
+                                    <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                    <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                    <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                    <div class="font-italic"><b>Example:</b> "I will write about what I am thankful for at least 10 minutes three times per week."</div>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="RISKY SUBSTANCE AVOIDANCE">
+                                    <div class="mb-1">Specific - What are you going to do to decrease your substance use?</div>
+                                    <div class="mb-1">Measurable - How much will you reduce it by?</div>
+                                    <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                    <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                    <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                    <div class="font-italic"><b>Example:</b> "I will swap my morning cigarette with chewing gum at least 5 days this week for the next four weeks. I will ask my partner to help keep me on track and use the free texting service for more support."</div>
+                                </div>
+
+                                <div class="bg-light border mb-2 p-2 help-text d-none" data-category="OTHER">
+                                    <div class="">Ensure that the goal is Specific, Measurable, Attainable, Realistic and Time-Connected.</div>
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Goal</label>
+                                    <input type="text" class="form-control form-control-sm min-width-unset"
+                                           data-name="goal"
+                                           value="{{@$goal->data->goal}}">
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-0">Historic / Preexisting / New</label>
+                                    <select class="form-control form-control-sm additionReasonCategory_ui" name="additionReasonCategory_ui" required>
+                                        <option value="">-- select --</option>
+                                        <option value="HISTORIC" {{$goal->addition_reason_category === 'ON_INTAKE' && $goal->is_removed ? 'selected' : ''}}>Historic</option>
+                                        <option value="PRE_EXISTING" {{$goal->addition_reason_category === 'ON_INTAKE' && !$goal->is_removed ? 'selected' : ''}}>Preexisting</option>
+                                        <option value="NEW" {{$goal->addition_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>New (Prescribed during this visit)</option>
+                                    </select>
+                                </div>
+
+                                <div class="d-flex align-items-start">
+                                    <div class="w-50 mb-2">
+                                        <div class="start_date_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Start Date</label>
+                                            <input type="date"
+                                                   data-name="start_date"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                    <div class="w-50 pl-2 mb-2">
+                                        <div class="prescriber_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Prescribed By</label>
+                                            <input type="text"
+                                                   data-name="prescriber"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                </div>
+                                <div class="d-flex align-items-start">
+                                    <div class="w-50 mb-2">
+                                        <div class="removalEffectiveDate_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">End Date</label>
+                                            <input type="date"
+                                                   name="removalEffectiveDate"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                    <div class="w-50 pl-2 mb-2">
+                                        <div class="removalReasonMemo_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Removal By/Memo</label>
+                                            <input type="text"
+                                                   name="removalReasonMemo"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Description</label>
+                                    <textarea rows="1" data-name="description" class="form-control form-control-sm">{{@$goal->data->description}}</textarea>
+                                </div>
+
+                                <div>
+                                    <button type="submit" class="btn-save-goal btn btn-sm btn-primary mr-2">Save</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                </td>
+                <td>
+                    @if($goal->added_in_note_id === $note->id)
+                        <div moe>
+                            <a start show href="#" title="Delete">Delete</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="<?= $goal->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <input type="hidden" name="isRemoved" value="1">
+                                <input type="hidden" name="isRemovedDueToEntryError" value="1">
+                                <input type="hidden" name="removalReasonMemo" value="Entry Error">
+                                <input type="hidden" name="removalEffectiveDate" value="<?= date('Y-m-d') ?>">
+                                <p class="mb-2"><b>Delete this goal?</b></p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @else
+                        @if(!$goal->is_removed)
+                            <div moe>
+                                <a start show href="#" title="Discontinue">Delete</a>
+                                <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                    <input type="hidden" name="uid" value="<?= $goal->uid ?>">
+                                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                    <input type="hidden" name="isRemoved" value="1">
+                                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+                                    <p class="mb-2"><b>Delete this goal?</b></p>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Already stopped / Stop now</label>
+                                        <select class="form-control form-control-sm" name="removalReasonCategory" required>
+                                            <option value="">-- select --</option>
+                                            <option value="ON_INTAKE">Already stopped (before this visit)</option>
+                                            <option value="DURING_VISIT">Stop now</option>
+                                        </select>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Reason</label>
+                                        <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Effective Date</label>
+                                        <input type="date" name="removalEffectiveDate"
+                                               value="<?= date('Y-m-d') ?>"
+                                               max="<?= date('Y-m-d') ?>"
+                                               class="form-control form-control-sm">
+                                    </div>
+                                    <div>
+                                        <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @endif
+                    @endif
+                </td>
+                <td>
+                    <?= !!@($goal->data->start_date) ? @($goal->data->start_date) : '-' ?>
+                    @if(!!@($goal->data->prescriber))
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($goal->data->prescriber) ? @($goal->data->prescriber) : '-' ?></div>
+                    @endif
+                </td>
+                <td>
+                    <?= !!@($goal->removal_effective_date) ? @($goal->removal_effective_date) : '-' ?>
+                    @if(!!@($goal->removal_reason_memo))
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($goal->removal_reason_memo) ? @($goal->removal_reason_memo) : '-' ?></div>
+                    @endif
+                </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            $point = $goal;
+                            include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                            ?>
+                        </div>
+                        <a class="px-2 view-review-log"
+                           native target="_blank"
+                           open-in-stag-popup
+                           popup-style="stag-popup-md"
+                           title="Review log<?= !!@($goal->data->goal) ? ' for ' . @($goal->data->goal) : '' ?>"
+                           href="/point/review-log/<?= $goal->uid ?>?popupmode=1">
+                            <i class="fa fa-history"></i>
+                        </a>
+                    </div>
+                </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
+                            ?>
+                        </div>
+                        <a class="px-2 view-review-log"
+                           native target="_blank"
+                           open-in-stag-popup
+                           popup-style="stag-popup-md"
+                           title="Plan log<?= !!@($goal->data->goal) ? ' for ' . @($goal->data->goal) : '' ?>"
+                           href="/point/plan-log/<?= $goal->uid ?>?popupmode=1">
+                            <i class="fa fa-history"></i>
+                        </a>
+                    </div>
+                </td>
+            </tr>
+            <?php endforeach; ?>
+        </table>
+
+        <div class="d-flex align-items-center">
+            <div class="mt-1 w-100 border p-2 bg-aliceblue border-info rounded">
+                <form action="/api/visitPoint/addTopLevel" class="mcp-theme-1 w-100" id="frm-add-goal">
+                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                    <input type="hidden" name="category" value="GOAL">
+                    <input type="hidden" name="data">
+
+                    <input type="hidden" name="additionReasonCategory">
+                    <input type="hidden" name="isRemoved">
+                    <input type="hidden" name="removalReasonCategory">
+                    <input type="hidden" name="isRemovedDueToEntryError">
+
+                    <p class="mb-2"><b>Add Goal</b></p>
+
+                    <div class="row">
+                        <div class="col-7">
+                            <div class="row mb-2">
+                                <div class="col-12">
+
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Category</label>
+                                        <select type="text" data-name="category" class="form-control form-control-sm">
+                                            <option value="">-- select --</option>
+                                            <option value="NUTRITION">NUTRITION</option>
+                                            <option value="ACTIVITY">ACTIVITY</option>
+                                            <option value="SLEEP">SLEEP</option>
+                                            <option value="SOCIAL CONNECTION">SOCIAL CONNECTION</option>
+                                            <option value="STRESS REDUCTION">STRESS REDUCTION</option>
+                                            <option value="RISKY SUBSTANCE AVOIDANCE">RISKY SUBSTANCE AVOIDANCE</option>
+                                            <option value="OTHER">OTHER</option>
+                                        </select>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="NUTRITION">
+                                        <div class="mb-1">Specific - What specific food would you like to add/change?</div>
+                                        <div class="mb-1">Measurable - How much or how many will you add or change?</div>
+                                        <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                        <div class="mb-1">Realistic - What can you do? (improvement over perfection)</div>
+                                        <div class="mb-2">Time-Connected - How often or for how long will you make this change?</div>
+                                        <div class="font-italic"><b>Example:</b> "I will add 1 cup of berries to breakfast and a small apple or orange as an afternoon snack at least five days this week."</div>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="ACTIVITY">
+                                        <div class="mb-1">Specific - What specific activity would you like to add/change?</div>
+                                        <div class="mb-1">Measurable - How much activity, how many sessions?</div>
+                                        <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                        <div class="mb-1">Realistic - What can you actually do? (know your limits, start small, build)</div>
+                                        <div class="mb-2">Time-Connected - How frequent or how long will you do the activity?</div>
+                                        <div class="font-italic"><b>Example:</b> "I will walk with a friend or family member for at least 20 minutes after dinner, every weekday for the next two months."</div>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="SLEEP">
+                                        <div class="mb-1">Specific - What are you going to do to improve your sleep quality/quantity?</div>
+                                        <div class="mb-1">Measurable - How much time, how many sessions?</div>
+                                        <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                        <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                        <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                        <div class="font-italic"><b>Example:</b> "I will begin a new bedtime routine of shutting off the television and instead, read a book for at least 30 minutes before bed, four nights this week."</div>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="SOCIAL CONNECTION">
+                                        <div class="mb-1">Specific - What are you going to do to improve feelings of connectedness?</div>
+                                        <div class="mb-1">Measurable - How much time, how many sessions?</div>
+                                        <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                        <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                        <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                        <div class="font-italic"><b>Example:</b> "I will increase my feeling of social connectedness by joining a group fitness class that meets for an hour, three nights of the week."</div>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="STRESS REDUCTION">
+                                        <div class="mb-1">Specific - What are you going to do to manage your stress?</div>
+                                        <div class="mb-1">Measurable - How much time, how many sessions?</div>
+                                        <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                        <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                        <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                        <div class="font-italic"><b>Example:</b> "I will write about what I am thankful for at least 10 minutes three times per week."</div>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="RISKY SUBSTANCE AVOIDANCE">
+                                        <div class="mb-1">Specific - What are you going to do to decrease your substance use?</div>
+                                        <div class="mb-1">Measurable - How much will you reduce it by?</div>
+                                        <div class="mb-1">Attainable - Do you have what it takes to follow through?</div>
+                                        <div class="mb-1">Realistic - What can you actually do? (improvement over perfection)</div>
+                                        <div class="mb-2">Time-Connected - How frequent? How long will you commit?</div>
+                                        <div class="font-italic"><b>Example:</b> "I will swap my morning cigarette with chewing gum at least 5 days this week for the next four weeks. I will ask my partner to help keep me on track and use the free texting service for more support."</div>
+                                    </div>
+
+                                    <div class="bg-light border mb-2 p-2 help-text d-none" data-category="OTHER">
+                                        <div class="">Ensure that the goal is Specific, Measurable, Attainable, Realistic and Time-Connected.</div>
+                                    </div>
+
+                                    <label class="text-sm text-secondary mb-0">Goal</label>
+                                    <input type="text"
+                                           data-name="goal"
+                                           class="form-control form-control-sm"
+                                           required>
+                                </div>
+                            </div>
+                            <div class="row mb-2">
+                                <div class="col-12">
+                                    <label class="text-sm text-secondary mb-0">Historic / Preexisting / New</label>
+                                    <select class="form-control form-control-sm additionReasonCategory_ui" name="additionReasonCategory_ui" required>
+                                        <option value="">-- select --</option>
+                                        <option value="HISTORIC">Historic</option>
+                                        <option value="PRE_EXISTING">Preexisting</option>
+                                        <option value="NEW">New (Prescribed during this visit)</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="d-flex align-items-start mb-2">
+                                <div class="w-25">
+                                    <div class="start_date_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Start Date</label>
+                                        <input type="date"
+                                               data-name="start_date"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="prescriber_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Prescribed By</label>
+                                        <input type="text"
+                                               data-name="prescriber"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="removalEffectiveDate_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">End Date</label>
+                                        <input type="date"
+                                               name="removalEffectiveDate"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="removalReasonMemo_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Removal By/Memo</label>
+                                        <input type="text"
+                                               name="removalReasonMemo"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="col-5 border-left">
+
+                        </div>
+                    </div>
+
+                    <div class="d-flex align-items-center">
+                        <button type="submit" class="btn btn-sm btn-primary mr-2 my-1">Save Goal</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            let parentSegment = $('#goals-center-{{$note->id}}');
+
+            parentSegment.find('select[data-name="category"]')
+                .off('change')
+                .on('change', function() {
+                    $(this).closest('form').find('.help-text').addClass('d-none');
+                    $(this).closest('form').find('.help-text[data-category="' + this.value + '"]').removeClass('d-none');
+                })
+                .trigger('change');
+
+            parentSegment.find('.additionReasonCategory_ui')
+                .off('change')
+                .on('change', function() {
+
+                    let form = $(this).closest('form');
+
+                    // additionReasonCategory
+                    // isRemoved
+                    // removalReasonCategory
+                    form.find('[name="isRemovedDueToEntryError"]').val('0');
+
+                    form.find('.start_date_ui').hide();
+                    form.find('.prescriber_ui').hide();
+                    form.find('.removalEffectiveDate_ui').hide();
+                    form.find('.removalReasonMemo_ui').hide();
+
+                    if(this.value === 'HISTORIC') {
+                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
+                        form.find('[name="isRemoved"]').val('1');
+                        form.find('.start_date_ui').show();
+                        form.find('.prescriber_ui').show();
+                        form.find('.removalEffectiveDate_ui').show();
+                        form.find('.removalReasonMemo_ui').show();
+                    }
+                    else if(this.value === 'PRE_EXISTING') {
+                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
+                        form.find('[name="isRemoved"]').val('0');
+                        form.find('.start_date_ui').show();
+                        form.find('.prescriber_ui').show();
+                    }
+                    else if(this.value === 'NEW') {
+                        form.find('[name="additionReasonCategory"]').val('DURING_VISIT');
+                        form.find('[name="isRemoved"]').val('0');
+                        form.find('.start_date_ui').show().find('input').val('{{date('Y-m-d')}}');
+                        form.find('.prescriber_ui').show().find('input').val('{{$note->hcpPro->displayName()}}');
+                    }
+
+                });
+
+            parentSegment.find('#frm-add-goal')
+                .off('submit')
+                .on('submit', function () {
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('action'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            refreshDynamicStagPopup();
+                            $('.visit-segment[data-segment-template-name="intake_goals"]').find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            parentSegment.find('.frm-edit-goal')
+                .off('submit')
+                .on('submit', function () {
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('url'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            refreshDynamicStagPopup();
+                            $('.visit-segment[data-segment-template-name="intake_goals"]').find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            initStagSuggest();
+
+            $('.additionReasonCategory_ui').trigger('change');
+        }
+        addMCInitializer('goals-center-{{$note->id}}', init, '#goals-center-{{$note->id}}')
+    }).call(window);
+</script>

+ 561 - 0
resources/views/app/patient/medications-center.blade.php

@@ -0,0 +1,561 @@
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+
+$points = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->where('is_removed_due_to_entry_error', false)
+    ->orderBy('is_removed')
+    ->orderBy('removal_effective_date', 'DESC')
+    ->orderBy('created_at')
+    ->get();
+foreach ($points as $point) {
+    if ($point->data) {
+        $point->data = json_decode($point->data);
+    }
+}
+$medications = $points;
+
+?>
+
+<div class="mt-3 p-3 border-top min-height-500px" id="medications-center-{{$note->id}}">
+    <div>
+
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white mb-2">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0 text-secondary">Name</th>
+                <th class="border-bottom-0 text-secondary">Frequency</th>
+                <th class="border-bottom-0 text-secondary">Active?</th>
+                <th class="border-bottom-0 text-secondary">Edit</th>
+                <th class="border-bottom-0 text-secondary">Delete</th>
+                <th class="border-bottom-0 text-secondary">Started</th>
+                <th class="border-bottom-0 text-secondary">Ended</th>
+                <th class="border-bottom-0 text-secondary">Last Review</th>
+                <th class="border-bottom-0 text-secondary">Last Plan</th>
+            </tr>
+            </thead>
+            <?php foreach($medications as $medication): ?>
+            <?php $point = $medication; ?>
+            <tr class="{{$medication->is_removed ? 'on-hover-opaque' : ''}}">
+                <td>
+                    <div class="d-flex align-items-baseline">
+                        @if($medication->is_removed)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @else
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @endif
+                        <div>
+                            <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                            @if(!$medication->is_removed && $medication->added_in_note_id === $note->id)
+                                <div class="mt-1 text-sm text-secondary">Added during this visit
+                                    @if($medication->addition_reason_category === 'ON_INTAKE')
+                                        (existing)
+                                    @elseif($medication->addition_reason_category === 'DURING_VISIT')
+                                        (new)
+                                    @endif
+                                </div>
+                            @endif
+                            @if($medication->is_removed && ($medication->added_in_note_id !== $note->id && $medication->removed_in_note_id === $note->id))
+                                <div class="mt-1 text-sm text-secondary">Discontinued during this visit</div>
+                            @endif
+                        </div>
+                    </div>
+                </td>
+                <td>
+                    <?= !!@($medication->data->frequency) ? @($medication->data->frequency) : '-' ?>
+                </td>
+                <td>
+                    @if($medication->is_removed)
+                        NO
+                    @else
+                        <b>YES</b>
+                    @endif
+                </td>
+                <td>
+                    @if($medication->added_in_note_id === $note->id)
+                        <div moe wide>
+                            <a start show href="#" title="Edit">Edit</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1 frm-edit-medication">
+                                <input type="hidden" name="uid" value="<?= $medication->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <p class="mb-2"><b>Update Medication</b></p>
+
+                                <input type="hidden" name="data">
+
+                                <input type="hidden" data-name="medId" value="{{@$medication->data->medId}}">
+                                <input type="hidden" data-name="routedMedId" value="{{@$medication->data->routedMedId}}">
+                                <input type="hidden" data-name="routedDosageFormMedId" value="{{@$medication->data->routedDosageFormMedId}}">
+                                <input type="hidden" data-name="gcnSeqno" value="{{@$medication->data->gcnSeqno}}">
+
+                                <input type="hidden" name="additionReasonCategory" value="{{@$medication->addition_reason_category}}">
+                                <input type="hidden" name="isRemoved" value="{{@$medication->is_removed}}">
+                                <input type="hidden" name="removalReasonCategory" value="{{@$medication->removal_reason_category}}">
+                                <input type="hidden" name="isRemovedDueToEntryError" value="{{@$medication->is_removed_due_to_entry_error}}">
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Drug</label>
+                                    <input type="text" class="form-control form-control-sm min-width-unset prescription-medication"
+                                           data-name="name"
+                                           value="{{@$medication->data->name}}"
+                                           stag-suggest
+                                           stag-suggest-ep="/fdb-med-suggest-v2/json">
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Frequency</label>
+                                    <input type="text" class="form-control form-control-sm min-width-unset"
+                                           data-option-list="frequency-options" data-field="frequency"
+                                           value="{{@$medication->data->frequency}}"
+                                           data-name="frequency">
+                                    <div id="frequency-options" class="data-option-list">
+                                        <div>Once a day</div>
+                                        <div>Twice a day</div>
+                                    </div>
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-0">Historic / Preexisting / New</label>
+                                    <select class="form-control form-control-sm additionReasonCategory_ui" name="additionReasonCategory_ui" required>
+                                        <option value="">-- select --</option>
+                                        <option value="HISTORIC" {{$medication->addition_reason_category === 'ON_INTAKE' && $medication->is_removed ? 'selected' : ''}}>Historic</option>
+                                        <option value="PRE_EXISTING" {{$medication->addition_reason_category === 'ON_INTAKE' && !$medication->is_removed ? 'selected' : ''}}>Preexisting</option>
+                                        <option value="NEW" {{$medication->addition_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>New (Prescribed during this visit)</option>
+                                    </select>
+                                </div>
+
+                                <div class="d-flex align-items-start">
+                                    <div class="w-50 mb-2">
+                                        <div class="start_date_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Start Date</label>
+                                            <input type="date"
+                                                   data-name="start_date"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                    <div class="w-50 pl-2 mb-2">
+                                        <div class="prescriber_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Prescribed By</label>
+                                            <input type="text"
+                                                   data-name="prescriber"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                </div>
+                                <div class="d-flex align-items-start">
+                                    <div class="w-50 mb-2">
+                                        <div class="removalEffectiveDate_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">End Date</label>
+                                            <input type="date"
+                                                   name="removalEffectiveDate"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                    <div class="w-50 pl-2 mb-2">
+                                        <div class="removalReasonMemo_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Removal By/Memo</label>
+                                            <input type="text"
+                                                   name="removalReasonMemo"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Description</label>
+                                    <textarea rows="1" data-name="description" class="form-control form-control-sm">{{@$medication->data->description}}</textarea>
+                                </div>
+
+                                <div>
+                                    <button type="submit" class="btn-save-medication btn btn-sm btn-primary mr-2">Save</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                </td>
+                <td>
+                    @if($medication->added_in_note_id === $note->id)
+                        <div moe>
+                            <a start show href="#" title="Delete">Delete</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="<?= $medication->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <input type="hidden" name="isRemoved" value="1">
+                                <input type="hidden" name="isRemovedDueToEntryError" value="1">
+                                <input type="hidden" name="removalReasonMemo" value="Entry Error">
+                                <input type="hidden" name="removalEffectiveDate" value="<?= date('Y-m-d') ?>">
+                                <p class="mb-2"><b>Delete this medication?</b></p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @else
+                        @if(!$medication->is_removed)
+                            <div moe>
+                                <a start show href="#" title="Discontinue">Discontinue</a>
+                                <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                    <input type="hidden" name="uid" value="<?= $medication->uid ?>">
+                                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                    <input type="hidden" name="isRemoved" value="1">
+                                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+                                    <p class="mb-2"><b>Discontinue this medication?</b></p>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Already stopped / Stop now</label>
+                                        <select class="form-control form-control-sm" name="removalReasonCategory" required>
+                                            <option value="">-- select --</option>
+                                            <option value="ON_INTAKE">Already stopped (before this visit)</option>
+                                            <option value="DURING_VISIT">Stop now</option>
+                                        </select>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Reason</label>
+                                        <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Effective Date</label>
+                                        <input type="date" name="removalEffectiveDate"
+                                               value="<?= date('Y-m-d') ?>"
+                                               max="<?= date('Y-m-d') ?>"
+                                               class="form-control form-control-sm">
+                                    </div>
+                                    <div>
+                                        <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @endif
+                    @endif
+                </td>
+                <td>
+                    <?= !!@($medication->data->start_date) ? @($medication->data->start_date) : '-' ?>
+                    @if(!!@($medication->data->prescriber))
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($medication->data->prescriber) ? @($medication->data->prescriber) : '-' ?></div>
+                    @endif
+                </td>
+                <td>
+                    <?= !!@($medication->removal_effective_date) ? @($medication->removal_effective_date) : '-' ?>
+                    @if(!!@($medication->removal_reason_memo))
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($medication->removal_reason_memo) ? @($medication->removal_reason_memo) : '-' ?></div>
+                    @endif
+                </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            $point = $medication;
+                            include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                            ?>
+                        </div>
+                        <a class="px-2 view-review-log"
+                           native target="_blank"
+                           open-in-stag-popup
+                           popup-style="stag-popup-md"
+                           title="Review log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
+                           href="/point/review-log/<?= $medication->uid ?>?popupmode=1">
+                            <i class="fa fa-history"></i>
+                        </a>
+                    </div>
+                </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
+                            ?>
+                        </div>
+                        <a class="px-2 view-review-log"
+                           native target="_blank"
+                           open-in-stag-popup
+                           popup-style="stag-popup-md"
+                           title="Plan log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
+                           href="/point/plan-log/<?= $medication->uid ?>?popupmode=1">
+                            <i class="fa fa-history"></i>
+                        </a>
+                    </div>
+                </td>
+            </tr>
+            <?php endforeach; ?>
+        </table>
+
+        <div class="d-flex align-items-center">
+            <div class="mt-1 w-100 border p-2 bg-aliceblue border-info rounded">
+                <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new medication, prescribed during this visit</a>-->
+                <form action="/api/visitPoint/addTopLevel" class="mcp-theme-1 w-100" id="frm-add-medication">
+                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                    <input type="hidden" name="category" value="MEDICATION">
+                    <input type="hidden" name="data">
+
+                    <input type="hidden" data-name="medId">
+                    <input type="hidden" data-name="routedMedId">
+                    <input type="hidden" data-name="routedDosageFormMedId">
+                    <input type="hidden" data-name="gcnSeqno">
+
+                    <input type="hidden" name="additionReasonCategory">
+                    <input type="hidden" name="isRemoved">
+                    <input type="hidden" name="removalReasonCategory">
+                    <input type="hidden" name="isRemovedDueToEntryError">
+
+                    <p class="mb-2"><b>Add Medication</b></p>
+
+                    <div class="row">
+                        <div class="col-7">
+                            <div class="row mb-2">
+                                <div class="col-8 pr-0">
+                                    <label class="text-sm text-secondary mb-0">Name</label>
+                                    <input type="text"
+                                           data-name="name"
+                                           class="form-control form-control-sm"
+                                           stag-suggest
+                                           stag-suggest-bottom-left
+                                           stag-suggest-ep="/fdb-med-suggest-v2/json"
+                                           required>
+                                </div>
+                                <div class="col-4">
+                                    <label class="text-sm text-secondary mb-0">Frequency</label>
+                                    <input type="text" class="form-control form-control-sm" data-name="frequency"
+                                           data-option-list="frequency-options" autocomplete="off">
+                                    <div id="frequency-options" class="data-option-list">
+                                        <div>Once a day</div>
+                                        <div>Twice a day</div>
+                                    </div>
+                                </div>
+                            </div>
+                            <div class="row mb-2">
+                                <div class="col-12">
+                                    <label class="text-sm text-secondary mb-0">Historic / Preexisting / New</label>
+                                    <select class="form-control form-control-sm additionReasonCategory_ui" name="additionReasonCategory_ui" required>
+                                        <option value="">-- select --</option>
+                                        <option value="HISTORIC">Historic</option>
+                                        <option value="PRE_EXISTING">Preexisting</option>
+                                        <option value="NEW">New (Prescribed during this visit)</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="d-flex align-items-start mb-2">
+                                <div class="w-25">
+                                    <div class="start_date_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Start Date</label>
+                                        <input type="date"
+                                               data-name="start_date"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="prescriber_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Prescribed By</label>
+                                        <input type="text"
+                                               data-name="prescriber"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="removalEffectiveDate_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">End Date</label>
+                                        <input type="date"
+                                               name="removalEffectiveDate"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="removalReasonMemo_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Removal By/Memo</label>
+                                        <input type="text"
+                                               name="removalReasonMemo"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="col-5 border-left">
+
+                        </div>
+                    </div>
+
+                    <div class="d-flex align-items-center">
+                        <button type="submit" class="btn btn-sm btn-primary mr-2 my-1">Save Medication</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            let parentSegment = $('#medications-center-{{$note->id}}');
+            parentSegment.find('input[stag-suggest][data-name="name"]')
+                .off('stag-suggest-selected')
+                .on('stag-suggest-selected', (_e, _input, _data) => {
+                    $(_input).closest('form').find('input[data-name="routedMedId"]').val(_data.routed_med_id);
+                    $(_input).closest('form').find('input[data-name="routedDosageFormMedId"]').val(_data.routed_dosage_form_med_id);
+                    $(_input).closest('form').find('input[data-name="gcnSeqno"]').val(_data.gcn_seqno);
+                    $(_input).closest('form').find('input[data-name="medId"]').val(_data.medid);
+                    return false;
+                });
+
+            parentSegment.find('.additionReasonCategory_ui')
+                .off('change')
+                .on('change', function() {
+
+                    let form = $(this).closest('form');
+
+                    // additionReasonCategory
+                    // isRemoved
+                    // removalReasonCategory
+                    form.find('[name="isRemovedDueToEntryError"]').val('0');
+
+                    form.find('.start_date_ui').hide();
+                    form.find('.prescriber_ui').hide();
+                    form.find('.removalEffectiveDate_ui').hide();
+                    form.find('.removalReasonMemo_ui').hide();
+
+                    if(this.value === 'HISTORIC') {
+                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
+                        form.find('[name="isRemoved"]').val('1');
+                        form.find('.start_date_ui').show();
+                        form.find('.prescriber_ui').show();
+                        form.find('.removalEffectiveDate_ui').show();
+                        form.find('.removalReasonMemo_ui').show();
+                    }
+                    else if(this.value === 'PRE_EXISTING') {
+                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
+                        form.find('[name="isRemoved"]').val('0');
+                        form.find('.start_date_ui').show();
+                        form.find('.prescriber_ui').show();
+                    }
+                    else if(this.value === 'NEW') {
+                        form.find('[name="additionReasonCategory"]').val('DURING_VISIT');
+                        form.find('[name="isRemoved"]').val('0');
+                        form.find('.start_date_ui').show().find('input').val('{{date('Y-m-d')}}');
+                        form.find('.prescriber_ui').show().find('input').val('{{$note->hcpPro->displayName()}}');
+                    }
+
+                });
+
+            parentSegment.find('#frm-add-medication')
+                .off('submit')
+                .on('submit', function () {
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('action'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            refreshDynamicStagPopup();
+                            $('.visit-segment[data-segment-template-name="intake_medications"]').find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            parentSegment.find('.frm-edit-medication')
+                .off('submit')
+                .on('submit', function () {
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('url'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            refreshDynamicStagPopup();
+                            $('.visit-segment[data-segment-template-name="intake_medications"]').find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            initStagSuggest();
+
+            $('.additionReasonCategory_ui').trigger('change');
+        }
+        addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}')
+    }).call(window);
+</script>

+ 175 - 2
resources/views/app/patient/note/dashboard.blade.php

@@ -515,7 +515,7 @@
                 </div>
                 @endif
                 <div class="note-rhs-content">
-            <div>
+                <div>
                 <div class="">
                     <div>
                         <?php
@@ -2207,7 +2207,80 @@
                     @include('app/patient/note/_cancel-signed-note')
                 </div>
 
-            </div>
+                </div>
+
+                    @if($isVisitTemplateBased)
+                    <div class="position-sticky note-bottom-toolbar border-top border-info p-0 bg-aliceblue d-flex align-items-stretch">
+                        <div class="nbt-container px-2 py-1 border-right border-info">
+                            <!-- render mrv segment here -->
+                            <?php $segment = null; ?>
+                            @foreach($note->segments as $segment)
+                                @if($segment->segmentTemplate->internal_name === 'medrisk_vigilence')
+                                    <div native target="_blank"
+                                         class="d-block c-pointer mrv-trigger d-flex align-items-center"
+                                         open-in-stag-popup
+                                         title="MedRisk Vigilance"
+                                         popup-style="stag-popup-md"
+                                         href="/segment-summary/{{$segment->uid}}">
+                                        <div class="text-info font-weight-bold text-center font-size-11">MRV</div>
+                                        {!! $segment->summary_html !!}
+                                    </div>
+                                @endif
+                            @endforeach
+                        </div>
+                        <div class="nbt-container px-2 py-1 border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center"
+                                 open-in-stag-popup
+                                 mc-initer="medications-center-{{$note->id}}"
+                                 title="Medications Center"
+                                 popup-style="wide overflow-visible"
+                                 href="/medications-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Rx</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container px-2 py-1 border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center"
+                                 open-in-stag-popup
+                                 mc-initer="problems-center-{{$note->id}}"
+                                 title="Problems Center"
+                                 popup-style="wide overflow-visible"
+                                 href="/problems-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Dx</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container px-2 py-1 border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center"
+                                 open-in-stag-popup
+                                 mc-initer="goals-center-{{$note->id}}"
+                                 title="Goals Center"
+                                 popup-style="wide overflow-visible"
+                                 href="/goals-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Goals</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container px-2 py-1 border-right border-info d-inline-flex align-self-stretch">
+                            <div class="position-relative on-click-menu d-inline-flex align-items-center">
+                                <span class="">Lifestyle <i class="fa fa-caret-up"></i></span>
+                                <div menu bottom class="bg-white border">
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_general">General</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_nutrition">Nutrition</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_physical_activity">Physical Activity</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_sleep">Sleep</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_social">Social Relationships</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_substances">Substance Use</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_stress">Stress</a>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    @endif
+
                 </div>
             </div>
         </div>
@@ -2288,3 +2361,103 @@
     </script>
     @endif
 @endsection
+@if(!$isVisitTemplateBased)
+@section('left-nav-content')
+    @if(!$note->is_signed_by_hcp)
+    <div class="left-nav-content" id="note-sections-app">
+        <div class="note-widget-title px-2 py-1">Note Sections</div>
+        <input type="search" class="d-block w-100 border-0 outline-0 px-2 py-1"
+               v-model="q" placeholder="Filter">
+        <div class="border-top py-1">
+            <div v-for="section in sections"
+                 v-show="section.title.toLowerCase().indexOf(q.toLowerCase()) !== -1">
+                <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
+                     :title="section.title + ' - Click to remove'"
+                     v-if="section.used"
+                     v-on:click.once="remove(section.section_uid)">
+                    <span class="mx-2">
+                        <a class="font-12 text-secondary" href="#">
+                            <i class="fa fa-minus-circle"></i>
+                        </a>
+                    </span>
+                    <span class="font-smaller text-ellipsis">
+                        @{{section.title}}
+                    </span>
+                </div>
+                <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
+                     :title="section.title + ' - Click to add'"
+                     v-if="!section.used"
+                     v-on:click.once="add(section.uid, section.internal_name)">
+                    <span class="mx-2">
+                        <a class="font-12" href="#">
+                            <i class="fa fa-plus-circle"></i>
+                        </a>
+                    </span>
+                    <span class="font-smaller text-ellipsis">
+                        @{{section.title}}
+                    </span>
+                </div>
+            </div>
+        </div>
+    </div>
+                <script>
+        (function() {
+            function initSectionsWidget() {
+                var allSections = <?= json_encode($allSections) ?>;
+                new Vue({
+                    el: '#note-sections-app',
+                    delimiters: ['@{{', '}}'],
+                    data: {
+                        q: '',
+                        sections: allSections
+                    },
+                    methods: {
+                        add: function(_uid, _section) {
+                            $.post('/api/section/create', {
+                                noteUid: '{{$note->uid}}',
+                                sectionTemplateUid: _uid,
+                            }, function(_data) {
+                                if(_data) {
+                                    if(_data.success) {
+                                        fastReload();
+                                    }
+                                    else {
+                                        toastr.error(_data.message);
+                                    }
+                                }
+                                else {
+                                    toastr.error('Unable to add section!');
+                                }
+                            }, 'json');
+                        },
+                        remove: function(_uid) {
+                            $.post('/api/section/deactivate', {
+                                uid: _uid,
+                                memo: 'Deactivated from note',
+                            }, function(_data) {
+                                if(_data) {
+                                    if(_data.success) {
+                                        fastReload();
+                                    }
+                                    else {
+                                        toastr.error(_data.message);
+                                    }
+                                }
+                                else {
+                                    toastr.error('Unable to remove section!');
+                                }
+                            }, 'json');
+                        }
+                    }
+                });
+
+                $('div[embed]').each(function() {
+                    $(this).load($(this).attr('embed'));
+                });
+            }
+            addMCInitializer('note-sections-widget', initSectionsWidget, '#note-sections-app');
+        })();
+    </script>
+    @endif
+@endsection
+@endif

+ 0 - 2
resources/views/app/patient/note/dashboard_script.blade.php

@@ -341,8 +341,6 @@
                         $(this).find('.edit-trigger').first().click();
                         return false;
                     });
-                @else
-                    $('#patient-header').closest('[role="main"]').css('padding-right', '50px');
                 @endif
 
                 // $(document)

+ 3 - 1
resources/views/app/patient/note/note-segment-list.blade.php

@@ -1,6 +1,8 @@
 <div class="segments-list" id="note-segments-list">
     @foreach($note->segments as $segment)
-        @include('app.patient.note.segment')
+        <div class="{{$segment->segmentTemplate->internal_name === 'medrisk_vigilence' ? 'd-none' : ''}}">
+            @include('app.patient.note.segment')
+        </div>
     @endforeach
 </div>
 @include('app.patient.note.segment_script')

+ 11 - 12
resources/views/app/patient/note/segment.blade.php

@@ -27,7 +27,7 @@
             </div>
         @else
             <span class="font-weight-bold d-flex align-items-center {{$isLSSegment || $iName === 'medrisk_vigilence' ? '' : 'mb-2'}}">
-			@if($isLSSegment && $iName === 'lifestyle_general')
+                @if($isLSSegment && $iName === 'lifestyle_general')
                     Lifestyle
                 @else
                     {{$segment->display_title}}
@@ -36,7 +36,7 @@
                 @if($segment->heading && $iName !== 'medrisk_vigilence')
                     <span class="text-secondary ml-2 text-sm font-weight-normal">({{$segment->heading}})</span>
                 @endif
-		</span>
+            </span>
         @endif
 
         @if($isLSSegment)
@@ -60,14 +60,15 @@
         @endif
 
         @if(!$note->is_signed_by_hcp && !$isLSSegment)
-            <a class="edit-trigger d-none if-edit c-pointer ml-3">Close</a>
+            <a class="edit-trigger d-none if-edit c-pointer ml-3">
+                <i class="fas fa-caret-up font-size-16"></i>
+            </a>
 
             <!-- refresh -->
-            <span class="mx-2 text-secondary text-sm {{$iName === 'medrisk_vigilence' ? 'd-none' : ''}}">|</span>
-            <a class="font-weight-normal refresh-segment c-pointer {{$iName === 'medrisk_vigilence' ? 'on-hover-only' : ''}}"
+            <a class="ml-3 font-weight-normal refresh-segment c-pointer {{$iName === 'medrisk_vigilence' ? 'on-hover-only' : ''}}"
                data-segment-uid="{{$segment->uid}}"
                title="Update with latest patient data">
-                Refresh
+                <i class="fa fa-sync"></i>
             </a>
 
             <!-- if intake - link to plan segment-->
@@ -78,11 +79,10 @@
                 <?php
                 $targetSegment = 'plan_' . substr($iName, 7);
                 ?>
-                <span class="mx-2 text-secondary text-sm">|</span>
-                <a class="segment-trigger"
+                <a class="segment-trigger ml-3"
                    href="#"
                    data-target="{{$targetSegment}}">
-                    Changes During this Visit
+                    Changes During this Visit (Plan)
                 </a>
             @endif
 
@@ -94,11 +94,10 @@
                 <?php
                 $targetSegment = 'intake_' . substr($iName, 5);
                 ?>
-                <span class="mx-2 text-secondary text-sm">|</span>
-                <a class="segment-trigger"
+                <a class="segment-trigger ml-3"
                    href="#"
                    data-target="{{$targetSegment}}">
-                    On Intake
+                    Back to Intake (Subjective)
                 </a>
             @endif
 

+ 44 - 2
resources/views/app/patient/note/segment_script.blade.php

@@ -21,9 +21,12 @@
                                 }, _data => {
                                     updateAllSegmentsInResponse(_data, false);
 
-                                    // TODO: remove this ugliness
+                                    // ugly hack!
                                     if(listenerSegmentTemplateName === 'medrisk_vigilence') {
-                                        toastr.info('Medrisk Vigilance Updated', null, { timeOut: 10000 });
+                                        $('.mrv-trigger')
+                                            .empty()
+                                            .append('<div class="text-info font-weight-bold text-center font-size-11">MRV</div>')
+                                            .append(_data.data.summaryHtml);
                                     }
 
                                 }, 'json');
@@ -245,6 +248,14 @@
 
         function init() {
 
+            $(document)
+                .off('input.auto-grow', '[visit-moe] form textarea')
+                .on('input.auto-grow', '[visit-moe] form textarea', function() {
+                    this.style.minHeight = "calc(1.5em + .5rem + 2px)";
+                    this.style.height = "calc(1.5em + .5rem + 2px)";
+                    this.style.height = (this.scrollHeight)+"px";
+                });
+
             let parent = $('.segments-list');
             initRTEs(parent);
             initSegmentMoes(parent);
@@ -319,6 +330,37 @@
                 initChangeListener($(this));
             });
              */
+
+            // relevance
+            $(document).off('change', '.visit-segment[data-segment-template-name] .chk-relevance');
+            $(document).on('change', '.visit-segment[data-segment-template-name] .chk-relevance', function () {
+                let segment = $(this).closest('.visit-segment');
+                if(this.checked) {
+                    $.post('/api/visitPoint/markPointRelevantToNote', {
+                        noteUid: '{{$note->uid}}',
+                        pointUid: $(this).attr('data-point-uid')
+                    }, _data => {
+                        if(!hasResponseError(_data)) {
+                            segment.find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                }
+                else {
+                    if($(this).attr('data-rel-uid')) {
+                        $.post('/api/visitPoint/undoMarkPointRelevantToNote', {
+                            uid: $(this).attr('data-rel-uid')
+                        }, _data => {
+                            if(!hasResponseError(_data)) {
+                                segment.find('.refresh-segment').trigger('click');
+                            }
+                        }, 'json');
+                    }
+                    else {
+                        console.log('Error - missing rel uid');
+                    }
+                }
+                return false;
+            });
         }
 
         addMCInitializer('note-segments-list', init, '#note-segments-list');

+ 13 - 6
resources/views/app/patient/note/sign-confirmation.blade.php

@@ -159,17 +159,24 @@
 
         function init() {
 
-            if($('.relevant-without-review[data-target-segment]').length) {
-                alert('Review missing for one or more items relevant to this note!');
+            if($('.relevant-without-review.block-signing[data-target-segment]').length) {
+                alert('Review missing for one or more problems relevant to this note!');
                 closeStagPopup(true);
-                $('.note-tree-node [data-segment-internal-name="' + $('.relevant-without-review[data-target-segment]').first().attr('data-target-segment') + '"]').trigger('click');
+                $('.note-tree-node [data-segment-internal-name="' + $('.relevant-without-review.block-signing[data-target-segment]').first().attr('data-target-segment') + '"]').trigger('click');
                 return false;
             }
 
-            if($('.relevant-without-plan[data-target-segment]').length) {
-                alert('Plan missing for one or more items relevant to this note!');
+            if($('.relevant-without-plan.block-signing[data-target-segment]').length) {
+                alert('Plan missing for one or more problems relevant to this note!');
                 closeStagPopup(true);
-                $('.note-tree-node [data-segment-internal-name="' + $('.relevant-without-plan[data-target-segment]').first().attr('data-target-segment') + '"]').trigger('click');
+                $('.note-tree-node [data-segment-internal-name="' + $('.relevant-without-plan.block-signing[data-target-segment]').first().attr('data-target-segment') + '"]').trigger('click');
+                return false;
+            }
+
+            if($('.no-relevant-with-icd.block-signing[data-target-segment]').length) {
+                alert('Need at least 1 relevant problem with an ICD before the note can be signed.');
+                closeStagPopup(true);
+                $('.note-tree-node [data-segment-internal-name="' + $('.no-relevant-with-icd.block-signing[data-target-segment]').first().attr('data-target-segment') + '"]').trigger('click');
                 return false;
             }
 

+ 31 - 21
resources/views/app/patient/notes.blade.php

@@ -10,30 +10,38 @@
                 <span class="mx-2 text-secondary">|</span>
                 <div moe>
                     <a start show class="py-0 mb-3">Add</a>
-                    <form url="/api/note/create" class="mcp-theme-1"
-                          redir="patients/view/{{ $patient->uid }}/notes/view/[data]">
+
+
+                    <form url="/api/note/createUsingTemplate"
+                          redir="/patients/view/{{$patient->uid}}/notes/view/[data]"
+                          class="mcp-theme-1">
                         <input type="hidden" name="clientUid" value="{{$patient->uid}}">
-                        <div class="form-group">
+                        <input type="hidden" name="effectiveDateEST" value="{{date("Y-m-d")}}">
+                        <input type="hidden" name="effectiveTime" value="{{date("h:i")}}">
+                        <input type="hidden" name="title" id="note-create-title" value="">
+                        <div class="form-group mb-2">
                             <label for="" class="text-secondary text-sm mb-1">Pro *</label>
                             <select name="hcpProUid" class="form-control" provider-search required data-pro-uid="{{$pro->is_hcp ? $pro->uid : ''}}">
                             </select>
                         </div>
-                        <input type="hidden" name="effectiveDateEST" value="{{ date('Y-m-d') }}">
-                        <div class="form-group">
-                            <label for="" class="text-secondary text-sm mb-1">Type *</label>
-                            <select name="newOrFuOrNa" class="form-control">
-                                <option value="NEW">New Patient</option>
-                                <option value="FU" {{$pro->is_hcp && $patient->hasNewNoteForPro($pro) ? 'selected' : ''}}>Follow Up</option>
-                                <option value="NA">N/A</option>
+                        <div class="form-group mb-2">
+                            <label for="" class="text-secondary text-sm mb-1">Note Template *</label>
+                            <select name="noteTemplateUid" class="form-control form-control-sm"
+                                    onchange="$('#note-create-title').val($(this).find('option:selected').text())"
+                                    required>
+                                <option value=""> --select--</option>
+                                @foreach($pro->noteTemplates as $noteTemplate)
+                                    <?php $nT = $noteTemplate->template(); ?>
+                                    <option value="{{$nT->uid}}">{{$nT->title}}</option>
+                                @endforeach
                             </select>
                         </div>
-                        <div class="form-group">
+                        <div class="mb-2">
                             <label for="" class="text-secondary text-sm mb-1">Method *</label>
-                            <select name="method" class="form-control note-method-select" required>
-                                <option value="">-- select --</option>
-                                <option value="VIDEO">Video</option>
+                            <select name="method" class="form-control form-control-sm note-method-select" required>
                                 <option value="AUDIO">Audio</option>
-                                <option value="IN_CLINIC">In Clinic</option>
+                                <option value="VIDEO">Video</option>
+                                <option value="IN_CLINIC">In-Clinic</option>
                                 <option value="HOUSE_CALL">House Call</option>
                             </select>
                         </div>
@@ -46,15 +54,14 @@
                                 @endforeach
                             </select>
                         </div>
-                        <div>
-                            <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
-                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                        <div class="form-group m-0">
+                            <button submit class="btn btn-primary btn-sm">submit</button>
                         </div>
                     </form>
                 </div>
                 <span class="mx-2 text-secondary">|</span>
                 <div moe>
-                <a start show class="py-0 mb-3">Add Visit</a>
+                <a start show class="py-0 mb-3 text-info font-weight-bold">Add Visit</a>
                 <form url="/api/visit/create"
                       redir="/patients/view/{{$patient->uid}}/notes/view/[data]"
                       class="mcp-theme-1">
@@ -166,9 +173,12 @@
         @foreach ($records as $note)
             <tr class="{{ $note->is_cancelled ? 'cancelled-item always-clickable' : '' }}">
                 <td class="px-2">
-                    <span class="font-weight-bold">
+                    <a href="/patients/view/{{ $patient->uid }}/notes/view/{{ $note->uid }}" class="font-weight-bold">
                         {{ friendly_date_time($note->effective_dateest, false) }}
-                    </span>
+                    </a>
+                    @if(!!$note->visitTemplate)
+                        <span class="text-info font-weight-bold">*</span>
+                    @endif
                     <span class="ml-1">{{ $note->is_cancelled ? '[cancelled]' : '' }}</span>
                 </td>
                 <td class="px-2">

+ 537 - 0
resources/views/app/patient/problems-center.blade.php

@@ -0,0 +1,537 @@
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+
+$points = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'PROBLEM')
+    ->where('is_removed_due_to_entry_error', false)
+    ->orderBy('is_removed')
+    ->orderBy('removal_effective_date', 'DESC')
+    ->orderBy('created_at')
+    ->get();
+foreach ($points as $point) {
+    if ($point->data) {
+        $point->data = json_decode($point->data);
+    }
+}
+$problems = $points;
+
+?>
+
+<div class="mt-3 p-3 border-top min-height-500px" id="problems-center-{{$note->id}}">
+    <div>
+
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white mb-2">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0 text-secondary">Name</th>
+                <th class="border-bottom-0 text-secondary">Active?</th>
+                <th class="border-bottom-0 text-secondary">Edit</th>
+                <th class="border-bottom-0 text-secondary">Delete</th>
+                <th class="border-bottom-0 text-secondary">Started</th>
+                <th class="border-bottom-0 text-secondary">Ended</th>
+                <th class="border-bottom-0 text-secondary">Last Review</th>
+                <th class="border-bottom-0 text-secondary">Last Plan</th>
+            </tr>
+            </thead>
+            <?php foreach($problems as $problem): ?>
+            <?php $point = $problem; ?>
+            <tr class="{{$problem->is_removed ? 'on-hover-opaque' : ''}}">
+                <td>
+                    <div class="d-flex align-items-baseline">
+                        @if($problem->is_removed)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @else
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @endif
+                        <div>
+                            <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
+                            @if(!$problem->is_removed && $problem->added_in_note_id === $note->id)
+                                <div class="mt-1 text-sm text-secondary">Added during this visit
+                                    @if($problem->addition_reason_category === 'ON_INTAKE')
+                                        (existing)
+                                    @elseif($problem->addition_reason_category === 'DURING_VISIT')
+                                        (new)
+                                    @endif
+                                </div>
+                            @endif
+                            @if($problem->is_removed && ($problem->added_in_note_id !== $note->id && $problem->removed_in_note_id === $note->id))
+                                <div class="mt-1 text-sm text-secondary">Discontinued during this visit</div>
+                            @endif
+                        </div>
+                    </div>
+                </td>
+                <td>
+                    @if($problem->is_removed)
+                        NO
+                    @else
+                        <b>YES</b>
+                    @endif
+                </td>
+                <td>
+                    @if($problem->added_in_note_id === $note->id)
+                        <div moe wide>
+                            <a start show href="#" title="Edit">Edit</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1 frm-edit-problem">
+                                <input type="hidden" name="uid" value="<?= $problem->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <p class="mb-2"><b>Update Problem</b></p>
+
+                                <input type="hidden" name="data">
+
+                                <input type="hidden" data-name="dxid" value="{{@$problem->data->dxid}}">
+                                <input type="hidden" data-name="icd-type" value="{{@$problem->data->{'icd-type'} }}">
+
+                                <input type="hidden" name="additionReasonCategory" value="{{@$problem->addition_reason_category}}">
+                                <input type="hidden" name="isRemoved" value="{{@$problem->is_removed}}">
+                                <input type="hidden" name="removalReasonCategory" value="{{@$problem->removal_reason_category}}">
+                                <input type="hidden" name="isRemovedDueToEntryError" value="{{@$problem->is_removed_due_to_entry_error}}">
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Problem</label>
+                                    <input type="text" class="form-control form-control-sm min-width-unset"
+                                           data-name="name"
+                                           value="{{@$problem->data->name}}"
+                                           stag-suggest
+                                           stag-suggest-ep="/fdb-dx-suggest/json">
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">ICD</label>
+                                    <select data-name="icd"
+                                            class="form-control form-control-sm"
+                                            disabled>
+                                    </select>
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-0">Historic / Preexisting / New</label>
+                                    <select class="form-control form-control-sm additionReasonCategory_ui" name="additionReasonCategory_ui" required>
+                                        <option value="">-- select --</option>
+                                        <option value="HISTORIC" {{$problem->addition_reason_category === 'ON_INTAKE' && $problem->is_removed ? 'selected' : ''}}>Historic</option>
+                                        <option value="PRE_EXISTING" {{$problem->addition_reason_category === 'ON_INTAKE' && !$problem->is_removed ? 'selected' : ''}}>Preexisting</option>
+                                        <option value="NEW" {{$problem->addition_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>New (Found during this visit)</option>
+                                    </select>
+                                </div>
+
+                                <div class="d-flex align-items-start">
+                                    <div class="w-50 mb-2">
+                                        <div class="start_date_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Start Date</label>
+                                            <input type="date"
+                                                   data-name="start_date"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                </div>
+                                <div class="d-flex align-items-start">
+                                    <div class="w-50 mb-2">
+                                        <div class="removalEffectiveDate_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">End Date</label>
+                                            <input type="date"
+                                                   name="removalEffectiveDate"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                    <div class="w-50 pl-2 mb-2">
+                                        <div class="removalReasonMemo_ui" style="display: none">
+                                            <label class="text-sm text-secondary mb-0">Removal Memo</label>
+                                            <input type="text"
+                                                   name="removalReasonMemo"
+                                                   class="form-control form-control-sm min-width-unset">
+                                        </div>
+                                    </div>
+                                </div>
+
+                                <div class="mb-2">
+                                    <label class="text-sm text-secondary mb-1">Description</label>
+                                    <textarea rows="1" data-name="description" class="form-control form-control-sm">{{@$problem->data->description}}</textarea>
+                                </div>
+
+                                <div>
+                                    <button type="submit" class="btn-save-problem btn btn-sm btn-primary mr-2">Save</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                </td>
+                <td>
+                    @if($problem->added_in_note_id === $note->id)
+                        <div moe>
+                            <a start show href="#" title="Delete">Delete</a>
+                            <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="<?= $problem->uid ?>">
+                                <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                <input type="hidden" name="isRemoved" value="1">
+                                <input type="hidden" name="isRemovedDueToEntryError" value="1">
+                                <input type="hidden" name="removalReasonMemo" value="Entry Error">
+                                <input type="hidden" name="removalEffectiveDate" value="<?= date('Y-m-d') ?>">
+                                <p class="mb-2"><b>Delete this problem?</b></p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @else
+                        @if(!$problem->is_removed)
+                            <div moe>
+                                <a start show href="#" title="Discontinue">Discontinue</a>
+                                <form url="/api/visitPoint/updateTopLevel" class="mcp-theme-1">
+                                    <input type="hidden" name="uid" value="<?= $problem->uid ?>">
+                                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                                    <input type="hidden" name="isRemoved" value="1">
+                                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+                                    <p class="mb-2"><b>Delete this problem?</b></p>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Already inactive?</label>
+                                        <select class="form-control form-control-sm" name="removalReasonCategory" required>
+                                            <option value="">-- select --</option>
+                                            <option value="ON_INTAKE">Already inactive (before this visit)</option>
+                                            <option value="DURING_VISIT">Mark inactive now</option>
+                                        </select>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Reason</label>
+                                        <textarea name="removalReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-sm text-secondary mb-1">Removal Effective Date</label>
+                                        <input type="date" name="removalEffectiveDate"
+                                               value="<?= date('Y-m-d') ?>"
+                                               max="<?= date('Y-m-d') ?>"
+                                               class="form-control form-control-sm">
+                                    </div>
+                                    <div>
+                                        <button submit class="btn btn-sm btn-danger mr-2">Delete</button>
+                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @endif
+                    @endif
+                </td>
+                <td>
+                    <?= !!@($problem->data->start_date) ? @($problem->data->start_date) : '-' ?>
+                </td>
+                <td>
+                    <?= !!@($problem->removal_effective_date) ? @($problem->removal_effective_date) : '-' ?>
+                    @if(!!@($problem->removal_reason_memo))
+                        <div class="mt-1 text-sm text-secondary"><?= !!@($problem->removal_reason_memo) ? @($problem->removal_reason_memo) : '-' ?></div>
+                    @endif
+                </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            $point = $problem;
+                            include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                            ?>
+                        </div>
+                        <a class="px-2 view-review-log"
+                           native target="_blank"
+                           open-in-stag-popup
+                           popup-style="stag-popup-md"
+                           title="Review log<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?>"
+                           href="/point/review-log/<?= $problem->uid ?>?popupmode=1">
+                            <i class="fa fa-history"></i>
+                        </a>
+                    </div>
+                </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
+                            ?>
+                        </div>
+                        <a class="px-2 view-review-log"
+                           native target="_blank"
+                           open-in-stag-popup
+                           popup-style="stag-popup-md"
+                           title="Plan log<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?>"
+                           href="/point/plan-log/<?= $problem->uid ?>?popupmode=1">
+                            <i class="fa fa-history"></i>
+                        </a>
+                    </div>
+                </td>
+            </tr>
+            <?php endforeach; ?>
+        </table>
+
+        <div class="d-flex align-items-center">
+            <div class="mt-1 w-100 border p-2 bg-aliceblue border-info rounded">
+                <form action="/api/visitPoint/addTopLevel" class="mcp-theme-1 w-100" id="frm-add-problem">
+                    <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
+                    <input type="hidden" name="category" value="PROBLEM">
+                    <input type="hidden" name="data">
+
+                    <input type="hidden" data-name="dxid">
+                    <input type="hidden" data-name="icd-type">
+
+                    <input type="hidden" name="additionReasonCategory">
+                    <input type="hidden" name="isRemoved">
+                    <input type="hidden" name="removalReasonCategory">
+                    <input type="hidden" name="isRemovedDueToEntryError">
+
+                    <p class="mb-2"><b>Add Problem</b></p>
+
+                    <div class="row">
+                        <div class="col-7">
+                            <div class="row mb-2">
+                                <div class="col-8 pr-0">
+                                    <label class="text-sm text-secondary mb-0">Name</label>
+                                    <input type="text"
+                                           data-name="name"
+                                           class="form-control form-control-sm"
+                                           stag-suggest
+                                           stag-suggest-bottom-left
+                                           stag-suggest-ep="/fdb-dx-suggest/json"
+                                           required>
+                                </div>
+                                <div class="col-4">
+                                    <label class="text-sm text-secondary mb-1">ICD</label>
+                                    <select data-name="icd"
+                                            class="form-control form-control-sm"
+                                            disabled>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="row mb-2">
+                                <div class="col-12">
+                                    <label class="text-sm text-secondary mb-0">Historic / Preexisting / New</label>
+                                    <select class="form-control form-control-sm additionReasonCategory_ui" name="additionReasonCategory_ui" required>
+                                        <option value="">-- select --</option>
+                                        <option value="HISTORIC">Historic</option>
+                                        <option value="PRE_EXISTING">Preexisting</option>
+                                        <option value="NEW">New (Found during this visit)</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="d-flex align-items-start mb-2">
+                                <div class="w-25">
+                                    <div class="start_date_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Start Date</label>
+                                        <input type="date"
+                                               data-name="start_date"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="removalEffectiveDate_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">End Date</label>
+                                        <input type="date"
+                                               name="removalEffectiveDate"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                                <div class="w-25 pl-2">
+                                    <div class="removalReasonMemo_ui" style="display: none">
+                                        <label class="text-sm text-secondary mb-0">Removal By/Memo</label>
+                                        <input type="text"
+                                               name="removalReasonMemo"
+                                               class="form-control form-control-sm min-width-unset">
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="col-5 border-left">
+
+                        </div>
+                    </div>
+
+                    <div class="d-flex align-items-center">
+                        <button type="submit" class="btn btn-sm btn-primary mr-2 my-1">Save Problem</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            let parentSegment = $('#problems-center-{{$note->id}}');
+            parentSegment.find('input[stag-suggest][data-name="name"]')
+                .off('stag-suggest-selected')
+                .on('stag-suggest-selected', (_e, _input, _data) => {
+                    $(_input).closest('form').find('input[data-name="dxid"]').val(_data.dxid);
+                    let icdSelect = $(_input).closest('form').find('[data-name="icd"]').empty().prop('disabled', true);
+                    $.get('/fdb-dx-icds-for-dxid?dxid=' + _data.dxid, _data => {
+                        icdSelect.empty().append('<option value="">-- select --</option>');
+                        for (let i = 0; i < _data.length; i++) {
+                            icdSelect.append('<option value="' + _data[i].search_icd_cd + '" data-icd-type="' + _data[i].icd_cd_type + '">' + _data[i].search_icd_cd + ' (' + (_data[i].icd_cd_type === '01' ? 'ICD-9' : 'ICD-10') + ') - ' + _data[i].icd_desc + '</option>')
+                        }
+                        icdSelect.prop('disabled', false);
+                        if (_data.length === 1) {
+                            icdSelect.val(_data[0].routed_med_id).trigger('change');
+                        }
+                    }, 'json');
+                });
+
+            // on route selection
+            parentSegment.find('input[data-name="icd"]')
+                .off('change')
+                .on('change', function () {
+                    $(this).closest('form').find('input[data-name="icd-type"]').val($(this).find('option:selected').attr('data-icd-type'));
+                });
+
+            parentSegment.find('.additionReasonCategory_ui')
+                .off('change')
+                .on('change', function() {
+
+                    let form = $(this).closest('form');
+
+                    // additionReasonCategory
+                    // isRemoved
+                    // removalReasonCategory
+                    form.find('[name="isRemovedDueToEntryError"]').val('0');
+
+                    form.find('.start_date_ui').hide();
+                    form.find('.removalEffectiveDate_ui').hide();
+                    form.find('.removalReasonMemo_ui').hide();
+
+                    if(this.value === 'HISTORIC') {
+                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
+                        form.find('[name="isRemoved"]').val('1');
+                        form.find('.start_date_ui').show();
+                        form.find('.removalEffectiveDate_ui').show();
+                        form.find('.removalReasonMemo_ui').show();
+                    }
+                    else if(this.value === 'PRE_EXISTING') {
+                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
+                        form.find('[name="isRemoved"]').val('0');
+                        form.find('.start_date_ui').show();
+                    }
+                    else if(this.value === 'NEW') {
+                        form.find('[name="additionReasonCategory"]').val('DURING_VISIT');
+                        form.find('[name="isRemoved"]').val('0');
+                        form.find('.start_date_ui').show().find('input').val('{{date('Y-m-d')}}');
+                    }
+
+                });
+
+            parentSegment.find('#frm-add-problem')
+                .off('submit')
+                .on('submit', function () {
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('action'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            refreshDynamicStagPopup();
+                            $('.visit-segment[data-segment-template-name="intake_problems"]').find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            parentSegment.find('.frm-edit-problem')
+                .off('submit')
+                .on('submit', function () {
+
+                    let form = $(this);
+
+                    if (!form[0].checkValidity()) {
+                        form[0].reportValidity();
+                        return false;
+                    }
+
+                    // add [data-name] values to payload
+                    let dataField = form.find('[name="data"]').first();
+                    let parsed = null;
+                    if(dataField.val()) {
+                        parsed = JSON.parse(dataField.val());
+                    }
+                    form.find('[data-name]').each(function() {
+                        if(!parsed) parsed = {};
+
+                        let keys = $(this).attr('data-name').split('->');
+                        let currentNode = parsed;
+                        for (let i = 0; i < keys.length; i++) {
+                            if(i !== keys.length - 1) {
+                                if(typeof currentNode[keys[i]] === 'undefined') {
+                                    currentNode[keys[i]] = {};
+                                }
+                                currentNode = currentNode[keys[i]];
+                            }
+                            else {
+                                if($(this).is(':checkbox')) {
+                                    currentNode[keys[i]] = $(this).prop('checked');
+                                }
+                                else {
+                                    currentNode[keys[i]] = $(this).val();
+                                }
+                            }
+                        }
+
+                    });
+                    if(parsed) {
+                        dataField.val(JSON.stringify(parsed));
+                    }
+
+                    $.post(form.attr('url'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            hideMask();
+                            refreshDynamicStagPopup();
+                            $('.visit-segment[data-segment-template-name="intake_problems"]').find('.refresh-segment').trigger('click');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            initStagSuggest();
+
+            $('.additionReasonCategory_ui').trigger('change');
+        }
+        addMCInitializer('problems-center-{{$note->id}}', init, '#problems-center-{{$note->id}}')
+    }).call(window);
+</script>

+ 33 - 3
resources/views/app/patient/segment-templates/_child_plan/edit-plan.php

@@ -1,18 +1,48 @@
 <?php
 $currentValue = '';
+$previousValue = '';
+$previousChildPlan = null;
 if ($point->lastChildPlan && $point->last_child_plan_point_scoped_note_id === $note->id) {
     $parsedPlan = json_decode($point->lastChildPlan->data);
     $currentValue = $parsedPlan->value;
+    $previousChildPlan = \App\Models\Point::where('id', '<', $point->lastChildPlan->id)
+        ->where('category', 'PLAN')
+        ->where('parent_point_id', $point->id)
+        ->orderBy('id', 'DESC')
+        ->first();
+    if($previousChildPlan && $previousChildPlan->data) {
+        $parsedPlan = json_decode($previousChildPlan->data);
+        $previousValue = $parsedPlan->value;
+    }
+}
+else {
+    $previousChildPlan = \App\Models\Point::where('parent_point_id', $point->id)
+        ->where('category', 'PLAN')
+        ->orderBy('id', 'DESC')
+        ->first();
+    if($previousChildPlan && $previousChildPlan->data) {
+        $parsedPlan = json_decode($previousChildPlan->data);
+        $previousValue = $parsedPlan->value;
+    }
 }
 ?>
-<div visit-moe large relative>
-    <a start show href="#">Edit</a>
+<div visit-moe large relative class="d-inline">
+    <a start show href="#"><i class="fa fa-plus-square"></i></a>
     <form url="/api/visitPoint/upsertChildPlan" class="mcp-theme-1" right>
         <input type="hidden" name="uid" value="<?= $point->uid ?>">
         <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
         <input type="hidden" name="data">
 
-        <p class="mb-2"><b>Review</b></p>
+        <p class="mb-2"><b>Plan</b></p>
+
+        <?php if($previousValue): ?>
+        <div class="mb-2">
+            <div class="d-flex align-items-baseline mb-1">
+                <span class="text-sm text-secondary">Previous Plan / <?= friendlier_date($previousChildPlan->created_at) ?>) (click to copy)</span>
+            </div>
+            <div class="p-2 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+        </div>
+        <?php endif; ?>
 
         <div class="mb-2">
             <div note-rte

+ 37 - 3
resources/views/app/patient/segment-templates/_child_review/edit-review.php

@@ -1,12 +1,37 @@
 <?php
 $currentValue = '';
+$previousValue = '';
+$previousChildReview = null;
 if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
     $parsedReview = json_decode($point->lastChildReview->data);
-    $currentValue = $parsedReview->value;
+    if(@$parsedReview->value) {
+        $currentValue = $parsedReview->value;
+        $previousChildReview = \App\Models\Point::where('id', '<', $point->lastChildReview->id)
+            ->where('category', 'REVIEW')
+            ->where('parent_point_id', $point->id)
+            ->orderBy('id', 'DESC')
+            ->first();
+        if($previousChildReview && $previousChildReview->data) {
+            $parsedReview = json_decode($previousChildReview->data);
+            $previousValue = $parsedReview->value;
+        }
+    }
+}
+else {
+    $previousChildReview = \App\Models\Point::where('parent_point_id', $point->id)
+        ->where('category', 'REVIEW')
+        ->orderBy('id', 'DESC')
+        ->first();
+    if($previousChildReview && $previousChildReview->data) {
+        $parsedReview = json_decode($previousChildReview->data);
+        if(@$parsedReview->value) {
+            $previousValue = $parsedReview->value;
+        }
+    }
 }
 ?>
-<div visit-moe relative>
-    <a start show href="#">Edit</a>
+<div visit-moe relative class="d-inline">
+    <a start show href="#"><i class="fa fa-plus-square"></i></a>
     <form url="/api/visitPoint/upsertChildReview" class="mcp-theme-1" right>
         <input type="hidden" name="uid" value="<?= $point->uid ?>">
         <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
@@ -14,6 +39,15 @@ if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id ==
 
         <p class="mb-2"><b>Review</b></p>
 
+        <?php if($previousValue): ?>
+            <div class="mb-2">
+                <div class="d-flex align-items-baseline mb-1">
+                    <span class="text-sm text-secondary">Previous Review / <?= friendlier_date($previousChildReview->created_at) ?>) (click to copy)</span>
+                </div>
+                <div class="p-2 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+            </div>
+        <?php endif; ?>
+
         <div class="mb-2">
             <textarea data-name="value" class="form-control form-control-sm" rows="3"><?= $currentValue ?></textarea>
         </div>

+ 2 - 2
resources/views/app/patient/segment-templates/_common_actions/remove-undo.php

@@ -11,9 +11,9 @@ $epNotPart = ($intakeOrVisit === 'INTAKE') ? 'DuringVisit' : 'OnIntake';
     <?php if ($point->is_removed_due_to_entry_error): ?>
         <span class="font-weight-bold text-secondary mr-2 text-nowrap">Entry error</span>
     <?php else: ?>
-        <?php if($medication->removal_reason_category === 'DURING_VISIT'): ?>
+        <?php if($point->removal_reason_category === 'DURING_VISIT'): ?>
         <span class="ont-weight-bold text-secondary mr-2 text-nowrap">Removed during visit</span>
-        <?php elseif($medication->removal_reason_category === 'ON_INTAKE'): ?>
+        <?php elseif($point->removal_reason_category === 'ON_INTAKE'): ?>
         <span class="ont-weight-bold text-secondary mr-2 text-nowrap">Removed on intake</span>
         <?php endif; ?>
     <?php endif; ?>

+ 17 - 69
resources/views/app/patient/segment-templates/intake_allergies/edit.blade.php

@@ -11,16 +11,6 @@ use \App\Models\Segment;
 
 $allergies = Point::getIntakePointsOfCategory($patient, 'ALLERGY', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'ALLERGIES_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -31,17 +21,18 @@ else {
                 <th class="border-bottom-0">Allergy</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php foreach($allergies as $allergy): ?>
                 <?php $point = $allergy; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$allergy->uid}}" {{in_array($allergy->uid, $relevance) ? 'checked' : ''}}>
-                            <span>&nbsp;</span>
+                                   data-point-uid="{{$allergy->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                         </label>
                     </td>
                     <td>
@@ -99,14 +90,19 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Review log<?= !!@($allergy->data->name) ? ' for ' . @($allergy->data->name) : '' ?>"
-                               href="/point/review-log/<?= $allergy->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Review log<?= !!@($allergy->data->name) ? ' for ' . @($allergy->data->name) : '' ?>"
+                                   href="/point/review-log/<?= $allergy->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
                     <td>
@@ -126,24 +122,11 @@ else {
                             </a>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="ALLERGIES_RELEVANT_TO_NOTE_ON_INTAKE">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add allergy patient ALREADY is diagnosed with, prior to this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1 w-100">
@@ -173,7 +156,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -193,39 +175,5 @@ else {
                 _input.closest('form').find('input[data-name="damConceptIdType"]').val(_data.dam_concept_id_typ);
             });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 4 - 14
resources/views/app/patient/segment-templates/intake_allergies/summary.blade.php

@@ -6,17 +6,6 @@ use App\Models\Point;
 
 $allergies = Point::getIntakePointsOfCategory($patient, 'ALLERGY', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'ALLERGIES_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 ?>
 
@@ -24,9 +13,10 @@ $numRelevant = 0;
     <div class="text-secondary">No allergies</div>
 <?php else: ?>
     <?php foreach ($allergies as $allergy): ?>
+        <?php $rel = $allergy->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($allergy->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -52,8 +42,8 @@ $numRelevant = 0;
                     <div class="text-secondary font-weight-bold">Review</div>
                     <div>{!! $review->data->value !!}</div>
                 </div>
-            <?php elseif(in_array($allergy->uid, $relevance)): ?>
-                <div class="relevant-without-review text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
+            <?php elseif($rel): ?>
+                <div class="relevant-without-review text-danger mt-1 text-sm" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>

+ 17 - 71
resources/views/app/patient/segment-templates/intake_care_team/edit.blade.php

@@ -11,16 +11,6 @@ use \App\Models\Segment;
 
 $careTeamMembers = Point::getIntakePointsOfCategory($patient, 'CARE_TEAM_MEMBER', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'CARE_TEAM_MEMBERS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,16 +22,17 @@ else {
                 <th class="border-bottom-0">Care Team Member</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php foreach($careTeamMembers as $careTeamMember): ?>
+                <?php $rel = $careTeamMember->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$careTeamMember->uid}}" {{in_array($careTeamMember->uid, $relevance) ? 'checked' : ''}}>
-                            <span>&nbsp;</span>
+                                   data-point-uid="{{$careTeamMember->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                         </label>
                     </td>
                     <td>
@@ -122,14 +113,19 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Review log<?= !!@($careTeamMember->data->name) ? ' for ' . @($careTeamMember->data->name) : '' ?>"
-                               href="/point/review-log/<?= $careTeamMember->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Review log<?= !!@($careTeamMember->data->name) ? ' for ' . @($careTeamMember->data->name) : '' ?>"
+                                   href="/point/review-log/<?= $careTeamMember->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
                     <td>
@@ -150,26 +146,12 @@ else {
                             </a>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        $point = $careTeamMember;
-                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>
     </div>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="CARE_TEAM_MEMBERS_RELEVANT_TO_NOTE_ON_INTAKE">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add care team member patient is ALREADY having, prior to this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1 w-100">
@@ -214,7 +196,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -225,40 +206,5 @@ else {
     window.segmentInitializers.<?= $segment->segmentTemplate->internal_name ?> = function() {
         // any JS can come here
         // will be run on page-load as well as whenever this segment is refreshed
-
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 4 - 14
resources/views/app/patient/segment-templates/intake_care_team/summary.blade.php

@@ -6,17 +6,6 @@ use App\Models\Point;
 
 $careTeamMembers = Point::getIntakePointsOfCategory($patient, 'CARE_TEAM_MEMBER', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'CARE_TEAM_MEMBERS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 
 ?>
@@ -25,9 +14,10 @@ $numRelevant = 0;
     <div class="text-secondary">No care team members</div>
 <?php else: ?>
     <?php foreach($careTeamMembers as $careTeamMember): ?>
+        <?php $rel = $careTeamMember->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($careTeamMember->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -57,8 +47,8 @@ $numRelevant = 0;
                 <div class="text-secondary font-weight-bold">Review</div>
                 <div>{!! $review->data->value !!}</div>
             </div>
-            <?php elseif(in_array($careTeamMember->uid, $relevance)): ?>
-            <div class="relevant-without-review text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
+            <?php elseif($rel): ?>
+            <div class="relevant-without-review text-danger mt-1 text-sm" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>

+ 17 - 69
resources/views/app/patient/segment-templates/intake_goals/edit.blade.php

@@ -11,16 +11,6 @@ use \App\Models\Segment;
 
 $goals = Point::getIntakePointsOfCategory($patient, 'GOAL', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'GOALS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -33,19 +23,20 @@ else {
                 <th class="border-bottom-0">Goal</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php $previousCategory = null; ?>
             <?php foreach($goals as $goal): ?>
                 <?php if(@($goal->data->category)): ?>
                 <?php $point = $goal; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$goal->uid}}" {{in_array($goal->uid, $relevance) ? 'checked' : ''}}>
-                            <span>&nbsp;</span>
+                                   data-point-uid="{{$goal->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                         </label>
                     </td>
                     <td>
@@ -175,14 +166,19 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Review log<?= !!@($goal->data->name) ? ' for ' . @($goal->data->name) : '' ?>"
-                               href="/point/review-log/<?= $goal->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Review log<?= !!@($goal->data->name) ? ' for ' . @($goal->data->name) : '' ?>"
+                                   href="/point/review-log/<?= $goal->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
                     <td>
@@ -202,11 +198,6 @@ else {
                             </a>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
-                        ?>
-                    </td>
                 </tr>
                 <?php $previousCategory = $goal->data->category; ?>
                 <?php endif; ?>
@@ -215,14 +206,6 @@ else {
     </div>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="GOALS_RELEVANT_TO_NOTE_ON_INTAKE">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add goal patient is ALREADY having, prior to this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1 w-100">
@@ -313,7 +296,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -333,39 +315,5 @@ else {
                 $(this).closest('form').find('.help-text[data-category="' + this.value + '"]').removeClass('d-none');
             });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 6 - 16
resources/views/app/patient/segment-templates/intake_goals/summary.blade.php

@@ -15,17 +15,6 @@ foreach($goals as $goal) {
     $grouped[$goal->data->category][] = $goal;
 }
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'GOALS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 
 ?>
@@ -36,12 +25,13 @@ $numRelevant = 0;
     <?php foreach($grouped as $k => $group): ?>
         <b><?= $k ?></b>
         <?php foreach($group as $goal): ?>
+            <?php $rel = $goal->relevanceToNote($note); ?>
             <div class="pl-2 mb-2">
                 <div class="d-flex align-items-baseline">
-                    @if(in_array($goal->uid, $relevance))
+                    @if($rel)
                         <span class="text-info mr-1">
-                            <i class="fa fa-star"></i>
-                        </span>
+                        <i class="fa fa-star"></i>
+                    </span>
                         <?php $numRelevant++; ?>
                     @endif
                     <div class="<?= $goal->is_removed ? 'strike-through' : '' ?>">
@@ -63,8 +53,8 @@ $numRelevant = 0;
                     <div class="text-secondary font-weight-bold">Review</div>
                     <div>{!! $review->data->value !!}</div>
                 </div>
-                <?php elseif(in_array($goal->uid, $relevance)): ?>
-                <div class="relevant-without-review text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
+                <?php elseif($rel): ?>
+                <div class="relevant-without-review text-danger mt-1 text-sm" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
                 <?php endif; ?>
             </div>
         <?php endforeach; ?>

+ 0 - 7
resources/views/app/patient/segment-templates/intake_interventions/edit.blade.php

@@ -22,7 +22,6 @@ $interventions = Point::getIntakePointsOfCategory($patient, 'INTERVENTION', $not
                 <th class="border-bottom-0">Intervention</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php $previousCategory = null; ?>
@@ -133,12 +132,6 @@ $interventions = Point::getIntakePointsOfCategory($patient, 'INTERVENTION', $not
                             </a>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        $point = $intervention;
-                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
-                        ?>
-                    </td>
                 </tr>
                 <?php $previousCategory = $intervention->data->category; ?>
             <?php endforeach; ?>

+ 17 - 70
resources/views/app/patient/segment-templates/intake_medications/edit.blade.php

@@ -11,16 +11,6 @@ use App\Models\Segment;
 
 $medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'MEDICATIONS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,15 +22,17 @@ else {
                 <th class="border-bottom-0">Medication</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php foreach($medications as $medication): ?>
                 <tr>
                     <td class="p-0">
+                        <?php $rel = $medication->relevanceToNote($note); ?>
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$medication->uid}}" {{in_array($medication->uid, $relevance) ? 'checked' : ''}}>
+                                   data-point-uid="{{$medication->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                             <span>&nbsp;</span>
                         </label>
                     </td>
@@ -137,14 +129,19 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Review log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
-                               href="/point/review-log/<?= $medication->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Review log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
+                                   href="/point/review-log/<?= $medication->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
                     <td>
@@ -165,26 +162,12 @@ else {
                             </a>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        $point = $medication;
-                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>
     </div>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="MEDICATIONS_RELEVANT_TO_NOTE_ON_INTAKE">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add medication patient is ALREADY taking, prior to this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1 w-100">
@@ -234,7 +217,6 @@ else {
 
                 <div class="d-flex align-items-start">
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -269,41 +251,6 @@ else {
                 return false;
             });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
     };
 </script>
 

+ 0 - 7
resources/views/app/patient/segment-templates/intake_medications/edit_old.blade.php

@@ -21,7 +21,6 @@ $medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
                 <th class="border-bottom-0">Medication</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php foreach($medications as $medication): ?>
@@ -82,12 +81,6 @@ $medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
                             </a>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        $point = $medication;
-                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>

+ 5 - 15
resources/views/app/patient/segment-templates/intake_medications/summary.blade.php

@@ -6,17 +6,6 @@ use App\Models\Point;
 
 $medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'MEDICATIONS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 
 ?>
@@ -25,9 +14,10 @@ $numRelevant = 0;
     <div class="text-secondary">No medications</div>
 <?php else: ?>
     <?php foreach ($medications as $medication): ?>
+        <?php $rel = $medication->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($medication->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -54,15 +44,15 @@ $numRelevant = 0;
                 <div class="text-secondary font-weight-bold">Review</div>
                 <div>{!! $review->data->value !!}</div>
             </div>
-            <?php elseif(in_array($medication->uid, $relevance)): ?>
-            <div class="relevant-without-review text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
+            <?php elseif($rel): ?>
+            <div class="relevant-without-review text-danger mt-1 text-sm" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>
     @if($numRelevant)
         <div class="d-flex align-items-baseline text-info mr-1 mt-3">
             <span class="text-sm mr-1"><i class="fa fa-star text-sm"></i></span>
-            <span class="text-sm">Medications to this note</span>
+            <span class="text-sm">Medications relevant to this note</span>
         </div>
     @endif
 <?php endif; ?>

+ 17 - 71
resources/views/app/patient/segment-templates/intake_problems/edit.blade.php

@@ -11,16 +11,6 @@ use \App\Models\Segment;
 
 $problems = Point::getIntakePointsOfCategory($patient, 'PROBLEM', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'PROBLEMS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,16 +22,17 @@ else {
                 <th class="border-bottom-0">Problem</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Review Today</th>
             </tr>
             </thead>
             <?php foreach($problems as $problem): ?>
+                <?php $rel = $problem->relevanceToNote($note); ?>
             <tr>
                 <td class="p-0">
                     <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                         <input type="checkbox" class="m-0 chk-relevance"
-                               data-uid="{{$problem->uid}}" {{in_array($problem->uid, $relevance) ? 'checked' : ''}}>
-                        <span>&nbsp;</span>
+                               data-point-uid="{{$problem->uid}}"
+                               data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                {{$rel ? 'checked' : ''}}>
                     </label>
                 </td>
                 <td>
@@ -111,14 +102,19 @@ else {
                             include resource_path('views/app/patient/segment-templates/_review/problem/last-review.php');
                             ?>
                         </div>
-                        <a class="px-2 view-review-log"
-                           native target="_blank"
-                           open-in-stag-popup
-                           popup-style="stag-popup-md"
-                           title="Review log<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?>"
-                           href="/point/review-log/<?= $problem->uid ?>?popupmode=1">
-                            <i class="fa fa-history"></i>
-                        </a>
+                        <div class="d-inline-flex flex-nowrap">
+                            <a class="px-2 view-review-log"
+                               native target="_blank"
+                               open-in-stag-popup
+                               popup-style="stag-popup-md"
+                               title="Review log<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?>"
+                               href="/point/review-log/<?= $problem->uid ?>?popupmode=1">
+                                <i class="fa fa-history"></i>
+                            </a>
+                            <?php
+                            include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                            ?>
+                        </div>
                     </div>
                 </td>
                 <td>
@@ -139,26 +135,12 @@ else {
                         </a>
                     </div>
                 </td>
-                <td>
-                    <?php
-                    $point = $problem;
-                    include resource_path('views/app/patient/segment-templates/_review/problem/edit-review.php');
-                    ?>
-                </td>
             </tr>
             <?php endforeach; ?>
         </table>
     </div>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="PROBLEMS_RELEVANT_TO_NOTE_ON_INTAKE">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add Problem patient is ALREADY having, prior
                 to this visit</a>-->
@@ -198,7 +180,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -242,40 +223,5 @@ else {
             $(this).closest('form').find('input[data-name="icd-type"]').val($(this).find('option:selected').attr('data-icd-type'));
         });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
     };
 </script>

+ 4 - 13
resources/views/app/patient/segment-templates/intake_problems/summary.blade.php

@@ -6,16 +6,6 @@ use App\Models\Point;
 
 $problems = Point::getIntakePointsOfCategory($patient, 'PROBLEM', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'PROBLEMS_RELEVANT_TO_NOTE_ON_INTAKE')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
 $numRelevant = 0;
 ?>
 
@@ -23,9 +13,10 @@ $numRelevant = 0;
     <div class="text-secondary">No problems</div>
 <?php else: ?>
     <?php foreach ($problems as $problem): ?>
+        <?php $rel = $problem->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($problem->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -55,8 +46,8 @@ $numRelevant = 0;
                 include resource_path('views/app/patient/segment-templates/_review/problem/view.php');
                 ?>
             </div>
-            <?php elseif(in_array($problem->uid, $relevance)): ?>
-            <div class="relevant-without-review text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
+            <?php elseif($rel): ?>
+            <div class="relevant-without-review block-signing text-danger mt-1 text-sm" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Review missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>

+ 30 - 12
resources/views/app/patient/segment-templates/medrisk_vigilence/summary.blade.php

@@ -4,6 +4,24 @@
 $drugs = \App\Models\Point::getPointsOfCategory($patient, "MEDICATION");
 $allergies = \App\Models\Point::getPointsOfCategory($patient, "ALLERGY");
 
+// filter out drugs without fdb info on them
+$drugs = $drugs->filter(function($_drug) {
+    return @$_drug->data &&
+        $_drug->data->name &&
+        $_drug->data->medId &&
+        $_drug->data->routedMedId &&
+        $_drug->data->routedDosageFormMedId &&
+        $_drug->data->gcnSeqno;
+});
+
+// filter out allergies without fdb info on them
+$allergies = $allergies->filter(function($_allergy) {
+    return @$_allergy->data &&
+        $_allergy->data->name &&
+        $_allergy->data->damConceptId &&
+        $_allergy->data->damConceptIdType;
+});
+
 // side effects
 $sideeffects = side_effects_info($drugs);
 
@@ -28,8 +46,8 @@ $hasMRVData = false;
 
 @if(!!$dptInfo)
     <?php $hasMRVData = true; ?>
-    <div class="mrv-badge mt-2 align-self-center on-hover-hide mx-auto" title="Duplicate Therapy Notes"><span>DT</span></div>
-    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-hover-only">
+    <div class="mrv-badge ml-1 align-self-center on-trigger-only" title="Duplicate Therapy Notes"><span>DT</span></div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-content-only">
         <p class="font-weight-bold m-0 font-size-14 text-info">Duplicate Therapy Notes</p>
         <div class="mt-3 ml-3">
             {!! $dptInfo !!}
@@ -39,8 +57,8 @@ $hasMRVData = false;
 
 @if(!!$coadministration)
     <?php $hasMRVData = true; ?>
-    <div class="mrv-badge mt-2 align-self-center on-hover-hide mx-auto" title="Coadministration Notes"><span>CA</span></div>
-    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-hover-only">
+    <div class="mrv-badge ml-1 align-self-center on-trigger-only" title="Coadministration Notes"><span>CA</span></div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-content-only">
         <p class="font-weight-bold m-0 font-size-14 text-info">Coadministration Notes</p>
         <div class="mt-3 ml-3">
             {!! $coadministration !!}
@@ -50,8 +68,8 @@ $hasMRVData = false;
 
 @if(!!$dam)
     <?php $hasMRVData = true; ?>
-    <div class="mrv-badge mt-2 align-self-center on-hover-hide mx-auto" title="Drug Allergy Notes"><span>DA</span></div>
-    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-hover-only">
+    <div class="mrv-badge ml-1 align-self-center on-trigger-only" title="Drug Allergy Notes"><span>DA</span></div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-content-only">
         <p class="font-weight-bold m-0 font-size-14 text-info">Drug Allergy Notes</p>
         <div class="mt-3 ml-3">
             {!! $dam !!}
@@ -61,8 +79,8 @@ $hasMRVData = false;
 
 @if(!!$ddi)
     <?php $hasMRVData = true; ?>
-    <div class="mrv-badge mt-2 align-self-center on-hover-hide mx-auto" title="Drug-Drug Interaction Notes"><span>DI</span></div>
-    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-hover-only">
+    <div class="mrv-badge ml-1 align-self-center on-trigger-only" title="Drug-Drug Interaction Notes"><span>DI</span></div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-content-only">
         <p class="font-weight-bold m-0 font-size-14 text-info">Drug-Drug Interaction Notes</p>
         <div class="mt-3 ml-3">
             {!! $ddi !!}
@@ -72,8 +90,8 @@ $hasMRVData = false;
 
 @if(count($sideeffects))
     <?php $hasMRVData = true; ?>
-    <div class="mrv-badge mt-2 align-self-center on-hover-hide mx-auto" title="Side Effects"><span>SE</span></div>
-    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-hover-only">
+    <div class="mrv-badge ml-1 align-self-center on-trigger-only" title="Side Effects"><span>SE</span></div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-content-only">
         <p class="font-weight-bold m-0 font-size-14 text-info">Side Effects</p>
         @foreach($sideeffects as $drug => $sideeffect)
             <div class="mt-3 ml-3">
@@ -90,8 +108,8 @@ $hasMRVData = false;
 
 @if(count($contraindications))
     <?php $hasMRVData = true; ?>
-    <div class="mrv-badge mt-2 align-self-center on-hover-hide mx-auto" title="Contraindications"><span>CI</span></div>
-    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-hover-only">
+    <div class="mrv-badge ml-1 align-self-center on-trigger-only" title="Contraindications"><span>CI</span></div>
+    <div class="p-3 mb-3 mt-2 border bg-white mr-0 on-content-only">
         <p class="font-weight-bold m-0 font-size-14 text-info">Contraindications</p>
         @foreach($contraindications as $drug => $contraindication)
             <div class="mt-3 ml-3">

+ 17 - 68
resources/views/app/patient/segment-templates/plan_allergies/edit.blade.php

@@ -12,16 +12,6 @@ use \App\Models\Segment;
 $allergies = Point::getPlanPointsOfCategory($patient, 'ALLERGY', $note);
 $intakeOrVisit = 'PLAN';
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'ALLERGIES_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,16 +22,18 @@ else {
                 <th class="border-bottom-0">Allergy</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Plan Today</th>
             </tr>
             </thead>
             <?php foreach($allergies as $allergy): ?>
                 <?php $point = $allergy; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$allergy->uid}}" {{in_array($allergy->uid, $relevance) ? 'checked' : ''}}>
+                                   data-point-uid="{{$point->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                             <span>&nbsp;</span>
                         </label>
                     </td>
@@ -117,34 +109,26 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Plan log<?= !!@($allergy->data->name) ? ' for ' . @($allergy->data->name) : '' ?>"
-                               href="/point/plan-log/<?= $allergy->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Plan log<?= !!@($allergy->data->name) ? ' for ' . @($allergy->data->name) : '' ?>"
+                                   href="/point/plan-log/<?= $allergy->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="ALLERGIES_RELEVANT_TO_NOTE_DURING_VISIT">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new allergy, added during this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1 w-100">
@@ -174,7 +158,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -194,39 +177,5 @@ else {
                 _input.closest('form').find('input[data-name="damConceptIdType"]').val(_data.dam_concept_id_typ);
             });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 4 - 14
resources/views/app/patient/segment-templates/plan_allergies/summary.blade.php

@@ -6,17 +6,6 @@ use App\Models\Point;
 
 $allergies = Point::getPlanPointsOfCategory($patient, 'ALLERGY', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'ALLERGIES_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 ?>
 
@@ -25,9 +14,10 @@ $numRelevant = 0;
 <?php else: ?>
     <?php foreach ($allergies as $allergy): ?>
         <?php if($allergy->is_removed && $allergy->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $allergy->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($allergy->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -57,8 +47,8 @@ $numRelevant = 0;
                 <div class="text-secondary font-weight-bold">Plan</div>
                 <div>{!! $review->data->value !!}</div>
             </div>
-            <?php elseif(in_array($allergy->uid, $relevance)): ?>
-            <div class="relevant-without-plan text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+            <?php elseif($rel): ?>
+            <div class="relevant-without-plan text-danger text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>

+ 17 - 68
resources/views/app/patient/segment-templates/plan_care_team/edit.blade.php

@@ -12,16 +12,6 @@ use \App\Models\Segment;
 $careTeamMembers = Point::getPlanPointsOfCategory($patient, 'CARE_TEAM_MEMBER', $note);
 $intakeOrVisit = 'PLAN';
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'CARE_TEAM_MEMBERS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,16 +22,18 @@ else {
                 <th class="border-bottom-0">Care Team Member</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Plan Today</th>
             </tr>
             </thead>
             <?php foreach($careTeamMembers as $careTeamMember): ?>
                 <?php $point = $careTeamMember; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$careTeamMember->uid}}" {{in_array($careTeamMember->uid, $relevance) ? 'checked' : ''}}>
+                                   data-point-uid="{{$point->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                             <span>&nbsp;</span>
                         </label>
                     </td>
@@ -139,34 +131,26 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Plan log<?= !!@($careTeamMember->data->name) ? ' for ' . @($careTeamMember->data->name) : '' ?>"
-                               href="/point/plan-log/<?= $careTeamMember->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Plan log<?= !!@($careTeamMember->data->name) ? ' for ' . @($careTeamMember->data->name) : '' ?>"
+                                   href="/point/plan-log/<?= $careTeamMember->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="CARE_TEAM_MEMBERS_RELEVANT_TO_NOTE_DURING_VISIT">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new care team member, added during this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1 w-100">
@@ -211,7 +195,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -225,39 +208,5 @@ else {
 
         let parentSegment = $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] ');
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 4 - 14
resources/views/app/patient/segment-templates/plan_care_team/summary.blade.php

@@ -6,17 +6,6 @@ use App\Models\Point;
 
 $careTeamMembers = Point::getPlanPointsOfCategory($patient, 'CARE_TEAM_MEMBER', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'CARE_TEAM_MEMBERS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 ?>
 
@@ -25,9 +14,10 @@ $numRelevant = 0;
 <?php else: ?>
     <?php foreach($careTeamMembers as $careTeamMember): ?>
         <?php if($careTeamMember->is_removed && $careTeamMember->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $careTeamMember->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($careTeamMember->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -61,8 +51,8 @@ $numRelevant = 0;
                 <div class="text-secondary font-weight-bold">Plan</div>
                 <div>{!! $review->data->value !!}</div>
             </div>
-            <?php elseif(in_array($careTeamMember->uid, $relevance)): ?>
-            <div class="relevant-without-plan text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+            <?php elseif($rel): ?>
+            <div class="relevant-without-plan text-danger text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>

+ 17 - 75
resources/views/app/patient/segment-templates/plan_goals/edit.blade.php

@@ -12,16 +12,6 @@ use \App\Models\Segment;
 $goals = Point::getPlanPointsOfCategory($patient, 'GOAL', $note);
 $intakeOrVisit = 'PLAN';
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'GOALS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -33,18 +23,20 @@ else {
                 <th class="border-bottom-0">Goal</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Plan Today</th>
             </tr>
             </thead>
             <?php $previousCategory = null; ?>
             <?php foreach($goals as $goal): ?>
                 <?php if(@($goal->data->category)): ?>
                 <?php $point = $goal; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$goal->uid}}" {{in_array($goal->uid, $relevance) ? 'checked' : ''}}>
+                                   data-point-uid="{{$point->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                             <span>&nbsp;</span>
                         </label>
                     </td>
@@ -192,21 +184,21 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Plan log<?= !!@($goal->data->name) ? ' for ' . @($goal->data->name) : '' ?>"
-                               href="/point/plan-log/<?= $goal->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Plan log<?= !!@($goal->data->name) ? ' for ' . @($goal->data->name) : '' ?>"
+                                   href="/point/plan-log/<?= $goal->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
-                        ?>
-                    </td>
                 </tr>
                 <?php $previousCategory = $goal->data->category; ?>
                 <?php endif; ?>
@@ -214,14 +206,6 @@ else {
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="GOALS_RELEVANT_TO_NOTE_DURING_VISIT">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new goal, added during this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1 w-100">
@@ -312,7 +296,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -326,46 +309,5 @@ else {
 
         let parentSegment = $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] ');
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        parentSegment.find('select[data-name="category"]')
-            .off('change')
-            .on('change', function() {
-                $(this).closest('form').find('.help-text').addClass('d-none');
-                $(this).closest('form').find('.help-text[data-category="' + this.value + '"]').removeClass('d-none');
-            });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 4 - 14
resources/views/app/patient/segment-templates/plan_goals/summary.blade.php

@@ -16,17 +16,6 @@ foreach($goals as $goal) {
     $grouped[$goal->data->category][] = $goal;
 }
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'GOALS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 ?>
 
@@ -36,9 +25,10 @@ $numRelevant = 0;
     <?php foreach($grouped as $k => $group): ?>
         <b><?= $k ?></b>
         <?php foreach ($group as $goal): ?>
+            <?php $rel = $goal->relevanceToNote($note); ?>
             <div class="pl-2 mb-2">
                 <div class="d-flex align-items-baseline">
-                    @if(in_array($goal->uid, $relevance))
+                    @if($rel)
                         <span class="text-info mr-1">
                             <i class="fa fa-star"></i>
                         </span>
@@ -67,8 +57,8 @@ $numRelevant = 0;
                     <div class="text-secondary font-weight-bold">Plan</div>
                     <div>{!! $review->data->value !!}</div>
                 </div>
-                <?php elseif(in_array($goal->uid, $relevance)): ?>
-                <div class="relevant-without-plan text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+                <?php elseif($rel): ?>
+                <div class="relevant-without-plan text-danger text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
                 <?php endif; ?>
             </div>
         <?php endforeach; ?>

+ 1 - 54
resources/views/app/patient/segment-templates/plan_interventions/edit.blade.php

@@ -12,16 +12,6 @@ use \App\Models\Segment;
 $interventions = Point::getPlanPointsOfCategory($patient, 'INTERVENTION', $note);
 $intakeOrVisit = 'PLAN';
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'INTERVENTIONS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -33,7 +23,6 @@ else {
                 <th class="border-bottom-0">Intervention</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Plan Today</th>
             </tr>
             </thead>
             <?php $previousCategory = null; ?>
@@ -43,7 +32,7 @@ else {
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$intervention->uid}}" {{in_array($intervention->uid, $relevance) ? 'checked' : ''}}>
+                                   data-uid="{{$intervention->uid}}" {{$rel ? 'checked' : ''}}>
                             <span>&nbsp;</span>
                         </label>
                     </td>
@@ -161,14 +150,6 @@ else {
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="INTERVENTIONS_RELEVANT_TO_NOTE_DURING_VISIT">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="max-width-500px">
             <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new intervention, added during this visit</a>
             <form url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1">
@@ -220,39 +201,5 @@ else {
 
         let parentSegment = $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] ');
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 1 - 12
resources/views/app/patient/segment-templates/plan_interventions/summary.blade.php

@@ -16,17 +16,6 @@ foreach($interventions as $intervention) {
     $grouped[$intervention->data->category][] = $intervention;
 }
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'INTERVENTIONS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 ?>
 
@@ -38,7 +27,7 @@ $numRelevant = 0;
         <?php foreach($group as $intervention): ?>
             <div class="mb-2 pl-3">
                 <div class="d-flex align-items-baseline">
-                    @if(in_array($intervention->uid, $relevance))
+                    @if($rel)
                         <span class="text-info mr-1">
                             <i class="fa fa-star"></i>
                         </span>

+ 17 - 69
resources/views/app/patient/segment-templates/plan_medications/edit.blade.php

@@ -12,16 +12,6 @@ use App\Models\Segment;
 $medications = Point::getPlanPointsOfCategory($patient, 'MEDICATION', $note);
 $intakeOrVisit = 'PLAN';
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'MEDICATIONS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,16 +22,18 @@ else {
                 <th class="border-bottom-0">Medication</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Plan Today</th>
             </tr>
             </thead>
             <?php foreach($medications as $medication): ?>
                 <?php $point = $medication; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
                 <tr>
                     <td class="p-0">
                         <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                             <input type="checkbox" class="m-0 chk-relevance"
-                                   data-uid="{{$medication->uid}}" {{in_array($medication->uid, $relevance) ? 'checked' : ''}}>
+                                   data-point-uid="{{$point->uid}}"
+                                   data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                    {{$rel ? 'checked' : ''}}>
                             <span>&nbsp;</span>
                         </label>
                     </td>
@@ -131,34 +123,26 @@ else {
                                 include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
                                 ?>
                             </div>
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Plan log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
-                               href="/point/plan-log/<?= $medication->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
+                            <div class="d-inline-flex flex-nowrap">
+                                <a class="px-2 view-review-log"
+                                   native target="_blank"
+                                   open-in-stag-popup
+                                   popup-style="stag-popup-md"
+                                   title="Plan log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
+                                   href="/point/plan-log/<?= $medication->uid ?>?popupmode=1">
+                                    <i class="fa fa-history"></i>
+                                </a>
+                                <?php
+                                include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
+                                ?>
+                            </div>
                         </div>
                     </td>
-                    <td>
-                        <?php
-                        include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
-                        ?>
-                    </td>
                 </tr>
             <?php endforeach; ?>
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="MEDICATIONS_RELEVANT_TO_NOTE_DURING_VISIT">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new medication, prescribed during this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1 w-100">
@@ -201,7 +185,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -236,40 +219,5 @@ else {
                 return false;
             });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
     };
 </script>

+ 4 - 14
resources/views/app/patient/segment-templates/plan_medications/summary.blade.php

@@ -6,17 +6,6 @@ use App\Models\Point;
 
 $medications = Point::getPlanPointsOfCategory($patient, 'MEDICATION', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'MEDICATIONS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
 ?>
 
@@ -25,9 +14,10 @@ $numRelevant = 0;
 <?php else: ?>
     <?php foreach ($medications as $medication): ?>
         <?php if($medication->is_removed && $medication->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $medication->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($medication->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
@@ -57,8 +47,8 @@ $numRelevant = 0;
                 <div class="text-secondary font-weight-bold">Plan</div>
                 <div>{!! $review->data->value !!}</div>
             </div>
-            <?php elseif(in_array($medication->uid, $relevance)): ?>
-            <div class="relevant-without-plan text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+            <?php elseif($rel): ?>
+            <div class="relevant-without-plan text-danger text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>

+ 17 - 68
resources/views/app/patient/segment-templates/plan_problems/edit.blade.php

@@ -12,16 +12,6 @@ use \App\Models\Segment;
 $problems = Point::getPlanPointsOfCategory($patient, 'PROBLEM', $note);
 $intakeOrVisit = 'PLAN';
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'PROBLEMS_RELEVANT_TO_NOTE_DURING_VISIT')
-    ->orderBy('id', 'DESC')->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 ?>
 <div>
 
@@ -32,16 +22,18 @@ else {
                 <th class="border-bottom-0">Problem</th>
                 <th class="border-bottom-0">Most Recent Review</th>
                 <th class="border-bottom-0">Most Recent Plan</th>
-                <th class="border-bottom-0">Plan Today</th>
             </tr>
             </thead>
             <?php foreach($problems as $problem): ?>
                 <?php $point = $problem; ?>
+                <?php $rel = $point->relevanceToNote($note); ?>
             <tr>
                 <td class="p-0">
                     <label class="d-flex align-items-center px-2 py-1 m-0 c-pointer">
                         <input type="checkbox" class="m-0 chk-relevance"
-                               data-uid="{{$problem->uid}}" {{in_array($problem->uid, $relevance) ? 'checked' : ''}}>
+                               data-point-uid="{{$point->uid}}"
+                               data-rel-uid="{{$rel ? $rel->uid : ''}}"
+                                {{$rel ? 'checked' : ''}}>
                         <span>&nbsp;</span>
                     </label>
                 </td>
@@ -127,34 +119,26 @@ else {
                             include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
                             ?>
                         </div>
-                        <a class="px-2 view-review-log"
-                           native target="_blank"
-                           open-in-stag-popup
-                           popup-style="stag-popup-md"
-                           title="Plan log<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?>"
-                           href="/point/plan-log/<?= $problem->uid ?>?popupmode=1">
-                            <i class="fa fa-history"></i>
-                        </a>
+                        <div class="d-inline-flex flex-nowrap">
+                            <a class="px-2 view-review-log"
+                               native target="_blank"
+                               open-in-stag-popup
+                               popup-style="stag-popup-md"
+                               title="Plan log<?= !!@($problem->data->name) ? ' for ' . @($problem->data->name) : '' ?>"
+                               href="/point/plan-log/<?= $problem->uid ?>?popupmode=1">
+                                <i class="fa fa-history"></i>
+                            </a>
+                            <?php
+                            include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
+                            ?>
+                        </div>
                     </div>
                 </td>
-                <td>
-                    <?php
-                    include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
-                    ?>
-                </td>
             </tr>
             <?php endforeach; ?>
         </table>
 
     <div class="d-flex align-items-center">
-        <div visit-moe>
-            <form start show url="/api/visitPoint/upsertNoteSingleton" class="d-none" id="<?= $segment->uid ?>-relevance-form">
-                <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
-                <input type="hidden" name="category" value="PROBLEMS_RELEVANT_TO_NOTE_DURING_VISIT">
-                <input type="hidden" name="data">
-                <button submit class="btn btn-sm btn-info font-weight-bold">Save Relevance</button>
-            </form>
-        </div>
         <div visit-moe large class="mt-1 w-100 border p-2 bg-white rounded">
             <!--<a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add new problem, added during this visit</a>-->
             <form show url="/api/visitPoint/addTopLevelDuringVisit" class="mcp-theme-1 w-100">
@@ -193,7 +177,6 @@ else {
 
                 <div>
                     <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
-                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                 </div>
             </form>
         </div>
@@ -237,39 +220,5 @@ else {
             $(this).closest('form').find('input[data-name="icd-type"]').val($(this).find('option:selected').attr('data-icd-type'));
         });
 
-        // relevance
-        $(document).off('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance');
-        $(document).on('change', '[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance', function () {
-            let uids = $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val();
-            if(!!uids) {
-                uids = JSON.parse(uids);
-            }
-            else {
-                uids = [];
-            }
-            let uid = $(this).attr('data-uid'), found = uids.indexOf(uid) > -1;
-            if(this.checked === found) {
-                return false;
-            }
-            if(this.checked) {
-                uids.push(uid);
-            }
-            else {
-                uids = uids.filter(_x => _x !== uid);
-            }
-            $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
-
-            // auto save
-            $('#<?= $segment->uid ?>-relevance-form [submit]').trigger('click');
-
-            return false;
-        });
-
-        // pre-fill relevance data
-        let uids = [];
-        $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] .chk-relevance:checked').each(function() {
-            uids.push($(this).attr('data-uid'));
-        });
-        $('#<?= $segment->uid ?>-relevance-form').find('[name="data"]').val(JSON.stringify(uids));
     };
 </script>

+ 14 - 14
resources/views/app/patient/segment-templates/plan_problems/summary.blade.php

@@ -6,17 +6,8 @@ use App\Models\Point;
 
 $problems = Point::getPlanPointsOfCategory($patient, 'PROBLEM', $note);
 
-$relevance = Point::where('added_in_segment_id', $segment->id)
-    ->where('category', 'PROBLEMS_RELEVANT_TO_NOTE_DURING_VISIT')->orderBy('id', 'DESC')
-    ->first();
-if (!!@$relevance->data) {
-    $relevance = json_decode($relevance->data, true);
-}
-else {
-    $relevance = [];
-}
-
 $numRelevant = 0;
+$numRelevantWithICD = 0;
 ?>
 
 <?php if (!count($problems)): ?>
@@ -24,15 +15,19 @@ $numRelevant = 0;
 <?php else: ?>
     <?php foreach ($problems as $problem): ?>
         <?php if($problem->is_removed && $problem->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $problem->relevanceToNote($note); ?>
         <div class="mb-2">
             <div class="d-flex align-items-baseline">
-                @if(in_array($problem->uid, $relevance))
+                @if($rel)
                     <span class="text-info mr-1">
                         <i class="fa fa-star"></i>
                     </span>
                     <?php $numRelevant++; ?>
+                    @if(!!@($problem->data->icd) && !$problem->is_removed)
+                        <?php $numRelevantWithICD++; ?>
+                    @endif
                 @endif
-                <div class="<?= $problem->is_removed ? 'strike-through' : '' ?> <?= !in_array($problem->uid, $relevance) ? 'on-hover-opaque' : '' ?>">
+                <div class="<?= $problem->is_removed ? 'strike-through' : '' ?> <?= !$rel ? 'on-hover-opaque' : '' ?>">
                     <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
                     <?= !!@($problem->data->icd) ? '/&nbsp;' . @($problem->data->icd) : '' ?>
                     <?= !!@($problem->data->description) ? '/&nbsp;' . @($problem->data->description) : '' ?>
@@ -57,8 +52,10 @@ $numRelevant = 0;
                 <div class="text-secondary font-weight-bold">Plan</div>
                 <div>{!! $review->data->value !!}</div>
             </div>
-            <?php elseif(in_array($problem->uid, $relevance)): ?>
-            <div class="relevant-without-plan text-danger mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+            <?php elseif($rel && !$problem->is_removed): ?>
+            <div class="relevant-without-plan block-signing text-danger text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>">
+                <i class="fa fa-exclamation-triangle mr-1"></i>Plan missing
+            </div>
             <?php endif; ?>
         </div>
     <?php endforeach; ?>
@@ -68,5 +65,8 @@ $numRelevant = 0;
             <span class="text-sm">Problems relevant to this note</span>
         </div>
     @endif
+    @if(!$numRelevantWithICD)
+        <div class="no-relevant-with-icd block-signing text-danger mt-1 text-sm" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Need at least 1 relevant problem with an ICD before the note can be signed</div>
+    @endif
 <?php endif; ?>
 

+ 185 - 315
resources/views/layouts/patient.blade.php

@@ -514,321 +514,191 @@
 														<div class="mb-2">
 															<label class="text-secondary text-sm">Remove Physician Pro</label>
 
-														</div>
-														<div>
-															<button submit class="btn btn-sm btn-primary mr-1">Submit
-															</button>
-															<button cancel class="btn btn-sm btn-default border">
-																Cancel
-															</button>
-														</div>
-													</form>
-												</div>
-												@endif
-											@endif
-										</div>
-										<div>
-											<label>Nurse:</label> {{$patient->defaultNaPro ? $patient->defaultNaPro->displayName() : '-' }}
-											@if($pro->pro_type == 'ADMIN')
-												<div moe class="ml-2 hide-inside-popup">
-													<a start show><i class="fa fa-edit"></i></a>
-													<form url="/api/client/putDefaultNaPro" class="mcp-theme-1">
-														<input type="hidden" name="uid" value="{{$patient->uid}}">
-														<div class="mb-2">
-															<label class="text-secondary text-sm">Nurse Pro</label>
-															<select provider-search data-pro-uid="{{ @$patient->defaultNaPro->uid }}"
-																	name="defaultNaProUid"
-																	class="form-control form-control-sm">
-																<option value=""> --select--</option>
-																@foreach($pros as $iPro) <?php continue; ?>
-																	<option
-																		value="{{$iPro->uid}}" {{ $patient->defaultNaPro && $iPro->uid === $patient->defaultNaPro->uid ? 'selected' : '' }}>{{$iPro->displayName()}}</option>
-																@endforeach
-															</select>
-														</div>
-														<div>
-															<button submit class="btn btn-sm btn-primary mr-1">Submit
-															</button>
-															<button cancel class="btn btn-sm btn-default border">
-																Cancel
-															</button>
-														</div>
-													</form>
-												</div>
-												@if($patient->defaultNaPro)
-													<div moe class="ml-2 hide-inside-popup">
-														<a start show><i class="fa fa-times"></i></a>
-														<form url="/api/client/removeDefaultNaPro" class="mcp-theme-1">
-															<input type="hidden" name="uid" value="{{$patient->uid}}">
-															<div class="mb-2">
-																<label class="text-secondary text-sm">Remove Nurse Pro</label>
-
-															</div>
-															<div>
-																<button submit class="btn btn-sm btn-primary mr-1">Submit
-																</button>
-																<button cancel class="btn btn-sm btn-default border">
-																	Cancel
-																</button>
-															</div>
-														</form>
-													</div>
-												@endif
-											@endif
-										</div>
-										</div>
-									</section>
-									{{--<section>
-										<div>
-											<label>Next Appt:</label>
-											<?php
-											$nextAppointment = $patient->nextMcpAppointment();
-											$startTime = false;
-											$endTime = false;
-											if($nextAppointment) {
-												$startTime = date('H:i', strtotime($nextAppointment->start_time));
-												$endTime = date('H:i', strtotime($nextAppointment->end_time));
-												$nextAppointment = date('Y-m-d', strtotime($nextAppointment->start_time));
-											}
-											?>
-											{{$nextAppointment ? friendly_date_time($nextAppointment . ($startTime ? ' ' . $startTime : ''), true, '') : '-'}}
-											<span moe relative class="ml-1">
-												<a start show><i class="fa fa-edit"></i></a>
-												<form url="/api/appointment/create" class="mcp-theme-1" right>
-													<input type="hidden" name="clientUid" value="{{$patient->uid}}">
-													<input type="hidden" name="title" value="MCP Appointment">
-													<div class="mb-2">
-														<label class="text-secondary text-sm">Pro</label>
-														<select name="proUid" class="form-control form-control-sm">
-															<option value=""> --select-- </option>
-															@foreach($pros as $iPro)
-																<option value="{{$iPro->uid}}" {{ $iPro->uid === $pro->uid ? 'selected' : '' }}>{{$iPro->displayName()}}</option>
-															@endforeach
-														</select>
-													</div>
-													<div class="mb-2">
-														<label class="text-secondary text-sm">Date</label>
-														<input type="date" name="date" min="{{ date('Y-m-d') }}"
-															   value="{{ $nextAppointment ? $nextAppointment : date('Y-m-d') }}"
-															   class="form-control form-control-sm">
-													</div>
-													<div class="mb-2">
-														<label class="text-secondary text-sm">Start Time</label>
-														<input type="time" name="startTime" class="form-control form-control-sm"
-															   value="{{ $startTime ? $startTime : '' }}">
-													</div>
-													<div class="mb-2">
-														<label class="text-secondary text-sm">End Time</label>
-														<input type="time" name="endTime" class="form-control form-control-sm"
-															   value="{{ $endTime ? $endTime : '' }}">
-													</div>
-													<div>
-														<button submit class="btn btn-sm btn-primary mr-1">Submit</button>
-														<button cancel class="btn btn-sm btn-default border">Cancel</button>
-													</div>
-												</form>
-											</span>
-										</div>
-										<div>
-											<label>CM:</label> {{ $patient->is_enrolled_in_cm === 'YES' ? 'Yes' : 'No' }}
-											<label class="ml-2">RM:</label> {{ $patient->is_enrolled_in_rm === 'YES' ? 'Yes' : 'No' }}
-										</div>
-									</section>--}}
-									<section class="hide-inside-popup screen-only vbox mt-2 align-self-start ml-4">
-										{{--
-										<div moe>
-											<button start show><i class="fa fa-plus text-sm text-secondary"></i>&nbsp;Note
-											</button>
-											<form url="/api/note/createUsingTemplate"
-												  redir="/patients/view/{{$patient->uid}}/notes/view/[data]"
-												  class="mcp-theme-1">
-												<input type="hidden" name="clientUid" value="{{$patient->uid}}">
-												@if($pro->is_hcp)
-												<input type="hidden" name="hcpProUid" value="{{$pro->uid}}">
-												@else
-												<input type="hidden" name="naProUid" value="{{$pro->uid}}">
-												@endif
-												<input type="hidden" name="effectiveDateEST" value="{{date("Y-m-d")}}">
-												<input type="hidden" name="effectiveTime" value="{{date("h:i")}}">
-												<input type="hidden" name="title" id="note-create-title" value="">
-												<div class="form-group mb-2">
-													<label for="" class="text-secondary text-sm mb-1">Note Template *</label>
-													<select name="noteTemplateUid" class="form-control form-control-sm"
-															onchange="$('#note-create-title').val($(this).find('option:selected').text())"
-															required>
-														<option value=""> --select--</option>
-														@foreach($pro->noteTemplates as $noteTemplate)
-															<?php $nT = $noteTemplate->template(); ?>
-															<option value="{{$nT->uid}}">{{$nT->title}}</option>
-														@endforeach
-													</select>
-												</div>
-												<div class="mb-2">
-													<label for="" class="text-secondary text-sm mb-1">Method *</label>
-													<select name="method" class="form-control form-control-sm note-method-select" required>
-														<option value="AUDIO">Audio</option>
-														<option value="VIDEO">Video</option>
-														<option value="IN_CLINIC">In-Clinic</option>
-														<option value="HOUSE_CALL">House Call</option>
-													</select>
-												</div>
-												<div class="form-group if-in-clinic">
-													<label for="" class="text-secondary text-sm mb-1">Location</label>
-													<select name="hcpCompanyLocationUid" class="form-control">
-														<option value=""></option>
-														@foreach($pro->companyLocations() as $location)
-															<option value="{{$location->uid}}">{{$location->line1}} {{$location->city}}</option>
-														@endforeach
-													</select>
-												</div>
-												<div class="form-group m-0">
-													<button submit class="btn btn-primary btn-sm">submit</button>
-												</div>
-											</form>
-										</div> --}}
-										<div>
-											<div moe relative>
-												<button start show><i class="fa fa-plus text-sm text-secondary"></i>&nbsp;SMS
-												</button>
-												<form url="/api/clientSms/createOutgoing" right class="mcp-theme-1">
-													<input type="hidden" name="uid" value="{{ $patient->uid }}">
-													<div class="mb-2">
-														<label for="" class="text-sm text-secondary mb-1">Cell
-															Number</label>
-														<input type="text" class="form-control form-control-sm"
-															   name="cellNumber" value="{{$patient->cell_number}}">
-													</div>
-													<div class="mb-2">
-														<label for=""
-															   class="text-sm text-secondary mb-1">Message</label>
-														<textarea type="text" class="form-control form-control-sm"
-																  name="message"></textarea>
-													</div>
-													<div class="d-flex align-items-center">
-														<button class="btn btn-sm btn-primary mr-2" submit>Send</button>
-														<button class="btn btn-sm btn-default mr-2 border" cancel>
-															Cancel
-														</button>
-													</div>
-												</form>
-											</div>
-										</div>
-										<div>
-										<span moe relative class="">
-											<button start show title="SMS check-in link to the patient">Send&nbsp;<i
-													class="on-hover-opaque fa fa-paper-plane text-secondary"></i></button>
-											<form url="/api/client/sendCheckInTokenViaSmsOrEmail" right
-												  class="mcp-theme-1">
-												<input type="hidden" name="uid" value="{{ $patient->uid }}">
-												<p class="small min-width-200px mb-2">Send Check-In link to patient?</p>
-												<div class="mb-2">
-													<label for=""
-														   class="text-sm text-secondary mb-1">Cell Number</label>
-													<input type="text" class="form-control input-sm" name="cellNumber"
-														   value="{{$patient->cell_number}}">
-												</div>
-												<div class="mb-2">
-													<label for=""
-														   class="text-sm text-secondary mb-1">Email address</label>
-													<input type="text" class="form-control input-sm" name="emailAddress"
-														   value="{{$patient->email_address}}">
-												</div>
-												<div class="d-flex align-items-center">
-													<button class="btn btn-sm btn-primary mr-2" submit>Send</button>
-													<button class="btn btn-sm btn-default mr-2 border"
-															cancel>Cancel</button>
-												</div>
-											</form>
-										</span>
-										</div>
-									</section>
-									<section class="hide-inside-popup screen-only vbox mt-2 align-self-start ml-1">
-										@if($performer->pro->pro_type == 'ADMIN')
-										<div>
-											<button class="col-2-button" onclick="return openInRHS('/pro/check-video/{{ $patient->uid }}')">Check Video</button>
-										</div>
-										@endif
-										<div>
-											<button class="col-2-button" onclick="return openInRHS('/pro/meet/{{ $patient->uid }}')">Join Video</button>
-										</div>
-										{{--
-										<div class="">
-											@if($pro->isWorkingOnClient($patient))
-												<div moe>
-													<form url="/api/proClientWork/KillRunningWorkForSelf"
-														  class="mcp-theme-1" show>
-														<input type="hidden" name="uid" value="{{$patient->uid}}">
-														<div>
-															<button class="col-2-button" submit><i class="fa fa-stop text-secondary"></i>&nbsp;Work:
-																Stop
-															</button>
-														</div>
-													</form>
-												</div>
-											@else
-												<div moe>
-													<form url="/api/proClientWork/create" class="mcp-theme-1" show>
-														<input type="hidden" name="clientUid" value="{{$patient->uid}}">
-														<div>
-															<button class="col-2-button" submit><i class="fa fa-play text-secondary"></i>&nbsp;Work:
-																Start
-															</button>
-														</div>
-													</form>
-												</div>
-											@endif
-										</div>
-										--}}
-										<div class="mr-auto">
-											@if($pro->isWorkingOnClient($patient))
-												<div class="d-flex align-items-center">
-													@if($patient->active_mcp_request_id)
-														{{-- kill mcp request for client --}}
-														<div moe relative class="">
-															<button href="" start show class="col-2-button"><i
-																	class="fa fa-times text-danger"></i>&nbsp;MCP Req.
-															</button>
-															<form url="/api/mcpRequest/kill" class="mcp-theme-1" right>
-																<input type="hidden" name="clientUid"
-																	   value="{{$patient->uid}}">
-																<p>Kill the MCP Request for this patient?</p>
-																<div>
-																	<button submit class="btn btn-sm btn-primary mr-2">
-																		Yes
-																	</button>
-																	<button cancel
-																			class="btn btn-sm btn-default border">Cancel
-																	</button>
-																</div>
-															</form>
-														</div>
-													@else
-														{{-- create mcp request for client --}}
-														<div moe relative class="">
-															<button href="" start show class="col-2-button"><i
-																	class="fa fa-plus text-sm text-secondary"></i>&nbsp;MCP
-																Req.
-															</button>
-															<form url="/api/mcpRequest/createAsPro" class="mcp-theme-1"
-																  right>
-																<p>Create an MCP Request for this patient?</p>
-																<div>
-																	<button submit class="btn btn-sm btn-primary mr-2">
-																		Yes
-																	</button>
-																	<button cancel
-																			class="btn btn-sm btn-default border">Cancel
-																	</button>
-																</div>
-															</form>
-														</div>
-													@endif
-												</div>
-											@endif
-										</div>
-									</section>
-
-                                    <section>
+                                                            </div>
+                                                            <div>
+                                                                <button submit class="btn btn-sm btn-primary mr-1">Submit
+                                                                </button>
+                                                                <button cancel class="btn btn-sm btn-default border">
+                                                                    Cancel
+                                                                </button>
+                                                            </div>
+                                                        </form>
+                                                    </div>
+                                                @endif
+                                            @endif
+                                        </div>
+                                        </div>
+                                    </section>
+                                    {{--<section>
+                                        <div>
+                                            <label>Next Appt:</label>
+                                            <?php
+                                            $nextAppointment = $patient->nextMcpAppointment();
+                                            $startTime = false;
+                                            $endTime = false;
+                                            if($nextAppointment) {
+                                                $startTime = date('H:i', strtotime($nextAppointment->start_time));
+                                                $endTime = date('H:i', strtotime($nextAppointment->end_time));
+                                                $nextAppointment = date('Y-m-d', strtotime($nextAppointment->start_time));
+                                            }
+                                            ?>
+                                            {{$nextAppointment ? friendly_date_time($nextAppointment . ($startTime ? ' ' . $startTime : ''), true, '') : '-'}}
+                                            <span moe relative class="ml-1">
+                                                <a start show><i class="fa fa-edit"></i></a>
+                                                <form url="/api/appointment/create" class="mcp-theme-1" right>
+                                                    <input type="hidden" name="clientUid" value="{{$patient->uid}}">
+                                                    <input type="hidden" name="title" value="MCP Appointment">
+                                                    <div class="mb-2">
+                                                        <label class="text-secondary text-sm">Pro</label>
+                                                        <select name="proUid" class="form-control form-control-sm">
+                                                            <option value=""> --select-- </option>
+                                                            @foreach($pros as $iPro)
+                                                                <option value="{{$iPro->uid}}" {{ $iPro->uid === $pro->uid ? 'selected' : '' }}>{{$iPro->displayName()}}</option>
+                                                            @endforeach
+                                                        </select>
+                                                    </div>
+                                                    <div class="mb-2">
+                                                        <label class="text-secondary text-sm">Date</label>
+                                                        <input type="date" name="date" min="{{ date('Y-m-d') }}"
+                                                               value="{{ $nextAppointment ? $nextAppointment : date('Y-m-d') }}"
+                                                               class="form-control form-control-sm">
+                                                    </div>
+                                                    <div class="mb-2">
+                                                        <label class="text-secondary text-sm">Start Time</label>
+                                                        <input type="time" name="startTime" class="form-control form-control-sm"
+                                                               value="{{ $startTime ? $startTime : '' }}">
+                                                    </div>
+                                                    <div class="mb-2">
+                                                        <label class="text-secondary text-sm">End Time</label>
+                                                        <input type="time" name="endTime" class="form-control form-control-sm"
+                                                               value="{{ $endTime ? $endTime : '' }}">
+                                                    </div>
+                                                    <div>
+                                                        <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                                    </div>
+                                                </form>
+                                            </span>
+                                        </div>
+                                        <div>
+                                            <label>CM:</label> {{ $patient->is_enrolled_in_cm === 'YES' ? 'Yes' : 'No' }}
+                                            <label class="ml-2">RM:</label> {{ $patient->is_enrolled_in_rm === 'YES' ? 'Yes' : 'No' }}
+                                        </div>
+                                    </section>--}}
+                                    <section class="hide-inside-popup screen-only vbox mt-2 align-self-start ml-4">
+                                        
+                                        <div moe>
+                                            <button start show><i class="fa fa-plus text-sm text-secondary"></i>&nbsp;Note
+                                            </button>
+                                            <form url="/api/note/createUsingTemplate"
+                                                  redir="/patients/view/{{$patient->uid}}/notes/view/[data]"
+                                                  class="mcp-theme-1">
+                                                <input type="hidden" name="clientUid" value="{{$patient->uid}}">
+                                                @if($pro->is_hcp)
+                                                <input type="hidden" name="hcpProUid" value="{{$pro->uid}}">
+                                                @else
+                                                <input type="hidden" name="naProUid" value="{{$pro->uid}}">
+                                                @endif
+                                                <input type="hidden" name="effectiveDateEST" value="{{date("Y-m-d")}}">
+                                                <input type="hidden" name="effectiveTime" value="{{date("h:i")}}">
+                                                <input type="hidden" name="title" id="note-create-title" value="">
+                                                <div class="form-group mb-2">
+                                                    <label for="" class="text-secondary text-sm mb-1">Note Template *</label>
+                                                    <select name="noteTemplateUid" class="form-control form-control-sm"
+                                                            onchange="$('#note-create-title').val($(this).find('option:selected').text())"
+                                                            required>
+                                                        <option value=""> --select--</option>
+                                                        @foreach($pro->noteTemplates as $noteTemplate)
+                                                            <?php $nT = $noteTemplate->template(); ?>
+                                                            <option value="{{$nT->uid}}">{{$nT->title}}</option>
+                                                        @endforeach
+                                                    </select>
+                                                </div>
+                                                <div class="mb-2">
+                                                    <label for="" class="text-secondary text-sm mb-1">Method *</label>
+                                                    <select name="method" class="form-control form-control-sm note-method-select" required>
+                                                        <option value="AUDIO">Audio</option>
+                                                        <option value="VIDEO">Video</option>
+                                                        <option value="IN_CLINIC">In-Clinic</option>
+                                                        <option value="HOUSE_CALL">House Call</option>
+                                                    </select>
+                                                </div>
+                                                <div class="form-group if-in-clinic">
+                                                    <label for="" class="text-secondary text-sm mb-1">Location</label>
+                                                    <select name="hcpCompanyLocationUid" class="form-control">
+                                                        <option value=""></option>
+                                                        @foreach($pro->companyLocations() as $location)
+                                                            <option value="{{$location->uid}}">{{$location->line1}} {{$location->city}}</option>
+                                                        @endforeach
+                                                    </select>
+                                                </div>
+                                                <div class="form-group m-0">
+                                                    <button submit class="btn btn-primary btn-sm">submit</button>
+                                                </div>
+                                            </form>
+                                        </div>
+                                        <div>
+                                            <div moe relative>
+                                                <button start show><i class="fa fa-plus text-sm text-secondary"></i>&nbsp;SMS
+                                                </button>
+                                                <form url="/api/clientSms/createOutgoing" right class="mcp-theme-1">
+                                                    <input type="hidden" name="uid" value="{{ $patient->uid }}">
+                                                    <div class="mb-2">
+                                                        <label for="" class="text-sm text-secondary mb-1">Cell
+                                                            Number</label>
+                                                        <input type="text" class="form-control form-control-sm"
+                                                               name="cellNumber" value="{{$patient->cell_number}}">
+                                                    </div>
+                                                    <div class="mb-2">
+                                                        <label for=""
+                                                               class="text-sm text-secondary mb-1">Message</label>
+                                                        <textarea type="text" class="form-control form-control-sm"
+                                                                  name="message"></textarea>
+                                                    </div>
+                                                    <div class="d-flex align-items-center">
+                                                        <button class="btn btn-sm btn-primary mr-2" submit>Send</button>
+                                                        <button class="btn btn-sm btn-default mr-2 border" cancel>
+                                                            Cancel
+                                                        </button>
+                                                    </div>
+                                                </form>
+                                            </div>
+                                        </div>
+                                        <div>
+                                        <span moe relative class="">
+                                            <button start show title="SMS check-in link to the patient">Send&nbsp;<i
+                                                    class="on-hover-opaque fa fa-paper-plane text-secondary"></i></button>
+                                            <form url="/api/client/sendCheckInTokenViaSmsOrEmail" right
+                                                  class="mcp-theme-1">
+                                                <input type="hidden" name="uid" value="{{ $patient->uid }}">
+                                                <p class="small min-width-200px mb-2">Send Check-In link to patient?</p>
+                                                <div class="mb-2">
+                                                    <label for=""
+                                                           class="text-sm text-secondary mb-1">Cell Number</label>
+                                                    <input type="text" class="form-control input-sm" name="cellNumber"
+                                                           value="{{$patient->cell_number}}">
+                                                </div>
+                                                <div class="mb-2">
+                                                    <label for=""
+                                                           class="text-sm text-secondary mb-1">Email address</label>
+                                                    <input type="text" class="form-control input-sm" name="emailAddress"
+                                                           value="{{$patient->email_address}}">
+                                                </div>
+                                                <div class="d-flex align-items-center">
+                                                    <button class="btn btn-sm btn-primary mr-2" submit>Send</button>
+                                                    <button class="btn btn-sm btn-default mr-2 border"
+                                                            cancel>Cancel</button>
+                                                </div>
+                                            </form>
+                                        </span>
+                                        </div>
+                                    </section>
+                                    <section class="hide-inside-popup screen-only vbox mt-2 align-self-start ml-1">
+                                        @if($performer->pro->pro_type == 'ADMIN')
+                                        <div>
+                                            <button class="col-2-button" onclick="return openInRHS('/pro/check-video/{{ $patient->uid }}')">Check Video</button>
+                                        </div>
+                                        @endif
                                         <div>
                                             @if($pro->pro_type === 'ADMIN')
                                                 @include('app.patient.coverage-status')

+ 4 - 0
routes/web.php

@@ -318,6 +318,10 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/point/review-log/{point}', 'NoteController@reviewLog')->name('point-review-log');
     Route::get('/point/plan-log/{point}', 'NoteController@planLog')->name('point-plan-log');
     Route::get('/note/pdf/{note}', 'NoteController@downloadAsPdf')->name('note-pdf');
+    Route::get('/segment-summary/{segment}', 'NoteController@segmentSummary')->name('segment-summary');
+    Route::get('/medications-center/{patient}/{note}', 'NoteController@medicationsCenter')->name('medications-center');
+    Route::get('/problems-center/{patient}/{note}', 'NoteController@problemsCenter')->name('problems-center');
+    Route::get('/goals-center/{patient}/{note}', 'NoteController@goalsCenter')->name('goals-center');
 
     //mb claim single view
     Route::get('mb-claims/view/{mbClaim}', 'PatientController@mbClaim')->name('mb-claim');