Explorar o código

Note - replace tickets with prescriptions

Vijayakrishnan %!s(int64=3) %!d(string=hai) anos
pai
achega
916d08e202

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

@@ -438,6 +438,17 @@ class PatientController extends Controller
         return view('app.patient.prescriptions.index', compact('patient', 'type', 'currentErx'));
     }
 
+    public function prescriptionsList(Request $request, Client $patient, String $type = '', String $currentErx = '') {
+        if(!!$currentErx) {
+            $currentErx = Erx::where('uid', $currentErx)->first();
+        }
+        $note = null;
+        if($request->input('noteUid')) {
+            $note = Note::where('uid', $request->input('noteUid'))->first();
+        }
+        return view('app.patient.prescriptions.list', compact('patient', 'type', 'currentErx', 'note'));
+    }
+
     public function downloadPrescriptionAsPdf(Request $request, Erx $prescription){
         if($request->input('html')) {
             return view('app.patient.prescriptions.pdf.pdf-preview', compact('prescription'));

+ 1 - 0
app/Models/Client.php

@@ -94,6 +94,7 @@ class Client extends Model
     public function prescriptions()
     {
         return $this->hasMany(Erx::class, 'client_id', 'id')
+            ->orderByRaw('note_id DESC NULLS LAST')
             ->orderBy('created_at', 'desc');
     }
 

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

@@ -523,275 +523,7 @@
                 <span class="d-none latest-section-ts">{{ $latestSectionTS }}</span>
 
                 <div class="p-3 border-bottom screen-only">
-                    <div class="">
-                        <div class="d-flex align-items-center mb-2">
-                            <p class="font-weight-bold text-secondary m-0 font-size-14">ERx/Orders Summary</p>
-                            <span class="mx-2 text-secondary screen-only">|</span>
-                            <a href="/patients/view/{{$patient->uid}}/tickets/erx/create?popupmode=1&note-uid={{$note->uid}}"
-                               native target="_blank"
-                               class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
-                                + ERx
-                            </a>
-                            <span class="mx-2 text-secondary screen-only">|</span>
-                            <a href="/patients/view/{{$patient->uid}}/tickets/lab/create?popupmode=1&note-uid={{$note->uid}}"
-                               native target="_blank"
-                               class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
-                                + Lab
-                            </a>
-                            <span class="mx-2 text-secondary screen-only">|</span>
-                            <a href="/patients/view/{{$patient->uid}}/tickets/imaging/create?popupmode=1&note-uid={{$note->uid}}"
-                               native target="_blank"
-                               class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
-                                + Imaging
-                            </a>
-                            <span class="mx-2 text-secondary screen-only">|</span>
-                            <a href="/patients/view/{{$patient->uid}}/tickets/other/create?popupmode=1&note-uid={{$note->uid}}"
-                               native target="_blank"
-                               class="ticket-popup-trigger note-dashboard-action d-block text-nowrap screen-only">
-                                + Other
-                            </a>
-                        </div>
-
-                        <div class="p-3 border">
-
-                            <p class="font-weight-bold text-secondary mb-2 mr-2">Associated with this note</p>
-                            <div>
-                                @if($ticketsOnNote && count($ticketsOnNote))
-                                    <table class="table table-sm table-bordered mb-0">
-                                    <thead>
-                                    <tr class="bg-light">
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Created</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Type</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Pro</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">View</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Status</th>
-                                        <th class="px-2 text-secondary border-bottom-0">Detail</th>
-                                    </tr>
-                                    </thead>
-                                    <tbody>
-                                    @foreach($ticketsOnNote as $ticket)
-                                        <?php $data = json_decode($ticket->data); ?>
-                                        @if($ticket->category === 'erx' || $ticket->category === 'lab' || $ticket->category === 'imaging')
-                                        <tr class="{{$ticket->is_open ? '' : 'bg-light on-hover-opaque'}}">
-                                            <td class="px-2 text-nowrap">
-                                                {{friendly_time($ticket->created_at)}}
-                                            </td>
-                                            <td class="px-2 text-nowrap">
-                                                {{$ticket->category}}
-                                            </td>
-                                            <td class="px-2 text-nowrap">
-                                                @if($ticket->orderingPro)
-                                                    @if($ticket->orderingPro->id !== $pro->id)
-                                                        <b>{{$ticket->orderingPro->displayName()}}</b>
-                                                    @else
-                                                        You
-                                                    @endif
-                                                @else
-                                                    -
-                                                @endif
-                                            </td>
-                                            <td class="px-2 text-nowrap">
-                                                <div class="d-flex align-items-center flex-nowrap">
-                                                    <a href="/patients/view/{{$ticket->patient->uid}}/tickets/{{$ticket->category}}/{{$ticket->uid}}?popupmode=1"
-                                                       native target="_blank"
-                                                       class="ticket-popup-trigger note-dashboard-action d-block text-nowrap mr-3">
-                                                        View
-                                                    </a>
-                                                </div>
-                                            </td>
-                                            <td class="px-2 text-nowrap">
-                                                {{$ticket->is_open ? 'Open' : 'Closed'}}
-                                            </td>
-                                            <td class="px-2">
-                                            @if($ticket->category === 'erx')
-                                                <div class="font-size-13 mb-1">{{$data->medication}}</div>
-                                                <div class="d-flex align-items-center flex-wrap text-secondary">
-                                                    @if($data->strength)
-                                                        <span class="d-inline-flex align-items-center">
-                                                            <span class="mx-2 text-secondary">•</span>
-                                                            <span>{{$data->strength}}</span>
-                                                        </span>
-                                                    @endif
-                                                    @if($data->route)
-                                                        <span class="d-inline-flex align-items-center">
-                                                            <span class="mx-2 text-secondary">•</span>
-                                                            <span>{{$data->route}}</span>
-                                                        </span>
-                                                    @endif
-                                                    @if($data->frequency)
-                                                        <span class="d-inline-flex align-items-center">
-                                                            <span class="mx-2 text-secondary">•</span>
-                                                            <span>{{$data->frequency}}</span>
-                                                        </span>
-                                                    @endif
-                                                    @if($data->dispense)
-                                                        <span class="d-inline-flex align-items-center">
-                                                            <span class="mx-2 text-secondary">•</span>
-                                                            <span>Dispense:</span> {{$data->dispense}}
-                                                        </span>
-                                                    @endif
-                                                    @if($data->frequency)
-                                                        <span class="d-inline-flex align-items-center">
-                                                            <span class="mx-2 text-secondary">•</span>
-                                                            <span><span>Refills:</span> {{$data->refills}}</span>
-                                                        </span>
-                                                    @endif
-                                                    @if($data->dispense)
-                                                        <span class="d-inline-flex align-items-center">
-                                                            <span class="mx-2 text-secondary">•</span>
-                                                            <span><span>Purpose:</span> {{$data->purpose}}</span>
-                                                        </span>
-                                                    @endif
-                                                </div>
-                                            @endif
-                                            @if($ticket->category === 'lab' || $ticket->category === 'imaging')
-                                                @if(@$data->tests && is_array($data->tests))
-                                                    <div>
-                                                        <span class="text-secondary">Tests:</span>
-                                                        {{implode(", ", $data->tests)}}
-                                                    </div>
-                                                @endif
-                                                @if(@$data->icds && is_array($data->icds))
-                                                    <div>
-                                                        <span class="text-secondary">ICDs:</span>
-                                                        {{implode(", ", $data->icds)}}
-                                                    </div>
-                                                @endif
-                                            @endif
-                                            </td>
-                                        </tr>
-                                        @endif
-                                    @endforeach
-                                    </tbody>
-                                    </table>
-                                @else
-                                    <div class="text-secondary">None</div>
-                                @endif
-                            </div>
-
-                            <hr class="my-2">
-
-                            <p class="font-weight-bold text-secondary mb-2 mr-2">Others open as of {{friendlier_date(date('Y-m-d'))}}</p>
-                            @if($otherOpenTickets && count($otherOpenTickets))
-                                <table class="table table-sm table-bordered mb-0">
-                                    <thead>
-                                    <tr class="bg-light">
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Created</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Type</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Pro</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">View</th>
-                                        <th class="px-2 text-secondary border-bottom-0 width-30px">Status</th>
-                                        <th class="px-2 text-secondary border-bottom-0">Detail</th>
-                                    </tr>
-                                    </thead>
-                                    <tbody>
-                                    @foreach($otherOpenTickets as $ticket)
-                                        <?php $data = json_decode($ticket->data); ?>
-                                        @if($ticket->category === 'erx' || $ticket->category === 'lab' || $ticket->category === 'imaging' || $ticket->category === 'other')
-                                            <tr class="{{$ticket->is_open ? '' : 'bg-light on-hover-opaque'}}">
-                                                <td class="px-2 text-nowrap">
-                                                    {{friendly_time($ticket->created_at)}}
-                                                </td>
-                                                <td class="px-2 text-nowrap">
-                                                    {{$ticket->category}}
-                                                </td>
-                                                <td class="px-2 text-nowrap">
-                                                    @if($ticket->orderingPro)
-                                                        @if($ticket->orderingPro->id !== $pro->id)
-                                                            <b>{{$ticket->orderingPro->displayName()}}</b>
-                                                        @else
-                                                            You
-                                                        @endif
-                                                    @else
-                                                        -
-                                                    @endif
-                                                </td>
-                                                <td class="px-2 text-nowrap">
-                                                    <div class="d-flex align-items-center flex-nowrap">
-                                                        <a href="/patients/view/{{$ticket->patient->uid}}/tickets/{{$ticket->category}}/{{$ticket->uid}}?popupmode=1"
-                                                           native target="_blank"
-                                                           class="ticket-popup-trigger note-dashboard-action d-block text-nowrap mr-3">
-                                                            View
-                                                        </a>
-                                                    </div>
-                                                </td>
-                                                <td class="px-2 text-nowrap">
-                                                    {{$ticket->is_open ? 'Open' : 'Closed'}}
-                                                </td>
-                                                <td class="px-2">
-                                                    @if($ticket->category === 'erx')
-                                                        <div class="font-size-13 mb-1">{{$data->medication}}</div>
-                                                        <div class="d-flex align-items-center flex-wrap text-secondary">
-                                                            @if($data->strength)
-                                                                <span class="d-inline-flex align-items-center">
-                                                        <span class="mx-2 text-secondary">•</span>
-                                                        <span>{{$data->strength}}</span>
-                                                    </span>
-                                                            @endif
-                                                            @if($data->route)
-                                                                <span class="d-inline-flex align-items-center">
-                                                        <span class="mx-2 text-secondary">•</span>
-                                                        <span>{{$data->route}}</span>
-                                                    </span>
-                                                            @endif
-                                                            @if($data->frequency)
-                                                                <span class="d-inline-flex align-items-center">
-                                                        <span class="mx-2 text-secondary">•</span>
-                                                        <span>{{$data->frequency}}</span>
-                                                    </span>
-                                                            @endif
-                                                            @if($data->dispense)
-                                                                <span class="d-inline-flex align-items-center">
-                                                        <span class="mx-2 text-secondary">•</span>
-                                                        <span>Dispense:</span> {{$data->dispense}}
-                                                    </span>
-                                                            @endif
-                                                            @if($data->frequency)
-                                                                <span class="d-inline-flex align-items-center">
-                                                        <span class="mx-2 text-secondary">•</span>
-                                                        <span><span>Refills:</span> {{$data->refills}}</span>
-                                                    </span>
-                                                            @endif
-                                                            @if($data->dispense)
-                                                                <span class="d-inline-flex align-items-center">
-                                                        <span class="mx-2 text-secondary">•</span>
-                                                        <span><span>Purpose:</span> {{$data->purpose}}</span>
-                                                    </span>
-                                                            @endif
-                                                        </div>
-                                                    @endif
-                                                    @if($ticket->category === 'lab' || $ticket->category === 'imaging')
-                                                        @if(@$data->tests && is_array($data->tests))
-                                                            <div>
-                                                                <span class="text-secondary">Tests:</span>
-                                                                {{implode(", ", $data->tests)}}
-                                                            </div>
-                                                        @endif
-                                                        @if(@$data->icds && is_array($data->icds))
-                                                            <div>
-                                                                <span class="text-secondary">ICDs:</span>
-                                                                {{implode(", ", $data->icds)}}
-                                                            </div>
-                                                        @endif
-                                                    @endif
-                                                    @if($ticket->category === 'other')
-                                                        <div>
-                                                            {{$data->title}}
-                                                        </div>
-                                                    @endif
-                                                </td>
-                                            </tr>
-                                        @endif
-                                    @endforeach
-                                    </tbody>
-                                </table>
-                            @else
-                                <div class="text-secondary">None</div>
-                            @endif
-
-                        </div>
-
-                    </div>
+                    @include('app.patient.prescriptions.list', compact('patient', 'note'))
                 </div>
 
                 <div class="p-3 border-bottom screen-only">

+ 1 - 824
resources/views/app/patient/prescriptions/index.blade.php

@@ -1,828 +1,5 @@
 @extends ('layouts.patient')
 
 @section('inner-content')
-    <div id="prescriptions-{{$patient->id}}">
-        <div class="d-flex align-items-baseline py-2">
-            <h6 class="my-0 font-weight-bold text-secondary font-size-14">Prescriptions</h6>
-            <span class="mx-2 text-secondary on-hover-opaque">|</span>
-            <a href="#" v-on:click.prevent="newPrescription('DRUG')">+ Drug</a>
-            <span class="mx-2 text-secondary on-hover-opaque">|</span>
-            <a href="#" v-on:click.prevent="newPrescription('LAB')">+ Lab</a>
-            <span class="mx-2 text-secondary on-hover-opaque">|</span>
-            <a href="#" v-on:click.prevent="newPrescription('IMAGING')">+ Imaging</a>
-            <span class="mx-2 text-secondary on-hover-opaque">|</span>
-            <a href="#" v-on:click.prevent="newPrescription('REFERRAL')">+ Referral</a>
-            <span class="mx-2 text-secondary on-hover-opaque">|</span>
-            <a href="#" v-on:click.prevent="newPrescription('SUPPLY')">+ Supply</a>
-            <span class="mx-2 text-secondary on-hover-opaque">|</span>
-            <a href="#" v-on:click.prevent="newPrescription('OTHER')">+ Other</a>
-        </div>
-        <div class="d-flex align-items-start">
-            <table class="table table-striped table-sm table-bordered mb-0 flex-grow-1">
-                <thead>
-                <tr>
-                    <th class="px-2 text-secondary border-bottom-0">Created</th>
-                    <th class="px-2 text-secondary border-bottom-0">Type</th>
-                    <th class="px-2 text-secondary border-bottom-0">Clinical</th>
-                    <th class="px-2 text-secondary border-bottom-0">Prescriber</th>
-                    <th class="px-2 text-secondary border-bottom-0">Sign</th>
-                </tr>
-                </thead>
-                <tbody>
-                <tr v-for="(prescription, index) in prescriptions" :class="currentPrescription && currentPrescription.id === prescription.id ? 'bg-aliceblue' : ''">
-                    <td class="px-2">
-                        <a href="#" v-on:click.prevent="currentPrescription=prescription"
-                           :class="currentPrescription && currentPrescription.id === prescription.id ? 'font-weight-bold' : ''">@{{prescription.created_at_friendly_short}}</a>
-                    </td>
-                    <td class="px-2">@{{prescription.erx_category}}</td>
-                    <td class="px-2">
-                        <div class="d-flex align-items-baseline">
-                            {{--
-                            <a v-if="!prescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editClinicalDetails(prescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                            <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
-                            --}}
-                            <div v-if="prescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
-                                <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'DRUG'">
-                                    <b class="mr-2">@{{prescription.clinical_detail_json.medication ?? '-'}}</b>
-                                    <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.frequency ?? ''}}</span>
-                                </div>
-                                <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'LAB' || prescription.erx_category === 'IMAGING'">
-                                    <b class="mr-2">@{{prescription.clinical_detail_json.test ?? '-'}}</b>
-                                    <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.icds ?? '-'}}</span>
-                                </div>
-                                <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'REFERRAL'">
-                                    <b class="mr-2">@{{prescription.clinical_detail_json.to ?? '-'}}</b>
-                                    <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.memo ?? '-'}}</span>
-                                </div>
-                                <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'SUPPLY'">
-                                    <b class="mr-2">@{{prescription.clinical_detail_json.item ?? '-'}}</b>
-                                    <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.quantity ?? '-'}}</span>
-                                </div>
-                                <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'OTHER'">
-                                    <b class="mr-2">@{{prescription.clinical_detail_json.title ?? '-'}}</b>
-                                    <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.memo ?? '-'}}</span>
-                                </div>
-                            </div>
-                            <div v-else>-</div>
-                        </div>
-                    </td>
-                    <td class="px-2">
-                        <div class="d-flex align-items-baseline">
-                            {{--
-                            <a v-if="!prescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editHcpPro(prescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                            <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
-                            --}}
-                            <div>@{{prescription.hcpProDisplayName}}</div>
-                        </div>
-                    </td>
-                    <td class="px-2">
-                        <div v-if="prescription.has_hcp_pro_signed" class="d-flex align-items-baseline">
-                            <i class="text-secondary fa fa-check mr-1"></i>
-                            <span class="text-secondary">Signed</span>
-                        </div>
-                        {{--
-                        <div v-else>
-                            <a v-if="prescription.hcp_pro_id === {{$pro->id}}"
-                               href="#"
-                               v-on:click.prevent="signAsHcpPro(prescription)">Sign</a>
-                            <span v-else>-</span>
-                        </div>
-                        --}}
-                    </td>
-                </tr>
-                </tbody>
-            </table>
-            <div v-if="currentPrescription" class="min-width-500px ml-2 border align-self-stretch p-3">
-                <div class="d-flex align-items-center">
-                    <h3 class="font-size-16 m-0">
-                        <div v-if="currentPrescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'DRUG'">
-                                <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.medication ?? '-'}}</b>
-                                <!--<span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.strength ?? '-'}}</span>
-                                <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.amount ?? '-'}}</span>
-                                <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.route ?? '-'}}</span>-->
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'LAB' || currentPrescription.erx_category === 'IMAGING'">
-                                <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.test ?? '-'}}</b>
-                                <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.icds ?? '-'}}</span>
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'REFERRAL'">
-                                <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.to ?? '-'}}</b>
-                                <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'SUPPLY'">
-                                <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.item ?? '-'}}</b>
-                                <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.quantity ?? '-'}}</span>
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'OTHER'">
-                                <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.title ?? '-'}}</b>
-                                <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
-                            </div>
-                        </div>
-                        <div v-else>-</div>
-                    </h3>
-                    <a class="ml-auto" href="#" v-on:click.prevent="currentPrescription=null">
-                        <i class="fa fa-times-circle on-hover-opaque"></i>
-                    </a>
-                </div>
-                <hr class="my-3">
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Created</span>
-                    <span>@{{currentPrescription.created_at_friendly}}</span>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Type</span>
-                    <span>@{{currentPrescription.erx_category}}</span>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Clinical</span>
-                    <div class="d-inline-flex align-items-baseline flex-grow-1">
-                        <a v-if="!currentPrescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editClinicalDetails(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                        <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
-                        <div v-if="currentPrescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'DRUG'">
-                                <b class="mr-2">@{{currentPrescription.clinical_detail_json.medication ?? '-'}}</b>
-                                <!--<span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.strength ?? '-'}}</span>
-                                <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.dispense ?? '-'}}</span>
-                                <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.refills ?? '-'}}</span>-->
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'LAB' || currentPrescription.erx_category === 'IMAGING'">
-                                <b class="mr-2">@{{currentPrescription.clinical_detail_json.test ?? '-'}}</b>
-                                <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.icds ?? '-'}}</span>
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'REFERRAL'">
-                                <b class="mr-2">@{{currentPrescription.clinical_detail_json.to ?? '-'}}</b>
-                                <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'SUPPLY'">
-                                <b class="mr-2">@{{currentPrescription.clinical_detail_json.item ?? '-'}}</b>
-                                <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.quantity ?? '-'}}</span>
-                            </div>
-                            <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'OTHER'">
-                                <b class="mr-2">@{{currentPrescription.clinical_detail_json.title ?? '-'}}</b>
-                                <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
-                            </div>
-                        </div>
-                        <div v-else>-</div>
-                    </div>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Logistics</span>
-                    <div class="d-inline-flex align-items-baseline flex-grow-1">
-                        <a class="mr-2" href="#" v-on:click.prevent="editLogisticsDetails(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                        <div v-if="currentPrescription.logistics_detail_json" class="d-flex align-items-baseline">
-                            <div class="d-flex align-items-baseline">
-                                <b class="mr-2">@{{currentPrescription.logistics_detail_json.facilityName ?? '-'}}</b>
-                                <span class="text-secondary mr-1">@{{currentPrescription.logistics_detail_json.facilityCity ?? '-'}}</span>
-                                <span class="text-secondary mr-1">@{{currentPrescription.logistics_detail_json.facilityState ?? '-'}}</span>
-                            </div>
-                        </div>
-                        <div v-else>-</div>
-                    </div>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">HCP Pro</span>
-                    <div class="d-inline-flex align-items-baseline flex-grow-1">
-                        <a v-if="!currentPrescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editHcpPro(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                        <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
-                        <div>@{{currentPrescription.hcpProDisplayName}}</div>
-                    </div>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Sign</span>
-                    <div v-if="currentPrescription.has_hcp_pro_signed" class="d-inline-flex align-items-baseline">
-                        <i class="text-secondary fa fa-check mr-1"></i>
-                        <span class="text-secondary">Signed</span>
-                    </div>
-                    <div v-else>
-                        <a v-if="currentPrescription.hcp_pro_id === {{$pro->id}}"
-                           href="#"
-                           v-on:click.prevent="signAsHcpPro(currentPrescription)">Sign</a>
-                        <span v-else>-</span>
-                    </div>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Pro Status</span>
-                    <div class="d-inline-flex align-items-baseline">
-                        <a class="mr-2" href="#" v-on:click.prevent="editProStatus(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                        <div v-if="currentPrescription.pro_declared_status" class="d-flex align-items-baseline">
-                            @{{ sanitizeStatus(currentPrescription.pro_declared_status) }}
-                        </div>
-                        <div v-else>-</div>
-                    </div>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">Client Status</span>
-                    <div class="d-inline-flex align-items-baseline">
-                        <a class="mr-2" href="#" v-on:click.prevent="editClientStatus(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
-                        <div v-if="currentPrescription.client_declared_status" class="d-flex align-items-baseline">
-                            @{{ sanitizeStatus(currentPrescription.client_declared_status) }}
-                        </div>
-                        <div v-else>-</div>
-                    </div>
-                </div>
-                <div class="pb-2 d-flex align-items-center">
-                    <span class="min-width-140px text-secondary text-sm">PDF</span>
-                    <div class="d-inline-flex align-items-baseline">
-                        <a class="pdf-viewer-trigger" native target="_blank"
-                           :href="'/prescription-download-as-pdf/' + currentPrescription.uid">View</a>
-                        <span class="mx-2 text-secondary">|</span>
-                        <a native target="_blank"
-                           :href="'/prescription-download-as-pdf/' + currentPrescription.uid">Download</a>
-                        <span class="mx-2 text-secondary">|</span>
-                        <a href="#" v-on:click.prevent="transmit(currentPrescription)">Transmit</a>
-                    </div>
-                </div>
-            </div>
-        </div>
-        @include('app.patient.prescriptions.drug-form')
-        @include('app.patient.prescriptions.lab-form')
-        @include('app.patient.prescriptions.imaging-form')
-        @include('app.patient.prescriptions.referral-form')
-        @include('app.patient.prescriptions.supply-form')
-        @include('app.patient.prescriptions.other-form')
-        @include('app.patient.prescriptions.logistics-form')
-        @include('app.patient.prescriptions.hcp-pro-form')
-        @include('app.patient.prescriptions.sign-as-hcp-form')
-        @include('app.patient.prescriptions.pro-status-form')
-        @include('app.patient.prescriptions.client-status-form')
-        @include('app.patient.prescriptions.transmit-form')
-    </div>
-    <script>
-        (function() {
-
-            <?php
-            $prescriptions = $patient->prescriptions;
-            $currentPrescription = null;
-            foreach ($prescriptions as $prescription) {
-                if($prescription->clinical_detail_json) {
-                    $prescription->clinical_detail_json = json_decode($prescription->clinical_detail_json);
-                }
-                if($prescription->logistics_detail_json) {
-                    $prescription->logistics_detail_json = json_decode($prescription->logistics_detail_json);
-                }
-                $prescription->created_at_friendly = friendlier_date_time($prescription->created_at);
-                $prescription->created_at_friendly_short = friendlier_date_time($prescription->created_at, false);
-                $prescription->hcpProDisplayName = $prescription->hcpPro ? $prescription->hcpPro->displayName() : '-';
-                $prescription->hcpProUid = $prescription->hcpPro ? $prescription->hcpPro->uid : '';
-
-                if(!!@$currentErx && $currentErx->uid === $prescription->uid) {
-                    $currentPrescription = $prescription;
-                }
-            }
-            ?>
-
-            function init() {
-
-                new Vue({
-                    el: '#prescriptions-{{$patient->id}}',
-                    delimiters: ['@{{', '}}'],
-                    data: {
-                        prescriptions: <?= json_encode($prescriptions) ?>,
-
-                        currentPrescriptionAction: '',
-                        currentPrescriptionType: '',
-
-                        // selected
-                        currentPrescription:  <?= $currentPrescription ? json_encode($currentPrescription) : 'null' ?>,
-
-                        // for editing clinical details
-                        currentPrescription_DRUG: {
-                            noteUid: null, // TODO: this won't be null if created from a note
-                            clientUid: '{{ $patient->uid }}',
-                            replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                            hcpProUid: '{{$pro->uid}}',
-                            erxCategory: 'DRUG',
-                            clinicalDetailJson: {
-                                medication: '',
-                                route: '',
-                                dose: '',
-                                strength: '',
-                                frequency: '',
-                                dispense: '',
-                                refills: '',
-                                purpose: '',
-
-                                // fdb specific
-                                medNameID: '',
-                                routedMedID: '',
-                                dosageFormMedID: '',
-                                gcnSeqno: '',
-                                medId: '',
-                            }
-                        },
-                        currentPrescription_LAB: {
-                            noteUid: null, // TODO: this won't be null if created from a note
-                            clientUid: '{{ $patient->uid }}',
-                            replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                            hcpProUid: '{{$pro->uid}}',
-                            erxCategory: 'LAB',
-                            clinicalDetailJson: {
-                                test: '',
-                                icds: '',
-                                memo: '',
-                            }
-                        },
-                        currentPrescription_IMAGING: {
-                            noteUid: null, // TODO: this won't be null if created from a note
-                            clientUid: '{{ $patient->uid }}',
-                            replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                            hcpProUid: '{{$pro->uid}}',
-                            erxCategory: 'IMAGING',
-                            clinicalDetailJson: {
-                                test: '',
-                                icds: '',
-                                memo: '',
-                            }
-                        },
-                        currentPrescription_REFERRAL: {
-                            noteUid: null, // TODO: this won't be null if created from a note
-                            clientUid: '{{ $patient->uid }}',
-                            replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                            hcpProUid: '{{$pro->uid}}',
-                            erxCategory: 'REFERRAL',
-                            clinicalDetailJson: {
-                                to: '',
-                                memo: '',
-                            }
-                        },
-                        currentPrescription_SUPPLY: {
-                            noteUid: null, // TODO: this won't be null if created from a note
-                            clientUid: '{{ $patient->uid }}',
-                            replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                            hcpProUid: '{{$pro->uid}}',
-                            erxCategory: 'SUPPLY',
-                            clinicalDetailJson: {
-                                item: '',
-                                quantity: '',
-                                memo: '',
-                            }
-                        },
-                        currentPrescription_OTHER: {
-                            noteUid: null, // TODO: this won't be null if created from a note
-                            clientUid: '{{ $patient->uid }}',
-                            replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                            hcpProUid: '{{$pro->uid}}',
-                            erxCategory: 'OTHER',
-                            clinicalDetailJson: {
-                                title: '',
-                                memo: '',
-                            }
-                        },
-
-                        // for editing logistics - common
-                        currentPrescriptionLogistics: {
-                            uid: '',
-                            logisticsDetailJson: {
-                                facilityName: '',
-                                facilityCity: '',
-                                facilityState: '',
-                                facilityAddressMemo: '',
-                                facilityPhone: '',
-                                facilityFax: '',
-                                facilityZip: '',
-                            }
-                        },
-
-                        // for editing hcp, sign, pro status & client status - common
-                        currentPrescriptionHcpPro: {
-                            uid: '',
-                            newHcpProUid: '',
-                        },
-                        currentPrescriptionSign: {
-                            uid: '',
-                            declaredVersionNumber: '',
-                        },
-                        currentPrescriptionProStatus: {
-                            uid: '',
-                            status: '',
-                            memo: '',
-                        },
-                        currentPrescriptionClientStatus: {
-                            uid: '',
-                            status: '',
-                            memo: '',
-                        },
-                        currentPrescriptionTransmit: {
-                            uid: '',
-                            logistics: '',
-                            toWho: '',
-                            toEmail: '',
-                            toFaxNumber: '',
-                            toFaxNumberAttentionLine: '',
-                            toFaxNumberCoverSheetMemo: '',
-                            copyToPatient: false,
-                            copyToPatientFaxNumber: '',
-                            copyToPatientEmail: '',
-                        }
-                    },
-                    methods: {
-
-                        // new/edit/save-clinical
-                        newPrescription: function(_type) {
-                            this.currentPrescriptionAction = 'ADD';
-                            this.currentPrescriptionType = _type;
-                            switch (_type) {
-                                case 'DRUG':
-                                    this.currentPrescription_DRUG = {
-                                        noteUid: null, // TODO: this won't be null if created from a note
-                                        clientUid: '{{ $patient->uid }}',
-                                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                                        hcpProUid: '{{$pro->uid}}',
-                                        erxCategory: _type,
-                                        clinicalDetailJson: {
-                                            medication: '',
-                                            route: '',
-                                            dose: '',
-                                            strength: '',
-                                            frequency: '',
-                                            dispense: '',
-                                            refills: '',
-                                            purpose: '',
-
-                                            // fdb specific
-                                            medNameID: '',
-                                            routedMedID: '',
-                                            dosageFormMedID: '',
-                                            gcnSeqno: '',
-                                            medId: '',
-                                        }
-                                    };
-                                    break;
-                                case 'LAB':
-                                case 'IMAGING':
-                                    this.currentPrescription_LAB = {
-                                        noteUid: null, // TODO: this won't be null if created from a note
-                                        clientUid: '{{ $patient->uid }}',
-                                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                                        hcpProUid: '{{$pro->uid}}',
-                                        erxCategory: _type,
-                                        clinicalDetailJson: {
-                                            test: '',
-                                            icds: '',
-                                            memo: '',
-                                        }
-                                    };
-                                    break;
-                                case 'REFERRAL':
-                                    this.currentPrescription_LAB = {
-                                        noteUid: null, // TODO: this won't be null if created from a note
-                                        clientUid: '{{ $patient->uid }}',
-                                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                                        hcpProUid: '{{$pro->uid}}',
-                                        erxCategory: _type,
-                                        clinicalDetailJson: {
-                                            to: '',
-                                            memo: '',
-                                        }
-                                    };
-                                    break;
-                                case 'SUPPLY':
-                                    this.currentPrescription_LAB = {
-                                        noteUid: null, // TODO: this won't be null if created from a note
-                                        clientUid: '{{ $patient->uid }}',
-                                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                                        hcpProUid: '{{$pro->uid}}',
-                                        erxCategory: _type,
-                                        clinicalDetailJson: {
-                                            item: '',
-                                            quantity: '',
-                                            memo: '',
-                                        }
-                                    };
-                                    break;
-                                case 'OTHER':
-                                    this.currentPrescription_LAB = {
-                                        noteUid: null, // TODO: this won't be null if created from a note
-                                        clientUid: '{{ $patient->uid }}',
-                                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
-                                        hcpProUid: '{{$pro->uid}}',
-                                        erxCategory: _type,
-                                        clinicalDetailJson: {
-                                            title: '',
-                                            memo: '',
-                                        }
-                                    };
-                                    break;
-                            }
-                            Vue.nextTick(() => {
-                                showStagPopup('prescription-popup-' + this.currentPrescriptionType, true);
-                                if(_type === 'DRUG') {
-                                    $('[stag-suggest][stag-suggest-initialized]').removeAttr('stag-suggest-initialized');
-                                    initStagSuggest();
-                                    this.initFdbMedSuggest();
-                                }
-                            });
-                        },
-                        editClinicalDetails: function(_prescription) {
-                            this.currentPrescriptionAction = 'EDIT_CLINICAL';
-                            this.currentPrescriptionType = _prescription.erx_category;
-                            this['currentPrescription_' + this.currentPrescriptionType] = {
-                                uid: _prescription.uid,
-                                clinicalDetailJson: JSON.parse(JSON.stringify(_prescription.clinical_detail_json))
-                            };
-                            Vue.nextTick(() => {
-                                showStagPopup('prescription-popup-' + this.currentPrescriptionType, true);
-                                if(this.currentPrescriptionType === 'DRUG') {
-                                    $('[stag-suggest][stag-suggest-initialized]').removeAttr('stag-suggest-initialized');
-                                    initStagSuggest();
-                                    this.initFdbMedSuggest();
-
-                                    // re-populate drug fields
-                                    console.log(this.currentPrescription_DRUG);
-                                    let parentSegment = $('#prescriptions-{{$patient->id}} [stag-popup-key="prescription-popup-DRUG"]>form').first();
-                                    parentSegment.find('input.prescription-medication').val(this.currentPrescription_DRUG.clinicalDetailJson.medication);
-                                    parentSegment.find('select.prescription-route')
-                                        .empty()
-                                        .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.route))
-                                        .val(1);
-                                    parentSegment.find('select.prescription-dose')
-                                        .empty()
-                                        .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.dose))
-                                        .val(1);
-                                    parentSegment.find('select.prescription-strength')
-                                        .empty()
-                                        .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.strength))
-                                        .val(1);
-                                }
-                            });
-                        },
-                        savePrescription: function() {
-                            let payload = JSON.parse(JSON.stringify(this['currentPrescription_' + this.currentPrescriptionType]));
-                            payload.clinicalDetailJson = JSON.stringify(payload.clinicalDetailJson);
-                            switch (this.currentPrescriptionAction) {
-                                case 'ADD':
-                                    $.post('/api/erx/create', payload, _data => {
-                                        if(!hasResponseError(_data)) {
-                                            toastr.success('Prescription added');
-                                            closeStagPopup();
-                                            fastLoad('/patients/view/{{$patient->uid}}/prescriptions/' + this.currentPrescriptionType.toLowerCase() + '/' + _data.data);
-                                        }
-                                    }, 'json');
-                                    break;
-                                case 'EDIT_CLINICAL':
-                                    $.post('/api/erx/updateClinicalDetail', payload, _data => {
-                                        if(!hasResponseError(_data)) {
-                                            toastr.success('Prescription updated');
-                                            closeStagPopup();
-                                            fastReload();
-                                        }
-                                    }, 'json');
-                                    break;
-                            }
-                        },
-
-                        // edit logistics
-                        editLogisticsDetails: function(_prescription) {
-                            this.currentPrescriptionAction = 'EDIT_LOGISTICS';
-                            this.currentPrescriptionLogistics = {
-                                uid: _prescription.uid,
-                                logisticsDetailJson: _prescription.logistics_detail_json ? JSON.parse(JSON.stringify(_prescription.logistics_detail_json)) : {
-                                    facilityName: '',
-                                    facilityCity: '',
-                                    facilityState: '',
-                                    facilityAddressMemo: '',
-                                    facilityPhone: '',
-                                    facilityFax: '',
-                                    facilityZip: '',
-                                }
-                            }
-                            Vue.nextTick(() => {
-                                showStagPopup('logistics-popup', true);
-                            });
-                        },
-                        saveLogistics: function() {
-                            let payload = JSON.parse(JSON.stringify(this.currentPrescriptionLogistics));
-                            payload.logisticsDetailJson = JSON.stringify(payload.logisticsDetailJson);
-                            $.post('/api/erx/updateLogisticsDetail', payload, _data => {
-                                if(!hasResponseError(_data)) {
-                                    toastr.success('Logistics updated');
-                                    closeStagPopup();
-                                    fastReload();
-                                }
-                            }, 'json');
-                        },
-
-                        // edit hcp (ordering) pro
-                        editHcpPro: function(_prescription) {
-                            this.currentPrescriptionAction = 'EDIT_HCP_PRO';
-                            this.currentPrescriptionType = _prescription.erx_category;
-                            this.currentPrescriptionHcpPro = {
-                                uid: _prescription.uid,
-                                newHcpProUid: _prescription.hcpProUid
-                            };
-                            Vue.nextTick(() => {
-                                showStagPopup('hcp-pro-popup', true);
-                                $('.erx-hcp-pro-select').removeAttr('pro-suggest-initialized');
-                                initProSuggest();
-                            });
-                        },
-                        saveHcpPro: function() {
-                            let payload = JSON.parse(JSON.stringify(this.currentPrescriptionHcpPro));
-                            $.post('/api/erx/updateHcpPro', payload, _data => {
-                                if(!hasResponseError(_data)) {
-                                    toastr.success('HCP Pro updated');
-                                    closeStagPopup();
-                                    fastReload();
-                                }
-                            }, 'json');
-                        },
-
-                        // sign
-                        signAsHcpPro: function(_prescription) {
-                            this.currentPrescriptionAction = 'SIGN_AS_HCP';
-                            this.currentPrescriptionType = _prescription.erx_category;
-                            this.currentPrescriptionSign = {
-                                uid: _prescription.uid,
-                                declaredVersionNumber: _prescription.version_number
-                            };
-                            Vue.nextTick(() => {
-                                showStagPopup('sign-as-hcp-popup', true);
-                            });
-                        },
-                        saveSignAsHcpPro: function() {
-                            let payload = JSON.parse(JSON.stringify(this.currentPrescriptionSign));
-                            $.post('/api/erx/signAsHcp', payload, _data => {
-                                if(!hasResponseError(_data)) {
-                                    toastr.success('Signed');
-                                    closeStagPopup();
-                                    fastReload();
-                                }
-                            }, 'json');
-                        },
-
-                        // edit pro status
-                        editProStatus: function(_prescription) {
-                            this.currentPrescriptionAction = 'EDIT_PRO_DECLARED_STATUS';
-                            this.currentPrescriptionType = _prescription.erx_category;
-                            this.currentPrescriptionProStatus = {
-                                uid: _prescription.uid,
-                                status: _prescription.pro_declared_status,
-                                memo: _prescription.pro_declared_status_memo,
-                            };
-                            Vue.nextTick(() => {
-                                showStagPopup('pro-status-popup', true);
-                            });
-                        },
-                        saveProStatus: function() {
-                            let payload = JSON.parse(JSON.stringify(this.currentPrescriptionProStatus));
-                            $.post('/api/erx/updateProDeclaredStatus', payload, _data => {
-                                if(!hasResponseError(_data)) {
-                                    toastr.success('Pro declared status updated');
-                                    closeStagPopup();
-                                    fastReload();
-                                }
-                            }, 'json');
-                        },
-
-                        // edit client status
-                        editClientStatus: function(_prescription) {
-                            this.currentPrescriptionAction = 'EDIT_CLIENT_DECLARED_STATUS';
-                            this.currentPrescriptionType = _prescription.erx_category;
-                            this.currentPrescriptionClientStatus = {
-                                uid: _prescription.uid,
-                                status: _prescription.client_declared_status,
-                                memo: _prescription.client_declared_status_memo,
-                            };
-                            Vue.nextTick(() => {
-                                showStagPopup('client-status-popup', true);
-                            });
-                        },
-                        saveClientStatus: function() {
-                            let payload = JSON.parse(JSON.stringify(this.currentPrescriptionClientStatus));
-                            $.post('/api/erx/updateClientDeclaredStatus', payload, _data => {
-                                if(!hasResponseError(_data)) {
-                                    toastr.success('Client declared status updated');
-                                    closeStagPopup();
-                                    fastReload();
-                                }
-                            }, 'json');
-                        },
-
-                        // sane display status
-                        sanitizeStatus: function(_s) {
-                            _s = _s.toLowerCase().replaceAll('_', ' ');
-                            _s = _s[0].toUpperCase() + _s.substr(1);
-                            return _s;
-                        },
-
-                        // transmit
-                        transmit: function(_prescription) {
-                            this.currentPrescriptionTransmit = {
-                                uid: _prescription.uid,
-                                toWho: _prescription.logistics_detail_json ? _prescription.logistics_detail_json.facilityName : '',
-                                toEmail: '',
-                                toFaxNumber: _prescription.logistics_detail_json ? _prescription.logistics_detail_json.facilityFax : '',
-                                toFaxNumberAttentionLine: '',
-                                toFaxNumberCoverSheetMemo: '',
-                                copyToPatient: false,
-                                copyToPatientFaxNumber: '{{$patient->cell_number}}',
-                                copyToPatientEmail: '{{$patient->email_address}}',
-                                _token: '{{csrf_token()}}'
-                            };
-                            Vue.nextTick(() => {
-                                showStagPopup('transmit-popup');
-                                this.transmitModalPDFPreview();
-                            });
-                        },
-                        transmitModalPDFPreview: function() {
-
-                            let _loadedPDF = null, _numPages = 1, _page = 1;
-
-                            function _load(_url) {
-
-                                _loadedPDF = null;
-                                _numPages = 1;
-                                _page = 1;
-
-                                $('#transmit-pdf-preview>canvas').remove();
-
-                                let url = _url;
-                                let pdfjsLib = window['pdfjs-dist/build/pdf'];
-                                pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
-                                let loadingTask = pdfjsLib.getDocument(url);
-                                loadingTask.promise.then(function (pdf) {
-                                    _numPages = pdf.numPages;
-                                    _loadedPDF = pdf;
-                                    _page = 1;
-                                    _render();
-                                }, function (reason) {
-                                    // reason.message;
-                                });
-                            }
-                            function _render() {
-
-                                _loadedPDF.getPage(_page).then(function (page) {
-
-                                    // create canvas
-                                    let canvasElement = $('<canvas/>')
-                                        .addClass('pdf-viewer-page pdf-preview-page')
-                                        .appendTo('#transmit-pdf-preview');
-
-                                    let canvas = canvasElement[0];
-                                    let viewport = page.getViewport({scale: 0.75});
-                                    let context = canvas.getContext('2d');
-                                    canvas.height = viewport.height;
-                                    canvas.width = viewport.width;
-                                    const $canvas = $(canvas);
-                                    let renderContext = {
-                                        canvasContext: context,
-                                        viewport: viewport
-                                    };
-                                    let renderTask = page.render(renderContext);
-                                    renderTask.promise.then(function () {
-                                        if(_page < _numPages) {
-                                            _page++;
-                                            _render();
-                                        }
-                                    });
-                                });
-                            }
-
-                            _load('/prescription-download-as-pdf/' + this.currentPrescriptionTransmit.uid);
-                        },
-                        doTransmit: function (_item) {
-                            let payload = JSON.parse(JSON.stringify(this.currentPrescriptionTransmit));
-                            $.post('/prescription-transmit/' + payload.uid, payload, _data => {
-                                if(!hasResponseError(_data)) {
-                                    toastr.success('Transmission initiated');
-                                    closeStagPopup();
-                                    fastReload();
-                                }
-                            }, 'json');
-                            closeStagPopup();
-                        },
-
-                        // cancel, etc.
-
-                        initFdbMedSuggest: function() {
-
-                            let self = this;
-
-                            let parentSegment = $('#prescriptions-{{$patient->id}} [stag-popup-key="prescription-popup-DRUG"]>form').first();
-
-                            parentSegment.find('input.prescription-medication').off('stag-suggest-selected');
-                            parentSegment.find('input.prescription-medication').on('stag-suggest-selected', (_e, _input, _data) => {
-
-                                // _input is the textbox
-                                // _data is {med_name_id: "50567", text: "Children's Tylenol"}
-
-                                // set vue values
-                                self.currentPrescription_DRUG.clinicalDetailJson.medication = _data.text;
-
-                            });
-                        }
-                    },
-                    mounted: function() {
-                        let self = this;
-                        $(document).on('pro-changed', '.erx-hcp-pro-select', function() {
-                            self.currentPrescriptionHcpPro.newHcpProUid = this.value;
-                        });
-                    }
-                });
-
-            }
-            addMCInitializer('prescriptions-{{$patient->id}}', init, '#prescriptions-{{$patient->id}}')
-        }).call(window);
-    </script>
+    @include('app.patient.prescriptions.list')
 @endsection

+ 837 - 0
resources/views/app/patient/prescriptions/list.blade.php

@@ -0,0 +1,837 @@
+<div id="prescriptions-{{$patient->id}}">
+    <div class="d-flex align-items-baseline py-2">
+        <h6 class="my-0 font-weight-bold text-secondary font-size-14">Prescriptions</h6>
+        <span class="mx-2 text-secondary on-hover-opaque">|</span>
+        <a href="#" v-on:click.prevent="newPrescription('DRUG')">+ Drug</a>
+        <span class="mx-2 text-secondary on-hover-opaque">|</span>
+        <a href="#" v-on:click.prevent="newPrescription('LAB')">+ Lab</a>
+        <span class="mx-2 text-secondary on-hover-opaque">|</span>
+        <a href="#" v-on:click.prevent="newPrescription('IMAGING')">+ Imaging</a>
+        <span class="mx-2 text-secondary on-hover-opaque">|</span>
+        <a href="#" v-on:click.prevent="newPrescription('REFERRAL')">+ Referral</a>
+        <span class="mx-2 text-secondary on-hover-opaque">|</span>
+        <a href="#" v-on:click.prevent="newPrescription('SUPPLY')">+ Supply</a>
+        <span class="mx-2 text-secondary on-hover-opaque">|</span>
+        <a href="#" v-on:click.prevent="newPrescription('OTHER')">+ Other</a>
+    </div>
+    <div class="d-flex align-items-start">
+        <table class="table table-striped table-sm table-bordered mb-0 flex-grow-1">
+            <thead>
+            <tr>
+                <th class="px-2 text-secondary border-bottom-0">Created</th>
+                <th class="px-2 text-secondary border-bottom-0">Type</th>
+                <th class="px-2 text-secondary border-bottom-0">Clinical</th>
+                <th class="px-2 text-secondary border-bottom-0">Prescriber</th>
+                <th class="px-2 text-secondary border-bottom-0">Sign</th>
+            </tr>
+            </thead>
+            <tbody>
+            <tr v-for="(prescription, index) in prescriptions" :class="currentPrescription && currentPrescription.id === prescription.id ? 'bg-aliceblue' : ''">
+                <td class="px-2">
+                    <a href="#" v-on:click.prevent="currentPrescription=prescription"
+                       :class="currentPrescription && currentPrescription.id === prescription.id ? 'font-weight-bold' : ''">@{{prescription.created_at_friendly_short}}</a>
+                    @if(@$note)
+                        <div v-if="prescription.note_id === {{$note->id}}" class="text-info mt-1">* Create on this note</div>
+                    @endif
+                </td>
+                <td class="px-2">@{{prescription.erx_category}}</td>
+                <td class="px-2">
+                    <div class="d-flex align-items-baseline">
+                        {{--
+                        <a v-if="!prescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editClinicalDetails(prescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                        <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
+                        --}}
+                        <div v-if="prescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
+                            <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'DRUG'">
+                                <b class="mr-2">@{{prescription.clinical_detail_json.medication ?? '-'}}</b>
+                                <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.frequency ?? ''}}</span>
+                            </div>
+                            <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'LAB' || prescription.erx_category === 'IMAGING'">
+                                <b class="mr-2">@{{prescription.clinical_detail_json.test ?? '-'}}</b>
+                                <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.icds ?? '-'}}</span>
+                            </div>
+                            <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'REFERRAL'">
+                                <b class="mr-2">@{{prescription.clinical_detail_json.to ?? '-'}}</b>
+                                <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.memo ?? '-'}}</span>
+                            </div>
+                            <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'SUPPLY'">
+                                <b class="mr-2">@{{prescription.clinical_detail_json.item ?? '-'}}</b>
+                                <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.quantity ?? '-'}}</span>
+                            </div>
+                            <div class="d-flex align-items-baseline" v-if="prescription.erx_category === 'OTHER'">
+                                <b class="mr-2">@{{prescription.clinical_detail_json.title ?? '-'}}</b>
+                                <span class="text-secondary mr-1">@{{prescription.clinical_detail_json.memo ?? '-'}}</span>
+                            </div>
+                        </div>
+                        <div v-else>-</div>
+                    </div>
+                </td>
+                <td class="px-2">
+                    <div class="d-flex align-items-baseline">
+                        {{--
+                        <a v-if="!prescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editHcpPro(prescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                        <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
+                        --}}
+                        <div>@{{prescription.hcpProDisplayName}}</div>
+                    </div>
+                </td>
+                <td class="px-2">
+                    <div v-if="prescription.has_hcp_pro_signed" class="d-flex align-items-baseline">
+                        <i class="text-secondary fa fa-check mr-1"></i>
+                        <span class="text-secondary">Signed</span>
+                    </div>
+                    {{--
+                    <div v-else>
+                        <a v-if="prescription.hcp_pro_id === {{$pro->id}}"
+                           href="#"
+                           v-on:click.prevent="signAsHcpPro(prescription)">Sign</a>
+                        <span v-else>-</span>
+                    </div>
+                    --}}
+                </td>
+            </tr>
+            </tbody>
+        </table>
+        <div v-if="currentPrescription" class="min-width-500px ml-2 border align-self-stretch p-3">
+            <div class="d-flex align-items-center">
+                <h3 class="font-size-16 m-0">
+                    <div v-if="currentPrescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'DRUG'">
+                            <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.medication ?? '-'}}</b>
+                            <!--<span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.strength ?? '-'}}</span>
+                            <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.amount ?? '-'}}</span>
+                            <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.route ?? '-'}}</span>-->
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'LAB' || currentPrescription.erx_category === 'IMAGING'">
+                            <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.test ?? '-'}}</b>
+                            <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.icds ?? '-'}}</span>
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'REFERRAL'">
+                            <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.to ?? '-'}}</b>
+                            <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'SUPPLY'">
+                            <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.item ?? '-'}}</b>
+                            <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.quantity ?? '-'}}</span>
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'OTHER'">
+                            <b class="mr-2 font-size-16">@{{currentPrescription.clinical_detail_json.title ?? '-'}}</b>
+                            <span class="text-secondary mr-1 font-size-16">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
+                        </div>
+                    </div>
+                    <div v-else>-</div>
+                </h3>
+                <a class="ml-auto" href="#" v-on:click.prevent="currentPrescription=null">
+                    <i class="fa fa-times-circle on-hover-opaque"></i>
+                </a>
+            </div>
+            <hr class="my-3">
+            <div class="pb-2 d-flex align-items-start">
+                <span class="min-width-140px text-secondary text-sm">Created</span>
+                <div>
+                    <span>@{{currentPrescription.created_at_friendly}}</span>
+                    @if(@$note)
+                        <div v-if="currentPrescription.note_id === {{$note->id}}" class="text-info mt-1 font-weight-bold">* Create on this note</div>
+                    @endif
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">Type</span>
+                <span>@{{currentPrescription.erx_category}}</span>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">Clinical</span>
+                <div class="d-inline-flex align-items-baseline flex-grow-1">
+                    <a v-if="!currentPrescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editClinicalDetails(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                    <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
+                    <div v-if="currentPrescription.clinical_detail_json" class="d-inline-flex align-items-baseline">
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'DRUG'">
+                            <b class="mr-2">@{{currentPrescription.clinical_detail_json.medication ?? '-'}}</b>
+                            <!--<span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.strength ?? '-'}}</span>
+                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.dispense ?? '-'}}</span>
+                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.refills ?? '-'}}</span>-->
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'LAB' || currentPrescription.erx_category === 'IMAGING'">
+                            <b class="mr-2">@{{currentPrescription.clinical_detail_json.test ?? '-'}}</b>
+                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.icds ?? '-'}}</span>
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'REFERRAL'">
+                            <b class="mr-2">@{{currentPrescription.clinical_detail_json.to ?? '-'}}</b>
+                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'SUPPLY'">
+                            <b class="mr-2">@{{currentPrescription.clinical_detail_json.item ?? '-'}}</b>
+                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.quantity ?? '-'}}</span>
+                        </div>
+                        <div class="d-flex align-items-baseline" v-if="currentPrescription.erx_category === 'OTHER'">
+                            <b class="mr-2">@{{currentPrescription.clinical_detail_json.title ?? '-'}}</b>
+                            <span class="text-secondary mr-1">@{{currentPrescription.clinical_detail_json.memo ?? '-'}}</span>
+                        </div>
+                    </div>
+                    <div v-else>-</div>
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">Logistics</span>
+                <div class="d-inline-flex align-items-baseline flex-grow-1">
+                    <a class="mr-2" href="#" v-on:click.prevent="editLogisticsDetails(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                    <div v-if="currentPrescription.logistics_detail_json" class="d-flex align-items-baseline">
+                        <div class="d-flex align-items-baseline">
+                            <b class="mr-2">@{{currentPrescription.logistics_detail_json.facilityName ?? '-'}}</b>
+                            <span class="text-secondary mr-1">@{{currentPrescription.logistics_detail_json.facilityCity ?? '-'}}</span>
+                            <span class="text-secondary mr-1">@{{currentPrescription.logistics_detail_json.facilityState ?? '-'}}</span>
+                        </div>
+                    </div>
+                    <div v-else>-</div>
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">HCP Pro</span>
+                <div class="d-inline-flex align-items-baseline flex-grow-1">
+                    <a v-if="!currentPrescription.has_hcp_pro_signed" class="mr-2" href="#" v-on:click.prevent="editHcpPro(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                    <span v-else class="mr-2" title="Cannot edit. Prescription already signed."><i class="fa fa-edit on-hover-opaque text-secondary"></i></span>
+                    <div>@{{currentPrescription.hcpProDisplayName}}</div>
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">Sign</span>
+                <div v-if="currentPrescription.has_hcp_pro_signed" class="d-inline-flex align-items-baseline">
+                    <i class="text-secondary fa fa-check mr-1"></i>
+                    <span class="text-secondary">Signed</span>
+                </div>
+                <div v-else>
+                    <a v-if="currentPrescription.hcp_pro_id === {{$pro->id}}"
+                       href="#"
+                       v-on:click.prevent="signAsHcpPro(currentPrescription)">Sign</a>
+                    <span v-else>-</span>
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">Pro Status</span>
+                <div class="d-inline-flex align-items-baseline">
+                    <a class="mr-2" href="#" v-on:click.prevent="editProStatus(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                    <div v-if="currentPrescription.pro_declared_status" class="d-flex align-items-baseline">
+                        @{{ sanitizeStatus(currentPrescription.pro_declared_status) }}
+                    </div>
+                    <div v-else>-</div>
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">Client Status</span>
+                <div class="d-inline-flex align-items-baseline">
+                    <a class="mr-2" href="#" v-on:click.prevent="editClientStatus(currentPrescription)"><i class="fa fa-edit on-hover-opaque"></i></a>
+                    <div v-if="currentPrescription.client_declared_status" class="d-flex align-items-baseline">
+                        @{{ sanitizeStatus(currentPrescription.client_declared_status) }}
+                    </div>
+                    <div v-else>-</div>
+                </div>
+            </div>
+            <div class="pb-2 d-flex align-items-center">
+                <span class="min-width-140px text-secondary text-sm">PDF</span>
+                <div class="d-inline-flex align-items-baseline">
+                    <a class="pdf-viewer-trigger" native target="_blank"
+                       :href="'/prescription-download-as-pdf/' + currentPrescription.uid">View</a>
+                    <span class="mx-2 text-secondary">|</span>
+                    <a native target="_blank"
+                       :href="'/prescription-download-as-pdf/' + currentPrescription.uid">Download</a>
+                    <span class="mx-2 text-secondary">|</span>
+                    <a href="#" v-on:click.prevent="transmit(currentPrescription)">Transmit</a>
+                </div>
+            </div>
+        </div>
+    </div>
+    @include('app.patient.prescriptions.drug-form')
+    @include('app.patient.prescriptions.lab-form')
+    @include('app.patient.prescriptions.imaging-form')
+    @include('app.patient.prescriptions.referral-form')
+    @include('app.patient.prescriptions.supply-form')
+    @include('app.patient.prescriptions.other-form')
+    @include('app.patient.prescriptions.logistics-form')
+    @include('app.patient.prescriptions.hcp-pro-form')
+    @include('app.patient.prescriptions.sign-as-hcp-form')
+    @include('app.patient.prescriptions.pro-status-form')
+    @include('app.patient.prescriptions.client-status-form')
+    @include('app.patient.prescriptions.transmit-form')
+</div>
+<script>
+    (function() {
+
+        <?php
+        $prescriptions = $patient->prescriptions;
+        $currentPrescription = null;
+        foreach ($prescriptions as $prescription) {
+            if($prescription->clinical_detail_json) {
+                $prescription->clinical_detail_json = json_decode($prescription->clinical_detail_json);
+            }
+            if($prescription->logistics_detail_json) {
+                $prescription->logistics_detail_json = json_decode($prescription->logistics_detail_json);
+            }
+            $prescription->created_at_friendly = friendlier_date_time($prescription->created_at);
+            $prescription->created_at_friendly_short = friendlier_date_time($prescription->created_at, false);
+            $prescription->hcpProDisplayName = $prescription->hcpPro ? $prescription->hcpPro->displayName() : '-';
+            $prescription->hcpProUid = $prescription->hcpPro ? $prescription->hcpPro->uid : '';
+
+            if(!!@$currentErx && $currentErx->uid === $prescription->uid) {
+                $currentPrescription = $prescription;
+            }
+        }
+        ?>
+
+        function init() {
+
+            new Vue({
+                el: '#prescriptions-{{$patient->id}}',
+                delimiters: ['@{{', '}}'],
+                data: {
+
+                    prescriptions: <?= json_encode($prescriptions) ?>,
+
+                    currentPrescriptionAction: '',
+                    currentPrescriptionType: '',
+
+                    // selected
+                    currentPrescription:  <?= $currentPrescription ? json_encode($currentPrescription) : 'null' ?>,
+
+                    // for editing clinical details
+                    currentPrescription_DRUG: {
+                        noteUid: '{{ @$note ? $note->uid : '' }}',
+                        clientUid: '{{ $patient->uid }}',
+                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                        hcpProUid: '{{$pro->uid}}',
+                        erxCategory: 'DRUG',
+                        clinicalDetailJson: {
+                            medication: '',
+                            route: '',
+                            dose: '',
+                            strength: '',
+                            frequency: '',
+                            dispense: '',
+                            refills: '',
+                            purpose: '',
+
+                            // fdb specific
+                            medNameID: '',
+                            routedMedID: '',
+                            dosageFormMedID: '',
+                            gcnSeqno: '',
+                            medId: '',
+                        }
+                    },
+                    currentPrescription_LAB: {
+                        noteUid: '{{ @$note ? $note->uid : '' }}',
+                        clientUid: '{{ $patient->uid }}',
+                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                        hcpProUid: '{{$pro->uid}}',
+                        erxCategory: 'LAB',
+                        clinicalDetailJson: {
+                            test: '',
+                            icds: '',
+                            memo: '',
+                        }
+                    },
+                    currentPrescription_IMAGING: {
+                        noteUid: '{{ @$note ? $note->uid : '' }}',
+                        clientUid: '{{ $patient->uid }}',
+                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                        hcpProUid: '{{$pro->uid}}',
+                        erxCategory: 'IMAGING',
+                        clinicalDetailJson: {
+                            test: '',
+                            icds: '',
+                            memo: '',
+                        }
+                    },
+                    currentPrescription_REFERRAL: {
+                        noteUid: '{{ @$note ? $note->uid : '' }}',
+                        clientUid: '{{ $patient->uid }}',
+                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                        hcpProUid: '{{$pro->uid}}',
+                        erxCategory: 'REFERRAL',
+                        clinicalDetailJson: {
+                            to: '',
+                            memo: '',
+                        }
+                    },
+                    currentPrescription_SUPPLY: {
+                        noteUid: '{{ @$note ? $note->uid : '' }}',
+                        clientUid: '{{ $patient->uid }}',
+                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                        hcpProUid: '{{$pro->uid}}',
+                        erxCategory: 'SUPPLY',
+                        clinicalDetailJson: {
+                            item: '',
+                            quantity: '',
+                            memo: '',
+                        }
+                    },
+                    currentPrescription_OTHER: {
+                        noteUid: '{{ @$note ? $note->uid : '' }}',
+                        clientUid: '{{ $patient->uid }}',
+                        replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                        hcpProUid: '{{$pro->uid}}',
+                        erxCategory: 'OTHER',
+                        clinicalDetailJson: {
+                            title: '',
+                            memo: '',
+                        }
+                    },
+
+                    // for editing logistics - common
+                    currentPrescriptionLogistics: {
+                        uid: '',
+                        logisticsDetailJson: {
+                            facilityName: '',
+                            facilityCity: '',
+                            facilityState: '',
+                            facilityAddressMemo: '',
+                            facilityPhone: '',
+                            facilityFax: '',
+                            facilityZip: '',
+                        }
+                    },
+
+                    // for editing hcp, sign, pro status & client status - common
+                    currentPrescriptionHcpPro: {
+                        uid: '',
+                        newHcpProUid: '',
+                    },
+                    currentPrescriptionSign: {
+                        uid: '',
+                        declaredVersionNumber: '',
+                    },
+                    currentPrescriptionProStatus: {
+                        uid: '',
+                        status: '',
+                        memo: '',
+                    },
+                    currentPrescriptionClientStatus: {
+                        uid: '',
+                        status: '',
+                        memo: '',
+                    },
+                    currentPrescriptionTransmit: {
+                        uid: '',
+                        logistics: '',
+                        toWho: '',
+                        toEmail: '',
+                        toFaxNumber: '',
+                        toFaxNumberAttentionLine: '',
+                        toFaxNumberCoverSheetMemo: '',
+                        copyToPatient: false,
+                        copyToPatientFaxNumber: '',
+                        copyToPatientEmail: '',
+                    }
+                },
+                methods: {
+
+                    // new/edit/save-clinical
+                    newPrescription: function(_type) {
+                        this.currentPrescriptionAction = 'ADD';
+                        this.currentPrescriptionType = _type;
+                        switch (_type) {
+                            case 'DRUG':
+                                this.currentPrescription_DRUG = {
+                                    noteUid: '{{ @$note ? $note->uid : '' }}',
+                                    clientUid: '{{ $patient->uid }}',
+                                    replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                                    hcpProUid: '{{$pro->uid}}',
+                                    erxCategory: _type,
+                                    clinicalDetailJson: {
+                                        medication: '',
+                                        route: '',
+                                        dose: '',
+                                        strength: '',
+                                        frequency: '',
+                                        dispense: '',
+                                        refills: '',
+                                        purpose: '',
+
+                                        // fdb specific
+                                        medNameID: '',
+                                        routedMedID: '',
+                                        dosageFormMedID: '',
+                                        gcnSeqno: '',
+                                        medId: '',
+                                    }
+                                };
+                                break;
+                            case 'LAB':
+                            case 'IMAGING':
+                                this.currentPrescription_LAB = {
+                                    noteUid: '{{ @$note ? $note->uid : '' }}',
+                                    clientUid: '{{ $patient->uid }}',
+                                    replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                                    hcpProUid: '{{$pro->uid}}',
+                                    erxCategory: _type,
+                                    clinicalDetailJson: {
+                                        test: '',
+                                        icds: '',
+                                        memo: '',
+                                    }
+                                };
+                                break;
+                            case 'REFERRAL':
+                                this.currentPrescription_LAB = {
+                                    noteUid: '{{ @$note ? $note->uid : '' }}',
+                                    clientUid: '{{ $patient->uid }}',
+                                    replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                                    hcpProUid: '{{$pro->uid}}',
+                                    erxCategory: _type,
+                                    clinicalDetailJson: {
+                                        to: '',
+                                        memo: '',
+                                    }
+                                };
+                                break;
+                            case 'SUPPLY':
+                                this.currentPrescription_LAB = {
+                                    noteUid: '{{ @$note ? $note->uid : '' }}',
+                                    clientUid: '{{ $patient->uid }}',
+                                    replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                                    hcpProUid: '{{$pro->uid}}',
+                                    erxCategory: _type,
+                                    clinicalDetailJson: {
+                                        item: '',
+                                        quantity: '',
+                                        memo: '',
+                                    }
+                                };
+                                break;
+                            case 'OTHER':
+                                this.currentPrescription_LAB = {
+                                    noteUid: '{{ @$note ? $note->uid : '' }}',
+                                    clientUid: '{{ $patient->uid }}',
+                                    replacesCancelledErxUid: null, // TODO: step-2 support UI to mark a new one as replacing a cancelled one
+                                    hcpProUid: '{{$pro->uid}}',
+                                    erxCategory: _type,
+                                    clinicalDetailJson: {
+                                        title: '',
+                                        memo: '',
+                                    }
+                                };
+                                break;
+                        }
+                        Vue.nextTick(() => {
+                            showStagPopup('prescription-popup-' + this.currentPrescriptionType, true);
+                            if(_type === 'DRUG') {
+                                $('[stag-suggest][stag-suggest-initialized]').removeAttr('stag-suggest-initialized');
+                                initStagSuggest();
+                                this.initFdbMedSuggest();
+                            }
+                        });
+                    },
+                    editClinicalDetails: function(_prescription) {
+                        this.currentPrescriptionAction = 'EDIT_CLINICAL';
+                        this.currentPrescriptionType = _prescription.erx_category;
+                        this['currentPrescription_' + this.currentPrescriptionType] = {
+                            uid: _prescription.uid,
+                            clinicalDetailJson: JSON.parse(JSON.stringify(_prescription.clinical_detail_json))
+                        };
+                        Vue.nextTick(() => {
+                            showStagPopup('prescription-popup-' + this.currentPrescriptionType, true);
+                            if(this.currentPrescriptionType === 'DRUG') {
+                                $('[stag-suggest][stag-suggest-initialized]').removeAttr('stag-suggest-initialized');
+                                initStagSuggest();
+                                this.initFdbMedSuggest();
+
+                                // re-populate drug fields
+                                console.log(this.currentPrescription_DRUG);
+                                let parentSegment = $('#prescriptions-{{$patient->id}} [stag-popup-key="prescription-popup-DRUG"]>form').first();
+                                parentSegment.find('input.prescription-medication').val(this.currentPrescription_DRUG.clinicalDetailJson.medication);
+                                parentSegment.find('select.prescription-route')
+                                    .empty()
+                                    .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.route))
+                                    .val(1);
+                                parentSegment.find('select.prescription-dose')
+                                    .empty()
+                                    .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.dose))
+                                    .val(1);
+                                parentSegment.find('select.prescription-strength')
+                                    .empty()
+                                    .append($('<option/>').attr('value', 1).text(this.currentPrescription_DRUG.clinicalDetailJson.strength))
+                                    .val(1);
+                            }
+                        });
+                    },
+                    savePrescription: function() {
+                        let payload = JSON.parse(JSON.stringify(this['currentPrescription_' + this.currentPrescriptionType]));
+                        payload.clinicalDetailJson = JSON.stringify(payload.clinicalDetailJson);
+                        switch (this.currentPrescriptionAction) {
+                            case 'ADD':
+                                $.post('/api/erx/create', payload, _data => {
+                                    if(!hasResponseError(_data)) {
+                                        toastr.success('Prescription added');
+                                        closeStagPopup();
+                                        @if(@$note)
+                                        fastReload();
+                                        @else
+                                        fastLoad('/patients/view/{{$patient->uid}}/prescriptions/' + this.currentPrescriptionType.toLowerCase() + '/' + _data.data);
+                                        @endif
+                                    }
+                                }, 'json');
+                                break;
+                            case 'EDIT_CLINICAL':
+                                $.post('/api/erx/updateClinicalDetail', payload, _data => {
+                                    if(!hasResponseError(_data)) {
+                                        toastr.success('Prescription updated');
+                                        closeStagPopup();
+                                        fastReload();
+                                    }
+                                }, 'json');
+                                break;
+                        }
+                    },
+
+                    // edit logistics
+                    editLogisticsDetails: function(_prescription) {
+                        this.currentPrescriptionAction = 'EDIT_LOGISTICS';
+                        this.currentPrescriptionLogistics = {
+                            uid: _prescription.uid,
+                            logisticsDetailJson: _prescription.logistics_detail_json ? JSON.parse(JSON.stringify(_prescription.logistics_detail_json)) : {
+                                facilityName: '',
+                                facilityCity: '',
+                                facilityState: '',
+                                facilityAddressMemo: '',
+                                facilityPhone: '',
+                                facilityFax: '',
+                                facilityZip: '',
+                            }
+                        }
+                        Vue.nextTick(() => {
+                            showStagPopup('logistics-popup', true);
+                        });
+                    },
+                    saveLogistics: function() {
+                        let payload = JSON.parse(JSON.stringify(this.currentPrescriptionLogistics));
+                        payload.logisticsDetailJson = JSON.stringify(payload.logisticsDetailJson);
+                        $.post('/api/erx/updateLogisticsDetail', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Logistics updated');
+                                closeStagPopup();
+                                fastReload();
+                            }
+                        }, 'json');
+                    },
+
+                    // edit hcp (ordering) pro
+                    editHcpPro: function(_prescription) {
+                        this.currentPrescriptionAction = 'EDIT_HCP_PRO';
+                        this.currentPrescriptionType = _prescription.erx_category;
+                        this.currentPrescriptionHcpPro = {
+                            uid: _prescription.uid,
+                            newHcpProUid: _prescription.hcpProUid
+                        };
+                        Vue.nextTick(() => {
+                            showStagPopup('hcp-pro-popup', true);
+                            $('.erx-hcp-pro-select').removeAttr('pro-suggest-initialized');
+                            initProSuggest();
+                        });
+                    },
+                    saveHcpPro: function() {
+                        let payload = JSON.parse(JSON.stringify(this.currentPrescriptionHcpPro));
+                        $.post('/api/erx/updateHcpPro', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('HCP Pro updated');
+                                closeStagPopup();
+                                fastReload();
+                            }
+                        }, 'json');
+                    },
+
+                    // sign
+                    signAsHcpPro: function(_prescription) {
+                        this.currentPrescriptionAction = 'SIGN_AS_HCP';
+                        this.currentPrescriptionType = _prescription.erx_category;
+                        this.currentPrescriptionSign = {
+                            uid: _prescription.uid,
+                            declaredVersionNumber: _prescription.version_number
+                        };
+                        Vue.nextTick(() => {
+                            showStagPopup('sign-as-hcp-popup', true);
+                        });
+                    },
+                    saveSignAsHcpPro: function() {
+                        let payload = JSON.parse(JSON.stringify(this.currentPrescriptionSign));
+                        $.post('/api/erx/signAsHcp', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Signed');
+                                closeStagPopup();
+                                fastReload();
+                            }
+                        }, 'json');
+                    },
+
+                    // edit pro status
+                    editProStatus: function(_prescription) {
+                        this.currentPrescriptionAction = 'EDIT_PRO_DECLARED_STATUS';
+                        this.currentPrescriptionType = _prescription.erx_category;
+                        this.currentPrescriptionProStatus = {
+                            uid: _prescription.uid,
+                            status: _prescription.pro_declared_status,
+                            memo: _prescription.pro_declared_status_memo,
+                        };
+                        Vue.nextTick(() => {
+                            showStagPopup('pro-status-popup', true);
+                        });
+                    },
+                    saveProStatus: function() {
+                        let payload = JSON.parse(JSON.stringify(this.currentPrescriptionProStatus));
+                        $.post('/api/erx/updateProDeclaredStatus', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Pro declared status updated');
+                                closeStagPopup();
+                                fastReload();
+                            }
+                        }, 'json');
+                    },
+
+                    // edit client status
+                    editClientStatus: function(_prescription) {
+                        this.currentPrescriptionAction = 'EDIT_CLIENT_DECLARED_STATUS';
+                        this.currentPrescriptionType = _prescription.erx_category;
+                        this.currentPrescriptionClientStatus = {
+                            uid: _prescription.uid,
+                            status: _prescription.client_declared_status,
+                            memo: _prescription.client_declared_status_memo,
+                        };
+                        Vue.nextTick(() => {
+                            showStagPopup('client-status-popup', true);
+                        });
+                    },
+                    saveClientStatus: function() {
+                        let payload = JSON.parse(JSON.stringify(this.currentPrescriptionClientStatus));
+                        $.post('/api/erx/updateClientDeclaredStatus', payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Client declared status updated');
+                                closeStagPopup();
+                                fastReload();
+                            }
+                        }, 'json');
+                    },
+
+                    // sane display status
+                    sanitizeStatus: function(_s) {
+                        _s = _s.toLowerCase().replaceAll('_', ' ');
+                        _s = _s[0].toUpperCase() + _s.substr(1);
+                        return _s;
+                    },
+
+                    // transmit
+                    transmit: function(_prescription) {
+                        this.currentPrescriptionTransmit = {
+                            uid: _prescription.uid,
+                            toWho: _prescription.logistics_detail_json ? _prescription.logistics_detail_json.facilityName : '',
+                            toEmail: '',
+                            toFaxNumber: _prescription.logistics_detail_json ? _prescription.logistics_detail_json.facilityFax : '',
+                            toFaxNumberAttentionLine: '',
+                            toFaxNumberCoverSheetMemo: '',
+                            copyToPatient: false,
+                            copyToPatientFaxNumber: '{{$patient->cell_number}}',
+                            copyToPatientEmail: '{{$patient->email_address}}',
+                            _token: '{{csrf_token()}}'
+                        };
+                        Vue.nextTick(() => {
+                            showStagPopup('transmit-popup');
+                            this.transmitModalPDFPreview();
+                        });
+                    },
+                    transmitModalPDFPreview: function() {
+
+                        let _loadedPDF = null, _numPages = 1, _page = 1;
+
+                        function _load(_url) {
+
+                            _loadedPDF = null;
+                            _numPages = 1;
+                            _page = 1;
+
+                            $('#transmit-pdf-preview>canvas').remove();
+
+                            let url = _url;
+                            let pdfjsLib = window['pdfjs-dist/build/pdf'];
+                            pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
+                            let loadingTask = pdfjsLib.getDocument(url);
+                            loadingTask.promise.then(function (pdf) {
+                                _numPages = pdf.numPages;
+                                _loadedPDF = pdf;
+                                _page = 1;
+                                _render();
+                            }, function (reason) {
+                                // reason.message;
+                            });
+                        }
+                        function _render() {
+
+                            _loadedPDF.getPage(_page).then(function (page) {
+
+                                // create canvas
+                                let canvasElement = $('<canvas/>')
+                                    .addClass('pdf-viewer-page pdf-preview-page')
+                                    .appendTo('#transmit-pdf-preview');
+
+                                let canvas = canvasElement[0];
+                                let viewport = page.getViewport({scale: 0.75});
+                                let context = canvas.getContext('2d');
+                                canvas.height = viewport.height;
+                                canvas.width = viewport.width;
+                                const $canvas = $(canvas);
+                                let renderContext = {
+                                    canvasContext: context,
+                                    viewport: viewport
+                                };
+                                let renderTask = page.render(renderContext);
+                                renderTask.promise.then(function () {
+                                    if(_page < _numPages) {
+                                        _page++;
+                                        _render();
+                                    }
+                                });
+                            });
+                        }
+
+                        _load('/prescription-download-as-pdf/' + this.currentPrescriptionTransmit.uid);
+                    },
+                    doTransmit: function (_item) {
+                        let payload = JSON.parse(JSON.stringify(this.currentPrescriptionTransmit));
+                        $.post('/prescription-transmit/' + payload.uid, payload, _data => {
+                            if(!hasResponseError(_data)) {
+                                toastr.success('Transmission initiated');
+                                closeStagPopup();
+                                fastReload();
+                            }
+                        }, 'json');
+                        closeStagPopup();
+                    },
+
+                    // cancel, etc.
+
+                    initFdbMedSuggest: function() {
+
+                        let self = this;
+
+                        let parentSegment = $('#prescriptions-{{$patient->id}} [stag-popup-key="prescription-popup-DRUG"]>form').first();
+
+                        parentSegment.find('input.prescription-medication').off('stag-suggest-selected');
+                        parentSegment.find('input.prescription-medication').on('stag-suggest-selected', (_e, _input, _data) => {
+
+                            // _input is the textbox
+                            // _data is {med_name_id: "50567", text: "Children's Tylenol"}
+
+                            // set vue values
+                            self.currentPrescription_DRUG.clinicalDetailJson.medication = _data.text;
+
+                        });
+                    }
+                },
+                mounted: function() {
+                    let self = this;
+                    $(document).on('pro-changed', '.erx-hcp-pro-select', function() {
+                        self.currentPrescriptionHcpPro.newHcpProUid = this.value;
+                    });
+                }
+            });
+
+        }
+        addMCInitializer('prescriptions-{{$patient->id}}', init, '#prescriptions-{{$patient->id}}')
+    }).call(window);
+</script>

+ 1 - 0
routes/web.php

@@ -294,6 +294,7 @@ Route::middleware('pro.auth')->group(function () {
 
             // prescriptions (new)
             Route::get('prescriptions/{type?}/{currentErx?}', 'PatientController@prescriptions')->name('patient-prescriptions');
+            Route::get('prescriptions-list/{type?}/{currentErx?}', 'PatientController@prescriptionsList')->name('patient-prescriptions-list');
 
             // appointments
             Route::get('appointments/{forPro}/{status}', 'PatientController@appointments')->name('appointments');