Vijayakrishnan před 3 roky
rodič
revize
6f1d4eb417

+ 6 - 3
resources/views/app/patient/note/note-segment-list.blade.php

@@ -1,3 +1,6 @@
-@foreach($note->segments as $segment)
-@include('app.patient.note.segment')
-@endforeach
+<div class="segments-list">
+    @foreach($note->segments as $segment)
+        @include('app.patient.note.segment')
+    @endforeach
+</div>
+@include('app.patient.note.segment_script')

+ 2 - 2
resources/views/app/patient/note/segment.blade.php

@@ -16,7 +16,7 @@
 				<i class="fa fa-sync"></i>
 			</a>
 			<form url="/api/visit/updateSegmentHtml">
-				<p>Update this section with latest patient data?</p>
+				<p>Update with latest patient data?</p>
 				<input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
 				<div class="d-flex align-items-center">
 					<button class="btn btn-sm btn-primary mr-2" type="button" submit>Update</button>
@@ -33,7 +33,7 @@
 		{!! $segment->summary_html !!}
 	</div>
 
-	<div class="d-none if-edit">
+	<div class="d-none if-edit edit-container">
     	{!! $segment->edit_html !!}
 	</div>
 

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

@@ -0,0 +1,237 @@
+<script>
+    (function() {
+
+        function updateSegmentFromObject(_object) {
+            let segment = $('.note-section[data-segment-uid="' + _object.segmentUid + '"]');
+            if(segment && segment.length) {
+                segment.find('.summary-container').html(_object.summaryHtml);
+                segment.find('.edit-container').html(_object.editHtml);
+                initRTEs(segment);
+                initSegmentMoes(segment);
+                segment.removeClass('edit');
+            }
+        }
+
+        function initSegmentMoes(_parent) {
+            _parent.find('[visit-moe] [submit]')
+                .off('click.visit-moe-submit')
+                .on('click.visit-moe-submit', function() {
+                    let form = $(this).closest('form');
+                    $.post(form.attr('url'), form.serialize(), _data => {
+                        if(!hasResponseError(_data)) {
+                            for (let i=0; i<_data.data.length; i++) {
+                                updateSegmentFromObject(_data.data[i]);
+                            }
+                        }
+                    }, 'json');
+                    return false;
+                });
+
+            _parent.find('[visit-moe] [cancel]')
+                .off('click.visit-moe-cancel')
+                .on('click.visit-moe-cancel', function() {
+                    $(this).closest('.note-section').removeClass('edit');
+                    return false;
+                });
+        }
+
+        function initRTEs(_parent) {
+            _parent.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.name;
+
+                var el = this;
+                var existingContent = $(el).attr('data-content');
+                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;
+                    var dataValue = JSON.stringify({
+                        value: content
+                    });
+                    var dataField = $(el).closest('.note-section').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 parent = $('.segments-list');
+            initRTEs(parent);
+            initSegmentMoes(parent);
+
+            /*
+            $('[btn-save-form]').on('click', function() {
+                doSave($(this).closest('.note-section'));
+            });
+
+            @if(isset($guestAccessCode))
+                $('.note-section form').append("<input type='hidden' name='guest_access_code' value='{{$guestAccessCode}}'/>");
+            @endif
+
+            // copy link
+            $(document)
+                .off('click.copy', '.copy-link')
+                .on('click.copy', '.copy-link', function() {
+                    var copyText = $('#' + $(this).attr('data-id'));
+                    copyText.focus().select();
+                    document.execCommand("copy");
+                    toastr.success("The link " + copyText.val() + " has been copied to the clipboard");
+                    return false;
+                });
+
+            // [name="data"] change listener
+            $('.note-section input[name="data"], .note-section input[name="items"]').each(function() {
+                initChangeListener($(this));
+            });
+             */
+        }
+
+        /*
+        const debounce = (func, wait) => {
+            let timeout;
+
+            return function executedFunction(...args) {
+                const later = () => {
+                    clearTimeout(timeout);
+                    func(...args);
+                };
+
+                clearTimeout(timeout);
+                timeout = setTimeout(later, wait);
+            };
+        };
+
+        function doSave(_section) {
+            console.log(_section.attr('data-section-template-name'));
+
+            _section.find('[btn-save-form]').prop('disabled', true);
+            _section.find('.text-saving').removeClass('d-none');
+            _section.find('.text-saved').addClass('d-none');
+
+            var dataField = _section.find('input[name=data]')
+            var value = $(dataField).val();
+
+            var summaryContainer = _section.find('.summary-container')
+
+            var sectionUid = _section.attr('data-section-uid')
+
+            var _form = _section.find('form[processed]')[0];
+            if(_form){
+                console.log("Form found. submitting normally");
+                $.post("/process_form_submit", $(_form).serialize(), function(resp) {
+                    handleSubmitResponse(resp,_section, summaryContainer)
+                }, 'json');
+            }else{
+                console.log("Form not found.");
+                var dataToPost = {
+                    "section_uid": sectionUid,
+                    "data": value,
+                }
+                @if(isset($guestAccessCode))
+                    dataToPost['guest_access_code'] = '{{$guestAccessCode}}';
+                @endif
+                $.post("/process_form_submit", dataToPost, function(resp) {
+                    handleSubmitResponse(resp,_section, summaryContainer);
+
+                    // if "dx", refresh "cc" if it exists in the note
+                    if(_section.attr('data-section-template-name') === 'dx') {
+                        let ccSection = $('[data-section-template-name="cc"]').first();
+                        if(ccSection.length) {
+                            let ccSectionUid = ccSection.attr('data-section-uid');
+                            let items = JSON.parse(value);
+                            if(items && items.items) {
+                                items = items.items
+                                    .filter((_x) => {
+                                        return !!_x.included;
+                                    })
+                                    .map((_x) => {
+                                        return _x.title;
+                                    });
+                            }
+                            let itemsText = '';
+                            if(items.length > 1) {
+                                let lastItem = items[items.length - 1];
+                                items.splice(items.length - 1, 1);
+                                itemsText = items.join(', ') + ' and ' + lastItem;
+                            }
+                            else {
+                                itemsText = items[0];
+                            }
+                            if(!!itemsText && !!ccSectionUid) {
+                                let ccValue = 'Patient {{$patient->name_first . ' ' . $patient->name_last}} ' +
+                                    'is a {{$patient->age_in_years}} year old {{$patient->sex}} with a history of ' +
+                                    itemsText + ' ' +
+                                    '{{ @$note ? (@$note->new_or_fu_or_na === 'NEW' ? 'presenting for establishing care' : 'presenting for follow-up') : '' }}.';
+                                let para = $('<p/>').text(ccValue)[0].outerHTML;
+                                ccSection.find('[name="data"]').first().val(JSON.stringify({value: para}));
+                                ccSection.find('.ql-editor').html(para);
+                                ccSection.find('[btn-save-form]').click();
+                            }
+                        }
+                    }
+
+                }, 'json');
+            }
+        }
+
+        function handleSubmitResponse(resp,_section, summaryContainer){
+            $('body').removeClass('blocking-mode');
+            hideMoeFormMask();
+            if (resp.success) {
+                summaryContainer.html(resp.newSummaryHtml);
+            }
+            _section.find('[btn-save-form]').prop('disabled', false);
+            _section.find('.text-saving').addClass('d-none');
+            if(resp.success) {
+                _section.find('.text-saved').text('Last saved at ' + (new Date().toLocaleTimeString())).removeClass('d-none');
+            }
+        }
+
+        function initChangeListener(_elem) {
+            new MutationObserver(debounce(function() {
+                if(_elem.closest('.note-section').is('.edit')) {
+                    // console.log('ALIX: In edit mode. Auto-saving', _elem.closest('.note-section').attr('data-section-template-name'))
+                    $('body').addClass('blocking-mode');
+                    showMoeFormMask('blocking-overlay');
+                    doSave(_elem.closest('.note-section'));
+                }
+                else {
+                    // console.log('ALIX: Not in edit mode. Not auto-saving', _elem.closest('.note-section').attr('data-section-template-name'))
+                }
+            }, 250))
+            .observe(_elem[0], {
+                attributes: true
+            });
+        }
+        */
+
+        addMCInitializer('note-segments-list', init);
+
+    })();
+</script>