Ver Fonte

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

= há 3 anos atrás
pai
commit
cbc43b5222
35 ficheiros alterados com 4790 adições e 151 exclusões
  1. 45 0
      app/Models/Point.php
  2. 27 0
      config/app.php
  3. 8 4
      public/css/style.css
  4. 0 28
      public/js/icd-autocomplete copy.js
  5. 102 93
      resources/views/app/new-patient.blade.php
  6. 8 8
      resources/views/app/patient/coverage-status.blade.php
  7. 2742 0
      resources/views/app/patient/note/dashboard-bu-b4-pure-soap.blade.php
  8. 16 6
      resources/views/app/patient/note/dashboard.blade.php
  9. 609 0
      resources/views/app/patient/note/dashboard_script-bu-b4-oure-soap.blade.php
  10. 609 0
      resources/views/app/patient/note/dashboard_script-bu-b4-pure-soap.blade.php
  11. 16 8
      resources/views/app/patient/note/dashboard_script.blade.php
  12. 37 0
      resources/views/app/patient/note/note-segment-list-rhs.blade.php
  13. 9 3
      resources/views/app/patient/note/note-segment-list.blade.php
  14. 1 1
      resources/views/app/patient/note/rhs-sidebar.blade.php
  15. 0 0
      resources/views/app/patient/segment-templates/allergies/edit.blade.php
  16. 82 0
      resources/views/app/patient/segment-templates/allergies/summary.blade.php
  17. 4 0
      resources/views/app/patient/segment-templates/assessment_free_text/edit.blade.php
  18. 3 0
      resources/views/app/patient/segment-templates/assessment_free_text/summary.blade.php
  19. 0 0
      resources/views/app/patient/segment-templates/behavior/edit.blade.php
  20. 41 0
      resources/views/app/patient/segment-templates/behavior/summary.blade.php
  21. 0 0
      resources/views/app/patient/segment-templates/care_team/edit.blade.php
  22. 77 0
      resources/views/app/patient/segment-templates/care_team/summary.blade.php
  23. 27 0
      resources/views/app/patient/segment-templates/disclaimers/edit.blade.php
  24. 2 0
      resources/views/app/patient/segment-templates/disclaimers/summary.blade.php
  25. 0 0
      resources/views/app/patient/segment-templates/exercise/edit.blade.php
  26. 43 0
      resources/views/app/patient/segment-templates/exercise/summary.blade.php
  27. 0 0
      resources/views/app/patient/segment-templates/goals/edit.blade.php
  28. 72 0
      resources/views/app/patient/segment-templates/goals/summary.blade.php
  29. 0 0
      resources/views/app/patient/segment-templates/medications/edit.blade.php
  30. 78 0
      resources/views/app/patient/segment-templates/medications/summary.blade.php
  31. 0 0
      resources/views/app/patient/segment-templates/nutrition/edit.blade.php
  32. 52 0
      resources/views/app/patient/segment-templates/nutrition/summary.blade.php
  33. 0 0
      resources/views/app/patient/segment-templates/problems/edit.blade.php
  34. 73 0
      resources/views/app/patient/segment-templates/problems/summary.blade.php
  35. 7 0
      resources/views/app/patient/wizard-partials/common-script.blade.php

+ 45 - 0
app/Models/Point.php

@@ -178,6 +178,51 @@ class Point extends Model
         return $points;
     }
 
+    public static function getUnifiedPointsOfCategory(Client $_patient, String $_category, Note $_note, $_assoc = false) {
+        $points = Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('is_removed_due_to_entry_error', false)
+            ->where(function ($query1) use ($_note) {
+                $query1
+
+                    ->where(function ($query2) use ($_note) { // added on_intake on this note
+                        $query2->where('is_removed', false)
+                            ->where('addition_reason_category', 'ON_INTAKE')
+                            ->where('added_in_note_id', $_note->id);
+                    })
+                    ->orWhere(function ($query2) use ($_note) { // removed on_intake on this note
+                        $query2->where('is_removed', true)
+                            ->where('removal_reason_category', 'ON_INTAKE')
+                            ->where('removed_in_note_id', $_note->id);
+                    })
+                    ->orWhere('last_child_review_point_scoped_note_id', $_note->id) // review added during this note
+
+                    ->orWhere(function ($query2) use ($_note) { // added during_visit on this note
+                        $query2->where('is_removed', false)
+                            ->where('addition_reason_category', 'DURING_VISIT')
+                            ->where('added_in_note_id', $_note->id);
+                    })
+                    ->orWhere(function ($query2) use ($_note) { // removed during_visit on this note
+                        $query2->where('is_removed', true)
+                            ->where('removal_reason_category', 'DURING_VISIT')
+                            ->where('removed_in_note_id', $_note->id);
+                    })
+                    ->orWhere('last_child_plan_point_scoped_note_id', $_note->id) // plan added during this note
+
+                    // marked relevant to this note
+                    ->orWhereRaw("(SELECT count(id) from note_point WHERE is_active IS TRUE AND note_id = {$_note->id} AND point_id = point.id) > 0");
+            })
+            ->orderBy('created_at')
+            ->get();
+        foreach ($points as $point) {
+            if ($point->data) {
+                $point->data = json_decode($point->data, $_assoc);
+            }
+        }
+        return $points;
+    }
+
     public static function getPointsOfCategory(Client $_patient, String $_category, $_assoc = false) {
         $points = Point
             ::where('client_id', $_patient->id)

+ 27 - 0
config/app.php

@@ -251,4 +251,31 @@ return [
 
     ],
 
+    'note_lhs_segments' => [
+        'informed_consent',
+        'vitals',
+        'chief_complaint',
+        'subjective_general',
+        'objective_free_text',
+        'plan_free_text',
+        'assessment_free_text',
+        'disclaimers'
+    ],
+
+    'note_rhs_segments' => [
+        'allergies',
+        'allergies',
+        'medications',
+        'past_medical_history',
+        'problems',
+        'family_history',
+        'social_history',
+        'surgical_history',
+        'nutrition',
+        'exercise',
+        'behavior',
+        'goals',
+        'care_team'
+    ]
+
 ];

+ 8 - 4
public/css/style.css

@@ -2160,6 +2160,10 @@ body.in-iframe .main-row > .sidebar {
     max-height: calc(100vh - 55px);
     background-color: #fff;
 }
+.note-container.note_template_soap_visit .note-lhs-tree {
+    width: 0 !important;
+    opacity: 0 !important;
+}
 .note-container .note-lhs-tree:hover {
     overflow: overlay;
 }
@@ -2249,7 +2253,7 @@ body.in-iframe .main-row > .sidebar {
     padding-left: 4rem;
 }
 
-.note-container .note-rhs-sidebar {
+.note-container:not(.note_template_soap_visit) .note-rhs-sidebar {
     min-width: 180px;
     max-width: 180px;
     align-self: stretch;
@@ -2259,10 +2263,10 @@ body.in-iframe .main-row > .sidebar {
     max-height: calc(100vh - 55px);
     background-color: #fff;
 }
-.note-container .note-rhs-sidebar:hover {
+.note-container:not(.note_template_soap_visit) .note-rhs-sidebar:hover {
     overflow: overlay;
 }
-.note-container .note-rhs-sidebar.fixed {
+.note-container:not(.note_template_soap_visit) .note-rhs-sidebar.fixed {
     position: fixed;
     top: 55px;
     right: 0;
@@ -2270,7 +2274,7 @@ body.in-iframe .main-row > .sidebar {
     height: calc(100vh - 55px) !important;
     z-index: 1;
 }
-.note-container .note-rhs-sidebar.fixed ~ .note-rhs-content {
+.note-container:not(.note_template_soap_visit) .note-rhs-sidebar.fixed ~ .note-rhs-content {
     margin-right: 180px;
 }
 .spot-highlight {

+ 0 - 28
public/js/icd-autocomplete copy.js

@@ -1,28 +0,0 @@
-(function() {
-
-    function init() {
-        let self = this;
-        $('[icd-autocomplete-code]:not([ac-initialized])').each(function() {
-            let elem = this, dynID = 'icd-' + Math.ceil(Math.random() * 1000000),
-                codeElem = $(this), descElem = $(this).closest('form').find('[icd-autocomplete-description]');
-            $(elem).attr('id', dynID);
-            new window.Def.Autocompleter.Search(dynID,
-                'https://clinicaltables.nlm.nih.gov/api/icd10cm/v3/search?sf=code,name&ef=name', {
-                    tableFormat: true,
-                    valueCols: [0],
-                    colHeaders: ['Code', 'Name'],
-                }
-            );
-            window.Def.Autocompleter.Event.observeListSelections(dynID, function() {
-                let autocomp = elem.autocomp, acData = autocomp.getSelectedItemData();
-                codeElem.val(acData[0].code).trigger('change');
-                descElem.val(acData[0].data['name']).trigger('change');
-                return false;
-            });
-            $(elem).attr('ac-initialized', 1);
-        });
-    }
-
-    addMCInitializer('icd-autocomplete', init);
-
-}).call(window);

+ 102 - 93
resources/views/app/new-patient.blade.php

@@ -6,6 +6,11 @@
 $patients = [1, 2, 3, 4];
 $medicaidStates = Config::get('constants.medicaid_states');
 ?>
+<style media="screen">
+	.form-control {
+		border-radius: 0;
+	}
+</style>
 
 <div class="p-3 mcp-theme-1" id="newPatientContainer" v-cloak>
 	<div class="col-12">
@@ -23,63 +28,71 @@ $medicaidStates = Config::get('constants.medicaid_states');
 					<div class="alert alert-danger">{{ session('message') }}</div>
 					@endif
 					<div class="row">
-						<div class="border-lighter col-md-5">
+						<div class="border-lighter col-md-6">
 							<div class="row">
 								<div class="col-md-12 bg-light p-3 mb-2">
 									<h5 class="m-0 font-weight-bold">Patient Name / Demographics:</h5>
 								</div>
-								<div class="form-group col-md-4">
-									<label class="control-label">First Name <span class="text-danger">*</span> </label>
-									<input autocomplete="_blank" type="text" required name="patientNameFirst" value="" class="form-control input-sm">
-								</div>
-								<div class="form-group col-md-4">
-									<label class="control-label">Middle Name / MI</label>
-									<input autocomplete="_blank" type="text" name="patientNameMiddle" value="" class="form-control input-sm">
-								</div>
-								<div class="form-group col-md-4">
-									<label class="control-label">Last Name <span class="text-danger">*</span></label>
-									<input autocomplete="_blank" type="text" required name="patientNameLast" value="" class="form-control input-sm">
-								</div>
-								<div class="form-group col-md-4">
-									<label class="control-label">Prefix</label>
-									<input autocomplete="_blank" type="text" name="patientNamePrefix" value="" class="form-control input-sm">
+								<div class="col-md-12 form-group mt-2">
+									<div class="d-flex align-items-center">
+										<label class="m-0 w-25">Name:</label>
+										<input autocomplete="_blank" type="text" name="patientNamePrefix" placeholder="Prefix" class="ml-2 form-control input-sm w-50">
+										<input autocomplete="_blank" type="text" required name="patientNameFirst" placeholder="First" class="ml-2 form-control input-sm">
+										<input autocomplete="_blank" type="text" name="patientNameMiddle" placeholder="Middle" class="ml-2 form-control input-sm">
+										<input autocomplete="_blank" type="text" name="patientNameLast" placeholder="Last" class="ml-2 form-control input-sm">
+										<input autocomplete="_blank" type="text" name="patientNameSuffix" placeholder="Suffix" class="ml-2 form-control input-sm w-50">
+									</div>
 								</div>
-								<div class="form-group col-md-4">
-									<label class="control-label">Suffix</label>
-									<input autocomplete="_blank" type="text" name="patientNameSuffix" value="" class="form-control input-sm">
+								<div class="col-md-12 p-0">
+									<div class="col-md-6 form-group">
+										<div class="d-flex align-items-center">
+											<label class="m-0">Email:</label>
+											<input class='form-control ml-2' type='email' placeholder="Email Address" name='emailAddress'>
+										</div>
+									</div>
 								</div>
-								<div class="form-group col-md-4">
-									<label class="control-label">Sex</label>
-									<select class="form-control input-sm" name="patientSex" select2>
-										<option value="">--</option>
-										<option value="M">Male</option>
-										<option value="F">Female</option>
-										<option value="UNKNOWN">Unknown</option>
-									</select>
+								<div class="col-md-12 p-0">
+									<div class="col-md-4 form-group">
+										<div class="d-flex align-items-center">
+											<label class="m-0 w-25">Gender:</label>
+											<select class="form-control input-sm ml-2" name="patientSex" select2>
+												<option value="">--</option>
+												<option value="M">Male</option>
+												<option value="F">Female</option>
+												<option value="UNKNOWN">Unknown</option>
+											</select>
+										</div>
+									</div>
 								</div>
-								<div class="form-group col-md-6">
-									<label class="control-label">Date of Birth <span class="text-danger">*</span></label>
-									<input type="date" required name="patientDob" value="" class="form-control input-sm">
+							</div>
+							<div class="row">
+								<div class="col-md-5 form-group">
+									<div class="d-flex align-items-center">
+										<label class="m-0 w-25">DOB: <span class="text-danger">*</span></label>
+										<input type="date" required name="patientDob" value="" class="form-control input-sm">
+									</div>
 								</div>
-								<div class="form-group col-md-6">
-									<label class="control-label">Date Of Service</label>
-									<input type="date" name="dateOfService" value="{{date('Y-m-d')}}" class="form-control input-sm">
+								<div class="col-md-5 form-group">
+									<div class="d-flex align-items-center">
+										<label class="m-0 w-25">Service:</label>
+										<input type="date" name="dateOfService" value="{{date('Y-m-d')}}" class="form-control input-sm">
+									</div>
 								</div>
 							</div>
 							@if($pro->pro_type === 'ADMIN')
 							<div class="row">
-								<div class="col-md-6">
-									<div class='form-group mb-3'>
-										<label class='control-label'>HCP Pro</label>
-										<select name="hcpProUid" class="form-control" provider-search provider-type="hcp">
+								<div class="col-md-5 form-group">
+									<div class="d-flex align-items-center">
+										<label class="m-0 w-25">HCP Pro:</label>
+										<select name="hcpProUid" class="form-control input-sm" provider-search provider-type="hcp">
 											<option value="">--select--</option>
 										</select>
 									</div>
 								</div>
-								<div class="col-md-6">
-									<div class='form-group mb-3'>
-										<label class='control-label'>Care Coordinator</label>
-										<select name="assistantProUid" class="form-control" provider-search provider-type="default-na">
+								<div class="col-md-7 form-group">
+									<div class="d-flex align-items-center">
+										<label class='m-0 w-25'>Coordinator:</label>
+										<select name="assistantProUid" class="form-control input-sm ml-2" provider-search provider-type="default-na">
 											<option value="">--select--</option>
 										</select>
 									</div>
@@ -88,18 +101,20 @@ $medicaidStates = Config::get('constants.medicaid_states');
 							@elseif($pro->is_hcp === true)
 							<div class="row">
 								<div class="col-md-12">
-									<div class='form-group mb-3'>
-										<label class='control-label'>HCP Pro</label>
-										<input type="text" class="form-control" readonly value="{{$pro->displayName()}}">
-										<input type="hidden" name="hcpProUid" value="{{$pro->uid}}">
+									<div class='form-group'>
+										<div class="d-flex align-items-center">
+											<label class="m-0 w-25">HCP Pro:</label>
+											<input type="text" class="form-control" readonly value="{{$pro->displayName()}}">
+											<input type="hidden" name="hcpProUid" value="{{$pro->uid}}">
+										</div>
 									</div>
 								</div>
 							</div>
 							@elseif($pro->isDefaultNA())
 							<div class="row">
-								<div class="col-md-6">
-									<div class='form-group mb-3'>
-										<label class='control-label'>HCP Pro</label>
+								<div class="col-md-5 form-group">
+									<div class="d-flex align-items-center">
+										<label class="m-0 w-25">HCP Pro:</label>
 										<?php $teams = $pro->teamsWhereAssistant; ?>
 										<select name="hcpProUid" class="form-control">
 											@if(count($teams) > 1)
@@ -110,23 +125,21 @@ $medicaidStates = Config::get('constants.medicaid_states');
 											@endforeach
 										</select>
 									</div>
-
 								</div>
-								<div class="col-md-6">
-									<div class='form-group mb-3'>
-										<label class='control-label'>Care Coordinator</label>
+								<div class="col-md-7 form-group">
+									<div class="d-flex align-items-center">
+										<label class='m-0 w-25'>Coordinator:</label>
 										<input type="text" class="form-control" readonly value="{{$pro->displayName()}}">
 										<input type="hidden" name="assistantProUid" value="{{$pro->uid}}">
 									</div>
 								</div>
 							</div>
 							@endif
-
 							<div class="row">
-								<div class="col-md-4">
-									<div class='form-group mb-3'>
-										<label class='control-label d-flex align-items-center'>
-											<span>Home Phone Number</span>
+								<div class="col-md-6 form-group">
+									<div class="d-flex align-items-center">
+										<label class='control-label m-0 d-flex align-items-center'>
+											<span>Phone:</span>
 											<a v-if="form.homeNumber" @click="hpnToCpn" class="ml-1 px-1 on-hover-opaque hpn-to-cpn c-pointer">
 												<i class="fa fa-arrow-right"></i>
 											</a>
@@ -134,24 +147,20 @@ $medicaidStates = Config::get('constants.medicaid_states');
 												<i class="fa fa-retweet"></i>
 											</a>
 										</label>
-										<input class='form-control' autocomplete="_blank" stag-input-phone type='tel' name='homeNumber' v-model="form.homeNumber">
+										<input class='form-control ml-2' placeholder="Home Phone" autocomplete="_blank" stag-input-phone type='tel' name='homeNumber' v-model="form.homeNumber">
+										</select>
 									</div>
 								</div>
-								<div class="col-md-4">
-									<div class='form-group mb-3'>
-										<label class='control-label d-flex align-items-center'>
-											<span>Cell Phone Number</span>
+								<div class="col-md-6 form-group">
+									<div class="d-flex align-items-center">
+										<label class='control-label m-0 d-flex align-items-center'>
+											<span>Phone:</span>
 											<a v-if="form.cellNumber" @click="cpnToHpn" class="ml-1 px-1 on-hover-opaque cpn-to-hpn c-pointer">
 												<i class="fa fa-arrow-left"></i>
 											</a>
 										</label>
-										<input class='form-control' autocomplete="_blank" stag-input-phone type='tel' name='cellNumber' v-model="form.cellNumber">
-									</div>
-								</div>
-								<div class="col-md-4">
-									<div class='form-group mb-3'>
-										<label class='control-label'>Email Address </label>
-										<input class='form-control' type='email' name='emailAddress'>
+										<input class='form-control ml-2' placeholder="Cell Phone" autocomplete="_blank" stag-input-phone type='tel' name='cellNumber' v-model="form.cellNumber">
+										</select>
 									</div>
 								</div>
 							</div>
@@ -170,7 +179,7 @@ $medicaidStates = Config::get('constants.medicaid_states');
 							</div>
 
 						</div>
-						<div class="col-md-7">
+						<div class="col-md-6">
 							<div class="border-lighter">
 								<div class="col-md-12 bg-light py-3 px-3 mb-2 ">
 									<h5 class="m-0 font-weight-bold">Insurance Coverage:</h5>
@@ -271,23 +280,25 @@ $medicaidStates = Config::get('constants.medicaid_states');
 													<h5 class="m-0 font-weight-bold">Medicaid Information:</h5>
 												</div>
 											</div>
-											<div class="col-12 px-0">
-												<div class="px-2">
-													<div class="form-group col-md-6">
-														<label for="" class="control-label">Medicaid State</label>
-														<input class="form-control input-sm" list="mcdPayerOptions" name="mcdPayerName" id="mcdPayerName">
-														<datalist id="mcdPayerOptions">
-															<option value="">--</option>
-															@foreach($medicaidStates as $state)
-															<option>{{ $state }}</option>
-															@endforeach
-														</datalist>
-													</div>
+											<div class="col-12">
+												<div class="row">
 
-													<div class="form-group col-md-6">
-														<label class="control-label">Medicaid Number</label>
-														<input type="text" name="mcdNumber" class="form-control input-sm" oninput="this.value = this.value.toUpperCase()">
-													</div>
+												
+												<div class="form-group col-md-6">
+													<label for="" class="control-label">Medicaid State</label>
+													<input class="form-control input-sm" list="mcdPayerOptions" name="mcdPayerName" id="mcdPayerName">
+													<datalist id="mcdPayerOptions">
+														<option value="">--</option>
+														@foreach($medicaidStates as $state)
+														<option>{{ $state }}</option>
+														@endforeach
+													</datalist>
+												</div>
+
+												<div class="form-group col-md-6">
+													<label class="control-label">Medicaid Number</label>
+													<input type="text" name="mcdNumber" class="form-control input-sm" oninput="this.value = this.value.toUpperCase()">
+												</div>
 												</div>
 											</div>
 										</div>
@@ -298,12 +309,10 @@ $medicaidStates = Config::get('constants.medicaid_states');
 													<h5 class="m-0 font-weight-bold">Medicare Information:</h5>
 												</div>
 											</div>
-											<div class="col-12 px-0">
-												<div class="px-2">
-													<div class="form-group col-md-6">
-														<label class="control-label">Medicare Number</label>
-														<input type="text" name="mcrNumber" class="form-control input-sm" oninput="this.value = this.value.toUpperCase()">
-													</div>
+											<div class="col-12">
+												<div class="form-group col-md-6">
+													<label class="control-label">Medicare Number</label>
+													<input type="text" name="mcrNumber" class="form-control input-sm" oninput="this.value = this.value.toUpperCase()">
 												</div>
 											</div>
 
@@ -395,4 +404,4 @@ $medicaidStates = Config::get('constants.medicaid_states');
 	});
 </script>
 
-@endsection
+@endsection

+ 8 - 8
resources/views/app/patient/coverage-status.blade.php

@@ -72,9 +72,9 @@
             @endif
 
             @if($coverage->manual_medicare_is_partbprimary == 'YES')
-              <span><i class="fas fa-check-circle text-success"></i> <b>Part B Primary:</b> YES ({{$coverage->manual_determination_strategy}})</span> <br>
+              <span><i class="fas fa-check-circle text-success"></i> <b>Part B Primary:</b> YES ({{strtolower(implode(' ', explode('_', strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy))))))}})</span> <br>
             @elseif($coverage->manual_medicare_is_matched == 'NO')
-              <span><i class="fas fa-times text-danger"></i> record not found ({{$coverage->manual_determination_strategy}})</span> <br>
+              <span><i class="fas fa-times text-danger"></i> record not found ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span> <br>
             @else
               <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
               <span><i class="fas fa-times text-danger"></i> <b>Part B Primary:</b> {{$coverage->manual_medicare_is_partbprimary}}</span> <br>
@@ -135,11 +135,11 @@
               <span><i class="fas fa-check-circle text-success"></i></span>
               @elseif($coverage->manual_determination_category == 'NOT_COVERED')
               <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
-              <span><i class="fas fa-times text-danger"></i> not covered ({{$coverage->manual_determination_strategy}})</span>
+              <span><i class="fas fa-times text-danger"></i> not covered ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
               @elseif($coverage->manual_determination_category == 'INVALID')
-              <span><i class="fas fa-times text-danger"></i> record not found ({{$coverage->manual_determination_strategy}})</span>
+              <span><i class="fas fa-times text-danger"></i> record not found ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
               @else
-              <span><i class="fas fa-hourglass-half text-warning"></i> pending ({{$coverage->manual_determination_strategy}})</span>
+              <span><i class="fas fa-hourglass-half text-warning"></i> pending ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
               @endif
             </td>
           </tr>
@@ -183,11 +183,11 @@
               <span><i class="fas fa-check-circle text-success"></i></span>
               @elseif($coverage->manual_determination_category == 'NOT_COVERED')
               <span><i class="fas fa-check-circle text-success"></i> record found</span> <br>
-              <span><i class="fas fa-times text-danger"></i> not covered ({{$coverage->manual_determination_strategy}})</span>
+              <span><i class="fas fa-times text-danger"></i> not covered ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
               @elseif($coverage->manual_determination_category == 'INVALID')
-              <span><i class="fas fa-times text-danger"></i> record not found ({{$coverage->manual_determination_strategy}})</span>
+              <span><i class="fas fa-times text-danger"></i> record not found ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
               @else
-              <span><i class="fas fa-hourglass-half text-warning"></i> pending ({{$coverage->manual_determination_strategy}})</span>
+              <span><i class="fas fa-hourglass-half text-warning"></i> pending ({{strtolower(implode(' ', explode('_', $coverage->manual_determination_strategy)))}})</span>
               @endif
             </td>
           </tr>

+ 2742 - 0
resources/views/app/patient/note/dashboard-bu-b4-pure-soap.blade.php

@@ -0,0 +1,2742 @@
+<?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;
+            }
+        }
+    }
+
+    // is based on visit template
+    $isVisitTemplateBased = !!$note->visitTemplate;
+
+    $uiConfigsPath = $isVisitTemplateBased ? storage_path("visit-template-ui-configs/{$note->visitTemplate->internal_name}.json") : null;
+    $doesVisitTemplateUiConfigExist = $uiConfigsPath && file_exists($uiConfigsPath);
+    $visitTemplateUiConfig = $doesVisitTemplateUiConfigExist ? json_decode(file_get_contents($uiConfigsPath), true) : null;
+
+    $visitLayoutPath = '';
+    $doesVisitTemplateLayoutExist = false;
+
+    if($isVisitTemplateBased) {
+        $visitLayoutPath = "app.patient.note.visit-template-ui-layouts.{$note->visitTemplate->internal_name}";
+        $doesVisitTemplateLayoutExist = $isVisitTemplateBased && \Illuminate\Support\Facades\View::exists($visitLayoutPath);
+    }
+
+    $segmentMap = [];
+    foreach($note->segments as $segment):
+        $segmentMap[$segment->segmentTemplate->internal_name] = $segment;
+    endforeach;
+
+    ?>
+    <div id="note-single-header" class="pb-3 d-flex align-items-start screen-only zero-height">
+        <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
+                    <span class="text-secondary font-weight-normal">{{ $note->is_cancelled ? '(CANCELLED)' : '' }}</span>
+                </span>
+                @if($pro->pro_type === 'ADMIN')
+                    @if(!!$note->visitTemplate)
+                        <a native target="_blank"
+                           href="{{route('note-pdf', ['note' => $note])}}"
+                           class="ml-3 btn btn-sm btn-primary text-white font-weight-bold"><i class="fa fa-print"></i> Print</a>
+                    @else
+                        <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>
+                    @endif
+                    <?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-primary 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-primary 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-primary 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-primary 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-primary mr-1">Yes</button>
+                                <button cancel class="btn btn-sm btn-default border">No</button>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+            @endif
+        </h6>
+    </div>
+
+    <span class="card mb-0 {{ $note->is_cancelled ? 'cancelled-item' : '' }} border-0 rounded-0">
+        <div class="card-header d-flex align-items-start px-3 py-2 border-bottom rounded-0" 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><span class="text-secondary">HCP:</span> {{$note->hcpPro->name_display}}</span>
+                    @if($pro->pro_type === 'ADMIN')
+                    <div moe class="ml-2">
+                        <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-primary 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 name="naProUid" class="form-control" provider-search>
+                                        <option value="">--select--</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>
+                        </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 ? noteMethodDisplay($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 )
+                            <div class="d-flex align-items-baseline">
+                                <div class="text-secondary">
+                                    <i class="fa fa-check"></i>
+                                    Note Signed
+                                </div>
+                                @if($pro->pro_type === 'ADMIN' || ($note->hcpPro && $pro->id === $note->hcpPro->id))
+                                    <div class="ml-3">
+                                        @include('app/patient/note/_create-bill-only')
+                                    </div>
+                                @endif
+                            </div>
+                        @endif
+                        @if(!$note->is_signed_by_hcp )
+                            @if($note->hcp_pro_id !== $pro->id)
+                                <span class="text-sm text-secondary">Only the note's HCP can sign</span>
+                            @else
+                                @if(!$isVisitTemplateBased)
+                                    <div moe relative
+                                         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>
+                                @else
+                                    <a native target="_blank"
+                                       open-in-stag-popup
+                                       update-parent
+                                       mc-initer="note-sign-confirmation-{{$note->id}}"
+                                       popup-style="stag-popup-md"
+                                       title="Confirm and Sign"
+                                       href="{{route('patients.view.notes.view.sign-confirmation', compact('patient', 'note'))}}">
+                                        Sign Note As HCP
+                                    </a>
+                                @endif
+                            @endif
+                        @endif
+                    </div>
+                </div>
+                @if($note->allyPro && $pro->id === $note->allyPro->id)
+                <div class="mx-3">
+                    <div>
+                        @if($note->is_signed_by_ally)
+                            <span class="text-secondary">
+                                <i class="fa fa-check"></i>
+                                Note Signed By NA
+                                @if(!$note->is_signed_by_hcp)
+                                <span moe class="ml-2">
+                                    <a class="" href="" show start>Undo sign?</a>
+                                    <form url="/api/note/undoSignAsAlly" right>
+                                        <input type="hidden" name="uid" value="{{$note->uid}}">
+                                        <p>Undo sign?</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>
+                        @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">
+                @if($isVisitTemplateBased && !$doesVisitTemplateUiConfigExist)
+                    @include('app.patient.note.lhs-tree')
+                @endif
+                <div class="note-rhs-content">
+                <div>
+                <div class="border-bottom pb-3">
+                    <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>
+                        <script>
+                            window.hpiShortcuts = [
+                                {
+                                    name: 'Explain the problem.',
+                                    value: 'Explain the problem. ',
+                                },
+                                {
+                                    name: 'What happened between today and our last visit?',
+                                    value: 'What happened between today and our last visit? ',
+                                },
+                                {
+                                    name: 'How did it go with the plan I gave you?',
+                                    value: 'How did it go with the plan I gave you? ',
+                                },
+                                {
+                                    name: 'What barriers have you felt following the plan?',
+                                    value: 'What barriers have you felt following the plan? ',
+                                },
+                                {
+                                    name: 'How long have you had this?',
+                                    value: 'How long have you had this? ',
+                                },
+                                {
+                                    name: 'When does it get worse?',
+                                    value: 'When does it get worse? ',
+                                },
+                                {
+                                    name: 'When does it get better?',
+                                    value: 'When does it get better? ',
+                                },
+                                {
+                                    name: 'What have you done for treatment?',
+                                    value: 'What have you done for treatment? ',
+                                },
+                                {
+                                    name: 'How does it affect your ADLs?',
+                                    value: 'How does it affect your ADLs? ',
+                                },
+                                {
+                                    name: 'How do you cope?',
+                                    value: 'How do you cope? ',
+                                },
+                                {
+                                    name: 'How does this affect you emotionally?',
+                                    value: 'How does this affect you emotionally? ',
+                                },
+                            ];
+                        </script>
+                        <script>window.segmentInitializers = {};</script>
+                        <?php
+                        $shortcuts = "";
+                        $latestSectionTS = 0;
+                        ?>
+                        <div class="{{ $note->is_signed_by_hcp ? 'note-signed-by-hcp' : '' }}">
+                            @if($isVisitTemplateBased && $doesVisitTemplateLayoutExist)
+                                @include($visitLayoutPath)
+                            @elseif($isVisitTemplateBased && !$doesVisitTemplateUiConfigExist)
+                                @include('app.patient.note.note-segment-list')
+                            @elseif($isVisitTemplateBased && $doesVisitTemplateUiConfigExist)
+                                @include('app.patient.note.custom-visit')
+                            @else
+                                @include('app.patient.note.note-section-list')
+                            @endif
+                        </div>
+                    </div>
+                </div>
+
+                <span class="d-none latest-section-ts">{{ $latestSectionTS }}</span>
+
+                <!-- handouts -->
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="Handouts">
+                    <?php $handouts = \App\Models\Handout::where('is_active', true)->get(); ?>
+                    @include('app.patient.handouts-list', compact('patient', 'handouts'))
+                </div>
+
+                @if($isVisitTemplateBased && $doesVisitTemplateUiConfigExist)
+
+                @else
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="Prescriptions">
+                    @include('app.patient.prescriptions.list', compact('patient', 'note'))
+                </div>
+                @endif
+
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="CM Setup">
+                    <div class="d-flex align-items-center mb-3">
+                        <p class="font-weight-bold text-secondary m-0 font-size-14">Chronic Care Management (CCM)</p>
+                    </div>
+
+                    <div class="mb-3 d-flex align-items-baseline">
+                        <span class="min-width-140px">CCM Enrollment:</span>
+                        <div class="d-inline-flex align-items-center flex-grow-1">
+                            @if($patient->is_enrolled_in_cm === 'YES')
+                                <span class="text-nowrap text-success">
+                                    <i class="fa fa-check"></i>
+                                    <b>Enrolled</b>
+                                </span>
+                                <div moe class="ml-3">
+                                    <a href="" show start>Undo</a>
+                                    <form url="/api/client/setIsEnrolledInCmToFalse" target='[data-non-segment-section="CM Setup"]'>
+                                        <input type="hidden" name="uid" value="{{$patient->uid}}">
+                                        <p>Un-enroll from CCM?</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>
+                                </div>
+                            @else
+                                <span class="text-nowrap text-warning-mellow">
+                                    <i class="fa fa-times"></i>
+                                    <b>Not Enrolled</b>
+                                </span>
+                                @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
+                                    <a native target="_blank"
+                                       class="screen-only ml-3"
+                                       open-in-stag-popup
+                                       popup-style="medium overflow-visible"
+                                       mc-initer="ccm-agreement-{{$note->id}}"
+                                       title="Consent To Chronic Care Management Services"
+                                       href="/note/ccm-agreement/{{$note->uid}}?popupmode=1">
+                                        Mark as enrolled
+                                    </a>
+                                @endif
+                            @endif
+                        </div>
+                    </div>
+
+                    <div class="mb-3 d-flex align-items-baseline">
+                        <span class="min-width-140px">CCM Setup:</span>
+                        <div class="d-inline-flex align-items-center flex-grow-1">
+                            @if($patient->has_cm_setup_been_performed)
+                                <span class="text-nowrap text-success">
+                                    <i class="fa fa-check"></i>
+                                    <b>Performed</b>
+                                </span>
+                                @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
+                                    <div moe class="ml-3">
+                                        <a href="" show start>Undo</a>
+                                        <form url="/api/note/undoMarkCmSetupPerformed" target='[data-non-segment-section="CM Setup"]'>
+                                            <input type="hidden" name="uid" value="{{$note->uid}}">
+                                            <p>Mark CCM Setup as not performed?</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>
+                                    </div>
+                                @endif
+                            @else
+                                <span class="text-nowrap text-warning-mellow">
+                                    <i class="fa fa-times"></i>
+                                    <b>Not Performed</b>
+                                </span>
+                                @if($patient->mcp_pro_id === $pro->id || $pro->pro_type === 'ADMIN')
+                                    <div moe class="ml-3">
+                                        <a href="#" show start>Mark Performed</a>
+                                        <form url="/api/note/markCmSetupPerformed" target='[data-non-segment-section="CM Setup"]'>
+                                            <input type="hidden" name="uid" value="{{$note->uid}}">
+                                            <p>Mark CCM Setup as performed?</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>
+                                    </div>
+                                @endif
+                            @endif
+                        </div>
+                    </div>
+
+                    <div class="d-flex align-items-baseline mb-3">
+                        <span class="min-width-140px">CCM Reasons:</span>
+                        <div class="min-width-300px">
+                            @if(!$patient->cmReasons || !count($patient->cmReasons))
+                                <span class="text-secondary">None</span>
+                            @else
+                                <div>
+                                @foreach($patient->cmReasons as $reason)
+                                    <div class="border-bottom pb-1 mb-1 d-flex align-items-start">
+                                        <b class="min-width-70px">{{$reason->code}}</b>
+                                        <span class="max-width-200px mr-3">{{$reason->description}}</span>
+                                        <div moe relative class="ml-auto">
+                                            <a start show><i class="fa fa-pencil-alt"></i></a>
+                                            <form url="/api/clientCmRmReason/updateBasic" class="mcp-theme-1" right target='[data-non-segment-section="CM Setup"]'>
+                                                <input type="hidden" name="uid" value="{{$reason->uid}}">
+                                                <div class="mb-2">
+                                                    <label class="text-sm mb-1 text-secondary">Code *</label>
+                                                    <input type="text" class="form-control form-control-sm"
+                                                           icd-autocomplete-code
+                                                           name="code" value="{{$reason->code}}" required>
+                                                </div>
+                                                <div class="mb-2">
+                                                    <label class="text-sm mb-1 text-secondary">Description</label>
+                                                    <input type="text" class="form-control form-control-sm"
+                                                           icd-autocomplete-description
+                                                           name="description" value="{{$reason->description}}">
+                                                </div>
+                                                <div>
+                                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                                </div>
+                                            </form>
+                                        </div>
+                                        <div moe relative class="ml-2">
+                                            <a start show><i class="fa fa-trash-alt text-danger on-hover-opaque"></i></a>
+                                            <form url="/api/clientCmRmReason/remove" class="mcp-theme-1" right target='[data-non-segment-section="CM Setup"]'>
+                                                <input type="hidden" name="uid" value="{{$reason->uid}}">
+                                                <p>Remove this CM reason?</p>
+                                                <div>
+                                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                                </div>
+                                            </form>
+                                        </div>
+                                    </div>
+                                @endforeach
+                                </div>
+                            @endif
+                            @if(!$patient->cmReasons || count($patient->cmReasons) < 2)
+                                <div class="d-flex align-items-baseline">
+                                    <div moe>
+                                        <a start show>+ Add From Dx</a>
+                                        <form url="/api/clientCmRmReason/create" class="mcp-theme-1" target='[data-non-segment-section="CM Setup"]'>
+                                            <input type="hidden" name="clientUid" value="{{$patient->uid}}">
+                                            <input type="hidden" name="cmOrRm" value="CM">
+                                            <input type="hidden" name="code" value="">
+                                            <input type="hidden" name="description" value="">
+                                            <div class="mb-2">
+                                                <label class="text-sm mb-1 text-secondary">Reason *</label>
+                                                <select type="text" class="form-control form-control-sm problem-select" name="problem" required>
+                                                    <?php $problems = \App\Models\Point::getPointsOfCategory($patient, "PROBLEM"); ?>
+                                                    <option value="">-- select --</option>
+                                                    @foreach($problems as $problem)
+                                                        @if(!!@($problem->data->icd))
+                                                            <option value="{{$problem->uid}}" data-icd="{{$problem->data->icd}}" data-name="{{$problem->data->name}}">{{$problem->data->icd}} - {{$problem->data->name}}</option>
+                                                        @endif
+                                                    @endforeach
+                                                </select>
+                                            </div>
+                                            <div>
+                                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                    <span class="mx-2 text-secondary text-sm">|</span>
+                                    <div moe>
+                                        <a start show>+ Add</a>
+                                        <form url="/api/clientCmRmReason/create" class="mcp-theme-1" target='[data-non-segment-section="CM Setup"]'>
+                                            <input type="hidden" name="clientUid" value="{{$patient->uid}}">
+                                            <input type="hidden" name="cmOrRm" value="CM">
+                                            <div class="mb-2">
+                                                <label class="text-sm mb-1 text-secondary">Code *</label>
+                                                <input type="text" class="form-control form-control-sm"
+                                                       icd-autocomplete-code
+                                                       name="code" value="" required>
+                                            </div>
+                                            <div class="mb-2">
+                                                <label class="text-sm mb-1 text-secondary">Description</label>
+                                                <input type="text" class="form-control form-control-sm"
+                                                       icd-autocomplete-description
+                                                       name="description" value="">
+                                            </div>
+                                            <div>
+                                                <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
+                                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                </div>
+                            @endif
+                        </div>
+                    </div>
+
+                    @if($pro->pro_type === 'ADMIN' && $note->was_cm_setup_performed)
+                    <div class="d-flex align-items-baseline">
+                        <span class="min-width-140px">Manager Signature:</span>
+                        <div class="d-inline-flex align-items-center flex-grow-1">
+                            @if($note->cm_setup_manager_signature_status !== 'SIGNED')
+                                <div moe class="">
+                                    <a start show>Sign</a>
+                                    <form url="/api/note/updateCmSetupManagerSignatureStatus" class="mcp-theme-1">
+                                        <input type="hidden" name="uid" value="{{$note->uid}}">
+                                        <input type="hidden" name="managerSignatureStatus" value="SIGNED">
+                                        <p>Sign CM Setup Performed as Manager?</p>
+                                        <div>
+                                            <button submit class="btn btn-sm btn-success mr-1">Sign</button>
+                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @else
+                                <b>SIGNED</b>
+                                <div moe class="ml-3">
+                                    <a start show>Undo</a>
+                                    <form url="/api/note/updateCmSetupManagerSignatureStatus" class="mcp-theme-1">
+                                        <input type="hidden" name="uid" value="{{$note->uid}}">
+                                        <input type="hidden" name="managerSignatureStatus" value="">
+                                        <p>Undo sign as manager for CM Setup Performed?</p>
+                                        <div>
+                                            <button submit class="btn btn-sm btn-primary mr-1">Sign</button>
+                                            <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
+                        </div>
+                    </div>
+                    @endif
+
+                </div>
+
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="RM Setup">
+                    <div class="d-flex align-items-center mb-3">
+                        <p class="font-weight-bold text-secondary m-0 font-size-14">RM Setup</p>
+                    </div>
+                    @include('app.patient.note.rm-setup')
+                </div>
+
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="Supply Orders Summary">
+                    <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"
+                               popup-style="medium"
+                               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 bg-white">
+                                        <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">-</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 bg-white">
+                                    <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">-</div>
+                            @endif
+
+                        </div>
+                    </div>
+                </div>
+
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="Vitals Settings">
+                    <div class="d-flex align-items-center mb-3">
+                        <p class="font-weight-bold text-secondary m-0 font-size-14">Vitals Settings</p>
+                    </div>
+                    <div class="row" id="vitals-settings-{{$patient->uid}}">
+                        <div class="col-4 border-right">
+                            <div class="d-flex align-items-baseline">
+                                <b>BMI/Weight Management</b>
+                                <span class="mx-2 text-secondary">|</span>
+                                @include('app.patient.vitals-settings.bmi-management-form')
+                            </div>
+                            <div class="pt-3">
+                                @include('app.patient.vitals-settings.bmi-management-summary')
+                            </div>
+                        </div>
+                        <div class="col-8">
+                            <div class="d-flex align-items-baseline">
+                                <b>BP Management</b>
+                                <span class="mx-2 text-secondary">|</span>
+                                @include('app.patient.vitals-settings.bp-management-form')
+                            </div>
+                            <div class="pt-3">
+                                @include('app.patient.vitals-settings.bp-management-summary')
+                            </div>
+                        </div>
+                    </div>
+                    <script>
+                        (function () {
+                            function calculateUsualBmi() {
+                                let h = $('#bmi-management-settings [name="currentHeightInInches"]').val(),
+                                    wMin = $('#bmi-management-settings [name="usualWeightInPoundsMin"]').val(),
+                                    wMax = $('#bmi-management-settings [name="usualWeightInPoundsMax"]').val();
+                                let bmiMinElem = $('#bmi-management-settings [name="usualBmiMin"]').val(''),
+                                    bmiMinCategoryElem = $('#bmi-management-settings [name="usualBmiMinCategory"]').val(''),
+                                    bmiMaxElem = $('#bmi-management-settings [name="usualBmiMax"]').val(''),
+                                    bmiMaxCategoryElem = $('#bmi-management-settings [name="usualBmiMaxCategory"]').val('');
+                                calculateBmi(h, wMin, bmiMinElem, bmiMinCategoryElem);
+                                calculateBmi(h, wMax, bmiMaxElem, bmiMaxCategoryElem);
+                                return false;
+                            }
+
+                            function calculateIdealBmi() {
+                                let h = $('#bmi-management-settings [name="currentHeightInInches"]').val(),
+                                    w = $('#bmi-management-settings [name="idealWeightInPounds"]').val();
+                                let bmiElem = $('#bmi-management-settings [name="idealBmi"]').val(''),
+                                    bmiCategoryElem = $('#bmi-management-settings [name="idealBmiCategory"]').val('');
+                                calculateBmi(h, w, bmiElem, bmiCategoryElem);
+                                return false;
+                            }
+
+                            function calculateBmi(h, w, bmiElem, bmiCategoryElem) {
+                                let bmi = 0,
+                                    bmiCategory = '';
+                                try {
+                                    h = +h;
+                                    w = +w;
+                                    bmi = (w / (h * h)) * 703;
+                                    bmiElem.val(bmi.toFixed(1));
+                                    if (bmi < 18.5) {
+                                        bmiCategory = '(Underweight)';
+                                    }
+                                    if (bmi >= 18.5 && bmi < 25) {
+                                        bmiCategory = '(Healthy)';
+                                    }
+                                    if (bmi >= 25 && bmi < 30) {
+                                        bmiCategory = '(Overweight)';
+                                    }
+                                    if (bmi >= 30) {
+                                        bmiCategory = '(Obese)';
+                                    }
+                                    bmiCategoryElem.val(bmiCategory);
+                                } catch (e) {
+                                    return false;
+                                }
+                            }
+
+                            function init() {
+                                $(document)
+                                    .off('change input paste keyup',
+                                        '#bmi-management-settings [name="currentHeightInInches"], #bmi-management-settings [name="usualWeightInPoundsMin"],  #bmi-management-settings [name="usualWeightInPoundsMax"]')
+                                    .on('change input paste keyup',
+                                        '#bmi-management-settings [name="currentHeightInInches"], #bmi-management-settings [name="usualWeightInPoundsMin"],  #bmi-management-settings [name="usualWeightInPoundsMax"]', function () {
+                                            return calculateUsualBmi();
+                                        });
+                                $(document)
+                                    .off('change input paste keyup',
+                                        '#bmi-management-settings [name="currentHeightInInches"], #bmi-management-settings [name="idealWeightInPounds"]')
+                                    .on('change input paste keyup',
+                                        '#bmi-management-settings [name="currentHeightInInches"], #bmi-management-settings [name="idealWeightInPounds"]', function () {
+                                            return calculateIdealBmi();
+                                        });
+
+                                $('#bmi-management-settings [name="currentHeightInInches"]').trigger('change');
+
+                                let parentSegment = $('#bmi-management-settings');
+                                parentSegment.find('[heightFeetInput], [heightInchesInput]').off('change input paste');
+                                parentSegment.find('[heightFeetInput], [heightInchesInput]').on('change input paste', function () {
+                                    let inches = 0;
+                                    let ft = +(parentSegment.find('[heightFeetInput]').val()),
+                                        inc = +(parentSegment.find('[heightInchesInput]').val());
+                                    inches = Math.round(ft * 12 + inc);
+                                    parentSegment.find('[name="currentHeightInInches"]').val(inches).trigger('change');
+                                });
+                            }
+
+                            addMCInitializer('vitals-settings-{{$patient->uid}}', init, '#vitals-settings-{{$patient->uid}}')
+                        }).call(window);
+                    </script>
+                </div>
+
+                <div class="p-3 border-bottom" data-non-segment-section="ICDs">
+                    <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 position-static">No note reasons</div>
+                        @endif
+                        </div>
+                    </div>
+                </div>
+
+                @if($pro->pro_type === 'ADMIN')
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="Bills & Claims Summary">
+                    <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
+
+                {{-- companyPro, payer and location --}}
+                @if($note->method === 'IN_CLINIC' || $pro->pro_type === 'ADMIN')
+                <div class="p-3 border-bottom screen-only" data-non-segment-section="Pro/Payer Settings">
+                    <div class="ml-auto d-flex align-items-center">
+
+                        <div class="d-inline-flex align-items-center">
+                            <span class="text-secondary font-weight-bold">Company Pro:&nbsp;</span>
+                            <b>{{$note->hcpCompanyPro && $note->hcpCompanyPro->company ? $note->hcpCompanyPro->pro->displayName() . ' / ' . $note->hcpCompanyPro->company->name : '-'}}</b>
+                            @if($note->hcpCompanyPro && $note->hcpCompanyPro->company)
+                                <div moe class="ml-1">
+                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                    <form url="/api/note/wipeHcpCompanyPro">
+                                        <input type="hidden" name="uid" value="{{$note->uid}}">
+                                        <p>Wipe company pro 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>
+                                </div>
+                            @else
+                                <div moe class="ml-1">
+                                    <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
+                                    <form url="/api/note/putHcpCompanyPro">
+                                        <input type="hidden" name="uid" value="{{$note->uid}}">
+                                        <div class="mb-2">
+                                            <select name="hcpCompanyProUid" class="form-control form-control-sm">
+                                                <option value="">-- select --</option>
+                                                @foreach($note->hcpPro->companyPros as $companyPro)
+                                                    <option value="{{$companyPro->uid}}">{{$companyPro->pro->displayName() . ' / ' . $companyPro->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>
+                                </div>
+                            @endif
+                        </div>
+
+                        @if($note->hcpCompanyPro && $note->hcpCompanyPro->company)
+                            <span class="mx-2 text-secondary">|</span>
+                            <div class="d-inline-flex align-items-center">
+                                <span class="text-secondary font-weight-bold">Payer 1°:&nbsp;</span>
+                                <b>
+                                    {{$note->hcpCompanyProPayer && $note->hcpCompanyProPayer->payer ? $note->hcpCompanyProPayer->payer->name : '-'}}
+                                </b>
+                                @if($note->hcpCompanyProPayer && $note->hcpCompanyProPayer->payer)
+                                    <div 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>
+                                    </div>
+                                @else
+                                    <div 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->hcpCompanyPro->companyProPayers as $companyProPayer)
+                                                        <option value="{{$companyProPayer->uid}}">{{$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>
+                                    </div>
+                                @endif
+                            </div>
+
+                            <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>
+                            <div class="d-inline-flex align-items-center">
+                                <span class="text-secondary font-weight-bold">Location:&nbsp;</span><b>{{$note->hcpCompanyLocation ? $note->hcpCompanyLocation->line1 . ', ' . $note->hcpCompanyLocation->city : '-'}}</b>
+                                @if($note->hcpCompanyLocation)
+                                    <div 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>
+                                    </div>
+                                @else
+                                    <div 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-primary btn-sm" submit>Submit</button>
+                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </div>
+                                @endif
+                            </div>
+                        @endif
+                    </div>
+                </div>
+                @endif
+
+                {{-- bills --}}
+                @if($pro->pro_type === 'ADMIN' || ($note->hcpPro && $pro->id === $note->hcpPro->id))
+                    <div data-non-segment-section="HCP Bills">
+                    @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 && !!floatval($bill->na_expected_payment_amount))
+                                        <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
+
+                                    @if($pro->pro_type === 'ADMIN')
+                                        <b>{{$bill->hcpCompanyPro && $bill->hcpCompanyPro->company ? $bill->hcpCompanyPro->pro->displayName() . ' / ' . $bill->hcpCompanyPro->company->name : '-'}}</b>
+                                        <div moe class="ml-1">
+                                            <a class="text-primary" href="" show start>Swap HCP Company Pro</a>
+                                            <form url="/api/bill/swapHcpCompanyPro">
+                                                <input type="hidden" name="uid" value="{{$bill->uid}}">
+                                                <div class="mb-2">
+                                                    <select name="hcpCompanyProUid" class="form-control form-control-sm">
+                                                        <option value="">-- select --</option>
+                                                        @foreach($bill->hcp->companyPros as $companyPro)
+                                                            <option value="{{$companyPro->uid}}">{{$companyPro->pro->displayName() . ' / ' . $companyPro->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>
+                                        </div>
+                                    @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-primary 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-primary 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-primary 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 : 'Please contact billing.'}}</textarea>
+                                                </div>
+                                                <div>
+                                                    <button class="btn btn-primary 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">Please contact billing.</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 Ack.
+                                        </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>
+                                            Ack.
+                                        </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-primary 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-primary 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-primary 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>
+                            @elseif($note->hcpPro && $pro->id === $note->hcpPro->id)
+                                <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 pl-2">Verification</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 class="pl-2">
+                                    @if(!$bill->is_cancelled)
+                                        @if(!$bill->is_verified)
+                                            <div class="text-warning-mellow font-weight-bold">Not Verified</div>
+                                        @else
+                                            <div class="text-info font-weight-bold"><i class="fa fa-check"></i> Verified</div>
+                                        @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-primary 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-primary 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>
+                                            @if($bill->is_cancelled && !$bill->is_cancellation_acknowledged)
+                                                <div class="ml-2 text-secondary">
+                                                    <i class="fa fa-exclamation-triangle"></i>
+                                                    Not Ack.
+                                                </div>
+                                                <div class="d-block ml-2" 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="ml-2 text-secondary">
+                                                    <i class="fa fa-check"></i>
+                                                    Ack.
+                                                </div>
+                                                <div class="d-block ml-2" moe>
+                                                    <a class="" href="" show start>Undo</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-primary btn-sm"
+                                                                    submit>Submit</button>
+                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </div>
+                                            @endif
+                                        @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
+                    </div>
+                @endif
+
+                {{-- generic bills --}}
+                @if($pro->pro_type === 'ADMIN' || ($note->allyPro && $pro->id === $note->allyPro->id))
+                    <div data-non-segment-section="NA Bills">
+                    @include('app.generic-bills.inline', ['patient' => $patient, 'note' => $note, 'class' => 'p-3 border-bottom', 'label' => 'NA', 'entityType' => 'Note', 'entityUid' => $note->uid])
+                    </div>
+                @endif
+
+                {{-- claims --}}
+                @if($pro->pro_type === 'ADMIN')
+                    <div data-non-segment-section="Claims">
+                    @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-primary 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 p-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
+                    </div>
+                @endif
+
+                {{-- addendums --}}
+                @if($note->is_signed_by_hcp)
+                <div class="border-top p-3 screen-only" data-non-segment-section="Addendums">
+                    @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>
+                @endif
+
+                <div class="screen-only">
+                    @include('app/patient/note/_cancel-signed-note')
+                </div>
+
+                </div>
+
+                    @if($isVisitTemplateBased && !$note->is_signed_by_hcp)
+                    <div class="position-sticky note-bottom-toolbar border-top border-info p-0 bg-aliceblue d-flex align-items-stretch">
+                        <div class="nbt-container border-right border-info">
+                            <!-- render mrv segment here -->
+                            <?php $segment = null; ?>
+                            @foreach($note->segments as $segment)
+                                @if($segment->segmentTemplate->internal_name === 'medrisk_vigilence')
+                                    <div native target="_blank"
+                                         class="d-block c-pointer mrv-trigger d-flex align-items-center px-2 py-1"
+                                         open-in-stag-popup
+                                         title="MedRisk Vigilance"
+                                         popup-style="stag-popup-md"
+                                         href="/segment-summary/{{$segment->uid}}">
+                                        <div class="text-info font-weight-bold text-center font-size-11">MRV</div>
+                                        {!! $segment->summary_html !!}
+                                    </div>
+                                @endif
+                            @endforeach
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center medications-center-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 mc-initer="medications-center-{{$note->id}}"
+                                 title="Medications Center"
+                                 popup-style="medium-large overflow-visible"
+                                 href="/medications-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Rx</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center problems-center-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 mc-initer="problems-center-{{$note->id}}"
+                                 title="Problems Center"
+                                 popup-style="medium-large overflow-visible"
+                                 href="/problems-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Dx</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center goals-center-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 mc-initer="goals-center-{{$note->id}}"
+                                 title="Goals Center"
+                                 popup-style="medium-large overflow-visible"
+                                 href="/goals-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Goals</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center allergies-center-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 mc-initer="allergies-center-{{$note->id}}"
+                                 title="Allergies Center"
+                                 popup-style="medium-large overflow-visible"
+                                 href="/allergies-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Allergies</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center careteam-center-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 mc-initer="careteam-center-{{$note->id}}"
+                                 title="Care Team Center"
+                                 popup-style="medium-large overflow-visible"
+                                 href="/careteam-center/{{$patient->uid}}/{{$note->uid}}">
+                                <i class="fa fa-bolt mr-1"></i>
+                                <span>Care Team</span>
+                            </div>
+                        </div>
+                        <!--<div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div class="position-relative on-click-menu d-inline-flex align-items-center px-2 py-1">
+                                <span class="">LS <i class="fa fa-caret-up"></i></span>
+                                <div menu bottom class="bg-white border">
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_general">General</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_nutrition">Nutrition</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_physical_activity">Physical Activity</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_sleep">Sleep</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_social">Social Relationships</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_substances">Substance Use</a>
+                                    <a href="#" class="ls-segment-trigger px-2 py-1 text-nowrap d-block" data-target="lifestyle_stress">Stress</a>
+                                </div>
+                            </div>
+                        </div>-->
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center incoming-reports-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 mc-initer="incoming-reports"
+                                 title="Incoming Reports"
+                                 popup-style="wide overflow-visible"
+                                 href="/patients/view/{{$patient->uid}}/incoming-reports?noteUid={{$note->uid}}">
+                                <span>Inc. Rpts.</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center documents-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 title="Documents"
+                                 popup-style="wide overflow-visible"
+                                 href="/patients/view/{{$patient->uid}}/documents">
+                                <span>Docs</span>
+                            </div>
+                        </div>
+                        <div class="nbt-container border-right border-info d-inline-flex align-self-stretch">
+                            <div native target="_blank"
+                                 class="c-pointer d-inline-flex align-items-center handouts-trigger px-2 py-1"
+                                 open-in-stag-popup
+                                 title="Handouts"
+                                 popup-style="wide overflow-visible"
+                                 href="/patients/view/{{$patient->uid}}/handouts?noteUid={{$note->uid}}">
+                                <span>Handouts</span>
+                            </div>
+                        </div>
+                    </div>
+                    @endif
+
+                </div>
+                @if($isVisitTemplateBased && !$note->is_signed_by_hcp)
+                    @include('app.patient.note.rhs-sidebar')
+                @endif
+            </div>
+        </div>
+    </div>
+    <div class="note-templates-underlay"></div>
+    @include('app.patient.note.dashboard_script')
+    @if(!$isVisitTemplateBased)
+    @include('app.patient.canvas-sections.canvas-editor-modal', ['key' => 'rx', 'class' => 'wide', 'noEditLink' => true])
+    @endif
+    @if($isVisitTemplateBased)
+    <script>
+        (function() {
+            function init() {
+                fixTreeTopAndHeight();
+                $(window).on('resize', fixTreeTopAndHeight);
+                $(window).on('scroll', fixTreeTopAndHeight);
+                $('.note-tree-node>a[data-segment-uid]')
+                    .off('click.scroll-to-segment')
+                    .on('click.scroll-to-segment', 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');
+                        }
+                        return false;
+                    });
+                // clicking node parent - go to first child
+                $('.note-tree-node.note-tree-heading>a:not([data-segment-uid])')
+                    .off('click.scroll-to-first-child-segment')
+                    .on('click.scroll-to-first-child-segment', function() {
+                         $(this).parent().find('>.note-tree-children>.note-tree-node>a[data-segment-uid]').first().trigger('click');
+                         return false;
+                    });
+                $(document)
+                    .off('click.scroll-to-non-segment', '[data-non-segment-target]')
+                    .on('click.scroll-to-non-segment', '[data-non-segment-target]', function() {
+                        closeStagPopup(true);
+                        let section = $('div[data-non-segment-section="' + $(this).attr('data-non-segment-target') + '"]').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;
+                    });
+
+                // update disclaimers on fastReload()
+                // NOTE: this is NOT the ideal place to put this
+                @if(!$note->is_signed_by_hcp)
+                $('.visit-segment[data-segment-template-name="disclaimers"]').find('.refresh-segment').trigger('click');
+                @endif
+            }
+            function fixTreeTopAndHeight() {
+                let tree = $('#note-lhs-tree'), rhsSidebar = $('#note-rhs-sidebar'), noteCardHeader = $('#note-card-header');
+                if(!noteCardHeader.length) return;
+                let resultTop = (noteCardHeader.offset().top + noteCardHeader.outerHeight(true)) - $(window).scrollTop();
+                if(resultTop <= 55) {
+                    @if(!$note->is_signed_by_hcp)
+                    tree.addClass('fixed');
+                    rhsSidebar.addClass('fixed');
+                    @else
+                    tree.addClass('fixed-left');
+                    @endif
+                }
+                else {
+                    @if(!$note->is_signed_by_hcp)
+                    tree.removeClass('fixed');
+                    @else
+                    tree.removeClass('fixed-left');
+                    @endif
+                    tree.css('height', 'calc(100vh - ' + resultTop + 'px)');
+                    tree.css('max-height', 'calc(100vh - ' + resultTop + 'px)');
+                    rhsSidebar.removeClass('fixed');
+                    rhsSidebar.css('height', 'calc(100vh - ' + resultTop + 'px)');
+                    rhsSidebar.css('max-height', 'calc(100vh - ' + resultTop + 'px)');
+                }
+            }
+            addMCInitializer('note-tree', init, '#note-lhs-tree');
+        })();
+    </script>
+    @endif
+@endsection
+@if(!$isVisitTemplateBased)
+@section('left-nav-content')
+    @if(!$note->is_signed_by_hcp)
+    <div class="left-nav-content" id="note-sections-app">
+        <div class="note-widget-title px-2 py-1">Note Sections</div>
+        <input type="search" class="d-block w-100 border-0 outline-0 px-2 py-1"
+               v-model="q" placeholder="Filter">
+        <div class="border-top py-1">
+            <div v-for="section in sections"
+                 v-show="section.title.toLowerCase().indexOf(q.toLowerCase()) !== -1">
+                <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
+                     :title="section.title + ' - Click to remove'"
+                     v-if="section.used"
+                     v-on:click.once="remove(section.section_uid)">
+                    <span class="mx-2">
+                        <a class="font-12 text-secondary" href="#">
+                            <i class="fa fa-minus-circle"></i>
+                        </a>
+                    </span>
+                    <span class="font-smaller text-ellipsis">
+                        @{{section.title}}
+                    </span>
+                </div>
+                <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
+                     :title="section.title + ' - Click to add'"
+                     v-if="!section.used"
+                     v-on:click.once="add(section.uid, section.internal_name)">
+                    <span class="mx-2">
+                        <a class="font-12" href="#">
+                            <i class="fa fa-plus-circle"></i>
+                        </a>
+                    </span>
+                    <span class="font-smaller text-ellipsis">
+                        @{{section.title}}
+                    </span>
+                </div>
+            </div>
+        </div>
+    </div>
+                <script>
+        (function() {
+            function initSectionsWidget() {
+                var allSections = <?= json_encode($allSections) ?>;
+                new Vue({
+                    el: '#note-sections-app',
+                    delimiters: ['@{{', '}}'],
+                    data: {
+                        q: '',
+                        sections: allSections
+                    },
+                    methods: {
+                        add: function(_uid, _section) {
+                            $.post('/api/section/create', {
+                                noteUid: '{{$note->uid}}',
+                                sectionTemplateUid: _uid,
+                            }, function(_data) {
+                                if(_data) {
+                                    if(_data.success) {
+                                        fastReload();
+                                    }
+                                    else {
+                                        toastr.error(_data.message);
+                                    }
+                                }
+                                else {
+                                    toastr.error('Unable to add section!');
+                                }
+                            }, 'json');
+                        },
+                        remove: function(_uid) {
+                            $.post('/api/section/deactivate', {
+                                uid: _uid,
+                                memo: 'Deactivated from note',
+                            }, function(_data) {
+                                if(_data) {
+                                    if(_data.success) {
+                                        fastReload();
+                                    }
+                                    else {
+                                        toastr.error(_data.message);
+                                    }
+                                }
+                                else {
+                                    toastr.error('Unable to remove section!');
+                                }
+                            }, 'json');
+                        }
+                    }
+                });
+
+                $('div[embed]').each(function() {
+                    $(this).load($(this).attr('embed'));
+                });
+            }
+            addMCInitializer('note-sections-widget', initSectionsWidget, '#note-sections-app');
+        })();
+    </script>
+    @endif
+@endsection
+@endif

+ 16 - 6
resources/views/app/patient/note/dashboard.blade.php

@@ -40,7 +40,7 @@
     endforeach;
 
     ?>
-    <div id="note-single-header" class="pb-3 d-flex align-items-start screen-only zero-height">
+    <div id="note-single-header" class="pb-3 d-flex align-items-start screen-only zero-height note_template_{{$note->visitTemplate ? $note->visitTemplate->internal_name : ''}}">
         <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>
@@ -454,14 +454,14 @@
             </div>
         </div>
         <div class="card-body p-0">
-            <div class="note-container">
-                @if($isVisitTemplateBased && !$doesVisitTemplateUiConfigExist)
+            <div class="note-container note_template_{{$note->visitTemplate ? $note->visitTemplate->internal_name : ''}}"">
+                @if($isVisitTemplateBased && !$doesVisitTemplateUiConfigExist && $note->visitTemplate->internal_name !== 'soap_visit')
                     @include('app.patient.note.lhs-tree')
                 @endif
                 <div class="note-rhs-content">
                 <div>
                 <div class="border-bottom pb-3">
-                    <div>
+                    <div class="{{$isVisitTemplateBased && $note->visitTemplate->internal_name === 'soap_visit' ? 'd-flex align-items-stretch' : ''}}">
                         <?php
                         $shortCutsObject = [];
                         foreach ($pro->allShortcuts() as $shortcut) {
@@ -531,7 +531,7 @@
                         $shortcuts = "";
                         $latestSectionTS = 0;
                         ?>
-                        <div class="{{ $note->is_signed_by_hcp ? 'note-signed-by-hcp' : '' }}">
+                        <div class="{{ $note->is_signed_by_hcp ? 'note-signed-by-hcp' : '' }} {{$isVisitTemplateBased && $note->visitTemplate->internal_name === 'soap_visit' ? 'w-50' : ''}}">
                             @if($isVisitTemplateBased && $doesVisitTemplateLayoutExist)
                                 @include($visitLayoutPath)
                             @elseif($isVisitTemplateBased && !$doesVisitTemplateUiConfigExist)
@@ -542,6 +542,14 @@
                                 @include('app.patient.note.note-section-list')
                             @endif
                         </div>
+                        @if($isVisitTemplateBased && $note->visitTemplate->internal_name === 'soap_visit')
+                        <div class="w-50 border-left">
+                            @if($isVisitTemplateBased && !$note->is_signed_by_hcp)
+                                {{--@include('app.patient.note.rhs-sidebar')--}}
+                                @include('app.patient.note.note-segment-list-rhs')
+                            @endif
+                        </div>
+                        @endif
                     </div>
                 </div>
 
@@ -2539,7 +2547,7 @@
                     @endif
 
                 </div>
-                @if($isVisitTemplateBased && !$note->is_signed_by_hcp)
+                @if($isVisitTemplateBased && !$note->is_signed_by_hcp && $note->visitTemplate->internal_name !== 'soap_visit')
                     @include('app.patient.note.rhs-sidebar')
                 @endif
             </div>
@@ -2554,9 +2562,11 @@
     <script>
         (function() {
             function init() {
+                @if($note->visitTemplate->internal_name !== 'soap_visit')
                 fixTreeTopAndHeight();
                 $(window).on('resize', fixTreeTopAndHeight);
                 $(window).on('scroll', fixTreeTopAndHeight);
+                @endif
                 $('.note-tree-node>a[data-segment-uid]')
                     .off('click.scroll-to-segment')
                     .on('click.scroll-to-segment', function() {

+ 609 - 0
resources/views/app/patient/note/dashboard_script-bu-b4-oure-soap.blade.php

@@ -0,0 +1,609 @@
+<script>
+        (function() {
+
+            let numSectionsPendingInitialization = 0;
+
+            function init() {
+
+                // on note-section hover, highlight the according left-tree node(s)
+                $(document)
+                    .off('mouseenter', '.note-section')
+                    .on('mouseenter', '.note-section', function(){
+                        $('.note-tree-node').removeClass('hovered');
+                        let target = $('.note-tree-node a[data-segment-uid="' + $(this).attr('data-segment-uid') + '"]');
+                        target.parent().addClass('hovered');
+                        target.parent().parents('.note-tree-node').addClass('hovered');
+                        return false;
+                    });
+
+                $(document)
+                    .off('mouseenter', '[data-non-segment-section]')
+                    .on('mouseenter', '[data-non-segment-section]', function(){
+                        $('.note-tree-node').removeClass('hovered');
+                        let target = $('.note-tree-node a[data-non-segment-target="' + $(this).attr('data-non-segment-section') + '"]');
+                        target.parent().addClass('hovered');
+                        target.parent().parents('.note-tree-node').addClass('hovered');
+                        return false;
+                    });
+
+                $(document)
+                    .off('mouseleave', '.note-section')
+                    .on('mouseleave', '.note-section', () => {
+                        $('.note-tree-node').removeClass('hovered');
+                        return false;
+                    });
+
+                // print note
+                $(document)
+                    .off('click.print', '.print-note')
+                    .on('click.print', '.print-note', () => {
+                        window.print();
+                        return false;
+                    });
+                $('.print-note').removeClass('invisible');
+
+                $('.note-method-select').change(function() {
+                    let form = $(this).closest('form');
+                    if(this.value === 'IN_CLINIC') {
+                        form.find('.if-in-clinic').show();
+                    }
+                    else {
+                        form.find('.if-in-clinic').hide();
+                    }
+                });
+
+                $('.note-method-select').each(function() {
+                    let form = $(this).closest('form');
+                    if(this.value === 'IN_CLINIC') {
+                        form.find('.if-in-clinic').show();
+                    }
+                    else {
+                        form.find('.if-in-clinic').hide();
+                    }
+                });
+
+                $('textarea[rte]').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 ti = $('<input type="hidden" />')
+                        .val(this.value)
+                        .attr('name', this.name)
+                        .insertBefore(this);
+                    var ce = $('<div data-editor-id="' + editorID + '" data-field="' + this.name + '"/>')
+                        .html(this.value)
+                        .insertBefore(this);
+                    $(this).remove();
+
+                    var qe = new Quill('[data-editor-id="' + editorID + '"]', {
+                        theme: 'snow',
+                        modules: stagQuillConfig
+                    });
+                    var toolbar = $(qe.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);
+
+                    qe.on('text-change', function() {
+                        ti.val(qe.root.innerHTML);
+                    });
+
+                    $(qe.container)
+                        .find('.ql-editor[contenteditable]')
+                            .attr('data-field', fieldName)
+                            .attr('data-editor-id', editorID)
+                            .attr('with-shortcuts', 1);
+
+                });
+
+                $(document)
+                    .off('click.edit-trigger', '.edit-trigger:not(.edit)')
+                    .on('click.edit-trigger', '.edit-trigger:not(.edit)', function() {
+
+                        if($('.note-section>.stag-popup:visible').length) return;
+
+                        let editParent = $(this).closest('.note-section');
+
+                        // TEMP: disable edit mode for medrisk_vigilance
+                        // TODO: do this in the proper place
+                        if(editParent.is('[data-segment-template-name="medrisk_vigilence"]')) return false;
+
+                        // TEMP: show wizard for allergies, rx, dx, goals
+                        if(editParent.is('[data-segment-template-name="plan_allergies"]') ||
+                            editParent.is('[data-segment-template-name="intake_allergies"]')) {
+                            $('.note-bottom-toolbar .allergies-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_problems"]') ||
+                            editParent.is('[data-segment-template-name="intake_problems"]')) {
+                            $('.note-bottom-toolbar .problems-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_medications"]') ||
+                            editParent.is('[data-segment-template-name="intake_medications"]')) {
+                            $('.note-bottom-toolbar .medications-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_goals"]') ||
+                            editParent.is('[data-segment-template-name="intake_goals"]')) {
+                            $('.note-bottom-toolbar .goals-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_care_team"]') ||
+                            editParent.is('[data-segment-template-name="intake_care_team"]')) {
+                            $('.note-bottom-toolbar .careteam-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_supplements"]') ||
+                            editParent.is('[data-segment-template-name="intake_supplements"]')) {
+                            $('.note-bottom-toolbar .supplements-center-trigger').trigger('click');
+                            return false;
+                        }
+
+                        // TEMP: open in popup if LS segment
+                        if(editParent.is('[data-segment-template-name^="lifestyle_"]')) {
+                            showStagPopup('segment-popup-' + editParent.attr('data-segment-template-name'), true);
+                            return false;
+                        }
+
+                        if(editParent.is('[data-segment-template-name="plan_nutrition"]') ||
+                            editParent.is('[data-segment-template-name="intake_nutrition"]')) {
+                            openDynamicStagPopup('/nutrition-center/{{$note->client->uid}}/{{$note->uid}}',
+                                'nutrition-center-{{$note->id}}',
+                                '<img src="/img/nutrition-rx.png" class=""/> Nutrition Rx',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+
+                        if(editParent.is('[data-segment-template-name="plan_exercise"]') ||
+                            editParent.is('[data-segment-template-name="intake_exercise"]')) {
+                            openDynamicStagPopup('/exercise-center/{{$note->client->uid}}/{{$note->uid}}',
+                                'exercise-center-{{$note->id}}',
+                                '<img src="/img/exercise-rx.png" class=""/> Exercise Rx',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+
+                        if(editParent.is('[data-segment-template-name="plan_behavior"]') ||
+                            editParent.is('[data-segment-template-name="intake_behavior"]')) {
+                            openDynamicStagPopup('/behavior-center/{{$note->client->uid}}/{{$note->uid}}',
+                                'behavior-center-{{$note->id}}',
+                                '<img src="/img/behavior-rx.png" class=""/> Behavior Rx',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+
+                        <?php
+                        $rosSegment = $note->getSegmentByInternalName('ros');
+                        ?>
+                        @if($rosSegment)
+                        if(editParent.is('[data-segment-template-name="ros"]')) {
+                            openDynamicStagPopup('/note-segment-view/{{$note->client->uid}}/{{$note->uid}}/{{$rosSegment->uid}}/ros/edit',
+                                'init-ros-{{$note->id}}',
+                                'Review of Systems',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+                        @endif
+
+                        // OPEN popup for if note-segment-view exists
+                        if($('.' + editParent.attr('data-segment-template-name') + '-trigger').length) {
+                            $('.' + editParent.attr('data-segment-template-name') + '-trigger').trigger('click');
+                            return false;
+                        }
+
+                        if(editParent.is('.edit')) {
+                            editParent.removeClass('edit');
+                        }
+                        else {
+                            let docRoot = $('html');
+                            let prevEffectiveTop = editParent.offset().top - docRoot.scrollTop();
+                            $('.note-section.edit').removeClass('edit');
+                            editParent.addClass('edit');
+                            let newEffectiveTop = editParent.offset().top - docRoot.scrollTop();
+                            if(newEffectiveTop < prevEffectiveTop) {
+                                docRoot.scrollTop(docRoot.scrollTop() - (prevEffectiveTop - newEffectiveTop));
+                            }
+                        }
+
+                        let visitTreeLink = $('.note-tree-node a[data-segment-internal-name="' + editParent.attr('data-segment-template-name') + '"]');
+                        if(visitTreeLink.length) {
+                            $('.note-tree-node.active').removeClass('active');
+                            visitTreeLink.closest('.note-tree-node').addClass('active');
+                        }
+
+                        return false;
+                    });
+
+                $('.note-templates-trigger')
+                    .off('click.note-templates-trigger')
+                    .on('click.note-templates-trigger', function() {
+                        $('.note-templates-underlay').show();
+                        let container = $(this).closest('.note-section').find('.note-template-container');
+                        container.find('.note-template-children').hide();
+                        container.find('.note-template-item.selected').removeClass('selected');
+                        container.find('.note-template-item[prefix]').removeAttr('prefix');
+                        container.find('input[type="checkbox"]').prop('checked', false);
+                        container.find('.note-template-output-text').empty();
+                        container.show();
+                        loadTemplateSet(container.find('.note-template-set-chooser'));
+                        loadExamTemplateSet(container.find('.note-exam-template-set-chooser'),
+                            container.find('.note-exam-exam-chooser').val(),
+                            container.find('.note-exam-template-set-chooser').val());
+                        return false;
+                    });
+
+                $(document)
+                    .off('click.note-templates-trigger-assessment', '.note-templates-trigger-assessment')
+                    .on('click.note-templates-trigger-assessment', '.note-templates-trigger-assessment', function() {
+                        $('.note-templates-underlay').show();
+                        let container = $(this).closest('.note-section').find('.note-template-container');
+                        container.find('.note-template-children').hide();
+                        container.find('.note-template-item.selected').removeClass('selected');
+                        container.find('.note-template-item[prefix]').removeAttr('prefix');
+                        container.find('input[type="checkbox"]').prop('checked', false);
+                        container.find('.note-template-output-text').empty();
+                        container.attr('data-editor-id', $(this).attr('data-editor-id'));
+                        container.show();
+                        container.css({
+                            left: ($(this).position().left - 140) + 'px',
+                            top: ($(this).position().top + 22) + 'px',
+                        });
+                        loadTemplateSet(container.find('.note-template-set-chooser'));
+                        loadExamTemplateSet(container.find('.note-exam-template-set-chooser'),
+                            container.find('.note-exam-exam-chooser').val(),
+                            container.find('.note-exam-template-set-chooser').val());
+                        return false;
+                    });
+
+                $(document)
+                    .off('click.note-templates-underlay', '.note-templates-underlay, .note-template-close-trigger')
+                    .on('click.note-templates-underlay', '.note-templates-underlay, .note-template-close-trigger', function() {
+                        $('.note-templates-underlay').hide();
+                         $('.note-template-container').hide();
+                    });
+
+                $(document)
+                    .off('click.note-template-label', '.note-template-item .label')
+                    .on('click.note-template-label', '.note-template-item .label', function() {
+                        let item = $(this).closest('.note-template-item');
+                        let isChecked = $(this).find('>input[type="checkbox"]').prop('checked');
+                        let hasChildren = !!item.find('>.note-template-children').length,
+                            childrenShown = item.find('>.note-template-children:visible').length;
+
+                        if(isChecked && hasChildren && !childrenShown) { // just show
+                            $('.note-template-children').hide();
+                            $(this).parents('.note-template-children').show();
+                            item.find('>.note-template-children').show()
+                                .find('>textarea,>input[type="number"],>input[type="date"]').first().focus();
+                            return false;
+                        }
+
+                        $(this).find('>input[type="checkbox"]').prop('checked', !isChecked);
+                        isChecked = !isChecked;
+                        if(isChecked) {
+                            item.addClass('selected');
+                        }
+                        else {
+                            item.removeClass('selected');
+                        }
+                        $('.note-template-children').hide();
+                        $(this).parents('.note-template-children').show();
+                        if(isChecked) {
+                            item.find('>.note-template-children')
+                                .show()
+                                .find('>textarea,>input[type="number"],>input[type="date"]')
+                                .first().focus();
+                        }
+
+                        generateTemplateOutput();
+
+                        return false;
+                    });
+
+                $(document)
+                    .off('mousedown.note-templates-apply', '.note-template-apply-trigger')
+                    .on('mousedown.note-templates-apply', '.note-template-apply-trigger', function() {
+                        let templateContainer = $('.note-template-container:visible').first();
+                        let result = $('.note-template-output-text:visible').first().html();
+                        $('.note-templates-underlay').hide();
+                        $('.note-template-container').hide();
+                        let editor = null;
+                        if($(this).closest('.assessment-detail-template').length) {
+                            editor  = $('.ql-editor[data-editor-id="' + templateContainer.attr('data-editor-id') + '"]:visible').first();
+                        }
+                        else {
+                            editor  = $('.ql-editor[contenteditable]:visible').first();
+                        }
+                        if(editor && editor.length) {
+                            result = $.trim(editor.text() !== '' ? editor.html() : '') + result;
+                            editor.html(result).focus();
+                        }
+                        return false;
+                    });
+
+                $(document)
+                    .off('input paste change', '.note-template-item textarea, .note-template-item input[type="number"], .note-template-item input[type="date"]')
+                    .on('input paste change', '.note-template-item textarea, .note-template-item input[type="number"], .note-template-item input[type="date"]', function() {
+                        generateTemplateOutput();
+                    });
+
+                $(document)
+                    .off('click.plus-trigger', '.note-template-item .plus-trigger')
+                    .on('click.plus-trigger', '.note-template-item .plus-trigger', function() {
+                        let item = $(this).closest('.note-template-item');
+                        if(item.attr('prefix') === '(+)') {
+                            item.removeAttr('prefix');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', false);
+                            item.removeClass('selected');
+                        }
+                        else {
+                            item.attr('prefix', '(+)');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', true);
+                            item.addClass('selected');
+                        }
+                        generateTemplateOutput();
+                        return false;
+                    });
+
+                $(document)
+                    .off('click.minus-trigger', '.note-template-item .minus-trigger')
+                    .on('click.minus-trigger', '.note-template-item .minus-trigger', function() {
+                        let item = $(this).closest('.note-template-item');
+                        if(item.attr('prefix') === '(-)') {
+                            item.removeAttr('prefix');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', false);
+                            item.removeClass('selected');
+                        }
+                        else {
+                            item.attr('prefix', '(-)');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', true);
+                            item.addClass('selected');
+                        }
+                        generateTemplateOutput();
+                        return false;
+                    });
+
+                $(document)
+                    .off('change.note-template-set-chooser', '.note-template-set-chooser')
+                    .on('change.note-template-set-chooser', '.note-template-set-chooser', function() {
+                        return loadTemplateSet($(this));
+                    });
+
+                $(document)
+                    .off('change.note-exam-template-set-chooser', '.note-exam-template-set-chooser')
+                    .on('change.note-exam-template-set-chooser', '.note-exam-template-set-chooser', function() {
+                        $(this).closest('.note-template-container')
+                            .find('.note-exam-exam-chooser')
+                                .val($(this).find('option:selected').attr('exam'));
+                        return loadExamTemplateSet($(this),
+                            $(this).closest('.note-template-container').find('.note-exam-exam-chooser').first().val(),
+                            $(this).val());
+                    });
+
+                $(document)
+                    .off('change.note-exam-exam-chooser', '.note-exam-exam-chooser')
+                    .on('change.note-exam-exam-chooser', '.note-exam-exam-chooser', function() {
+                        return loadExamTemplateSet($(this),
+                            $(this).val(),
+                            $(this).closest('.note-template-container').find('.note-exam-template-set-chooser').first().val());
+                    });
+
+                $('.remove-section-trigger').click(function() {
+                    $.post('/api/section/deactivate', {
+                        uid: $(this).attr('data-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');
+                    // $(this).closest('.note-section').removeClass('edit');
+                    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) {
+                        if($(this).closest('.note-signed-by-hcp').length) return;
+                        e.stopPropagation();
+                        e.preventDefault();
+                        $(this).find('.edit-trigger').first().click();
+                        return false;
+                    });
+                @endif
+
+                $(document)
+                    .off('keydown.collapse-active-segment')
+                    .on('keydown.collapse-active-segment', function(e) {
+                        if(e.which === 27) {
+                            if(!isEventConsumed(e)) {
+                                if($('.visit-segment.edit').length) {
+                                    $('.visit-segment.edit').first().find('.edit-trigger').first().click();
+                                    markEventAsConsumed(e);
+                                    return false;
+                                }
+                            }
+                            else {
+                                // event already consumed!
+                            }
+                        }
+                    });
+
+                scrollToLatest();
+
+                function __moveSection(_uid, _direction) {
+                    $.post('/api/section/move' + _direction, {
+                        uid: _uid
+                    }, function(_data) {
+                        if(_data && _data.success) {
+                            fastReload();
+                        }
+                        else {
+                            if(_data) {
+                                toastr.error(_data.message);
+                            }
+                            else {
+                                toastr.error('Unknown error while moving section');
+                            }
+                        }
+                    }, 'json')
+                }
+
+                $('.move-up-trigger').click(function() {
+                    __moveSection($(this).attr('data-uid'), 'Up');
+                });
+
+                $('.move-down-trigger').click(function() {
+                    __moveSection($(this).attr('data-uid'), 'Down');
+                });
+
+                // refresh once ticket popup is closed
+                /*$('body').off('stag-popup-closed')
+                $('body').on('stag-popup-closed', function() {
+                    if($('#note-single-header').length) {
+                        fastReload();
+                    }
+                });*/
+                // ticket-popup
+                $(document)
+                    .off('click', '.ticket-popup-trigger.note-dashboard-action')
+                    .on('click', '.ticket-popup-trigger.note-dashboard-action', function() {
+                        showMask();
+                        window.noMc = true;
+                        $.get(this.href, (_data) => {
+
+                            if(!$('.ticket-popup').length) {
+                                $('main.stag-content').append('<div class="stag-popup stag-popup-lg ticket-popup mcp-theme-1" stag-popup-key="ticket-popup"></div>');
+                            }
+
+                            $('.ticket-popup').html(_data);
+                            showStagPopup('ticket-popup', true);
+                            $('.ticket-popup .stag-popup.stag-slide').attr('close-all-with-self', 1);
+                            runMCInitializer('patient-tickets'); // run specific mc initer
+                            hideMask();
+                        });
+                        return false;
+                    });
+
+            }
+
+            // scroll to latest created section
+            function scrollToLatest() {
+                window.setTimeout(function() {
+                    let latestSectionTS = $('.latest-section-ts');
+                    if(latestSectionTS.length) {
+                        let latestSection = $('.note-section[data-ts="' + latestSectionTS.text() + '"]');
+                        if(latestSection.length) {
+                            latestSection[0].scrollIntoView({behavior: "smooth", block: "center"});
+                            // latestSection.find('.edit-trigger').first().click();
+                            console.log('DONE!');
+                        }
+                    }
+                }, 100);
+            }
+
+            function loadTemplateSet(_chooser) {
+                if(!_chooser.length || !_chooser.val()) return false;
+                let container = _chooser.closest('.note-template-container');
+                container.find('>.note-template-item').remove();
+                container.find('.please-wait').remove();
+                container.append('<p class="please-wait my-2 text-secondary text-center">Please wait ...</p>');
+                $.get('/note-template-set/' + _chooser.attr('data-section') + '/' + _chooser.val(), function(_html) {
+                    container.find('.please-wait').remove();
+                    container.append(_html);
+                });
+                return false;
+            }
+
+            function loadExamTemplateSet(_chooser, _exam, _templateSet) {
+                if(!_chooser.length || !_chooser.val()) return false;
+                let container = _chooser.closest('.note-template-container');
+                container.find('>.note-template-item').remove();
+                container.find('.please-wait').remove();
+                container.append('<p class="please-wait my-2 text-secondary text-center">Please wait ...</p>');
+                $.get('/note-template-set/exam/' + _exam + '/' + _templateSet, function(_html) {
+                    container.find('.please-wait').remove();
+                    container.append(_html);
+                });
+                return false;
+            }
+
+            function generateOutputForNode(_node) {
+                let template = (_node.attr('prefix') ? _node.attr('prefix') : '') + _node.attr('template'),
+                    value = template;
+                let hasChildText = !!_node.find('>.note-template-children>textarea,>.note-template-children>input[type="number"],>.note-template-children>input[type="date"]').length;
+                let hasChildren = !!_node.find('>.note-template-children>.note-template-item').length;
+                if(hasChildText) {
+                    value = value.replace('{text}',
+                        _node
+                            .find('>.note-template-children')
+                                .find('>textarea,>input[type="number"],>input[type="date"]').first().val());
+                }
+                else if(hasChildren) {
+                    let values = [];
+                    _node.find('>.note-template-children>.note-template-item.selected').each(function() {
+                        values.push(generateOutputForNode($(this)));
+                    });
+                    let combined = '';
+                    for (let i = 0; i < values.length; i++) {
+                        combined += values[i];
+                        if(values.length > 1 && i <= values.length - 2) {
+                            if(i === values.length - 2) {
+                                combined += ' and ';
+                            }
+                            else {
+                                combined += ', ';
+                            }
+                        }
+                    }
+                    value = value.replace('{children}', ' ' + combined).replace('{text}', ' ' + combined);
+                }
+                return value;
+            }
+
+            function generateTemplateOutput() {
+                let container = $('.note-template-container:visible').first();
+                if(!container.length) return '';
+                let lines = [];
+                if(container.find('.note-template-set-chooser').length) {
+                    lines.push('<b>' + container.find('.note-template-set-chooser').first().find('option:selected').text() + '</b>');
+                }
+                else if(container.find('.note-exam-template-set-chooser').length && container.find('.note-exam-exam-chooser').length) {
+                    lines.push('<b>' +
+                        container.find('.note-exam-template-set-chooser').first().find('option:selected').text() +
+                        ': ' +
+                        container.find('.note-exam-exam-chooser').first().find('option:selected').text() +
+                        '</b>');
+                }
+                container.find('>.note-template-item.selected').each(function() {
+                    lines.push('<p class="note-template-output-line">' + generateOutputForNode($(this)) + '</p>');
+                });
+                $('.note-template-output-text:visible').first().html(lines.join(''));
+            }
+
+            addMCInitializer('note-single', init, '#note-single-header');
+        })();
+    </script>

+ 609 - 0
resources/views/app/patient/note/dashboard_script-bu-b4-pure-soap.blade.php

@@ -0,0 +1,609 @@
+<script>
+        (function() {
+
+            let numSectionsPendingInitialization = 0;
+
+            function init() {
+
+                // on note-section hover, highlight the according left-tree node(s)
+                $(document)
+                    .off('mouseenter', '.note-section')
+                    .on('mouseenter', '.note-section', function(){
+                        $('.note-tree-node').removeClass('hovered');
+                        let target = $('.note-tree-node a[data-segment-uid="' + $(this).attr('data-segment-uid') + '"]');
+                        target.parent().addClass('hovered');
+                        target.parent().parents('.note-tree-node').addClass('hovered');
+                        return false;
+                    });
+
+                $(document)
+                    .off('mouseenter', '[data-non-segment-section]')
+                    .on('mouseenter', '[data-non-segment-section]', function(){
+                        $('.note-tree-node').removeClass('hovered');
+                        let target = $('.note-tree-node a[data-non-segment-target="' + $(this).attr('data-non-segment-section') + '"]');
+                        target.parent().addClass('hovered');
+                        target.parent().parents('.note-tree-node').addClass('hovered');
+                        return false;
+                    });
+
+                $(document)
+                    .off('mouseleave', '.note-section')
+                    .on('mouseleave', '.note-section', () => {
+                        $('.note-tree-node').removeClass('hovered');
+                        return false;
+                    });
+
+                // print note
+                $(document)
+                    .off('click.print', '.print-note')
+                    .on('click.print', '.print-note', () => {
+                        window.print();
+                        return false;
+                    });
+                $('.print-note').removeClass('invisible');
+
+                $('.note-method-select').change(function() {
+                    let form = $(this).closest('form');
+                    if(this.value === 'IN_CLINIC') {
+                        form.find('.if-in-clinic').show();
+                    }
+                    else {
+                        form.find('.if-in-clinic').hide();
+                    }
+                });
+
+                $('.note-method-select').each(function() {
+                    let form = $(this).closest('form');
+                    if(this.value === 'IN_CLINIC') {
+                        form.find('.if-in-clinic').show();
+                    }
+                    else {
+                        form.find('.if-in-clinic').hide();
+                    }
+                });
+
+                $('textarea[rte]').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 ti = $('<input type="hidden" />')
+                        .val(this.value)
+                        .attr('name', this.name)
+                        .insertBefore(this);
+                    var ce = $('<div data-editor-id="' + editorID + '" data-field="' + this.name + '"/>')
+                        .html(this.value)
+                        .insertBefore(this);
+                    $(this).remove();
+
+                    var qe = new Quill('[data-editor-id="' + editorID + '"]', {
+                        theme: 'snow',
+                        modules: stagQuillConfig
+                    });
+                    var toolbar = $(qe.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);
+
+                    qe.on('text-change', function() {
+                        ti.val(qe.root.innerHTML);
+                    });
+
+                    $(qe.container)
+                        .find('.ql-editor[contenteditable]')
+                            .attr('data-field', fieldName)
+                            .attr('data-editor-id', editorID)
+                            .attr('with-shortcuts', 1);
+
+                });
+
+                $(document)
+                    .off('click.edit-trigger', '.edit-trigger:not(.edit)')
+                    .on('click.edit-trigger', '.edit-trigger:not(.edit)', function() {
+
+                        if($('.note-section>.stag-popup:visible').length) return;
+
+                        let editParent = $(this).closest('.note-section');
+
+                        // TEMP: disable edit mode for medrisk_vigilance
+                        // TODO: do this in the proper place
+                        if(editParent.is('[data-segment-template-name="medrisk_vigilence"]')) return false;
+
+                        // TEMP: show wizard for allergies, rx, dx, goals
+                        if(editParent.is('[data-segment-template-name="plan_allergies"]') ||
+                            editParent.is('[data-segment-template-name="intake_allergies"]')) {
+                            $('.note-bottom-toolbar .allergies-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_problems"]') ||
+                            editParent.is('[data-segment-template-name="intake_problems"]')) {
+                            $('.note-bottom-toolbar .problems-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_medications"]') ||
+                            editParent.is('[data-segment-template-name="intake_medications"]')) {
+                            $('.note-bottom-toolbar .medications-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_goals"]') ||
+                            editParent.is('[data-segment-template-name="intake_goals"]')) {
+                            $('.note-bottom-toolbar .goals-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_care_team"]') ||
+                            editParent.is('[data-segment-template-name="intake_care_team"]')) {
+                            $('.note-bottom-toolbar .careteam-center-trigger').trigger('click');
+                            return false;
+                        }
+                        else if(editParent.is('[data-segment-template-name="plan_supplements"]') ||
+                            editParent.is('[data-segment-template-name="intake_supplements"]')) {
+                            $('.note-bottom-toolbar .supplements-center-trigger').trigger('click');
+                            return false;
+                        }
+
+                        // TEMP: open in popup if LS segment
+                        if(editParent.is('[data-segment-template-name^="lifestyle_"]')) {
+                            showStagPopup('segment-popup-' + editParent.attr('data-segment-template-name'), true);
+                            return false;
+                        }
+
+                        if(editParent.is('[data-segment-template-name="plan_nutrition"]') ||
+                            editParent.is('[data-segment-template-name="intake_nutrition"]')) {
+                            openDynamicStagPopup('/nutrition-center/{{$note->client->uid}}/{{$note->uid}}',
+                                'nutrition-center-{{$note->id}}',
+                                '<img src="/img/nutrition-rx.png" class=""/> Nutrition Rx',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+
+                        if(editParent.is('[data-segment-template-name="plan_exercise"]') ||
+                            editParent.is('[data-segment-template-name="intake_exercise"]')) {
+                            openDynamicStagPopup('/exercise-center/{{$note->client->uid}}/{{$note->uid}}',
+                                'exercise-center-{{$note->id}}',
+                                '<img src="/img/exercise-rx.png" class=""/> Exercise Rx',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+
+                        if(editParent.is('[data-segment-template-name="plan_behavior"]') ||
+                            editParent.is('[data-segment-template-name="intake_behavior"]')) {
+                            openDynamicStagPopup('/behavior-center/{{$note->client->uid}}/{{$note->uid}}',
+                                'behavior-center-{{$note->id}}',
+                                '<img src="/img/behavior-rx.png" class=""/> Behavior Rx',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+
+                        <?php
+                        $rosSegment = $note->getSegmentByInternalName('ros');
+                        ?>
+                        @if($rosSegment)
+                        if(editParent.is('[data-segment-template-name="ros"]')) {
+                            openDynamicStagPopup('/note-segment-view/{{$note->client->uid}}/{{$note->uid}}/{{$rosSegment->uid}}/ros/edit',
+                                'init-ros-{{$note->id}}',
+                                'Review of Systems',
+                                false,
+                                "medium-large overflow-visible");
+                            return false;
+                        }
+                        @endif
+
+                        // OPEN popup for if note-segment-view exists
+                        if($('.' + editParent.attr('data-segment-template-name') + '-trigger').length) {
+                            $('.' + editParent.attr('data-segment-template-name') + '-trigger').trigger('click');
+                            return false;
+                        }
+
+                        if(editParent.is('.edit')) {
+                            editParent.removeClass('edit');
+                        }
+                        else {
+                            let docRoot = $('html');
+                            let prevEffectiveTop = editParent.offset().top - docRoot.scrollTop();
+                            $('.note-section.edit').removeClass('edit');
+                            editParent.addClass('edit');
+                            let newEffectiveTop = editParent.offset().top - docRoot.scrollTop();
+                            if(newEffectiveTop < prevEffectiveTop) {
+                                docRoot.scrollTop(docRoot.scrollTop() - (prevEffectiveTop - newEffectiveTop));
+                            }
+                        }
+
+                        let visitTreeLink = $('.note-tree-node a[data-segment-internal-name="' + editParent.attr('data-segment-template-name') + '"]');
+                        if(visitTreeLink.length) {
+                            $('.note-tree-node.active').removeClass('active');
+                            visitTreeLink.closest('.note-tree-node').addClass('active');
+                        }
+
+                        return false;
+                    });
+
+                $('.note-templates-trigger')
+                    .off('click.note-templates-trigger')
+                    .on('click.note-templates-trigger', function() {
+                        $('.note-templates-underlay').show();
+                        let container = $(this).closest('.note-section').find('.note-template-container');
+                        container.find('.note-template-children').hide();
+                        container.find('.note-template-item.selected').removeClass('selected');
+                        container.find('.note-template-item[prefix]').removeAttr('prefix');
+                        container.find('input[type="checkbox"]').prop('checked', false);
+                        container.find('.note-template-output-text').empty();
+                        container.show();
+                        loadTemplateSet(container.find('.note-template-set-chooser'));
+                        loadExamTemplateSet(container.find('.note-exam-template-set-chooser'),
+                            container.find('.note-exam-exam-chooser').val(),
+                            container.find('.note-exam-template-set-chooser').val());
+                        return false;
+                    });
+
+                $(document)
+                    .off('click.note-templates-trigger-assessment', '.note-templates-trigger-assessment')
+                    .on('click.note-templates-trigger-assessment', '.note-templates-trigger-assessment', function() {
+                        $('.note-templates-underlay').show();
+                        let container = $(this).closest('.note-section').find('.note-template-container');
+                        container.find('.note-template-children').hide();
+                        container.find('.note-template-item.selected').removeClass('selected');
+                        container.find('.note-template-item[prefix]').removeAttr('prefix');
+                        container.find('input[type="checkbox"]').prop('checked', false);
+                        container.find('.note-template-output-text').empty();
+                        container.attr('data-editor-id', $(this).attr('data-editor-id'));
+                        container.show();
+                        container.css({
+                            left: ($(this).position().left - 140) + 'px',
+                            top: ($(this).position().top + 22) + 'px',
+                        });
+                        loadTemplateSet(container.find('.note-template-set-chooser'));
+                        loadExamTemplateSet(container.find('.note-exam-template-set-chooser'),
+                            container.find('.note-exam-exam-chooser').val(),
+                            container.find('.note-exam-template-set-chooser').val());
+                        return false;
+                    });
+
+                $(document)
+                    .off('click.note-templates-underlay', '.note-templates-underlay, .note-template-close-trigger')
+                    .on('click.note-templates-underlay', '.note-templates-underlay, .note-template-close-trigger', function() {
+                        $('.note-templates-underlay').hide();
+                         $('.note-template-container').hide();
+                    });
+
+                $(document)
+                    .off('click.note-template-label', '.note-template-item .label')
+                    .on('click.note-template-label', '.note-template-item .label', function() {
+                        let item = $(this).closest('.note-template-item');
+                        let isChecked = $(this).find('>input[type="checkbox"]').prop('checked');
+                        let hasChildren = !!item.find('>.note-template-children').length,
+                            childrenShown = item.find('>.note-template-children:visible').length;
+
+                        if(isChecked && hasChildren && !childrenShown) { // just show
+                            $('.note-template-children').hide();
+                            $(this).parents('.note-template-children').show();
+                            item.find('>.note-template-children').show()
+                                .find('>textarea,>input[type="number"],>input[type="date"]').first().focus();
+                            return false;
+                        }
+
+                        $(this).find('>input[type="checkbox"]').prop('checked', !isChecked);
+                        isChecked = !isChecked;
+                        if(isChecked) {
+                            item.addClass('selected');
+                        }
+                        else {
+                            item.removeClass('selected');
+                        }
+                        $('.note-template-children').hide();
+                        $(this).parents('.note-template-children').show();
+                        if(isChecked) {
+                            item.find('>.note-template-children')
+                                .show()
+                                .find('>textarea,>input[type="number"],>input[type="date"]')
+                                .first().focus();
+                        }
+
+                        generateTemplateOutput();
+
+                        return false;
+                    });
+
+                $(document)
+                    .off('mousedown.note-templates-apply', '.note-template-apply-trigger')
+                    .on('mousedown.note-templates-apply', '.note-template-apply-trigger', function() {
+                        let templateContainer = $('.note-template-container:visible').first();
+                        let result = $('.note-template-output-text:visible').first().html();
+                        $('.note-templates-underlay').hide();
+                        $('.note-template-container').hide();
+                        let editor = null;
+                        if($(this).closest('.assessment-detail-template').length) {
+                            editor  = $('.ql-editor[data-editor-id="' + templateContainer.attr('data-editor-id') + '"]:visible').first();
+                        }
+                        else {
+                            editor  = $('.ql-editor[contenteditable]:visible').first();
+                        }
+                        if(editor && editor.length) {
+                            result = $.trim(editor.text() !== '' ? editor.html() : '') + result;
+                            editor.html(result).focus();
+                        }
+                        return false;
+                    });
+
+                $(document)
+                    .off('input paste change', '.note-template-item textarea, .note-template-item input[type="number"], .note-template-item input[type="date"]')
+                    .on('input paste change', '.note-template-item textarea, .note-template-item input[type="number"], .note-template-item input[type="date"]', function() {
+                        generateTemplateOutput();
+                    });
+
+                $(document)
+                    .off('click.plus-trigger', '.note-template-item .plus-trigger')
+                    .on('click.plus-trigger', '.note-template-item .plus-trigger', function() {
+                        let item = $(this).closest('.note-template-item');
+                        if(item.attr('prefix') === '(+)') {
+                            item.removeAttr('prefix');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', false);
+                            item.removeClass('selected');
+                        }
+                        else {
+                            item.attr('prefix', '(+)');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', true);
+                            item.addClass('selected');
+                        }
+                        generateTemplateOutput();
+                        return false;
+                    });
+
+                $(document)
+                    .off('click.minus-trigger', '.note-template-item .minus-trigger')
+                    .on('click.minus-trigger', '.note-template-item .minus-trigger', function() {
+                        let item = $(this).closest('.note-template-item');
+                        if(item.attr('prefix') === '(-)') {
+                            item.removeAttr('prefix');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', false);
+                            item.removeClass('selected');
+                        }
+                        else {
+                            item.attr('prefix', '(-)');
+                            item.find('>.note-template-text>.label>input[type="checkbox"]').prop('checked', true);
+                            item.addClass('selected');
+                        }
+                        generateTemplateOutput();
+                        return false;
+                    });
+
+                $(document)
+                    .off('change.note-template-set-chooser', '.note-template-set-chooser')
+                    .on('change.note-template-set-chooser', '.note-template-set-chooser', function() {
+                        return loadTemplateSet($(this));
+                    });
+
+                $(document)
+                    .off('change.note-exam-template-set-chooser', '.note-exam-template-set-chooser')
+                    .on('change.note-exam-template-set-chooser', '.note-exam-template-set-chooser', function() {
+                        $(this).closest('.note-template-container')
+                            .find('.note-exam-exam-chooser')
+                                .val($(this).find('option:selected').attr('exam'));
+                        return loadExamTemplateSet($(this),
+                            $(this).closest('.note-template-container').find('.note-exam-exam-chooser').first().val(),
+                            $(this).val());
+                    });
+
+                $(document)
+                    .off('change.note-exam-exam-chooser', '.note-exam-exam-chooser')
+                    .on('change.note-exam-exam-chooser', '.note-exam-exam-chooser', function() {
+                        return loadExamTemplateSet($(this),
+                            $(this).val(),
+                            $(this).closest('.note-template-container').find('.note-exam-template-set-chooser').first().val());
+                    });
+
+                $('.remove-section-trigger').click(function() {
+                    $.post('/api/section/deactivate', {
+                        uid: $(this).attr('data-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');
+                    // $(this).closest('.note-section').removeClass('edit');
+                    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) {
+                        if($(this).closest('.note-signed-by-hcp').length) return;
+                        e.stopPropagation();
+                        e.preventDefault();
+                        $(this).find('.edit-trigger').first().click();
+                        return false;
+                    });
+                @endif
+
+                $(document)
+                    .off('keydown.collapse-active-segment')
+                    .on('keydown.collapse-active-segment', function(e) {
+                        if(e.which === 27) {
+                            if(!isEventConsumed(e)) {
+                                if($('.visit-segment.edit').length) {
+                                    $('.visit-segment.edit').first().find('.edit-trigger').first().click();
+                                    markEventAsConsumed(e);
+                                    return false;
+                                }
+                            }
+                            else {
+                                // event already consumed!
+                            }
+                        }
+                    });
+
+                scrollToLatest();
+
+                function __moveSection(_uid, _direction) {
+                    $.post('/api/section/move' + _direction, {
+                        uid: _uid
+                    }, function(_data) {
+                        if(_data && _data.success) {
+                            fastReload();
+                        }
+                        else {
+                            if(_data) {
+                                toastr.error(_data.message);
+                            }
+                            else {
+                                toastr.error('Unknown error while moving section');
+                            }
+                        }
+                    }, 'json')
+                }
+
+                $('.move-up-trigger').click(function() {
+                    __moveSection($(this).attr('data-uid'), 'Up');
+                });
+
+                $('.move-down-trigger').click(function() {
+                    __moveSection($(this).attr('data-uid'), 'Down');
+                });
+
+                // refresh once ticket popup is closed
+                /*$('body').off('stag-popup-closed')
+                $('body').on('stag-popup-closed', function() {
+                    if($('#note-single-header').length) {
+                        fastReload();
+                    }
+                });*/
+                // ticket-popup
+                $(document)
+                    .off('click', '.ticket-popup-trigger.note-dashboard-action')
+                    .on('click', '.ticket-popup-trigger.note-dashboard-action', function() {
+                        showMask();
+                        window.noMc = true;
+                        $.get(this.href, (_data) => {
+
+                            if(!$('.ticket-popup').length) {
+                                $('main.stag-content').append('<div class="stag-popup stag-popup-lg ticket-popup mcp-theme-1" stag-popup-key="ticket-popup"></div>');
+                            }
+
+                            $('.ticket-popup').html(_data);
+                            showStagPopup('ticket-popup', true);
+                            $('.ticket-popup .stag-popup.stag-slide').attr('close-all-with-self', 1);
+                            runMCInitializer('patient-tickets'); // run specific mc initer
+                            hideMask();
+                        });
+                        return false;
+                    });
+
+            }
+
+            // scroll to latest created section
+            function scrollToLatest() {
+                window.setTimeout(function() {
+                    let latestSectionTS = $('.latest-section-ts');
+                    if(latestSectionTS.length) {
+                        let latestSection = $('.note-section[data-ts="' + latestSectionTS.text() + '"]');
+                        if(latestSection.length) {
+                            latestSection[0].scrollIntoView({behavior: "smooth", block: "center"});
+                            // latestSection.find('.edit-trigger').first().click();
+                            console.log('DONE!');
+                        }
+                    }
+                }, 100);
+            }
+
+            function loadTemplateSet(_chooser) {
+                if(!_chooser.length || !_chooser.val()) return false;
+                let container = _chooser.closest('.note-template-container');
+                container.find('>.note-template-item').remove();
+                container.find('.please-wait').remove();
+                container.append('<p class="please-wait my-2 text-secondary text-center">Please wait ...</p>');
+                $.get('/note-template-set/' + _chooser.attr('data-section') + '/' + _chooser.val(), function(_html) {
+                    container.find('.please-wait').remove();
+                    container.append(_html);
+                });
+                return false;
+            }
+
+            function loadExamTemplateSet(_chooser, _exam, _templateSet) {
+                if(!_chooser.length || !_chooser.val()) return false;
+                let container = _chooser.closest('.note-template-container');
+                container.find('>.note-template-item').remove();
+                container.find('.please-wait').remove();
+                container.append('<p class="please-wait my-2 text-secondary text-center">Please wait ...</p>');
+                $.get('/note-template-set/exam/' + _exam + '/' + _templateSet, function(_html) {
+                    container.find('.please-wait').remove();
+                    container.append(_html);
+                });
+                return false;
+            }
+
+            function generateOutputForNode(_node) {
+                let template = (_node.attr('prefix') ? _node.attr('prefix') : '') + _node.attr('template'),
+                    value = template;
+                let hasChildText = !!_node.find('>.note-template-children>textarea,>.note-template-children>input[type="number"],>.note-template-children>input[type="date"]').length;
+                let hasChildren = !!_node.find('>.note-template-children>.note-template-item').length;
+                if(hasChildText) {
+                    value = value.replace('{text}',
+                        _node
+                            .find('>.note-template-children')
+                                .find('>textarea,>input[type="number"],>input[type="date"]').first().val());
+                }
+                else if(hasChildren) {
+                    let values = [];
+                    _node.find('>.note-template-children>.note-template-item.selected').each(function() {
+                        values.push(generateOutputForNode($(this)));
+                    });
+                    let combined = '';
+                    for (let i = 0; i < values.length; i++) {
+                        combined += values[i];
+                        if(values.length > 1 && i <= values.length - 2) {
+                            if(i === values.length - 2) {
+                                combined += ' and ';
+                            }
+                            else {
+                                combined += ', ';
+                            }
+                        }
+                    }
+                    value = value.replace('{children}', ' ' + combined).replace('{text}', ' ' + combined);
+                }
+                return value;
+            }
+
+            function generateTemplateOutput() {
+                let container = $('.note-template-container:visible').first();
+                if(!container.length) return '';
+                let lines = [];
+                if(container.find('.note-template-set-chooser').length) {
+                    lines.push('<b>' + container.find('.note-template-set-chooser').first().find('option:selected').text() + '</b>');
+                }
+                else if(container.find('.note-exam-template-set-chooser').length && container.find('.note-exam-exam-chooser').length) {
+                    lines.push('<b>' +
+                        container.find('.note-exam-template-set-chooser').first().find('option:selected').text() +
+                        ': ' +
+                        container.find('.note-exam-exam-chooser').first().find('option:selected').text() +
+                        '</b>');
+                }
+                container.find('>.note-template-item.selected').each(function() {
+                    lines.push('<p class="note-template-output-line">' + generateOutputForNode($(this)) + '</p>');
+                });
+                $('.note-template-output-text:visible').first().html(lines.join(''));
+            }
+
+            addMCInitializer('note-single', init, '#note-single-header');
+        })();
+    </script>

+ 16 - 8
resources/views/app/patient/note/dashboard_script.blade.php

@@ -119,27 +119,32 @@
 
                         // TEMP: show wizard for allergies, rx, dx, goals
                         if(editParent.is('[data-segment-template-name="plan_allergies"]') ||
-                            editParent.is('[data-segment-template-name="intake_allergies"]')) {
+                            editParent.is('[data-segment-template-name="intake_allergies"]') ||
+                            editParent.is('[data-segment-template-name="allergies"]')) {
                             $('.note-bottom-toolbar .allergies-center-trigger').trigger('click');
                             return false;
                         }
                         else if(editParent.is('[data-segment-template-name="plan_problems"]') ||
-                            editParent.is('[data-segment-template-name="intake_problems"]')) {
+                            editParent.is('[data-segment-template-name="intake_problems"]') ||
+                            editParent.is('[data-segment-template-name="problems"]')) {
                             $('.note-bottom-toolbar .problems-center-trigger').trigger('click');
                             return false;
                         }
                         else if(editParent.is('[data-segment-template-name="plan_medications"]') ||
-                            editParent.is('[data-segment-template-name="intake_medications"]')) {
+                            editParent.is('[data-segment-template-name="intake_medications"]') ||
+                            editParent.is('[data-segment-template-name="medications"]')) {
                             $('.note-bottom-toolbar .medications-center-trigger').trigger('click');
                             return false;
                         }
                         else if(editParent.is('[data-segment-template-name="plan_goals"]') ||
-                            editParent.is('[data-segment-template-name="intake_goals"]')) {
+                            editParent.is('[data-segment-template-name="intake_goals"]') ||
+                            editParent.is('[data-segment-template-name="goals"]')) {
                             $('.note-bottom-toolbar .goals-center-trigger').trigger('click');
                             return false;
                         }
                         else if(editParent.is('[data-segment-template-name="plan_care_team"]') ||
-                            editParent.is('[data-segment-template-name="intake_care_team"]')) {
+                            editParent.is('[data-segment-template-name="intake_care_team"]') ||
+                            editParent.is('[data-segment-template-name="care_team"]')) {
                             $('.note-bottom-toolbar .careteam-center-trigger').trigger('click');
                             return false;
                         }
@@ -156,7 +161,8 @@
                         }
 
                         if(editParent.is('[data-segment-template-name="plan_nutrition"]') ||
-                            editParent.is('[data-segment-template-name="intake_nutrition"]')) {
+                            editParent.is('[data-segment-template-name="intake_nutrition"]') ||
+                            editParent.is('[data-segment-template-name="nutrition"]')) {
                             openDynamicStagPopup('/nutrition-center/{{$note->client->uid}}/{{$note->uid}}',
                                 'nutrition-center-{{$note->id}}',
                                 '<img src="/img/nutrition-rx.png" class=""/> Nutrition Rx',
@@ -166,7 +172,8 @@
                         }
 
                         if(editParent.is('[data-segment-template-name="plan_exercise"]') ||
-                            editParent.is('[data-segment-template-name="intake_exercise"]')) {
+                            editParent.is('[data-segment-template-name="intake_exercise"]') ||
+                            editParent.is('[data-segment-template-name="exercise"]')) {
                             openDynamicStagPopup('/exercise-center/{{$note->client->uid}}/{{$note->uid}}',
                                 'exercise-center-{{$note->id}}',
                                 '<img src="/img/exercise-rx.png" class=""/> Exercise Rx',
@@ -176,7 +183,8 @@
                         }
 
                         if(editParent.is('[data-segment-template-name="plan_behavior"]') ||
-                            editParent.is('[data-segment-template-name="intake_behavior"]')) {
+                            editParent.is('[data-segment-template-name="intake_behavior"]') ||
+                            editParent.is('[data-segment-template-name="behavior"]')) {
                             openDynamicStagPopup('/behavior-center/{{$note->client->uid}}/{{$note->uid}}',
                                 'behavior-center-{{$note->id}}',
                                 '<img src="/img/behavior-rx.png" class=""/> Behavior Rx',

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

@@ -0,0 +1,37 @@
+<div class="segments-list" id="note-rhs-segments-list">
+    <?php
+    $previousHeading = null;
+    $previousSubHeading = null;
+    ?>
+    @foreach($note->segments as $segment)
+        @if(in_array($segment->segmentTemplate->internal_name, config('app.note_rhs_segments')))
+        <?php
+        if ($segment->heading !== $previousHeading) {
+            if (!empty($previousHeading)) {
+                echo '</div></div>'; // <!-- end the previous parent section -->
+            }
+            if (!empty($segment->heading)) {
+
+	?>
+	<div class="note-content-node note-content-heading">
+		<div class="py-2 px-3 border-bottom font-size-16 font-weight-bold bg-light text-secondary {{ $previousHeading ? 'mt-4 border-top' : '' }}">
+			{{ $segment->heading }}
+		</div>
+		<div class="note-content-children ml-5 border-left">
+			<!-- open new node -->
+        <?php
+	    }
+            $previousHeading = $segment->heading;
+        }
+        ?>
+        <div>
+            @include('app.patient.note.segment')
+        </div>
+        @endif
+    @endforeach
+    <?php
+    if (!empty($previousHeading)) {
+        echo '</div></div>'; // <!-- close any open parent section -->
+    }
+    ?>
+</div>

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

@@ -23,9 +23,15 @@
             $previousHeading = $segment->heading;
         }
         ?>
-        <div class="{{$segment->segmentTemplate->internal_name === 'medrisk_vigilence' ? 'd-none' : ''}}">
-            @include('app.patient.note.segment')
-        </div>
+		@if($note->visitTemplate->internal_name !== 'soap_visit')
+			<div class="{{$segment->segmentTemplate->internal_name === 'medrisk_vigilence' ? 'd-none' : ''}}">
+				@include('app.patient.note.segment')
+			</div>
+		@else
+			<div class="{{in_array($segment->segmentTemplate->internal_name, config('app.note_lhs_segments')) ? '' : 'd-none'}}">
+				@include('app.patient.note.segment')
+			</div>
+		@endif
     @endforeach
     <?php
     if (!empty($previousHeading)) {

+ 1 - 1
resources/views/app/patient/note/rhs-sidebar.blade.php

@@ -1,4 +1,4 @@
-<div class="note-rhs-sidebar border-left" id="note-rhs-sidebar">
+<div class="note-rhs-sidebar {{$note->visitTemplate && $note->visitTemplate->internal_name === 'soap_visit' ? '' : 'border-left'}}" id="note-rhs-sidebar">
     <?php
     $allergies = \App\Models\Point::getPointsOfCategory($patient, "ALLERGY");
     $medications = \App\Models\Point::getPointsOfCategory($patient, "MEDICATION");

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


+ 82 - 0
resources/views/app/patient/segment-templates/allergies/summary.blade.php

@@ -0,0 +1,82 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$points = Point::getUnifiedPointsOfCategory($patient, 'ALLERGY', $note);
+$tracker = Point::getGlobalSingletonOfCategory($patient, 'NO_KNOWN_TRACKER');
+$numRelevant = 0;
+$numVisible = 0;
+$plural = 'Allergies';
+?>
+
+<?php if($tracker && @($tracker->data->no_known_drug_allergies)): ?>
+    <div class="text-secondary mb-2"><span>-</span></div>
+<?php endif; ?>
+<?php if($tracker && @($tracker->data->no_known_allergies_of_any_type)): ?>
+    <div class="text-secondary mb-2"><span>-</span></div>
+<?php endif; ?>
+
+<?php if(!$tracker || !@($tracker->data->no_known_allergies_of_any_type)): ?>
+<?php if (!count($points)): ?>
+    <div class="text-secondary">-</div>
+<?php else: ?>
+    <table class="table table-bordered table-xs table-cage mb-0">
+    <?php $j = 0; foreach ($points as $point): $j++; ?>
+        <?php if($point->is_removed && $point->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $point->relevanceToNote($note); ?>
+        <?php $plan = $point->lastChildPlan; ?>
+        <?php if($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+        <?php $numVisible++; ?>
+        <tr>
+            <td class="width-40px px-2 {{ $rel ? 'font-weight-bold text-info':'' }}">
+                @if($rel)
+                    <?php $numRelevant++; ?>
+                    {{ $j }}.*
+                @else
+                    {{ $j }}.
+                @endif
+            </td>
+            <td class="px-2 width-300px">
+                <div class="<?= $point->is_removed ? 'strike-through' : '' ?>">
+                    <b><?= !!@($point->data->name) ? @($point->data->name) : '-' ?></b>
+                </div>
+            </td>
+            <td class="px-2 width-300px">
+                <div>
+                    <?php if(!!$plan): ?>
+                        <div class="pl-3 mt-1 d-flex align-items-baseline">
+                            <span>{!! $plan->data->value !!}</span>
+                        </div>
+                    <?php elseif($rel): ?>
+                        <div class="relevant-without-plan text-warning-mellow text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+                    <?php endif; ?>
+                </div>
+                <div class="d-flex align-items-baseline">
+                    <?php if ($point->is_removed): ?>
+                        @if($point->removal_reason_category === 'DURING_VISIT')
+                            <span class="ml-2 text-sm text-secondary">Removed during visit</span>
+                        @elseif($point->removal_reason_category === 'ON_INTAKE')
+                            <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+                        @endif
+                    <?php elseif ($point->added_in_note_id === $note->id): ?>
+                        <?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
+                            <span class="ml-2 text-sm text-success">* Diagnosed during visit</span>
+                        <?php else: ?>
+                            <span class="ml-2 text-sm text-info">* Added on intake</span>
+                        <?php endif;?>
+                    <?php endif; ?>
+                </div>
+            </td>
+            <td></td>
+        </tr>
+    <?php endforeach; ?>
+    </table>
+    @if(!$numVisible)
+        <div class="d-flex align-items-baseline mr-1">
+            <span class="text-secondary">-</span>
+        </div>
+    @endif
+<?php endif; ?>
+<?php endif; ?>

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

@@ -0,0 +1,4 @@
+<?php
+$category = 'ASSESSMENT_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/assessment_free_text/summary.blade.php

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

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


+ 41 - 0
resources/views/app/patient/segment-templates/behavior/summary.blade.php

@@ -0,0 +1,41 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$selfMonitoring = Point::getOnlyPointOfCategory($patient, 'SELF_MONITORING');
+$foodTriggers = Point::getOnlyPointOfCategory($patient, 'FOOD_TRIGGERS');
+$cravings = Point::getOnlyPointOfCategory($patient, 'CRAVINGS');
+$sleepHabits = Point::getOnlyPointOfCategory($patient, 'SLEEP_HABITS');
+
+$points = [
+    ["category" => 'SELF_MONITORING', "name" => 'Self Monitoring', "point" => $selfMonitoring],
+    ["category" => 'FOOD_TRIGGERS', "name" => 'Food Triggers', "point" => $foodTriggers],
+    ["category" => 'CRAVINGS', "name" => 'Cravings', "point" => $cravings],
+    ["category" => 'SLEEP_HABITS', "name" => 'Sleep Habits', "point" => $sleepHabits],
+];
+?>
+<table class="table table-bordered table-sm mb-0 table-cage">
+    <?php foreach ($points as $p): ?>
+    <?php $point = $p['point']; ?>
+    <?php if(!!$point): ?>
+    <?php $plan = $point->lastChildPlan; ?>
+    <?php if ($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+    <tr>
+        <td class="width-300px">
+            <?= $p['name'] ?>
+        </td>
+        <td class="width-300px">
+            <?php if(!!$plan): ?>
+            <div class="ml-3 inline-html-container">
+                <?php $plan = $plan->data; ?>
+                <?php include(resource_path('views/app/patient/segment-templates/_child_plan/behavior/' . $p['category'] . '/view-plan.php')); ?>
+            </div>
+            <?php endif; ?>
+        </td>
+        <td></td>
+    </tr>
+    <?php endif; ?>
+    <?php endforeach; ?>
+</table>

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


+ 77 - 0
resources/views/app/patient/segment-templates/care_team/summary.blade.php

@@ -0,0 +1,77 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$points = Point::getUnifiedPointsOfCategory($patient, 'CARE_TEAM_MEMBER', $note);
+$numRelevant = 0;
+$numVisible = 0;
+$plural = 'Care team members';
+?>
+
+<?php if (!count($points)): ?>
+    <div class="text-secondary">-</div>
+<?php else: ?>
+    <table class="table table-bordered table-xs table-cage mb-0">
+    <?php $j = 0; foreach ($points as $point): $j++; ?>
+        <?php if($point->is_removed && $point->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $point->relevanceToNote($note); ?>
+        <?php $plan = $point->lastChildPlan; ?>
+        <?php if($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+        <?php $numVisible++; ?>
+        <tr>
+            <td class="width-40px px-2 {{ $rel ? 'font-weight-bold text-info':'' }}">
+                @if($rel)
+                    <?php $numRelevant++; ?>
+                    {{ $j }}.*
+                @else
+                    {{ $j }}.
+                @endif
+            </td>
+            <td class="px-2 width-300px">
+                <div class="<?= $point->is_removed ? 'strike-through' : '' ?>">
+                    <b><?= !!@($point->data->name) ? @($point->data->name) : '-' ?></b>
+                    <?= !!@($point->data->specialty) ? '/&nbsp;' . @($point->data->specialty) . '' : '' ?>
+                    <?= !!@($point->data->organization) ? '/&nbsp;' . @($point->data->organization) . '' : '' ?><br>
+                    <?= !!@($point->data->phone) ? 'Ph: ' . @($point->data->phone) . '' : '' ?>
+                    <?= !!@($point->data->fax) ? '&nbsp;/&nbsp;Fax: ' . @($point->data->fax) . '<br>' : '' ?>
+                    <?= !!@($point->data->date) ? '&nbsp;/&nbsp;Date: ' . @($point->data->date) : '' ?>
+                </div>
+            </td>
+            <td class="px-2 width-300px">
+                <div class="pl-3">
+                    <?php if(!!$plan): ?>
+                        <div class="mt-1 d-flex align-items-baseline">
+                            <span>{!! $plan->data->value !!}</span>
+                        </div>
+                    <?php elseif($rel): ?>
+                        <div class="relevant-without-plan text-warning-mellow text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+                    <?php endif; ?>
+                </div>
+                <div class="pl-3 d-flex align-items-baseline">
+                    <?php if ($point->is_removed): ?>
+                        @if($point->removal_reason_category === 'DURING_VISIT')
+                            <span class="mt-1 text-sm text-secondary">Removed during visit</span>
+                        @elseif($point->removal_reason_category === 'ON_INTAKE')
+                            <span class="mt-1 text-sm text-secondary">Removed on intake</span>
+                        @endif
+                    <?php elseif ($point->added_in_note_id === $note->id): ?>
+                        <?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
+                            <span class="mt-1 text-sm text-success">* Added during visit</span>
+                        <?php else: ?>
+                            <span class="mt-1 text-sm text-info">* Added on intake</span>
+                        <?php endif;?>
+                    <?php endif; ?>
+                </div>
+            </td>
+            <td></td>
+        </tr>
+    <?php endforeach; ?>
+    </table>
+    @if(!$numVisible)
+        <div class="d-flex align-items-baseline mr-1">
+            <span class="text-secondary">-</span>
+        </div>
+    @endif
+<?php endif; ?>

+ 27 - 0
resources/views/app/patient/segment-templates/disclaimers/edit.blade.php

@@ -24,6 +24,13 @@ if (!!@$point->data) {
         <input type="hidden" name="category" value="<?= $category ?>">
         <input type="hidden" name="data" value="{{json_encode($contentData)}}">
 
+        <label class="d-flex align-items-baseline mb-2">
+            <div class="mr-2 align-self-stretch" style="padding-top: 2px;">
+                <input type="checkbox" class="chk-disclaimers-check-all" onchange="$(this).closest('form').find(':checkbox[data-name]').prop('checked', this.checked)">
+            </div>
+            <span class="font-weight-bold">Check ALL</span>
+        </label>
+
         <label class="d-flex align-items-baseline mb-2">
             <div class="mr-2 align-self-stretch" style="padding-top: 2px;">
                 <input type="checkbox" data-name="consent_for_telehealth_visit" {{@($contentData["consent_for_telehealth_visit"] ? 'checked' : '')}}>
@@ -142,8 +149,10 @@ if (!!@$point->data) {
         @if($note->method == 'AUDIO' || $note->method == 'VIDEO')
             <p class="mb-2">The visit was conducted with the use of an interactive <b>{{$note->method}}</b> telecommunications system that permits real time communication
                 between the patient and the provider. Patient consent for telehealth visit was obtained.</p>
+            <?php /*
             <p class="mb-2">Originating Site: <b>{{$note->hcpCompanyPro && $note->hcpCompanyPro->company ? $note->hcpCompanyPro->company->name : '-'}}</b></p>
             <p class="mb-2">Distant Site: <b>Patient Home</b></p>
+            */ ?>
         @endif
 
         <div class="pt-2">
@@ -158,3 +167,21 @@ if (!!@$point->data) {
         </div>
     </form>
 </div>
+
+<script>
+    (function() {
+        window.segmentInitializers.<?= !!@$segment ? $segment->segmentTemplate->internal_name : $segmentInternalName ?> = function () {
+            let parentSegment = $('[data-segment-template-name="<?= $segment->segmentTemplate->internal_name ?>"] ');
+            function __checkAll() {
+                parentSegment.find('.chk-disclaimers-check-all').prop('checked',
+                    parentSegment.find(':checkbox[data-name]').length === parentSegment.find(':checkbox[data-name]:checked').length);
+            }
+            parentSegment.find(':checkbox[data-name]')
+                .off('change.check-all-toggle')
+                .on('change.check-all-toggle', function() {
+                    __checkAll();
+                });
+            __checkAll();
+        };
+    }).call(window);
+</script>

+ 2 - 0
resources/views/app/patient/segment-templates/disclaimers/summary.blade.php

@@ -161,7 +161,9 @@ $erxs = \App\Models\Erx::where('client_id', $note->client->id)
 @if($note->method == 'AUDIO' || $note->method == 'VIDEO')
     <p class="mb-2">The visit was conducted with the use of an interactive <b>{{$note->method}}</b> telecommunications system that permits real time communication
         between the patient and the provider. Patient consent for telehealth visit was obtained.</p>
+    <?php /*
     <p class="mb-2">Originating Site: <b>{{$note->hcpCompanyPro && $note->hcpCompanyPro->company ? $note->hcpCompanyPro->company->name : '-'}}</b></p>
     <p class="mb-2">Distant Site: <b>Patient Home</b></p>
+    */ ?>
 @endif
 

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


+ 43 - 0
resources/views/app/patient/segment-templates/exercise/summary.blade.php

@@ -0,0 +1,43 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$aerobicActivity = Point::getOnlyPointOfCategory($patient, 'AEROBIC_ACTIVITY');
+$strengthTraining = Point::getOnlyPointOfCategory($patient, 'STRENGTH_TRAINING');
+$neat = Point::getOnlyPointOfCategory($patient, 'NEAT');
+
+$points = [
+    ["category" => 'AEROBIC_ACTIVITY', "name" => 'Aerobic Activity', "point" => $aerobicActivity],
+    ["category" => 'STRENGTH_TRAINING', "name" => 'Strength Training', "point" => $strengthTraining],
+    ["category" => 'NEAT', "name" => 'Non-Exercise Activity Time (NEAT)', "point" => $neat],
+];
+?>
+
+<?php if(!count($points)): ?>
+    <span>-</span>
+<?php endif ?>
+<table class="table table-bordered table-sm mb-0 table-cage">
+    <?php foreach ($points as $p): ?>
+    <?php $point = $p['point']; ?>
+    <?php if(!!$point): ?>
+    <?php $plan = $point->lastChildPlan; ?>
+    <?php if ($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+    <tr>
+        <td class="width-300px">
+            <?= $p['name'] ?>
+        </td>
+        <td class="width-300px">
+            <?php if(!!$plan): ?>
+            <div class="ml-3 inline-html-container">
+                <?php $plan = $plan->data; ?>
+                <?php include(resource_path('views/app/patient/segment-templates/_child_plan/exercise/' . $p['category'] . '/view-plan.php')); ?>
+            </div>
+            <?php endif; ?>
+        </td>
+        <td></td>
+    </tr>
+    <?php endif; ?>
+    <?php endforeach; ?>
+</table>

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


+ 72 - 0
resources/views/app/patient/segment-templates/goals/summary.blade.php

@@ -0,0 +1,72 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$points = Point::getUnifiedPointsOfCategory($patient, 'GOAL', $note);
+$numRelevant = 0;
+$numVisible = 0;
+$plural = 'Goals';
+?>
+
+<?php if (!count($points)): ?>
+    <div class="text-secondary">-</div>
+<?php else: ?>
+    <table class="table table-bordered table-xs table-cage mb-0">
+    <?php $j = 0; foreach ($points as $point): $j++; ?>
+        <?php if($point->is_removed && $point->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $point->relevanceToNote($note); ?>
+        <?php $plan = $point->lastChildPlan; ?>
+        <?php if($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+        <?php $numVisible++; ?>
+        <tr>
+            <td class="width-40px px-2 {{ $rel ? 'font-weight-bold text-info':'' }}">
+                @if($rel)
+                    <?php $numRelevant++; ?>
+                    {{ $j }}.*
+                @else
+                    {{ $j }}.
+                @endif
+            </td>
+            <td class="px-2 width-300px">
+                <div class="<?= $point->is_removed ? 'strike-through' : '' ?>">
+                    <b><?= !!@($point->data->goal) ? @($point->data->goal) : '-' ?></b>
+                </div>
+            </td>
+            <td class="px-2 width-300px">
+                <div>
+                    <?php if(!!$plan): ?>
+                        <div class="pl-3 mt-1 d-flex align-items-baseline">
+                            <span>{!! $plan->data->value !!}</span>
+                        </div>
+                    <?php elseif($rel): ?>
+                        <div class="relevant-without-plan text-warning-mellow text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+                    <?php endif; ?>
+                </div>
+                <div class="d-flex align-items-baseline">
+                    <?php if ($point->is_removed): ?>
+                        @if($point->removal_reason_category === 'DURING_VISIT')
+                            <span class="ml-2 text-sm text-secondary">Removed during visit</span>
+                        @elseif($point->removal_reason_category === 'ON_INTAKE')
+                            <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+                        @endif
+                    <?php elseif ($point->added_in_note_id === $note->id): ?>
+                        <?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
+                            <span class="ml-2 text-sm text-success">* Prescribed during visit</span>
+                        <?php else: ?>
+                            <span class="ml-2 text-sm text-info">* Added on intake</span>
+                        <?php endif;?>
+                    <?php endif; ?>
+                </div>
+            </td>
+            <td></td>
+        </tr>
+    <?php endforeach; ?>
+    </table>
+    @if(!$numVisible)
+        <div class="d-flex align-items-baseline mr-1">
+            <span class="text-secondary">-</span>
+        </div>
+    @endif
+<?php endif; ?>

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


+ 78 - 0
resources/views/app/patient/segment-templates/medications/summary.blade.php

@@ -0,0 +1,78 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$points = Point::getUnifiedPointsOfCategory($patient, 'MEDICATION', $note);
+$tracker = Point::getGlobalSingletonOfCategory($patient, 'NO_KNOWN_TRACKER');
+$numRelevant = 0;
+$numVisible = 0;
+$plural = 'Medications';
+?>
+
+<?php if($tracker && @($tracker->data->no_known_medications)): ?>
+    <div class="text-secondary"><span>-</span></div>
+<?php endif; ?>
+<?php if(!$tracker || !@($tracker->data->no_known_medications)): ?>
+<?php if (!count($points)): ?>
+    <div class="text-secondary">-</div>
+<?php else: ?>
+    <table class="table table-bordered table-xs table-cage mb-0">
+        <?php $j = 0; foreach ($points as $point): $j++; ?>
+        <?php if($point->is_removed && $point->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $point->relevanceToNote($note); ?>
+        <?php $plan = $point->lastChildPlan; ?>
+        <?php if($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+        <?php $numVisible++; ?>
+        <tr>
+            <td class="width-40px px-2 {{ $rel ? 'font-weight-bold text-info':'' }}">
+                @if($rel)
+                    <?php $numRelevant++; ?>
+                    {{ $j }}.*
+                @else
+                    {{ $j }}.
+                @endif
+            </td>
+            <td class="px-2 width-300px">
+                <div class="font-weight-bold <?= $point->is_removed ? 'strike-through' : '' ?>">
+                    <?= !!@($point->data->name) ? @($point->data->name) : '-' ?>
+                </div>
+            </td>
+            <td class="px-2 width-300px">
+                <div>
+                    <?php if(!!$plan): ?>
+                    <div class="pl-3 mt-1 d-flex align-items-baseline">
+                        <span>{!! $plan->data->value !!}</span>
+                    </div>
+                    <?php elseif($rel): ?>
+                    <div class="relevant-without-plan text-warning-mellow text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+                    <?php endif; ?>
+                </div>
+                <div class="d-flex align-items-baseline">                
+                    <?php if ($point->is_removed): ?>
+                        @if($point->removal_reason_category === 'DURING_VISIT')
+                            <span class="ml-2 text-sm text-secondary">Removed during visit</span>
+                        @elseif($point->removal_reason_category === 'ON_INTAKE')
+                            <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+                        @endif
+                    <?php elseif ($point->added_in_note_id === $note->id): ?>
+                        <?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
+                            <span class="ml-2 text-sm text-success">* Prescribed during visit</span>
+                        <?php else: ?>
+                            <span class="ml-2 text-sm text-info">* Added on intake</span>
+                        <?php endif;?>
+                    <?php endif; ?>
+                </div>
+            </td>
+            <td></td>
+        </tr>
+    <?php endforeach; ?>
+    </table>
+    @if(!$numVisible)
+        <div class="d-flex align-items-baseline mr-1">
+            <span class="text-secondary">-</span>
+        </div>
+    @endif
+<?php endif; ?>
+<?php endif; ?>

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


+ 52 - 0
resources/views/app/patient/segment-templates/nutrition/summary.blade.php

@@ -0,0 +1,52 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$highSugarBeverages = Point::getOnlyPointOfCategory($patient, 'HIGH_SUGAR_BEVERAGES');
+$waterIntake = Point::getOnlyPointOfCategory($patient, 'WATER_INTAKE');
+$fastFood = Point::getOnlyPointOfCategory($patient, 'FAST_FOOD');
+$snacks = Point::getOnlyPointOfCategory($patient, 'SNACKS');
+$vegetables = Point::getOnlyPointOfCategory($patient, 'VEGETABLES');
+$portionSizes = Point::getOnlyPointOfCategory($patient, 'PORTION_SIZES');
+$dailyIntakeCarbohydrates = Point::getOnlyPointOfCategory($patient, 'DAILY_INTAKE_CARBOHYDRATES');
+$dailyIntakeCalories = Point::getOnlyPointOfCategory($patient, 'DAILY_INTAKE_CALORIES');
+
+$points = [
+    ["category" => 'HIGH_SUGAR_BEVERAGES', "name" => 'High Sugar Beverages', "point" => $highSugarBeverages],
+    ["category" => 'WATER_INTAKE', "name" => 'Water Intake', "point" => $waterIntake],
+    ["category" => 'FAST_FOOD', "name" => 'Fast Food', "point" => $fastFood],
+    ["category" => 'SNACKS', "name" => 'Snacks', "point" => $snacks],
+    ["category" => 'VEGETABLES', "name" => 'Vegetables', "point" => $vegetables],
+    ["category" => 'PORTION_SIZES', "name" => 'Portion Sizes', "point" => $portionSizes],
+    ["category" => 'DAILY_INTAKE_CARBOHYDRATES', "name" => 'Daily Intake Carbohydrates', "point" => $dailyIntakeCarbohydrates],
+    ["category" => 'DAILY_INTAKE_CALORIES', "name" => 'Daily Intake Calories', "point" => $dailyIntakeCalories],
+];
+?>
+
+<?php if(!count($points)): ?>
+    <span>-</span>
+<?php endif ?>
+<table class="table table-bordered table-sm mb-0 table-cage">
+    <?php foreach ($points as $p): ?>
+    <?php $point = $p['point']; ?>
+    <?php if(!!$point): ?>
+    <?php $plan = $point->lastChildPlan; ?>
+    <?php if ($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+    <tr>
+        <td class="width-300px">
+            <?= $p['name'] ?>
+        </td>
+        <td class="width-300px">
+            <?php if(!!$plan): ?>
+            <div class="ml-3">
+                <span>{!! $plan->data->value ? strip_tags($plan->data->value) : '-' !!}</span>
+            </div>
+            <?php endif; ?>
+        </td>
+        <td></td>
+    </tr>
+    <?php endif; ?>
+    <?php endforeach; ?>
+</table>

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


+ 73 - 0
resources/views/app/patient/segment-templates/problems/summary.blade.php

@@ -0,0 +1,73 @@
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$points = Point::getUnifiedPointsOfCategory($patient, 'PROBLEM', $note);
+$numRelevant = 0;
+$numVisible = 0;
+$plural = 'Problems';
+?>
+
+<?php if (!count($points)): ?>
+    <div class="text-secondary">-</div>
+<?php else: ?>
+    <table class="table table-bordered table-xs table-cage mb-0">
+    <?php $j = 0; foreach ($points as $point): $j++; ?>
+        <?php if($point->is_removed && $point->is_removed_due_to_entry_error) continue; ?>
+        <?php $rel = $point->relevanceToNote($note); ?>
+        <?php $plan = $point->lastChildPlan; ?>
+        <?php if($plan && @($plan->data)) $plan->data = json_decode($plan->data); ?>
+        <?php $numVisible++; ?>
+        <tr>
+            <td class="width-40px px-2 {{ $rel ? 'font-weight-bold text-info':'' }}">
+                @if($rel)
+                    <?php $numRelevant++; ?>
+                    {{ $j }}.*
+                @else
+                    {{ $j }}.
+                @endif
+            </td>
+            <td class="px-2 width-300px">
+                <div class="<?= $point->is_removed ? 'strike-through' : '' ?>">
+                    <b><?= !!@($point->data->name) ? @($point->data->name) : '-' ?></b>
+                </div>
+            </td>
+            <td class="px-2 width-300px">
+                <div>
+                    <?php if(!!$plan): ?>
+                        <div class="pl-3 mt-1 d-flex align-items-baseline">
+                            <span>{!! $plan->data->value !!}</span>
+                        </div>
+                    <?php elseif($rel): ?>
+                        <div class="relevant-without-plan text-warning-mellow text-sm mt-1" data-target-segment="<?= $segment->segmentTemplate->internal_name ?>"><i class="fa fa-exclamation-triangle mr-1"></i>Plan missing</div>
+                    <?php endif; ?>
+                </div>
+                <div class="d-flex align-items-baseline">
+                    <?php if ($point->is_removed): ?>
+                        @if($point->removal_reason_category === 'DURING_VISIT')
+                            <span class="ml-2 text-sm text-secondary">Removed during visit</span>
+                        @elseif($point->removal_reason_category === 'ON_INTAKE')
+                            <span class="ml-2 text-sm text-secondary">Removed on intake</span>
+                        @endif
+                    <?php elseif ($point->added_in_note_id === $note->id): ?>
+                        <?php if ($point->addition_reason_category === 'DURING_VISIT'): ?>
+                            <span class="ml-2 text-sm text-success">* Diagnosed during visit</span>
+                        <?php else: ?>
+                            <span class="ml-2 text-sm text-info">* Added on intake</span>
+                        <?php endif;?>
+                    <?php endif; ?>
+                </div>
+            </td>
+            <td></td>
+        </tr>
+    <?php endforeach; ?>
+    </table>
+    @if(!$numVisible)
+        <div class="d-flex align-items-baseline mr-1">
+            <span class="text-secondary">-</span>
+        </div>
+    @endif
+<?php endif; ?>
+

+ 7 - 0
resources/views/app/patient/wizard-partials/common-script.blade.php

@@ -322,6 +322,7 @@ parentSegment.find('#frm-add-{{$label}}')
                 refreshDynamicStagPopup();
                 $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 if(typeof refreshRHSSidebar !== 'undefined') refreshRHSSidebar();
 
                 // only for canvas-migrate
@@ -447,6 +448,7 @@ parentSegment.find('.frm-edit-{{$label}}')
                 refreshDynamicStagPopup();
                 $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 if(typeof refreshRHSSidebar !== 'undefined') refreshRHSSidebar();
             }
         }, 'json');
@@ -463,6 +465,7 @@ parentSegment.find('.frm-upsert-review-plan-{{$label}}')
             if(!hasResponseError(_data)) {
                 $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 refreshDynamicStagPopup();
             }
         }).then(() => {
@@ -591,6 +594,7 @@ parentSegment.find('.frm-review-plan-lifestyle')
             if(!hasResponseError(_data)) {
                 $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 refreshDynamicStagPopup();
             }
         }).then(() => {
@@ -612,6 +616,7 @@ parentSegment.find('.toggle-relevance')
                     refreshDynamicStagPopup();
                     $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                     $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                    $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                     if(typeof refreshRHSSidebar !== 'undefined') refreshRHSSidebar();
                 }
             }, 'json');
@@ -624,6 +629,7 @@ parentSegment.find('.toggle-relevance')
                         refreshDynamicStagPopup();
                         $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                         $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                        $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                         if(typeof refreshRHSSidebar !== 'undefined') refreshRHSSidebar();
                     }
                 }, 'json');
@@ -659,6 +665,7 @@ parentSegment.find('.tracker-input')
                 refreshDynamicStagPopup();
                 $('.visit-segment[data-segment-template-name="intake_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
                 $('.visit-segment[data-segment-template-name="plan_{{$segment_part}}"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="{{$segment_part}}"]').find('.refresh-segment').trigger('click');
             }
         }, 'json');
     });