Ver código fonte

Wizards - 'no same-named item in same-state' validation

Vijayakrishnan 3 anos atrás
pai
commit
6b9ad38773

+ 7 - 3
resources/views/app/patient/allergies-center.blade.php

@@ -13,7 +13,7 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
 ?>
 
 <div class="mt-3 p-3 border-top" id="allergies-center-{{$note->id}}">
-    <div>
+    <div class="point-table-container">
 
         <?php $tracker = Point::getGlobalSingletonOfCategory($patient, 'NO_KNOWN_TRACKER'); ?>
         <textarea class="no_known_tracker d-none">{!! $tracker && @($tracker->data) ? json_encode($tracker->data) : '{}' !!}</textarea>
@@ -33,7 +33,7 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
             </label>
         </div>
 
-        <table class="table table-sm table-bordered mb-0 bg-white mb-2">
+        <table class="table table-sm table-bordered mb-0 bg-white mb-2 point-table">
             <thead>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -56,7 +56,11 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
             @endif
             <?php $prevRowState = $allergy->state; ?>
             <?php $rel = $allergy->relevanceToNote($note); ?>
-            <tr class="{{$rel ? 'relevant-to-visit' : ''}}">
+            <tr class="{{$rel ? 'relevant-to-visit' : ''}} point-row"
+                data-uid="{{$allergy->uid}}"
+                data-name-base64="{{!!@($allergy->data->name) ? base64_encode($allergy->data->name) : ''}}"
+                data-is-removed="{{$allergy->is_removed ? 1 : 0}}"
+                data-is-removed-due-to-entry-error="{{$allergy->is_removed_due_to_entry_error ? 1 : 0}}">
                 @if($patient->core_note_id !== $note->id)
                     @include('app.patient.wizard-partials.relevance-column', ['point' => $allergy])
                 @endif

+ 7 - 3
resources/views/app/patient/careteam-center.blade.php

@@ -12,9 +12,9 @@ list($careTeamMembers, $counts) = Point::getPointsOfCategoryExtended($patient, '
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="careteam-center-{{$note->id}}">
-    <div>
+    <div class="point-table-container">
 
-        <table class="table table-sm table-bordered mb-0 bg-white mb-2">
+        <table class="table table-sm table-bordered mb-0 bg-white mb-2 point-table">
             <thead>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -37,7 +37,11 @@ list($careTeamMembers, $counts) = Point::getPointsOfCategoryExtended($patient, '
             @endif
             <?php $prevRowState = $careTeamMember->state; ?>
             <?php $rel = $careTeamMember->relevanceToNote($note); ?>
-            <tr class="{{$rel ? 'relevant-to-visit' : ''}}">
+            <tr class="{{$rel ? 'relevant-to-visit' : ''}} point-row"
+                data-uid="{{$careTeamMember->uid}}"
+                data-name-base64="{{!!@($careTeamMember->data->name) ? base64_encode($careTeamMember->data->name) : ''}}"
+                data-is-removed="{{$careTeamMember->is_removed ? 1 : 0}}"
+                data-is-removed-due-to-entry-error="{{$careTeamMember->is_removed_due_to_entry_error ? 1 : 0}}">
                 @if($patient->core_note_id !== $note->id)
                     @include('app.patient.wizard-partials.relevance-column', ['point' => $careTeamMember])
                 @endif

+ 8 - 4
resources/views/app/patient/goals-center.blade.php

@@ -12,9 +12,9 @@ list($goals, $counts) = Point::getPointsOfCategoryExtended($patient, 'GOAL', $no
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="goals-center-{{$note->id}}">
-    <div>
+    <div class="point-table-container">
 
-        <table class="table table-sm table-bordered mb-0 bg-white mb-2">
+        <table class="table table-sm table-bordered mb-0 bg-white mb-2 point-table">
             <thead>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -37,7 +37,11 @@ list($goals, $counts) = Point::getPointsOfCategoryExtended($patient, 'GOAL', $no
             @endif
             <?php $prevRowState = $goal->state; ?>
             <?php $rel = $goal->relevanceToNote($note); ?>
-            <tr class="{{$rel ? 'relevant-to-visit' : ''}}">
+            <tr class="{{$rel ? 'relevant-to-visit' : ''}} point-row"
+                data-uid="{{$goal->uid}}"
+                data-name-base64="{{!!@($goal->data->goal) ? base64_encode($goal->data->goal) : ''}}"
+                data-is-removed="{{$goal->is_removed ? 1 : 0}}"
+                data-is-removed-due-to-entry-error="{{$goal->is_removed_due_to_entry_error ? 1 : 0}}">
                 @if($patient->core_note_id !== $note->id)
                     @include('app.patient.wizard-partials.relevance-column', ['point' => $goal])
                 @endif
@@ -223,7 +227,7 @@ list($goals, $counts) = Point::getPointsOfCategoryExtended($patient, 'GOAL', $no
                 })
                 .trigger('change');
 
-            @include('app.patient.wizard-partials.common-script', ['label' => 'goal', 'segment_part' => 'goals'])
+            @include('app.patient.wizard-partials.common-script', ['label' => 'goal', 'segment_part' => 'goals', 'nameKey' => 'goal'])
 
             initSegmentMoes($('#goals-center-{{$note->id}}'));
             __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));

+ 7 - 3
resources/views/app/patient/medications-center.blade.php

@@ -14,7 +14,7 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
 ?>
 
 <div class="mt-3 p-3 border-top" id="medications-center-{{$note->id}}">
-    <div>
+    <div class="point-table-container">
 
         <?php $tracker = Point::getGlobalSingletonOfCategory($patient, 'NO_KNOWN_TRACKER'); ?>
         <textarea class="no_known_tracker d-none">{!! $tracker && @($tracker->data) ? json_encode($tracker->data) : '{}' !!}</textarea>
@@ -28,7 +28,7 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
             </label>
         </div>
 
-        <table class="table table-sm table-bordered mb-0 bg-white mb-2">
+        <table class="table table-sm table-bordered mb-0 bg-white mb-2 point-table">
             <thead>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -51,7 +51,11 @@ $numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
                 @endif
                 <?php $prevRowState = $medication->state; ?>
                 <?php $rel = $medication->relevanceToNote($note); ?>
-                <tr class="{{$rel ? 'relevant-to-visit' : ''}}">
+                <tr class="{{$rel ? 'relevant-to-visit' : ''}} point-row"
+                    data-uid="{{$medication->uid}}"
+                    data-name-base64="{{!!@($medication->data->name) ? base64_encode($medication->data->name) : ''}}"
+                    data-is-removed="{{$medication->is_removed ? 1 : 0}}"
+                    data-is-removed-due-to-entry-error="{{$medication->is_removed_due_to_entry_error ? 1 : 0}}">
                     @if($patient->core_note_id !== $note->id)
                         @include('app.patient.wizard-partials.relevance-column', ['point' => $medication])
                     @endif

+ 7 - 3
resources/views/app/patient/problems-center.blade.php

@@ -14,7 +14,7 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="problems-center-{{$note->id}}">
-    <div>
+    <div class="point-table-container">
 
         @if($patient->core_note_id !== $note->id)
         <div class="d-flex align-items-baseline">
@@ -28,7 +28,7 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
         @endif
 
         <div class="mb-2 font-weight-bold font-size-14 text-secondary">Problems</div>
-        <table class="table table-sm table-bordered mb-0 bg-white mb-2">
+        <table class="table table-sm table-bordered mb-0 bg-white mb-2 point-table">
             <thead>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -51,7 +51,11 @@ $ccSegment = $ccSegment ?? $note->getSegmentByInternalName('mc_cc');
             @endif
             <?php $prevRowState = $problem->state; ?>
             <?php $rel = $problem->relevanceToNote($note); ?>
-            <tr class="{{$rel ? 'relevant-to-visit' : ''}}">
+            <tr class="{{$rel ? 'relevant-to-visit' : ''}} point-row"
+                data-uid="{{$problem->uid}}"
+                data-name-base64="{{!!@($problem->data->name) ? base64_encode($problem->data->name) : ''}}"
+                data-is-removed="{{$problem->is_removed ? 1 : 0}}"
+                data-is-removed-due-to-entry-error="{{$problem->is_removed_due_to_entry_error ? 1 : 0}}">
                 @if($patient->core_note_id !== $note->id)
                     @include('app.patient.wizard-partials.relevance-column', ['point' => $problem])
                 @endif

+ 7 - 3
resources/views/app/patient/supplements-center.blade.php

@@ -13,9 +13,9 @@ list($supplements, $counts) = Point::getPointsOfCategoryExtended($patient, 'SUPP
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="supplements-center-{{$note->id}}">
-    <div>
+    <div class="point-table-container">
 
-        <table class="table table-sm table-bordered mb-0 bg-white mb-2">
+        <table class="table table-sm table-bordered mb-0 bg-white mb-2 point-table">
             <thead>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -38,7 +38,11 @@ list($supplements, $counts) = Point::getPointsOfCategoryExtended($patient, 'SUPP
                 @endif
                 <?php $prevRowState = $supplement->state; ?>
                 <?php $rel = $supplement->relevanceToNote($note); ?>
-                <tr class="{{$rel ? 'relevant-to-visit' : ''}}">
+                <tr class="{{$rel ? 'relevant-to-visit' : ''}} point-row"
+                    data-uid="{{$supplement->uid}}"
+                    data-name-base64="{{!!@($supplement->data->name) ? base64_encode($supplement->data->name) : ''}}"
+                    data-is-removed="{{$supplement->is_removed ? 1 : 0}}"
+                    data-is-removed-due-to-entry-error="{{$supplement->is_removed_due_to_entry_error ? 1 : 0}}">
                     @if($patient->core_note_id !== $note->id)
                         @include('app.patient.wizard-partials.relevance-column', ['point' => $supplement])
                     @endif

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

@@ -2,6 +2,42 @@ function __reset(_input) {
     _input.val(_input.attr('value') ? _input.attr('value') : '');
 }
 
+function __isUniqueInState(form, _uid = '') {
+
+    // no same-named item in same-state validation
+    let nameKey = '{{@$nameKey ? $nameKey : "name"}}',
+        namePlain = $.trim(form.find('[data-name="' + nameKey + '"]').val()),
+        nameBase64 = btoa(namePlain),
+        table = form.closest('.point-table-container').find('.point-table').first(),
+        exists = false,
+        state = '',
+        uidPart = !!_uid ? ':not([data-uid="' + _uid + '"])' : '';
+    if (form.find('[name="isRemoved"][value="1"]').is(':checked')) { // inactive
+        if (form.find('[name="isRemovedDueToEntryError"][value="1"]').is(':checked')) { // entry error
+            if (table.find('tr.point-row[data-name-base64="' + nameBase64 + '"][data-is-removed="1"][data-is-removed-due-to-entry-error="1"]' + uidPart).length) {
+                exists = true;
+                state = 'entry error';
+            }
+        } else { // historic
+            if (table.find('tr.point-row[data-name-base64="' + nameBase64 + '"][data-is-removed="1"][data-is-removed-due-to-entry-error="0"]' + uidPart).length) {
+                exists = true;
+                state = 'historic';
+            }
+        }
+    } else { // active
+        if (table.find('tr.point-row[data-name-base64="' + nameBase64 + '"][data-is-removed="0"]' + uidPart).length) {
+            exists = true;
+            state = 'active';
+        }
+    }
+    if (exists) {
+        toastr.error(namePlain + ' already exists in ' + state + ' state!');
+        return false;
+    }
+
+    return true;
+}
+
 function __initRTEs(_collection) {
     _collection.each(function() {
 
@@ -206,6 +242,10 @@ parentSegment.find('#frm-add-{{$label}}')
             return false;
         }
 
+        if(!__isUniqueInState(form)) return false;
+
+        showMask();
+
         // add [data-name] values to payload
         let dataField = form.find('[name="data"]').first();
         let parsed = null;
@@ -295,6 +335,10 @@ parentSegment.find('.frm-edit-{{$label}}')
             return false;
         }
 
+        if(!__isUniqueInState(form, form.find('[name="uid"]').first().val())) return false;
+
+        showMask();
+
         // add [data-name] values to payload
         let dataField = form.find('[name="data"]').first();
         let parsed = null;