Bläddra i källkod

NKA/NKAM - logic updates

Vijayakrishnan 3 år sedan
förälder
incheckning
391f8d9816

+ 8 - 0
app/Models/Point.php

@@ -182,6 +182,14 @@ class Point extends Model
         return $points;
     }
 
+    public static function getNumPointsOfCategory(Client $_patient, String $_category) {
+        return Point
+            ::where('client_id', $_patient->id)
+            ->where('category', $_category)
+            ->where('is_removed', false)
+            ->count();
+    }
+
     public static function getPointsOfCategoryExtended(Client $_patient, String $_category, Note $_note) {
         $points = Point
             ::where('client_id', $_patient->id)

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

@@ -9,6 +9,7 @@ use App\Models\Segment;
 /** @var Note $note */
 
 list($allergies, $counts) = Point::getPointsOfCategoryExtended($patient, 'ALLERGY', $note);
+$numActiveItems = Point::getNumPointsOfCategory($patient, 'ALLERGY');
 ?>
 
 <div class="mt-3 p-3 border-top" id="allergies-center-{{$note->id}}">
@@ -26,12 +27,12 @@ list($allergies, $counts) = Point::getPointsOfCategoryExtended($patient, 'ALLERG
             <label class="border border-info d-inline-flex align-items-center my-0 mr-3 p-2 rounded">
                 <input type="checkbox" class="tracker-input mr-2"
                        {{$tracker && @($tracker->data->no_known_allergies_of_any_type) ? 'checked' : ''}}
-                       data-field-name="no_known_allergies_of_any_type">
+                       data-field-name="no_known_allergies_of_any_type"
+                       data-num-active-items="{{$numActiveItems}}">
                 <span>No Known Allergies of Any Type</span>
             </label>
         </div>
 
-        @if(!$tracker || !@($tracker->data->no_known_allergies_of_any_type))
         <table class="table table-sm table-bordered mb-0 bg-white mb-2">
             <thead>
             <tr class="">
@@ -230,7 +231,7 @@ list($allergies, $counts) = Point::getPointsOfCategoryExtended($patient, 'ALLERG
                 </form>
             </div>
         </div>
-        @endif
+
     </div>
 </div>
 
@@ -260,6 +261,11 @@ list($allergies, $counts) = Point::getPointsOfCategoryExtended($patient, 'ALLERG
 
             initSegmentMoes($('#allergies-center-{{$note->id}}'));
             __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
+
+            // if there are active items, and it is marked NKAM, auto-unmark it
+            @if($numActiveItems && $tracker && @($tracker->data->no_known_allergies_of_any_type))
+                parentSegment.find('[data-field-name="no_known_allergies_of_any_type"]').prop('checked', false).trigger('change');
+            @endif
         }
         addMCInitializer('allergies-center-{{$note->id}}', init, '#allergies-center-{{$note->id}}');
     }).call(window);

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

@@ -9,6 +9,7 @@ use App\Models\Segment;
 /** @var Note $note */
 
 list($medications, $counts) = Point::getPointsOfCategoryExtended($patient, 'MEDICATION', $note);
+$numActiveItems = Point::getNumPointsOfCategory($patient, 'MEDICATION');
 
 ?>
 
@@ -21,12 +22,12 @@ list($medications, $counts) = Point::getPointsOfCategoryExtended($patient, 'MEDI
             <label class="border border-info d-inline-flex align-items-center my-0 mr-3 p-2 rounded">
                 <input type="checkbox" class="tracker-input mr-2"
                        {{$tracker && @($tracker->data->no_known_medications) ? 'checked' : ''}}
-                       data-field-name="no_known_medications">
+                       data-field-name="no_known_medications"
+                       data-num-active-items="{{$numActiveItems}}">
                 <span>No Known Medications</span>
             </label>
         </div>
 
-        @if(!$tracker || !@($tracker->data->no_known_medications))
         <table class="table table-sm table-bordered mb-0 bg-white mb-2">
             <thead>
             <tr class="">
@@ -250,7 +251,7 @@ list($medications, $counts) = Point::getPointsOfCategoryExtended($patient, 'MEDI
                 </form>
             </div>
         </div>
-        @endif
+
     </div>
 </div>
 
@@ -316,6 +317,11 @@ list($medications, $counts) = Point::getPointsOfCategoryExtended($patient, 'MEDI
 
         initSegmentMoes(parentSegment);
         __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
+
+        // if there are active items, and it is marked NKAM, auto-unmark it
+        @if($numActiveItems && $tracker && @($tracker->data->no_known_medications))
+            parentSegment.find('[data-field-name="no_known_medications"]').prop('checked', false).trigger('change');
+        @endif
     }
     addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}');
 }).call(window);

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

@@ -438,6 +438,16 @@ parentSegment.find('.tracker-input')
     .off('change.tracker-input')
     .on('change.tracker-input', function () {
         let trackerData = JSON.parse($.trim(parentSegment.find('.no_known_tracker').first().val()));
+
+        // disallow if [data-num-active-items] and data-num-active-items is not 0
+        if($(this).is('[data-num-active-items]')) {
+            if(this.checked && +$(this).attr('data-num-active-items') !== 0) {
+                toastr.error('There are active items');
+                this.checked = false;
+                return false;
+            }
+        }
+
         trackerData[$(this).attr('data-field-name')] = this.checked;
         trackerData = JSON.stringify(trackerData);
         $.post('/api/visitPoint/upsertGlobalSingleton', {