Jelajahi Sumber

Create/link account updates

Vijayakrishnan 4 tahun lalu
induk
melakukan
87d9f688c9

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

@@ -429,4 +429,8 @@ class PatientController extends Controller
     public function mbClaim(Request $request, MBClaim $mbClaim) {
         return view('app.patient.mb-claim-single', compact('mbClaim'));
     }
+
+    public function accounts(Request $request, Client $patient) {
+        return view('app.patient.accounts', compact('patient'));
+    }
 }

+ 11 - 0
app/Models/Account.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+# use Illuminate\Database\Eloquent\Model;
+
+class Account extends Model
+{
+    protected $table = 'account';
+
+}

+ 8 - 0
app/Models/AccountClient.php

@@ -8,4 +8,12 @@ class AccountClient extends Model
 {
     protected $table = 'account_client';
 
+    public function client() {
+        return $this->hasOne(Client::class, 'id', 'client_id');
+    }
+
+    public function account() {
+        return $this->hasOne(Account::class, 'id', 'account_id');
+    }
+
 }

+ 17 - 0
app/Models/AccountInvite.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class AccountInvite extends Model
+{
+
+    protected $table = 'account_invite';
+
+    public function getRouteKeyName()
+    {
+        return 'access_token';
+    }
+}

+ 12 - 4
app/Models/Client.php

@@ -488,10 +488,6 @@ class Client extends Model
             ->count();
     }
 
-    public function accountClient() {
-        return $this->hasOne(AccountClient::class, 'client_id', 'id')->where('is_removed', false);
-    }
-
     public function smsReminders()
     {
         return $this->hasMany(SimpleSMSReminder::class, 'client_id', 'id')
@@ -523,4 +519,16 @@ class Client extends Model
             ->orderBy('created_at', 'asc');
     }
 
+    public function accountInvites()
+    {
+        return $this->hasMany(AccountInvite::class, 'for_client_id', 'id')
+            ->orderBy('created_at', 'desc');
+    }
+    public function linkedAccounts()
+    {
+        return $this->hasMany(AccountClient::class, 'client_id', 'id')
+            ->orderBy('created_at', 'desc');
+    }
+
+
 }

+ 197 - 0
resources/views/app/patient/accounts.blade.php

@@ -0,0 +1,197 @@
+@extends ('layouts.patient')
+@section('inner-content')
+    <div class="">
+        <div class="d-flex align-items-end pb-3">
+            <h4 class="font-weight-bold m-0 font-size-16">
+                <i class="fa fa-link"></i>
+                Linked Accounts
+            </h4>
+            <span class="mx-2 text-secondary">|</span>
+            <div moe relative class="">
+                <a href="#" start show class="col-2-button">
+                    + Add
+                </a>
+                <form url="/api/accountInvite/create" class="mcp-theme-1" right>
+                    <input type="hidden" name="forClientUid" value="{{$patient->uid}}">
+                    <div class="mb-2">
+                        <label class="text-secondary text-sm">Email Address</label>
+                        <input type="email" name="toEmailAddress" value="{{ $patient->email_address }}"
+                               class="form-control form-control-sm" required>
+                    </div>
+                    <div class="mb-2">
+                        <label class="text-secondary text-sm">First Name</label>
+                        <input type="text" name="firstName" value="{{ $patient->name_first }}"
+                               class="form-control form-control-sm" required>
+                    </div>
+                    <div class="mb-2">
+                        <label class="text-secondary text-sm">Last Name</label>
+                        <input type="text" name="lastName" value="{{ $patient->name_last }}"
+                               class="form-control form-control-sm" required>
+                    </div>
+                    <div class="mb-2">
+                        <label class="text-secondary text-sm">Cell Number</label>
+                        <input type="tel" name="cellNumber" value="{{ $patient->cell_number }}"
+                               class="form-control form-control-sm">
+                    </div>
+                    <div>
+                        <button submit class="btn btn-sm btn-primary mr-2">Yes</button>
+                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
+                    </div>
+                </form>
+            </div>
+        </div>
+        <table class="table table-sm table-bordered mb-0">
+            @if($patient->linkedAccounts && count($patient->linkedAccounts))
+                <thead>
+                <tr class="bg-light">
+                    <th class="px-2 text-secondary border-bottom-0">Created At</th>
+                    <th class="px-2 text-secondary border-bottom-0">Name</th>
+                    <th class="px-2 text-secondary border-bottom-0">Email</th>
+                    <th class="px-2 text-secondary border-bottom-0">Cell Number</th>
+                    <th class="px-2 text-secondary border-bottom-0">Access Allowed?</th>
+                    <th class="px-2 text-secondary border-bottom-0">Is Removed?</th>
+                    <th class="px-2 text-secondary border-bottom-0">&nbsp;</th>
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($patient->linkedAccounts as $linkedAccount)
+                    <tr class="{{$linkedAccount->is_removed ? 'bg-light text-secondary' : ''}}">
+                        <td class="px-2">{{ friendlier_date_time($linkedAccount->created_at) }}
+                            @if($linkedAccount->is_removed)
+                                <span class="text-sm text-secondary">(REMOVED)</span>
+                            @endif
+                        </td>
+                        <td class="px-2">{{ $linkedAccount->account->name_first }} {{ $linkedAccount->account->name_last }}</pre></td>
+                        <td class="px-2">{{ $linkedAccount->account->email }}</td>
+                        <td class="px-2">{{ $linkedAccount->account->phone_number }}</td>
+                        <td class="px-2">
+                            <div class="d-flex">
+                                <span class="width-40px">{{ $linkedAccount->is_access_allowed ? 'YES' : 'NO' }}</span>
+                                @if(!$linkedAccount->is_removed)
+                                    @if(!$linkedAccount->is_access_allowed)
+                                        <span moe class="ml-1" relative>
+                                            <a class="" href="" show start>Allow</a>
+                                            <form url="/api/accountClient/proAllowAccess" right>
+                                                <input type="hidden" name="uid" value="{{$linkedAccount->uid}}">
+                                                <p>Access access to this client from this linked account?</p>
+                                                <div class="mb-0">
+                                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                </div>
+                                            </form>
+                                        </span>
+                                    @else
+                                        <span moe class="ml-1" relative>
+                                            <a class="" href="" show start>Deny</a>
+                                            <form url="/api/accountClient/proDenyAccess" right>
+                                                <input type="hidden" name="uid" value="{{$linkedAccount->uid}}">
+                                                <p>Deny access to this client from this linked account?</p>
+                                                <div class="mb-0">
+                                                    <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                                </div>
+                                            </form>
+                                        </span>
+                                    @endif
+                                @endif
+                            </div>
+                        </td>
+                        <td class="px-2">{{ $linkedAccount->is_removed ? 'YES' : 'NO' }}</td>
+                        <td class="px-2">
+                            @if(!$linkedAccount->is_removed)
+                                <div moe class="ml-1" relative>
+                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
+                                    <form url="/api/accountClient/remove" right>
+                                        <input type="hidden" name="uid" value="{{$linkedAccount->uid}}">
+                                        <p>Remove this linked account?</p>
+                                        <div class="mb-0">
+                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                        </div>
+                                    </form>
+                                </div>
+                            @endif
+                        </td>
+                    </tr>
+                @endforeach
+                </tbody>
+            @else
+                <tbody>
+                <tr>
+                    <td class="text-secondary p-3">No linked accounts</td>
+                </tr>
+                </tbody>
+            @endif
+        </table>
+
+        @if($patient->accountInvites && count($patient->accountInvites))
+            <div class="d-flex align-items-end pb-3 mt-4">
+                <h4 class="font-weight-bold m-0 font-size-14">
+                    <i class="fa fa-envelope"></i>
+                    Accounts Invites
+                </h4>
+            </div>
+            <table class="table table-sm table-bordered mb-0">
+                <thead>
+                <tr class="bg-light">
+                    <th class="px-2 text-secondary border-bottom-0">Created At</th>
+                    <th class="px-2 text-secondary border-bottom-0">Name</th>
+                    <th class="px-2 text-secondary border-bottom-0">Email</th>
+                    <th class="px-2 text-secondary border-bottom-0">Cell Number</th>
+                    <th class="px-2 text-secondary border-bottom-0">Status</th>
+                    <th class="px-2 text-secondary border-bottom-0">&nbsp;</th>
+                </tr>
+                </thead>
+                <tbody>
+                @foreach($patient->accountInvites as $accountInvite)
+                    <tr>
+                        <td class="px-2">
+                            {{ friendlier_date_time($accountInvite->created_at) }}
+                            @if($accountInvite->status === 'CANCELLED')
+                                <span class="text-sm text-secondary">(CANCELLED)</span>
+                            @endif
+                        </td>
+                        <td class="px-2">{{ $accountInvite->first_name }} {{ $accountInvite->last_name }}</pre></td>
+                        <td class="px-2">{{ $accountInvite->to_email_address }}</td>
+                        <td class="px-2">{{ $accountInvite->cell_number }}</td>
+                        <td class="px-2">{{ $accountInvite->status }} <span class="text-sm text-secondary">(Updated: {{friendlier_date_time($accountInvite->status_updated_at)}})</span>
+                            @if($accountInvite->status_memo)
+                                <div class="py-1 font-italic text-secondary text-sm">{{$accountInvite->status_memo}}</div>
+                            @endif
+                        </td>
+                        <td class="px-2">
+                            <div class="d-flex">
+                                @if($accountInvite->status !== 'CANCELLED')
+                                    <span moe class="ml-1" relative>
+                                        <a class="" href="" show start>Cancel</a>
+                                        <form url="/api/accountInvite/markAsCancelled" right>
+                                            <input type="hidden" name="uid" value="{{$accountInvite->uid}}">
+                                            <p>Cancel this invite?</p>
+                                            <div class="mb-0">
+                                                <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </span>
+                                @else
+                                    <span moe class="ml-1" relative>
+                                        <a class="" href="" show start>Undo Cancel</a>
+                                        <form url="/api/accountInvite/undoMarkAsCancelled" right>
+                                            <input type="hidden" name="uid" value="{{$accountInvite->uid}}">
+                                            <p>Un-cancel this invite?</p>
+                                            <div class="mb-0">
+                                                <button class="btn btn-primary btn-sm" submit>Submit</button>
+                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
+                                            </div>
+                                        </form>
+                                    </span>
+                                @endif
+                            </div>
+                        </td>
+                    </tr>
+                @endforeach
+                </tbody>
+            </table>
+        @endif
+    </div>
+@endsection

+ 1 - 1
resources/views/app/patients.blade.php

@@ -209,7 +209,7 @@
                             </table>
                         </td>
                         <td>
-                            @if($patient->accountClient)
+                            @if($patient->linkedAccounts && count($patient->linkedAccounts))
                                 <span class="font-weight-bold text-info"><i class="fa fa-check"></i></span>
                             @else
                                 <span class="text-secondary">-</span>

+ 10 - 27
resources/views/layouts/patient.blade.php

@@ -190,6 +190,10 @@
                                href="{{ route('patients.view.claims-resolver', $patient) }}">Claims Resolver</a>
                         </li>
                         @endif
+                        <li class="nav-item">
+                            <a class="nav-link {{ strpos($routeName, 'patients.view.accounts') === 0 ? 'active' : '' }}"
+                               href="{{ route('patients.view.accounts', $patient) }}">Linked Accounts</a>
+                        </li>
                     </ul>
                     <div class="mt-3 mcp-theme-1">
                         @yield('left-nav-content')
@@ -903,37 +907,16 @@
                                             <span class="aligned-icon"><i class="fa fa-envelope" aria-hidden="true"></i></span>
                                             {{$confirmedEmail}}
                                         </li>
-                                        @if(!$patient->accountClient)
                                         <li>
-                                            <span class="aligned-icon">
+                                            <span class="aligned-icon text-primary">
                                                 <i class="fa fa-link" aria-hidden="true"></i>
                                             </span>
-                                            <div moe relative class="">
-                                                <a href="#" start show class="col-2-button">
-                                                    Create/Link Account
-                                                </a>
-                                                <form url="/api/client/linkOrCreateAccountClient" class="mcp-theme-1" right>
-                                                    <input type="hidden" name="uid" value="{{$patient->uid}}">
-                                                    <div class="mb-2">
-                                                        <label class="text-secondary text-sm">Email Address</label>
-                                                        <input type="email" name="accountEmail" value="{{ $confirmedEmail }}"
-                                                               class="form-control form-control-sm">
-                                                    </div>
-                                                    <div>
-                                                        <button submit class="btn btn-sm btn-primary mr-2">Yes</button>
-                                                        <button cancel class="btn btn-sm btn-default border">Cancel</button>
-                                                    </div>
-                                                </form>
-                                            </div>
+                                            <?php $numLinkedAccounts = $patient->linkedAccounts ? count($patient->linkedAccounts) : 0; ?>
+                                            <a href="{{route('patients.view.accounts', ['patient' => $patient])}}">
+                                                {{ $numLinkedAccounts === 0 ? 'No' : $numLinkedAccounts }}
+                                                account{{ $numLinkedAccounts === 1 ? '' : 's' }} linked
+                                            </a>
                                         </li>
-                                        @else
-                                            <li>
-                                                <span class="aligned-icon text-info">
-                                                    <i class="fa fa-check" aria-hidden="true"></i>
-                                                </span>
-                                                <span class="text-info">Account Linked</span>
-                                            </li>
-                                        @endif
                                     </ul>
                                 </div>
                             </div>

+ 2 - 0
routes/web.php

@@ -222,6 +222,8 @@ Route::middleware('pro.auth')->group(function () {
             // CLAIMS RESOLVER
             Route::get('claims-resolver', 'PatientController@claimsResolver')->name('claims-resolver');
 
+            Route::get('accounts', 'PatientController@accounts')->name('accounts');
+
         });
 
     });