Browse Source

Guest page for accessing handout

Vijayakrishnan 4 years ago
parent
commit
1a165177a1

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

@@ -5,17 +5,20 @@ namespace App\Http\Controllers;
 use App\Models\CareMonth;
 use App\Models\CareMonthEntry;
 use App\Models\Client;
+use App\Models\Handout;
+use App\Models\HandoutClient;
 use App\Models\Pro;
 use App\Models\Section;
 use App\Models\SectionTemplate;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Response;
 
 class GuestController extends Controller
 {
     public function section(Request $request, $guestAccessCode )
     {
-        
+
         $section = Section::where('guest_access_code', $guestAccessCode)->first();
         abort_if(!$section, 404, 'Invalid access code');
         abort_if($section->guest_access_level == 'NONE', 401, 'Invalid access code');
@@ -26,8 +29,24 @@ class GuestController extends Controller
         }else{
             $patient = $section->client;
         }
-               
+
        return view('app.guest.section', compact('patient','section', 'guestAccessCode'));
     }
 
+    public function handout(Request $request, $handoutClientUid )
+    {
+
+        $handoutClient = HandoutClient::where('uid', $handoutClientUid)->first();
+        abort_if((!$handoutClient || !$handoutClient->is_active), 404, 'Invalid access code');
+
+        $handout = Handout::where('id', $handoutClient->handout_id)->first();
+        abort_if((!$handout || !$handout->is_active), 404, 'Invalid access code');
+
+        return Response::download(
+            $handout->pdf_file_path,
+            $handout->internal_name . '.pdf',
+            ['Content-Type: application/pdf']
+        );
+    }
+
 }

+ 3 - 2
resources/views/app/patient/handouts.blade.php

@@ -37,11 +37,12 @@
             </thead>
             <tbody>
             @foreach($patient->handouts() as $handout)
+                <?php $downloadLink = env('APP_URL') . "/guest/handout/{$handout->handout_client_uid}"; ?>
                 <tr>
                     <td class="px-2">{{$handout->internal_name}}</td>
                     <td class="px-2">{{$handout->display_name}}</td>
-                    <td class="px-2"><a href="#">View</a></td>
-                    <td class="px-2">{{ env('APP_URL') }}/guest/handout/{{ $handout->handout_client_uid }}</td>
+                    <td class="px-2"><a native href="{{ $downloadLink }}" target="_blank">View</a></td>
+                    <td class="px-2"><b>{{ $downloadLink }}</b></td>
                 </tr>
             @endforeach
             </tbody>

+ 1 - 0
routes/web.php

@@ -40,6 +40,7 @@ Route::post('/set_password', 'HomeController@postSetPassword')->name('post-set_p
 Route::post('/set_security_questions', 'HomeController@postSetSecurityQuestions')->name('post-set_security_questions');
 
 Route::get("/guest/section/{accessToken}", 'GuestController@section')->name('guest_section_access');
+Route::get("/guest/handout/{handoutClientUid}", 'GuestController@handout')->name('guest_handout_access');
 
 Route::middleware('pro.auth')->group(function () {