Jelajahi Sumber

Point - cope plan/review logic impl

Vijayakrishnan 3 tahun lalu
induk
melakukan
c66e2cf344

+ 10 - 0
app/Models/Point.php

@@ -68,6 +68,16 @@ class Point extends Model
         return $this->hasOne(Note::class, 'id', 'last_child_plan_point_scoped_note_id');
     }
 
+    public function coreChildReview()
+    {
+        return $this->hasOne(Point::class, 'id', 'core_child_review_point_id');
+    }
+
+    public function coreChildPlan()
+    {
+        return $this->hasOne(Point::class, 'id', 'core_child_plan_point_id');
+    }
+
     public function client()
     {
         return $this->hasOne(Client::class, 'id', 'client_id');

+ 11 - 0
public/css/style.css

@@ -427,6 +427,17 @@ body>nav.navbar {
 .mcp-theme-1 .ql-editor[contenteditable] {
     min-height: 100px;
 }
+body [note-rte][data-field-name="reviewValue"],
+body [note-rte][data-field-name="corePlanValue"],
+body [note-rte][data-field-name="planValue"] {
+    border: 1px solid #ced4da !important;
+}
+body [note-rte][data-field-name="reviewValue"] .ql-editor[contenteditable],
+body [note-rte][data-field-name="corePlanValue"] .ql-editor[contenteditable],
+body [note-rte][data-field-name="planValue"] .ql-editor[contenteditable] {
+    min-height: 28px !important;
+    padding: .25rem .5rem !important;
+}
 .ql-container p {
     margin-top: 1rem;
 }

+ 74 - 56
resources/views/app/patient/wizard-partials/common-fields.blade.php

@@ -1,5 +1,5 @@
 <div class="mb-2">
-    <span class="font-weight-bold">Is this {{$label}} active?</span>
+    <span class="font-weight-bold">Is this {{$label}} currently active?</span>
     <div class="d-flex align-items-baseline mt-1">
         <label class="my-0 d-inline-flex align-items-center">
             <input type="radio" name="isRemoved" required value="0" {{!$point || !$point->is_removed ? 'checked' : ''}}>
@@ -79,32 +79,34 @@
 <div {{@$point ? 'if-not-entry-error class="d-none"' : ''}}>
     <div if-addition-or-removal-on-intake-or-during-visit class="d-none">
         <div class="row mb-2">
-            <div class="col-6 pr-0">
+            <div class="col-3 pr-0">
                 <label class="text-sm mb-0 font-weight-bold">Start Date</label>
                 <input type="date"
                        data-name="start_date"
                        value="{{@$point->data ? @$point->data->start_date : ''}}"
                        class="form-control form-control-sm min-width-unset">
             </div>
-            <div class="col-6">
+            <div class="col-3 pr-0">
                 <label class="text-sm mb-0 font-weight-bold">{{@$addVerbPT ? ucwords($addVerbPT) : 'Added'}} By</label>
                 <input type="text"
                        data-name="prescriber"
                        value="{{@$point->data ? @$point->data->prescriber : ''}}"
                        class="form-control form-control-sm min-width-unset">
             </div>
-        </div>
-        <div if-not-active class="d-none">
-            <div if-removal-on-intake-or-during-visit class="d-none">
-                <div class="row mb-2">
-                    <div class="col-6 pr-0">
+            <div class="col-3 pr-0">
+                <div if-not-active class="d-none">
+                    <div if-removal-on-intake-or-during-visit class="d-none">
                         <label class="text-sm mb-0 font-weight-bold">End Date</label>
                         <input type="date"
                                name="removalEffectiveDate"
                                value="{{@$point->removal_effective_date}}"
                                class="form-control form-control-sm min-width-unset">
                     </div>
-                    <div class="col-6">
+                </div>
+            </div>
+            <div class="col-3">
+                <div if-not-active class="d-none">
+                    <div if-removal-on-intake-or-during-visit class="d-none">
                         <label class="text-sm mb-0 font-weight-bold">Removal By/Memo</label>
                         <input type="text"
                                name="removalReasonMemo"
@@ -121,61 +123,77 @@
     <div if-active-or-not-active class="d-none">
 
     @if(1 || $patient->core_note_id !== $note->id) {{-- allow review/plan from core note --}}
-        <div class="row mb-2">
-            @if(!@$noReview)
-                <div class="col-6 pr-0">
-                    <?php
-                    $currentValue = '';
-                    $previousValue = '';
-                    $previousChildReview = null;
-                    if (@$point) {
-                        if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
-                            $parsedReview = json_decode($point->lastChildReview->data);
-                            if (@($parsedReview->value)) {
-                                $currentValue = $parsedReview->value;
-                                $previousChildReview = \App\Models\Point::where('id', '<', $point->lastChildReview->id)
-                                    ->where('category', 'REVIEW')
-                                    ->where('parent_point_id', $point->id)
-                                    ->orderBy('id', 'DESC')
-                                    ->first();
-                                if ($previousChildReview && $previousChildReview->data) {
-                                    $parsedReview = json_decode($previousChildReview->data);
-                                    if (@($parsedReview->value)) {
-                                        $previousValue = $parsedReview->value;
-                                    }
-                                }
-                            }
-                        } else {
-                            $previousChildReview = \App\Models\Point::where('parent_point_id', $point->id)
+
+        {{-- pre-existing plan (coreChildPlan) - show only when-adding OR when-editing-from-created-note --}}
+        <div if-active-and-pre-existing-or-not-active class="mb-2 d-none">
+            <?php
+            $currentValue = '';
+            if (@$point && $point->coreChildPlan) {
+                $parsedPlan = json_decode($point->coreChildPlan->data);
+                $currentValue = @($parsedPlan->value) ? $parsedPlan->value : '';
+            }
+            ?>
+            <label class="text-sm mb-0 font-weight-bold">Pre-existing {{@$planLabel ? $planLabel : 'Plan'}} (before this visit)</label>
+            <div note-rte
+                 class="form-group mb-2 rte-holder bg-white border rounded"
+                 data-field-name="corePlanValue"><?= $currentValue ?></div>
+        </div>
+
+        @if(!@$noReview)
+            <div class="mb-2">
+                <?php
+                $currentValue = '';
+                $previousValue = '';
+                $previousChildReview = null;
+                if (@$point) {
+                    if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
+                        $parsedReview = json_decode($point->lastChildReview->data);
+                        if (@($parsedReview->value)) {
+                            $currentValue = $parsedReview->value;
+                            $previousChildReview = \App\Models\Point::where('id', '<', $point->lastChildReview->id)
                                 ->where('category', 'REVIEW')
+                                ->where('parent_point_id', $point->id)
                                 ->orderBy('id', 'DESC')
                                 ->first();
                             if ($previousChildReview && $previousChildReview->data) {
                                 $parsedReview = json_decode($previousChildReview->data);
-                                if (@$parsedReview->value) {
+                                if (@($parsedReview->value)) {
                                     $previousValue = $parsedReview->value;
                                 }
                             }
                         }
+                    } else {
+                        $previousChildReview = \App\Models\Point::where('parent_point_id', $point->id)
+                            ->where('category', 'REVIEW')
+                            ->orderBy('id', 'DESC')
+                            ->first();
+                        if ($previousChildReview && $previousChildReview->data) {
+                            $parsedReview = json_decode($previousChildReview->data);
+                            if (@$parsedReview->value) {
+                                $previousValue = $parsedReview->value;
+                            }
+                        }
                     }
-                    ?>
-                    <label class="text-sm mb-1 font-weight-bold">{{@$reviewLabel ? $reviewLabel : 'Review'}}</label>
-                    <div note-rte
-                         class="form-group mb-2 border-left border-right rte-holder bg-white"
-                         data-field-name="reviewValue"><?= $currentValue ?></div>
-                    <?php if($previousValue): ?>
-                    <div class="mb-2">
-                        <div class="d-flex align-items-baseline mb-1">
-                            <span class="text-sm text-secondary">Previous {{@$reviewLabel ? $reviewLabel : 'Review'}} / <?= friendlier_date($previousChildReview->created_at) ?> (click to copy)</span>
-                        </div>
-                        <div class="p-2 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+                }
+            ?>
+                <label class="text-sm mb-0 font-weight-bold">{{@$reviewLabel ? $reviewLabel : 'Review'}}</label>
+                <div note-rte
+                     class="form-group mb-2 rte-holder bg-white border rounded"
+                     data-field-name="reviewValue"><?= $currentValue ?></div>
+                <?php if($previousValue): ?>
+                <div class="mb-2">
+                    <div class="d-flex align-items-baseline mb-1">
+                        <span class="text-sm text-secondary">Previous {{@$reviewLabel ? $reviewLabel : 'Review'}} / <?= friendlier_date($previousChildReview->created_at) ?> (click to copy)</span>
                     </div>
-                    <div class="d-none disallow-if-review-same-as" compare-width="reviewValue"><?= str_compact($previousValue) ?></div>
-                    <?php endif; ?>
+                    <div class="p-2 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
                 </div>
-            @endif
-            <div class="col-{{!@$noReview ? '6' : '12'}}">
-                @if(!@$noPlan)
+                <div class="d-none disallow-if-review-same-as" compare-width="reviewValue"><?= str_compact($previousValue) ?></div>
+                <?php endif; ?>
+            </div>
+        @endif
+
+        @if(!@$noPlan)
+            <div class="mb-2">
                 <?php
                 $currentValue = '';
                 $previousValue = '';
@@ -205,9 +223,9 @@
                     }
                 }
                 ?>
-                <label class="text-sm mb-1 font-weight-bold">{{@$planLabel ? $planLabel : 'Plan'}}</label>
+                <label class="text-sm mb-0 font-weight-bold">Changes to {{@$planLabel ? $planLabel : 'Plan'}} during this visit (as part of my plan)</label>
                 <div note-rte
-                     class="form-group mb-2 border-left border-right rte-holder bg-white"
+                     class="form-group mb-2 rte-holder bg-white border rounded"
                      data-field-name="planValue"><?= $currentValue ?></div>
                 <?php if($previousValue): ?>
                 <div class="mb-2">
@@ -218,9 +236,9 @@
                 </div>
                 <div class="d-none disallow-if-plan-same-as" compare-width="planValue"><?= str_compact($previousValue) ?></div>
                 <?php endif; ?>
-                @endif
             </div>
-        </div>
+        @endif
+
     @endif
 
     </div>

+ 27 - 4
resources/views/app/patient/wizard-partials/common-script.blade.php

@@ -8,7 +8,7 @@ function __initRTEs(_collection) {
         let noteRTE = $(this);
 
         $(this).wrap(
-            $('<div class="border-left border-right rte-holder"/>')
+            $('<div class="rte-holder"/>')
                 .attr('data-shortcuts', '')
         );
 
@@ -20,7 +20,9 @@ function __initRTEs(_collection) {
         var existingContent = $(el).html();
         var quill = new Quill(el, {
             theme: 'snow',
-            modules: stagQuillConfig
+            modules: {
+                toolbar: false
+            }
         });
 
         var toolbar = $(quill.container).prev('.ql-toolbar');
@@ -77,7 +79,7 @@ parentSegment.find('[name="isRemoved"]')
     .off('change')
     .on('change', function () {
         let form = $(this).closest('form');
-        form.find('[if-active-or-not-active], [if-active], [if-not-active]').addClass('d-none');
+        form.find('[if-active-or-not-active], [if-active], [if-not-active], [if-active-and-pre-existing-or-not-active]').addClass('d-none');
         if(form.find('[name="isRemoved"]:checked').length) form.find('[if-active-or-not-active]').removeClass('d-none');
         if(form.find('[name="isRemoved"]:checked').val() === '1') form.find('[if-not-active]').removeClass('d-none');
         else if(form.find('[name="isRemoved"]:checked').val() === '0') {
@@ -85,6 +87,9 @@ parentSegment.find('[name="isRemoved"]')
             form.find('[name="removalEffectiveDate"]').val('');
             form.find('[name="removalReasonMemo"]').val('');
         }
+        if(form.find('[name="isRemoved"]:checked').val() === '1' || form.find('[name="additionReasonCategory"]:checked').val() === 'ON_INTAKE') {
+            form.find('[if-active-and-pre-existing-or-not-active]').removeClass('d-none');
+        }
         return false;
     })
     .trigger('change');
@@ -93,7 +98,7 @@ parentSegment.find('[name="additionReasonCategory"]')
     .off('change')
     .on('change', function () {
         let form = $(this).closest('form');
-        form.find('[if-addition-on-intake-or-during-visit], [if-addition-on-intake], [if-addition-during-visit]').addClass('d-none');
+        form.find('[if-addition-on-intake-or-during-visit], [if-addition-on-intake], [if-addition-during-visit], [if-active-and-pre-existing-or-not-active]').addClass('d-none');
         if(form.find('[name="additionReasonCategory"]:checked').length) form.find('[if-addition-on-intake-or-during-visit]').removeClass('d-none');
         form.find('[if-addition-or-removal-on-intake-or-during-visit]').addClass('d-none');
         if(form.find('[name="additionReasonCategory"]:checked').length || form.find('[name="removalReasonCategory"]:checked').length) {
@@ -109,6 +114,9 @@ parentSegment.find('[name="additionReasonCategory"]')
             form.find('[data-name="start_date"]').val('{{$patient->core_note_id !== $note->id ? $note->effective_dateest : date("Y-m-d")}}');
             form.find('[data-name="prescriber"]').val('{{$patient->core_note_id !== $note->id ? ($note->hcpPro ? $note->hcpPro->displayName() : "")  : ""}}');
         }
+        if(form.find('[name="isRemoved"]:checked').val() === '1' || form.find('[name="additionReasonCategory"]:checked').val() === 'ON_INTAKE') {
+            form.find('[if-active-and-pre-existing-or-not-active]').removeClass('d-none');
+        }
         return false;
     })
     .trigger('change');
@@ -183,12 +191,14 @@ parentSegment.find('#frm-add-{{$label}}')
 
         @if(1 || $patient->core_note_id !== $note->id)
         // store plan content
+        let corePlanContent = parsed && parsed.corePlanValue ? parsed.corePlanValue : '';
         let planContent = parsed && parsed.planValue ? parsed.planValue : '';
         let reviewContent = parsed && parsed.reviewValue ? parsed.reviewValue : '';
         // if(!$.trim($('<div/>').html(planContent).text())) {
         //     toastr.error('Directions cannot be empty');
         //     return false;
         // }
+        if(parsed.corePlanValue) delete parsed.corePlanValue;
         if(parsed.planValue) delete parsed.planValue;
         if(parsed.reviewValue) delete parsed.reviewValue;
         @endif
@@ -223,6 +233,11 @@ parentSegment.find('#frm-add-{{$label}}')
         let payload = {};
         form.serializeArray().map(x => {payload[x.name] = x.value;});
         @if(1 || $patient->core_note_id !== $note->id)
+        if(!!corePlanContent && $.trim($('<div/>').html(corePlanContent).text())) {
+            payload.corePlanData = JSON.stringify({
+                value: corePlanContent
+            })
+        }
         if(!!reviewContent && $.trim($('<div/>').html(reviewContent).text())) {
             payload.childReviewData = JSON.stringify({
                 value: reviewContent
@@ -271,6 +286,8 @@ parentSegment.find('.frm-edit-{{$label}}')
         }
 
         @if(1 || $patient->core_note_id !== $note->id)
+        let corePlanContent = parsed && parsed.corePlanValue ? parsed.corePlanValue : '';
+
         let reviewContent = parsed && parsed.reviewValue ? parsed.reviewValue : '';
 
         let compareWith = false;
@@ -299,6 +316,7 @@ parentSegment.find('.frm-edit-{{$label}}')
             }
         }
 
+        if(parsed.corePlanValue) delete parsed.corePlanValue;
         if(parsed.planValue) delete parsed.planValue;
         if(parsed.reviewValue) delete parsed.reviewValue;
         @endif
@@ -333,6 +351,11 @@ parentSegment.find('.frm-edit-{{$label}}')
         let payload = {};
         form.serializeArray().map(x => {payload[x.name] = x.value;});
         @if(1 || $patient->core_note_id !== $note->id)
+        if(!!corePlanContent && $.trim($('<div/>').html(corePlanContent).text())) {
+            payload.corePlanData = JSON.stringify({
+                value: corePlanContent
+            })
+        }
         if(!!reviewContent && $.trim($('<div/>').html(reviewContent).text())) {
             payload.childReviewData = JSON.stringify({
                 value: reviewContent