Parcourir la source

fixed simple note

Josh il y a 4 ans
Parent
commit
880bd12b68

+ 49 - 98
app/Http/Controllers/NoteController.php

@@ -14,7 +14,8 @@ use App\Models\SectionTemplate;
 
 class NoteController extends Controller
 {
-    public function dashboard(Request $request, Client $patient, Note $note )
+    
+    public function dashboard(Request $request, Client $patient, Note $note)
     {
         $pros = Pro::all();
         $noteSections = $note->sections;
@@ -22,7 +23,7 @@ class NoteController extends Controller
         foreach ($allSections as $section) {
             $section->used = false;
             foreach ($noteSections as $noteSection) {
-                if($noteSection->sectionTemplate->id === $section->id) {
+                if ($noteSection->sectionTemplate->id === $section->id) {
                     $section->used = true;
                     $section->section_uid = $noteSection->uid;
                     break;
@@ -41,136 +42,86 @@ class NoteController extends Controller
         return view('client/note', compact('note', 'client'));
     }
 
-    public function sectionCreateForm($note_uid, $section_template_uid, Request $request)
+    // JAVA ONLY
+    public function getDefaultValueForSection($patientID, $sectionTemplateID)
     {
-        $note = Note::where('uid', $note_uid)->first();
-        $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
-        $section = null; // convenience
-        include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
+        $contentData = [];
+        $summaryHtml = '';
+        $patient = Client::where('id', $patientID)->first();
+        $sectionTemplate = SectionTemplate::where('id', $sectionTemplateID)->first();
+        
+        if (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'))) {
+            // default should simply assign to $contentData and $summaryHtml as needed
+            include(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'));
+        }
+        return [
+            'contentData' => $contentData,
+            'summaryHtml' => $summaryHtml
+        ];
     }
 
-    public function sectionUpdateForm($section_uid, Request $request)
+    public function processFormSubmit(Request $request)
     {
+        // TODO require
+        $section_uid =  $request->get('section_uid');
+
         $section = Section::where('uid', $section_uid)->first();
         $note = Note::where('id', $section->note_id)->first();
         $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
-        include(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'));
-    }
-
-    public function getDefaultValueForSection($section, $patient_uid) {
-        $defaultData = [
-            "summary" => "",
-            "value" => ""
-        ];
-        $patient = Client::where('uid', $patient_uid)->first();
-        if(file_exists(storage_path('sections/' . $section . '/default.php'))) {
-            include(storage_path('sections/' . $section . '/default.php'));
-        }
-        return json_encode($defaultData);
-    }
-
-    public function processFormSubmit(Request $request)
-    {
-        // for CREATE
-        $note_uid =  $request->note_uid;
-        $section_template_uid =  $request->section_template_uid;
-
-        // for UPDATE
-        $section_uid =  $request->section_uid;
-
-        $section = $section_uid ? Section::where('uid', $section_uid)->first() : null;
-        $note = null;
-        $sectionTemplate = null;
-
-        // if CREATE
-        if($section == null){
-            // TODO require valid note_uid & section_template_uid
-            $note = Note::where('uid', $note_uid)->first();
-            $sectionTemplate = SectionTemplate::where('uid', $section_template_uid)->first();
-        } else {
-            $note = Note::where('id', $section->note_id)->first();
-            $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
-        }
 
-        // our intention is to now process a submit...
-        // ... the point of which is to have newContentData and newSummaryHtml
         $newContentData = [];
         $newSummaryHtml = "";
 
-        // we wish to pass THESE arguments into this include:
-        // if CREATE, $note and $sectionTemplate, and $request
-        // if UPDATE, $section, and $request
-
-        // remember: the existence of form.php overrides section_template.is_canvas == TRUE
+        $sectionInternalName = $sectionTemplate->internal_name;
+        if ($sectionTemplate->is_canvas) {
 
-        if($sectionTemplate->is_canvas){
-            if(file_exists()){
-                include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
-            }else{
+            if (file_exists("app.patient.canvas-sections.{$sectionInternalName}.processor")) {
+                include("app.patient.canvas-sections.{$sectionInternalName}.processor");
+            } else {
                 $newContentData = json_decode($request->get('data'), true);
             }
             ob_start();
-            // TODO include the resource_path
-            include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
+            include("app.patient.canvas-sections.{$sectionInternalName}.summary");
             $newSummaryHtml = ob_get_contents();
             ob_end_clean();
-        }elseif(file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'))) {
+        } elseif (file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/form.blade.php'))) {
 
             include(storage_path('sections/' . $sectionTemplate->internal_name . '/processor.php'));
 
-            // now, create summaryHtml appropriate
             ob_start();
             include(storage_path('sections/' . $sectionTemplate->internal_name . '/summary.php'));
             $newSummaryHtml = ob_get_contents();
             ob_end_clean();
-        }else{
+        } else {
+
             $newContentData = json_decode($request->get('data'), true);
-            if(isset($newContentData['value'])){
+            if (isset($newContentData['value'])) {
                 $newSummaryHtml = $newContentData['value'];
             }
         }
 
         $response = null;
-        if($section){
-            // call Java to update section
-            $data = [
-                'uid' => $section->uid,
-                'contentData' => json_encode($newContentData),
-                'summaryHtml' => $newSummaryHtml
-            ];
-            $response = $this->calljava($request, '/section/update', $data);
-            //TODO: handle if response->success == false
-        }else{
-            // call Java to create section
-            // if default.php, run it to hydrate $newContentData and $newSummaryHtml
-
-            if(file_exists(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'))) {
-                include(storage_path('sections/' . $sectionTemplate->internal_name . '/default.php'));
-            }
-
-            $data = [
-                'noteUid' => $note->uid,
-                'sectionTemplateUid' => $sectionTemplate->uid,
-                'contentData' => json_encode($newContentData),
-                'summaryHtml' => $newSummaryHtml
-            ];
-
-            $response = $this->callJava($request, '/section/create', $data);
-            //TODO: handle if response->success == false
-        }
-        return redirect(route('patients.view.notes',$note->client->uid));
-         return [
-             'success' => $response->success,
-             'newSummaryHtml' => $newSummaryHtml
-         ];
+        $data = [
+            'uid' => $section->uid,
+            'contentData' => json_encode($newContentData),
+            'summaryHtml' => $newSummaryHtml
+        ];
+        $response = $this->calljava($request, '/section/update', $data);
+        return [
+            'success' => $response['success'],
+            'newSummaryHtml' => $newSummaryHtml
+        ];
     }
 
-    private function callJava($request, $endPoint, $data){
+    // TODO move to utility
+    private function callJava($request, $endPoint, $data)
+    {
         $url =  config('stag.backendUrl') . $endPoint;
         $response = Http::asForm()
-        ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
-        ->post($url, $data)
-        ->json();
+            ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
+            ->post($url, $data)
+            ->json();
         return $response;
     }
+
 }

+ 1 - 1
public/js/mc.js

@@ -349,6 +349,6 @@ function initPatientPresenceIndicator() {
                     }
                 }, 'json');
             }
-        }, 2500);
+        }, 2500000);
     }
 }

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

@@ -576,27 +576,7 @@
                         return false;
                     });
 
-                $('.note-section.pending-initialization').each(function() {
-                    let sName = $(this).attr('data-section-template-name');
-                    if(['vitals', 'allergies', 'medication', 'care-team', 'assessment', 'new-patient-intake', 'cc'].indexOf(sName) === -1) {
-                        $(this).removeClass('pending-initialization');
-                    }
-                });
-
-                let sectionsPendingInitialization = $('.note-section.pending-initialization');
-                numSectionsPendingInitialization = sectionsPendingInitialization.length;
-                if(numSectionsPendingInitialization > 0) {
-                    showMask('Initializing note. Please wait...');
-                    sectionsPendingInitialization.each(function() {
-                        initializeSection(
-                            $(this).attr('data-section-uid'),
-                            $(this).attr('data-section-template-name')
-                        );
-                    });
-                }
-                else {
-                    scrollToLatest();
-                }
+                scrollToLatest();
 
                 function __moveSection(_uid, _direction) {
                     $.post('/api/section/move' + _direction, {
@@ -641,33 +621,6 @@
                 }, 100);
             }
 
-            function initializeSection(_sectionUid, _sectionTemplateName) {
-                $.get('/get-default-section-data/' + _sectionTemplateName + '/{{$patient->uid}}' , function(_data) {
-                    if(!_data) {
-                        numSectionsPendingInitialization--;
-                        if(numSectionsPendingInitialization <= 0) {
-                            fastReload();
-                        }
-                        return;
-                    }
-                    let payload = {
-                        section_uid: _sectionUid
-                    };
-                    for(let x in _data) {
-                        if(_data.hasOwnProperty(x)) {
-                            payload[x] = _data[x];
-                        }
-                    }
-                    $.post('/process_form_submit', payload, function(_data) {
-                        console.log('done: ', _sectionTemplateName);
-                        numSectionsPendingInitialization--;
-                        if(numSectionsPendingInitialization <= 0) {
-                            fastReload();
-                        }
-                    });
-                }, 'json');
-            }
-
             function loadTemplateSet(_chooser) {
                 if(!_chooser.length || !_chooser.val()) return false;
                 let container = _chooser.closest('.note-template-container');
@@ -802,12 +755,9 @@
                         sections: allSections
                     },
                     methods: {
-                        add: function(_uid, _section) {
-                            $.get('/get-default-section-data/' + _section + '/{{$patient->uid}}' , function(_data) {
+                        add: function(_uid, _section) {                            
                                 $.post('/api/section/create', {
                                     noteUid: '{{$note->uid}}',
-                                    summaryHtml: _data.summary,
-                                    contentData: JSON.stringify({value: _data.value}),
                                     sectionTemplateUid: _uid,
                                 }, function(_data) {
                                     if(_data) {
@@ -822,7 +772,6 @@
                                         toastr.error('Unable to add section!');
                                     }
                                 }, 'json');
-                            }, 'json');
                         },
                         remove: function(_uid) {
                             $.post('/api/section/deactivate', {

+ 22 - 19
resources/views/app/patient/note/note-section-list.blade.php

@@ -2,8 +2,7 @@
 @foreach($note->sections as $section)
     <?php
     $sectionTS = strtotime($section->created_at);
-    // TODO ask Vijay why is this here?
-    if($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
+    if($latestSectionTS === 0 || $latestSectionTS < $sectionTS){
         $latestSectionTS = $sectionTS;
     }
     ?>
@@ -13,7 +12,6 @@
             data-section-uid="{{ $section->uid }}"
             data-section-template-uid="{{ $section->sectionTemplate->uid }}"
             data-section-template-name="{{ $section->sectionTemplate->internal_name }}">
-
         <div class="d-flex align-items-start">
             @if(!$note->is_signed_by_hcp)
                 <a class="font-weight-bold mb-2 d-flex align-items-center c-pointer">
@@ -55,7 +53,7 @@
             </a>
 
         </div>
-        <div class="d-none if-not-edit  inset-comment">
+        <div class="d-none if-not-edit  inset-comment summary-container">
             {!! !empty($section->summary_html) ? $section->summary_html : '-' !!}
         </div>
 
@@ -94,10 +92,15 @@
                     ];
                 }
             ?>
+                <input type="hidden" name="data">
                 <div note-rte data-content="{{$contentData['value']}}" class="form-group mb-2 border-left border-right rte-holder"></div>
             <?php
             }
             ?>
+
+            <div class="form-control">
+                <button  class="btn btn-sm btn-primary" btn-save-form><i class="fa fa-save"></i></button>
+            </div>
         </div>
     </div>
     @endforeach
@@ -127,25 +130,25 @@
                 quill.on('text-change', function(delta, oldDelta, source){
                     var content = quill.root.innerHTML;
                     var dataValue = JSON.stringify({value: content});
-                    var dataField = $(el).closest('form').find('input[name=data]').val(dataValue);
+                    var dataField = $(el).closest('.note-section').find('input[name=data]').val(dataValue);
                 });
-
             })
 
-            $('[ajax-form]').each(function(){
-                showMask();
-                $(this).ajaxForm(function(result){
-                    console.log("DONE: "+result);
-                    //TODO: Swap new summary html
-                    fastReload();
-                });
+            $('[btn-save-form]').on('click', function(){
+                var  dataField = $(this).closest('.note-section').find('input[name=data]')
+                var value = $(dataField).val();
+
+                var summaryContainer = $(this).closest('.note-section').find('.summary-container')
+                
+                var sectionUid = $(this).closest('.note-section').attr('data-section-uid')
+                $.post("/process_form_submit", {"section_uid":sectionUid , "data": value}, function(resp) {
+                   console.log(resp);
+                   if(resp.success){
+                       summaryContainer.html(resp.newSummaryHtml);
+                   }
+                },'json');
             })
-
-            function cancelFormNoteSection(el) {
-                $(el).closest('.note-section').toggleClass('edit');
-                return false;
-            }
-
+            
         })
 
     </script>

+ 1 - 1
resources/views/app/video/call.blade.php

@@ -547,7 +547,7 @@
                     this.refresh();
                     window.setInterval(function() {
                         self.refresh();
-                    }, 2500);
+                    }, 2500000);
                 },
                 methods: {
                     refresh: function() {

+ 1 - 1
resources/views/layouts/template.blade.php

@@ -255,7 +255,7 @@
                     $('.current-work').html(_data);
                     initFastLoad($('.current-work'));
                 });
-            }, 2500);
+            }, 2500000);
         });
     </script>
     <script>

+ 3 - 1
routes/web.php

@@ -142,9 +142,11 @@ Route::middleware('pro.auth')->group(function () {
     Route::get('/section_create_form/{note_uid}/{section_template_uid}', 'NoteController@sectionCreateForm')->name('section_create_form');
     Route::get('/section_update_form/{section_uid}', 'NoteController@sectionUpdateForm')->name('section_update_form');
     Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');
-    Route::get("/get-default-section-data/{section}/{uid}", 'NoteController@getDefaultValueForSection')->name('get_default_section_data');
 
     Route::get("/log_in_as", 'HomeController@logInAs')->name('log-in-as');
     Route::post("/process-log_in_as", 'HomeController@processLogInAs')->name('process-log-in-as');
     Route::post("/back_to_admin_pro", 'HomeController@backToAdminPro')->name('back-to-admin-pro');
 });
+
+Route::get("/get-default-section-data/{patientID}/{sectionTemplateID}", 'NoteController@getDefaultValueForSection')->name('get_default_section_data');
+

+ 1 - 26
storage/sections/assessment/form.blade.php

@@ -1,15 +1,3 @@
-<?php
-$contentData = false;
-if($section){
-    $contentData = json_decode($section->content_data, true);
-}
-if(!$contentData || !isset($contentData['value'])) {
-    $contentData = [
-        'value'=>''
-    ];
-}
-$formID = rand(0, 100000);
-?>
 <form method="POST" action="/process_form_submit" onsubmit="return submitForm_NoteSection_{{ $formID }}(this);">
     <?php if($section): ?>
         <input type="hidden" name="section_uid" value="<?= $section->uid?>">
@@ -24,17 +12,4 @@ $formID = rand(0, 100000);
         <button class="btn btn-sm btn-primary mr-2">Submit</button>
         <button class="btn btn-sm btn-default border" onclick="return cancelForm_NoteSection_{{ $formID }}(this)">Cancel</button>
     </div>
-</form>
-<script>
-    function submitForm_NoteSection_{{ $formID }}(_form) {
-        showMask();
-        $.post(_form.action, $(_form).serialize(), function(_data) {
-            fastReload();
-        });
-        return false;
-    }
-    function cancelForm_NoteSection_{{ $formID }}(_trigger) {
-        $(_trigger).closest('.note-section').toggleClass('edit');
-        return false;
-    }
-</script>
+</form>

+ 5 - 5
storage/sections/cc/default.php

@@ -9,10 +9,10 @@ foreach($infoLines as $category => $lines):
         endforeach;
     endif;
 endforeach;
-$newSummaryHtml = $patient->displayName() . ", {$patient->age_in_years} years old {$patient->sex} ";
+$summaryHtml = $patient->displayName() . ", {$patient->age_in_years} years old {$patient->sex} ";
 if(count($value)) {
-    $newSummaryHtml .= "presenting with " . implode(", ", $value);
+    $summaryHtml .= "presenting with " . implode(", ", $value);
 }
-$newContentData = [
-    'value' => $newSummaryHtml
-];
+$contentData = [
+    'value' => $summaryHtml
+];

+ 0 - 16
storage/sections/current-goals/form.blade.php

@@ -1,16 +0,0 @@
-<?php
-$contentData = false;
-if ($section) {
-    $contentData = json_decode($section->content_data, true);
-}
-if (!$contentData || !isset($contentData['value'])) {
-    $contentData = [
-        'value' => ''
-    ];
-}
-$formID = rand(0, 100000);
-?>
-
-<div class="form-group mb-2">
-    <textarea rte type="text" class="form-control form-control-sm p-2" name="value" placeholder="Value"><?= $contentData['value'] ?></textarea>
-</div>

+ 0 - 4
storage/sections/current-goals/processor.php

@@ -1,4 +0,0 @@
-<?php
-$newContentData = [
-    'value' => $request->get('value')
-];

+ 0 - 1
storage/sections/current-goals/summary.php

@@ -1 +0,0 @@
-<div><?= $newContentData['value']; ?></div>