Pārlūkot izejas kodu

Support for global shortcuts

Vijayakrishnan 4 gadi atpakaļ
vecāks
revīzija
0a404acd50

+ 21 - 2
app/Http/Controllers/PracticeManagementController.php

@@ -202,8 +202,27 @@ class PracticeManagementController extends Controller
 
     public function myTextShortcuts(Request $request)
     {
-        $performer = $this->performer();
-        $myTextShortcuts = ProTextShortcut::where('pro_id', $performer->pro_id)->where('is_removed', false)->get();
+
+        $myTextShortcuts = DB::table('pro_text_shortcut')
+            ->leftJoin('pro', 'pro_text_shortcut.pro_id', '=', 'pro.id')
+            ->select(
+                'pro_text_shortcut.uid',
+                'pro_text_shortcut.shortcut',
+                'pro_text_shortcut.text',
+                'pro.name_first',
+                'pro.name_last'
+            )
+            ->where('pro_text_shortcut.is_removed', false);
+
+        if($this->performer()->pro->pro_type !== 'ADMIN') {
+            $myTextShortcuts = $myTextShortcuts->where('pro_id', $this->performer()->pro_id);
+        }
+
+        $myTextShortcuts = $myTextShortcuts
+            ->orderBy('pro.name_last')
+            ->orderBy('pro.name_first')
+            ->get();
+
         return view('app.practice-management.my-text-shortcuts', compact('myTextShortcuts'));
     }
 

+ 12 - 0
app/Models/Pro.php

@@ -85,6 +85,18 @@ class Pro extends Model
         return $this->hasMany(ProTextShortcut::class, 'pro_id')->where('is_removed', false);
     }
 
+    public function allShortcuts() {
+        $myId = $this->id;
+        $shortcuts = ProTextShortcut::where('is_removed', false)
+            ->where(function ($query2) use ($myId) {
+                $query2
+                    ->where('pro_id', $myId)
+                    ->orWhereNull('pro_id');
+            })
+            ->get();
+        return $shortcuts;
+    }
+
     public function noteTemplates() {
         return $this->hasMany(NoteTemplatePro::class, 'pro_id')
             ->where('is_removed', false)

+ 1 - 1
app/Models/ProTextShortcut.php

@@ -10,7 +10,7 @@ class ProTextShortcut extends Model
     protected $table = 'pro_text_shortcut';
 
     public function pro() {
-        return $this->hasOne(Pro::class, 'pro_id', 'id');
+        return $this->hasOne(Pro::class, 'id', 'pro_id');
     }
 
 }

+ 1 - 1
resources/views/app/patient/care-month/dashboard.blade.php

@@ -8,7 +8,7 @@
 
     <?php
     $shortCutsObject = [];
-    foreach ($pro->shortcuts as $shortcut) {
+    foreach ($pro->allShortcuts() as $shortcut) {
 
         // %replaceables%
         $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);

+ 1 - 1
resources/views/app/patient/dashboard.blade.php

@@ -3,7 +3,7 @@
 @section('inner-content')
     <?php
     $shortCutsObject = [];
-    foreach ($pro->shortcuts as $shortcut) {
+    foreach ($pro->allShortcuts() as $shortcut) {
 
         // %replaceables%
         $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);

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

@@ -356,7 +356,7 @@
                     <div>
                         <?php
                         $shortCutsObject = [];
-                        foreach ($pro->shortcuts as $shortcut) {
+                        foreach ($pro->allShortcuts() as $shortcut) {
 
                             // %replaceables%
                             $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);

+ 1 - 1
resources/views/app/patient/sections.blade.php

@@ -14,7 +14,7 @@
                     <div>
                         <?php
                         $shortCutsObject = [];
-                        foreach ($pro->shortcuts as $shortcut) {
+                        foreach ($pro->allShortcuts() as $shortcut) {
 
                             // %replaceables%
                             $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);

+ 23 - 9
resources/views/app/practice-management/my-text-shortcuts.blade.php

@@ -16,14 +16,19 @@
                     Add
                 </a>
                 <form url="/api/proTextShortcut/create">
-                    <input type="hidden" name="proUid" value="{{$pro->uid}}">
+                    @if($pro->pro_type !== 'ADMIN')
+                        <input type="hidden" name="proUid" value="{{$pro->uid}}">
+                    @else
+                        <p><b>Add Global Shortcut</b></p>
+                    @endif
                     <div class="mb-2">
                         <input type="text" class="form-control form-control-sm" name="shortcut"
                                placeholder="Shortcut *">
                     </div>
                     <div class="mb-2">
-                        <textarea type="text" rows="10" class="form-control form-control-sm" name="text"
-                                                      placeholder="Content *"></textarea>
+                        <textarea type="text"
+                                  rows="10" class="form-control form-control-sm" name="text"
+                                  placeholder="Content *"></textarea>
                     </div>
                     <div class="form-group m-0">
                         <button submit class="btn btn-primary btn-sm mr-2">Submit</button>
@@ -33,22 +38,31 @@
             </div>
         </div>
         <div class="card-body p-0">
-            <table class="table table-condensed p-0 m-0">
+            <table class="table table-condensed table-hover p-0 m-0">
                 <thead class="bg-light">
                 <tr>
-                    <th class="px-3 border-0 w-25">Shortcut</th>
+                    <th class="px-3 border-0">Pro</th>
+                    <th class="border-0 width-200px">Shortcut</th>
                     <th class="border-0">Text</th>
-                    <th class="border-0 w-25">&nbsp;</th>
+                    <th class="border-0 width-200px">&nbsp;</th>
                 </tr>
                 </thead>
                 <tbody>
                 @foreach($myTextShortcuts as $textShortcut)
                     <tr>
-                        <td class="px-3">{{ $textShortcut->shortcut }}</td>
-                        <td><pre class="mb-0">{{ $textShortcut->text }}</pre></td>
+                        <td class="px-3 text-nowrap">
+                            @if($textShortcut->name_first || $textShortcut->name_last)
+                                {{ $textShortcut->name_first ? $textShortcut->name_first : '' }}
+                                {{ $textShortcut->name_last ? $textShortcut->name_last : '' }}
+                            @else
+                                <span class="text-secondary">(global)</span>
+                            @endif
+                        </td>
+                        <td>{{ $textShortcut->shortcut }}</td>
+                        <td><pre class="max-width-700px my-0" style="white-space: break-spaces;">{{ $textShortcut->text }}</pre></td>
                         <td>
                             <div class="d-flex align-items-center">
-                                <div moe wide class="mr-3">
+                                <div moe large relative class="mr-3">
                                     <a start show>
                                         <i class="fa fa-pencil-alt"></i>
                                     </a>