|
@@ -1,6 +1,14 @@
|
|
|
<script>
|
|
|
(function() {
|
|
|
|
|
|
+ function updateAllSegmentsInResponse(_response) {
|
|
|
+ if(!hasResponseError(_response)) {
|
|
|
+ for (let i=0; i<_response.data.length; i++) {
|
|
|
+ updateSegmentFromObject(_response.data[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function updateSegmentFromObject(_object) {
|
|
|
let segment = $('.note-section[data-segment-uid="' + _object.segmentUid + '"]');
|
|
|
if(segment && segment.length) {
|
|
@@ -17,12 +25,26 @@
|
|
|
.off('click.visit-moe-submit')
|
|
|
.on('click.visit-moe-submit', function() {
|
|
|
let form = $(this).closest('form');
|
|
|
+
|
|
|
+ // 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 = {};
|
|
|
+ parsed[$(this).attr('data-name')] = $(this).val();
|
|
|
+ });
|
|
|
+ if(parsed) {
|
|
|
+ dataField.val(JSON.stringify(parsed));
|
|
|
+ }
|
|
|
+
|
|
|
+ showMask();
|
|
|
+
|
|
|
$.post(form.attr('url'), form.serialize(), _data => {
|
|
|
- if(!hasResponseError(_data)) {
|
|
|
- for (let i=0; i<_data.data.length; i++) {
|
|
|
- updateSegmentFromObject(_data.data[i]);
|
|
|
- }
|
|
|
- }
|
|
|
+ hideMask();
|
|
|
+ updateAllSegmentsInResponse(_data);
|
|
|
}, 'json');
|
|
|
return false;
|
|
|
});
|
|
@@ -85,6 +107,20 @@
|
|
|
initRTEs(parent);
|
|
|
initSegmentMoes(parent);
|
|
|
|
|
|
+ // refresh segment
|
|
|
+ $(document)
|
|
|
+ .off('click.refresh-segment', '.refresh-segment')
|
|
|
+ .on('click.refresh-segment', '.refresh-segment', function() {
|
|
|
+ showMask();
|
|
|
+ $.post('/api/visit/updateSegmentHtml', {
|
|
|
+ segmentUid: $(this).attr('data-segment-uid')
|
|
|
+ }, _data => {
|
|
|
+ hideMask();
|
|
|
+ updateAllSegmentsInResponse(_data);
|
|
|
+ }, 'json');
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
/*
|
|
|
$('[btn-save-form]').on('click', function() {
|
|
|
doSave($(this).closest('.note-section'));
|
|
@@ -112,125 +148,6 @@
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- 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);
|
|
|
|
|
|
})();
|