Эх сурвалжийг харах

Goals wizard - last-plan to directions + adding plan with goal in one shot

Vijayakrishnan 3 жил өмнө
parent
commit
0505f701fd

+ 63 - 32
resources/views/app/patient/goals-center.blade.php

@@ -35,12 +35,12 @@ $goals = $points;
                 <th class="border-bottom-0 text-secondary text-center width-30px">Rel.</th>
                 <th class="border-bottom-0 text-secondary">Goal</th>
                 <th class="border-bottom-0 text-secondary">Category</th>
+                <th class="border-bottom-0 text-secondary w-25">Directions</th>
                 <th class="border-bottom-0 text-secondary">Active?</th>
                 <th class="border-bottom-0 text-secondary">Edit</th>
                 <th class="border-bottom-0 text-secondary">Started</th>
                 <th class="border-bottom-0 text-secondary">Ended</th>
                 <th class="border-bottom-0 text-secondary">Last Review</th>
-                <th class="border-bottom-0 text-secondary">Last Plan</th>
             </tr>
             </thead>
             <?php $prevRowRemoved = -1; ?>
@@ -94,6 +94,31 @@ $goals = $points;
                 <td>
                     <?= !!@($goal->data->category) ? @($goal->data->category) : '-' ?>
                 </td>
+                <td>
+                    <div class="d-flex align-items-start">
+                        <div class="flex-grow-1">
+                            <?php
+                            include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
+                            ?>
+                        </div>
+                        <div class="d-inline-flex flex-nowrap">
+                            <a class="px-2 view-review-log"
+                               native target="_blank"
+                               open-in-stag-popup
+                               popup-style="stag-popup-md"
+                               title="Plan log<?= !!@($goal->data->goal) ? ' for ' . @($goal->data->goal) : '' ?>"
+                               href="/point/plan-log/<?= $goal->uid ?>?popupmode=1">
+                                <i class="fa fa-history"></i>
+                            </a>
+                            <?php
+                            $segment = $note->getSegmentByInternalName('plan_goals');
+                            if($segment) {
+                                include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
+                            }
+                            ?>
+                        </div>
+                    </div>
+                </td>
                 <td>
                     @if($goal->is_removed)
                         NO
@@ -330,31 +355,6 @@ $goals = $points;
                         </div>
                     </div>
                 </td>
-                <td>
-                    <div class="d-flex align-items-start">
-                        <div class="flex-grow-1">
-                            <?php
-                            include resource_path('views/app/patient/segment-templates/_child_plan/last-plan.php');
-                            ?>
-                        </div>
-                        <div class="d-inline-flex flex-nowrap">
-                            <a class="px-2 view-review-log"
-                               native target="_blank"
-                               open-in-stag-popup
-                               popup-style="stag-popup-md"
-                               title="Plan log<?= !!@($goal->data->goal) ? ' for ' . @($goal->data->goal) : '' ?>"
-                               href="/point/plan-log/<?= $goal->uid ?>?popupmode=1">
-                                <i class="fa fa-history"></i>
-                            </a>
-                            <?php
-                            $segment = $note->getSegmentByInternalName('plan_goals');
-                            if($segment) {
-                                include resource_path('views/app/patient/segment-templates/_child_plan/edit-plan.php');
-                            }
-                            ?>
-                        </div>
-                    </div>
-                </td>
             </tr>
             <?php endforeach; ?>
         </table>
@@ -453,6 +453,13 @@ $goals = $points;
                                 </div>
                             </div>
 
+                            <div class="mb-2">
+                                <label class="text-sm mb-1">Directions</label>
+                                <div note-rte
+                                     class="form-group mb-2 border-left border-right rte-holder bg-white"
+                                     data-field-name="value"></div>
+                            </div>
+
                             <div class="row mb-2">
                                 <div class="col-6 pr-0">
                                     <label class="text-sm mb-0">Start Date</label>
@@ -544,8 +551,8 @@ $goals = $points;
 
 <script>
     (function() {
-        function initVisitMoeRTEs() {
-            $('.stag-popup [visit-moe]').find('[note-rte]:not(.ql-container)').each(function() {
+        function initRTEs(_collection) {
+            _collection.each(function() {
 
                 $(this).wrap(
                     $('<div class="border-left border-right rte-holder"/>')
@@ -577,7 +584,11 @@ $goals = $points;
                     let dataObject = {};
                     dataObject[fieldName] = content;
                     var dataValue = JSON.stringify(dataObject);
-                    $(el).closest('[visit-moe]').find('input[name=data]').val(dataValue);
+                    let pElem = $(el).closest('[visit-moe]');
+                    if(!pElem.length) {
+                        pElem = $(el).closest('form');
+                    }
+                    pElem.find('input[name=data]').val(dataValue);
                 };
 
                 quill.on('text-change', onTextChange);
@@ -676,6 +687,15 @@ $goals = $points;
                     if(dataField.val()) {
                         parsed = JSON.parse(dataField.val());
                     }
+
+                    // store plan content
+                    let planContent = parsed.value ? parsed.value : '';
+                    if(!$.trim($('<div/>').html(planContent).text())) {
+                        toastr.error('Directions cannot be empty');
+                        return false;
+                    }
+                    if(parsed.value) delete parsed.value;
+
                     form.find('[data-name]').each(function() {
                         if(!parsed) parsed = {};
 
@@ -705,8 +725,19 @@ $goals = $points;
 
                     $.post(form.attr('action'), form.serialize(), _data => {
                         if(!hasResponseError(_data)) {
-                            hideMask();
-                            refreshDynamicStagPopup();
+
+                            // save child plan
+                            $.post('/api/visitPoint/upsertChildPlan', {
+                                uid: _data.data,
+                                segmentUid: '{{$note->getSegmentByInternalName('plan_goals')->uid}}',
+                                data: JSON.stringify({value: planContent})
+                            }, _data => {
+                                if(!hasResponseError(_data)) {
+                                    hideMask();
+                                    refreshDynamicStagPopup();
+                                }
+                            }, 'json');
+
                             $('.visit-segment[data-segment-template-name="intake_goals"]').find('.refresh-segment').trigger('click');
                         }
                     }, 'json');
@@ -803,7 +834,7 @@ $goals = $points;
             parentSegment.find('[name="isRemoved"]').trigger('change');
 
             initSegmentMoes($('#goals-center-{{$note->id}}'));
-            initVisitMoeRTEs();
+            initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
         }
         addMCInitializer('goals-center-{{$note->id}}', init, '#goals-center-{{$note->id}}');
     }).call(window);