ソースを参照

Apply new list/add/edit changes to all wizards

Vijayakrishnan 3 年 前
コミット
e7b9e9df5c

+ 1 - 1
app/Models/Point.php

@@ -170,7 +170,7 @@ class Point extends Model
     public static function getPointsOfCategoryExtended(Client $_patient, String $_category, Note $_note) {
         $points = Point
             ::where('client_id', $_patient->id)
-            ->where('category', 'MEDICATION')
+            ->where('category', $_category)
             ->where(function ($q) use($_note) {
                 $q
                     ->where('is_removed_due_to_entry_error', false)

+ 28 - 431
resources/views/app/patient/allergies-center.blade.php

@@ -8,20 +8,7 @@ use App\Models\Segment;
 /** @var Client $patient */
 /** @var Note $note */
 
-$points = Point
-    ::where('client_id', $patient->id)
-    ->where('category', 'ALLERGY')
-    ->where('is_removed_due_to_entry_error', false)
-    ->orderBy('is_removed')
-    ->orderBy('removal_effective_date', 'DESC')
-    ->orderBy('created_at')
-    ->get();
-foreach ($points as $point) {
-    if ($point->data) {
-        $point->data = json_decode($point->data);
-    }
-}
-$allergies = $points;
+$allergies = Point::getPointsOfCategoryExtended($patient, 'ALLERGY', $note);
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="allergies-center-{{$note->id}}">
@@ -39,19 +26,19 @@ $allergies = $points;
                 <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 w-25">Last Review</th>
-                <th class="border-bottom-0 text-secondary w-25">Last Plan</th>
+                <th class="border-bottom-0 text-secondary w-25">Review</th>
+                <th class="border-bottom-0 text-secondary w-25">Plan</th>
             </tr>
             </thead>
-            <?php $prevRowRemoved = -1; ?>
+            <?php $prevRowState = -1; ?>
             <?php foreach($allergies as $allergy): ?>
             <?php $point = $allergy; ?>
-            @if($prevRowRemoved !== -1 && $prevRowRemoved !== $allergy->is_removed)
+            @if($prevRowState !== -1 && $prevRowState !== $allergy->state)
                 <tr>
                     <td colspan="9" class="px-0 pt-1 pb-0 on-hover-opaque bg-secondary"></td>
                 </tr>
             @endif
-            <?php $prevRowRemoved = $allergy->is_removed; ?>
+            <?php $prevRowState = $allergy->state; ?>
             <?php $rel = $allergy->relevanceToNote($note); ?>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -71,10 +58,14 @@ $allergies = $points;
                 @endif
                 <td>
                     <div class="d-flex align-items-baseline">
-                        @if($allergy->is_removed)
-                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
-                        @else
-                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @if($allergy->state === 1)
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($allergy->state === 2)
+                            <i class="text-info fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($allergy->state === 3)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($allergy->state === 4)
+                            <i class="text-secondary fa fa-circle text-sm on-hover-opaque mr-2"></i>
                         @endif
                         <div>
                             <b><?= !!@($allergy->data->name) ? @($allergy->data->name) : '-' ?></b>
@@ -121,9 +112,9 @@ $allergies = $points;
                             <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
                             <p class="mb-2"><b>Update Allergy</b></p>
 
-                            @if($allergy->added_in_note_id === $note->id)
+                            <input type="hidden" name="data" value='{{json_encode($allergy->data)}}'>
 
-                                <input type="hidden" name="data">
+                            @if($allergy->added_in_note_id === $note->id)
 
                                 <input type="hidden" data-name="damConceptId" value="{{@$allergy->data->damConceptId}}">
                                 <input type="hidden" data-name="damConceptIdType" value="{{@$allergy->data->damConceptIdType}}">
@@ -136,23 +127,6 @@ $allergies = $points;
                                            stag-suggest-ep="/fdb-allergy-suggest/json">
                                 </div>
 
-                                <div class="row mb-2">
-                                    <div class="col-6 pr-0">
-                                        <label class="text-sm mb-0">Start Date</label>
-                                        <input type="date"
-                                               data-name="start_date"
-                                               value="{{@$allergy->data->start_date}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                    <div class="col-6">
-                                        <label class="text-sm mb-0">Added By</label>
-                                        <input type="text"
-                                               data-name="prescriber"
-                                               value="{{@$allergy->data->prescriber}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                </div>
-
                             @else
 
                                 <div class="mb-2 bg-light p-2 border">
@@ -168,80 +142,20 @@ $allergies = $points;
 
                             @endif
 
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0">When Added</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="additionReasonCategory" required>
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE" {{$allergy->addition_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$allergy->addition_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-8">
-                                    <label class="text-sm mb-0 min-width-unset">Addition Memo</label>
-                                    <input type="text"
-                                           name="additionReasonMemo"
-                                           value="{{$allergy->addition_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">Is allergy active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="">-- select --</option>
-                                        <option value="0" {{!$allergy->is_removed ? 'selected' : ''}}>Yes</option>
-                                        <option value="1" {{$allergy->is_removed ? 'selected' : ''}}>No</option>
-                                    </select>
-                                </div>
-                                <div class="col-6 is_removed_ui_1" style="display: none">
-                                    <label class="text-sm mb-0 min-width-unset">Is entry error?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemovedDueToEntryError">
-                                        <option value="1" {{$allergy->is_removed_due_to_entry_error ? 'selected' : ''}}>Yes</option>
-                                        <option value="0" {{!$allergy->is_removed_due_to_entry_error ? 'selected' : ''}}>No</option>
-                                    </select>
-                                </div>
-                            </div>
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'allergy', 'point' => $allergy])
 
-                            <div class="row mb-2 is_removed_ui_2" style="display: none">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">When Removed</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="removalReasonCategory">
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE" {{$allergy->removal_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$allergy->removal_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">End Date</label>
-                                    <input type="date"
-                                           name="removalEffectiveDate"
-                                           value="{{$allergy->removal_effective_date ? $allergy->removal_effective_date : ''}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-4">
-                                    <label class="text-sm mb-0 min-width-unset">Removal By/Memo</label>
-                                    <input type="text"
-                                           name="removalReasonMemo"
-                                           value="{{$allergy->removal_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <div>
+                            <div class="mt-3 pt-2 d-flex align-items-center border-top">
                                 <button type="submit" class="btn-save-allergy btn btn-sm btn-primary mr-2">Save</button>
-                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                <button cancel class="btn btn-sm bg-light btn-default border">Cancel</button>
                             </div>
                         </form>
                     </div>
                 </td>
                 <td>
                     <?= !!@($allergy->data->start_date) ? friendly_date($allergy->data->start_date) : '-' ?>
+                    @if(!!@($allergy->data->prescriber))
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($allergy->data->prescriber) ? @($allergy->data->prescriber) : '-' ?></div>
+                    @endif
                 </td>
                 <td>
                     <?= !!@($allergy->removal_effective_date) ? friendly_date($allergy->removal_effective_date) : '-' ?>
@@ -314,6 +228,8 @@ $allergies = $points;
                     <input type="hidden" data-name="damConceptId">
                     <input type="hidden" data-name="damConceptIdType">
 
+                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+
                     <div class="row">
                         <div class="col-7">
                             <p class="mb-2"><b>Add Allergy</b></p>
@@ -324,79 +240,9 @@ $allergies = $points;
                                        stag-suggest-ep="/fdb-allergy-suggest/json"
                                        required>
                             </div>
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0">Start Date</label>
-                                    <input type="date"
-                                           data-name="start_date"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-6">
-                                    <label class="text-sm mb-0">Added By</label>
-                                    <input type="text"
-                                           data-name="prescriber"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-                            <!--<div class="mb-2">
-                                <label class="text-sm mb-1">Description</label>
-                                <textarea rows="1" data-name="description" class="form-control form-control-sm"></textarea>
-                            </div>-->
-
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0">When Added</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="additionReasonCategory" required>
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE">On Intake</option>
-                                        <option value="DURING_VISIT">During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-8">
-                                    <label class="text-sm mb-0 min-width-unset">Addition Memo</label>
-                                    <input type="text"
-                                           name="additionReasonMemo"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">Is allergy active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="0" selected>Yes</option>
-                                        <option value="1">No</option>
-                                    </select>
-                                </div>
-                                <input type="hidden" name="isRemovedDueToEntryError" value="0">
-                            </div>
 
-                            <div class="row mb-2 is_removed_ui_2" style="display: none">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">When Removed</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="removalReasonCategory">
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE">On Intake</option>
-                                        <option value="DURING_VISIT">During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">End Date</label>
-                                    <input type="date"
-                                           name="removalEffectiveDate"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-4">
-                                    <label class="text-sm mb-0 min-width-unset">Removal By/Memo</label>
-                                    <input type="text"
-                                           name="removalReasonMemo"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
+                            <?php $point = null; ?>
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'allergy'])
 
                         </div>
                         <div class="col-5 border-left">
@@ -417,62 +263,6 @@ $allergies = $points;
 
 <script>
     (function() {
-        function initVisitMoeRTEs() {
-            $('.stag-popup [visit-moe]').find('[note-rte]:not(.ql-container)').each(function() {
-
-                let noteRTE = $(this);
-
-                $(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).attr('data-field-name') ? $(this).attr('data-field-name') : 'free_text';
-
-                var el = this;
-                var existingContent = $(el).html();
-                var quill = new Quill(el, {
-                    theme: 'snow',
-                    modules: stagQuillConfig
-                });
-
-                var toolbar = $(quill.container).prev('.ql-toolbar');
-
-                // add button for new shortcut
-                if(!noteRTE.is('[use-shortcuts]') || !noteRTE.attr('use-shortcuts')) {
-                    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);
-                }
-
-                quill.root.innerHTML = existingContent;
-
-                let onTextChange = function(delta, oldDelta, source) {
-                    var content = quill.root.innerHTML;
-                    let dataObject = {};
-                    dataObject[fieldName] = content;
-                    var dataValue = JSON.stringify(dataObject);
-                    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);
-
-                $(quill.container)
-                    .find('.ql-editor[contenteditable]')
-                    .attr('data-field', fieldName)
-                    .attr('data-editor-id', editorID)
-                    .attr('with-shortcuts', 1);
-
-                // set value initially
-                onTextChange();
-            });
-        }
         function init() {
             let parentSegment = $('#allergies-center-{{$note->id}}');
             parentSegment.find('input[stag-suggest][data-name="name"]')
@@ -493,203 +283,10 @@ $allergies = $points;
 
                 });
 
-            parentSegment.find('.additionReasonCategory_ui')
-                .off('change')
-                .on('change', function() {
-
-                    let form = $(this).closest('form');
-
-                    // additionReasonCategory
-                    // isRemoved
-                    // removalReasonCategory
-                    form.find('[name="isRemovedDueToEntryError"]').val('0');
-
-                    form.find('.start_date_ui').hide();
-                    form.find('.removalEffectiveDate_ui').hide();
-                    form.find('.removalReasonMemo_ui').hide();
-
-                    if(this.value === 'HISTORIC') {
-                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
-                        form.find('[name="isRemoved"]').val('1');
-                        form.find('.start_date_ui').show();
-                        form.find('.removalEffectiveDate_ui').show();
-                        form.find('.removalReasonMemo_ui').show();
-                    }
-                    else if(this.value === 'PRE_EXISTING') {
-                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
-                        form.find('[name="isRemoved"]').val('0');
-                        form.find('.start_date_ui').show();
-                    }
-                    else if(this.value === 'NEW') {
-                        form.find('[name="additionReasonCategory"]').val('DURING_VISIT');
-                        form.find('[name="isRemoved"]').val('0');
-                        form.find('.start_date_ui').show().find('input').val('{{date('Y-m-d')}}');
-                    }
-
-                });
-
-            parentSegment.find('[name="isRemoved"], [name="isRemovedDueToEntryError"]')
-                .off('change')
-                .on('change', function () {
-                    let form = $(this).closest('form');
-
-                    form.find('.is_removed_ui_1').hide();
-                    if(form.find('[name="isRemoved"]').val() === '1') {
-                        form.find('.is_removed_ui_1').show();
-                    }
-
-                    form.find('.is_removed_ui_2').hide();
-                    if(form.find('[name="isRemoved"]').val() === '1' && form.find('[name="isRemovedDueToEntryError"]').val() !== '1') {
-                        form.find('.is_removed_ui_2').show();
-                    }
-                    return false;
-                });
-
-            parentSegment.find('#frm-add-allergy')
-                .off('submit')
-                .on('submit', function () {
-
-                    let form = $(this);
-
-                    if (!form[0].checkValidity()) {
-                        form[0].reportValidity();
-                        return false;
-                    }
-
-                    // add [data-name] values to payload
-                    let dataField = form.find('[name="data"]').first();
-                    let parsed = null;
-                    if(dataField.val()) {
-                        parsed = JSON.parse(dataField.val());
-                    }
-                    form.find('[data-name]').each(function() {
-                        if(!parsed) parsed = {};
-
-                        let keys = $(this).attr('data-name').split('->');
-                        let currentNode = parsed;
-                        for (let i = 0; i < keys.length; i++) {
-                            if(i !== keys.length - 1) {
-                                if(typeof currentNode[keys[i]] === 'undefined') {
-                                    currentNode[keys[i]] = {};
-                                }
-                                currentNode = currentNode[keys[i]];
-                            }
-                            else {
-                                if($(this).is(':checkbox')) {
-                                    currentNode[keys[i]] = $(this).prop('checked');
-                                }
-                                else {
-                                    currentNode[keys[i]] = $(this).val();
-                                }
-                            }
-                        }
-
-                    });
-                    if(parsed) {
-                        dataField.val(JSON.stringify(parsed));
-                    }
-
-                    $.post(form.attr('action'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-                            hideMask();
-                            refreshDynamicStagPopup();
-                            $('.visit-segment[data-segment-template-name="intake_allergies"]').find('.refresh-segment').trigger('click');
-                        }
-                    }, 'json');
-                    return false;
-                });
-
-            parentSegment.find('.frm-edit-allergy')
-                .off('submit')
-                .on('submit', function () {
-
-                    let form = $(this);
-
-                    if (!form[0].checkValidity()) {
-                        form[0].reportValidity();
-                        return false;
-                    }
-
-                    // add [data-name] values to payload
-                    let dataField = form.find('[name="data"]').first();
-                    let parsed = null;
-                    if(dataField.val()) {
-                        parsed = JSON.parse(dataField.val());
-                    }
-                    form.find('[data-name]').each(function() {
-                        if(!parsed) parsed = {};
-
-                        let keys = $(this).attr('data-name').split('->');
-                        let currentNode = parsed;
-                        for (let i = 0; i < keys.length; i++) {
-                            if(i !== keys.length - 1) {
-                                if(typeof currentNode[keys[i]] === 'undefined') {
-                                    currentNode[keys[i]] = {};
-                                }
-                                currentNode = currentNode[keys[i]];
-                            }
-                            else {
-                                if($(this).is(':checkbox')) {
-                                    currentNode[keys[i]] = $(this).prop('checked');
-                                }
-                                else {
-                                    currentNode[keys[i]] = $(this).val();
-                                }
-                            }
-                        }
-
-                    });
-                    if(parsed) {
-                        dataField.val(JSON.stringify(parsed));
-                    }
-
-                    $.post(form.attr('url'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-                            hideMask();
-                            refreshDynamicStagPopup();
-                            $('.visit-segment[data-segment-template-name="intake_allergies"]').find('.refresh-segment').trigger('click');
-                        }
-                    }, 'json');
-                    return false;
-                });
-
-            parentSegment.find('.toggle-relevance')
-                .off('click.toggle-relevance')
-                .on('click.toggle-relevance', function () {
-                    if(+$(this).attr('data-relevant') === 0) {
-                        $.post('/api/visitPoint/markPointRelevantToNote', {
-                            noteUid: '{{$note->uid}}',
-                            pointUid: $(this).attr('data-point-uid')
-                        }, _data => {
-                            if(!hasResponseError(_data)) {
-                                refreshDynamicStagPopup();
-                            }
-                        }, 'json');
-                    }
-                    else {
-                        if($(this).attr('data-rel-uid')) {
-                            $.post('/api/visitPoint/undoMarkPointRelevantToNote', {
-                                uid: $(this).attr('data-rel-uid')
-                            }, _data => {
-                                if(!hasResponseError(_data)) {
-                                    refreshDynamicStagPopup();
-                                }
-                            }, 'json');
-                        }
-                        else {
-                            console.log('Error - missing rel uid');
-                        }
-                    }
-                    return false;
-                });
-
-            initStagSuggest();
-
-            parentSegment.find('.additionReasonCategory_ui').trigger('change');
-            parentSegment.find('[name="isRemoved"]').trigger('change');
+            @include('app.patient.wizard-partials.common-script', ['label' => 'allergy'])
 
             initSegmentMoes($('#allergies-center-{{$note->id}}'));
-            initVisitMoeRTEs();
+            __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
         }
         addMCInitializer('allergies-center-{{$note->id}}', init, '#allergies-center-{{$note->id}}');
     }).call(window);

+ 51 - 487
resources/views/app/patient/goals-center.blade.php

@@ -8,22 +8,7 @@ use App\Models\Segment;
 /** @var Client $patient */
 /** @var Note $note */
 
-$points = Point
-    ::where('client_id', $patient->id)
-    ->where('category', 'GOAL')
-    ->where('is_removed_due_to_entry_error', false)
-    ->orderBy('category')
-    ->orderBy('is_removed')
-    ->orderBy('removal_effective_date', 'DESC')
-    ->orderBy('created_at')
-    ->get();
-foreach ($points as $point) {
-    if ($point->data) {
-        $point->data = json_decode($point->data);
-    }
-}
-$goals = $points;
-
+$goals = Point::getPointsOfCategoryExtended($patient, 'GOAL', $note);
 ?>
 
 <div class="mt-3 p-3 border-top min-height-500px" id="goals-center-{{$note->id}}">
@@ -37,23 +22,23 @@ $goals = $points;
                 @endif
                 <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 w-25">Review</th>
+                <th class="border-bottom-0 text-secondary w-25">Plan</th>
             </tr>
             </thead>
-            <?php $prevRowRemoved = -1; ?>
+            <?php $prevRowState = -1; ?>
             <?php foreach($goals as $goal): ?>
             <?php $point = $goal; ?>
-            @if($prevRowRemoved !== -1 && $prevRowRemoved !== $goal->is_removed)
+            @if($prevRowState !== -1 && $prevRowState !== $goal->state)
                 <tr>
-                    <td colspan="10" class="px-0 pt-1 pb-0 on-hover-opaque bg-secondary"></td>
+                    <td colspan="9" class="px-0 pt-1 pb-0 on-hover-opaque bg-secondary"></td>
                 </tr>
             @endif
-            <?php $prevRowRemoved = $goal->is_removed; ?>
+            <?php $prevRowState = $goal->state; ?>
             <?php $rel = $goal->relevanceToNote($note); ?>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -73,10 +58,14 @@ $goals = $points;
                 @endif
                 <td>
                     <div class="d-flex align-items-baseline">
-                        @if($goal->is_removed)
-                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
-                        @else
-                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @if($goal->state === 1)
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($goal->state === 2)
+                            <i class="text-info fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($goal->state === 3)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($goal->state === 4)
+                            <i class="text-secondary fa fa-circle text-sm on-hover-opaque mr-2"></i>
                         @endif
                         <div>
                             <b><?= !!@($goal->data->goal) ? @($goal->data->goal) : '-' ?></b>
@@ -111,31 +100,6 @@ $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
@@ -151,9 +115,9 @@ $goals = $points;
                             <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
                             <p class="mb-2"><b>Update Goal</b></p>
 
-                            @if($goal->added_in_note_id === $note->id)
+                            <input type="hidden" name="data" value='{{json_encode($goal->data)}}'>
 
-                                <input type="hidden" name="data">
+                            @if($goal->added_in_note_id === $note->id)
 
                                 <div class="mb-2">
                                     <label class="text-sm text-secondary mb-1">Category</label>
@@ -234,23 +198,6 @@ $goals = $points;
                                            value="{{@$goal->data->goal}}">
                                 </div>
 
-                                <div class="row mb-2">
-                                    <div class="col-6 pr-0">
-                                        <label class="text-sm mb-0">Start Date</label>
-                                        <input type="date"
-                                               data-name="start_date"
-                                               value="{{@$goal->data->start_date}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                    <div class="col-6">
-                                        <label class="text-sm mb-0">Added By</label>
-                                        <input type="text"
-                                               data-name="prescriber"
-                                               value="{{@$goal->data->prescriber}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                </div>
-
                             @else
 
                                 <div class="mb-2 bg-light p-2 border">
@@ -266,74 +213,11 @@ $goals = $points;
 
                             @endif
 
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0">When Added</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="additionReasonCategory" required>
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE" {{$goal->addition_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$goal->addition_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-8">
-                                    <label class="text-sm mb-0 min-width-unset">Addition Memo</label>
-                                    <input type="text"
-                                           name="additionReasonMemo"
-                                           value="{{$goal->addition_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <hr class="my-3">
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'goal', 'point' => $goal])
 
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">Is goal active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="">-- select --</option>
-                                        <option value="0" {{!$goal->is_removed ? 'selected' : ''}}>Yes</option>
-                                        <option value="1" {{$goal->is_removed ? 'selected' : ''}}>No</option>
-                                    </select>
-                                </div>
-                                <div class="col-6 is_removed_ui_1" style="display: none">
-                                    <label class="text-sm mb-0 min-width-unset">Is entry error?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemovedDueToEntryError">
-                                        <option value="1" {{$goal->is_removed_due_to_entry_error ? 'selected' : ''}}>Yes</option>
-                                        <option value="0" {{!$goal->is_removed_due_to_entry_error ? 'selected' : ''}}>No</option>
-                                    </select>
-                                </div>
-                            </div>
-
-                            <div class="row mb-2 is_removed_ui_2" style="display: none">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">When Removed</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="removalReasonCategory">
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE" {{$goal->removal_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$goal->removal_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">End Date</label>
-                                    <input type="date"
-                                           name="removalEffectiveDate"
-                                           value="{{$goal->removal_effective_date ? $goal->removal_effective_date : ''}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-4">
-                                    <label class="text-sm mb-0 min-width-unset">Removal By/Memo</label>
-                                    <input type="text"
-                                           name="removalReasonMemo"
-                                           value="{{$goal->removal_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <div>
+                            <div class="mt-3 pt-2 d-flex align-items-center border-top">
                                 <button type="submit" class="btn-save-goal btn btn-sm btn-primary mr-2">Save</button>
-                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                <button cancel class="btn btn-sm bg-light btn-default border">Cancel</button>
                             </div>
                         </form>
                     </div>
@@ -376,6 +260,31 @@ $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>
@@ -387,6 +296,8 @@ $goals = $points;
                     <input type="hidden" name="category" value="GOAL">
                     <input type="hidden" name="data">
 
+                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+
                     <p class="mb-2"><b>Add Goal</b></p>
 
                     <div class="row">
@@ -474,86 +385,8 @@ $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>
-                                    <input type="date"
-                                           data-name="start_date"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-6">
-                                    <label class="text-sm mb-0">Added By</label>
-                                    <input type="text"
-                                           data-name="prescriber"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-                            <!--<div class="mb-2">
-                                <label class="text-sm mb-1">Description</label>
-                                <textarea rows="1" data-name="description" class="form-control form-control-sm"></textarea>
-                            </div>-->
-
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0">When Added</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="additionReasonCategory" required>
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE">On Intake</option>
-                                        <option value="DURING_VISIT">During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-8">
-                                    <label class="text-sm mb-0 min-width-unset">Addition Memo</label>
-                                    <input type="text"
-                                           name="additionReasonMemo"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">Is goal active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="0" selected>Yes</option>
-                                        <option value="1">No</option>
-                                    </select>
-                                </div>
-                                <input type="hidden" name="isRemovedDueToEntryError" value="0">
-                            </div>
-
-                            <div class="row mb-2 is_removed_ui_2" style="display: none">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">When Removed</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="removalReasonCategory">
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE">On Intake</option>
-                                        <option value="DURING_VISIT">During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">End Date</label>
-                                    <input type="date"
-                                           name="removalEffectiveDate"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-4">
-                                    <label class="text-sm mb-0 min-width-unset">Removal By/Memo</label>
-                                    <input type="text"
-                                           name="removalReasonMemo"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
+                            <?php $point = null; ?>
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'goal'])
 
                         </div>
                         <div class="col-5 border-left">
@@ -572,58 +405,6 @@ $goals = $points;
 
 <script>
     (function() {
-        function initRTEs(_collection) {
-            _collection.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).attr('data-field-name') ? $(this).attr('data-field-name') : 'free_text';
-
-                var el = this;
-                var existingContent = $(el).html();
-                var quill = new Quill(el, {
-                    theme: 'snow',
-                    modules: stagQuillConfig
-                });
-
-                var toolbar = $(quill.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);
-
-                quill.root.innerHTML = existingContent;
-
-                let onTextChange = function(delta, oldDelta, source) {
-                    var content = quill.root.innerHTML;
-                    let dataObject = {};
-                    dataObject[fieldName] = content;
-                    var dataValue = JSON.stringify(dataObject);
-                    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);
-
-                $(quill.container)
-                    .find('.ql-editor[contenteditable]')
-                    .attr('data-field', fieldName)
-                    .attr('data-editor-id', editorID)
-                    .attr('with-shortcuts', 1);
-
-                // set value initially
-                onTextChange();
-            });
-        }
         function init() {
             let parentSegment = $('#goals-center-{{$note->id}}');
 
@@ -635,227 +416,10 @@ $goals = $points;
                 })
                 .trigger('change');
 
-            parentSegment.find('.additionReasonCategory_ui')
-                .off('change')
-                .on('change', function() {
-
-                    let form = $(this).closest('form');
-
-                    // additionReasonCategory
-                    // isRemoved
-                    // removalReasonCategory
-                    form.find('[name="isRemovedDueToEntryError"]').val('0');
-
-                    form.find('.start_date_ui').hide();
-                    form.find('.prescriber_ui').hide();
-                    form.find('.removalEffectiveDate_ui').hide();
-                    form.find('.removalReasonMemo_ui').hide();
-
-                    if(this.value === 'HISTORIC') {
-                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
-                        form.find('[name="isRemoved"]').val('1');
-                        form.find('.start_date_ui').show();
-                        form.find('.prescriber_ui').show();
-                        form.find('.removalEffectiveDate_ui').show();
-                        form.find('.removalReasonMemo_ui').show();
-                    }
-                    else if(this.value === 'PRE_EXISTING') {
-                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
-                        form.find('[name="isRemoved"]').val('0');
-                        form.find('.start_date_ui').show();
-                        form.find('.prescriber_ui').show();
-                    }
-                    else if(this.value === 'NEW') {
-                        form.find('[name="additionReasonCategory"]').val('DURING_VISIT');
-                        form.find('[name="isRemoved"]').val('0');
-                        form.find('.start_date_ui').show().find('input').val('{{date('Y-m-d')}}');
-                        form.find('.prescriber_ui').show().find('input').val('{{$note->hcpPro->displayName()}}');
-                    }
-
-                });
-
-            parentSegment.find('[name="isRemoved"], [name="isRemovedDueToEntryError"]')
-                .off('change')
-                .on('change', function () {
-                    let form = $(this).closest('form');
-
-                    form.find('.is_removed_ui_1').hide();
-                    if(form.find('[name="isRemoved"]').val() === '1') {
-                        form.find('.is_removed_ui_1').show();
-                    }
-
-                    form.find('.is_removed_ui_2').hide();
-                    if(form.find('[name="isRemoved"]').val() === '1' && form.find('[name="isRemovedDueToEntryError"]').val() !== '1') {
-                        form.find('.is_removed_ui_2').show();
-                    }
-                    return false;
-                });
-
-            parentSegment.find('#frm-add-goal')
-                .off('submit')
-                .on('submit', function () {
-
-                    let form = $(this);
-
-                    if (!form[0].checkValidity()) {
-                        form[0].reportValidity();
-                        return false;
-                    }
-
-                    // add [data-name] values to payload
-                    let dataField = form.find('[name="data"]').first();
-                    let parsed = null;
-                    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 = {};
-
-                        let keys = $(this).attr('data-name').split('->');
-                        let currentNode = parsed;
-                        for (let i = 0; i < keys.length; i++) {
-                            if(i !== keys.length - 1) {
-                                if(typeof currentNode[keys[i]] === 'undefined') {
-                                    currentNode[keys[i]] = {};
-                                }
-                                currentNode = currentNode[keys[i]];
-                            }
-                            else {
-                                if($(this).is(':checkbox')) {
-                                    currentNode[keys[i]] = $(this).prop('checked');
-                                }
-                                else {
-                                    currentNode[keys[i]] = $(this).val();
-                                }
-                            }
-                        }
-
-                    });
-                    if(parsed) {
-                        dataField.val(JSON.stringify(parsed));
-                    }
-
-                    $.post(form.attr('action'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-
-                            // 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');
-                    return false;
-                });
-
-            parentSegment.find('.frm-edit-goal')
-                .off('submit')
-                .on('submit', function () {
-
-                    let form = $(this);
-
-                    if (!form[0].checkValidity()) {
-                        form[0].reportValidity();
-                        return false;
-                    }
-
-                    // add [data-name] values to payload
-                    let dataField = form.find('[name="data"]').first();
-                    let parsed = null;
-                    if(dataField.val()) {
-                        parsed = JSON.parse(dataField.val());
-                    }
-                    form.find('[data-name]').each(function() {
-                        if(!parsed) parsed = {};
-
-                        let keys = $(this).attr('data-name').split('->');
-                        let currentNode = parsed;
-                        for (let i = 0; i < keys.length; i++) {
-                            if(i !== keys.length - 1) {
-                                if(typeof currentNode[keys[i]] === 'undefined') {
-                                    currentNode[keys[i]] = {};
-                                }
-                                currentNode = currentNode[keys[i]];
-                            }
-                            else {
-                                if($(this).is(':checkbox')) {
-                                    currentNode[keys[i]] = $(this).prop('checked');
-                                }
-                                else {
-                                    currentNode[keys[i]] = $(this).val();
-                                }
-                            }
-                        }
-
-                    });
-                    if(parsed) {
-                        dataField.val(JSON.stringify(parsed));
-                    }
-
-                    $.post(form.attr('url'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-                            hideMask();
-                            refreshDynamicStagPopup();
-                            $('.visit-segment[data-segment-template-name="intake_goals"]').find('.refresh-segment').trigger('click');
-                        }
-                    }, 'json');
-                    return false;
-                });
-
-            parentSegment.find('.toggle-relevance')
-                .off('click.toggle-relevance')
-                .on('click.toggle-relevance', function () {
-                    if(+$(this).attr('data-relevant') === 0) {
-                        $.post('/api/visitPoint/markPointRelevantToNote', {
-                            noteUid: '{{$note->uid}}',
-                            pointUid: $(this).attr('data-point-uid')
-                        }, _data => {
-                            if(!hasResponseError(_data)) {
-                                refreshDynamicStagPopup();
-                            }
-                        }, 'json');
-                    }
-                    else {
-                        if($(this).attr('data-rel-uid')) {
-                            $.post('/api/visitPoint/undoMarkPointRelevantToNote', {
-                                uid: $(this).attr('data-rel-uid')
-                            }, _data => {
-                                if(!hasResponseError(_data)) {
-                                    refreshDynamicStagPopup();
-                                }
-                            }, 'json');
-                        }
-                        else {
-                            console.log('Error - missing rel uid');
-                        }
-                    }
-                    return false;
-                });
-
-            initStagSuggest();
-
-            parentSegment.find('.additionReasonCategory_ui').trigger('change');
-            parentSegment.find('[name="isRemoved"]').trigger('change');
+            @include('app.patient.wizard-partials.common-script', ['label' => 'goal'])
 
             initSegmentMoes($('#goals-center-{{$note->id}}'));
-            initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
+            __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
         }
         addMCInitializer('goals-center-{{$note->id}}', init, '#goals-center-{{$note->id}}');
     }).call(window);

+ 1 - 72
resources/views/app/patient/medications-center.blade.php

@@ -175,7 +175,6 @@ $medications = Point::getPointsOfCategoryExtended($patient, 'MEDICATION', $note)
                             <div class="mt-3 pt-2 d-flex align-items-center border-top">
                                 <button type="submit" class="btn-save-medication btn btn-sm btn-primary mr-2">Save</button>
                                 <button cancel class="btn btn-sm bg-light btn-default border">Cancel</button>
-                                <!--<button type="button" class="ml-auto btn btn-sm btn-danger btn-mark-as-ee" data-uid="{{$medication->uid}}">Mark as Entry Error</button>-->
                             </div>
                         </form>
                     </div>
@@ -273,76 +272,6 @@ $medications = Point::getPointsOfCategoryExtended($patient, 'MEDICATION', $note)
 
 <script>
     (function() {
-        function initRTEs(_collection) {
-            _collection.each(function() {
-
-                let noteRTE = $(this);
-
-                $(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).attr('data-field-name') ? $(this).attr('data-field-name') : 'free_text';
-
-                var el = this;
-                var existingContent = $(el).html();
-                var quill = new Quill(el, {
-                    theme: 'snow',
-                    modules: stagQuillConfig
-                });
-
-                var toolbar = $(quill.container).prev('.ql-toolbar');
-
-                // add button for new shortcut
-                if(!noteRTE.is('[use-shortcuts]') || !noteRTE.attr('use-shortcuts')) {
-                    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);
-                }
-
-                quill.root.innerHTML = existingContent;
-
-                let onTextChange = function(delta, oldDelta, source) {
-                    var content = quill.root.innerHTML;
-                    let dataObject = {};
-                    dataObject[fieldName] = content;
-                    var dataValue = JSON.stringify(dataObject);
-                    let pElem = $(el).closest('[visit-moe]');
-                    if(!pElem.length) {
-                        pElem = $(el).closest('form');
-                    }
-                    let v = pElem.find('input[name=data]').val();
-                    if(!!v) {
-                        try {
-                            v = JSON.parse(v);
-                            v[fieldName] = content;
-                            v = JSON.stringify(v);
-                        }
-                        catch (e) {
-                            v = JSON.stringify(dataObject);
-                        }
-                    }
-                    else {
-                        v = JSON.stringify(dataObject);
-                    }
-                    pElem.find('input[name=data]').val(v);
-                };
-
-                quill.on('text-change', onTextChange);
-
-                $(quill.container)
-                    .find('.ql-editor[contenteditable]')
-                    .attr('data-field', fieldName)
-                    .attr('data-editor-id', editorID)
-                    .attr('with-shortcuts', 1);
-
-                // set value initially
-                onTextChange();
-            });
-        }
         function init() {
             let parentSegment = $('#medications-center-{{$note->id}}');
             parentSegment.find('input[stag-suggest][data-name="name"]')
@@ -406,7 +335,7 @@ $medications = Point::getPointsOfCategoryExtended($patient, 'MEDICATION', $note)
             buttonContainer.insertAfter(titleElem);
 
             initSegmentMoes(parentSegment);
-            initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
+            __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
         }
         addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}');
     }).call(window);

+ 28 - 431
resources/views/app/patient/problems-center.blade.php

@@ -8,21 +8,7 @@ use App\Models\Segment;
 /** @var Client $patient */
 /** @var Note $note */
 
-$points = Point
-    ::where('client_id', $patient->id)
-    ->where('category', 'PROBLEM')
-    ->where('is_removed_due_to_entry_error', false)
-    ->orderBy('is_removed')
-    ->orderBy('removal_effective_date', 'DESC')
-    ->orderBy('created_at')
-    ->get();
-foreach ($points as $point) {
-    if ($point->data) {
-        $point->data = json_decode($point->data);
-    }
-}
-$problems = $points;
-
+$problems = Point::getPointsOfCategoryExtended($patient, 'PROBLEM', $note);
 $ccSegment = $note->getSegmentByInternalName('chief_complaint');
 ?>
 
@@ -52,19 +38,19 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                 <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 w-25">Last Review</th>
-                <th class="border-bottom-0 text-secondary w-25">Last Plan</th>
+                <th class="border-bottom-0 text-secondary w-25">Review</th>
+                <th class="border-bottom-0 text-secondary w-25">Plan</th>
             </tr>
             </thead>
-            <?php $prevRowRemoved = -1; ?>
+            <?php $prevRowState = -1; ?>
             <?php foreach($problems as $problem): ?>
             <?php $point = $problem; ?>
-            @if($prevRowRemoved !== -1 && $prevRowRemoved !== $problem->is_removed)
+            @if($prevRowState !== -1 && $prevRowState !== $problem->state)
                 <tr>
                     <td colspan="9" class="px-0 pt-1 pb-0 on-hover-opaque bg-secondary"></td>
                 </tr>
             @endif
-            <?php $prevRowRemoved = $problem->is_removed; ?>
+            <?php $prevRowState = $problem->state; ?>
             <?php $rel = $problem->relevanceToNote($note); ?>
             <tr class="">
                 @if($patient->core_note_id !== $note->id)
@@ -84,10 +70,14 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                 @endif
                 <td>
                     <div class="d-flex align-items-baseline">
-                        @if($problem->is_removed)
-                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2"></i>
-                        @else
-                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2"></i>
+                        @if($problem->state === 1)
+                            <i class="text-success fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($problem->state === 2)
+                            <i class="text-info fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($problem->state === 3)
+                            <i class="text-warning-mellow fa fa-circle text-sm on-hover-opaque mr-2 active-record"></i>
+                        @elseif($problem->state === 4)
+                            <i class="text-secondary fa fa-circle text-sm on-hover-opaque mr-2"></i>
                         @endif
                         <div>
                             <b><?= !!@($problem->data->name) ? @($problem->data->name) : '-' ?></b>
@@ -134,9 +124,10 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                             <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
                             <p class="mb-2"><b>Update Problem</b></p>
 
+                            <input type="hidden" name="data" value='{{json_encode($problem->data)}}'>
+
                             @if($problem->added_in_note_id === $note->id)
 
-                                <input type="hidden" name="data">
                                 <input type="hidden" data-name="dxid" value="{{@$problem->data->dxid}}">
                                 <input type="hidden" data-name="icd-type" value="{{@$problem->data->{'icd-type'} }}">
 
@@ -157,23 +148,6 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                                     </select>
                                 </div>
 
-                                <div class="row mb-2">
-                                    <div class="col-6 pr-0">
-                                        <label class="text-sm mb-0">Start Date</label>
-                                        <input type="date"
-                                               data-name="start_date"
-                                               value="{{@$problem->data->start_date}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                    <div class="col-6">
-                                        <label class="text-sm mb-0">Added By</label>
-                                        <input type="text"
-                                               data-name="prescriber"
-                                               value="{{@$problem->data->prescriber}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                </div>
-
                             @else
 
                                 <div class="mb-2 bg-light p-2 border">
@@ -189,80 +163,20 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
 
                             @endif
 
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0">When Added</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="additionReasonCategory" required>
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE" {{$problem->addition_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$problem->addition_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-8">
-                                    <label class="text-sm mb-0 min-width-unset">Addition Memo</label>
-                                    <input type="text"
-                                           name="additionReasonMemo"
-                                           value="{{$problem->addition_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <hr class="my-3">
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'problem', 'point' => $problem])
 
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">Is problem active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="">-- select --</option>
-                                        <option value="0" {{!$problem->is_removed ? 'selected' : ''}}>Yes</option>
-                                        <option value="1" {{$problem->is_removed ? 'selected' : ''}}>No</option>
-                                    </select>
-                                </div>
-                                <div class="col-6 is_removed_ui_1" style="display: none">
-                                    <label class="text-sm mb-0 min-width-unset">Is entry error?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemovedDueToEntryError">
-                                        <option value="1" {{$problem->is_removed_due_to_entry_error ? 'selected' : ''}}>Yes</option>
-                                        <option value="0" {{!$problem->is_removed_due_to_entry_error ? 'selected' : ''}}>No</option>
-                                    </select>
-                                </div>
-                            </div>
-
-                            <div class="row mb-2 is_removed_ui_2" style="display: none">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">When Removed</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="removalReasonCategory">
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE" {{$problem->removal_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$problem->removal_reason_category === 'DURING_VISIT' ? 'selected' : ''}}>During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">End Date</label>
-                                    <input type="date"
-                                           name="removalEffectiveDate"
-                                           value="{{$problem->removal_effective_date ? $problem->removal_effective_date : ''}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-4">
-                                    <label class="text-sm mb-0 min-width-unset">Removal By/Memo</label>
-                                    <input type="text"
-                                           name="removalReasonMemo"
-                                           value="{{$problem->removal_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-
-                            <div>
+                            <div class="mt-3 pt-2 d-flex align-items-center border-top">
                                 <button type="submit" class="btn-save-problem btn btn-sm btn-primary mr-2">Save</button>
-                                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                                <button cancel class="btn btn-sm bg-light btn-default border">Cancel</button>
                             </div>
                         </form>
                     </div>
                 </td>
                 <td>
                     <?= !!@($problem->data->start_date) ? friendly_date($problem->data->start_date) : '-' ?>
+                    @if(!!@($problem->data->prescriber))
+                        <div class="mt-1 text-sm text-secondary">By: <?= !!@($problem->data->prescriber) ? @($problem->data->prescriber) : '-' ?></div>
+                    @endif
                 </td>
                 <td>
                     <?= !!@($problem->removal_effective_date) ? friendly_date($problem->removal_effective_date) : '-' ?>
@@ -335,6 +249,8 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                     <input type="hidden" data-name="dxid">
                     <input type="hidden" data-name="icd-type">
 
+                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+
                     <div class="row">
                         <div class="col-7">
                             <p class="mb-2"><b>Add Problem</b></p>
@@ -357,79 +273,9 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                                     </select>
                                 </div>
                             </div>
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0">Start Date</label>
-                                    <input type="date"
-                                           data-name="start_date"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-6">
-                                    <label class="text-sm mb-0">Added By</label>
-                                    <input type="text"
-                                           data-name="prescriber"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
-                            <!--<div class="mb-2">
-                                <label class="text-sm mb-1">Description</label>
-                                <textarea rows="1" data-name="description" class="form-control form-control-sm"></textarea>
-                            </div>-->
-
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0">When Added</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="additionReasonCategory" required>
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE">On Intake</option>
-                                        <option value="DURING_VISIT">During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-8">
-                                    <label class="text-sm mb-0 min-width-unset">Addition Memo</label>
-                                    <input type="text"
-                                           name="additionReasonMemo"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
 
-                            <hr class="my-3">
-
-                            <div class="row mb-2">
-                                <div class="col-6 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">Is problem active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="0" selected>Yes</option>
-                                        <option value="1">No</option>
-                                    </select>
-                                </div>
-                                <input type="hidden" name="isRemovedDueToEntryError" value="0">
-                            </div>
-
-                            <div class="row mb-2 is_removed_ui_2" style="display: none">
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">When Removed</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="removalReasonCategory">
-                                        <option value="">-- select --</option>
-                                        <option value="ON_INTAKE">On Intake</option>
-                                        <option value="DURING_VISIT">During Visit</option>
-                                    </select>
-                                </div>
-                                <div class="col-4 pr-0">
-                                    <label class="text-sm mb-0 min-width-unset">End Date</label>
-                                    <input type="date"
-                                           name="removalEffectiveDate"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                                <div class="col-4">
-                                    <label class="text-sm mb-0 min-width-unset">Removal By/Memo</label>
-                                    <input type="text"
-                                           name="removalReasonMemo"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
+                            <?php $point = null; ?>
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'problem'])
 
                         </div>
                         <div class="col-5 border-left">
@@ -450,62 +296,6 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
 
 <script>
     (function() {
-        function initVisitMoeRTEs() {
-            $('.stag-popup [visit-moe]').find('[note-rte]:not(.ql-container)').each(function() {
-
-                let noteRTE = $(this);
-
-                $(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).attr('data-field-name') ? $(this).attr('data-field-name') : 'free_text';
-
-                var el = this;
-                var existingContent = $(el).html();
-                var quill = new Quill(el, {
-                    theme: 'snow',
-                    modules: stagQuillConfig
-                });
-
-                var toolbar = $(quill.container).prev('.ql-toolbar');
-
-                // add button for new shortcut
-                if(!noteRTE.is('[use-shortcuts]') || !noteRTE.attr('use-shortcuts')) {
-                    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);
-                }
-
-                quill.root.innerHTML = existingContent;
-
-                let onTextChange = function(delta, oldDelta, source) {
-                    var content = quill.root.innerHTML;
-                    let dataObject = {};
-                    dataObject[fieldName] = content;
-                    var dataValue = JSON.stringify(dataObject);
-                    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);
-
-                $(quill.container)
-                    .find('.ql-editor[contenteditable]')
-                    .attr('data-field', fieldName)
-                    .attr('data-editor-id', editorID)
-                    .attr('with-shortcuts', 1);
-
-                // set value initially
-                onTextChange();
-            });
-        }
         function init() {
             let parentSegment = $('#problems-center-{{$note->id}}');
             parentSegment.find('input[stag-suggest][data-name="name"]')
@@ -542,195 +332,7 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                     $(this).closest('form').find('input[data-name="icd-type"]').val($(this).find('option:selected').attr('data-icd-type'));
                 });
 
-            parentSegment.find('.additionReasonCategory_ui')
-                .off('change')
-                .on('change', function() {
-
-                    let form = $(this).closest('form');
-
-                    // additionReasonCategory
-                    // isRemoved
-                    // removalReasonCategory
-                    form.find('[name="isRemovedDueToEntryError"]').val('0');
-
-                    form.find('.start_date_ui').hide();
-                    form.find('.removalEffectiveDate_ui').hide();
-                    form.find('.removalReasonMemo_ui').hide();
-
-                    if(this.value === 'HISTORIC') {
-                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
-                        form.find('[name="isRemoved"]').val('1');
-                        form.find('.start_date_ui').show();
-                        form.find('.removalEffectiveDate_ui').show();
-                        form.find('.removalReasonMemo_ui').show();
-                    }
-                    else if(this.value === 'PRE_EXISTING') {
-                        form.find('[name="additionReasonCategory"]').val('ON_INTAKE');
-                        form.find('[name="isRemoved"]').val('0');
-                        form.find('.start_date_ui').show();
-                    }
-                    else if(this.value === 'NEW') {
-                        form.find('[name="additionReasonCategory"]').val('DURING_VISIT');
-                        form.find('[name="isRemoved"]').val('0');
-                        form.find('.start_date_ui').show().find('input').val('{{date('Y-m-d')}}');
-                    }
-
-                });
-
-            parentSegment.find('[name="isRemoved"], [name="isRemovedDueToEntryError"]')
-                .off('change')
-                .on('change', function () {
-                    let form = $(this).closest('form');
-
-                    form.find('.is_removed_ui_1').hide();
-                    if(form.find('[name="isRemoved"]').val() === '1') {
-                        form.find('.is_removed_ui_1').show();
-                    }
-
-                    form.find('.is_removed_ui_2').hide();
-                    if(form.find('[name="isRemoved"]').val() === '1' && form.find('[name="isRemovedDueToEntryError"]').val() !== '1') {
-                        form.find('.is_removed_ui_2').show();
-                    }
-                    return false;
-                });
-
-            parentSegment.find('#frm-add-problem')
-                .off('submit')
-                .on('submit', function () {
-
-                    let form = $(this);
-
-                    if (!form[0].checkValidity()) {
-                        form[0].reportValidity();
-                        return false;
-                    }
-
-                    // add [data-name] values to payload
-                    let dataField = form.find('[name="data"]').first();
-                    let parsed = null;
-                    if(dataField.val()) {
-                        parsed = JSON.parse(dataField.val());
-                    }
-                    form.find('[data-name]').each(function() {
-                        if(!parsed) parsed = {};
-
-                        let keys = $(this).attr('data-name').split('->');
-                        let currentNode = parsed;
-                        for (let i = 0; i < keys.length; i++) {
-                            if(i !== keys.length - 1) {
-                                if(typeof currentNode[keys[i]] === 'undefined') {
-                                    currentNode[keys[i]] = {};
-                                }
-                                currentNode = currentNode[keys[i]];
-                            }
-                            else {
-                                if($(this).is(':checkbox')) {
-                                    currentNode[keys[i]] = $(this).prop('checked');
-                                }
-                                else {
-                                    currentNode[keys[i]] = $(this).val();
-                                }
-                            }
-                        }
-
-                    });
-                    if(parsed) {
-                        dataField.val(JSON.stringify(parsed));
-                    }
-
-                    $.post(form.attr('action'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-                            hideMask();
-                            refreshDynamicStagPopup();
-                            $('.visit-segment[data-segment-template-name="intake_problems"]').find('.refresh-segment').trigger('click');
-                        }
-                    }, 'json');
-                    return false;
-                });
-
-            parentSegment.find('.frm-edit-problem')
-                .off('submit')
-                .on('submit', function () {
-
-                    let form = $(this);
-
-                    if (!form[0].checkValidity()) {
-                        form[0].reportValidity();
-                        return false;
-                    }
-
-                    // add [data-name] values to payload
-                    let dataField = form.find('[name="data"]').first();
-                    let parsed = null;
-                    if(dataField.val()) {
-                        parsed = JSON.parse(dataField.val());
-                    }
-                    form.find('[data-name]').each(function() {
-                        if(!parsed) parsed = {};
-
-                        let keys = $(this).attr('data-name').split('->');
-                        let currentNode = parsed;
-                        for (let i = 0; i < keys.length; i++) {
-                            if(i !== keys.length - 1) {
-                                if(typeof currentNode[keys[i]] === 'undefined') {
-                                    currentNode[keys[i]] = {};
-                                }
-                                currentNode = currentNode[keys[i]];
-                            }
-                            else {
-                                if($(this).is(':checkbox')) {
-                                    currentNode[keys[i]] = $(this).prop('checked');
-                                }
-                                else {
-                                    currentNode[keys[i]] = $(this).val();
-                                }
-                            }
-                        }
-
-                    });
-                    if(parsed) {
-                        dataField.val(JSON.stringify(parsed));
-                    }
-
-                    $.post(form.attr('url'), form.serialize(), _data => {
-                        if(!hasResponseError(_data)) {
-                            hideMask();
-                            refreshDynamicStagPopup();
-                            $('.visit-segment[data-segment-template-name="intake_problems"]').find('.refresh-segment').trigger('click');
-                        }
-                    }, 'json');
-                    return false;
-                });
-
-            parentSegment.find('.toggle-relevance')
-                .off('click.toggle-relevance')
-                .on('click.toggle-relevance', function () {
-                    if(+$(this).attr('data-relevant') === 0) {
-                        $.post('/api/visitPoint/markPointRelevantToNote', {
-                            noteUid: '{{$note->uid}}',
-                            pointUid: $(this).attr('data-point-uid')
-                        }, _data => {
-                            if(!hasResponseError(_data)) {
-                                refreshDynamicStagPopup();
-                            }
-                        }, 'json');
-                    }
-                    else {
-                        if($(this).attr('data-rel-uid')) {
-                            $.post('/api/visitPoint/undoMarkPointRelevantToNote', {
-                                uid: $(this).attr('data-rel-uid')
-                            }, _data => {
-                                if(!hasResponseError(_data)) {
-                                    refreshDynamicStagPopup();
-                                }
-                            }, 'json');
-                        }
-                        else {
-                            console.log('Error - missing rel uid');
-                        }
-                    }
-                    return false;
-                });
+            @include('app.patient.wizard-partials.common-script', ['label' => 'problem'])
 
             @if($patient->core_note_id !== $note->id)
             parentSegment.find('.regenerate-cc')
@@ -757,13 +359,8 @@ $ccSegment = $note->getSegmentByInternalName('chief_complaint');
                 });
             @endif
 
-            initStagSuggest();
-
-            parentSegment.find('.additionReasonCategory_ui').trigger('change');
-            parentSegment.find('[name="isRemoved"]').trigger('change');
-
             initSegmentMoes($('#problems-center-{{$note->id}}'));
-            initVisitMoeRTEs();
+            __initRTEs(parentSegment.find('[note-rte]:not(.ql-container)'));
         }
         addMCInitializer('problems-center-{{$note->id}}', init, '#problems-center-{{$note->id}}');
     }).call(window);

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

@@ -2,6 +2,77 @@ function __reset(_input) {
     _input.val(_input.attr('value') ? _input.attr('value') : '');
 }
 
+function __initRTEs(_collection) {
+    _collection.each(function() {
+
+        let noteRTE = $(this);
+
+        $(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).attr('data-field-name') ? $(this).attr('data-field-name') : 'free_text';
+
+        var el = this;
+        var existingContent = $(el).html();
+        var quill = new Quill(el, {
+            theme: 'snow',
+            modules: stagQuillConfig
+        });
+
+        var toolbar = $(quill.container).prev('.ql-toolbar');
+
+        // add button for new shortcut
+        if(!noteRTE.is('[use-shortcuts]') || !noteRTE.attr('use-shortcuts')) {
+            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);
+        }
+
+        quill.root.innerHTML = existingContent;
+
+        let onTextChange = function(delta, oldDelta, source) {
+            var content = quill.root.innerHTML;
+            let dataObject = {};
+            dataObject[fieldName] = content;
+            var dataValue = JSON.stringify(dataObject);
+            let pElem = $(el).closest('[visit-moe]');
+            if(!pElem.length) {
+                pElem = $(el).closest('form');
+            }
+            let v = pElem.find('input[name=data]').val();
+            if(!!v) {
+                try {
+                    v = JSON.parse(v);
+                    v[fieldName] = content;
+                    v = JSON.stringify(v);
+                }
+                catch (e) {
+                    v = JSON.stringify(dataObject);
+                }
+            }
+            else {
+                v = JSON.stringify(dataObject);
+            }
+            pElem.find('input[name=data]').val(v);
+        };
+
+        quill.on('text-change', onTextChange);
+
+        $(quill.container)
+            .find('.ql-editor[contenteditable]')
+            .attr('data-field', fieldName)
+            .attr('data-editor-id', editorID)
+            .attr('with-shortcuts', 1);
+
+        // set value initially
+        onTextChange();
+    });
+}
+
 parentSegment.find('[name="isRemoved"]')
     .off('change')
     .on('change', function () {