Sfoglia il codice sorgente

Merge branch 'master' of rav.triplestart.com:jmudaka/stagfe2

root 3 anni fa
parent
commit
ebb4371fa0
100 ha cambiato i file con 5723 aggiunte e 143 eliminazioni
  1. 48 11
      app/Http/Controllers/FDBPGController.php
  2. 1 0
      app/Http/Controllers/HomeController.php
  3. 40 0
      app/Http/Controllers/NoteController.php
  4. 4 1
      app/Models/Client.php
  5. 11 0
      app/Models/Note.php
  6. 88 0
      app/Models/Point.php
  7. 10 0
      app/Models/Pro.php
  8. 22 0
      app/Models/Segment.php
  9. 11 0
      app/Models/SegmentTemplate.php
  10. 10 0
      app/Models/VisitTemplate.php
  11. 1 1
      config/app.php
  12. 347 0
      fdb_notes.txt
  13. 106 0
      public/css/style.css
  14. 191 0
      public/js/stag-suggest.js
  15. 11 0
      resources/views/app/dashboard/measurements.blade.php
  16. 42 0
      resources/views/app/patient/note/_templates-v2-index.blade.php
  17. 2147 0
      resources/views/app/patient/note/dashboard-univ.blade.php
  18. 102 103
      resources/views/app/patient/note/dashboard.blade.php
  19. 5 3
      resources/views/app/patient/note/dashboard_script.blade.php
  20. 6 0
      resources/views/app/patient/note/note-segment-list.blade.php
  21. 34 24
      resources/views/app/patient/note/section.blade.php
  22. 35 0
      resources/views/app/patient/note/segment.blade.php
  23. 228 0
      resources/views/app/patient/note/segment_script.blade.php
  24. 55 0
      resources/views/app/patient/notes.blade.php
  25. 78 0
      resources/views/app/patient/page-sections/cc/form.blade.php
  26. 23 0
      resources/views/app/patient/page-sections/cc/summary.php
  27. 121 0
      resources/views/app/patient/page-sections/rx/form.blade.php
  28. 45 0
      resources/views/app/patient/page-sections/rx/summary.php
  29. 78 0
      resources/views/app/patient/page-sections/subjective/form.blade.php
  30. 23 0
      resources/views/app/patient/page-sections/subjective/summary.php
  31. 20 0
      resources/views/app/patient/page-sections/vitals/default.php
  32. 264 0
      resources/views/app/patient/page-sections/vitals/form.blade.php
  33. 131 0
      resources/views/app/patient/page-sections/vitals/summary.php
  34. 37 0
      resources/views/app/patient/segment-templates/_child_review/edit-review.php
  35. 38 0
      resources/views/app/patient/segment-templates/_child_review/last-review.php
  36. 160 0
      resources/views/app/patient/segment-templates/_common_actions/remove-undo.php
  37. 24 0
      resources/views/app/patient/segment-templates/_simple_text_segment/edit.php
  38. 20 0
      resources/views/app/patient/segment-templates/_simple_text_segment/summary.php
  39. 4 0
      resources/views/app/patient/segment-templates/chief_complaint/edit.blade.php
  40. 3 0
      resources/views/app/patient/segment-templates/chief_complaint/summary.blade.php
  41. 1 0
      resources/views/app/patient/segment-templates/history_family/edit.blade.php
  42. 1 0
      resources/views/app/patient/segment-templates/history_family/summary.blade.php
  43. 1 0
      resources/views/app/patient/segment-templates/history_screenings/edit.blade.php
  44. 1 0
      resources/views/app/patient/segment-templates/history_screenings/summary.blade.php
  45. 267 0
      resources/views/app/patient/segment-templates/history_social/edit.blade.php
  46. 95 0
      resources/views/app/patient/segment-templates/history_social/summary.blade.php
  47. 1 0
      resources/views/app/patient/segment-templates/history_surgical/edit.blade.php
  48. 1 0
      resources/views/app/patient/segment-templates/history_surgical/summary.blade.php
  49. 87 0
      resources/views/app/patient/segment-templates/intake_allergies/edit.blade.php
  50. 48 0
      resources/views/app/patient/segment-templates/intake_allergies/summary.blade.php
  51. 1 0
      resources/views/app/patient/segment-templates/intake_care_team/edit.blade.php
  52. 1 0
      resources/views/app/patient/segment-templates/intake_care_team/summary.blade.php
  53. 87 0
      resources/views/app/patient/segment-templates/intake_goals/edit.blade.php
  54. 47 0
      resources/views/app/patient/segment-templates/intake_goals/summary.blade.php
  55. 1 0
      resources/views/app/patient/segment-templates/intake_interventions/edit.blade.php
  56. 1 0
      resources/views/app/patient/segment-templates/intake_interventions/summary.blade.php
  57. 214 0
      resources/views/app/patient/segment-templates/intake_medications/edit.blade.php
  58. 30 0
      resources/views/app/patient/segment-templates/intake_medications/summary.blade.php
  59. 95 0
      resources/views/app/patient/segment-templates/intake_problems/edit.blade.php
  60. 49 0
      resources/views/app/patient/segment-templates/intake_problems/summary.blade.php
  61. 1 0
      resources/views/app/patient/segment-templates/lifestyle_general/edit.blade.php
  62. 1 0
      resources/views/app/patient/segment-templates/lifestyle_general/summary.blade.php
  63. 1 0
      resources/views/app/patient/segment-templates/lifestyle_nutrition/edit.blade.php
  64. 1 0
      resources/views/app/patient/segment-templates/lifestyle_nutrition/summary.blade.php
  65. 1 0
      resources/views/app/patient/segment-templates/lifestyle_physical_activity/edit.blade.php
  66. 1 0
      resources/views/app/patient/segment-templates/lifestyle_physical_activity/summary.blade.php
  67. 1 0
      resources/views/app/patient/segment-templates/lifestyle_sleep/edit.blade.php
  68. 1 0
      resources/views/app/patient/segment-templates/lifestyle_sleep/summary.blade.php
  69. 1 0
      resources/views/app/patient/segment-templates/lifestyle_social/edit.blade.php
  70. 1 0
      resources/views/app/patient/segment-templates/lifestyle_social/summary.blade.php
  71. 1 0
      resources/views/app/patient/segment-templates/lifestyle_stress/edit.blade.php
  72. 1 0
      resources/views/app/patient/segment-templates/lifestyle_stress/summary.blade.php
  73. 1 0
      resources/views/app/patient/segment-templates/lifestyle_substances/edit.blade.php
  74. 1 0
      resources/views/app/patient/segment-templates/lifestyle_substances/summary.blade.php
  75. 1 0
      resources/views/app/patient/segment-templates/medrisk_vigilence/edit.blade.php
  76. 1 0
      resources/views/app/patient/segment-templates/medrisk_vigilence/summary.blade.php
  77. 1 0
      resources/views/app/patient/segment-templates/metrics/edit.blade.php
  78. 1 0
      resources/views/app/patient/segment-templates/metrics/summary.blade.php
  79. 4 0
      resources/views/app/patient/segment-templates/objective_free_text/edit.blade.php
  80. 3 0
      resources/views/app/patient/segment-templates/objective_free_text/summary.blade.php
  81. 4 0
      resources/views/app/patient/segment-templates/objective_imaging/edit.blade.php
  82. 3 0
      resources/views/app/patient/segment-templates/objective_imaging/summary.blade.php
  83. 4 0
      resources/views/app/patient/segment-templates/objective_labs/edit.blade.php
  84. 3 0
      resources/views/app/patient/segment-templates/objective_labs/summary.blade.php
  85. 4 0
      resources/views/app/patient/segment-templates/objective_measurements/edit.blade.php
  86. 3 0
      resources/views/app/patient/segment-templates/objective_measurements/summary.blade.php
  87. 4 0
      resources/views/app/patient/segment-templates/objective_other_investigations/edit.blade.php
  88. 3 0
      resources/views/app/patient/segment-templates/objective_other_investigations/summary.blade.php
  89. 1 0
      resources/views/app/patient/segment-templates/past_medical_history/edit.blade.php
  90. 1 0
      resources/views/app/patient/segment-templates/past_medical_history/summary.blade.php
  91. 1 0
      resources/views/app/patient/segment-templates/plan_allergies/edit.blade.php
  92. 1 0
      resources/views/app/patient/segment-templates/plan_allergies/summary.blade.php
  93. 1 0
      resources/views/app/patient/segment-templates/plan_care_team/edit.blade.php
  94. 1 0
      resources/views/app/patient/segment-templates/plan_care_team/summary.blade.php
  95. 4 0
      resources/views/app/patient/segment-templates/plan_free_text/edit.blade.php
  96. 3 0
      resources/views/app/patient/segment-templates/plan_free_text/summary.blade.php
  97. 1 0
      resources/views/app/patient/segment-templates/plan_goals/edit.blade.php
  98. 1 0
      resources/views/app/patient/segment-templates/plan_goals/summary.blade.php
  99. 1 0
      resources/views/app/patient/segment-templates/plan_interventions/edit.blade.php
  100. 1 0
      resources/views/app/patient/segment-templates/plan_interventions/summary.blade.php

+ 48 - 11
app/Http/Controllers/FDBPGController.php

@@ -25,6 +25,21 @@ class FDBPGController extends Controller
         return view('app.fdb-pg.fdb-med-suggest', compact('matches'));
     }
 
+    // 1.1 medication suggest (json response)
+    public function medSuggestJSON(Request $request)
+    {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        if (empty($term)) return '';
+        $matches = DB::connection('pgsql_fdb')->select(
+            "SELECT med_name_id, med_name as text FROM rminmid1_med_name WHERE med_status_cd = '0' AND med_name ILIKE :term ORDER BY med_name",
+            ['term' => '%' . $term . '%']
+        );
+        return json_encode([
+            "success" => true,
+            "data" => $matches
+        ]);
+    }
+
     // 2. routed meds from men name
     public function routedMeds(Request $request)
     {
@@ -67,8 +82,8 @@ class FDBPGController extends Controller
         $gcnSeqNo = $request->input('gcn-seq-no') ? trim($request->input('gcn-seq-no')) : '';
         if (empty($gcnSeqNo)) return '';
         $sides = DB::connection('pgsql_fdb')->select("
-SELECT r1.side, sm.side_freq, sm.side_sev, sm.dxid, dx.dxid_desc56 
-FROM rsidegc0_gcnseqno_link r1 
+SELECT r1.side, sm.side_freq, sm.side_sev, sm.dxid, dx.dxid_desc56
+FROM rsidegc0_gcnseqno_link r1
     JOIN rsidema3_mstr sm ON r1.side = sm.side
     JOIN rfmldx0_dxid dx ON sm.dxid = dx.dxid
 WHERE r1.gcn_seqno = :gcnSeqNo
@@ -86,7 +101,7 @@ ORDER BY sm.side_sev DESC, sm.side_freq ASC
         if (empty($gcnSeqNo)) return '';
         $precautions = DB::connection('pgsql_fdb')->select("
 SELECT r1.geri_code, gm.geri_sl, gm.geri_desc, gm.geri_narrative
-FROM rgerigc0_geri_gcnseqno_link r1 
+FROM rgerigc0_geri_gcnseqno_link r1
     JOIN rgerima1_geri_mstr gm ON r1.geri_code = gm.geri_code
 WHERE r1.gcn_seqno = :gcnSeqNo
 ORDER BY gm.geri_desc
@@ -103,7 +118,7 @@ ORDER BY gm.geri_desc
         if (empty($gcnSeqNo)) return '';
         $indications = DB::connection('pgsql_fdb')->select("
 SELECT r1.indcts, r2.indcts_sn, r2.indcts_lbl, r2.dxid, r2.proxy_ind, r3.dxid_desc56
-FROM rindmgc0_indcts_gcnseqno_link r1 
+FROM rindmgc0_indcts_gcnseqno_link r1
     JOIN rindmma2_indcts_mstr r2 ON r1.indcts = r2.indcts
     JOIN rfmldx0_dxid r3 ON r2.dxid = r3.dxid
 WHERE r1.gcn_seqno = :gcnSeqNo
@@ -121,7 +136,7 @@ ORDER BY r3.dxid_desc56
         if (empty($routedMedID)) return '';
         $contraindications = DB::connection('pgsql_fdb')->select("
 SELECT r1.ddxcn, r2.dxid, r2.ddxcn_sl, r3.dxid_desc56
-FROM rddcmrm0_routed_med_link r1 
+FROM rddcmrm0_routed_med_link r1
     JOIN rddcmma1_contra_mstr r2 ON r1.ddxcn = r2.ddxcn
     JOIN rfmldx0_dxid r3 ON r2.dxid = r3.dxid
 WHERE r1.routed_med_id = :routedMedID
@@ -138,7 +153,7 @@ ORDER BY r2.ddxcn_sl
         $term = $request->input('term') ? trim($request->input('term')) : '';
         if (empty($term)) return '';
         $matches = DB::connection('pgsql_fdb')->select("
-SELECT distinct(r1.dxid), r1.dxid_desc56 
+SELECT distinct(r1.dxid), r1.dxid_desc56
 FROM rfmldx0_dxid r1
 JOIN rfmlsyn0_dxid_syn r2 ON r1.dxid = r2.dxid
 WHERE (r1.dxid_desc56 ILIKE :term OR r1.dxid_desc100 ILIKE :term OR r2.dxid_syn_desc56 ILIKE :term OR r2.dxid_syn_desc100 ILIKE :term)
@@ -149,6 +164,28 @@ ORDER BY r1.dxid_desc56
         return view('app.fdb-pg.fdb-dx-suggest', compact('matches'));
     }
 
+    public function dxSuggestJSON(Request $request)
+    {
+        $term = $request->input('term') ? trim($request->input('term')) : '';
+        //sample
+        $matches = [
+             ['icd' => '384',  "text" =>"juvenile diabetes"],
+             ['icd' => '387',  "text" =>"insulin-dependent DM"],
+             ['icd' => '388',  "text" =>"insulin-dependent diabetes mellitus"],
+             ['icd' => '389',  "text" =>"ketosis-prone diabetes mellitus"],
+             ['icd' => '390',  "text" =>"ketosis-prone diabetes"],
+             ['icd' => '391',  "text" =>"juvenile-onset diabetes"],
+             ['icd' => '392',  "text" =>"juvenile-onset diabetes mellitus"],
+             ['icd' => '393',  "text" =>"juvenile onset DM"],
+             ['icd' => '394',  "text" =>"type I diabetes mellitus"],
+             ['icd' => '395',  "text" =>"diabetes mellitus type"],
+             ['icd' => '396',  "text" =>"ketosis-prone DM"],
+           ['icd' => '58331',  "text" =>"insulin dependent diabetes mellitus"],
+           ['icd' => '58407',  "text" =>"immune mediated diabetes mellitus"],
+        ];
+        return response()->json(['success'=>true, 'data'=>$matches]);
+    }
+
     // allergy suggest
     public function allergySuggest(Request $request)
     {
@@ -482,7 +519,7 @@ INTERSECT
             $ddiCodexArray = [];
             $query = DB::connection('pgsql_fdb')->select("
     SELECT r1.ddi_codex
-    FROM RADIMGC4_GCNSEQNO_LINK r1 
+    FROM RADIMGC4_GCNSEQNO_LINK r1
     WHERE r1.gcn_seqno = :gcnSeqNo
                 ",
                 ['gcnSeqNo' => $_gcnSeqNo]
@@ -514,7 +551,7 @@ INTERSECT
             $ddiCodexArray = [];
             $query = DB::connection('pgsql_fdb')->select("
     SELECT distinct r1.ddi_codex
-    FROM RDDIMIN0_NDC_INACTV_DDIM_LINK r1 
+    FROM RDDIMIN0_NDC_INACTV_DDIM_LINK r1
     WHERE r1.ddi_ndc IN (" . implode(',', array_map(function($_x) {return "'" . $_x . "'";}, $_ndc)) . ")
                 "
             );
@@ -531,7 +568,7 @@ INTERSECT
         if(count($_ddiCodexArray)) {
             $ddiCodexMonoxPairsArray = DB::connection('pgsql_fdb')->select("
 SELECT r1.ddi_codex, r1.ddi_monox
-FROM RADIMMA5_MSTR r1 
+FROM RADIMMA5_MSTR r1
 WHERE r1.ddi_codex IN (" . implode(',', array_map(function($_x) {return "'" . $_x . "'";}, $_ddiCodexArray)) . ")
             "
             );
@@ -547,7 +584,7 @@ WHERE r1.ddi_codex IN (" . implode(',', array_map(function($_x) {return "'" . $_
 
         $coadministration = DB::connection('pgsql_fdb')->select("
 SELECT distinct r1.coadmin_dosing_text
-FROM radige0_ddi_gcnseqno_except r1 
+FROM radige0_ddi_gcnseqno_except r1
 WHERE r1.side_a_gcn_seqno in ($gcnSeqnos) AND r1.side_b_gcn_seqno in ($gcnSeqnos)
             "
         );
@@ -609,7 +646,7 @@ WHERE r1.side_a_gcn_seqno in ($gcnSeqnos) AND r1.side_b_gcn_seqno in ($gcnSeqnos
         private function getDptClassFromGcnSeqNo($_gcnSeqNo) {
             return DB::connection('pgsql_fdb')->select("
     SELECT distinct r1.dpt_class_id, r2.dpt_allowance, r2.dpt_class_desc
-    FROM RDPTGC0_GCNSEQNO_LINK r1 
+    FROM RDPTGC0_GCNSEQNO_LINK r1
     JOIN RDPTCL0_CLASS_ID r2 on r1.dpt_class_id = r2.dpt_class_id
     WHERE r1.gcn_seqno = :gcnSeqNo
                 ",

+ 1 - 0
app/Http/Controllers/HomeController.php

@@ -616,6 +616,7 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
                 "
 SELECT measurement.uid as uid,
        care_month.uid as care_month_uid,
+       care_month.start_date as care_month_start_date,
        measurement.label,
        measurement.value,
        measurement.sbp_mm_hg,

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

@@ -2,18 +2,22 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\AppSession;
 use App\Models\Page;
 use App\Models\Pro;
 use App\Models\SupplyOrder;
 use App\Models\Ticket;
 use Illuminate\Http\Request;
 use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Blade;
 use Illuminate\Support\Facades\Http;
 
 use App\Models\Note;
 use App\Models\Client;
 use App\Models\Section;
 use App\Models\SectionTemplate;
+use App\Models\Segment;
+use App\Models\SegmentTemplate;
 
 class NoteController extends Controller
 {
@@ -80,6 +84,42 @@ class NoteController extends Controller
             compact('patient', 'note', 'section', 'page'));
     }
 
+    public function getHtmlForSegment($segmentUid, $sessionKey){
+
+        $performer = AppSession::where('session_key', $sessionKey)->first();
+        if(!$performer || !$performer->is_active){
+            return response()->json([
+                'success'=>false,
+                'message'=>'Invalid session key'
+            ]);
+        }
+        $pro = $performer->pro;
+
+        $segment = Segment::where('uid', $segmentUid)->first();
+        $segmentTemplate = $segment->segmentTemplate;
+
+        $note = $segment->note;
+        $patient = $note->client;
+
+        $data = compact('performer', 'pro', 'segment', 'segmentTemplate', 'note', 'patient');
+
+        //try {
+            $summaryHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/summary', $data)->render();
+            $editHtml = view('app.patient.segment-templates.' . $segmentTemplate->internal_name . '/edit', $data)->render();
+      //  } catch (\Throwable $e) {
+//            return response()->json([
+//                'success'=>false,
+//                'message'=>$e->getMessage()
+//            ]);
+       // }
+
+        return response()->json([
+            'success'=>true,
+            'summaryHtml' => $summaryHtml,
+            'editHtml' => $editHtml
+        ]);
+    }
+
     // JAVA ONLY
     // ... if hcpProId is passed, get from request
     public function getDefaultValueForSection($patientID, $sectionTemplateID)

+ 4 - 1
app/Models/Client.php

@@ -676,9 +676,12 @@ SELECT m.id   AS measurement_id,
 FROM measurement m
          JOIN care_month cm ON m.care_month_id = cm.id
 WHERE m.care_month_id = :careMonthID
+        AND m.label NOT IN ('SBP', 'DBP')
         AND m.bdt_measurement_id IS NOT NULL
-        AND m.is_cellular_zero IS FALSE
         AND m.is_removed IS FALSE
+        AND (m.is_cellular_zero = FALSE or m.is_cellular_zero IS NULL)
+        AND m.ts IS NOT NULL
+        AND m.client_bdt_measurement_id IS NOT NULL
 ORDER BY m.effective_date
             ",
             ['careMonthID' => $_careMonth->id]

+ 11 - 0
app/Models/Note.php

@@ -57,6 +57,13 @@ class Note extends Model
             ->orderBy('position_index', 'asc');
     }
 
+    public function segments()
+    {
+        return $this->hasMany(Segment::class, 'note_id', 'id')
+            ->where('is_active', true)
+            ->orderBy('position_index', 'asc');
+    }
+
     public function reasons()
     {
         return $this->hasMany(NoteReason::class, 'note_id', 'id');
@@ -98,4 +105,8 @@ class Note extends Model
         return $this->hasOne(NotePickupForProcessing::class, 'id', 'current_note_pickup_for_processing_id');
     }
 
+    public function visitTemplate()
+    {
+        return $this->hasOne(VisitTemplate::class, 'id', 'visit_template_id');
+    }
 }

+ 88 - 0
app/Models/Point.php

@@ -0,0 +1,88 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class Point extends Model
+{
+    protected $table = 'point';
+
+    public function lastChildReview()
+    {
+        return $this->hasOne(Point::class, 'id', 'last_child_review_point_id');
+    }
+
+    public function lastChildReviewNote()
+    {
+        return $this->hasOne(Note::class, 'id', 'last_child_review_point_scoped_note_id');
+    }
+
+    public function lastChildPlan()
+    {
+        return $this->hasOne(Point::class, 'id', 'last_child_plan_point_id');
+    }
+
+    public function lastChildPlanNote()
+    {
+        return $this->hasOne(Note::class, 'id', 'last_child_plan_point_scoped_note_id');
+    }
+
+    public static function getGlobalSingletonOfCategory(Client $_patient, String $_category, $_assoc = false) {
+        $point = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->orderBy('created_at', 'DESC')
+            ->first();
+        if ($point->data) {
+            $point->data = json_decode($point->data, $_assoc);
+        }
+        return $point;
+    }
+
+    public static function getIntakePointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('addition_reason_category', 'ON_INTAKE')
+            ->where(function ($query1) use ($_note) {
+                $query1
+                    ->where('is_removed', false)
+                    ->orWhere(function ($query2) use ($_note) {
+                        $query2->where('is_removed', true)
+                            ->where('removed_in_note_id', $_note->id);
+                    });
+            })
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data, $_assoc);
+            }
+        }
+        return $points;
+    }
+
+    public static function getPlanPointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('addition_reason_category', 'DURING_VISIT')
+            ->where(function ($query1) use ($_note) {
+                $query1
+                    ->where('is_removed', false)
+                    ->orWhere(function ($query2) use ($_note) {
+                        $query2->where('is_removed', true)
+                            ->where('removed_in_note_id', $_note->id);
+                    });
+            })
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data, $_assoc);
+            }
+        }
+        return $points;
+    }
+}

+ 10 - 0
app/Models/Pro.php

@@ -33,6 +33,11 @@ class Pro extends Model
         return strtolower(implode("", $characters));
     }
 
+    public function debitBills()
+    {
+        return $this->hasMany(Bill::class, 'debit_pro_id');
+    }
+
     public function cmBills()
     {
         return $this->hasMany(Bill::class, 'cm_pro_id');
@@ -121,6 +126,11 @@ class Pro extends Model
             ->orderBy('position_index', 'asc');
     }
 
+    public function visitTemplates() {
+        //TODO: use visit access
+        return VisitTemplate::all();
+    }
+
     public function currentWork() {
         return ProClientWork::where('pro_id', $this->id)->where('is_active', true)->first();
     }

+ 22 - 0
app/Models/Segment.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class Segment extends Model
+{
+    protected $table = 'segment';
+
+    public function segmentTemplate() {
+        return $this->hasOne(SegmentTemplate::class, 'id', 'segment_template_id');
+    }
+
+    public function note() {
+        return $this->hasOne(Note::class, 'id', 'note_id');
+    }
+
+    public function client() {
+        return $this->hasOne(Client::class, 'id', 'client_id');
+    }
+}

+ 11 - 0
app/Models/SegmentTemplate.php

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

+ 10 - 0
app/Models/VisitTemplate.php

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

+ 1 - 1
config/app.php

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

+ 347 - 0
fdb_notes.txt

@@ -0,0 +1,347 @@
+medSuggest
+https://docs.fdbhealth.com/display/MKDOCUS/Navigating+to+a+Routed+Medication+Route+Dosage+Form+and+Medication
+Retrieve the MED Medication Name ID (MED_NAME_ID) from the MED Medication Name Table (RMINMID1_MED_NAME) where the MED Medication Name (MED_NAME) equals the given drug.
+"SELECT med_name_id, med_name FROM rminmid1_med_name WHERE med_status_cd = '0' AND med_name ILIKE :term ORDER BY med_name",
+['term' => '%' . $term . '%']
+
+SELECT * FROM rminmid1_med_name LIMIT 5;
+ med_name_id |           med_name            | med_name_type_cd | med_status_cd 
+-------------+-------------------------------+------------------+---------------
+           1 | sertraline                    | 2                | 0
+           2 | Acetaminophen-Hydrocodone     | 1                | 1
+           3 | hydrocodone-carbinox-pseudoep | 2                | 3
+           4 | Phenylhistine DH              | 1                | 3
+           5 | denture care products         | 2                | 3
+
+
+
+routedMeds
+https://docs.fdbhealth.com/display/MKDOCUS/Navigating+to+a+Routed+Medication+Route+Dosage+Form+and+Medication
+Retrieve the Routed Medication ID (ROUTED_MED_ID) and MED Routed Medication Description (MED_ROUTED_MED_ID_DESC) values from the MED Routed Medication Table (RMIRMID1_ROUTED_MED) where the MED Medication Name (MED_NAME_ID) equals the value retrieved in the previous step and the MED Medication Status Code (MED_STATUS_CD) value equals 0 (active). 
+"SELECT routed_med_id, med_routed_med_id_desc FROM rmirmid1_routed_med WHERE med_status_cd = '0' AND med_name_id = :medNameID ORDER BY med_routed_med_id_desc",
+['medNameID' => $medNameID]
+ SELECT * FROM rmirmid1_routed_med  WHERE med_name_id = 1; 
+ routed_med_id | med_name_id | med_route_id | med_routed_med_id_desc | med_status_cd 
+---------------+-------------+--------------+------------------------+---------------
+             1 |           1 |           24 | sertraline oral        | 0
+
+
+routedDosages
+https://docs.fdbhealth.com/display/MKDOCUS/Navigating+to+a+Routed+Medication+Route+Dosage+Form+and+Medication
+Retrieve the MED Routed Dosage Form Med ID (ROUTED_DOSAGE_FORM_MED_ID) and from the MED Routed Dosage Form Medication Table (RMIDFID1_ROUTED_DOSE_FORM_MED) where the MED Routed Medication ID (ROUTED_MED_ID) equals the value retrieved in step 2 and th
+"SELECT routed_dosage_form_med_id, med_routed_df_med_id_desc FROM rmidfid1_routed_dose_form_med WHERE med_status_cd = '0' AND routed_med_id = :routedMedID ORDER BY med_routed_df_med_id_desc",
+['routedMedID' => $routedMedID]
+SELECT * FROM rmidfid1_routed_dose_form_med WHERE routed_med_id = 1;
+ routed_dosage_form_med_id | routed_med_id | med_dosage_form_id |  med_routed_df_med_id_desc  | med_status_cd 
+---------------------------+---------------+--------------------+-----------------------------+---------------
+                         1 |             1 |                 81 | sertraline tablet           | 0
+                     20735 |             1 |                 10 | sertraline oral concentrate | 0
+
+
+meds
+https://docs.fdbhealth.com/display/MKDOCUS/Navigating+to+a+Routed+Medication+Route+Dosage+Form+and+Medication
+Retrieve the Medication Identifier (MEDID) and MED Medication Description (MED_MEDID_DESC) values from the MED Medication Table (RMIID1_MED) where the MED Routed Dosage Form Med ID (ROUTED_DOSAGE_FORM_MED_ID) equals the value retrieved in the previous step and the MED Medication Status Code (MED_STATUS_CD) value equals 0 (active).
+"SELECT medid, med_medid_desc, gcn_seqno FROM rmiid1_med WHERE med_status_cd = '0' AND routed_dosage_form_med_id = :dosageFormMedId ORDER BY med_medid_desc",
+['dosageFormMedId' => $dosageFormMedId]
+\d rmiid1_med
+Table "public.rmiid1_med"
+          Column           |         Type          | Collation | Nullable | Default 
+---------------------------+-----------------------+-----------+----------+---------
+ medid                     | numeric(8,0)          |           | not null | 
+ routed_dosage_form_med_id | numeric(8,0)          |           | not null | 
+ med_strength              | character varying(15) |           |          | 
+ med_strength_uom          | character varying(15) |           |          | 
+ med_medid_desc            | character varying(70) |           | not null | 
+ gcn_seqno                 | numeric(6,0)          |           | not null | 
+ med_gcnseqno_assign_cd    | character varying(1)  |           | not null | 
+ med_name_source_cd        | character varying(1)  |           | not null | 
+ med_ref_fed_legend_ind    | character varying(1)  |           | not null | 
+ med_ref_dea_cd            | character varying(1)  |           | not null | 
+ med_ref_multi_source_cd   | character varying(1)  |           | not null | 
+ med_ref_gen_drug_name_cd  | character varying(1)  |           | not null | 
+ med_ref_gen_comp_price_cd | character varying(1)  |           | not null | 
+ med_ref_gen_spread_cd     | character varying(1)  |           | not null | 
+ med_ref_innov_ind         | character varying(1)  |           | not null | 
+ med_ref_gen_thera_equ_cd  | character varying(1)  |           | not null | 
+ med_ref_desi_ind          | character varying(1)  |           | not null | 
+ med_ref_desi2_ind         | character varying(1)  |           | not null | 
+ med_status_cd             | character varying(1)  |           | not null | 
+ generic_medid             | numeric(8,0)          |           |          |
+
+sideEffects
+https://docs.fdbhealth.com/display/MKDOCUS/Retrieving+a+List+of+Side+Effects
+-- Query the GCN_SEQNO column of the SIDE GCN_SEQNO/Drug Side Effect Code Relation Table (RSIDEGC0_GCNSEQNO_LINK) using the drug’s Clinical Formulation ID (GCN_SEQNO) value to retrieve all of its related SIDE Side Effects Code (SIDE) values.
+-- Query the SIDE column of the SIDE Master Table (RSIDEMA3_MSTR) using each SIDE value from the previous step to retrieve the following columns:
+	-- SIDE Frequency of Occurrence Code (SIDE_FREQ)
+	-- SIDE Severity Code (SIDE_SEV)
+	-- FML Disease Identifier (DXID)
+-- Follow the process described in the FML module’s Finding DXID Descriptions and Synonyms application to find each DXID value’s Primary Layman Name.
+SELECT r1.side, sm.side_freq, sm.side_sev, sm.dxid, dx.dxid_desc56 
+FROM rsidegc0_gcnseqno_link r1 
+    JOIN rsidema3_mstr sm ON r1.side = sm.side
+    JOIN rfmldx0_dxid dx ON sm.dxid = dx.dxid
+WHERE r1.gcn_seqno = :gcnSeqNo
+ORDER BY sm.side_sev DESC, sm.side_freq ASC
+['gcnSeqNo' => $gcnSeqNo]
+-- get a drug(routed dosage med) gcn_seqno 
+SELECT gcn_seqno FROM rmiid1_med WHERE routed_dosage_form_med_id  = 20735;
+ gcn_seqno 
+-----------
+     46230
+
+-- get side effects for the genseq
+SELECT * FROM rsidegc0_gcnseqno_link WHERE gcn_seqno = 46230;
+ gcn_seqno | side 
+-----------+------
+     46230 |  560
+     46230 | 2451
+
+
+-- get side effect details 
+SELECT * FROM RSIDEMA3_MSTR WHERE side = 560;
+ side | side_sn |   fdbdx   | side_freq | side_sev | side_viscd | side_labcd | side_phys | side_hyper | dxid  
+------+---------+-----------+-----------+----------+------------+------------+-----------+------------+-------
+  560 |       0 | 03.276100 | 2         | 1        | 2          | 1          | 1         |            |   736
+  560 |       1 | 05.296000 | 2         | 1        | 1          | 0          | 1         |            |   950
+  560 |       2 | 05.296010 | 2         | 1        | 1          | 0          | 1         |            |   951
+  560 |       3 | 05.300007 | 2         | 0        | 1          | 0          | 0         |            | 14664
+  560 |       4 | 05.300906 | 2         | 1        | 1          | 0          | 1         |            |   985
+  560 |       5 | 05.302700 | 0         | 1        | 1          | 0          | 1         |            |   992
+  560 |       6 | 05.302701 | 0         | 1        | 1          | 0          | 1         |            |   993
+  560 |       7 | 05.307900 | 1         | 0        | 1          | 0          | 0         |            |  1018
+
+-- side_feq dictionary 
+1 = Incidence less frequent
+0 = Incidence more frequent
+2 = Incidence rare or very rare
+
+-- side_sev dictionary
+0 = “less severe” if it is non-threatening (such as constipation)
+1 = “severe” if it may be life-threatening (such as agranulocytosis)
+
+-- get the description for a side effect using  dxid 
+SELECT * FROM rfmldx0_dxid WHERE dxid = 736;
+ dxid | dxid_desc56  | dxid_desc100 | dxid_status |   fdbdx   | dxid_disease_duration_cd 
+------+--------------+--------------+-------------+-----------+--------------------------
+  736 | hyponatremia | hyponatremia | 0           | 03.276100 | 3
+
+
+geriatricPrecautions
+https://docs.fdbhealth.com/display/MKDOCUS/Application%3A+Screening+a+Drug+for+Geriatric+Precautions
+-- Select Geriatric Precaution Code (GERI_CODE) from the GERI GCN_SEQNO Link Table (RGERIGC0_GERI_GCNSEQNO_LINK) where the Clinical Formulation ID (GCN_SEQNO) column equals the Clinical Formulation ID (GCN_SEQNO) of the drug to screen.
+-- Select GERI precautions information from the Geriatric Precautions Master Table (RGERIMA1_GERI_MSTR) where the GERI_CODE column equals the GERI_CODE value from the previous step.
+SELECT r1.geri_code, gm.geri_sl, gm.geri_desc, gm.geri_narrative
+FROM rgerigc0_geri_gcnseqno_link r1 
+JOIN rgerima1_geri_mstr gm ON r1.geri_code = gm.geri_code
+WHERE r1.gcn_seqno = :gcnSeqNo
+ORDER BY gm.geri_desc
+['gcnSeqNo' => $gcnSeqNo]
+-- select geriatricPrecautions based for a given drug formulation code 
+SELECT * FROM RGERIGC0_GERI_GCNSEQNO_LINK WHERE gcn_seqno = 46230 LIMIT 5 ;
+ gcn_seqno | geri_code 
+-----------+-----------
+     46230 |       831
+-- get the meaning of the geri_code 
+SELECT geri_code, geri_desc, geri_narrative FROM RGERIMA1_GERI_MSTR WHERE geri_code = 831;
+ geri_code | geri_desc  |                                                                                                                            geri_narrative                                                                                                                             
+-----------+------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------
+       831 | Sertraline | Hepatic-Mild hepatic impairment of aging may predispose the elderly to increased serum levels and increased adverse events.  Endocrine-May exacerbate or cause SIADH
+ or hyponatremia. Monitor sodium level closely when starting or changing dosages in older adults.
+
+
+indications
+https://docs.fdbhealth.com/display/MKDOCUS/Retrieving+a+Drug%27s+List+of+Indications
+Indications refers to the use of that drug for treating a particular disease
+-- Retrieve the INDM Indications Code (INDCTS) associated to the drug product’s Clinical Formulation ID (GCN_SEQNO) using the INDM GCN_SEQNO/Drug Indications Code Relation Table (RINDMGC0_INDCTS_GCNSEQNO_LINK).
+-- For each Clinical Formulation ID (GCN_SEQNO)/INDCTS combination retrieved in step 2, retrieve the following columns from the INDM Master Table (RINDMMA2_INDCTS_MSTR):
+	-- INDM Sequence Number (INDCTS_SN)
+	-- INDM Labeled Code (INDCTS_LBL)
+	-- FML Disease Identifier (DXID)
+	-- INDM Proxy Indicator (PROXY_IND)
+-- Get the description from https://docs.fdbhealth.com/display/MKDOCUS/Finding+DXID+Descriptions+and+Synonyms
+	-- For DxID 00000595’s Primary Professional Name, find its associated FML 56-character Description column (DXID_DESC56) and FML 100-character Description column (DXID_DESC100) in the FML Disease Identifier (DxID) Table (RFMLDX0_DXID).
+SELECT r1.indcts, r2.indcts_sn, r2.indcts_lbl, r2.dxid, r2.proxy_ind, r3.dxid_desc56
+FROM rindmgc0_indcts_gcnseqno_link r1 
+    JOIN rindmma2_indcts_mstr r2 ON r1.indcts = r2.indcts
+    JOIN rfmldx0_dxid r3 ON r2.dxid = r3.dxid
+WHERE r1.gcn_seqno = :gcnSeqNo
+ORDER BY r3.dxid_desc56
+['gcnSeqNo' => $gcnSeqNo]
+-- Select indications for a given gcn_seqno 
+SELECT * FROM RINDMGC0_INDCTS_GCNSEQNO_LINK WHERE gcn_seqno = 46230;
+ gcn_seqno | indcts 
+-----------+--------
+     46230 |    201
+-- get the details of the indicts 
+SELECT * FROM RINDMMA2_INDCTS_MSTR WHERE indcts = 201 AND proxy_ind <> 'Y' LIMIT 5;
+ indcts | indcts_sn | indcts_lbl |   fdbdx   | dxid  | proxy_ind | pred_code 
+--------+-----------+------------+-----------+-------+-----------+-----------
+    201 |         0 | U          | 05.296500 | 12862 | N         | 3
+    201 |         1 | U          | 05.298001 |  8464 | N         | 3
+    201 |         2 | L          | 05.300010 |   970 | N         | 2
+    201 |         3 | L          | 05.300230 |   975 | N         | 2
+    201 |         4 | L          | 05.300300 |   976 | N         | 3
+NB: to remove Non-FDA approved, add where indcts_lbl <> 'U'; //U == unlabeled
+-- get the meaning of DXIDs 
+SELECT * FROM RFMLDX0_DXID WHERE dxid IN (970, 975, 976);
+ dxid |          dxid_desc56          |         dxid_desc100          | dxid_status |   fdbdx   | dxid_disease_duration_cd 
+------+-------------------------------+-------------------------------+-------------+-----------+--------------------------
+  970 | panic disorder                | panic disorder                | 0           | 05.300010 | 1
+  975 | social phobia                 | social phobia                 | 0           | 05.300230 | 2
+  976 | obsessive-compulsive disorder | obsessive-compulsive disorder | 0           | 05.300300 | 2
+
+
+contraindications
+https://docs.fdbhealth.com/display/MKDOCUS/Retrieving+a+List+of+Drug+Contraindications
+-- Get drug ddxcn from rddcmrm0_routed_med_link
+-- Retrieve the FML Disease Identifier (DXID) values associated with DDXCN 50225 from the DDCM Master Table (RDDCMMA1_CONTRA_MSTR).
+-- Retrieve the FML 100-Character Description (DXID_DESC100) for each DXID value using the FML Disease Identifier (DxID) Table (RFMLDX0_DXID).
+SELECT r1.ddxcn, r2.dxid, r2.ddxcn_sl, r3.dxid_desc56
+FROM rddcmrm0_routed_med_link r1 
+    JOIN rddcmma1_contra_mstr r2 ON r1.ddxcn = r2.ddxcn
+    JOIN rfmldx0_dxid r3 ON r2.dxid = r3.dxid
+WHERE r1.routed_med_id = :routedMedID
+ORDER BY r2.ddxcn_sl
+['routedMedID' => $routedMedID]
+
+-- get drug disease contraindications for a given routed_med_id 
+SELECT * FROM RDDCMRM0_ROUTED_MED_LINK  WHERE routed_med_id = 1;
+ routed_med_id | ddxcn 
+---------------+-------
+             1 | 50005
+-- get the details of ddxcn 
+SELECT * FROM RDDCMDD0_CONTRA_DRUG_DESC WHERE ddxcn = 50005;
+ ddxcn | ddxcn_drug_desc 
+-------+-----------------
+ 50005 | SERTRALINE
+
+-- get dxid associated with the ddxcn (get disease id associated with the contraindications)
+SELECT * FROM RDDCMMA1_CONTRA_MSTR WHERE ddxcn = 50005; 
+ddxcn | ddxcn_sn |   fdbdx   | ddxcn_sl |         ddxcn_ref          | dxid  
+-------+----------+-----------+----------+----------------------------+-------
+ 50005 |        0 | 03.276100 | 3        | ZOLOFT PI, 12/2016         |   736
+ 50005 |        1 | 03.253600 | 3        | ZOLOFT PI, 12/2016         |   624
+ 50005 |        2 | 04.286906 | 3        | ZOLOFT PI, 12/2016         |   867
+ 50005 |        3 | 05.296700 | 3        | ZOLOFT PI, 12/2016         |   954
+ 50005 |        4 | 05.300906 | 2        | MEDWATCH, 3/04, PI 5/14    |   985
+ 50005 |        5 | 09.573900 | 2        | ZOLOFT PI, 12/2016         |  2202
+
+-- get human readable meanings of the dxid 
+SELECT * FROM RFMLDX0_DXID WHERE dxid IN (736,624,867,954,985,2202);
+ dxid |        dxid_desc56         |        dxid_desc100        | dxid_status |   fdbdx   | dxid_disease_duration_cd 
+------+----------------------------+----------------------------+-------------+-----------+--------------------------
+  624 | SIADH syndrome             | SIADH syndrome             | 0           | 03.253600 | 3
+  736 | hyponatremia               | hyponatremia               | 0           | 03.276100 | 3
+  867 | increased risk of bleeding | increased risk of bleeding | 0           | 04.286906 | 2
+  954 | bipolar disorder           | bipolar disorder           | 0           | 05.296700 | 2
+  985 | suicidal ideation          | suicidal ideation          | 0           | 05.300906 | 3
+ 2202 | disease of liver           | disease of liver           | 0           | 09.573900 | 2
+
+
+dxSuggest
+https://docs.fdbhealth.com/display/MKDOCUS/Finding+DXID+Descriptions+and+Synonyms
+-- For DxID 00000595’s Primary Professional Name, find its associated FML 56-character Description column (DXID_DESC56) and FML 100-character Description column (DXID_DESC100) in the FML Disease Identifier (DxID) Table (RFMLDX0_DXID).
+-- For DxID 00000595’s Professional Synonyms, find its associated FML 56-character Synonym Description (DXID_SYN_DESC56) and FML 100-character Synonym Description (DXID_SYN_DESC100) in the FML Disease Identifier (DxID) Synonym Table (RFMLSYN0_DXID_SYN). Specify a value of 01 for the FML Name Type Code (DXID_SYN_NMTYP) to signify that you wish to retrieve this DxID’s Professional Synonyms.
+-- i.e search where term matches in the main table (rfmldx0_dxid) and in the synonyms table (rfmlsyn0_dxid_syn) on both 56 and 100 character descriptions
+SELECT distinct(r1.dxid), r1.dxid_desc56 
+FROM rfmldx0_dxid r1
+JOIN rfmlsyn0_dxid_syn r2 ON r1.dxid = r2.dxid
+WHERE (r1.dxid_desc56 ILIKE :term OR r1.dxid_desc100 ILIKE :term OR r2.dxid_syn_desc56 ILIKE :term OR r2.dxid_syn_desc100 ILIKE :term)
+ORDER BY r1.dxid_desc56
+['term' => '%' . $term . '%']
+-- DX has 
+	- Primary Professional Name: one and only one - RFMLDX0_DXID
+	RFMLSYN0_DXID_SYN
+	- Professional Synonym: zero, one, or many -  dxid_syn_nmtyp = 01
+	- Primary Layman Name: zero, one, or many - dxid_syn_nmtyp = 02
+	- Layman Synonym: zero, one, or many - dxid_syn_nmtyp = 03
+	- Abbreviation: zero, one, or many - dxid_syn_nmtyp = 04
+ SELECT * FROM RFMLDX0_DXID WHERE dxid = '595';
+ dxid |       dxid_desc56        |       dxid_desc100       | dxid_status |   fdbdx   | dxid_disease_duration_cd 
+------+--------------------------+--------------------------+-------------+-----------+--------------------------
+  595 | type 1 diabetes mellitus | type 1 diabetes mellitus | 0           | 03.250010 | 2
+
+-- get synonyms: 
+ SELECT * FROM RFMLSYN0_DXID_SYN WHERE dxid = 595 AND dxid_syn_nmtyp = '01';
+ dxid_synid | dxid | dxid_syn_nmtyp |           dxid_syn_desc56           |          dxid_syn_desc100           | dxid_syn_status 
+------------+------+----------------+-------------------------------------+-------------------------------------+-----------------
+        384 |  595 | 01             | juvenile diabetes                   | juvenile diabetes                   | 0
+        387 |  595 | 01             | insulin-dependent DM                | insulin-dependent DM                | 0
+        388 |  595 | 01             | insulin-dependent diabetes mellitus | insulin-dependent diabetes mellitus | 0
+        389 |  595 | 01             | ketosis-prone diabetes mellitus     | ketosis-prone diabetes mellitus     | 0
+        390 |  595 | 01             | ketosis-prone diabetes              | ketosis-prone diabetes              | 0
+        391 |  595 | 01             | juvenile-onset diabetes             | juvenile-onset diabetes             | 0
+        392 |  595 | 01             | juvenile-onset diabetes mellitus    | juvenile-onset diabetes mellitus    | 0
+        393 |  595 | 01             | juvenile onset DM                   | juvenile onset DM                   | 0
+        394 |  595 | 01             | type I diabetes mellitus            | type I diabetes mellitus            | 0
+        395 |  595 | 01             | diabetes mellitus type 1            | diabetes mellitus type 1            | 0
+        396 |  595 | 01             | ketosis-prone DM                    | ketosis-prone DM                    | 0
+      58331 |  595 | 01             | insulin dependent diabetes mellitus | insulin dependent diabetes mellitus | 0
+      58407 |  595 | 01             | immune mediated diabetes mellitus   | immune mediated diabetes mellitus   | 0
+
+
+allergySuggest
+https://docs.fdbhealth.com/display/MKDOCUS/Recording+Patient+Allergy+Information
+-- Query the DAM Allergen Concept ID Description column (DAM_CONCEPT_ID_DESC) in the RDAMAPM0_ALRGN_PICKLIST_MSTR table or the RDAMCA0_CONCEPT table to find all entries with the description “carbamates."
+SELECT r1.dam_concept_id, r1.dam_concept_id_typ, r1.dam_concept_id_desc
+FROM rdamca0_concept r1
+WHERE (r1.dam_concept_id_desc ILIKE :term)
+ORDER BY r1.dam_concept_id_desc
+
+
+drugDrugInteraction
+https://docs.fdbhealth.com/display/MKDOCUS/Screening+for+Active+and+Inactive+Ingredient+Drug-Drug+Interactions
+
+drugCoadministration
+https://docs.fdbhealth.com/display/MKDOCUS/Displaying+Coadministration+Text
+
+duplicateTherapy
+https://docs.fdbhealth.com/display/MKDOCUS/Detecting+Therapeutic+Class+Duplications
+-- Retrieve the Routed Medication ID (ROUTED_MED_ID) in the DPT Routed Medication ID Table(rmirmid1_routed_med), or Routed Generic Identifier (ROUTED_GEN_ID) in the DPT Routed Generic Table, or Clinical Formulation ID (GCN_SEQNO) in the DPT GCN_SEQNO Table for the newly prescribed (prospective) drug and for each drug in the patient profile (profiled drugs).
+-- Retrieve the associated DPT Class Identifiers (DPT_CLASS_ID) from the DPT Class Table (RDPTCL0_CLASS_ID) for each prospective drug and each profiled drug.
+-- Compare the DPT_CLASS_IDs and retrieve the DPT Class Description (DPT_CLASS_DESC) record from the RDPTCL0_CLASS_ID table when Duplicate Therapy Class matches occur.
+-- Compare the number of times that a match of a given class is returned with the DPT Duplication Allowance (DPT_ALLOWANCE) from the RDPTCL0_CLASS_ID table. If the number of matches exceeds the DPT_ALLOWANCE value, a duplicate therapy exists. In most instances, the duplication allowance is zero. Programming for a duplication allowance of one or more should occur only for drugs in the same class that are used concurrently, per accepted medical practice.
+
+=====================================================================================================
+Get drugs used to treat a given condition 
+-- get dxid for the condition eg. 'social phobia'
+SELECT * FROM RFMLDX0_DXID WHERE dxid_desc56 ILIKE 'social%';
+ dxid |  dxid_desc56  | dxid_desc100  | dxid_status |   fdbdx   | dxid_disease_duration_cd 
+------+---------------+---------------+-------------+-----------+--------------------------
+  975 | social phobia | social phobia | 0           | 05.300230 | 2
+
+-- get indcts for the condition 
+SELECT DISTINCT(indcts) FROM RINDMMA2_INDCTS_MSTR WHERE dxid = 975 AND proxy_ind <> 'Y' AND indcts_lbl <> 'U';
+ indcts 
+--------
+    201
+   1006
+   1457
+   1695
+
+-- get clinical formulations (gcn_seqno) for the above indcts 
+SELECT * FROM RINDMGC0_INDCTS_GCNSEQNO_LINK WHERE indcts IN (201,1006,1457,1695);
+ gcn_seqno | indcts 
+-----------+--------
+     46222 |   1006
+     46223 |   1006
+     46224 |   1006
+     46225 |   1006
+     46226 |   1006
+....
+
+-- get drugs that contain this gcn_seqno 
+SELECT medid, med_medid_desc, gcn_seqno FROM rmiid1_med WHERE gcn_seqno IN (SELECT gcn_seqno FROM RINDMGC0_INDCTS_GCNSEQNO_LINK WHERE indcts IN (201,1006,1457,1695));
+SELECT medid, med_medid_desc, gcn_seqno FROM rmiid1_med WHERE gcn_seqno IN (SELECT gcn_seqno FROM RINDMGC0_INDCTS_GCNSEQNO_LINK WHERE indcts IN (201,1006,1457,1695));
+ medid  |                    med_medid_desc                     | gcn_seqno 
+--------+-------------------------------------------------------+-----------
+ 157825 | paroxetine ER 37.5 MG tablet,extended release 24 hr   |     50138
+ 159557 | venlafaxine ER 37.5 mg capsule,extended release 24 hr |     46403
+ 160594 | venlafaxine ER 75 mg capsule,extended release 24 hr   |     46404
+ 162880 | paroxetine 10 mg tablet                               |     46222
+ 165384 | Effexor XR 75 mg capsule,extended release             |     46404
+ 166110 | Paxil CR 37.5 MG tablet,extended release              |     50138
+ 182739 | Effexor XR 37.5 mg capsule,extended release           |     46403
+ 183163 | Paxil 20 mg tablet                                    |     46223
+ 184142 | Paxil 10 mg/5 mL oral suspension                      |     46226
+ 187550 | sertraline 100 mg tablet                              |     46229

+ 106 - 0
public/css/style.css

@@ -1899,4 +1899,110 @@ body.in-iframe .stag-content {
 body.in-iframe .main-row > .sidebar {
     top: 0;
     height: 100%;
+}
+.stag-popup .hide-inside-popup {
+    display: none !important;
+}
+.strike-through {
+    text-decoration: line-through;
+}
+
+/* visit-moe */
+[visit-moe] [url]:not([show]){
+    display: none;
+}
+[visit-moe] {
+    display: inline-block;
+}
+[visit-moe][relative] {
+    position: relative;
+}
+[visit-moe] [url]:not([show]) {
+    z-index: 99999;
+    position: absolute;
+    background-color: white;
+    padding: 10px;
+    border: 1px solid gray;
+}
+[visit-moe][fixed-center] [url]:not([show]) {
+    position: fixed !important;
+    top: 50% !important;
+    left: 50% !important;
+    width: 600px;
+    transform: translate(-50%, -50%) !important;
+}
+[visit-moe] [url][right] {
+    right: 0;
+    min-width: 200px;
+}
+[visit-moe][large] form, [visit-moe][large] [url] {
+    width: 450px;
+}
+[visit-moe][bottom] form {
+    bottom: 100%;
+}
+.note-container {
+    display: flex;
+    align-items: start;
+}
+.note-container .note-lhs-tree {
+    min-width: 220px;
+    max-width: 220px;
+    align-self: stretch;
+    border-right: 1px solid #ddd;
+    padding-top: 0.85rem;
+    height: 300px;
+    overflow: overlay;
+    max-height: calc(100vh - 55px);
+    background-color: #fff;
+}
+.note-container .note-lhs-tree.fixed {
+    position: fixed;
+    top: 55px;
+    max-height: calc(100vh - 55px) !important;
+    height: calc(100vh - 55px) !important;
+}
+.note-container .note-lhs-tree.fixed ~ .note-rhs-content {
+    margin-left: 220px;
+}
+.note-container .note-lhs-tree .note-tree-node.note-tree-heading>a {
+
+}
+.note-container .note-lhs-tree .note-tree-node>a {
+    display: block;
+    padding: 0.15rem 0;
+    padding-left: 0.75rem;
+    white-space: nowrap;
+    text-overflow: ellipsis;
+    overflow: hidden;
+    text-decoration: none;
+    color: #333;
+}
+.note-container .note-lhs-tree .note-tree-node>a:hover {
+    background-color: aliceblue;
+    color: #0d59af !important;
+}
+.note-container .note-lhs-tree .note-tree-node.active>a {
+    background-color: aliceblue;
+    font-weight: bold !important;
+    color: #0d59af !important;
+}
+.note-container .note-lhs-tree .note-tree-children>.note-tree-node>a {
+    padding-left: 2rem;
+}
+.note-container .note-lhs-tree .note-tree-children .note-tree-children>.note-tree-node>a {
+    padding-left: 4rem;
+}
+.note-container .note-rhs-content {
+    flex-grow: 1;
+}
+.spot-highlight {
+    background: aliceblue !important;
+}
+.on-click-menu [menu] {
+    position: absolute;
+    display: none;
+    top: 100%;
+    right: 0;
+    z-index: 1;
 }

+ 191 - 0
public/js/stag-suggest.js

@@ -0,0 +1,191 @@
+(function () {
+    window.initStagSuggest = function () {
+
+        let suggestionsOuter = null;
+
+        const debounce = (func, wait) => {
+            let timeout;
+            return function executedFunction(...args) {
+                const later = () => {
+                    clearTimeout(timeout);
+                    func(...args);
+                };
+                clearTimeout(timeout);
+                timeout = setTimeout(later, wait);
+            };
+        };
+
+        var lastTerm = '';
+        var returnedFunction = debounce(function (elem) {
+            let term = elem.val();
+            if (!!term && lastTerm !== term) {
+                let ep = $(elem).attr('stag-suggest-ep');
+                $.get(ep + '?term=' + $.trim(term), function (_data) {
+
+                    /*
+                    expected return format:
+                    {
+                        success: true,
+                        data: [
+                            {
+                                x: ...,
+                                y: ...,
+                                text: ...    // "text" key is "mandatory"
+                            },
+                            {
+                                x: ...,
+                                y: ...,
+                                text: ...    // "text" key is "mandatory"
+                            },
+                            ...
+                        ]
+                    }
+                     */
+
+                    suggestionsOuter.empty();
+                    if(!hasResponseError(_data) && _data.data && _data.data.length) {
+                        for (let i = 0; i < _data.data.length; i++) {
+                            let item = $('<a native href="#" class="d-block suggest-item stag-suggest text-nowrap"/>');
+                            for(let x in _data.data[i]) {
+                                if(_data.data[i].hasOwnProperty(x) && x !== 'text') {
+                                    item.attr('data-' + x, _data.data[i][x]);
+                                }
+                            }
+                            item.data('suggest-data', _data.data[i]);
+                            item.html(_data.data[i].text);
+                            suggestionsOuter.append(item);
+                        }
+                    }
+                    else {
+                        suggestionsOuter.html('<span class="d-block no-suggest-items">No matches!</span>');
+                    }
+
+                    suggestionsOuter.removeClass('d-none');
+                }, 'json');
+                lastTerm = term;
+            } else {
+                suggestionsOuter.addClass('d-none');
+            }
+        }, 250);
+
+        function handleKeydown(elem, e) {
+            let term = $.trim(elem.val());
+            let activeItem = suggestionsOuter.find('.suggest-item.active');
+            switch (e.which) {
+                case 27:
+                    suggestionsOuter.addClass('d-none');
+                    return false;
+                case 38:
+                    if (activeItem.prev().length) {
+                        activeItem.prev()
+                            .addClass('active')
+                            .siblings().removeClass('active');
+                        activeItem = suggestionsOuter.find('.suggest-item.active');
+                        if (activeItem.length) {
+                            activeItem[0].scrollIntoView();
+                        }
+                    }
+                    return false;
+                case 40:
+                    if (activeItem.next().length) {
+                        activeItem.next()
+                            .addClass('active')
+                            .siblings().removeClass('active');
+                        activeItem = suggestionsOuter.find('.suggest-item.active');
+                        if (activeItem.length) {
+                            activeItem[0].scrollIntoView();
+                        }
+                    }
+                    return false;
+                case 13:
+                    if (activeItem.length) {
+                        activeItem.first().click();
+                    }
+                    return false;
+                default:
+                    if (!!term) {
+                        suggestionsOuter
+                            .html('<span class="d-block no-suggest-items">Searching...</span>')
+                            .removeClass('d-none');
+                        returnedFunction(elem);
+                    } else {
+                        suggestionsOuter.addClass('d-none');
+                    }
+                    break;
+            }
+        }
+
+        function handleKeypress(elem, e) {
+            var term = $.trim(elem.val());
+            if (!!term) {
+                suggestionsOuter
+                    .html('<span class="d-block no-suggest-items">Searching...</span>')
+                    .removeClass('d-none');
+                returnedFunction(elem);
+            } else {
+                suggestionsOuter.addClass('d-none');
+            }
+        }
+
+        $('[stag-suggest]:not([stag-suggest-initialized])').each(function () {
+            let elem = $(this);
+            elem.next('.stag-suggestions-container').remove();
+            $('<div class="stag-suggestions-container position-relative">' +
+                '<div class="suggestions-outer stag-suggestions position-absolute d-none"></div>' +
+                '</div>').insertAfter(elem);
+
+            elem
+                .off('keydown.stag-suggest')
+                .on('keydown.stag-suggest', function (e) {
+                    suggestionsOuter = $(this).next('.stag-suggestions-container').find('>.suggestions-outer');
+                    return handleKeydown($(this), e);
+                })
+                .off('keypress.stag-suggest')
+                .on('keypress.stag-suggest', function (e) {
+                    suggestionsOuter = $(this).next('.stag-suggestions-container').find('>.suggestions-outer');
+                    return handleKeypress($(this), e);
+                });
+
+            $(this).attr('stag-suggest-initialized', 1);
+        });
+
+        // on auto-suggest selection
+        $(document).off('click', '.suggest-item.stag-suggest');
+        $(document).on('click', '.suggest-item.stag-suggest', function () {
+
+            $('.suggestions-outer.stag-suggestions').addClass('d-none');
+
+            let data = $(this).data('suggest-data'),
+                label = $.trim($(this).text());
+
+            // set value
+            let input = $(this).closest('.position-relative').prev('[stag-suggest]');
+            input.val(label);
+            input.data('suggest-data', data);
+
+            let scope = input.attr('stag-suggest-scope');
+            if(!scope) scope = 'form';
+            scope = $(scope);
+
+            for(let x in data) {
+                if(data.hasOwnProperty(x)) {
+                    input.attr('data-' + x, data[x]);
+
+                    // auto-populate if there's a field matching data-name="x" in the scope
+                    if(scope.find('[data-name="' + x + '"]').length) {
+                        scope.find('[data-name="' + x + '"]').val(data[x]).trigger('change');
+                    }
+
+                }
+            }
+            input.trigger('input');
+            input.trigger('change');
+
+            input.trigger('stag-suggest-selected', [input, data]);
+
+            return false;
+        });
+
+    }
+    addMCInitializer('stag-suggest', window.initStagSuggest);
+})();

+ 11 - 0
resources/views/app/dashboard/measurements.blade.php

@@ -42,6 +42,7 @@
                             0
                         @endif
                     </td>
+                    <?php /*
                     <td colspan="px-2">
                         <?php
                         $stampEndPoint = '';
@@ -104,6 +105,16 @@
                             </div>
                         @endif
                     </td>
+                    */ ?>
+                    <td class="px-2">
+                        <a native target="_blank"
+                           open-in-stag-popup
+                           update-parent
+                           title="Care Month Matrix: {{date('M Y', strtotime($measurement->care_month_start_date))}}"
+                           href="/patient-care-month-matrix/{{$measurement->care_month_uid}}">
+                            View &amp; Stamp
+                        </a>
+                    </td>
                 </tr>
             <?php endforeach ?>
         @else

+ 42 - 0
resources/views/app/patient/note/_templates-v2-index.blade.php

@@ -0,0 +1,42 @@
+<?php
+$templateIndex = json_decode(file_get_contents(storage_path('templates/index.json')));
+$hasTemplates = false;
+if(isset($templateIndex->{$sectionInternalName})) {
+    $hasTemplates = true;
+    $templateName = '';
+    $defaultTemplateName = '';
+    foreach($templateIndex->{$sectionInternalName} as $k => $templateSet) {
+        if($templateName === '') $templateName = $k;
+        if($templateSet->default) $defaultTemplateName = $k;
+    }
+    if($defaultTemplateName !== '') $templateName = $defaultTemplateName;
+?>
+    <span class="mx-2 text-secondary text-sm d-none if-edit">|</span>
+    <span class="position-relative d-none if-edit">
+        <a href="#" class="note-templates-trigger">Templates</a>
+        <div class="note-template-container">
+            <div class="position-relative w-100">
+                <div class="note-template-output">
+                    <div class="font-weight-bold text-secondary">Result:</div>
+                    <div class="note-template-output-text"></div>
+                </div>
+                <div class="note-template-buttons d-flex align-items-center">
+                    <button class="btn btn-sm btn-default bg-white border text-primary border-primary note-template-apply-trigger">Apply</button>
+                    <button class="btn btn-sm btn-default bg-light border text-secondary border-secondary note-template-close-trigger">Close</button>
+                </div>
+            </div>
+            <div class="p-1 border border-bottom">
+                <select class="form-control form-control-sm note-template-set-chooser" data-section="{{$sectionInternalName}}">
+                    @foreach($templateIndex->{$sectionInternalName} as $k => $templateSet)
+                        <option value="{{$k}}" {{$k === $templateName ? 'selected' : ''}}>{{$templateSet->name}}</option>
+                    @endforeach
+                </select>
+            </div>
+            {{--@include('app/patient/note/_template')--}}
+        </div>
+    </span>
+<?php
+}
+?>
+
+

+ 2147 - 0
resources/views/app/patient/note/dashboard-univ.blade.php

@@ -0,0 +1,2147 @@
+<?php
+/** @var App\Models\Note $note */
+/** @var App\Models\Pro $pro */
+/** @var App\Models\Section $section */
+/** @var $allSections */
+?>
+@extends ('layouts.patient')
+
+@section('inner-content')
+
+    <?php
+    $hasBills = false;
+    if($note->bills->count()) {
+        foreach ($note->bills as $bill) {
+            if(!$bill->is_cancelled) {
+                $hasBills = true;
+                break;
+            }
+        }
+    }
+    ?>
+
+    {{--
+    @if(!count($pro->companyProPayers) ||  /* pro has no assoc with any payer */
+                    ($patient->is_part_b_primary !== 'YES' && !$patient->non_mc_primary_payer_id) ||    /* patient is not part_b and has no primary non-mc payer */
+                    ($patient->is_part_b_primary === 'YES' && !$pro->isAssociatedWithMCPayer()) ||      /* patient is part_b but pro has no mc payer assoc */
+                    ($patient->is_part_b_primary !== 'YES' && $patient->non_mc_primary_payer_id &&      /* patient is not part_b and has non-mc-primary, but pro has no assoc with that payer */
+                        !$pro->isAssociatedWithNonMCPayer($patient->non_mc_primary_payer_id))
+                )
+        <div class="alert alert-warning mcp-theme-1 p-3 hide-inside-ticket-popup">
+            <div class="font-size-14 font-weight-bold">
+                <i class="fa fa-exclamation-triangle text-warning-mellow"></i>
+                This patient may not be covered for this visit. Please check with practice administrator.
+            </div>
+        </div>
+    @endif
+    --}}
+
+    <div id="note-single-header" class="pb-3 d-flex align-items-start screen-only">
+        <h6 class="my-0 text-secondary d-flex align-items-center w-100">
+            <a href="/patients/view/{{ $patient->uid }}/notes" class="small text-decoration-none mr-3">
+                <i class="fa fa-chevron-left"></i>
+            </a>
+            <div class="mr-auto d-inline-flex align-items-center">
+                <span class="text-dark font-weight-bold">Note (univ *)
+                    <span class="text-secondary font-weight-normal">{{ $note->is_cancelled ? '(CANCELLED)' : '' }}</span>
+                </span>
+                @if($pro->pro_type === 'ADMIN')
+                    <a href="#" class="print-note ml-3 btn btn-sm btn-primary text-white font-weight-bold invisible"><i class="fa fa-print"></i> Print</a>
+                    <?php
+                    $isBad = false;
+                    $isGood = false;
+		            if($note->detail_json) {
+                        $parsed = json_decode($note->detail_json);
+                        $isBad = $parsed && @$parsed->isBad;
+			            $isGood = $parsed && @$parsed->isGood;
+                    }
+                    ?>
+                    @if(!$isBad)
+                        <div moe relative>
+                            <a href="#" start show  class="print-note ml-2 btn btn-sm btn-danger text-white font-weight-bold invisible"><i class="fa fa-exclamation-triangle"></i> Mark as Bad Note</a>
+                            <form url="/api/note/markNoteAsBad" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <p class="min-width-200px">Mark this note as <b>bad</b>?</p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-success mr-1">Yes</button>
+                                    <button cancel class="btn btn-sm btn-default border">No</button>
+                                </div>
+                            </form>
+                        </div>
+                    @else
+                        <div moe relative>
+                            <a href="#" start show class="print-note ml-2 btn btn-sm btn-info text-white font-weight-bold invisible"><i class="fa fa-undo"></i> Marked as bad! Click to undo.</a>
+                            <form url="/api/note/undoMarkNoteAsBad" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <p class="min-width-200px">Mark this note as <b>not bad</b>?</p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-success mr-1">Yes</button>
+                                    <button cancel class="btn btn-sm btn-default border">No</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+		            @if(!$isGood)
+                        <div moe relative>
+                            <a href="#" start show  class="print-note ml-2 btn btn-sm btn-success text-white font-weight-bold invisible"><i class="fa fa-check"></i> Mark as Good Note</a>
+                            <form url="/api/note/markNoteAsGood" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <p class="min-width-200px">Mark this note as <b>good</b>?</p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-success mr-1">Yes</button>
+                                    <button cancel class="btn btn-sm btn-default border">No</button>
+                                </div>
+                            </form>
+                        </div>
+                    @else
+                        <div moe relative>
+                            <a href="#" start show class="print-note ml-2 btn btn-sm btn-info text-white font-weight-bold invisible"><i class="fa fa-undo"></i> Marked as good! Click to undo.</a>
+                            <form url="/api/note/undoMarkNoteAsGood" class="mcp-theme-1">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <p class="min-width-200px">Mark this note as <b>not good</b>?</p>
+                                <div>
+                                    <button submit class="btn btn-sm btn-success mr-1">Yes</button>
+                                    <button cancel class="btn btn-sm btn-default border">No</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                @endif
+            </div>
+            @if($patient->has_mcp_done_onboarding_visit !== 'YES')
+                <div class="ml-auto">
+                    <div moe relative>
+                        <a start show class="font-weight-bold">Mark as Onboarding Visit Note</a>
+                        <form url="/api/client/updateMcpOnboardingVisitInfo" class="mcp-theme-1" right>
+                            <input type="hidden" name="uid" value="{{$patient->uid}}">
+                            <input type="hidden" name="mcpOnboardingVisitNoteUid" value="{{$note->uid}}">
+                            <input type="hidden" name="hasMcpDoneOnboardingVisit" value="YES">
+                            <input type="hidden" name="mcpOnboardingVisitDate" value="{{$note->effective_dateest}}">
+                            <p class="min-width-200px">Mark this patient's onboarding as completed using this note?</p>
+                            <div>
+                                <button submit class="btn btn-sm btn-success mr-1">Yes</button>
+                                <button cancel class="btn btn-sm btn-default border">No</button>
+                            </div>
+                        </form>
+                    </div>
+
+                </div>
+            @endif
+        </h6>
+    </div>
+
+    <div class="card mb-0 {{ $note->is_cancelled ? 'cancelled-item' : '' }}">
+        <div class="card-header d-flex align-items-start px-3 py-2 border-bottom" id="note-card-header">
+            <div class="pr-2">
+                {{$note->title}}
+                @if(!$note->is_signed_by_hcp || $pro->pro_type === 'ADMIN')
+                <div moe>
+                    <a href="" show start><i class="fa fa-edit"></i></a>
+                    <form url="/api/note/putTitle">
+                        <input type="hidden" name="uid" value="{{$note->uid}}">
+                        <div class="mb-2">
+                            <input type="text" name="title" value="{{$note->title}}" class="form-control form-control-sm"
+                                   placeholder="Title">
+                        </div>
+                        <div class="form-group mb-0">
+                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                        </div>
+                    </form>
+                </div>
+                @endif
+            </div>
+            <div class="px-2 border-left border-right">
+                <div class="d-flex">
+                    <span class="mr-2">{{friendly_date_time($note->effective_dateest, false, '')}}</span>
+                    @if(!$note->is_signed_by_hcp || $pro->pro_type === 'ADMIN')
+                    <span moe class="ml-auto">
+                        <a href="" show start><i class="fa fa-calendar"></i></a>
+                        <form url="/api/note/putEffectiveDateEST">
+                            <input type="hidden" name="uid" value="{{$note->uid}}">
+                            <div class="mb-2">
+                                <label for="" class="text-secondary text-sm">Effective date EST</label>
+                                <input type="date" name="effectiveDateEST" value="{{$note->effective_dateest}}" class="form-control form-control-sm">
+                            </div>
+                            <div class="mb-0">
+                                <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                            </div>
+                        </form>
+                    </span>
+                    @endif
+                </div>
+            </div>
+
+            {{--<div class="px-2 border-left border-right">
+                <div class="d-flex">
+                    <span class="mr-2">{{friendly_time($note->effective_time, '')}}</span>
+                    @if(!$note->is_signed_by_hcp)
+                        <span moe class="ml-auto">
+                            <a href="" show start><i class="fa fa-clock"></i></a>
+                            <form url="/api/note/putEffectiveTime">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <div class="mb-2">
+                                    <label for="" class="text-secondary text-sm">Effective time </label>
+                                    <input type="time" name="effectiveTime" value="{{ date("H:i", strtotime($note->effective_time)) }}" class="form-control form-control-sm">
+                                </div>
+                                <div class="mb-0">
+                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </span>
+                    @endif
+                </div>
+            </div>--}}
+
+            <div class="px-2 border-right">
+                <div class="d-flex">
+                    <span class="mr-2"><span class="text-secondary">HCP:</span> {{$note->hcpPro->name_display}}</span>
+                    @if(!$note->is_signed_by_hcp || $pro->pro_type === 'ADMIN')
+                    <div moe class="ml-auto">
+                        <a href="" show start><i class="fa fa-edit"></i></a>
+                        <form url="/api/note/putHcp">
+                            <input type="hidden" name="uid" value="{{$note->uid}}">
+                            <div class="mb-2">
+                                <select provider-search data-pro-uid="{{ @$note->hcpPro->uid }}"
+                                        name="hcpProUid" class="form-control form-control-sm">
+                                    <option value="">-- Select HCP Pro --</option>
+                                </select>
+                            </div>
+                            <div class="mb-0">
+                                <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                            </div>
+                        </form>
+                    </div>
+                    @endif
+                </div>
+            </div>
+
+
+            @if($performer->pro->pro_type == 'ADMIN' || ($note->allyPro && $note->allyPro->uid === $performer->pro->uid))
+                <span class="px-2 border-right d-flex">
+                    @if($note->allyPro)
+                        <span class="mr-2"><span class="text-secondary">NA:</span>  {{$note->allyPro->name_first}} {{$note->allyPro->name_last}}</span>
+                        @if($performer->pro->pro_type == 'ADMIN')
+                            <span class="d-inline-block" moe>
+                                <a class="text-danger" href="" show start>
+                                    <i class="fa fa-times"></i>
+                                </a>
+                                <form url="/api/note/removeNa">
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <p>Remove NA?</p>
+                                    <div class="mb-0">
+                                        <button class="btn btn-success btn-sm" submit>Submit</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </span>
+                        @endif
+                    @else
+                        <span class="mr-2"><span class="text-secondary">NA:</span> - </span>
+                        <span class="d-block" moe>
+                            <a class="" href="" show start>
+                                <i class="fa fa-edit"></i>
+                            </a>
+                            <form url="/api/note/putNa">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <div class="form-group">
+                                    <label for="" class="control-label">NA</label>
+                                    <select provider-search
+                                            name="naProUid" class="form-control form-control-sm">
+                                        <option value="">-- Select Ally Pro --</option>
+                                    </select>
+                                </div>
+                                <div class="mb-0">
+                                    <button class="btn btn-success btn-sm" submit>Submit</button>
+                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </span>
+                    @endif
+
+                </span>
+            @endif
+
+
+            <div class="px-2 border-right">
+                <div class="d-flex">
+                    <span class="mr-2"><span class="text-secondary">Type:</span> {{$note->new_or_fu_or_na ? ($note->new_or_fu_or_na === 'NEW' ? 'New Patient' : $note->new_or_fu_or_na) : '-'}}</span>
+                    @if(!$note->is_signed_by_hcp || $pro->pro_type === 'ADMIN')
+                        <div moe class="ml-auto">
+                            <a href="" show start><i class="fa fa-edit"></i></a>
+                            <form url="/api/note/updateNewOrFuOrNa">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <div class="mb-2">
+                                    <select name="newOrFuOrNa" class="form-control form-control-sm" required>
+                                        <option value="">-- select --</option>
+                                        <option value="NEW" {{ $note->new_or_fu_or_na === "NEW" ? "selected" : "" }}>New</option>
+                                        <option value="FU" {{ $note->new_or_fu_or_na === "FU" ? "selected" : "" }}>Follow-up</option>
+                                        <option value="NA" {{ $note->new_or_fu_or_na === "NA" ? "selected" : "" }}>N/A</option>
+                                    </select>
+                                </div>
+                                <div class="mb-0">
+                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                </div>
+            </div>
+
+            <div class="px-2">
+                <div class="d-flex">
+                    <span class="mr-2"><span class="text-secondary">Method:</span> {{$note->method ? $note->method : '-'}}</span>
+                    @if(!$note->is_signed_by_hcp || $pro->pro_type === 'ADMIN')
+                        <div moe class="ml-auto">
+                            <a href="" show start><i class="fa fa-edit"></i></a>
+                            <form url="/api/note/updateMethod">
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <div class="mb-2">
+                                    <select name="method" class="form-control form-control-sm note-method-select" required>
+                                        <option value="AUDIO" {{ $note->method === "AUDIO" ? "selected" : "" }}>Audio</option>
+                                        <option value="VIDEO" {{ $note->method === "VIDEO" ? "selected" : "" }}>Video</option>
+                                        <option value="IN_CLINIC" {{ $note->method === "IN_CLINIC" ? "selected" : "" }}>In-Clinic</option>
+                                        <option value="HOUSE_CALL" {{ $note->method === "HOUSE_CALL" ? "selected" : "" }}>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->id === $note->hcp_company_location_id ? 'selected' : ''}}>{{$location->line1}} {{$location->city}}</option>
+                                        @endforeach
+                                    </select>
+                                </div>
+                                <div class="mb-0">
+                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </div>
+                    @endif
+                </div>
+            </div>
+
+            <div class="ml-auto d-flex align-items-start">
+                <div class="">
+                    <div>
+                        @if($note->is_signed_by_hcp)
+                            <span class="text-secondary">
+                        <i class="fa fa-check"></i>
+                        Note Signed
+                        @if($pro->pro_type == 'ADMIN')
+                        <span moe class="ml-2 d-none">
+                            <a class="" href="" show start>Undo sign?</a>
+                            <form url="/api/note/adminUndoSignAsHcp" right>
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <p>Undo sign?</p>
+                                <div class="mb-0">
+                                    <button class="btn btn-success btn-sm" submit>Submit</button>
+                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                </div>
+                            </form>
+                        </span>
+                        @endif
+                    </span>
+                        @else
+                            <div moe
+                                 class="{{ $note->hcp_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                 title="{{ $note->hcp_pro_id !== $pro->id ? 'Only the note\'s HCP can sign' : '' }}">
+                                <a class="" href="" show start>Sign Note As HCP</a>
+                                <form url="/api/note/signAsHcp" right>
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <p>Sign this note as HCP?</p>
+                                    <div class="mb-0">
+                                        <button class="btn btn-success btn-sm" submit>Sign</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @endif
+                    </div>
+                </div>
+                @if($note->allyPro)
+                <div class="mx-4">
+                    <div>
+                        @if($note->is_signed_by_ally)
+                            <span class="text-secondary">
+                        <i class="fa fa-check"></i>
+                        Note Signed By NA
+                    </span>
+                        @else
+                            <div moe
+                                 class="{{ $note->ally_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                 title="{{ $note->ally_pro_id !== $pro->id ? 'Only the note\'s Ally can sign' : '' }}">
+                                <a class="" href="" show start>Sign Note As NA</a>
+                                <form url="/api/note/signAsAlly" right>
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <p>Sign this NA?</p>
+                                    <div class="mb-0">
+                                        <button class="btn btn-success btn-sm" submit>Sign</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </div>
+                        @endif
+                    </div>
+                </div>
+                @endif
+                @if($note->is_cancelled || (!$note->is_cancelled && !$note->is_signed_by_hcp))
+                <div class="ml-2 pl-2 border-left">
+                    <div class="d-flex justify-content-end">
+                        @if(!$note->is_cancelled)
+                        <div moe relatve
+                             class="{{ $hasBills ? 'moe-disabled' : '' }}"
+                             title="{{ $hasBills ? 'Cannot cancel note since it has un-cancelled bills in it' : '' }}">
+                            <a class="text-danger" href="" show start>Cancel</a>
+                            <form url="/api/note/cancel" right>
+                                <input type="hidden" name="uid" value="{{$note->uid}}">
+                                <p class="small mb-2">Are you sure you want to cancel this note?</p>
+                                <div class="mb-2">
+                                    <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="memo-textarea form-control form-control-sm"></textarea>
+                                </div>
+                                <div class="d-flex align-items-center">
+                                    <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
+                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
+                                </div>
+                            </form>
+                        </div>
+                        @else
+                            <span class="text-secondary font-weight-bold">CANCELLED</span>
+                        @endif
+                    </div>
+                </div>
+                @endif
+
+            </div>
+        </div>
+        <div class="card-body p-0">
+            <div class="note-container">
+                <div class="note-lhs-tree" id="note-lhs-tree">
+                    <?php
+                    $previousHeading = null;
+                    $sectionTemplates = $note->noteTemplate->sectionTemplatesRaw();
+                    ?>
+                    @foreach($sectionTemplates as $sectionTemplate)
+                        <?php
+                        if($sectionTemplate->heading !== $previousHeading) {
+                            if(!empty($previousHeading)) {
+                                echo '</div></div>'; // <!-- end the previous parent section -->
+                            }
+                            if(!empty($sectionTemplate->heading)) {
+                                echo '<div class="note-tree-node note-tree-heading">' .
+                                        '<a class="">' . $sectionTemplate->heading . '</a>' .
+                                        '<div class="note-tree-children">'; // <!-- open new node -->
+                            }
+                            $previousHeading = $sectionTemplate->heading;
+                        }
+                        echo '<div class="note-tree-node">' .
+                            '<a native target="_top" data-section-template-name="' . $sectionTemplate->internal_name . '" href="#" >' . $sectionTemplate->title . '</a>' .
+                            '</div>';
+                        ?>
+                    @endforeach
+                    <?php
+                    if(!empty($previousHeading)) {
+                        echo '</div></div>'; // <!-- close any open parent section -->
+                    }
+                    ?>
+                </div>
+                <div class="note-rhs-content">
+                    <div>
+                        <div class="">
+                            <div>
+                                <?php
+                                $shortCutsObject = [];
+                                foreach ($pro->allShortcuts() as $shortcut) {
+
+                                    // %replaceables%
+                                    $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
+                                    $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
+                                    $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);
+
+                                    $shortCutsObject[] = [
+                                        "name" => $shortcut->shortcut,
+                                        "value" => $shortcut->text
+                                    ];
+                                }
+                                ?>
+                                <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>
+                                <?php
+                                $shortcuts = "";
+                                $latestSectionTS = 0;
+                                ?>
+                                <div class="{{ $note->is_signed_by_hcp ? 'note-signed-by-hcp' : '' }}">
+                                    @include('app.patient.note.note-section-list')
+                                </div>
+                            </div>
+                        </div>
+
+                        <span class="d-none latest-section-ts">{{ $latestSectionTS }}</span>
+
+                        <div class="p-3 border-bottom">
+                            <div class="">
+                                <div class="d-flex align-items-center mb-2">
+                                    <p class="font-weight-bold text-secondary m-0 font-size-14">ERx/Orders Summary</p>
+                                    <span class="mx-2 text-secondary screen-only">|</span>
+                                    <a href="/patients/view/{{$patient->uid}}/tickets/erx/create?popupmode=1&note-uid={{$note->uid}}"
+                                       native target="_blank"
+                                       class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
+                                        + ERx
+                                    </a>
+                                    <span class="mx-2 text-secondary screen-only">|</span>
+                                    <a href="/patients/view/{{$patient->uid}}/tickets/lab/create?popupmode=1&note-uid={{$note->uid}}"
+                                       native target="_blank"
+                                       class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
+                                        + Lab
+                                    </a>
+                                    <span class="mx-2 text-secondary screen-only">|</span>
+                                    <a href="/patients/view/{{$patient->uid}}/tickets/imaging/create?popupmode=1&note-uid={{$note->uid}}"
+                                       native target="_blank"
+                                       class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
+                                        + Imaging
+                                    </a>
+                                    <span class="mx-2 text-secondary screen-only">|</span>
+                                    <a href="/patients/view/{{$patient->uid}}/tickets/other/create?popupmode=1&note-uid={{$note->uid}}"
+                                       native target="_blank"
+                                       class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
+                                        + Other
+                                    </a>
+                                </div>
+
+                                <div class="p-3 border">
+
+                                    <p class="font-weight-bold text-secondary mb-2 mr-2">Associated with this note</p>
+                                    <div>
+                                        @if($ticketsOnNote && count($ticketsOnNote))
+                                            <table class="table table-sm table-bordered mb-0">
+                                                <thead>
+                                                <tr class="bg-light">
+                                                    <th class="px-2 text-secondary border-bottom-0 width-30px">Created</th>
+                                                    <th class="px-2 text-secondary border-bottom-0 width-30px">Type</th>
+                                                    <th class="px-2 text-secondary border-bottom-0 width-30px">Pro</th>
+                                                    <th class="px-2 text-secondary border-bottom-0 width-30px">View</th>
+                                                    <th class="px-2 text-secondary border-bottom-0 width-30px">Status</th>
+                                                    <th class="px-2 text-secondary border-bottom-0">Detail</th>
+                                                </tr>
+                                                </thead>
+                                                <tbody>
+                                                @foreach($ticketsOnNote as $ticket)
+                                                    <?php $data = json_decode($ticket->data); ?>
+                                                    @if($ticket->category === 'erx' || $ticket->category === 'lab' || $ticket->category === 'imaging')
+                                                        <tr class="{{$ticket->is_open ? '' : 'bg-light on-hover-opaque'}}">
+                                                            <td class="px-2 text-nowrap">
+                                                                {{friendly_time($ticket->created_at)}}
+                                                            </td>
+                                                            <td class="px-2 text-nowrap">
+                                                                {{$ticket->category}}
+                                                            </td>
+                                                            <td class="px-2 text-nowrap">
+                                                                @if($ticket->orderingPro)
+                                                                    @if($ticket->orderingPro->id !== $pro->id)
+                                                                        <b>{{$ticket->orderingPro->displayName()}}</b>
+                                                                    @else
+                                                                        You
+                                                                    @endif
+                                                                @else
+                                                                    -
+                                                                @endif
+                                                            </td>
+                                                            <td class="px-2 text-nowrap">
+                                                                <div class="d-flex align-items-center flex-nowrap">
+                                                                    <a href="/patients/view/{{$ticket->patient->uid}}/tickets/{{$ticket->category}}/{{$ticket->uid}}?popupmode=1"
+                                                                       native target="_blank"
+                                                                       class="ticket-popup-trigger note-dashboard-action d-block text-nowrap mr-3">
+                                                                        View
+                                                                    </a>
+                                                                </div>
+                                                            </td>
+                                                            <td class="px-2 text-nowrap">
+                                                                {{$ticket->is_open ? 'Open' : 'Closed'}}
+                                                            </td>
+                                                            <td class="px-2">
+                                                                @if($ticket->category === 'erx')
+                                                                    <div class="font-size-13 mb-1">{{$data->medication}}</div>
+                                                                    <div class="d-flex align-items-center flex-wrap text-secondary">
+                                                                        @if($data->strength)
+                                                                            <span class="d-inline-flex align-items-center">
+                                                            <span class="mx-2 text-secondary">•</span>
+                                                            <span>{{$data->strength}}</span>
+                                                        </span>
+                                                                        @endif
+                                                                        @if($data->route)
+                                                                            <span class="d-inline-flex align-items-center">
+                                                            <span class="mx-2 text-secondary">•</span>
+                                                            <span>{{$data->route}}</span>
+                                                        </span>
+                                                                        @endif
+                                                                        @if($data->frequency)
+                                                                            <span class="d-inline-flex align-items-center">
+                                                            <span class="mx-2 text-secondary">•</span>
+                                                            <span>{{$data->frequency}}</span>
+                                                        </span>
+                                                                        @endif
+                                                                        @if($data->dispense)
+                                                                            <span class="d-inline-flex align-items-center">
+                                                            <span class="mx-2 text-secondary">•</span>
+                                                            <span>Dispense:</span> {{$data->dispense}}
+                                                        </span>
+                                                                        @endif
+                                                                        @if($data->frequency)
+                                                                            <span class="d-inline-flex align-items-center">
+                                                            <span class="mx-2 text-secondary">•</span>
+                                                            <span><span>Refills:</span> {{$data->refills}}</span>
+                                                        </span>
+                                                                        @endif
+                                                                        @if($data->dispense)
+                                                                            <span class="d-inline-flex align-items-center">
+                                                            <span class="mx-2 text-secondary">•</span>
+                                                            <span><span>Purpose:</span> {{$data->purpose}}</span>
+                                                        </span>
+                                                                        @endif
+                                                                    </div>
+                                                                @endif
+                                                                @if($ticket->category === 'lab' || $ticket->category === 'imaging')
+                                                                    @if(@$data->tests && is_array($data->tests))
+                                                                        <div>
+                                                                            <span class="text-secondary">Tests:</span>
+                                                                            {{implode(", ", $data->tests)}}
+                                                                        </div>
+                                                                    @endif
+                                                                    @if(@$data->icds && is_array($data->icds))
+                                                                        <div>
+                                                                            <span class="text-secondary">ICDs:</span>
+                                                                            {{implode(", ", $data->icds)}}
+                                                                        </div>
+                                                                    @endif
+                                                                @endif
+                                                            </td>
+                                                        </tr>
+                                                    @endif
+                                                @endforeach
+                                                </tbody>
+                                            </table>
+                                        @else
+                                            <div class="text-secondary">None</div>
+                                        @endif
+                                    </div>
+
+                                    <hr class="my-2">
+
+                                    <p class="font-weight-bold text-secondary mb-2 mr-2">Others open as of {{friendlier_date(date('Y-m-d'))}}</p>
+                                    @if($otherOpenTickets && count($otherOpenTickets))
+                                        <table class="table table-sm table-bordered mb-0">
+                                            <thead>
+                                            <tr class="bg-light">
+                                                <th class="px-2 text-secondary border-bottom-0 width-30px">Created</th>
+                                                <th class="px-2 text-secondary border-bottom-0 width-30px">Type</th>
+                                                <th class="px-2 text-secondary border-bottom-0 width-30px">Pro</th>
+                                                <th class="px-2 text-secondary border-bottom-0 width-30px">View</th>
+                                                <th class="px-2 text-secondary border-bottom-0 width-30px">Status</th>
+                                                <th class="px-2 text-secondary border-bottom-0">Detail</th>
+                                            </tr>
+                                            </thead>
+                                            <tbody>
+                                            @foreach($otherOpenTickets as $ticket)
+                                                <?php $data = json_decode($ticket->data); ?>
+                                                @if($ticket->category === 'erx' || $ticket->category === 'lab' || $ticket->category === 'imaging' || $ticket->category === 'other')
+                                                    <tr class="{{$ticket->is_open ? '' : 'bg-light on-hover-opaque'}}">
+                                                        <td class="px-2 text-nowrap">
+                                                            {{friendly_time($ticket->created_at)}}
+                                                        </td>
+                                                        <td class="px-2 text-nowrap">
+                                                            {{$ticket->category}}
+                                                        </td>
+                                                        <td class="px-2 text-nowrap">
+                                                            @if($ticket->orderingPro)
+                                                                @if($ticket->orderingPro->id !== $pro->id)
+                                                                    <b>{{$ticket->orderingPro->displayName()}}</b>
+                                                                @else
+                                                                    You
+                                                                @endif
+                                                            @else
+                                                                -
+                                                            @endif
+                                                        </td>
+                                                        <td class="px-2 text-nowrap">
+                                                            <div class="d-flex align-items-center flex-nowrap">
+                                                                <a href="/patients/view/{{$ticket->patient->uid}}/tickets/{{$ticket->category}}/{{$ticket->uid}}?popupmode=1"
+                                                                   native target="_blank"
+                                                                   class="ticket-popup-trigger note-dashboard-action d-block text-nowrap mr-3">
+                                                                    View
+                                                                </a>
+                                                            </div>
+                                                        </td>
+                                                        <td class="px-2 text-nowrap">
+                                                            {{$ticket->is_open ? 'Open' : 'Closed'}}
+                                                        </td>
+                                                        <td class="px-2">
+                                                            @if($ticket->category === 'erx')
+                                                                <div class="font-size-13 mb-1">{{$data->medication}}</div>
+                                                                <div class="d-flex align-items-center flex-wrap text-secondary">
+                                                                    @if($data->strength)
+                                                                        <span class="d-inline-flex align-items-center">
+                                                                            <span class="mx-2 text-secondary">•</span>
+                                                                            <span>{{$data->strength}}</span>
+                                                                        </span>
+                                                                    @endif
+                                                                    @if($data->route)
+                                                                        <span class="d-inline-flex align-items-center">
+                                                                            <span class="mx-2 text-secondary">•</span>
+                                                                            <span>{{$data->route}}</span>
+                                                                        </span>
+                                                                    @endif
+                                                                    @if($data->frequency)
+                                                                        <span class="d-inline-flex align-items-center">
+                                                                            <span class="mx-2 text-secondary">•</span>
+                                                                            <span>{{$data->frequency}}</span>
+                                                                        </span>
+                                                                    @endif
+                                                                    @if($data->dispense)
+                                                                        <span class="d-inline-flex align-items-center">
+                                                                            <span class="mx-2 text-secondary">•</span>
+                                                                            <span>Dispense:</span> {{$data->dispense}}
+                                                                        </span>
+                                                                    @endif
+                                                                    @if($data->frequency)
+                                                                        <span class="d-inline-flex align-items-center">
+                                                                            <span class="mx-2 text-secondary">•</span>
+                                                                            <span><span>Refills:</span> {{$data->refills}}</span>
+                                                                        </span>
+                                                                    @endif
+                                                                    @if($data->dispense)
+                                                                        <span class="d-inline-flex align-items-center">
+                                                                            <span class="mx-2 text-secondary">•</span>
+                                                                            <span><span>Purpose:</span> {{$data->purpose}}</span>
+                                                                        </span>
+                                                                    @endif
+                                                                </div>
+                                                            @endif
+                                                            @if($ticket->category === 'lab' || $ticket->category === 'imaging')
+                                                                @if(@$data->tests && is_array($data->tests))
+                                                                    <div>
+                                                                        <span class="text-secondary">Tests:</span>
+                                                                        {{implode(", ", $data->tests)}}
+                                                                    </div>
+                                                                @endif
+                                                                @if(@$data->icds && is_array($data->icds))
+                                                                    <div>
+                                                                        <span class="text-secondary">ICDs:</span>
+                                                                        {{implode(", ", $data->icds)}}
+                                                                    </div>
+                                                                @endif
+                                                            @endif
+                                                            @if($ticket->category === 'other')
+                                                                <div>
+                                                                    {{$data->title}}
+                                                                </div>
+                                                            @endif
+                                                        </td>
+                                                    </tr>
+                                                @endif
+                                            @endforeach
+                                            </tbody>
+                                        </table>
+                                    @else
+                                        <div class="text-secondary">None</div>
+                                    @endif
+
+                                </div>
+
+                            </div>
+                        </div>
+
+                        <div class="p-3 border-bottom">
+                            <div class="">
+                                <div class="d-flex align-items-center mb-2">
+                                    <p class="font-weight-bold text-secondary m-0 font-size-14">Supply Orders Summary</p>
+                                    <span class="mx-2 text-secondary screen-only">|</span>
+                                    <a native target="_blank"
+                                       class="screen-only"
+                                       open-in-stag-popup
+                                       update-parent
+                                       mc-initer="patient-supply-orders"
+                                       title="{{$patient->displayName()}} - Supply Orders"
+                                       href="/patients/view/{{$patient->uid}}/supply-orders?popupmode=1&note-uid={{$note->uid}}&filter=active">
+                                        Manage Supply Orders
+                                    </a>
+                                </div>
+
+                                <div class="p-3 border">
+
+                                    <p class="font-weight-bold text-secondary mb-2 mr-2">Associated with this note</p>
+                                    <div>
+                                        @if($supplyOrdersOnNote && count($supplyOrdersOnNote))
+                                            <table class="table table-sm table-bordered mb-0">
+                                                <thead>
+                                                <tr class="bg-light">
+                                                    <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Title</div></th>
+                                                    <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Reason</div></th>
+                                                    <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Created At</div></th>
+                                                    <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Pro Signed?</div></th>
+                                                    <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Cancelled?</div></th>
+                                                    <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Shipment</div></th>
+                                                </tr>
+                                                </thead>
+                                                <tbody>
+                                                @foreach($supplyOrdersOnNote as $iSupplyOrder)
+                                                    <tr class="">
+                                                        <td class="px-2">
+                                                            {{ $iSupplyOrder->product->title }}
+                                                        </td>
+                                                        <td class="px-2">{{ $iSupplyOrder->reason }}</td>
+                                                        <td class="px-2">{{ friendlier_date_time($iSupplyOrder->created_at) }}</td>
+                                                        <td class="px-2">{{ $iSupplyOrder->is_signed_by_pro ? $iSupplyOrder->signedPro->displayName() : '-' }}</td>
+                                                        <td class="px-2">{{ $iSupplyOrder->is_cancelled ? 'Yes' : 'No' }}</td>
+                                                        <td class="px-2">
+                                                            @if($iSupplyOrder->shipment_id)
+                                                                <i class="fa fa-building"></i>
+                                                                {{$iSupplyOrder->shipment->status ? $iSupplyOrder->shipment->status : 'CREATED'}}
+                                                            @elseif($iSupplyOrder->is_cleared_for_shipment)
+                                                                <span class="text-info">
+                                                            <i class="fa fa-user-nurse"></i>
+                                                            Cleared for shipment
+                                                        </span>
+                                                            @else
+                                                                <span class="text-warning-mellow">
+                                                            <i class="fa fa-user-nurse"></i>
+                                                            Not cleared for shipment
+                                                        </span>
+                                                            @endif
+                                                        </td>
+                                                    </tr>
+                                                @endforeach
+                                                </tbody>
+                                            </table>
+                                        @else
+                                            <div class="text-secondary">None</div>
+                                        @endif
+                                    </div>
+
+                                    <hr class="my-2">
+
+                                    <p class="font-weight-bold text-secondary mb-2 mr-2">Others as of {{friendlier_date(date('Y-m-d'))}}</p>
+                                    @if($otherOpenSupplyOrders && count($otherOpenSupplyOrders))
+                                        <table class="table table-sm table-bordered mb-0">
+                                            <thead>
+                                            <tr class="bg-light">
+                                                <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Title</div></th>
+                                                <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Reason</div></th>
+                                                <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Created At</div></th>
+                                                <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Pro Signed?</div></th>
+                                                <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Cancelled?</div></th>
+                                                <th class="px-2 text-nowrap text-secondary border-bottom-0"><div class="text-ellipsis">Shipment</div></th>
+                                            </tr>
+                                            </thead>
+                                            <tbody>
+                                            @foreach($otherOpenSupplyOrders as $iSupplyOrder)
+                                                <tr class="">
+                                                    <td class="px-2">
+                                                        {{ $iSupplyOrder->product->title }}
+                                                    </td>
+                                                    <td class="px-2">{{ $iSupplyOrder->reason }}</td>
+                                                    <td class="px-2">{{ friendlier_date_time($iSupplyOrder->created_at) }}</td>
+                                                    <td class="px-2">{{ $iSupplyOrder->is_signed_by_pro ? $iSupplyOrder->signedPro->displayName() : '-' }}</td>
+                                                    <td class="px-2">{{ $iSupplyOrder->is_cancelled ? 'Yes' : 'No' }}</td>
+                                                    <td class="px-2">
+                                                        @if($iSupplyOrder->shipment_id)
+                                                            <i class="fa fa-building"></i>
+                                                            {{$iSupplyOrder->shipment->status ? $iSupplyOrder->shipment->status : 'CREATED'}}
+                                                        @elseif($iSupplyOrder->is_cleared_for_shipment)
+                                                            <span class="text-info">
+                                                            <i class="fa fa-user-nurse"></i>
+                                                            Cleared for shipment
+                                                        </span>
+                                                        @else
+                                                            <span class="text-warning-mellow">
+                                                            <i class="fa fa-user-nurse"></i>
+                                                            Not cleared for shipment
+                                                        </span>
+                                                        @endif
+                                                    </td>
+                                                </tr>
+                                            @endforeach
+                                            </tbody>
+                                        </table>
+                                    @else
+                                        <div class="text-secondary">None</div>
+                                    @endif
+
+                                </div>
+
+                            </div>
+                        </div>
+
+                        <div class="p-3 border-bottom">
+                            <div class="">
+                                <div class="d-flex align-items-center mb-2">
+                                    <p class="font-weight-bold text-secondary m-0 mr-2">ICDs</p>
+                                    @include('app/patient/note/_create-note-reason')
+                                </div>
+                                <div class="d-flex align-items-start flex-wrap">
+                                    @if(count($note->reasons))
+                                        @foreach ($note->reasons as $reason)
+                                            <span class="badge badge-info p-2 mb-2 mr-2">
+                                    {{ $reason->description}} ({{ $reason->code }})
+                                </span>
+                                        @endforeach
+                                    @else
+                                        <div class="alert alert-info">No note reasons</div>
+                                    @endif
+                                </div>
+                            </div>
+                        </div>
+                        @if($pro->pro_type === 'ADMIN')
+                            <div class="p-3 border-bottom screen-only">
+                                <div>
+                                    <h2 class="font-weight-bold text-secondary">Bills & Claims Summary</h2>
+                                    <div class="d-flex justify-content-center align-items-start">
+                                        <table class="w-25 flex-grow-1 table-bordered table-condensed table-sm table-striped">
+                                            <tbody>
+                                            <tr>
+                                                <td class="text-secondary">Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Is Billing Closed</td>
+                                                <td>{{$note->is_bill_closed ? 'Yes' : 'No'}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Bill Summary</td>
+                                                <td>{{$note->bill_summary ? $note->bill_summary : '-'}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Bill Total Paid</td>
+                                                <td>${{friendly_money($note->bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Billing Closed At</td>
+                                                <td>{{friendlier_date_time($note->bill_closed_at)}}</td>
+                                            </tr>
+                                            </tbody>
+                                        </table>
+                                        <table class="w-25 flex-grow-1 table-bordered table-condensed table-sm table-striped ml-2">
+                                            <tbody>
+                                            <tr>
+                                                <td class="text-secondary">Claim Total Exp.</td>
+                                                <td>${{friendly_money($note->claim_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Is Claiming Closed</td>
+                                                <td>{{$note->is_claim_closed ? 'Yes' : 'No'}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Claim Summary</td>
+                                                <td>{{$note->claim_summary ? $note->claim_summary : '-'}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Claim Total Paid</td>
+                                                <td>${{friendly_money($note->claim_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">Claiming Closed At</td>
+                                                <td>{{$note->claim_closed_at ? friendlier_date_time($note->claim_closed_at) : '-'}}</td>
+                                            </tr>
+                                            </tbody>
+                                        </table>
+                                        <table class="w-25 flex-grow-1 table-bordered table-condensed table-sm table-striped ml-2">
+                                            <tbody>
+                                            <tr>
+                                                <td class="text-secondary">HCP Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->hcp_bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">NA Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->na_bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RMM Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->rmm_bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RME Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->rme_bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RMS Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->rms_bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RMG Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->rmg_bill_total_expected)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">CM Bill Total Exp.</td>
+                                                <td>${{friendly_money($note->cm_bill_total_expected)}}</td>
+                                            </tr>
+                                            </tbody>
+                                        </table>
+                                        <table class="w-25 flex-grow-1 table-bordered table-condensed table-sm table-striped ml-2">
+                                            <tbody>
+                                            <tr>
+                                                <td class="text-secondary">HCP Bill Total Paid</td>
+                                                <td>${{friendly_money($note->hcp_bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">NA Bill Total Paid</td>
+                                                <td>${{friendly_money($note->na_bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RMM Bill Total Paid</td>
+                                                <td>${{friendly_money($note->rmm_bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RME Bill Total Paid</td>
+                                                <td>${{friendly_money($note->rme_bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RMS Bill Total Paid</td>
+                                                <td>${{friendly_money($note->rms_bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">RMG Bill Total Paid</td>
+                                                <td>${{friendly_money($note->rmg_bill_total_paid)}}</td>
+                                            </tr>
+                                            <tr>
+                                                <td class="text-secondary">CM Bill Total Paid</td>
+                                                <td>${{friendly_money($note->cm_bill_total_paid)}}</td>
+                                            </tr>
+                                            <!--                                <tr>
+                                    <td class="text-secondary">HCP Company Pro</td>
+                                    <td>{{$note->hcp_company_pro_id}}</td>
+                                </tr>-->
+                                            </tbody>
+                                        </table>
+                                    </div>
+                                </div>
+                            </div>
+                        @endif
+
+                        @if($note->method === 'IN_CLINIC' || $pro->pro_type === 'ADMIN')
+                            <div class="p-3 border-bottom screen-only">
+                                <div class="ml-auto d-inline-flex align-items-center">
+
+                                    <span class="text-secondary font-weight-bold">Pro:&nbsp;</span>
+                                    <b>{{$note->hcpPro ? $note->hcpPro->displayName() : '-'}}</b>
+
+                                    <span class="mx-2 text-secondary">|</span>
+                                    <span>
+                            <span class="text-secondary font-weight-bold">Payer 1°: </span>
+                            <b>
+                                {{$note->hcpCompanyProPayer && $note->hcpCompanyProPayer->company ? $note->hcpCompanyProPayer->company->name : '-'}}
+                                /
+                                {{$note->hcpCompanyProPayer && $note->hcpCompanyProPayer->payer ? $note->hcpCompanyProPayer->payer->name : '-'}}
+                            </b>
+                            <span moe class="ml-1">
+                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
+                                <form url="/api/note/putHcpCompanyProPayer">
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <div class="mb-2">
+                                        <select name="hcpCompanyProPayerUid" class="form-control form-control-sm">
+                                            <option value="">-- select --</option>
+                                            @foreach($note->hcpPro->companyProPayers as $companyProPayer)
+                                                <option value="{{$companyProPayer->uid}}">{{$companyProPayer->company->name}} / {{$companyProPayer->payer->name}}</option>
+                                            @endforeach
+                                        </select>
+                                    </div>
+                                    <div class="mb-0">
+                                        <button class="btn btn-success btn-sm" submit>Submit</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </span>
+                            @if($note->hcpCompanyProPayer && $note->hcpCompanyProPayer->payer)
+                                            <span moe class="ml-1">
+                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                <form url="/api/note/wipeHcpCompanyProPayer">
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <p>Wipe payer from this note?</p>
+                                    <div class="mb-0">
+                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </span>
+                                        @endif
+                        </span>
+
+                                    <span class="mx-2 text-secondary">|</span>
+                                    <span>
+                            <span class="text-secondary font-weight-bold">Payer 2°: </span>
+                        </span>
+
+                                    <span class="mx-2 text-secondary">|</span>
+                                    <span>
+                            <span class="text-secondary font-weight-bold">Location: </span><b>{{$note->hcpCompanyLocation ? $note->hcpCompanyLocation->line1 . ', ' . $note->hcpCompanyLocation->city : '-'}}</b>
+                            <span moe class="ml-1">
+                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
+                                <form url="/api/note/putHcpCompanyLocation">
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <div class="mb-2">
+                                        <select name="hcpCompanyLocationUid" class="form-control form-control-sm">
+                                            <option value="">-- select --</option>
+                                            @if($note->hcpCompany && $note->hcpCompany->locations)
+                                                @foreach($note->hcpCompany->locations as $location)
+                                                    <option value="{{$location->uid}}">{{$location->line1 . ', ' . $location->city}}</option>
+                                                @endforeach
+                                            @endif
+                                        </select>
+                                    </div>
+                                    <div class="mb-0">
+                                        <button class="btn btn-success btn-sm" submit>Submit</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </span>
+                            @if($note->hcpCompanyLocation)
+                                            <span moe class="ml-1">
+                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                <form url="/api/note/wipeHcpCompanyLocation">
+                                    <input type="hidden" name="uid" value="{{$note->uid}}">
+                                    <p>Wipe location from this note?</p>
+                                    <div class="mb-0">
+                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                    </div>
+                                </form>
+                            </span>
+                                        @endif
+                        </span>
+                                </div>
+                            </div>
+                        @endif
+
+                        {{-- bills --}}
+                        @if($pro->pro_type === 'ADMIN' || ($note->hcpPro && $pro->id === $note->hcpPro->id) || ($note->allyPro && $pro->id === $note->allyPro->id))
+                            @if($note->bills->count())
+                                <div class="p-3 border-bottom">
+                                    <div class="d-flex align-items-center mb-2">
+                                        <p class="font-weight-bold text-secondary font-size-13 m-0">Bills</p>
+                                        @if($pro->pro_type === 'ADMIN' || ($note->hcpPro && $pro->id === $note->hcpPro->id))
+                                            @include('app/patient/note/_create-bill')
+                                        @endif
+                                    </div>
+
+                                    @if($pro->pro_type === 'ADMIN')
+                                        <table class="table table-sm tabe-striped mb-0 table-bordered">
+                                            <thead class="bg-light">
+                                            <tr class="text-secondary">
+                                                <?php /* <th class="border-bottom-0"></th> */ ?>
+                                                <th class="border-bottom-0">Date</th>
+                                                <th class="border-bottom-0">Service</th>
+                                                <th class="border-bottom-0">Billable</th>
+                                                <th class="border-bottom-0">HCP</th>
+                                                <th class="border-bottom-0 screen-only">Total</th>
+                                                <th class="border-bottom-0">Sign</th>
+                                                <th class="border-bottom-0 screen-only">Bal Post Date</th>
+                                                <th class="border-bottom-0">Verification</th>
+                                                <th class="border-bottom-0">Cancellation</th>
+                                                <th class="border-bottom-0 screen-only">Payment</th>
+                                            </tr>
+                                            </thead>
+                                            <tbody>
+                                            @foreach ($note->bills as $bill)
+                                                <tr class="{{$bill->is_cancelled ? 'bg-light text-secondary' : ''}}">
+                                                    <?php /* <td class="p-0">
+                                        <table class="table-striped table-sm table-condensed border border-left-0 border-top-0 border-bottom-0">
+                                            <tbody>
+                                                <tr><td>collected_amount</td><td>{{$bill->collected_amount}}</td></tr>
+                                                <tr><td>effective_date</td><td>{{$bill->effective_date}}</td></tr>
+                                                <tr><td>has_hcp_been_paid</td><td>{{$bill->has_hcp_been_paid}}</td></tr>
+                                                <tr><td>hcp_expected_payment_amount</td><td>{{$bill->hcp_expected_payment_amount}}</td></tr>
+                                                <tr><td>hcp_payment_amount</td><td>{{$bill->hcp_payment_amount}}</td></tr>
+                                                <tr><td>is_cancelled</td><td>{{$bill->is_cancelled}}</td></tr>
+                                                <tr><td>hcp_payment_pro_transaction_id</td><td>{{$bill->hcp_payment_pro_transaction_id}}</td></tr>
+                                                <tr><td>balance_post_date</td><td>{{$bill->balance_post_date}}</td></tr>
+                                                <tr><td>is_verified</td><td>{{$bill->is_verified}}</td></tr>
+                                                <tr><td>is_cancellation_acknowledged</td><td>{{$bill->is_cancellation_acknowledged}}</td></tr>
+                                                <tr><td>is_cancelled_by_administrator</td><td>{{$bill->is_cancelled_by_administrator}}</td></tr>
+                                                <tr><td>total_expected</td><td>{{$bill->total_expected}}</td></tr>
+                                                <tr><td>total_paid</td><td>{{$bill->total_paid}}</td></tr>
+                                            </tbody>
+                                        </table>
+                                    </td> */ ?>
+                                                    <td class="text-nowrap">{{friendlier_date_time($bill->effective_date, false)}}</td>
+                                                    <td>{{$bill->code}}</td>
+                                                    <td class="">
+                                                        @if(strpos(strtolower($bill->code), 'treatment services') !== FALSE)
+                                                            <?php
+                                                            $totalSeconds = $bill->number_of_units * 3600;
+                                                            $remainder = $totalSeconds % 60;
+                                                            if ($remainder !== 0) {
+                                                                if ($remainder < 30) {
+                                                                    $totalSeconds = $totalSeconds - $remainder;
+                                                                }
+                                                                else {
+                                                                    $totalSeconds = $totalSeconds + (60 - $remainder);
+                                                                }
+                                                            }
+                                                            ?>
+                                                            {{ time_in_hrminsec($totalSeconds) }}
+                                                        @else
+                                                            @if(!!$bill->number_of_units)
+                                                                {{ $bill->number_of_units }} unit(s)
+                                                            @else
+                                                                -
+                                                            @endif
+                                                        @endif
+                                                    </td>
+                                                    <td class="">
+                                                        <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->hcp->displayName() }} (HCP)</div>
+                                                        <div class="text-nowrap mt-1 screen-only">
+                                                            <span class="text-secondary">Paid: </span>
+                                                            <span>{{ $bill->has_hcp_been_paid ? 'Yes' : 'No' }}</span>
+                                                        </div>
+                                                        @if(!$bill->has_hcp_been_paid)
+                                                            <div class="text-nowrap mt-1 screen-only">
+                                                                <span class="text-secondary">Expected: </span>
+                                                                <span class="font-weight-bold">${{ $bill->hcp_expected_payment_amount }}</span>
+                                                            </div>
+                                                        @else
+                                                            <div class="text-nowrap mt-1 screen-only">
+                                                                <span class="text-secondary">Amount: </span>
+                                                                <span class="font-weight-bold">${{ $bill->hcp_payment_amount }}</span>
+                                                            </div>
+                                                        @endif
+                                                        @if($bill->ally)
+                                                            <hr>
+                                                            <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->ally->displayName() }} (NA)</div>
+                                                            <div class="text-nowrap mt-1 screen-only">
+                                                                <span class="text-secondary">Paid: </span>
+                                                                <span>{{ $bill->has_na_been_paid ? 'Yes' : 'No' }}</span>
+                                                            </div>
+                                                            @if(!$bill->has_na_been_paid)
+                                                                <div class="text-nowrap mt-1 screen-only">
+                                                                    <span class="text-secondary">Expected: </span>
+                                                                    <span class="font-weight-bold">${{ $bill->na_expected_payment_amount }}</span>
+                                                                </div>
+                                                            @else
+                                                                <div class="text-nowrap mt-1 screen-only">
+                                                                    <span class="text-secondary">Amount: </span>
+                                                                    <span class="font-weight-bold">${{ $bill->na_payment_amount }}</span>
+                                                                </div>
+                                                            @endif
+                                                        @endif
+
+                                                    </td>
+                                                    <td class="pr-3 screen-only">
+                                                        @if($bill->has_hcp_been_paid)
+                                                            <span class="text-secondary">Paid. </span>
+                                                            <span class="font-weight-bold">${{ friendly_money($bill->total_paid) }}</span>
+                                                        @else
+                                                            <span class="text-secondary">Exp. </span>
+                                                            <span class="font-weight-bold">{{ $bill->total_expected ? '$' . friendly_money($bill->total_expected) : '-' }}</span>
+                                                        @endif
+                                                    </td>
+                                                    <td>
+                                                        @if(!$bill->is_cancelled)
+                                                            @if($bill->is_signed_by_hcp)
+                                                                <span class="d-block text-secondary text-nowrap">
+                                                        <i class="fa fa-check"></i>
+                                                        HCP Signed
+                                                    </span>
+                                                            @else
+                                                                <span moe
+                                                                      class="d-block {{ $bill->hcp_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                                                      title="{{ $bill->hcp_pro_id !== $pro->id ? 'Only the bill\'s HCP can sign' : '' }}">
+                                                    <a class="" href="" show start>Sign As HCP</a>
+                                                    <form url="/api/bill/signAsHcp">
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Sign this bill as HCP?</p>
+                                                        <div class="mb-0">
+                                                            <button class="btn btn-success btn-sm" submit>Sign</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @endif
+
+                                                            @if($bill->is_signed_by_na)
+                                                                <span class="d-block text-secondary text-nowrap">
+                                                    <i class="fa fa-check"></i>
+                                                    NA Signed
+                                                </span>
+                                                            @else
+                                                                <span moe
+                                                                      class="d-block {{ $bill->na_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                                                      title="{{ $bill->na_pro_id !== $pro->id ? 'Only the bill\'s NA can sign' : '' }}">
+                                                    <a class="" href="" show start>Sign As NA</a>
+                                                    <form url="/api/bill/signAsNa">
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Sign this bill as NA?</p>
+                                                        <div class="mb-0">
+                                                            <button class="btn btn-success btn-sm" submit>Sign</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @endif
+                                                        @endif
+                                                    </td>
+                                                    <td class="screen-only">
+                                                        @if(!$bill->is_cancelled)
+                                                            <span class="d-block" moe>
+                                                <a class="" href="" show start>
+                                                    {{$bill->balance_post_date ? friendlier_date_time($bill->balance_post_date, false) : '(not set)' }}
+                                                </a>
+                                                <form url="/api/bill/updateBalancePostDate">
+                                                    <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                    <p>Update Balance Post Date</p>
+                                                    <div class="mb-0">
+                                                        <input type="date" class="text form-control form-control-sm" name="balancePostDate" value="{{$bill->balance_post_date}}" placeholder="balance post date"><br>
+                                                        <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                    </div>
+                                                </form>
+                                            </span>
+                                                        @endif
+                                                    </td>
+                                                    <td> <!-- verification -->
+                                                        @if($pro->pro_type === 'ADMIN' && !$bill->is_cancelled)
+                                                            @if(!$bill->is_verified)
+                                                                <div class="text-warning-mellow font-weight-bold">Not Verified</div>
+                                                                <span class="d-block mt-1" moe>
+                                                    <a href="" show start>Mark Verified</a>
+                                                    <form url="/api/bill/markAsVerified">
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Mark As Verfified?</p>
+                                                        <div class="mb-0">
+                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @else
+                                                                <div class="text-success font-weight-bold"><i class="fa fa-check"></i> Verified</div>
+                                                                <span class="d-block mt-1" moe>
+                                                    <a class="" href="" show start>Undo</a>
+                                                    <form url="/api/bill/undoMarkAsVerified">
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Undo Mark As Verfified?</p>
+                                                        <div class="mb-0">
+                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @endif
+                                                        @endif
+                                                    </td>
+                                                    <td>  <!-- cancellation -->
+                                                        @if($bill->is_cancelled)
+                                                            <div class="text-warning-mellow font-weight-bold">Cancelled</div>
+                                                            @if($bill->cancellation_memo)
+                                                                <div class="text-dark text-sm font-italic my-1">{{$bill->cancellation_memo}}</div>
+                                                            @endif
+                                                            @if($bill->is_cancelled_by_administrator)
+                                                                <div class="text-secondary text-sm">(by Administrator)</div>
+                                                            @endif
+                                                            <div moe class="mt-1">
+                                                                <a class="" href="" show start>Update Memo</a>
+                                                                <form url="/api/bill/updateCancellationMemo">
+                                                                    <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                                    <p>Update Cancellation Memo</p>
+                                                                    <div class="mb-2">
+                                                                        <textarea class="text form-control form-control-sm" name="cancellationMemo" placeholder="">{{$bill->cancellation_memo ? $bill->cancellation_memo : 'Insufficient documentation for billable service.'}}</textarea>
+                                                                    </div>
+                                                                    <div>
+                                                                        <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                    </div>
+                                                                </form>
+                                                            </div>
+                                                        @else
+                                                            <span class="d-block" moe relative="">
+                                                <a class="text-danger" href="" show start>Cancel</a>
+                                                <form url="/api/bill/markCancelled" right="">
+                                                    <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                    <p class="mb-2">Cancel this bill?</p>
+                                                    <div class="mb-2">
+                                                        <label class="mb-1 text-secondary">Cancellation Memo</label>
+                                                        <textarea type="text" name="memo" placeholder="Memo" class="form-control form-control-sm">Insufficient documentation for billable service.</textarea>
+                                                    </div>
+                                                    <div class="mb-0">
+                                                        <button class="btn btn-danger btn-sm" submit>Yes</button>
+                                                        <button class="btn btn-default border btn-sm" cancel>No</button>
+                                                    </div>
+                                                </form>
+                                            </span>
+                                                        @endif
+
+                                                        @if($bill->is_cancelled && !$bill->is_cancellation_acknowledged)
+                                                            <div class="mt-2 text-secondary">
+                                                                <i class="fa fa-exclamation-triangle"></i>
+                                                                Not Acknowledged
+                                                            </div>
+                                                            <div class="d-block mt-1" moe>
+                                                                <a class="" href="" show start>Ack. Cancellation</a>
+                                                                <form url="/api/bill/acknowledgeCancellation">
+                                                                    <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                                    <p>Acknowledge Cancellation?</p>
+                                                                    <div class="mb-0">
+                                                                        {{--<input type="text" class="text form-control form-control-sm" name="cancellationMemo" value="{{$bill->cancellation_memo}}" placeholder=""><br>--}}
+                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                    </div>
+                                                                </form>
+                                                            </div>
+                                                        @endif
+
+                                                        @if($bill->is_cancellation_acknowledged && !$note->is_billing_marked_done)
+                                                            <div class="mt-2 text-secondary">
+                                                                <i class="fa fa-check"></i>
+                                                                Acknowledged
+                                                            </div>
+                                                            <div class="d-block mt-1" moe>
+                                                                <a class="" href="" show start>Undo Cancellation Ack.</a>
+                                                                <form url="/api/bill/undoAcknowledgeCancellation">
+                                                                    <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                                    <p>Undo Acknowledge Cancellation?</p>
+                                                                    <div class="mb-0">
+                                                                        <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                    </div>
+                                                                </form>
+                                                            </div>
+                                                        @endif
+
+                                                    </td>
+                                                    <td class="screen-only"> <!-- submit payment -->
+                                                        <div class="my-1">
+                                                            @if(!$bill->is_cancelled && !$bill->has_hcp_been_paid )
+                                                                @if(+$bill->hcp_expected_payment_amount && $bill->is_signed_by_hcp)
+                                                                    <span class="d-block" moe relative="">
+                                                        <a class="font-weight-bold" href="" show start>Submit Payment For HCP</a>
+                                                        <form url="/api/bill/payHcpAmount" right>
+                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                            <p>Submit Payment</p>
+                                                            <div class="mb-0">
+                                                                <input type="text" class="text form-control form-control-sm" name="hcpPaymentAmount" value="{{$bill->hcp_expected_payment_amount}}" placeholder="amount"><br>
+                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                            </div>
+                                                        </form>
+                                                    </span>
+                                                                @else
+                                                                    @if(!+$bill->hcp_expected_payment_amount)
+                                                                        <div class="mb-1 text-danger">
+                                                                            <i class="fa fa-exclamation-triangle"></i>
+                                                                            HCP expected amount is invalid
+                                                                        </div>
+                                                                    @endif
+                                                                    @if(!$bill->is_signed_by_hcp)
+                                                                        <div class="mb-1 text-danger">
+                                                                            <i class="fa fa-exclamation-triangle"></i>
+                                                                            HCP has not signed the bill
+                                                                        </div>
+                                                                    @endif
+                                                                @endif
+                                                            @endif
+                                                        </div>
+                                                        <div class="my-1">
+                                                            @if(!$bill->is_cancelled && !$bill->has_na_been_paid && $bill->ally)
+                                                                @if(+$bill->na_expected_payment_amount && $bill->is_signed_by_na)
+                                                                    <span class="d-block" moe relative="">
+                                                        <a class="font-weight-bold" href="" show start>Submit Payment For NA</a>
+                                                        <form url="/api/bill/payNaAmount" right>
+                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                            <p>Submit Payment For NA</p>
+                                                            <div class="mb-0">
+                                                                <input type="text" class="text form-control form-control-sm" name="naPaymentAmount" value="{{$bill->na_expected_payment_amount}}" placeholder="amount"><br>
+                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                            </div>
+                                                        </form>
+                                                    </span>
+                                                                @else
+                                                                    @if(!+$bill->na_expected_payment_amount)
+                                                                        <div class="mb-1 text-danger">
+                                                                            <i class="fa fa-exclamation-triangle"></i>
+                                                                            NA expected amount is invalid
+                                                                        </div>
+                                                                    @endif
+                                                                    @if(!$bill->is_signed_by_na)
+                                                                        <div class="mb-1 text-danger">
+                                                                            <i class="fa fa-exclamation-triangle"></i>
+                                                                            NA has not signed the bill
+                                                                        </div>
+                                                                    @endif
+                                                                @endif
+                                                            @endif
+                                                        </div>
+                                                    </td>
+                                                </tr>
+                                            @endforeach
+                                            </tbody>
+                                        </table>
+                                    @else
+                                        <table class="table table-sm tabe-striped mb-3 border-left border-right border-bottom">
+                                            <thead class="bg-light">
+                                            <tr>
+                                                <th class="border-bottom-0 pl-3">HCP</th>
+                                                @if($note->ally_pro_id === $pro->id)
+                                                    <th class="border-bottom-0 pl-3">NA</th>
+                                                @endif
+                                                <th class="border-bottom-0 w-25 pl-3">Service</th>
+                                                {{--<th class="border-bottom-0 w-25 pl-2">Reason</th>--}}
+                                                <th class="border-bottom-0 pl-3">Billable</th>
+                                                <th class="border-bottom-0 pl-2">Amount</th>
+                                                <th class="border-bottom-0"></th>
+                                            </tr>
+                                            </thead>
+                                            <tbody>
+                                            @foreach ($note->bills as $bill)
+                                                <tr>
+                                                    <td class="pl-3">{{ $bill->hcp->displayName() }}</td>
+                                                    @if($note->ally_pro_id === $pro->id)
+                                                        <td class="pl-3">{{ $note->allyPro->displayName() }}</td>
+                                                    @endif
+                                                    <td class="pl-3 {{ $bill->is_cancelled ? 'text-secondary' : '' }}">{{$bill->code}}</td>
+                                                    {{--<td class="pl-2">
+                                                        {{ $bill->reason1 }}
+                                                        <div class="text-secondary small">{{ $bill->reason2 }}</div>
+                                                    </td>--}}
+                                                    <td class="pl-3">
+                                                        @if(strpos(strtolower($bill->code), 'treatment services') !== FALSE)
+                                                            <?php
+                                                            $totalSeconds = $bill->number_of_units * 3600;
+                                                            $remainder = $totalSeconds % 60;
+                                                            if ($remainder !== 0) {
+                                                                if ($remainder < 30) {
+                                                                    $totalSeconds = $totalSeconds - $remainder;
+                                                                }
+                                                                else {
+                                                                    $totalSeconds = $totalSeconds + (60 - $remainder);
+                                                                }
+                                                            }
+                                                            ?>
+                                                            {{ time_in_hrminsec($totalSeconds) }}
+                                                        @else
+                                                            @if(!!$bill->number_of_units)
+                                                                {{ $bill->number_of_units }} unit(s)
+                                                            @else
+                                                                -
+                                                            @endif
+                                                        @endif
+                                                    </td>
+                                                    <td class="pl-2">
+                                                        @if($bill->hcp_pro_id === $pro->id)
+                                                            @if($bill->has_hcp_been_paid)
+                                                                <span class="text-dark">Processed:</span><span class="font-weight-bold text-success ml-2">${{ $bill->hcp_payment_amount }}</span>
+                                                            @else
+                                                                <span class="text-dark">Expected:</span><span class="font-weight-bold text-dark ml-2">{{ $bill->hcp_expected_payment_amount ? '$' . $bill->hcp_expected_payment_amount : '-' }}</span>
+                                                            @endif
+                                                        @elseif($bill->na_pro_id === $pro->id)
+                                                            @if($bill->has_na_been_paid)
+                                                                <span class="text-dark">Processed:</span><span class="font-weight-bold text-success ml-2">${{ $bill->na_payment_amount }}</span>
+                                                            @else
+                                                                <span class="text-dark">Expected:</span><span class="font-weight-bold text-dark ml-2">{{ $bill->na_expected_payment_amount ? '$' . $bill->na_expected_payment_amount : '-' }}</span>
+                                                            @endif
+                                                        @endif
+                                                    </td>
+                                                    <td>
+                                                        <div class="d-flex align-items-center">
+                                                            @if(!$bill->is_cancelled)
+                                                                @if($bill->is_signed_by_hcp)
+                                                                    <span class="d-block text-secondary">
+                                                        <i class="fa fa-check"></i>
+                                                        HCP Signed
+                                                    </span>
+                                                                @else
+                                                                    <span moe
+                                                                          class="d-block {{ $bill->hcp_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                                                          title="{{ $bill->hcp_pro_id !== $pro->id ? 'Only the bill\'s HCP can sign' : '' }}">
+                                                        <a class="" href="" show start>Sign as HCP</a>
+                                                        <form url="/api/bill/signAsHcp">
+                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                            <p>Sign this bill as HCP?</p>
+                                                            <div class="mb-0">
+                                                                <button class="btn btn-success btn-sm" submit>Sign</button>
+                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                            </div>
+                                                        </form>
+                                                    </span>
+                                                                @endif
+                                                                @if($bill->na_pro_id === $pro->id)
+                                                                    <span class="mx-2 text-secondary">|</span>
+                                                                    @if($bill->is_signed_by_na)
+                                                                        <span class="d-block text-secondary">
+                                                            <i class="fa fa-check"></i>
+                                                            NA Signed
+                                                        </span>
+                                                                    @else
+                                                                        <span moe
+                                                                              class="d-block {{ $bill->na_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
+                                                                              title="{{ $bill->hcp_pro_id !== $pro->id ? 'Only the bill\'s NA can sign' : '' }}">
+                                                            <a class="" href="" show start>Sign as NA</a>
+                                                            <form url="/api/bill/signAsNa">
+                                                                <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                                <p>Sign this bill as NA?</p>
+                                                                <div class="mb-0">
+                                                                    <button class="btn btn-success btn-sm" submit>Sign</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </span>
+                                                                    @endif
+                                                                @endif
+                                                            @endif
+                                                            @if(!$bill->has_hcp_been_paid && $pro->pro_type === 'ADMIN')
+                                                                <span class="mx-2 text-secondary">|</span>
+                                                                <span class="d-block" moe>
+                                                    <a class="text-danger" href="" show start>Submit Payment</a>
+                                                    <form url="/api/bill/payHcpAmount">
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Submit payment:</p>
+                                                        <div class="mb-0">
+                                                            <input type="text" class="text form-control form-control-sm" name="hcpPaymentAmount" value="{{$bill->hcp_expected_payment_amount}}" placeholder="amount"><br>
+                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @endif
+                                                            @if(!$bill->has_na_been_paid && $bill->ally && $pro->pro_type === 'ADMIN')
+                                                                <span class="d-block" moe relative="">
+                                                    <a class="font-weight-bold" href="" show start>Submit Payment For NA</a>
+                                                    <form url="/api/bill/payNaAmount" right>
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Submit Payment For NA</p>
+                                                        <div class="mb-0">
+                                                            <input type="text" class="text form-control form-control-sm" name="naPaymentAmount" value="{{$bill->na_expected_payment_amount}}" placeholder="amount"><br>
+                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @endif
+                                                            @if($bill->is_cancelled)
+                                                                <span class="mx-2 text-secondary">|</span>
+                                                                <span class="d-block text-secondary">
+                                                    Cancelled
+                                                </span>
+                                                            @else
+                                                                <span class="mx-2 text-secondary">|</span>
+                                                                <span class="d-block" moe>
+                                                    <a class="text-danger" href="" show start>Cancel</a>
+                                                    <form url="/api/bill/markCancelled" right>
+                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                        <p>Cancel this bill?</p>
+                                                        <div class="mb-0">
+                                                            <button class="btn btn-danger btn-sm" submit>Yes</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>No</button>
+                                                        </div>
+                                                    </form>
+                                                </span>
+                                                            @endif
+                                                        </div>
+                                                    </td>
+                                                </tr>
+                                            @endforeach
+                                            </tbody>
+                                        </table>
+                                    @endif
+
+                                </div>
+                            @else
+                                <div class="p-3 d-flex  border-bottom">
+                                    <p class="font-weight-bold mb-0 text-secondary">No bills in this note</p>
+                                    @include('app/patient/note/_create-bill')
+                                </div>
+                            @endif
+                        @endif
+
+                        {{-- claims --}}
+                        @if($pro->pro_type === 'ADMIN')
+                            @if($note->claims->count())
+                                <div class="screen-only p-3">
+                                    <div class="d-flex align-items-center mb-2">
+                                        <p class="font-weight-bold text-secondary m-0">Claims</p>
+                                        @include('app/patient/note/_create-claim')
+                                        <div class="ml-auto">
+                                            <select class="form-control form-control-sm"
+                                                    onchange="fastLoad('{{route('patients.view.notes.view.dashboard', ['patient' => $patient, 'note' => $note])}}?claims-filter=' + this.value)">
+                                                <option value="active" {{!request('claims-filter') || request('claims-filter') === 'active' ? 'selected' : ''}}>Active Claims</option>
+                                                <option value="all" {{request('claims-filter') === 'all' ? 'selected' : ''}}>All Claims</option>
+                                            </select>
+                                        </div>
+                                    </div>
+
+                                    <table class="table table-sm tabe-striped mb-3 border-left border-right border-bottom">
+                                        <thead class="bg-light">
+                                        <tr>
+                                            <th class="border-bottom-0 pl-2">IID</th>
+                                            <th class="border-bottom-0">Details</th>
+                                            <th class="border-bottom-0">Status</th>
+                                            <th class="border-bottom-0">Submissions</th>
+                                        </tr>
+                                        </thead>
+                                        <tbody>
+                                        @foreach ($note->claims as $claim)
+                                            @if($claim->status !== 'CANCELLED' || request('claims-filter') === 'all')
+                                                <tr class="bg-secondary on-hover-opaque">
+                                                    <td colspan="5" class="pt-0 pb-1"></td>
+                                                </tr>
+                                                <tr class="{{ $claim->status === 'CANCELLED' ? 'text-secondary bg-light on-hover-opaque' : '' }}">
+                                                    <td class="pl-2">
+                                                        <div>{{ $claim->iid }}</div>
+                                                        <div class="text-sm text-secondary font-weight-bold mt-1">Current Version:</div>
+                                                        <div class="text-sm text-secondary">{{$claim->currentVersion ? friendlier_date_time($claim->currentVersion->created_at) : '-'}}</div>
+                                                        @if($claim->status === 'CANCELLED')
+                                                            <div class="text-secondary font-weight-bold text-sm mt-1">[CANCELLED]</div>
+                                                        @else
+                                                            <div moe class="text-left mt-1" title="Cancel Claim">
+                                                                <a class="" href="" show start>Cancel</a>
+                                                                <form url="/api/claim/updateStatus">
+                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                    <input type="hidden" name="status" value="CANCELLED">
+                                                                    <p>Cancel this claim?</p>
+                                                                    <div class="mb-2">
+                                                                        <label for="" class="control-label">Cancellation Memo</label>
+                                                                        <textarea name="memo" class="form-control"></textarea>
+                                                                    </div>
+                                                                    <div class="mb-0">
+                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                    </div>
+                                                                </form>
+                                                            </div>
+                                                        @endif
+                                                    </td>
+                                                    <td class="p-0 border-left border-right">
+                                                        @if($claim->lines->count())
+                                                            <table class="table table-sm table-condensed border-0 mb-0">
+                                                                <thead>
+                                                                <tr class="bg-light">
+                                                                    <th class="border-0">CPT</th>
+                                                                    <th class="border-0">DOS</th>
+                                                                    <th class="border-0">ICDs</th>
+                                                                </tr>
+                                                                </thead>
+                                                                <tbody class="pb-3">
+                                                                @foreach($claim->lines as $line)
+                                                                    <tr class="claim-line">
+                                                                        <td>{{$line->cpt}}
+                                                                            <div>Units: <b>{{!@$line->units ? 1 : $line->units}}</b></div>
+                                                                        </td>
+                                                                        <td class="text-nowrap">{{friendlier_date($line->date_of_service)}}</td>
+                                                                        <td>
+                                                                            @if(count($line->claimLineIcds))
+                                                                                @foreach($line->claimLineIcds as $icd)
+                                                                                    <div>
+                                                                                        <b class="c-pointer border-secondary border-bottom" title="{{$icd->description}}">{{$icd->code}}</b>
+                                                                                    </div>
+                                                                                @endforeach
+                                                                            @else
+                                                                                <p>No ICDs set</p>
+                                                                            @endif
+                                                                        </td>
+                                                                    </tr>
+                                                                @endforeach
+                                                                </tbody>
+                                                            </table>
+                                                        @else
+                                                            <p>No lines for this claim</p>
+                                                        @endif
+                                                    </td>
+                                                    <td class="border-right p-0">
+
+                                                        <!-- payer, company, location -->
+                                                        <div class="p-1">
+                                                            <div class="mt-1">
+                                                                <div>
+                                                                    <span class="text-secondary text-sm">Payer (1°): </span>
+                                                                    <b>{{$claim->primaryPayer ? $claim->primaryPayer->name : '-'}}</b>
+                                                                    @if(0 && $claim->status !== 'CANCELLED')
+                                                                        <span moe class="ml-1">
+                                                            <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
+                                                            <form url="/api/claim/putPrimaryPayer">
+                                                                <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                <div class="mb-2">
+                                                                    <select name="primaryPayerUid" class="form-control form-control-sm">
+                                                                        <option value="">-- select --</option>
+                                                                        @foreach($note->hcpPro->companyProPayers as $companyProPayer)
+                                                                            <option value="{{$companyProPayer->payer->uid}}"
+                                                                                    {{$claim->primaryPayer && $claim->primaryPayer->uid === $companyProPayer->payer->uid ? 'selected' : ''}}>{{$companyProPayer->payer->name}}</option>
+                                                                        @endforeach
+                                                                    </select>
+                                                                </div>
+                                                                <div class="mb-0">
+                                                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </span>
+                                                                        @if($claim->primaryPayer)
+                                                                            <span moe class="ml-1">
+                                                            <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                                            <form url="/api/claim/wipePrimaryPayer">
+                                                                <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                <p>Wipe payer from this claim?</p>
+                                                                <div class="mb-0">
+                                                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </span>
+                                                                        @endif
+                                                                    @endif
+                                                                </div>
+                                                                <div class="py-1 border-bottom d-flex align-items-center">
+                                                                    <span class="text-secondary text-sm pr-1">Status: </span>
+                                                                    <div>
+                                                                        {{$claim->status ? $claim->status : '(not set)'}}
+                                                                        @if($claim->status !== 'CANCELLED')
+                                                                            <span moe class="d-inline-block text-left ml-1" title="Update Status">
+                                                                    <a class="" href="" show start><i class="fa fa-edit"></i></a>
+                                                                    <form url="/api/claim/updateStatus">
+                                                                        <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                        <div class="mb-2">
+                                                                            <label for="" class="control-label">Status</label>
+                                                                            <select name="status" class="form-control form-control-sm" required>
+                                                                                <option value="">-- select --</option>
+                                                                                <option value="NEW" {{$claim->status === 'NEW' ? 'selected' : ''}}>New</option>
+                                                                                <option value="PICKED_UP" {{$claim->status === 'PICKED_UP' ? 'selected' : ''}}>Picked Up</option>
+                                                                                <option value="SUBMITTED" {{$claim->status === 'SUBMITTED' ? 'selected' : ''}}>Submitted</option>
+                                                                                <option value="IN_PROCESS" {{$claim->status === 'IN_PROCESS' ? 'selected' : ''}}>In Process</option>
+                                                                                <option value="ACCEPTED" {{$claim->status === 'ACCEPTED' ? 'selected' : ''}}>Accepted</option>
+                                                                                <option value="REJECTED" {{$claim->status === 'REJECTED' ? 'selected' : ''}}>Rejected</option>
+                                                                                <option value="ABANDONED" {{$claim->status === 'ABANDONED' ? 'selected' : ''}}>Abandoned</option>
+                                                                            </select>
+                                                                        </div>
+                                                                        <div class="mb-2">
+                                                                            <label for="" class="control-label">Status Memo</label>
+                                                                            <textarea name="memo" class="form-control"></textarea>
+                                                                        </div>
+                                                                        <div class="mb-0">
+                                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                        </div>
+                                                                    </form>
+                                                                </span>
+                                                                        @endif
+                                                                    </div>
+                                                                    @if($claim->status_memo)
+                                                                        <div class="text-secondary font-italic text-sm">{{$claim->status_memo}}</div>
+                                                                    @endif
+                                                                </div>
+                                                            </div>
+
+                                                            <div class="mt-1">
+                                                                <span class="text-secondary text-sm">Payer (2°): </span>
+                                                                <b>-</b>
+                                                            </div>
+
+                                                            <div class="mt-1">
+                                                                <span class="text-secondary text-sm">Company: </span>
+                                                                <b>{{$claim->companyPro && $claim->companyPro->company ? $claim->companyPro->company->name : '-'}}</b>
+                                                                @if(0 && $claim->status !== 'CANCELLED')
+                                                                    <span moe class="ml-1">
+                                                            <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
+                                                            <form url="/api/claim/putCompanyPro">
+                                                                <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                <div class="mb-2">
+                                                                    <select name="companyProUid" class="form-control form-control-sm">
+                                                                        <option value="">-- select --</option>
+                                                                        @foreach($note->hcpPro->companyProPayers as $companyProPayer)
+                                                                            <option value="{{$companyProPayer->companyPro->uid}}"
+                                                                                    {{$claim->companyPro && $claim->companyPro->uid === $companyProPayer->companyPro->uid ? 'selected' : ''}}>{{$companyProPayer->company->name}}</option>
+                                                                        @endforeach
+                                                                    </select>
+                                                                </div>
+                                                                <div class="mb-0">
+                                                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </span>
+                                                                    @if($claim->companyPro && $claim->companyPro->company)
+                                                                        <span moe class="ml-1">
+                                                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                                                <form url="/api/claim/wipeCompanyPro">
+                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                    <p>Wipe company from this claim?</p>
+                                                                    <div class="mb-0">
+                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                    </div>
+                                                                </form>
+                                                            </span>
+                                                                    @endif
+                                                                @endif
+                                                            </div>
+
+                                                            <div class="mt-1">
+                                                                <span class="text-secondary text-sm">Location: </span>
+                                                                <b>{{$claim->companyLocation ? $claim->companyLocation->line1 . ', ' . $claim->companyLocation->city : '-'}}</b>
+                                                                @if(0 && $claim->status !== 'CANCELLED')
+                                                                    <span moe class="ml-1">
+                                                            <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
+                                                            <form url="/api/claim/putCompanyLocation">
+                                                                <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                <div class="mb-2">
+                                                                    <select name="companyLocationUid" class="form-control form-control-sm">
+                                                                        <option value="">-- select --</option>
+                                                                        @if($claim->company && $claim->company->locations)
+                                                                            @foreach($claim->company->locations as $location)
+                                                                                <option value="{{$location->uid}}"
+                                                                                        {{$claim->companyLocation && $claim->companyLocation->uid === $location->uid ? 'selected' : ''}}>
+                                                                                    {{$location->line1 . ', ' . $location->city}}
+                                                                                </option>
+                                                                            @endforeach
+                                                                        @endif
+                                                                    </select>
+                                                                </div>
+                                                                <div class="mb-0">
+                                                                    <button class="btn btn-success btn-sm" submit>Submit</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </span>
+                                                                    @if($claim->companyLocation)
+                                                                        <span moe class="ml-1">
+                                                            <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                                            <form url="/api/claim/wipeCompanyLocation">
+                                                                <input type="hidden" name="uid" value="{{$claim->uid}}">
+                                                                <p>Wipe location from this claim?</p>
+                                                                <div class="mb-0">
+                                                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </span>
+                                                                    @endif
+                                                                @endif
+                                                            </div>
+                                                        </div>
+                                                    </td>
+                                                    <td class="p-0 border-left border-right">
+                                                        <table class="table table-sm table-condensed border-0 mb-0">
+                                                            @if($claim->status !== 'CANCELLED')
+                                                                <thead>
+                                                                <tr class="">
+                                                                    <th colspan="3" class="border-top-0 border-bottom">
+                                                                        <div>
+                                                                <span moe class="d-block" title="Submit Claim">
+                                                                    <a class="" href="" show start>Generate Submission to Payer (1°)</a>
+                                                                    <form url="/api/mbClaim/createFromClaimForPrimaryPayer">
+                                                                        <input type="hidden" name="claimUid" value="{{$claim->uid}}">
+                                                                        <p>Generate Submission?</p>
+                                                                        <div class="mb-0">
+                                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                        </div>
+                                                                    </form>
+                                                                </span>
+                                                                        </div>
+                                                                    </th>
+                                                                </tr>
+                                                                </thead>
+                                                            @endif
+                                                            @if(count($claim->mbClaims))
+                                                                <thead>
+                                                                <tr class="bg-light">
+                                                                    <th class="border-0">Created</th>
+                                                                    <th class="border-0">Status</th>
+                                                                    <th class="border-0">&nbsp;</th>
+                                                                </tr>
+                                                                </thead>
+                                                                <tbody class="pb-3">
+                                                                @foreach($claim->mbClaims as $mbClaim)
+                                                                    <tr>
+                                                                        <td>
+                                                                            @if($mbClaim->claim_version_id !== $claim->current_version_id)
+                                                                                <i class="fa fa-exclamation-triangle text-warning-mellow text-sm" title="This submission was generated using an older version of the claim"></i>
+                                                                            @else
+                                                                                <i class="fa fa-asterisk text-secondary text-sm" title="This submission is up to date"></i>
+                                                                            @endif
+                                                                            <a native target="_blank"
+                                                                               open-in-stag-popup
+                                                                               title="Submission Details"
+                                                                               href="{{route('mb-claim', ['patient' => $patient, 'mbClaim' => $mbClaim])}}">
+                                                                                {{ friendlier_date_time($mbClaim->created_at) }}
+                                                                            </a>
+                                                                        </td>
+                                                                        <td>
+                                                                            {{$mbClaim->status}}
+                                                                            @if($mbClaim->status_memo)
+                                                                                <div class="font-italic text-secondary text-sm">{{$mbClaim->status_memo}}</div>
+                                                                            @endif
+                                                                        </td>
+                                                                        <td class="text-right pr-2">
+                                                                 <span moe relative title="Submit Claim">
+                                                                    <a class="" href="" show start><i class="fa fa-edit"></i></a>
+                                                                    <form url="/api/mbClaim/updateStatus" right>
+                                                                        <input type="hidden" name="uid" value="{{$mbClaim->uid}}">
+                                                                        <div class="form-group">
+                                                                            <label for="" class="control-label">Status</label>
+                                                                            <select name="status" class="form-control form-control-sm" required>
+                                                                                <option value="">-- select --</option>
+                                                                                <option value="NEW" {{$mbClaim->status === 'NEW' ? 'selected' : ''}}>New</option>
+                                                                                <option value="PROCESSING" {{$mbClaim->status === 'PROCESSING' ? 'selected' : ''}}>Processing</option>
+                                                                                <option value="SUBMITTED" {{$mbClaim->status === 'SUBMITTED' ? 'selected' : ''}}>Submitted</option>
+                                                                            </select>
+                                                                        </div>
+                                                                        <div class="form-group">
+                                                                            <label for="" class="control-label">Status Memo</label>
+                                                                            <textarea name="memo" class="form-control"></textarea>
+                                                                        </div>
+                                                                        <div class="mb-0">
+                                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                        </div>
+                                                                    </form>
+                                                                </span>
+                                                                            <a class="ml-1" target="_blank" native href="/api/mbClaim/downloadEDI/{{$mbClaim->uid}}" show start><i class="fa fa-file-download"></i></a>
+                                                                            <a class="ml-1 text-success" href="" show start><i class="fa fa-arrow-right"></i></a>
+                                                                        </td>
+                                                                    </tr>
+                                                                @endforeach
+                                                                </tbody>
+                                                            @else
+                                                                <tbody>
+                                                                <tr>
+                                                                    <td colspan="3">
+                                                                        <p class="p-1 text-secondary m-0">No submissions in this claim</p>
+                                                                    </td>
+                                                                </tr>
+                                                                </tbody>
+                                                            @endif
+                                                        </table>
+                                                    </td>
+                                                </tr>
+                                            @endif
+                                        @endforeach
+                                        </tbody>
+                                    </table>
+                                </div>
+                            @else
+                                <div class="screen-only my-3 px-3 d-flex">
+                                    <p class="font-weight-bold mb-0 text-secondary">No claims in this note</p>
+                                    @include('app/patient/note/_create-claim')
+                                </div>
+                            @endif
+                        @endif
+
+
+                        <div class="border-top p-3 screen-only">
+                            @if($note->addendums->count())
+                                <div class="">
+                                    <div class="d-flex align-items-center mb-2">
+                                        <p class="font-weight-bold text-secondary m-0">Addendums</p>
+                                        @include('app/patient/note/_create-addendum')
+                                    </div>
+                                    <table class="table table-sm tabe-striped border-left border-right border-bottom m-0">
+                                        <thead class="bg-light">
+                                        <tr>
+                                            <th class="border-bottom-0 pl-2 w-75">Addendum</th>
+                                            <th class="border-bottom-0">Created</th>
+                                            <th class="border-bottom-0 delete-column"></th>
+                                        </tr>
+                                        </thead>
+                                        <tbody>
+                                        @foreach ($note->addendums as $addendum)
+                                            <tr>
+                                                <td class="pl-2">{{ $addendum->memo }}</td>
+                                                <td class="">{{ friendly_date_time($addendum->created_at, false)}}</td>
+                                                <td>
+                                                    <div class="d-flex align-items-center">
+                                                        <div moe relative class="mr-2">
+                                                            <a href="" show start><i class="fa fa-pencil-alt"></i></a>
+                                                            <form url="/api/noteAddendum/updateMemo" right>
+                                                                <input type="hidden" name="uid" value="{{$addendum->uid}}">
+                                                                <div class="mb-2 d-block">
+                                                                    <label class="d-block text-sm text-secondary mb-1">Addendum</label>
+                                                                    <textarea class="form-control form-control-sm" name="memo" rows="5">{{$addendum->memo}}</textarea>
+                                                                </div>
+                                                                <div class="form-group mb-0">
+                                                                    <button class="btn btn-primary btn-sm mr-1" submit>Submit</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                                </div>
+                                                            </form>
+                                                        </div>
+                                                        <div moe relative class="mr-1">
+                                                            <a href="" show start class="text-danger"><i class="fa fa-trash"></i></a>
+                                                            <form url="/api/noteAddendum/remove" right>
+                                                                <input type="hidden" name="uid" value="{{$addendum->uid}}">
+                                                                <p>Remove this addendum?</p>
+                                                                <div class="form-group mb-0">
+                                                                    <button class="btn btn-danger btn-sm mr-1" submit>Yes</button>
+                                                                    <button class="btn btn-default border btn-sm" cancel>No</button>
+                                                                </div>
+                                                            </form>
+                                                        </div>
+                                                    </div>
+                                                </td>
+                                            </tr>
+                                        @endforeach
+                                        </tbody>
+                                    </table>
+                                </div>
+                            @else
+                                <div class="d-flex">
+                                    <p class="font-weight-bold mb-0 text-secondary">No addendums in this note</p>
+                                    @include('app/patient/note/_create-addendum')
+                                </div>
+                            @endif
+                        </div>
+
+                        <div class="screen-only">
+                            @include('app/patient/note/_cancel-signed-note')
+                        </div>
+
+
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+    <div class="note-templates-underlay"></div>
+    @include('app.patient.note.dashboard_script')
+    @include('app.patient.canvas-sections.canvas-editor-modal', ['key' => 'rx', 'class' => 'wide', 'noEditLink' => true])
+    <script>
+        (function() {
+            function init() {
+                fixTreeTopAndHeight();
+                $(window).on('resize', fixTreeTopAndHeight);
+                $(window).on('scroll', fixTreeTopAndHeight);
+                $('.note-tree-node>a[data-section-template-name]')
+                    .off('click.scroll-to-section')
+                    .on('click.scroll-to-section', function() {
+                         let section = $('div.note-section[data-section-template-name="' + $(this).attr('data-section-template-name') + '"]').first();
+                         if(section.length) {
+                             section[0].scrollIntoView({
+                                 behavior: "smooth",
+                                 block: "center",
+                                 inline: "center"
+                             });
+                             section.addClass('spot-highlight');
+                             setTimeout(() => {
+                                 section.removeClass('spot-highlight');
+                             }, 1500);
+                             $('.note-tree-node.active').removeClass('active');
+                             $(this).closest('.note-tree-node').addClass('active');
+                         }
+                         return false;
+                    });
+            }
+            function fixTreeTopAndHeight() {
+                let tree = $('#note-lhs-tree'), noteCardHeader = $('#note-card-header'),
+                    resultTop = (noteCardHeader.offset().top + noteCardHeader.outerHeight(true)) - $(window).scrollTop();
+                if(resultTop <= 55) {
+                    tree.addClass('fixed');
+                }
+                else {
+                    tree.removeClass('fixed');
+                    tree.css('height', 'calc(100vh - ' + resultTop + 'px)');
+                    tree.css('max-height', 'calc(100vh - ' + resultTop + 'px)');
+                }
+            }
+            addMCInitializer('note-tree', init, '#note-lhs-tree');
+        })();
+    </script>
+@endsection

+ 102 - 103
resources/views/app/patient/note/dashboard.blade.php

@@ -10,14 +10,17 @@
 
     <?php
     $hasBills = false;
-    if($note->bills->count()) {
+    if ($note->bills->count()) {
         foreach ($note->bills as $bill) {
-            if(!$bill->is_cancelled) {
+            if (!$bill->is_cancelled) {
                 $hasBills = true;
                 break;
             }
         }
     }
+
+    // is based on visit template
+    $isVisitTemplateBased = !!$note->visitTemplate;
     ?>
 
     {{--
@@ -36,7 +39,7 @@
     @endif
     --}}
 
-    <div id="note-single-header" class="pt-2 pb-3 d-flex align-items-start screen-only">
+    <div id="note-single-header" class="pb-3 d-flex align-items-start screen-only">
         <h6 class="my-0 text-secondary d-flex align-items-center w-100">
             <a href="/patients/view/{{ $patient->uid }}/notes" class="small text-decoration-none mr-3">
                 <i class="fa fa-chevron-left"></i>
@@ -50,10 +53,10 @@
                     <?php
                     $isBad = false;
                     $isGood = false;
-		    if($note->detail_json) {
+		            if($note->detail_json) {
                         $parsed = json_decode($note->detail_json);
                         $isBad = $parsed && @$parsed->isBad;
-			$isGood = $parsed && @$parsed->isGood;
+			            $isGood = $parsed && @$parsed->isGood;
                     }
                     ?>
                     @if(!$isBad)
@@ -83,7 +86,7 @@
                     @endif
 		     @if(!$isGood)
                         <div moe relative>
-                            <a href="#" start show  class="print-note ml-2 btn btn-sm btn-success text-white font-weight-bold invisible"><i class="fa fa-exclamation-triangle"></i> Mark as Good Note</a>
+                            <a href="#" start show  class="print-note ml-2 btn btn-sm btn-success text-white font-weight-bold invisible"><i class="fa fa-check"></i> Mark as Good Note</a>
                             <form url="/api/note/markNoteAsGood" class="mcp-theme-1">
                                 <input type="hidden" name="uid" value="{{$note->uid}}">
                                 <p class="min-width-200px">Mark this note as <b>good</b>?</p>
@@ -130,8 +133,8 @@
         </h6>
     </div>
 
-    <div class="card mb-0 {{ $note->is_cancelled ? 'cancelled-item' : '' }}">
-        <span class="card-header d-flex align-items-start px-3 py-2 border-bottom">
+    <span class="card mb-0 {{ $note->is_cancelled ? 'cancelled-item' : '' }}">
+        <div class="card-header d-flex align-items-start px-3 py-2 border-bottom" id="note-card-header">
             <div class="pr-2">
                 {{$note->title}}
                 @if(!$note->is_signed_by_hcp || $pro->pro_type === 'ADMIN')
@@ -207,9 +210,6 @@
                                 <select provider-search data-pro-uid="{{ @$note->hcpPro->uid }}"
                                         name="hcpProUid" class="form-control form-control-sm">
                                     <option value="">-- Select HCP Pro --</option>
-                                    @foreach ($pros as $iPro)
-                                        <option value="{{$iPro->uid}}" {{ $note->hcpPro && $iPro->id === $note->hcpPro->id ? 'selected' : '' }}>{{$iPro->name_display}}</option>
-                                    @endforeach
                                 </select>
                             </div>
                             <div class="mb-0">
@@ -436,6 +436,53 @@
             </div>
         </div>
         <div class="card-body p-0">
+            <div class="note-container">
+                @if($isVisitTemplateBased)
+                <div class="note-lhs-tree" id="note-lhs-tree">
+                    <?php
+                    $previousHeading = null;
+                    $previousSubHeading = null;
+                    ?>
+                    @foreach($note->segments as $segment)
+                        <?php
+                        if ($segment->heading !== $previousHeading) {
+                            if (!empty($previousHeading)) {
+                                echo '</div></div>'; // <!-- end the previous parent section -->
+                            }
+                            if (!empty($segment->heading)) {
+                                echo '<div class="note-tree-node note-tree-heading">' .
+                                    '<a class="">' . $segment->heading . '</a>' .
+                                    '<div class="note-tree-children">'; // <!-- open new node -->
+                            }
+                            $previousHeading = $segment->heading;
+                        }
+                        if ($segment->subheading !== $previousSubHeading) {
+                            if (!empty($previousSubHeading)) {
+                                echo '</div></div>'; // <!-- end the previous parent section -->
+                            }
+                            if (!empty($segment->subheading)) {
+                                echo '<div class="note-tree-node note-tree-heading">' .
+                                    '<a class="">' . $segment->subheading . '</a>' .
+                                    '<div class="note-tree-children">'; // <!-- open new node -->
+                            }
+                            $previousSubHeading = $segment->subheading;
+                        }
+                        echo '<div class="note-tree-node">' .
+                            '<a native target="_top" data-segment-uid="' . $segment->uid . '" href="#" >' . $segment->display_title . '</a>' .
+                            '</div>';
+                        ?>
+                    @endforeach
+                    <?php
+                    if (!empty($previousSubHeading)) {
+                        echo '</div></div>'; // <!-- close any open parent section -->
+                    }
+                    if (!empty($previousHeading)) {
+                        echo '</div></div>'; // <!-- close any open parent section -->
+                    }
+                    ?>
+                </div>
+                @endif
+                <div class="note-rhs-content">
             <div>
                 <div class="">
                     <div>
@@ -455,12 +502,17 @@
                         }
                         ?>
                         <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>
+                        <script>window.segmentInitializers = {};</script>
                         <?php
                         $shortcuts = "";
                         $latestSectionTS = 0;
                         ?>
                         <div class="{{ $note->is_signed_by_hcp ? 'note-signed-by-hcp' : '' }}">
-                        @include('app.patient.note.note-section-list')
+                            @if($isVisitTemplateBased)
+                                @include('app.patient.note.note-segment-list')
+                            @else
+                                @include('app.patient.note.note-section-list')
+                            @endif
                         </div>
                     </div>
                 </div>
@@ -2167,107 +2219,54 @@
                 </div>
 
 
+            </div>
+                </div>
             </div>
         </div>
     </div>
     <div class="note-templates-underlay"></div>
     @include('app.patient.note.dashboard_script')
     @include('app.patient.canvas-sections.canvas-editor-modal', ['key' => 'rx', 'class' => 'wide', 'noEditLink' => true])
-@endsection
-@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>
+    @if($isVisitTemplateBased)
     <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');
+            function init() {
+                fixTreeTopAndHeight();
+                $(window).on('resize', fixTreeTopAndHeight);
+                $(window).on('scroll', fixTreeTopAndHeight);
+                $('.note-tree-node>a[data-segment-uid]')
+                    .off('click.scroll-to-section')
+                    .on('click.scroll-to-section', function() {
+                        let section = $('div.note-section[data-segment-uid="' + $(this).attr('data-segment-uid') + '"]').first();
+                        if(section.length) {
+                            section[0].scrollIntoView({
+                                behavior: "smooth",
+                                block: "center",
+                                inline: "center"
+                            });
+                            section.addClass('spot-highlight');
+                            setTimeout(() => {
+                                section.removeClass('spot-highlight');
+                            }, 1500);
+                            $('.note-tree-node.active').removeClass('active');
+                            $(this).closest('.note-tree-node').addClass('active');
                         }
-                    }
-                });
-
-                $('div[embed]').each(function() {
-                    $(this).load($(this).attr('embed'));
-                });
+                        return false;
+                    });
+            }
+            function fixTreeTopAndHeight() {
+                let tree = $('#note-lhs-tree'), noteCardHeader = $('#note-card-header'),
+                    resultTop = (noteCardHeader.offset().top + noteCardHeader.outerHeight(true)) - $(window).scrollTop();
+                if(resultTop <= 55) {
+                    tree.addClass('fixed');
+                }
+                else {
+                    tree.removeClass('fixed');
+                    tree.css('height', 'calc(100vh - ' + resultTop + 'px)');
+                    tree.css('max-height', 'calc(100vh - ' + resultTop + 'px)');
+                }
             }
-            addMCInitializer('note-sections-widget', initSectionsWidget, '#note-sections-app');
+            addMCInitializer('note-tree', init, '#note-lhs-tree');
         })();
     </script>
     @endif

+ 5 - 3
resources/views/app/patient/note/dashboard_script.blade.php

@@ -77,9 +77,9 @@
 
                 });
 
-                $('.edit-trigger')
-                    .off('click.edit-trigger')
-                    .on('click.edit-trigger', function() {
+                $(document)
+                    .off('click.edit-trigger', '.edit-trigger:not(.edit)')
+                    .on('click.edit-trigger', '.edit-trigger:not(.edit)', function() {
                         let editParent = $(this).closest('.note-section');
                         if(editParent.is('.edit')) {
                             editParent.removeClass('edit');
@@ -289,6 +289,7 @@
                     return false;
                 });
 
+                @if(!$note->visitTemplate)
                 $(document)
                     .off('mousedown.enable-edit', '.note-section:not(.edit):not(.page-driven)')
                     .on('mousedown.enable-edit', '.note-section:not(.edit):not(.page-driven)', function(e) {
@@ -298,6 +299,7 @@
                         $(this).find('.edit-trigger').first().click();
                         return false;
                     });
+                @endif
 
                 // $(document)
                 //     .off('mousedown.enable-edit', '.note-section:not(.edit).page-driven')

+ 6 - 0
resources/views/app/patient/note/note-segment-list.blade.php

@@ -0,0 +1,6 @@
+<div class="segments-list">
+    @foreach($note->segments as $segment)
+        @include('app.patient.note.segment')
+    @endforeach
+</div>
+@include('app.patient.note.segment_script')

+ 34 - 24
resources/views/app/patient/note/section.blade.php

@@ -4,7 +4,7 @@ if ($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
     $latestSectionTS = $sectionTS;
 }
 ?>
-<div data-ts="{{$sectionTS}}" class="p-3 border-bottom note-section {{ $section->sectionTemplate->is_page_driven ? 'page-driven' : '' }}"
+<div data-ts="{{$sectionTS}}" class="p-3 border-bottom note-section {{ $section->sectionTemplate->is_page_driven ? '' : '' }}"
     data-section-uid="{{ $section->uid }}"
     data-section-template-uid="{{ $section->sectionTemplate->uid }}"
     data-section-template-name="{{ $section->sectionTemplate->internal_name }}">
@@ -12,7 +12,7 @@ if ($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
         @if(!isset($note) || (isset($note) && !$note->is_signed_by_hcp))
             <a class="font-weight-bold mb-2 d-flex align-items-center c-pointer">
                 {{$section->sectionTemplate->title}}
-                @if(!isset($guestAccessCode) && !$section->sectionTemplate->is_page_driven)
+                @if(!isset($guestAccessCode) )
                     <span class="d-none if-not-edit"><i class="fa fa-edit ml-2"></i></span>
                     <span class="d-none if-edit edit-trigger font-weight-normal ml-2">Collapse</span>
                     <span class="edit-trigger"></span>
@@ -26,14 +26,14 @@ if ($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
         <?php $sectionInternalName = $section->sectionTemplate->internal_name; ?>
 
         @if($sectionInternalName === "exam" || $sectionInternalName === "objective")
-        @include('app/patient/note/_templates-exam-index')
+            @include('app/patient/note/_templates-exam-index')
         @else
-        @include('app/patient/note/_templates-index')
+            @include('app/patient/note/_templates-index')
         @endif
 
         @if (!$section->sectionTemplate->is_page_driven)
             @if (file_exists(storage_path('sections/' . $sectionInternalName . '/actions.php'))) {
-            <?php include(storage_path('sections/' . $sectionInternalName . '/actions.php')); ?>
+                <?php include(storage_path('sections/' . $sectionInternalName . '/actions.php')); ?>
             @elseif (file_exists(storage_path('sections/' . $sectionInternalName . '/actions.blade.php')))
                 @include('sections/' . $sectionInternalName . '/actions')
             @endif
@@ -71,35 +71,36 @@ if ($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
                     Remove
                 </a>
                 @if($pro->pro_type === 'ADMIN' || true)
-                <a href="#" class="d-none if-edit ml-2 move-up-trigger" data-uid="{{$section->uid}}" title="Move Up">
-                    <i class="fa fa-arrow-up"></i>
-                </a>
-                <a href="#" class="d-none if-edit ml-2 move-down-trigger" data-uid="{{$section->uid}}" title="Move Down">
-                    <i class="fa fa-arrow-down"></i>
-                </a>
+                    <a href="#" class="d-none if-edit ml-2 move-up-trigger" data-uid="{{$section->uid}}" title="Move Up">
+                        <i class="fa fa-arrow-up"></i>
+                    </a>
+                    <a href="#" class="d-none if-edit ml-2 move-down-trigger" data-uid="{{$section->uid}}" title="Move Down">
+                        <i class="fa fa-arrow-down"></i>
+                    </a>
                 @endif
             </div>
         @endif
     </div>
+
     @if(!isset($guestAccessCode) || $section->guest_access_level == 'READ')
-    <div class="{{isset($guestAccessCode)?'':'d-none'}} if-not-edit  inset-comment summary-container">
-        <?php if ($section->sectionTemplate->is_page_driven): ?>
-            @include("app.patient.page-sections.{$sectionInternalName}.summary")
-        <?php else: ?>
-            {!! !empty($section->summary_html) ? $section->summary_html : '-' !!}
-        <?php endif; ?>
-    </div>
+        <div class="{{isset($guestAccessCode)?'':'d-none'}} if-not-edit  inset-comment summary-container">
+            <?php if ($section->sectionTemplate->is_page_driven): ?>
+                @include("app.patient.page-sections.{$sectionInternalName}.summary")
+            <?php else: ?>
+                {!! !empty($section->summary_html) ? $section->summary_html : '-' !!}
+            <?php endif; ?>
+        </div>
     @endif
 
     @if(!$section->sectionTemplate->is_page_driven && (!isset($guestAccessCode) || $section->guest_access_level == 'WRITE'))
-    <div class="{{isset($guestAccessCode)?'':'d-none'}} if-edit">
+        <div class="{{isset($guestAccessCode)?'':'d-none'}} if-edit">
 
         <?php
         // if page
-        if ($section->sectionTemplate->is_page_driven) {
-        $contentData = false;
+            if ($section->sectionTemplate->is_page_driven) {
+                $contentData = false;
         ?>
-        @include("app.patient.page-sections.{$sectionInternalName}.form")
+            @include("app.patient.page-sections.{$sectionInternalName}.form")
         <?php
         }
         // if canvas
@@ -133,8 +134,8 @@ if ($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
             }
         ?>
             <input type="hidden" name="data">
-            <div note-rte data-content="{{$contentData['value']}}" class="form-group mb-2 border-left border-right rte-holder"></div>
-        <?php
+                <div note-rte data-content="{{$contentData['value']}}" class="form-group mb-2 border-left border-right rte-holder"></div>
+            <?php
         }
         ?>
 
@@ -145,4 +146,13 @@ if ($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
         </div>
     </div>
     @endif
+
+    @if($section->sectionTemplate->is_page_driven && (!isset($guestAccessCode) || $section->guest_access_level == 'WRITE'))
+        <div class="{{isset($guestAccessCode)?'':'d-none'}} if-edit">
+
+
+            @include("app.patient.page-sections.{$sectionInternalName}.form")
+
+        </div>
+    @endif
 </div>

+ 35 - 0
resources/views/app/patient/note/segment.blade.php

@@ -0,0 +1,35 @@
+<div class="p-3 border-bottom note-section visit-segment edit-trigger"
+	 data-segment-uid="{{ $segment->uid }}"
+	 data-segment-template-uid="{{ $segment->segmentTemplate->uid }}"
+	 data-segment-template-name="{{ $segment->segmentTemplate->internal_name }}">
+
+	<div class="d-flex align-items-start">
+
+		<!-- title -->
+		<span class="font-weight-bold mb-2 d-flex align-items-center">
+			{{$segment->display_title}}
+		</span>
+
+		<a class="edit-trigger d-none if-edit c-pointer ml-3">Close</a>
+
+		<!-- refresh -->
+		<span class="mx-2 text-secondary text-sm">|</span>
+		<a class="font-weight-normal refresh-segment c-pointer"
+		   data-segment-uid="{{$segment->uid}}"
+		   title="Update with latest patient data">
+			Refresh
+		</a>
+
+		@include('app/patient/note/_templates-v2-index', ['sectionInternalName' => $segment->segmentTemplate->internal_name])
+
+	</div>
+
+	<div class="d-none if-not-edit inset-comment summary-container">
+		{!! $segment->summary_html !!}
+	</div>
+
+	<div class="d-none if-edit edit-container">
+    	{!! $segment->edit_html !!}
+	</div>
+
+</div>

+ 228 - 0
resources/views/app/patient/note/segment_script.blade.php

@@ -0,0 +1,228 @@
+<script>
+    (function() {
+
+        function updateAllSegmentsInResponse(_response) {
+            if(!hasResponseError(_response)) {
+                for (let i=0; i<_response.data.length; i++) {
+                    updateSegmentFromObject(_response.data[i]);
+                }
+            }
+        }
+
+        function updateSegmentFromObject(_object) {
+            let segment = $('.note-section[data-segment-uid="' + _object.segmentUid + '"]');
+            if(segment && segment.length) {
+                segment.find('.summary-container').html(_object.summaryHtml);
+                segment.find('.edit-container').html(_object.editHtml);
+                initRTEs(segment);
+                initSegmentMoes(segment);
+                initMoes();
+                initStagSuggest();
+                if(window.segmentInitializers) {
+                    let internalName = segment.attr('data-segment-template-name');
+                    if(window.segmentInitializers.hasOwnProperty(internalName) &&
+                        typeof window.segmentInitializers[internalName] === 'function') {
+                        window.segmentInitializers[internalName].call(window);
+                    }
+                }
+            }
+        }
+
+        function initSegmentMoes(_parent) {
+
+            $('body')
+                .off('mousedown.visit-moe-outside-click')
+                .on('mousedown.visit-moe-outside-click', function (e) {
+                    if ($(e.target).closest('[visit-moe]').length) {
+                        return;
+                    }
+                    $('[visit-moe] [url]:not([show])').hide();
+                });
+
+            _parent.find('[visit-moe] [submit]')
+                .off('click.visit-moe-submit')
+                .on('click.visit-moe-submit', function() {
+                    let form = $(this).closest('form');
+
+                    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));
+                    }
+
+                    showMask();
+
+                    let closeOnSave = false, noteSection = form.closest('.note-section');
+                    if($(this).closest('[visit-moe]').is('[close-on-save]')) {
+                        closeOnSave = true;
+                    }
+
+                    $.post(form.attr('url'), form.serialize(), _data => {
+                        hideMask();
+                        updateAllSegmentsInResponse(_data);
+                        if(closeOnSave) {
+                            noteSection.removeClass('edit');
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            _parent.find('[visit-moe]>a[start]')
+                .off('click.visit-moe-show')
+                .on('click.visit-moe-show', function () {
+                    $('[visit-moe] [url]:not([show])').hide();
+                    $(this)
+                        .closest('[visit-moe]')
+                        .find('form[url]')
+                        .show();
+                    return false;
+                });
+
+            _parent.find('[visit-moe] [cancel]')
+                .off('click.visit-moe-cancel')
+                .on('click.visit-moe-cancel', function() {
+                    $(this).closest('[visit-moe]').find('[url]:not([show])').hide();
+                    if($(this).closest('[visit-moe]').is('[close-on-cancel]')) {
+                        $(this).closest('.note-section').removeClass('edit');
+                    }
+                    return false;
+                });
+        }
+
+        function initRTEs(_parent) {
+            _parent.find('[note-rte]:not(.ql-container)').each(function() {
+
+                $(this).wrap(
+                    $('<div class="border-left border-right rte-holder"/>')
+                        .attr('data-shortcuts', '')
+                );
+
+                // give a unique id to this editor instance
+                var editorID = Math.ceil(Math.random() * 99999),
+                    fieldName = this.name;
+
+                var el = this;
+                var existingContent = $(el).html();
+                var quill = new Quill(el, {
+                    theme: 'snow',
+                    modules: stagQuillConfig
+                });
+
+                var toolbar = $(quill.container).prev('.ql-toolbar');
+
+                // add button for new shortcut
+                var newSCButton = $('<button class="btn bg-white btn-sm btn-default text-primary w-auto px-2 border py-0 ' +
+                    'text-sm add-shortcut" data-editor-id="' + editorID + '">+ Shortcut</button>');
+                toolbar.append(newSCButton);
+
+                quill.root.innerHTML = existingContent;
+
+                quill.on('text-change', function(delta, oldDelta, source) {
+                    var content = quill.root.innerHTML;
+                    var dataValue = JSON.stringify({
+                        value: content
+                    });
+                    var dataField = $(el).closest('.note-section').find('input[name=data]').val(dataValue);
+                });
+
+                $(quill.container)
+                    .find('.ql-editor[contenteditable]')
+                    .attr('data-field', fieldName)
+                    .attr('data-editor-id', editorID)
+                    .attr('with-shortcuts', 1);
+            });
+        }
+
+        function init() {
+
+            let parent = $('.segments-list');
+            initRTEs(parent);
+            initSegmentMoes(parent);
+            initStagSuggest();
+
+            // check and run all segment initializers
+            if(window.segmentInitializers) {
+                for(let x in window.segmentInitializers) {
+                    if(window.segmentInitializers.hasOwnProperty(x) && typeof window.segmentInitializers[x] === 'function') {
+                        window.segmentInitializers[x].call(window);
+                    }
+                }
+            }
+
+            // refresh segment
+            $(document)
+                .off('click.refresh-segment', '.refresh-segment')
+                .on('click.refresh-segment', '.refresh-segment', function() {
+                    showMask();
+                    $.post('/api/visit/updateSegmentHtml', {
+                        segmentUid: $(this).attr('data-segment-uid')
+                    }, _data => {
+                        hideMask();
+                        updateAllSegmentsInResponse(_data);
+                    }, 'json');
+                    return false;
+                });
+
+            /*
+            $('[btn-save-form]').on('click', function() {
+                doSave($(this).closest('.note-section'));
+            });
+
+            @if(isset($guestAccessCode))
+                $('.note-section form').append("<input type='hidden' name='guest_access_code' value='{{$guestAccessCode}}'/>");
+            @endif
+
+            // copy link
+            $(document)
+                .off('click.copy', '.copy-link')
+                .on('click.copy', '.copy-link', function() {
+                    var copyText = $('#' + $(this).attr('data-id'));
+                    copyText.focus().select();
+                    document.execCommand("copy");
+                    toastr.success("The link " + copyText.val() + " has been copied to the clipboard");
+                    return false;
+                });
+
+            // [name="data"] change listener
+            $('.note-section input[name="data"], .note-section input[name="items"]').each(function() {
+                initChangeListener($(this));
+            });
+             */
+        }
+
+        addMCInitializer('note-segments-list', init);
+
+    })();
+</script>

+ 55 - 0
resources/views/app/patient/notes.blade.php

@@ -100,6 +100,61 @@
                     </div>
                 </form>
             </div>
+            <div moe>
+                <a start show class="py-0 mb-3">Add Visit</a>
+                <form url="/api/visit/create"
+                      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="effectiveDate" value="{{date("Y-m-d")}}">
+                    <input type="hidden" name="effectiveTime" value="{{date("h:i")}}">
+                    <input type="text" class="form-control form-control-sm" placeholder="title" 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="visitTemplateUid" class="form-control form-control-sm"
+                                onchange="$('#note-create-title').val($(this).find('option:selected').text())"
+                                required>
+                            <option value=""> --select--</option>
+                            @foreach($pro->visitTemplates() as $visitTemplate)
+                                <option value="{{$visitTemplate->uid}}">{{$visitTemplate->title}}</option>
+                            @endforeach
+                        </select>
+                    </div>
+                    <div class="mb-2">
+                        <label for="" class="text-secondary text-sm mb-1">New/Fu</label>
+                        <select name="newOrFuOrNa" class="form-control form-control-sm note-method-select" required>
+                            <option value="NEW">New</option>
+                            <option value="FU">Follow-Up</option>
+                        </select>
+                    </div>
+                    <div class="mb-2">
+                        <label for="" class="text-secondary text-sm mb-1">Method *</label>
+                        <select name="noteContactMethod" 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>
             <select class="ml-auto max-width-300px form-control form-control-sm"
                     onchange="fastLoad('/patients/view/{{$patient->uid}}/notes/' + this.value, true, false, false)">
                 <option value="active" {{ $filter === 'active' ? 'selected' : '' }}>Active notes</option>

+ 78 - 0
resources/views/app/patient/page-sections/cc/form.blade.php

@@ -0,0 +1,78 @@
+<?php
+
+use App\Models\Page;
+
+$page = Page::where('note_id', $note->id)->where('category', 'CHIEF_COMPLAINT')->first();
+
+
+$contentData = [
+    'value'=>''
+];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}
+?>
+<div id="ccSection">
+    <div class="form-group mb-2">
+        <input type="hidden" name="data" id="cc-data">
+        <div note-rte note-rte-ros data-content="{{isset($contentData['value'])?$contentData['value']:'' }}" class="form-group mb-2 border-left border-right rte-holder"></div>
+    </div>
+    <div class="form-group mb-2">
+        <button class="btn btn-sm btn-outline-primary" @click="save">Submit</button>
+    </div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            window.clientVitalsApp = new Vue({
+                el: '#ccSection',
+                data: {
+                    value: '',
+                },
+                mounted: function() {
+                    $(this.$el).closest('#ccSection').find('[name="data"]').val(this.value);
+                },
+                watch: {
+                    value: {
+                        handler: function(val, oldVal) {
+                            $(this.$el).closest('#ccSection').find('[name="data"]').val(this.value);
+                        },
+                        deep: true
+                    },
+                },
+                methods: {
+
+                    save: function(){
+                        console.log(this.value);
+                        showMask();
+                        console.log("DATA", this.value);
+
+                        var payload = {
+                            noteUid:  '{{$note->uid}}',
+                            parentPageUid: null,
+                            clientUid: '{{$patient->uid}}',
+                            category: 'CHIEF_COMPLAINT',
+                            key: null,
+                            data: $(this.$el).closest('#ccSection').find('[name="data"]').val()
+                        }
+                        console.log("PAYLOAD:  ", payload);
+                        $.post('/api/page/changeOrCreateNoteScoped', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Medication updated!');
+                                closeStagPopup();
+                            }
+                        }, 'json');
+                        hideMask();
+                        fastReload();
+                        return false;
+
+                    }
+                }
+            });
+        }
+        addMCInitializer('client-cc', init, '#ccSection');
+    })();
+</script>
+

+ 23 - 0
resources/views/app/patient/page-sections/cc/summary.php

@@ -0,0 +1,23 @@
+<?php
+
+use App\Models\Page;
+
+$page = Page::where('note_id', $note->id)->where('category', 'CHIEF_COMPLAINT')->first();
+
+$contentData = [
+    'value'=>''
+];
+if($page && $page->data){
+    $contentData = json_decode($page->data, true);
+}
+
+?>
+
+<?php if(!$page): ?>
+    <div>No CC data</div>
+<?php else: ?>
+    <div class="d-flex">
+        <div><?php echo $contentData['value'] ?></div>
+    </div>
+<?php endif; ?>
+

+ 121 - 0
resources/views/app/patient/page-sections/rx/form.blade.php

@@ -0,0 +1,121 @@
+<?php
+
+use App\Models\Page;
+
+$medicationsAddedOnIntake = Page::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->whereRaw("(is_active IS TRUE AND added_during_note_uid = ? AND added_reason_category = 'ADDED_ON_INTAKE') ",[$note->uid])
+    ->get();
+
+$medicationsRemovedOnIntake = Page::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->whereRaw("(is_active IS FALSE AND deactivated_during_note_uid  = ? AND deactivation_reason_category = 'REMOVED_ON_INTAKE')", [$note->uid])
+    ->get();
+
+
+?>
+<div id="medicationSection">
+    <table>
+        <thead>
+        <tr>
+            <th>Medication</th>
+            <th></th>
+            <th></th>
+            <th></th>
+        </tr>
+        </thead>
+        @foreach($medicationsAddedOnIntake as $medOnIntake)
+        <tr>
+            <td>{{$medOnIntake->key }}</td>
+            <td>Dose</td>
+            <td>Route</td>
+            <td>Frequency</td>
+            <td>Description</td>
+            <td></td>
+        </tr>
+        @endforeach
+        <tr>
+            <td>
+                <input type="text" v-model="currentMed.name" placeholder="name">
+            </td>
+            <td>
+                <input type="text" v-model="currentMed.dose" placeholder="dose">
+            </td>
+            <td>
+                <input type="text" v-model="currentMed.route" placeholder="route">
+            </td>
+            <td>
+                <input type="text" v-model="currentMed.frequency" placeholder="frequency">
+            </td>
+            <td>
+                <input type="text" v-model="currentMed.description" placeholder="description">
+            </td>
+            <td>
+                <button class="btn btn-sm btn-outline-primary" @click="save">Submit</button>
+            </td>
+        </tr>
+    </table>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            window.clientVitalsApp = new Vue({
+                el: '#medicationSection',
+                data: {
+                    value: '',
+                    currentMed: {
+                        name:'',
+                        dose:'',
+                        route:'',
+                        frequency:'',
+                        description:''
+                    }
+                },
+                mounted: function() {
+                    $(this.$el).closest('#medicationSection').find('[name="data"]').val(this.value);
+                },
+                watch: {
+                    value: {
+                        handler: function(val, oldVal) {
+                            $(this.$el).closest('#medicationSection').find('[name="data"]').val(this.value);
+                        },
+                        deep: true
+                    },
+                },
+                methods: {
+
+                    save: function(){
+                        console.log(this.value);
+                        showMask();
+                        console.log("DATA", this.value);
+                        this.currentMed.isActive = true;
+                        this.currentMed.addedReasonCategory = 'ADDED_ON_INTAKE'; // ADDED_BY_HCP_DURING_NOTE, ADDED_ON_INTAKE;
+                        this.currentMed.addedReasonCategoryMemo = 'added on intake';
+                        var payload = {
+                            noteUid:  '{{$note->uid}}',
+                            parentPageUid: null,
+                            clientUid: '{{$patient->uid}}',
+                            category: 'MEDICATION',
+                            key: this.currentMed.name,
+                            data: JSON.stringify(this.currentMed)
+                        }
+                        console.log("PAYLOAD:  ", payload);
+                        $.post('/api/page/changeOrCreateClientScoped', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Medication updated!');
+                                closeStagPopup();
+                            }
+                        }, 'json');
+                        hideMask();
+                        fastReload();
+                        return false;
+
+                    }
+                }
+            });
+        }
+        addMCInitializer('client-medication', init, '#medicationSection');
+    })();
+</script>
+

+ 45 - 0
resources/views/app/patient/page-sections/rx/summary.php

@@ -0,0 +1,45 @@
+<?php
+
+use App\Models\Page;
+
+$medicationsAddedOnIntake = Page::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->whereRaw("(is_active IS TRUE AND  added_reason_category = 'ADDED_ON_INTAKE') ") //TODO fix query
+    ->get();
+
+$medicationsRemovedOnIntake = Page::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->whereRaw("(is_active IS FALSE AND deactivated_during_note_uid  = ? AND deactivation_reason_category = 'REMOVED_ON_INTAKE')", [$note->uid])
+    ->get();
+
+?>
+
+<?php if(!count($medicationsAddedOnIntake)): ?>
+    <div>No medications</div>
+<?php else: ?>
+    <div><h1><?php echo count($medicationsAddedOnIntake); ?></h1></div>
+    <div class="d-flex">
+        <table>
+            <thead>
+            <tr>
+                <th>Medication</th>
+                <th>Dose</th>
+                <th>Route</th>
+                <th>Frequency</th>
+                <th></th>
+            </tr>
+            </thead>
+            <?php foreach($medicationsAddedOnIntake as $medOnIntake): ?>
+            <tr>
+                <td><?php echo $medOnIntake->key ?></td>
+                <td><?php echo $medOnIntake->data_dose ?></td>
+                <td><?php echo $medOnIntake->data_route ?></td>
+                <td><?php echo $medOnIntake->data_frequency ?></td>
+                <td></td>
+            </tr>
+            <?php endforeach; ?>
+
+        </table>
+    </div>
+<?php endif; ?>
+

+ 78 - 0
resources/views/app/patient/page-sections/subjective/form.blade.php

@@ -0,0 +1,78 @@
+<?php
+
+use App\Models\Page;
+
+$page = Page::where('note_id', $note->id)->where('category', 'SUBJECTIVE_GENERAL')->first();
+
+
+$contentData = [
+    'value'=>''
+];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}
+?>
+<div id="subjectiveSection">
+    <div class="form-group mb-2">
+        <input type="hidden" name="data" id="subjective-data">
+        <div note-rte note-rte-ros data-content="{{isset($contentData['value'])?$contentData['value']:'' }}" class="form-group mb-2 border-left border-right rte-holder"></div>
+    </div>
+    <div class="form-group mb-2">
+        <button class="btn btn-sm btn-outline-primary" @click="save">Submit</button>
+    </div>
+</div>
+
+<script>
+    (function() {
+        function init() {
+            window.clientVitalsApp = new Vue({
+                el: '#subjectiveSection',
+                data: {
+                    value: '',
+                },
+                mounted: function() {
+                    $(this.$el).closest('#subjectiveSection').find('[name="data"]').val(this.value);
+                },
+                watch: {
+                    value: {
+                        handler: function(val, oldVal) {
+                            $(this.$el).closest('#subjectiveSection').find('[name="data"]').val(this.value);
+                        },
+                        deep: true
+                    },
+                },
+                methods: {
+
+                    save: function(){
+                        console.log(this.value);
+                        showMask();
+                        console.log("DATA", this.value);
+
+                        var payload = {
+                            noteUid:  '{{$note->uid}}',
+                            parentPageUid: null,
+                            clientUid: '{{$patient->uid}}',
+                            category: 'SUJECTIVE_GENERAL',
+                            key: null,
+                            data: $(this.$el).closest('#subjectiveSection').find('[name="data"]').val()
+                        }
+                        console.log("PAYLOAD:  ", payload);
+                        $.post('/api/page/changeOrCreateNoteScoped', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Record updated!');
+                                closeStagPopup();
+                            }
+                        }, 'json');
+                        hideMask();
+                        fastReload();
+                        return false;
+
+                    }
+                }
+            });
+        }
+        addMCInitializer('client-subjective', init, '#subjectiveSection');
+    })();
+</script>
+

+ 23 - 0
resources/views/app/patient/page-sections/subjective/summary.php

@@ -0,0 +1,23 @@
+<?php
+
+use App\Models\Page;
+
+$page = Page::where('note_id', $note->id)->where('category', 'SUBJECTIVE_GENERAL')->first();
+
+$contentData = [
+    'value'=>''
+];
+if($page && $page->data){
+    $contentData = json_decode($page->data, true);
+}
+
+?>
+
+<?php if(!$page): ?>
+    <div>No Subject data</div>
+<?php else: ?>
+    <div class="d-flex">
+        <div><?php echo $contentData['value'] ?></div>
+    </div>
+<?php endif; ?>
+

+ 20 - 0
resources/views/app/patient/page-sections/vitals/default.php

@@ -0,0 +1,20 @@
+<?php
+
+
+use App\Models\Page;
+
+$page = Page::where('client_id', $patient->id)->where('category', 'VITALS')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if ($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if (isset($canvasData["vitals"])) {
+            $contentData = $canvasData["vitals"];
+        }
+    }
+}
+

+ 264 - 0
resources/views/app/patient/page-sections/vitals/form.blade.php

@@ -0,0 +1,264 @@
+<?php
+
+use App\Models\Page;
+
+$page = Page::where('note_id', $note->id)->where('category', 'VITALS')->first();
+
+$contentData = [];
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}
+
+$vitalLabels = [
+    "heightInInches" => "Ht. (in.)",
+    "weightPounds" => "Wt. (lbs.)",
+    "temperatureF" => "Temp. (F)",
+    "systolicBP" => "SBP",
+    "diastolicBP" => "DBP",
+    "pulseRatePerMinute" => "Pulse",
+    "respirationRatePerMinute" => "Resp.",
+    "pulseOx" => "Pulse Ox.",
+    "smokingStatus" => "Smoking Status",
+    "bmi" => "BMI (kg/m²)",
+];
+if(!$contentData) {
+    $contentData = [
+        "heightInInches" => [
+            "label" => "Ht. (in.)",
+            "value" => "",
+            "date" => "",
+        ],
+        "weightPounds" => [
+            "label" => "Wt. (lbs.)",
+            "value" => "",
+            "date" => "",
+        ],
+        "temperatureF" => [
+            "label" => "Temp. (F)",
+            "value" => "",
+            "date" => "",
+        ],
+        "systolicBP" => [
+            "label" => "SBP",
+            "value" => "",
+            "date" => "",
+        ],
+        "diastolicBP" => [
+            "label" => "DBP",
+            "value" => "",
+            "date" => "",
+        ],
+        "pulseRatePerMinute" => [
+            "label" => "Pulse",
+            "value" => "",
+            "date" => "",
+        ],
+        "respirationRatePerMinute" => [
+            "label" => "Resp.",
+            "value" => "",
+            "date" => "",
+        ],
+        "pulseOx" => [
+            "label" => "Pulse Ox.",
+            "value" => "",
+            "date" => "",
+        ],
+        "smokingStatus" => [
+            "label" => "Smoking Status",
+            "value" => "",
+            "date" => "",
+        ],
+        "bmi" => [
+            "label" => "BMI (kg/m²)",
+            "value" => "",
+            "date" => "",
+        ],
+    ];
+}
+else {
+    // ensure $contentData has all the expected vitals and correct labels!
+    foreach ($vitalLabels as $k => $v) {
+        if(!isset($contentData[$k])) {
+            $contentData[$k] = [
+                "label" => $v,
+                "value" => "",
+                "date" => "",
+            ];
+        }
+    }
+}
+
+$formID = rand(0, 100000);
+?>
+<div id="vitalsSection">
+    <h3 class="stag-popup-title mb-2 border-bottom-0 pb-1 hide-if-note">
+        <span>Vitals</span>
+        <a href="#" onclick="return closeStagPopup()"
+           class="ml-auto text-secondary">
+            <i class="fa fa-times-circle"></i>
+        </a>
+    </h3>
+
+    <input type="hidden" name="data" value="{{json_encode($contentData)}}">
+
+    <table class="table table-sm table-bordered mb-2 table-edit-sheet">
+        <thead>
+        <tr class="bg-light">
+            <th class="px-2 text-secondary border-bottom-0 w-25">Vital</th>
+            <th class="px-2 text-secondary border-bottom-0 w-35">Value</th>
+            <th class="px-2 text-secondary border-bottom-0">Date</th>
+        </tr>
+        </thead>
+        <tbody>
+            @foreach($vitalLabels as $k => $v)
+                <tr>
+                    <td>
+                        <input type="text" tabindex="-1"
+                               class="form-control form-control-sm events-none"
+                               data-field="title" value="{{ $v }}" readonly>
+                    </td>
+                    <td class="position-relative">
+                        @if($k === "bmi")
+                            <input type="text" readonly
+                                   class="form-control form-control-sm vitals-title"
+                                   data-field="value" v-model="bmi">
+                            <p class="py-1 m-0 px-2 font-weight-bold bg-white" v-if="!!bmi">
+                                <span class="text-sm text-warning-mellow" v-if="+bmi < 18.5">Underweight</span>
+                                <span class="text-sm text-success" v-if="+bmi >= 18.5 && +bmi < 25">Healthy Weight</span>
+                                <span class="text-sm text-warning-mellow" v-if="+bmi >= 25 && +bmi < 30">Overweight</span>
+                                <span class="text-sm text-warning-mellow" v-if="+bmi >= 30">Obese</span>
+                            </p>
+                        @elseif($k === "smokingStatus")
+                            <input type="text"
+                                   class="form-control form-control-sm"
+                                   data-field="value" v-model="items['smokingStatus'].value"
+                                   data-option-list="smokingStatus"
+                                   v-on:change="autoDate(items['smokingStatus'], 'smokingStatus')" v-on:keyup="autoDate(items['smokingStatus'], 'smokingStatus')">
+                            <div id="smoking-status-options" class="data-option-list">
+                                <div>Current</div>
+                                <div>Former</div>
+                                <div>Never</div>
+                            </div>
+                        @else
+                            <input type="text"
+                                   class="form-control form-control-sm"
+                                   data-field="value" v-model="items['{{ $k }}'].value"
+                                   v-on:change="autoDate(items['{{ $k }}'], '{{ $k }}')" v-on:keyup="autoDate(items['{{ $k }}'], '{{ $k }}')">
+                        @endif
+                    </td>
+                    <td>
+                        <input type="date" {{ $k === 'bmi' ? 'readonly' : '' }}
+                               class="form-control form-control-sm vitals-title"
+                               data-field="date" v-model="items['{{ $k }}'].date">
+                    </td>
+                </tr>
+
+            @endforeach
+        </tbody>
+    </table>
+    <div>
+        <button class="btn btn-sm btn-outline-primary" @click="save">Submit</button>
+    </div>
+</div>
+<script>
+    (function() {
+        function init() {
+            window.clientVitalsApp = new Vue({
+                el: '#vitalsSection',
+                data: {
+                    today: '{{ date("Y-m-d") }}',
+                    items: <?= json_encode($contentData) ?>,
+                    itemsOriginal: <?= json_encode($contentData) ?>
+                },
+                mounted: function() {
+                    $(this.$el).closest('#vitalsSection').find('[name="data"]').val(
+                        JSON.stringify(this.cleanObject(this.items))
+                    );
+                },
+                watch: {
+                    items: {
+                        handler: function(val, oldVal) {
+                            $(this.$el).closest('#vitalsSection').find('[name="data"]').val(
+                                JSON.stringify(this.cleanObject(this.items))
+                            );
+                        },
+                        deep: true
+                    },
+                },
+                computed: {
+                    bmi: function () {
+                        let result = '';
+                        let h = this.items.heightInInches, w = this.items.weightPounds;
+                        if(!h || !w) {
+                            return result;
+                        }
+                        h = h.value;
+                        w = w.value;
+                        try {
+                            h = parseFloat(h);
+                            w = parseFloat(w);
+                            if(!h || !w) {
+                                this.items.bmi.value = '';
+                                return result;
+                            }
+                            let result = (w / [ h * h]) * 703;
+                            return result.toFixed(1);
+                        }
+                        catch (e) {
+                            return result;
+                        }
+                    }
+                },
+                methods: {
+                    autoDate: function(_item, _index) {
+                        console.log('ALIX autoDate for', _index)
+                        if((_item.value !== this.itemsOriginal[_index].value) && !_item.date) {
+                            _item.date = this.today;
+                        }
+                    },
+                    cleanObject: function(_source) {
+                        let plObject = {};
+                        for (let y in _source) {
+                            if(_source.hasOwnProperty(y)) {
+                                plObject[y] = _source[y];
+                            }
+                        }
+                        plObject.bmi = {
+                            label: "BMI (kg/m²)",
+                            value: this.bmi,
+                            date: this.bmi ? this.today : '',
+                        };
+                        return plObject;
+                    },
+                    save: function(){
+                        console.log(this.items);
+                        showMask();
+                        console.log("DATA", this.items);
+
+                        var payload = {
+                             noteUid:  '{{$note->uid}}',
+                             parentPageUid: null,
+                             clientUid: '{{$patient->uid}}',
+                             category: 'VITALS',
+                             key: null,
+                             data: JSON.stringify(this.items)
+                        }
+                        console.log("PAYLOAD:  ", payload);
+                        $.post('/api/page/changeOrCreateNoteScoped', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Record updated!');
+                                closeStagPopup();
+                            }
+                        }, 'json');
+                        hideMask();
+                        fastReload();
+                        return false;
+
+                    }
+                }
+            });
+        }
+        addMCInitializer('client-vitals', init, '#vitalsSection');
+    })();
+</script>

+ 131 - 0
resources/views/app/patient/page-sections/vitals/summary.php

@@ -0,0 +1,131 @@
+<?php
+
+use App\Models\Page;
+
+$page = Page::where('note_id', $note->id)->where('category', 'VITALS')->first();
+$vitalLabels = [
+    "heightInInches" => "Ht. (in.)",
+    "weightPounds" => "Wt. (lbs.)",
+    "temperatureF" => "Temp. (F)",
+    "systolicBP" => "SBP",
+    "diastolicBP" => "DBP",
+    "pulseRatePerMinute" => "Pulse",
+    "respirationRatePerMinute" => "Resp.",
+    "pulseOx" => "Pulse Ox.",
+    "smokingStatus" => "Smoking Status",
+    "bmi" => "BMI (kg/m²)",
+];
+$contentData = [
+    "heightInInches" => [
+        "label" => "Ht. (in.)",
+        "value" => "",
+        "date" => "",
+    ],
+    "weightPounds" => [
+        "label" => "Wt. (lbs.)",
+        "value" => "",
+        "date" => "",
+    ],
+    "temperatureF" => [
+        "label" => "Temp. (F)",
+        "value" => "",
+        "date" => "",
+    ],
+    "systolicBP" => [
+        "label" => "SBP",
+        "value" => "",
+        "date" => "",
+    ],
+    "diastolicBP" => [
+        "label" => "DBP",
+        "value" => "",
+        "date" => "",
+    ],
+    "pulseRatePerMinute" => [
+        "label" => "Pulse",
+        "value" => "",
+        "date" => "",
+    ],
+    "respirationRatePerMinute" => [
+        "label" => "Resp.",
+        "value" => "",
+        "date" => "",
+    ],
+    "pulseOx" => [
+        "label" => "Pulse Ox.",
+        "value" => "",
+        "date" => "",
+    ],
+    "smokingStatus" => [
+        "label" => "Smoking Status",
+        "value" => "",
+        "date" => "",
+    ],
+    "bmi" => [
+        "label" => "BMI (kg/m²)",
+        "value" => "",
+        "date" => "",
+    ],
+];
+
+
+if($page){
+    $contentData = json_decode($page->data, true);
+}else{
+    if($patient->canvas_data) {
+        $canvasData = json_decode($patient->canvas_data, true);
+        if(isset($canvasData["vitals"])) {
+            $contentData = $canvasData["vitals"];
+            // ensure $contentData has all the expected vitals and correct labels!
+        }
+    }
+}
+
+foreach ($vitalLabels as $k => $v) {
+    if(!isset($contentData[$k])) {
+        $contentData[$k] = [
+            "label" => $v,
+            "value" => "",
+            "date" => "",
+        ];
+    }
+}
+
+foreach ($vitalLabels as $k => $v) {
+?>
+    <div class="d-flex vital-item align-items-center">
+        <span class="content-html text-nowrap">
+            <span><?= $v ?>:</span>
+            <?php
+            $vital = [];
+            if(isset($contentData[$k])) {
+                $vital = $contentData[$k];
+            }
+            ?>
+            <b><?= isset($vital["value"]) && !empty($vital["value"]) ? $vital["value"] : '-' ?></b>
+            <?php if($k === 'bmi' && isset($vital["value"]) && !empty($vital["value"])):
+                $bmi = floatval($vital["value"]);
+                ?>
+                <span class="ml-2 py-1 m-0 font-weight-bold">
+                    <?php if($bmi < 18.5): ?>
+                        <span class="text-sm text-warning-mellow">(Underweight)</span>
+                    <?php endif; ?>
+                    <?php if($bmi >= 18.5 && $bmi < 25): ?>
+                        <span class="text-sm text-success">(Healthy Weight)</span>
+                    <?php endif; ?>
+                    <?php if($bmi >= 25 && $bmi < 30): ?>
+                        <span class="text-sm text-warning-mellow">(Overweight)</span>
+                    <?php endif; ?>
+                    <?php if($bmi >= 30): ?>
+                        <span class="text-sm text-warning-mellow">(Obese)</span>
+                    <?php endif; ?>
+                </span>
+            <?php endif; ?>
+            <?php if(!!$vital["date"]): ?>
+                <span class="font-weight-normal text-secondary ml-2 text-sm">(as on <?= friendly_date_time($vital["date"], false) ?>)</span>
+            <?php endif; ?>
+        </span>
+    </div>
+<?php
+}
+?>

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

@@ -0,0 +1,37 @@
+<?php
+if (!@$intakeOrVisit) {
+    $intakeOrVisit = 'INTAKE'; // default
+}
+$epPart = ($intakeOrVisit === 'INTAKE') ? 'Review' : 'Plan';
+$currentValue = '';
+if($intakeOrVisit === 'INTAKE') {
+    if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
+        $parsedReview = json_decode($point->lastChildReview->data);
+        $currentValue = $parsedReview->value;
+    }
+}
+else {
+    if ($point->lastChildPlan && $point->last_child_plan_point_scoped_note_id === $note->id) {
+        $parsedReview = json_decode($point->lastChildPlan->data);
+        $currentValue = $parsedReview->value;
+    }
+}
+?>
+<div visit-moe relative>
+    <a start show href="#">Edit</a>
+    <form url="/api/visitPoint/upsertChild<?= $epPart ?>" 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>
+
+        <div class="mb-2">
+            <textarea data-name="value" class="form-control form-control-sm" rows="3"><?= $currentValue ?></textarea>
+        </div>
+        <div>
+            <button submit class="btn btn-sm btn-primary mr-2">Save</button>
+            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+        </div>
+    </form>
+</div>

+ 38 - 0
resources/views/app/patient/segment-templates/_child_review/last-review.php

@@ -0,0 +1,38 @@
+<?php
+if (!@$intakeOrVisit) {
+    $intakeOrVisit = 'INTAKE'; // default
+}
+?>
+<?php if ($intakeOrVisit === 'INTAKE'): ?>
+    <?php if ($point->lastChildReview): ?>
+        <?php $parsedReview = json_decode($point->lastChildReview->data); ?>
+        <div><?= $parsedReview->value ?></div>
+        <div class="text-secondary text-sm"></div>
+        <?php if ($point->last_child_review_point_scoped_note_id === $note->id): ?>
+            <span class="text-secondary text-sm">(reviewed on this note)</span>
+        <?php else: ?>
+            <a native target="_blank"
+               href="<?= route('patients.view.notes.view.dashboard', ['patient' => $patient, 'note' => $point->lastChildReviewNote]) ?>">
+                <?= friendlier_date_time($point->last_child_review_effective_date) ?>
+            </a>
+        <?php endif; ?>
+    <?php else: ?>
+        <span class="text-secondary text-sm">None</span>
+    <?php endif; ?>
+<?php else: ?>
+    <?php if ($point->lastChildPlan): ?>
+        <?php $parsedReview = json_decode($point->lastChildPlan->data); ?>
+        <div><?= $parsedReview->value ?></div>
+        <div class="text-secondary text-sm"></div>
+        <?php if ($point->last_child_plan_point_scoped_note_id === $note->id): ?>
+            <span class="text-secondary text-sm">(reviewed on this note)</span>
+        <?php else: ?>
+            <a native target="_blank"
+               href="<?= route('patients.view.notes.view.dashboard', ['patient' => $patient, 'note' => $point->lastChildPlanNote]) ?>">
+                <?= friendlier_date_time($point->last_child_plan_effective_date) ?>
+            </a>
+        <?php endif; ?>
+    <?php else: ?>
+        <span class="text-secondary text-sm">None</span>
+    <?php endif; ?>
+<?php endif; ?>

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

@@ -0,0 +1,160 @@
+<?php
+if(!@$intakeOrVisit) {
+    $intakeOrVisit = 'INTAKE'; // default
+}
+$whenLabel = ($intakeOrVisit === 'INTAKE') ? 'on intake' : 'during visit';
+$epPart = ($intakeOrVisit === 'INTAKE') ? 'OnIntake' : 'DuringVisit';
+?>
+<?php if ($point->is_removed): ?>
+    <?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: ?>
+        <span class="font-weight-bold text-secondary mr-2 text-nowrap">Removed <?= $whenLabel ?></span>
+    <?php endif; ?>
+    <div visit-moe>
+        <form show url="/api/visitPoint/undoMarkRemoved" class="mcp-theme-1">
+            <input type="hidden" name="uid" value="<?= $point->uid ?>">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <a submit href="#">Undo</a>
+        </form>
+    </div>
+<?php else: ?>
+    <?php if($point->added_in_note_id === $note->id): ?>
+        <span class="font-weight-bold text-success mx-2 text-nowrap">* Added <?= $whenLabel ?></span>
+    <?php endif; ?>
+    <div visit-moe>
+        <a start show href="#">Remove</a>
+        <form url="/api/visitPoint/markRemoved<?= $epPart ?>" class="mcp-theme-1">
+            <input type="hidden" name="uid" value="<?= $point->uid ?>">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+
+            <p class="mb-2"><b>Remove <?= $label ?> <?= $whenLabel ?></b></p>
+
+            <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>
+            <?php if($point->added_in_note_id === $note->id): ?>
+                <div class="mb-2">
+                    <label class="text-sm text-secondary mb-1">Is Entry Error?  *</label>
+                    <select name="isRemovedDueToEntryError" class="form-control form-control-sm" required>
+                        <option value="">-- select --</option>
+                        <option value="1" selected>Yes</option>
+                        <option value="0">No</option>
+                    </select>
+                </div>
+            <?php else: ?>
+                <input type="hidden" name="isRemovedDueToEntryError" value="0">
+            <?php endif; ?>
+            <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">Remove</button>
+                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+            </div>
+        </form>
+    </div>
+<?php endif; ?>
+
+<!-- additional actions -->
+<div class="ml-2 position-relative on-click-menu">
+    <span class="d-block btn btn-sm btn-default px-1 py-0 border font-weight-bold text-secondary align-middle">&hellip;</span>
+    <div menu class="bg-white border">
+
+        <!-- if removed -->
+            <!-- ACT: update removal reason memo -->
+            <!-- if entry error -->
+                <!-- ACT: mark as not entry error-->
+            <!-- if not entry error-->
+                <!-- ACT: mark as entry error-->
+        <!-- if not removed -->
+            <!-- ACT: update addition reason memo -->
+            <!-- ACT: mark added during visit -->
+
+        <?php if ($point->is_removed): ?>
+            <div class="border-bottom">
+                <div visit-moe>
+                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Update removal reason</a>
+                    <form url="/api/visitPoint/updateRemovalReasonMemo" class="mcp-theme-1">
+                        <input type="hidden" name="uid" value="<?= $point->uid ?>">
+                        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+                        <p class="mb-2"><b>Update Removal Reason</b></p>
+                        <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>
+                            <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>
+            </div>
+            <?php if ($point->is_removed_due_to_entry_error): ?>
+                <div class="border-bottom">
+                    <div visit-moe>
+                        <form show url="/api/visitPoint/setIsRemovedDueToEntryErrorToFalse" class="mcp-theme-1">
+                            <input type="hidden" name="uid" value="<?= $point->uid ?>">
+                            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+                            <a submit href="#" class="text-nowrap px-2 py-1 d-block">Mark as not entry error</a>
+                        </form>
+                    </div>
+                </div>
+            <?php else: ?>
+                <div class="border-bottom">
+                    <div visit-moe>
+                        <form show url="/api/visitPoint/setIsRemovedDueToEntryErrorToTrue" class="mcp-theme-1">
+                            <input type="hidden" name="uid" value="<?= $point->uid ?>">
+                            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+                            <a submit href="#" class="text-nowrap px-2 py-1 d-block">Mark as entry error</a>
+                        </form>
+                    </div>
+                </div>
+            <?php endif; ?>
+        <?php else: ?>
+            <div class="border-bottom">
+                <div visit-moe>
+                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Update addition reason</a>
+                    <form url="/api/visitPoint/updateAdditionReasonMemo" class="mcp-theme-1">
+                        <input type="hidden" name="uid" value="<?= $point->uid ?>">
+                        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+                        <p class="mb-2"><b>Update Addition Reason</b></p>
+                        <div class="mb-2">
+                            <label class="text-sm text-secondary mb-1">Addition Reason</label>
+                            <textarea name="additionReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+                        </div>
+                        <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>
+            </div>
+            <div class="border-bottom">
+                <div visit-moe>
+                    <a start show href="#" class="px-2 py-1 d-block text-nowrap">Mark as added <?= $whenLabel ?></a>
+                    <form url="/api/visitPoint/markAdded<?= $epPart ?>" class="mcp-theme-1">
+                        <input type="hidden" name="uid" value="<?= $point->uid ?>">
+                        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+                        <p class="mb-2"><b>Mark as added <?= $whenLabel ?></b></p>
+                        <div class="mb-2">
+                            <label class="text-sm text-secondary mb-1">Addition Reason</label>
+                            <textarea name="additionReasonMemo" class="form-control form-control-sm" rows="2"></textarea>
+                        </div>
+                        <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>
+            </div>
+        <?php endif; ?>
+
+
+    </div>
+</div>

+ 24 - 0
resources/views/app/patient/segment-templates/_simple_text_segment/edit.php

@@ -0,0 +1,24 @@
+<?php
+
+use App\Models\Point;
+
+$point = Point::where('added_in_segment_id', $segment->id)->where('category', $category)->orderBy('id', 'DESC')->first();
+$parsed = null;
+if (!!@$point->data) {
+    $parsed = json_decode($point->data);
+}
+?>
+<div visit-moe close-on-save close-on-cancel class="d-block">
+    <form show url="/api/visitPoint/<?= $endPoint ?>" class="mcp-theme-1">
+        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+        <input type="hidden" name="category" value="<?= $category ?>">
+        <input type="hidden" name="data">
+        <div note-rte
+             class="form-group mb-2 border-left border-right rte-holder"
+        ><?= $parsed && $parsed->value ? $parsed->value : '' ?></div>
+        <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>

+ 20 - 0
resources/views/app/patient/segment-templates/_simple_text_segment/summary.php

@@ -0,0 +1,20 @@
+<?php
+
+use App\Models\Point;
+
+$point = Point::where('added_in_segment_id', $segment->id)->where('category', $category)->orderBy('id', 'DESC')->first();
+$parsed = null;
+if (!!@$point->data) {
+    $parsed = json_decode($point->data);
+}
+?>
+<div>
+    <?php
+    if (!!$parsed && @$parsed->value) {
+        echo $parsed->value;
+    }
+    else {
+        echo "-";
+    }
+    ?>
+</div>

+ 4 - 0
resources/views/app/patient/segment-templates/chief_complaint/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'CHIEF_COMPLAINT';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/chief_complaint/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'CHIEF_COMPLAINT';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 1 - 0
resources/views/app/patient/segment-templates/history_family/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for history_family</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/history_family/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for history_family</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/history_screenings/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for history_screenings</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/history_screenings/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for history_screenings</h1>

+ 267 - 0
resources/views/app/patient/segment-templates/history_social/edit.blade.php

@@ -0,0 +1,267 @@
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$point = Point::getGlobalSingletonOfCategory($patient, 'SOCIAL_HISTORY',true);
+
+$socHx = $point->data;
+
+$fields = [
+    [
+        "Tobacco" => ["Current every day smoker", "Current some day smoker", "Former smoker", "Heavy tobacco smoker", "Light tobacco smoker", "Never smoker", "Smoker, current status unknown", "Unknown if ever smoked "],
+    ],
+    [
+        "Alcohol" => ["Do not drink", "Drink daily", "Frequently drink", "Hx of Alcoholism", "Occasional drink"],
+        "Drug Abuse" => ["IVDU", "Illicit drug use", "No illicit drug use"],
+    ],
+    [
+        "Cardiovascular" => ["Eat healthy meals", "Regular exercise", "Take daily aspirin"],
+        "Safety" => ["Household Smoke detector", "Keep Firearms in home", "Wear seatbelts"],
+    ],
+    [
+        "Sexual Activity" => ["Exposure to STI", "Homosexual encounters", "Not sexually active", "Safe sex practices", "Sexually active"],
+        "Birth Gender" => ["Male", "Female", "Undifferentiated"],
+    ]
+];
+
+$customFields = [];
+/*
+ // TODO
+$customFields = $pro->canvasCustomItems('sochx');
+$customFields = array_map(function($_item) {
+    return $_item['label'];
+}, $customFields->toArray());
+*/
+if (!$socHx) {
+    $socHx = [
+        "common" => [],
+        "custom" => [],
+        "comments" => "",
+    ];
+}
+
+$contentData = $socHx;
+?>
+<div visit-moe close-on-save close-on-cancel class="d-block">
+    <form show url="/api/visitPoint/upsertGlobalSingleton" class="mcp-theme-1">
+        <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+        <input type="hidden" name="category" value="SOCIAL_HISTORY">
+        <input type="hidden" name="data">
+        <div class="row">
+            <?php for ($i = 0; $i < count($fields); $i++): ?>
+                <div class="col-md-3">
+                    <?php foreach ($fields[$i] as $head => $values): ?>
+                        <div class="font-weight-bold mb-2"><?= $head ?></div>
+                        <div class="mb-3">
+                            <?php for ($k = 0; $k < count($values); $k++): ?>
+                                <?php $fName = $head . '_' . sanitize_field_name($values[$k]); ?>
+                                <label class="d-flex align-items-center mb-1">
+                                    <input type="checkbox" class="m-0"
+                                           data-name="common-><?= $fName ?>"
+                                        <?= @$contentData['common'][$fName] ? 'checked' : '' ?>
+                                    >
+                                    <span class="mx-2"><?= $values[$k] ?></span>
+                                    <!--<div moe>
+                                        <a href="#" start show>
+                                            <i v-show="common['<?= $fName ?>']" class="fa-comment"
+                                               :class="common['<?= $fName ?>__comments'] ? 'fas' : 'far'"></i>
+                                        </a>
+                                        <div url="/nop">
+                                            <div class="mb-2">
+                                        <textarea class="form-control form-control-sm ns-custom-comment"
+                                                  data-name="common['<?= $fName ?>__comments']"></textarea>
+                                            </div>
+                                            <div class="">
+                                                <button type="button" class="btn btn-sm btn-primary" cancel>Close
+                                                </button>
+                                            </div>
+                                        </div>
+                                    </div>-->
+                                </label>
+                            <?php endfor; ?>
+                        </div>
+                    <?php endforeach; ?>
+                </div>
+            <?php endfor; ?>
+        </div>
+
+        <?php /*
+            <div class="row border-top pt-3">
+                <div class="col-12">
+                    <div class="d-flex align-items-center mb-2">
+                        <span class="font-weight-bold">Custom Items</span>
+                        <span class="mx-2 text-secondary">|</span>
+                        <div moe>
+                            <a href="#" start show>Add</a>
+                            <div custom-item-form url="/api/sectionTemplateCustomItem/create">
+                                <div class="mb-2">
+                                    <input type="text" placeholder="Label"
+                                           v-model="newCustomItemLabel"
+                                           class="form-control form-control-sm label_new_custom_item">
+                                </div>
+                                <div>
+                                    <button type="button" class="btn btn-sm btn-primary mr-1"
+                                            v-on:click.prevent="saveCustomItem(newCustomItemLabel)">Submit</button>
+                                    <button type="button" class="btn btn-sm btn-default border"
+                                            v-on:click.prevent="cancelCustomItem()">Cancel</button>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+
+                    {{-- custom items --}}
+                    <div class="d-flex align-items-start flex-wrap custom-items-container">
+                        <div class="w-25" v-for="item in customFields">
+                            <label class="d-flex align-items-center mb-1">
+                                <input type="checkbox" class="m-0"
+                                       v-model="item.value">
+                                <span class="mx-2">@{{ item.label }}</span>
+                                <div moe>
+                                    <a href="#" start show>
+                                        <i v-show="item.value" class="fa-comment" :class="item.comments ? 'fas' : 'far'"></i>
+                                    </a>
+                                    <div url="/nop">
+                                        <div class="mb-2">
+                                            <textarea class="form-control form-control-sm ns-custom-comment" v-model="item.comments"></textarea>
+                                        </div>
+                                        <div class="">
+                                            <button type="button" class="btn btn-sm btn-primary" cancel>Close</button>
+                                        </div>
+                                    </div>
+                                </div>
+                            </label>
+                        </div>
+                    </div>
+
+                </div>
+            </div>
+            */ ?>
+
+        <div class="row mb-3">
+            <div class="col-12">
+                <textarea type="text" class="form-control form-control-sm p-2 mt-2"
+                          data-name="comments"
+                          placeholder="Comments"><?= @$contentData['comments'] ?: '' ?></textarea>
+            </div>
+        </div>
+
+        <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>
+
+<script>
+    (function () {
+        let model = <?= json_encode($contentData) ?>;
+        model.newCustomItemLabel = '';
+        let customFields = <?= json_encode($customFields) ?>;
+        if (!model.customFields) {
+            model.customFields = [];
+        }
+        for (let i = 0; i < customFields.length; i++) {
+            let found = model.customFields.filter(function (_item) {
+                return _item.label === customFields[i];
+            }).length;
+            if (!found) {
+                model.customFields.push({
+                    label: customFields[i],
+                    value: '',
+                    comments: '',
+                })
+            }
+        }
+
+        function init() {
+            window.clientSocHXApp = new Vue({
+                el: '#sochxSection',
+                data: model,
+                mounted: function () {
+                    $('#sochxSection [moe][initialized]').removeAttr('initialized');
+                    initMoes();
+                    $('#sochxSection').find('[name="data"]').val(JSON.stringify({
+                        common: this.cleanObject(this.common),
+                        customFields: this.customFields,
+                        comments: this.comments,
+                    }));
+                },
+                watch: {
+                    $data: {
+                        handler: function (val, oldVal) {
+                            $('#sochxSection').find('[name="data"]').val(JSON.stringify({
+                                common: this.cleanObject(this.common),
+                                customFields: this.customFields,
+                                comments: this.comments,
+                            }));
+                        },
+                        deep: true
+                    }
+                },
+                methods: {
+                    cleanObject: function (_source) {
+                        let plObject = {};
+                        for (let y in _source) {
+                            if (_source.hasOwnProperty(y)) {
+                                plObject[y] = _source[y];
+                            }
+                        }
+                        return plObject;
+                    },
+                    saveCustomItem: function (_label) {
+                        if (!_label) return false;
+                        showMask();
+                        let self = this;
+                        $.post('/api/clientCanvasCustomItem/create', {
+                            proUid: '{{ $pro->uid }}',
+                            key: 'sochx',
+                            label: _label
+                        }, function (_data) {
+                            hideMask();
+                            if (_data && _data.success) {
+                                self.appendCustomItem(_label);
+                                hideMoeFormMask();
+                                $('[custom-item-form]').hide();
+                            } else {
+                                toastr.error(_data.message);
+                            }
+                        }, 'json');
+                        return false;
+                    },
+                    cancelCustomItem: function () {
+                        hideMoeFormMask();
+                        $('div[moe]').hide();
+                        return false;
+                    },
+                    appendCustomItem: function (_name) {
+                        this.customFields.push({
+                            label: _name,
+                            value: '',
+                            comments: '',
+                        });
+                        Vue.nextTick(function () {
+                            $('.custom-items-container [moe][initialized]').removeAttr('initialized');
+                            initMoes();
+                        });
+                    }
+                }
+            });
+        }
+
+        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
+        };
+
+        // addMCInitializer('client-sochx', init, '#sochxSection');
+    })();
+</script>

+ 95 - 0
resources/views/app/patient/segment-templates/history_social/summary.blade.php

@@ -0,0 +1,95 @@
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$point = Point::getGlobalSingletonOfCategory($patient, 'SOCIAL_HISTORY', true);
+
+$contentData = $point->data;
+
+$fields = [
+    [
+        "Tobacco" => ["Current every day smoker", "Current some day smoker", "Former smoker", "Heavy tobacco smoker", "Light tobacco smoker", "Never smoker", "Smoker, current status unknown", "Unknown if ever smoked "],
+    ],
+    [
+        "Alcohol" => ["Do not drink", "Drink daily", "Frequently drink", "Hx of Alcoholism", "Occasional drink"],
+        "Drug Abuse" => ["IVDU", "Illicit drug use", "No illicit drug use"],
+    ],
+    [
+        "Cardiovascular" => ["Eat healthy meals", "Regular exercise", "Take daily aspirin"],
+        "Safety" => ["Household Smoke detector", "Keep Firearms in home", "Wear seatbelts"],
+    ],
+    [
+        "Sexual Activity" => ["Exposure to STI", "Homosexual encounters", "Not sexually active", "Safe sex practices", "Sexually active"],
+        "Birth Gender" => ["Male", "Female", "Undifferentiated"],
+    ]
+];
+
+$isempty = false;
+if(!$contentData) {
+    $contentData = [
+        "common" => [],
+        "customFields" => [],
+        "comments" => "",
+    ];
+    $isempty = true;
+}
+
+if($isempty) {
+    echo '<span class="text-secondary">No social history in the system</span>';
+}
+else {
+
+    for ($i = 0; $i < count($fields); $i++):
+        foreach($fields[$i] as $head => $values):
+            for($k = 0; $k < count($values); $k++):
+                $fName = $head . '_' . sanitize_field_name($values[$k]);
+                if(@$contentData['common'][$fName]): ?>
+                    <div>
+                        <?= ucwords($head) ?>
+                        <i class="fa fa-arrow-right text-sm text-secondary"></i>
+                        <span class="font-weight-bold"><?= $values[$k] ?></span>
+                        <?php if(@$contentData['common'][$fName . '__comments']): ?>
+                            <span class="text-sm ml-1 text-secondary">(<?= $contentData['common'][$fName . '__comments'] ?>)</span>
+                        <?php endif; ?>
+                    </div>
+                <?php
+                endif;
+            endfor;
+        endforeach;
+    endfor;
+
+    // custom fields
+    if(@$contentData['customFields'] && count($contentData['customFields'])):
+        ?> <div class="mt-2"> <?php
+        for ($i = 0; $i < count($contentData['customFields']); $i++):
+            $item = $contentData['customFields'][$i];
+            if($item['value']): ?>
+                <div>
+                    Custom
+                    <i class="fa fa-arrow-right text-sm text-secondary"></i>
+                    <span class="font-weight-bold"><?= $item['label'] ?></span>
+                    <?php if($item['comments']): ?>
+                        <span class="text-sm ml-1 text-secondary">(<?= $item['comments'] ?>)</span>
+                    <?php endif; ?>
+                </div>
+            <?php
+            endif;
+        endfor;
+        ?> </div> <?php
+    endif;
+
+    if(isset($contentData['comments'])) { ?>
+        <div class="mt-2 mb-1">
+            <div class="font-weight-bold">Comments:</div>
+            <div><?= $contentData['comments'] ?></div>
+        </div>
+    <?php }
+}
+?>

+ 1 - 0
resources/views/app/patient/segment-templates/history_surgical/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for history_surgical</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/history_surgical/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for history_surgical</h1>

+ 87 - 0
resources/views/app/patient/segment-templates/intake_allergies/edit.blade.php

@@ -0,0 +1,87 @@
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$allergies = Point::getIntakePointsOfCategory($patient, 'ALLERGY', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Allergy</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($allergies as $allergy): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $allergy->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($allergy->data->name) ? @($allergy->data->name) : '-' ?></b>
+                                <?= !!@($allergy->data->description) ? '/&nbsp;' . @($allergy->data->description) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $allergy;
+                                $label = 'Allergy';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $allergy;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $allergy;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add allergy patient is ALREADY having, prior to this visit</a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="ALLERGY">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Allergy (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </div>
+
+            <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>
+</div>
+

+ 48 - 0
resources/views/app/patient/segment-templates/intake_allergies/summary.blade.php

@@ -0,0 +1,48 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$allergies = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'ALLERGY')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($allergies as $allergy) {
+    if ($allergy->data) {
+        $allergy->data = json_decode($allergy->data);
+    }
+}
+
+?>
+
+<?php if (!count($allergies)): ?>
+    <div class="text-secondary">No allergies</div>
+<?php else: ?>
+    <?php foreach ($allergies as $allergy): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $allergy->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($allergy->data->name) ? @($allergy->data->name) : '-' ?></b>
+                <?= !!@($allergy->data->description) ? '/&nbsp;' . @($allergy->data->description) : '' ?>
+            </div>
+            <?php if ($allergy->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($allergy->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+

+ 1 - 0
resources/views/app/patient/segment-templates/intake_care_team/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for intake_care_team</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/intake_care_team/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for intake_care_team</h1>

+ 87 - 0
resources/views/app/patient/segment-templates/intake_goals/edit.blade.php

@@ -0,0 +1,87 @@
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$goals = Point::getIntakePointsOfCategory($patient, 'GOAL', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Goal</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($goals as $goal): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $goal->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($goal->data->name) ? @($goal->data->name) : '-' ?></b>
+                                <?= !!@($goal->data->description) ? '/&nbsp;' . @($goal->data->description) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $goal;
+                                $label = 'Goal';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $goal;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $goal;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add goal </a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="GOAL">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Goal (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </div>
+
+            <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>
+</div>
+

+ 47 - 0
resources/views/app/patient/segment-templates/intake_goals/summary.blade.php

@@ -0,0 +1,47 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$goals = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'GOAL')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($goals as $goal) {
+    if ($goal->data) {
+        $goal->data = json_decode($goal->data);
+    }
+}
+
+?>
+
+<?php if (!count($goals)): ?>
+    <div class="text-secondary">No goals</div>
+<?php else: ?>
+    <?php foreach ($goals as $goal): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $goal->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($goal->data->name) ? @($goal->data->name) : '-' ?></b>
+                <?= !!@($goal->data->description) ? '/&nbsp;' . @($goal->data->description) : '' ?>
+            </div>
+            <?php if ($goal->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($goal->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>

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

@@ -0,0 +1 @@
+<h1>Edit for intake_interventions</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/intake_interventions/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for intake_interventions</h1>

+ 214 - 0
resources/views/app/patient/segment-templates/intake_medications/edit.blade.php

@@ -0,0 +1,214 @@
+<?php
+
+use App\Models\Point;
+use App\Models\Client;
+use App\Models\Note;
+use App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Medication</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($medications as $medication): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $medication->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                                <?= !!@($medication->data->route) ? '/&nbsp;' . @($medication->data->route) : '' ?>
+                                <?= !!@($medication->data->dose) ? '/&nbsp;' . @($medication->data->dose) : '' ?>
+                                <?= !!@($medication->data->strength) ? '/&nbsp;' . @($medication->data->strength) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $medication;
+                                $label = 'Medication';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $medication;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </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 visit-moe large class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add medication patient is ALREADY taking, prior to this visit</a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="MEDICATION">
+            <input type="hidden" name="data">
+
+            <input type="hidden" data-name="medNameId">
+            <input type="hidden" data-name="route">
+            <input type="hidden" data-name="dose">
+            <input type="hidden" data-name="strength">
+            <input type="hidden" data-name="medId">
+
+            <p class="mb-2"><b>Add Medication (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text"
+                       data-name="name"
+                       class="form-control form-control-sm"
+                       stag-suggest
+                       stag-suggest-ep="/fdb-med-suggest/json">
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Route</label>
+                <select data-name="routedMedId"
+                        class="form-control form-control-sm"
+                        disabled>
+                </select>
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Dosage</label>
+                <select data-name="routedDosageFormMedId"
+                        class="form-control form-control-sm"
+                        disabled>
+                </select>
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Strength</label>
+                <select data-name="gcnSeqno"
+                        class="form-control form-control-sm"
+                        disabled>
+                </select>
+            </div>
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </div>
+
+            <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>
+</div>
+
+
+<script>
+    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
+
+        $('input[stag-suggest][data-name="name"]')
+            .off('stag-suggest-selected')
+            .on('stag-suggest-selected', (_e, _input, _data) => {
+
+                // _input is the textbox
+                // _data is {med_name_id: "50567", text: "Children's Tylenol"}
+
+                let medNameID = _data.med_name_id;
+                $('input[data-name="medNameId"]').val(medNameID);
+
+                let routeSelect = $('[data-name="routedMedId"]').empty().prop('disabled', true);
+                let dosageSelect = $('[data-name="routedDosageFormMedId"]').empty().prop('disabled', true);
+                let strengthSelect = $('[data-name="gcnSeqno"]').empty().prop('disabled', true);
+
+                $.get('/fdb-routed-meds?med-name-id=' + medNameID, _data => {
+                    routeSelect
+                        .empty()
+                        .append('<option value="">-- select --</option>');
+                    for (let i = 0; i < _data.length; i++) {
+                        routeSelect.append('<option value="' + _data[i].routed_med_id + '">' + _data[i].med_routed_med_id_desc + '</option>')
+                    }
+                    routeSelect.prop('disabled', false);
+                    if(_data.length === 1) {
+                        routeSelect.val(_data[0].routed_med_id).trigger('change');
+                    }
+                }, 'json');
+            });
+
+        // on route selection
+        $(document).off('change', '[data-name="routedMedId"]');
+        $(document).on('change', '[data-name="routedMedId"]', function () {
+
+            // clear
+            let dosageSelect = $('[data-name="routedDosageFormMedId"]').empty().prop('disabled', true);
+            let strengthSelect = $('[data-name="gcnSeqno"]').empty().prop('disabled', true);
+            let routedMedID = $(this).val();
+            $('input[data-name="route"]').val($(this).find('option:selected').text());
+
+            $.get('/fdb-routed-dosages?routed-med-id=' + routedMedID, _data => {
+                dosageSelect
+                    .empty()
+                    .append('<option value="">-- select --</option>');
+                for (let i = 0; i < _data.length; i++) {
+                    dosageSelect.append('<option value="' + _data[i].routed_dosage_form_med_id + '">' + _data[i].med_routed_df_med_id_desc + '</option>')
+                }
+                dosageSelect.prop('disabled', false);
+                if(_data.length === 1) {
+                    dosageSelect.val(_data[0].routed_dosage_form_med_id).trigger('change');
+                }
+            }, 'json');
+        });
+
+        // on dosage selection
+        $(document).off('change', '[data-name="routedDosageFormMedId"]');
+        $(document).on('change', '[data-name="routedDosageFormMedId"]', function () {
+
+            // clear
+            let strengthSelect = $('[data-name="gcnSeqno"]').empty().prop('disabled', true);
+            let dosageFormMedID = $(this).val();
+            $('input[data-name="dose"]').val($(this).find('option:selected').text());
+
+            $.get('/fdb-meds?dosage-form-med-id=' + dosageFormMedID, _data => {
+                strengthSelect
+                    .empty()
+                    .append('<option value="">-- select --</option>');
+                for (let i = 0; i < _data.length; i++) {
+                    strengthSelect.append('<option data-medid="' + _data[i].medid + '" value="' + _data[i].gcn_seqno + '">' + _data[i].med_medid_desc + '</option>')
+                }
+                strengthSelect.prop('disabled', false);
+                if(_data.length === 1) {
+                    strengthSelect.val(_data[0].gcn_seqno).trigger('change');
+                    $('input[data-name="description"]').focus();
+                }
+            }, 'json');
+        });
+
+        // on strength (medid) selection
+        $(document).off('change', '[data-name="gcnSeqno"]');
+        $(document).on('change', '[data-name="gcnSeqno"]', function () {
+
+            $('input[data-name="medId"]').val($(this).find('option:selected').attr('data-medid'));
+            $('input[data-name="strength"]').val($(this).find('option:selected').text());
+
+        });
+
+    };
+</script>
+

+ 30 - 0
resources/views/app/patient/segment-templates/intake_medications/summary.blade.php

@@ -0,0 +1,30 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$medications = Point::getIntakePointsOfCategory($patient, 'MEDICATION', $note);
+
+?>
+
+<?php if (!count($medications)): ?>
+    <div class="text-secondary">No medications</div>
+<?php else: ?>
+    <?php foreach ($medications as $medication): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $medication->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($medication->data->name) ? @($medication->data->name) : '-' ?></b>
+                <?= !!@($medication->data->dose) ? '/&nbsp;' . @($medication->data->dose) : '' ?>
+                <?= !!@($medication->data->route) ? '/&nbsp;' . @($medication->data->route) : '' ?>
+                <?= !!@($medication->data->frequency) ? '/&nbsp;' . @($medication->data->frequency) : '' ?>
+            </div>
+            <?php if ($medication->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($medication->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+

+ 95 - 0
resources/views/app/patient/segment-templates/intake_problems/edit.blade.php

@@ -0,0 +1,95 @@
+<?php
+
+use App\Models\Point;
+use \App\Models\Client;
+use \App\Models\Note;
+use \App\Models\Segment;
+
+/** @var Client $patient */
+/** @var Note $note */
+/** @var Segment $segment */
+
+$problems = Point::getIntakePointsOfCategory($patient, 'PROBLEM', $note);
+
+?>
+<div>
+
+    <div class="d-flex mb-2">
+        <table class="table table-sm table-bordered table-striped mb-0 bg-white">
+            <thead>
+            <tr class="">
+                <th class="border-bottom-0">Problem</th>
+                <th class="border-bottom-0">Last Review</th>
+                <th class="border-bottom-0">Review Today</th>
+            </tr>
+            </thead>
+            <?php foreach($problems as $problem): ?>
+                <tr>
+                    <td>
+                        <div class="d-flex align-items-baseline">
+                            <div class="<?= $problem->is_removed ? 'strike-through' : '' ?>">
+                                <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
+                                <?= !!@($problem->data->description) ? '/&nbsp;' . @($problem->data->description) : '' ?>
+                            </div>
+
+                            <!-- common actions -->
+                            <div class="ml-auto d-inline-flex align-items-baseline pr-2">
+                                <?php
+                                $point = $problem;
+                                $label = 'Problem';
+                                include resource_path('views/app/patient/segment-templates/_common_actions/remove-undo.php');
+                                ?>
+                            </div>
+                        </div>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $problem;
+                        include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
+                        ?>
+                    </td>
+                    <td>
+                        <?php
+                        $point = $problem;
+                        include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                        ?>
+                    </td>
+                </tr>
+            <?php endforeach; ?>
+        </table>
+    </div>
+
+    <div visit-moe class="mt-1">
+        <a href="#" start show class="btn btn-sm btn btn-outline-primary">+ Add Problem patient is ALREADY having, prior to this visit</a>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="PROBLEM">
+            <input type="hidden" name="data">
+
+            <p class="mb-2"><b>Add Problem (on intake)</b></p>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Name</label>
+                <input type="text" data-name="name" class="form-control form-control-sm"
+                       stag-suggest
+                       stag-suggest-ep="/fdb-dx-suggest/json">
+            </div>
+
+			<div class="mb-2">
+                <label class="text-sm text-secondary mb-1">ICD</label>
+                <input type="text" data-name="icd" class="form-control form-control-sm">
+            </div>
+
+            <div class="mb-2">
+                <label class="text-sm text-secondary mb-1">Description</label>
+                <input type="text" data-name="description" class="form-control form-control-sm">
+            </div>
+
+            <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>
+</div>
+

+ 49 - 0
resources/views/app/patient/segment-templates/intake_problems/summary.blade.php

@@ -0,0 +1,49 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$problems = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'PROBLEM')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                    ->where('is_removed_due_to_entry_error', false)
+                    ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($problems as $problem) {
+    if ($problem->data) {
+        $problem->data = json_decode($problem->data);
+    }
+}
+
+?>
+
+<?php if (!count($problems)): ?>
+    <div class="text-secondary">No problems</div>
+<?php else: ?>
+    <?php foreach ($problems as $problem): ?>
+        <div class="d-flex align-items-baseline mb-2">
+            <div class="<?= $problem->is_removed ? 'strike-through' : '' ?>">
+                <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
+                <?= !!@($problem->data->icd) ? '/&nbsp;' . @($problem->data->icd) : '' ?>
+                <?= !!@($problem->data->description) ? '/&nbsp;' . @($problem->data->description) : '' ?>
+            </div>
+            <?php if ($problem->is_removed): ?>
+                <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+            <?php elseif ($problem->added_in_note_id === $note->id): ?>
+                <span class="ml-2 text-sm text-success">* Added on intake</span>
+            <?php endif; ?>
+        </div>
+    <?php endforeach; ?>
+<?php endif; ?>
+

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_general/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_general</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_general/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_general</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_nutrition/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_nutrition</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_nutrition/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_nutrition</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_physical_activity/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_physical_activity</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_physical_activity/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_physical_activity</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_sleep/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_sleep</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_sleep/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_sleep</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_social/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_social</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_social/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_social</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_stress/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_stress</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_stress/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_stress</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_substances/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for lifestyle_substances</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/lifestyle_substances/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for lifestyle_substances</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/medrisk_vigilence/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for medrisk_vigilence</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/medrisk_vigilence/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for medrisk_vigilence</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/metrics/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for metrics</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/metrics/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for metrics</h1>

+ 4 - 0
resources/views/app/patient/segment-templates/objective_free_text/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'OBJECTIVE_FREE_TEXT';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/objective_free_text/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'OBJECTIVE_FREE_TEXT';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 0
resources/views/app/patient/segment-templates/objective_imaging/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'IMAGING';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/objective_imaging/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'IMAGING';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 0
resources/views/app/patient/segment-templates/objective_labs/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'LABS';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/objective_labs/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'LABS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 0
resources/views/app/patient/segment-templates/objective_measurements/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'MEASUREMENTS_RELEVANT_TO_NOTE';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/objective_measurements/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'MEASUREMENTS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 4 - 0
resources/views/app/patient/segment-templates/objective_other_investigations/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'OTHER_INVESTIGATIONS';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/objective_other_investigations/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'OTHER_INVESTIGATIONS';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 1 - 0
resources/views/app/patient/segment-templates/past_medical_history/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for past_medical_history</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/past_medical_history/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for past_medical_history</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/plan_allergies/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for plan_allergies</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/plan_allergies/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for plan_allergies</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/plan_care_team/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for plan_care_team</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/plan_care_team/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for plan_care_team</h1>

+ 4 - 0
resources/views/app/patient/segment-templates/plan_free_text/edit.blade.php

@@ -0,0 +1,4 @@
+<?php
+$category = 'PLAN_FREE_TEXT';
+$endPoint = 'upsertNoteSingleton';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/edit.php');

+ 3 - 0
resources/views/app/patient/segment-templates/plan_free_text/summary.blade.php

@@ -0,0 +1,3 @@
+<?php
+$category = 'PLAN_FREE_TEXT';
+include resource_path('views/app/patient/segment-templates/_simple_text_segment/summary.php');

+ 1 - 0
resources/views/app/patient/segment-templates/plan_goals/edit.blade.php

@@ -0,0 +1 @@
+<h1>Edit for plan_goals</h1>

+ 1 - 0
resources/views/app/patient/segment-templates/plan_goals/summary.blade.php

@@ -0,0 +1 @@
+<h1>Summary for plan_goals</h1>

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

@@ -0,0 +1 @@
+<h1>Edit for plan_interventions</h1>

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

@@ -0,0 +1 @@
+<h1>Summary for plan_interventions</h1>

Some files were not shown because too many files changed in this diff