Ver código fonte

Rx wizard - update add and edit forms

Vijayakrishnan 3 anos atrás
pai
commit
ef5637cae1

+ 26 - 398
resources/views/app/patient/medications-center.blade.php

@@ -35,12 +35,12 @@ $medications = $points;
                 <th class="border-bottom-0 text-secondary text-center width-30px">Rel.</th>
                 @endif
                 <th class="border-bottom-0 text-secondary">Name</th>
-                <th class="border-bottom-0 text-secondary w-25">Directions</th>
+                <th class="border-bottom-0 text-secondary w-25">Plan</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 w-25">Last Review</th>
+                <th class="border-bottom-0 text-secondary w-25">Review</th>
             </tr>
             </thead>
             <?php $prevRowRemoved = -1; ?>
@@ -146,9 +146,9 @@ $medications = $points;
                             <input type="hidden" name="noteUid" value="<?= $note->uid ?>">
                             <p class="mb-2"><b>Update Medication</b></p>
 
-                            @if($medication->added_in_note_id === $note->id)
+                            <input type="hidden" name="data" value='{{json_encode($medication->data)}}'>
 
-                                <input type="hidden" name="data">
+                            @if($medication->added_in_note_id === $note->id)
 
                                 <input type="hidden" data-name="medId" value="{{@$medication->data->medId}}">
                                 <input type="hidden" data-name="routedMedId" value="{{@$medication->data->routedMedId}}">
@@ -164,28 +164,6 @@ $medications = $points;
                                            stag-suggest-ep="/fdb-med-suggest-v2/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="{{@$medication->data->start_date}}"
-                                               class="form-control form-control-sm min-width-unset">
-                                    </div>
-                                    <div class="col-6">
-                                        <label class="text-sm mb-0">Prescribed By</label>
-                                        <input type="text"
-                                               data-name="prescriber"
-                                               value="{{@$medication->data->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">{{@$medication->data->description}}</textarea>
-                                </div>-->
-
                             @else
 
                                 <div class="mb-2 bg-light p-2 border">
@@ -201,70 +179,7 @@ $medications = $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" {{$medication->addition_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$medication->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="{{$medication->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 medication active?</label>
-                                    <select class="form-control form-control-sm min-width-unset" name="isRemoved" required>
-                                        <option value="">-- select --</option>
-                                        <option value="0" {{!$medication->is_removed ? 'selected' : ''}}>Yes</option>
-                                        <option value="1" {{$medication->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" {{$medication->is_removed_due_to_entry_error ? 'selected' : ''}}>Yes</option>
-                                        <option value="0" {{!$medication->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" {{$medication->removal_reason_category === 'ON_INTAKE' ? 'selected' : ''}}>On Intake</option>
-                                        <option value="DURING_VISIT" {{$medication->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="{{$medication->removal_effective_date ? $medication->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="{{$medication->removal_reason_memo}}"
-                                           class="form-control form-control-sm min-width-unset">
-                                </div>
-                            </div>
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'medication', 'point' => $medication])
 
                             <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>
@@ -329,11 +244,13 @@ $medications = $points;
                     <input type="hidden" data-name="routedDosageFormMedId">
                     <input type="hidden" data-name="gcnSeqno">
 
+                    <input type="hidden" name="isRemovedDueToEntryError" value="0">
+
                     <div class="row">
                         <div class="col-7">
                             <p class="mb-2"><b>Add Medication</b></p>
                             <div class="mb-2">
-                                <label class="text-sm mb-0">Name</label>
+                                <label class="mb-0">Name</label>
                                 <input type="text"
                                        data-name="name"
                                        class="form-control form-control-sm"
@@ -342,88 +259,10 @@ $medications = $points;
                                        stag-suggest-ep="/fdb-med-suggest-v2/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">Prescribed 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>-->
-
-                            @if($patient->core_note_id !== $note->id)
-                            <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>
-                            @endif
 
-                            <hr class="my-3">
+                            <?php $point = null; ?>
+                            @include('app.patient.wizard-partials.common-fields', ['label' => 'medication'])
 
-                            <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 medication 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>
                         </div>
                         <div class="col-5 border-left">
                             <div class="fdb-rx-vigilance max-height-400px overflow-auto">
@@ -484,7 +323,21 @@ $medications = $points;
                     if(!pElem.length) {
                         pElem = $(el).closest('form');
                     }
-                    pElem.find('input[name=data]').val(dataValue);
+                    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);
@@ -524,232 +377,7 @@ $medications = $points;
                     return false;
                 });
 
-            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-medication')
-                .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());
-                    }
-
-                    @if($patient->core_note_id !== $note->id)
-                    // 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;
-                    @endif
-
-                    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();
-
-                            // save child plan
-                            @if($patient->core_note_id !== $note->id)
-                                debugger
-                            $.post('/api/visitPoint/upsertChildPlan', {
-                                uid: _data.data,
-                                segmentUid: '{{$note->getSegmentByInternalName('plan_medications')->uid}}',
-                                data: JSON.stringify({value: planContent})
-                            }, _data => {
-                                if(!hasResponseError(_data)) {
-                                    refreshDynamicStagPopup();
-                                }
-                            }, 'json');
-                            @else
-                            refreshDynamicStagPopup();
-                            @endif
-
-                            $('.visit-segment[data-segment-template-name="intake_medications"]').find('.refresh-segment').trigger('click');
-                        }
-                    }, 'json');
-                    return false;
-                });
-
-            parentSegment.find('.frm-edit-medication')
-                .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_medications"]').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' => 'medication', 'point' => $medication])
 
             // custom buttons on title bar
             $('.button-container').remove();

+ 211 - 0
resources/views/app/patient/wizard-partials/common-fields.blade.php

@@ -0,0 +1,211 @@
+<div class="mb-2">
+    <span class="">Is this {{$label}} active?</span>
+    <div class="d-flex align-items-baseline mt-1">
+        <label class="my-0 d-inline-flex align-items-center">
+            <input type="radio" name="isRemoved" value="0" {{$point && !$point->is_removed ? 'checked' : ''}}>
+            <span class="ml-1">Yes</span>
+        </label>
+        <label class="ml-3 my-0 d-inline-flex align-items-center">
+            <input type="radio" name="isRemoved" value="1" {{$point && $point->is_removed ? 'checked' : ''}}>
+            <span class="ml-1">No</span>
+        </label>
+    </div>
+</div>
+
+<div if-active class="d-none">
+
+    <hr class="mb-2 mt-0">
+
+    <div class="mb-2">
+        <span class="">Is this pre-existing, or being added during this visit?</span>
+        <div class="d-flex align-items-baseline mt-1">
+            <label class="my-0 d-inline-flex align-items-center">
+                <input type="radio" name="additionReasonCategory" value="ON_INTAKE" {{$point && $point->addition_reason_category === 'ON_INTAKE' ? 'checked' : ''}}>
+                <span class="ml-1">Pre-existing</span>
+            </label>
+            <label class="ml-3 my-0 d-inline-flex align-items-center">
+                <input type="radio" name="additionReasonCategory" value="DURING_VISIT" {{$point && $point->addition_reason_category === 'DURING_VISIT' ? 'checked' : ''}}>
+                <span class="ml-1">Added during this visit (as part of my plan)</span>
+            </label>
+        </div>
+    </div>
+
+    <div if-addition-on-intake-or-during-visit class="d-none">
+        <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="{{@$point->data ? @$point->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="{{@$point->data ? @$point->data->prescriber : ''}}"
+                       class="form-control form-control-sm min-width-unset">
+            </div>
+        </div>
+    </div>
+
+</div>
+
+<div if-not-active class="d-none">
+
+    <hr class="mb-2 mt-0">
+
+    @if(@$point)
+        <div class="mb-2">
+            <span class="">Is this medication being removed due to an entry error?</span>
+            <div class="d-flex align-items-baseline mt-1">
+                <label class="my-0 d-inline-flex align-items-center">
+                    <input type="radio" name="isRemovedDueToEntryError" value="1" {{$point && $point->is_removed_due_to_entry_error === '1' ? 'checked' : ''}}>
+                    <span class="ml-1">Yes</span>
+                </label>
+                <label class="ml-3 my-0 d-inline-flex align-items-center">
+                    <input type="radio" name="isRemovedDueToEntryError" value="0" {{$point && $point->is_removed_due_to_entry_error === '0' ? 'checked' : ''}}>
+                    <span class="ml-1">No</span>
+                </label>
+            </div>
+        </div>
+    @endif
+
+    <div {{@$point ? 'if-not-entry-error class="d-none"' : ''}}>
+
+        <div class="mb-2">
+            <span class="">Was this {{$label}} removed PRIOR to this visit or DURING this visit?</span>
+            <div class="d-flex align-items-baseline mt-1">
+                <label class="my-0 d-inline-flex align-items-center">
+                    <input type="radio" name="removalReasonCategory" value="ON_INTAKE" {{$point && $point->removal_reason_category === 'ON_INTAKE' ? 'checked' : ''}}>
+                    <span class="ml-1">Prior to visit</span>
+                </label>
+                <label class="ml-3 my-0 d-inline-flex align-items-center">
+                    <input type="radio" name="removalReasonCategory" value="DURING_VISIT" {{$point && $point->removal_reason_category === 'DURING_VISIT' ? 'checked' : ''}}>
+                    <span class="ml-1">Removed during this visit</span>
+                </label>
+            </div>
+        </div>
+
+        <div if-removal-on-intake-or-during-visit class="d-none">
+            <div class="row mb-2">
+                <div class="col-6 pr-0">
+                    <label class="text-sm mb-0">End Date</label>
+                    <input type="date"
+                           name="removalEffectiveDate"
+                           value="{{@$point->removal_effective_date}}"
+                           class="form-control form-control-sm min-width-unset">
+                </div>
+                <div class="col-6">
+                    <label class="text-sm mb-0">Removal By/Memo</label>
+                    <input type="text"
+                           name="removalReasonMemo"
+                           value="{{@$point->removal_reason_memo}}"
+                           class="form-control form-control-sm min-width-unset">
+                </div>
+            </div>
+        </div>
+
+    </div>
+
+</div>
+
+<div {{@$point ? 'if-not-entry-error class="d-none"' : ''}}>
+    <div if-active-or-not-active class="d-none">
+
+    @if($patient->core_note_id !== $note->id)
+        <?php
+        $currentValue = '';
+        $previousValue = '';
+        $previousChildReview = null;
+        if (@$point) {
+            if ($point->lastChildReview && $point->last_child_review_point_scoped_note_id === $note->id) {
+                $parsedReview = json_decode($point->lastChildReview->data);
+                if (@$parsedReview->value) {
+                    $currentValue = $parsedReview->value;
+                    $previousChildReview = \App\Models\Point::where('id', '<', $point->lastChildReview->id)
+                        ->where('category', 'REVIEW')
+                        ->where('parent_point_id', $point->id)
+                        ->orderBy('id', 'DESC')
+                        ->first();
+                    if ($previousChildReview && $previousChildReview->data) {
+                        $parsedReview = json_decode($previousChildReview->data);
+                        $previousValue = $parsedReview->value;
+                    }
+                }
+            } else {
+                $previousChildReview = \App\Models\Point::where('parent_point_id', $point->id)
+                    ->where('category', 'REVIEW')
+                    ->orderBy('id', 'DESC')
+                    ->first();
+                if ($previousChildReview && $previousChildReview->data) {
+                    $parsedReview = json_decode($previousChildReview->data);
+                    if (@$parsedReview->value) {
+                        $previousValue = $parsedReview->value;
+                    }
+                }
+            }
+        }
+        ?>
+        <div class="mb-2">
+            <label class="text-sm mb-1">Review</label>
+            <?php if($previousValue): ?>
+            <div class="mb-2">
+                <div class="d-flex align-items-baseline mb-1">
+                    <span class="text-sm text-secondary">Previous Review / <?= friendlier_date($previousChildReview->created_at) ?>) (click to copy)</span>
+                </div>
+                <div class="p-2 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+            </div>
+            <?php endif; ?>
+            <div note-rte
+                 class="form-group mb-2 border-left border-right rte-holder bg-white"
+                 data-field-name="reviewValue"><?= $currentValue ?></div>
+        </div>
+
+        <?php
+        $currentValue = '';
+        $previousValue = '';
+        $previousChildPlan = null;
+        if (@$point) {
+            if ($point->lastChildPlan && $point->last_child_plan_point_scoped_note_id === $note->id) {
+                $parsedPlan = json_decode($point->lastChildPlan->data);
+                $currentValue = $parsedPlan->value;
+                $previousChildPlan = \App\Models\Point::where('id', '<', $point->lastChildPlan->id)
+                    ->where('category', 'PLAN')
+                    ->where('parent_point_id', $point->id)
+                    ->orderBy('id', 'DESC')
+                    ->first();
+                if ($previousChildPlan && $previousChildPlan->data) {
+                    $parsedPlan = json_decode($previousChildPlan->data);
+                    $previousValue = $parsedPlan->value;
+                }
+            } else {
+                $previousChildPlan = \App\Models\Point::where('parent_point_id', $point->id)
+                    ->where('category', 'PLAN')
+                    ->orderBy('id', 'DESC')
+                    ->first();
+                if ($previousChildPlan && $previousChildPlan->data) {
+                    $parsedPlan = json_decode($previousChildPlan->data);
+                    $previousValue = $parsedPlan->value;
+                }
+            }
+        }
+        ?>
+        <div class="mb-2">
+            <label class="text-sm mb-1">Plan</label>
+            <?php if($previousValue): ?>
+            <div class="mb-2">
+                <div class="d-flex align-items-baseline mb-1">
+                    <span class="text-sm text-secondary">Previous Plan / <?= friendlier_date($previousChildPlan->created_at) ?>) (click to copy)</span>
+                </div>
+                <div class="p-2 bg-light border inline-html-container click-to-copy"><?= $previousValue ?></div>
+            </div>
+            <?php endif; ?>
+            <div note-rte
+                 class="form-group mb-2 border-left border-right rte-holder bg-white"
+                 data-field-name="planValue"><?= $currentValue ?></div>
+        </div>
+    @endif
+
+    </div>
+</div>

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

@@ -0,0 +1,263 @@
+parentSegment.find('[name="isRemoved"]')
+    .off('change')
+    .on('change', function () {
+        let form = $(this).closest('form');
+        form.find('[if-active-or-not-active], [if-active], [if-not-active]').addClass('d-none');
+        if(form.find('[name="isRemoved"]:checked').length) form.find('[if-active-or-not-active]').removeClass('d-none');
+        if(form.find('[name="isRemoved"]:checked').val() === '1') form.find('[if-not-active]').removeClass('d-none');
+        else if(form.find('[name="isRemoved"]:checked').val() === '0') {
+            form.find('[if-active]').removeClass('d-none');
+            form.find('[name="removalEffectiveDate"]').val('');
+            form.find('[name="removalReasonMemo"]').val('');
+        }
+        return false;
+    })
+    .trigger('change');
+
+parentSegment.find('[name="additionReasonCategory"]')
+    .off('change')
+    .on('change', function () {
+        let form = $(this).closest('form');
+        form.find('[if-addition-on-intake-or-during-visit], [if-addition-on-intake], [if-addition-during-visit]').addClass('d-none');
+        if(form.find('[name="additionReasonCategory"]:checked').length) form.find('[if-addition-on-intake-or-during-visit]').removeClass('d-none');
+        if(form.find('[name="additionReasonCategory"]:checked').val() === 'ON_INTAKE') {
+            form.find('[if-addition-on-intake]').removeClass('d-none');
+            form.find('[data-name="start_date"]').val('');
+            form.find('[data-name="prescriber"]').val('');
+        }
+        else if(form.find('[name="additionReasonCategory"]:checked').val() === 'DURING_VISIT') {
+            form.find('[if-addition-during-visit]').removeClass('d-none');
+            form.find('[data-name="start_date"]').val('{{$patient->core_note_id !== $note->id ? $note->effective_dateest : date("Y-m-d")}}');
+            form.find('[data-name="prescriber"]').val('{{$patient->core_note_id !== $note->id ? ($note->hcpPro ? $note->hcpPro->displayName() : "")  : ""}}');
+        }
+        return false;
+    })
+    .trigger('change');
+
+parentSegment.find('[name="removalReasonCategory"]')
+    .off('change')
+    .on('change', function () {
+        let form = $(this).closest('form');
+        form.find('[if-removal-on-intake-or-during-visit], [if-removal-on-intake], [if-removal-during-visit]').addClass('d-none');
+        if(form.find('[name="removalReasonCategory"]:checked').length) form.find('[if-removal-on-intake-or-during-visit]').removeClass('d-none');
+        if(form.find('[name="removalReasonCategory"]:checked').val() === 'ON_INTAKE') {
+            form.find('[if-removal-on-intake]').removeClass('d-none');
+            form.find('[name="removalEffectiveDate"]').val('');
+            form.find('[name="removalReasonMemo"]').val('');
+        }
+        else if(form.find('[name="removalReasonCategory"]:checked').val() === 'DURING_VISIT') {
+            form.find('[if-removal-during-visit]').removeClass('d-none');
+            form.find('[name="removalEffectiveDate"]').val('{{$patient->core_note_id !== $note->id ? $note->effective_dateest : date("Y-m-d")}}');
+            form.find('[name="removalReasonMemo"]').val('{{$patient->core_note_id !== $note->id ? ($note->hcpPro ? $note->hcpPro->displayName() : "")  : ""}}');
+        }
+        return false;
+    })
+    .trigger('change');
+
+parentSegment.find('[name="isRemovedDueToEntryError"]')
+    .off('change')
+    .on('change', function () {
+        let form = $(this).closest('form');
+        form.find('[if-not-entry-error]').removeClass('d-none');
+        if(form.find('[name="isRemovedDueToEntryError"]:checked').val() === '1') form.find('[if-not-entry-error]').addClass('d-none');
+        return false;
+    })
+    .trigger('change');
+
+parentSegment.find('#frm-add-{{$label}}')
+    .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());
+        }
+
+        @if($patient->core_note_id !== $note->id)
+        // store plan content
+        let planContent = parsed && parsed.planValue ? parsed.planValue : '';
+        let reviewContent = parsed && parsed.reviewValue ? parsed.reviewValue : '';
+        // if(!$.trim($('<div/>').html(planContent).text())) {
+        //     toastr.error('Directions cannot be empty');
+        //     return false;
+        // }
+        if(parsed.planValue) delete parsed.planValue;
+        if(parsed.reviewValue) delete parsed.reviewValue;
+        @endif
+
+        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));
+        }
+
+        let payload = {};
+        form.serializeArray().map(x => {payload[x.name] = x.value;});
+        @if($patient->core_note_id !== $note->id)
+        if(!!reviewContent) {
+            payload.childReviewData = JSON.stringify({
+                value: reviewContent
+            })
+        }
+        if(!!planContent) {
+            payload.childPlanData = JSON.stringify({
+                value: planContent
+            })
+        }
+        @endif
+
+        $.post(form.attr('action'), payload, _data => {
+            if(!hasResponseError(_data)) {
+                hideMask();
+                refreshDynamicStagPopup();
+                $('.visit-segment[data-segment-template-name="intake_{{$label}}s"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="plan_{{$label}}s"]').find('.refresh-segment').trigger('click');
+            }
+        }, 'json');
+        return false;
+    });
+
+parentSegment.find('.frm-edit-{{$label}}')
+    .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());
+        }
+
+        @if($patient->core_note_id !== $note->id)
+        // store plan content
+        let planContent = parsed && parsed.planValue ? parsed.planValue : '';
+        let reviewContent = parsed && parsed.reviewValue ? parsed.reviewValue : '';
+        // if(!$.trim($('<div/>').html(planContent).text())) {
+        //     toastr.error('Directions cannot be empty');
+        //     return false;
+        // }
+        if(parsed.planValue) delete parsed.planValue;
+        if(parsed.reviewValue) delete parsed.reviewValue;
+        @endif
+
+        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));
+        }
+
+        let payload = {};
+        form.serializeArray().map(x => {payload[x.name] = x.value;});
+        @if($patient->core_note_id !== $note->id)
+        if(!!reviewContent) {
+            payload.childReviewData = JSON.stringify({
+                value: reviewContent
+            })
+        }
+        if(!!planContent) {
+            payload.childPlanData = JSON.stringify({
+                value: planContent
+            })
+        }
+        @endif
+
+        $.post(form.attr('url'), payload, _data => {
+            if(!hasResponseError(_data)) {
+                hideMask();
+                refreshDynamicStagPopup();
+                $('.visit-segment[data-segment-template-name="intake_{{$label}}s"]').find('.refresh-segment').trigger('click');
+                $('.visit-segment[data-segment-template-name="plan_{{$label}}s"]').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();