瀏覽代碼

Rx wizard - add/edit review

Vijayakrishnan 3 年之前
父節點
當前提交
53ba2ce3bd

+ 16 - 0
app/Models/Note.php

@@ -83,6 +83,22 @@ class Note extends Model
             ->orderBy('position_index', 'asc');
     }
 
+    public function coreSegment()
+    {
+        return $this->hasOne(Segment::class, 'id', 'core_segment_id');
+    }
+
+    public function getSegmentByInternalName($_name) {
+        $segmentTemplate = SegmentTemplate::where('internal_name', $_name)->first();
+        if(!!$segmentTemplate) {
+            return Segment::where('note_id', $this->id)
+                ->where('id', '!=', $this->core_segment_id) // dont include core-segment
+                ->where('segment_template_id', $segmentTemplate->id)
+                ->first();
+        }
+        return null;
+    }
+
     public function reasons()
     {
         return $this->hasMany(NoteReason::class, 'note_id', 'id');

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

@@ -292,14 +292,22 @@ $medications = $points;
                             include resource_path('views/app/patient/segment-templates/_child_review/last-review.php');
                             ?>
                         </div>
-                        <a class="px-2 view-review-log"
-                           native target="_blank"
-                           open-in-stag-popup
-                           popup-style="stag-popup-md"
-                           title="Review log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
-                           href="/point/review-log/<?= $medication->uid ?>?popupmode=1">
-                            <i class="fa fa-history"></i>
-                        </a>
+                        <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="Review log<?= !!@($medication->data->name) ? ' for ' . @($medication->data->name) : '' ?>"
+                               href="/point/review-log/<?= $medication->uid ?>?popupmode=1">
+                                <i class="fa fa-history"></i>
+                            </a>
+                            <?php
+                            $segment = $note->getSegmentByInternalName('intake_medications');
+                            if($segment) {
+                                include resource_path('views/app/patient/segment-templates/_child_review/edit-review.php');
+                            }
+                            ?>
+                        </div>
                     </div>
                 </td>
                 <td>
@@ -428,6 +436,49 @@ $medications = $points;
 
 <script>
     (function() {
+        function initVisitMoeRTEs() {
+            $('.stag-popup [visit-moe]').find('[note-rte]:not(.ql-container)').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;
+
+                quill.on('text-change', function(delta, oldDelta, source) {
+                    var content = quill.root.innerHTML;
+                    let dataObject = {};
+                    dataObject[fieldName] = content;
+                    var dataValue = JSON.stringify(dataObject);
+                    $(el).closest('[visit-moe]').find('input[name=data]').val(dataValue);
+                });
+
+                $(quill.container)
+                    .find('.ql-editor[contenteditable]')
+                    .attr('data-field', fieldName)
+                    .attr('data-editor-id', editorID)
+                    .attr('with-shortcuts', 1);
+            });
+        }
         function init() {
             let parentSegment = $('#medications-center-{{$note->id}}');
             parentSegment.find('input[stag-suggest][data-name="name"]')
@@ -625,7 +676,10 @@ $medications = $points;
                 .appendTo(buttonContainer);
 
             buttonContainer.insertAfter(titleElem);
+
+            initSegmentMoes($('#medications-center-{{$note->id}}'));
+            initVisitMoeRTEs();
         }
-        addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}')
+        addMCInitializer('medications-center-{{$note->id}}', init, '#medications-center-{{$note->id}}');
     }).call(window);
 </script>

+ 1 - 1
resources/views/app/patient/note/segment_script.blade.php

@@ -162,7 +162,7 @@
             return false;
         }
 
-        function initSegmentMoes(_parent) {
+        window.initSegmentMoes = function(_parent) {
 
             $('body')
                 .off('mousedown.visit-moe-outside-click')