فهرست منبع

Handout fixes

Samson Mutunga 3 سال پیش
والد
کامیت
a7fc56cfb0

+ 3 - 1
app/Http/Controllers/PatientController.php

@@ -13,6 +13,7 @@ use App\Models\CompanyPro;
 use App\Models\Erx;
 use App\Models\Facility;
 use App\Models\Handout;
+use App\Models\HandoutClient;
 use App\Models\IncomingReport;
 use App\Models\MBClaim;
 use App\Models\MBPayer;
@@ -328,8 +329,9 @@ class PatientController extends Controller
 
     public function handouts(Request $request, Client $patient )
     {
+        $clientHandouts = HandoutClient::where('client_id', $patient->id)->get();
         $handouts = Handout::where('is_active', true)->get();
-        return view('app.patient.handouts', compact('patient', 'handouts'));
+        return view('app.patient.handouts', compact('patient', 'clientHandouts', 'handouts'));
     }
 
     public function settings(Request $request, Client $patient )

+ 9 - 8
app/Models/Client.php

@@ -200,14 +200,15 @@ class Client extends Model
             $mappings = $mappings->where('note_id', $note->id);
         }
         $mappings = $mappings->get();
-        $handouts = new Collection();
-        foreach ($mappings as $mapping) {
-            $handout = Handout::where('id', $mapping->handout_id)->first();
-            $handout->handout_client_uid = $mapping->uid;
-            $handouts->add($handout);
-        }
-        $handouts = $handouts->sortBy('created_at');
-        return $handouts;
+        return $mappings;
+        // $handouts = new Collection();
+        // foreach ($mappings as $mapping) {
+        //     $handout = Handout::where('id', $mapping->handout_id)->first();
+        //     $handout->handout_client_uid = $mapping->uid;
+        //     $handouts->add($handout);
+        // }
+        // $handouts = $handouts->sortBy('created_at');
+        // return $handouts;
     }
 
     public function duplicateOf()

+ 8 - 0
app/Models/HandoutClient.php

@@ -8,4 +8,12 @@ class HandoutClient extends Model
 {
     protected $table = 'handout_client';
 
+    public function client(){
+        return $this->hasOne(Client::class, 'id', 'client_id');
+    }
+
+    public function handout(){
+        return $this->hasOne(Handout::class, 'id', 'handout_id');
+    }
+
 }

+ 5 - 5
resources/views/app/patient/handouts-list.blade.php

@@ -37,11 +37,11 @@
         </tr>
         </thead>
         <tbody>
-        @foreach($handouts as $handout)
-            <?php $downloadLink = config('app.url') . "/guest/handout/{$handout->handout_client_uid}"; ?>
+        @foreach($clientHandouts as $clientHandout)            
+            <?php $downloadLink = config('app.url') . "/guest/handout/".$clientHandout->uid; ?>
             <tr>
-                <td>{{$handout->internal_name}}</td>
-                <td>{{$handout->display_name}}</td>
+                <td>{{$clientHandout->handout->internal_name}}</td>
+                <td>{{$clientHandout->handout->display_name}}</td>
                 <td>
                     <a native href="{{ $downloadLink }}" target="_blank" class="pdf-viewer-triggerd-flex align-items-center">
                         <i class="fa fa-eye mr-2"></i>View
@@ -59,7 +59,7 @@
                             </div>
                             <div class="mb-2">
                                 <label for="" class="text-sm text-secondary mb-1">Message</label>
-                                <textarea type="text" rows="10" class="form-control form-control-sm" name="message">Dear {{$patient->displayName()}}, Access the handout ({{$handout->display_name}}) at the following link: <a href="{{$downloadLink}}">{{$downloadLink}}</a></textarea>
+                                <textarea type="text" rows="10" class="form-control form-control-sm" name="message">Dear {{$patient->displayName()}}, Access the handout ({{$clientHandout->handout->display_name}}) at the following link: <a href="{{$downloadLink}}">{{$downloadLink}}</a></textarea>
                             </div>
                             <div class="d-flex align-items-center">
                                 <button class="btn btn-sm btn-primary mr-2" submit="">Send</button>

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

@@ -1,5 +1,8 @@
 <?php
 /** @var App\Models\Note $note */
+
+use App\Models\Handout;
+
 /** @var App\Models\Pro $pro */
 /** @var App\Models\Section $section */
 /** @var $allSections */
@@ -795,8 +798,11 @@
 
                 <!-- handouts -->
                 <div class="p-3 border-bottom screen-only" data-non-segment-section="Handouts">
-                    <?php $handouts = $patient->handouts($note); ?>
-                    @include('app.patient.handouts-list', compact('patient', 'handouts', 'note'))
+                    <?php 
+                        $handouts = Handout::where('is_active', true)->get();
+                        $clientHandouts = $patient->handouts($note); 
+                    ?>
+                    @include('app.patient.handouts-list', compact('patient', 'clientHandouts', 'handouts', 'note'))
                 </div>
 
                 <div class="p-3 border-bottom screen-only" data-non-segment-section="Prescriptions">