Ver Fonte

completed section sharing

Josh há 4 anos atrás
pai
commit
06dc3a7251

+ 7 - 2
app/Http/Controllers/GuestController.php

@@ -20,8 +20,13 @@ class GuestController extends Controller
         abort_if(!$section, 404, 'Invalid access code');
         abort_if($section->guest_access_level == 'NONE', 401, 'Invalid access code');
 
-        $patient = $section->note->client;
-        
+        $patient = null;
+        if($section->note){
+           $patient = $section->note->client;
+        }else{
+            $patient = $section->client;
+        }
+               
        return view('app.guest.section', compact('patient','section', 'guestAccessCode'));
     }
 

+ 7 - 2
app/Http/Controllers/NoteController.php

@@ -79,7 +79,13 @@ class NoteController extends Controller
 
         $section = Section::where('uid', $section_uid)->first();
         $note = Note::where('id', $section->note_id)->first();
-        $client = Client::where('id', $note->client_id)->first();
+        $client = null;
+        if($note){
+            $client = Client::where('id', $note->client_id)->first();
+        }else{
+            $client = Client::where('id', $section->client_id)->first();
+        }
+        
         $patient = $client;
         $sectionTemplate = SectionTemplate::where('id', $section->section_template_id)->first();
 
@@ -135,7 +141,6 @@ class NoteController extends Controller
             'summaryHtml' => $newSummaryHtml
         ];
         $response = $this->calljava($request, '/section/update', $data, $guestAccessCode);
-
         return [
             'success' => $response['success'],
             'newSummaryHtml' => $newSummaryHtml

+ 19 - 0
app/Http/Controllers/PatientController.php

@@ -148,6 +148,25 @@ class PatientController extends Controller
         return view('app.patient.notes', compact('patient','pros'));
     }
 
+    public function sections(Request $request, Client $patient )
+    {
+        $pros = Pro::all();
+        $sections = $patient->sections;
+    
+        $allSections = SectionTemplate::where('is_active', true)->get();
+        foreach ($allSections as $section) {
+            $section->used = false;
+            foreach ($sections as $section) {
+                if ($section->sectionTemplate->id === $section->id) {
+                    $section->used = true;
+                    $section->section_uid = $section->uid;
+                    break;
+                }
+            }
+        }
+        return view('app.patient.sections', compact('patient', 'pros', 'allSections'));
+    }
+
     public function flowSheets(Request $request, Client $patient )
     {
         return view('app.patient.flowsheets', compact('patient'));

+ 4 - 0
app/Models/Client.php

@@ -34,6 +34,10 @@ class Client extends Model
         return $this->hasMany(Note::class, 'client_id', 'id')->orderBy('effective_dateest', 'desc');
     }
 
+    public function sections() {
+        return $this->hasMany(Section::class, 'client_id', 'id')->where('is_active', true)->orderBy('created_at', 'asc');
+    }
+
     public function duplicateOf() {
         return $this->hasOne(Client::class, 'id', 'duplicate_of_client_id');
     }

+ 4 - 0
app/Models/Section.php

@@ -15,4 +15,8 @@ class Section extends Model
     public function note() {
         return $this->hasOne(Note::class, 'id', 'note_id');
     }
+
+    public function client() {
+        return $this->hasOne(Section::class, 'id', 'client_id');
+    }
 }

+ 142 - 0
resources/views/app/patient/sections.blade.php

@@ -0,0 +1,142 @@
+<?php
+/** @var App\Models\Note $note */
+/** @var App\Models\Pro $pro */
+/** @var App\Models\Section $section */
+/** @var $allSections */
+?>
+@extends ('layouts.patient')
+
+@section('inner-content')
+    <div class="card mb-0">
+        <div class="card-body p-0">
+            <div>
+                <div class="mb-3">
+                    <div>
+                        <?php
+                        $shortCutsObject = [];
+                        foreach ($pro->shortcuts as $shortcut) {
+
+                            // %replaceables%
+                            $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
+                            $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
+                            $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);
+
+                            $shortCutsObject[] = [
+                                "name" => $shortcut->shortcut,
+                                "value" => $shortcut->text
+                            ];
+                        }
+                        ?>
+                        <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>
+                        <?php
+                        $shortcuts = "";
+                        $latestSectionTS = 0;
+                        ?>
+                        @include('app.patient.sections.client-section-list')
+                    </div>
+                </div>
+
+                <span class="d-none latest-section-ts">{{ $latestSectionTS }}</span>
+            </div>
+        </div>
+    </div>
+    <div class="note-templates-underlay"></div>
+    @include('app.patient.note.dashboard_script')
+@endsection
+
+@section('left-nav-content')
+    <div class="left-nav-content" id="note-sections-app">
+        <div class="note-widget-title px-2 py-1">Note Sections</div>
+        <input type="search" class="d-block w-100 border-0 outline-0 px-2 py-1"
+               v-model="q" placeholder="Filter">
+        <div class="border-top py-1">
+            <div v-for="section in sections"
+                 v-show="section.title.toLowerCase().indexOf(q.toLowerCase()) !== -1">
+                <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
+                     :title="section.title + ' - Click to remove'"
+                     v-if="section.used"
+                     v-on:click.once="remove(section.section_uid)">
+                    <span class="mx-2">
+                        <a class="font-12 text-secondary" href="#">
+                            <i class="fa fa-minus-circle"></i>
+                        </a>
+                    </span>
+                    <span class="font-smaller text-ellipsis">
+                        @{{section.title}}
+                    </span>
+                </div>
+                <div class="d-flex pr-1 align-items-center note-widget-item c-pointer"
+                     :title="section.title + ' - Click to add'"
+                     v-if="!section.used"
+                     v-on:click.once="add(section.uid, section.internal_name)">
+                    <span class="mx-2">
+                        <a class="font-12" href="#">
+                            <i class="fa fa-plus-circle"></i>
+                        </a>
+                    </span>
+                    <span class="font-smaller text-ellipsis">
+                        @{{section.title}}
+                    </span>
+                </div>
+            </div>
+        </div>
+    </div>
+    <script>
+        (function() {
+            function initSectionsWidget() {
+                var allSections = <?= json_encode($allSections) ?>;
+                new Vue({
+                    el: '#note-sections-app',
+                    delimiters: ['@{{', '}}'],
+                    data: {
+                        q: '',
+                        sections: allSections
+                    },
+                    methods: {
+                        add: function(_uid, _section) {                            
+                                $.post('/api/section/createForClient', {
+                                    clientUid: '{{$patient->uid}}',
+                                    sectionTemplateUid: _uid,
+                                }, function(_data) {
+                                    if(_data) {
+                                        if(_data.success) {
+                                            fastReload();
+                                        }
+                                        else {
+                                            toastr.error(_data.message);
+                                        }
+                                    }
+                                    else {
+                                        toastr.error('Unable to add section!');
+                                    }
+                                }, 'json');
+                        },
+                        remove: function(_uid) {
+                            $.post('/api/section/deactivate', {
+                                uid: _uid,
+                                memo: 'Deactivated from note',
+                            }, function(_data) {
+                                if(_data) {
+                                    if(_data.success) {
+                                        fastReload();
+                                    }
+                                    else {
+                                        toastr.error(_data.message);
+                                    }
+                                }
+                                else {
+                                    toastr.error('Unable to remove section!');
+                                }
+                            }, 'json');
+                        }
+                    }
+                });
+
+                $('div[embed]').each(function() {
+                    $(this).load($(this).attr('embed'));
+                });
+            }
+            addMCInitializer('sections-widget', initSectionsWidget);
+        })();
+    </script>
+@endsection

+ 5 - 0
resources/views/app/patient/sections/client-section-list.blade.php

@@ -0,0 +1,5 @@
+<?php $canvasData = json_decode($patient->canvas_data, true); ?>
+@foreach($patient->sections as $section)
+@include('app.patient.note.section')
+@endforeach
+@include('app.patient.note.section_script')

+ 4 - 0
resources/views/layouts/patient.blade.php

@@ -33,6 +33,10 @@
                             <a class="nav-link {{ strpos($routeName, 'patients.view.notes') === 0 ? 'active' : '' }}"
                                href="{{ route('patients.view.notes', ['patient' => $patient]) }}">Notes</a>
                         </li>
+                        <li class="nav-item">
+                            <a class="nav-link {{ strpos($routeName, 'patients.view.sections') === 0 ? 'active' : '' }}"
+                               href="{{ route('patients.view.sections', ['patient' => $patient]) }}">Sections</a>
+                        </li>
                         <li class="nav-item">
                             <a class="nav-link {{ strpos($routeName, 'patients.view.action-items') === 0 ? 'active' : '' }}"
                                href="{{ route('patients.view.action-items', ['patient' => $patient]) }}">ERx/Orders</a>

+ 1 - 0
routes/web.php

@@ -100,6 +100,7 @@ Route::middleware('pro.auth')->group(function () {
         Route::name('notes.view.')->prefix('notes/view/{note}')->group(function () {
             Route::get('', 'NoteController@dashboard')->name('dashboard');
         });
+        Route::get('sections', 'PatientController@sections')->name('sections');
         Route::get('flowsheets', 'PatientController@flowSheets')->name('flowsheets');
         Route::get('settings', 'PatientController@settings')->name('settings');
         Route::get('account', 'PatientController@account')->name('account');