Forráskód Böngészése

Visit UI - update segment-refresh, toggle-edit, model relations

Vijayakrishnan 3 éve
szülő
commit
f029346047

+ 3 - 0
app/Http/Controllers/NoteController.php

@@ -87,6 +87,9 @@ class NoteController extends Controller
         $segment = Segment::where('uid', $segmentUid)->first();
         $segmentTemplate = $segment->segmentTemplate;
 
+        $note = $segment->note;
+        $patient = $note->client;
+
         ob_start();
         include(resource_path('views/app/patient/segment-templates/' . $segmentTemplate->internal_name . '/summary.php'));
         $summaryHtml = ob_get_contents();

+ 1 - 1
app/Models/Segment.php

@@ -17,6 +17,6 @@ class Segment extends Model
     }
 
     public function client() {
-        return $this->hasOne(Section::class, 'id', 'client_id');
+        return $this->hasOne(Client::class, 'id', 'client_id');
     }
 }

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

@@ -289,7 +289,7 @@
                     return false;
                 });
 
-                $(document)
+                /*$(document)
                     .off('mousedown.enable-edit', '.note-section:not(.edit):not(.page-driven)')
                     .on('mousedown.enable-edit', '.note-section:not(.edit):not(.page-driven)', function(e) {
                         if($(this).closest('.note-signed-by-hcp').length) return;
@@ -297,7 +297,7 @@
                         e.preventDefault();
                         $(this).find('.edit-trigger').first().click();
                         return false;
-                    });
+                    });*/
 
                 // $(document)
                 //     .off('mousedown.enable-edit', '.note-section:not(.edit).page-driven')

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

@@ -11,19 +11,11 @@
 		</span>
 
 		<!-- refresh -->
-		<div moe class="ml-2 d-none if-edit">
-			<a start show class="font-weight-normal" title="Update with latest patient data">
-				<i class="fa fa-sync"></i>
-			</a>
-			<form url="/api/visit/updateSegmentHtml">
-				<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>
-					<button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
-				</div>
-			</form>
-		</div>
+		<a class="ml-3 font-weight-normal refresh-segment c-pointer"
+		   data-segment-uid="{{$segment->uid}}"
+		   title="Update with latest patient data">
+			<i class="fa fa-sync"></i>
+		</a>
 
 		<!-- toggle to read mode -->
 		<a class="ml-auto edit-trigger d-none if-edit c-pointer">Close</a>

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

@@ -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);
 
     })();

+ 55 - 1
resources/views/app/patient/segment-templates/intake_medications/edit.php

@@ -1 +1,55 @@
-<h1>Edit for intake_medications</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$medicationsAddedOnIntake = Point::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->where('addition_reason_category', 'ADDED_ON_INTAKE')
+    ->where('is_removed', false)
+    ->orderBy('created_at')
+    ->get();
+
+$medicationsRemovedOnIntake = Point::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->where('addition_reason_category', 'ADDED_ON_INTAKE')
+    ->where('is_removed', true)
+    ->where('removed_in_note_id', $note->id)
+    ->orderBy('created_at')
+    ->get();
+
+?>
+<div>
+
+    <div visit-moe>
+        <b>Add New</b>
+        <form url="/api/visitPoint/addTopLevelOnIntake" class="mcp-theme-1">
+            <input type="hidden" name="segmentUid" value="<?= $segment->uid ?>">
+            <input type="hidden" name="category" value="MEDICATION">
+            <input type="hidden" name="data">
+
+            <div>
+                <input type="text" data-name="name" placeholder="name">
+            </div>
+            <div>
+                <input type="text" data-name="dose" placeholder="dose">
+            </div>
+            <div>
+                <input type="text" data-name="route" placeholder="route">
+            </div>
+            <div>
+                <input type="text" data-name="frequency" placeholder="frequency">
+            </div>
+            <div>
+                <input type="text" data-name="description" placeholder="description">
+            </div>
+
+            <div>
+                <button submit class="btn btn-sm btn-primary mr-2">Submit</button>
+                <button cancel class="btn btn-sm btn-default border">Cancel</button>
+            </div>
+        </form>
+    </div>
+</div>
+

+ 57 - 1
resources/views/app/patient/segment-templates/intake_medications/summary.php

@@ -1 +1,57 @@
-<h1>Summary for intake_medications</h1>
+<?php
+
+use App\Models\Point;
+
+/** @var \App\Models\Client $patient */
+
+$medications = Point
+    ::where('client_id', $patient->id)
+    ->where('category', 'MEDICATION')
+    ->where('addition_reason_category', 'ON_INTAKE')
+    ->where(function ($query1) use ($note) {
+        $query1
+            ->where('is_removed', false)
+            ->orWhere(function ($query2) use ($note) {
+                $query2->where('is_removed', true)
+                ->where('removed_in_note_id', $note->id);
+            });
+    })
+    ->orderBy('created_at')
+    ->get();
+
+foreach ($medications as $medication) {
+    if($medication->data) {
+        $medication->data = json_decode($medication->data);
+    }
+}
+
+?>
+
+<?php if(!count($medications)): ?>
+    <div>No medications</div>
+<?php else: ?>
+    <div class="d-flex">
+        <table>
+            <thead>
+            <tr>
+                <th>Medication</th>
+                <th>Dose</th>
+                <th>Route</th>
+                <th>Frequency</th>
+                <th></th>
+            </tr>
+            </thead>
+            <?php foreach($medications as $medication): ?>
+                <tr>
+                    <td><?= @$medication->data->name ?></td>
+                    <td><?= @$medication->data->dose ?></td>
+                    <td><?= @$medication->data->route ?></td>
+                    <td><?= @$medication->data->frequency ?></td>
+                    <td></td>
+                </tr>
+            <?php endforeach; ?>
+
+        </table>
+    </div>
+<?php endif; ?>
+