@extends ('layouts.patient')
@section('inner-content')
    <div>
        <div class="d-flex align-items-center pb-2">
            <h4 class="font-weight-bold m-0">Documents</h4>
            <span class="mx-2 text-secondary">|</span>
            <div moe>
                <a start show class="">Upload</a>
                <form url="dummy" action="/api/clientDocument/create"
                      method="post"
                      onsubmit="return submitDocument(this)"
                      enctype="multipart/form-data">
                    <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">Title *</label>
                        <input type="text" class="form-control form-control-sm" name="title"
                               value="" placeholder="Title" required>
                    </div>
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">File *</label>
                        <input type="file" class="form-control form-control-sm" name="file"
                               value="" placeholder="File" required>
                    </div>
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">Category *</label>
                        <select required name="category" class="form-control form-control-sm">
                            <option value="">-- select --</option>
                            <option value="Advanced Directive">Advanced Directive</option>
                            <option value="Advanced Directive Waiver">Advanced Directive Waiver</option>
                            <option value="Authorization">Authorization</option>
                            <option value="Cardiopulmonary Diagnosis">Cardiopulmonary Diagnosis</option>
                            <option value="Clinical Summary">Clinical Summary</option>
                            <option value="Consent for Treatment">Consent for Treatment</option>
                            <option value="Consultation">Consultation</option>
                            <option value="Continuity of Care Received">Continuity of Care Received</option>
                            <option value="Copay Log">Copay Log</option>
                            <option value="CT Report">CT Report</option>
                            <option value="Death Certificate">Death Certificate</option>
                            <option value="Demographics">Demographics</option>
                            <option value="Diagnostic Ultrasound">Diagnostic Ultrasound</option>
                            <option value="Disability Info">Disability Info</option>
                            <option value="Discharge Summary">Discharge Summary</option>
                            <option value="Dismissals">Dismissals</option>
                            <option value="Document Batch">Document Batch</option>
                            <option value="Drivers License">Drivers License</option>
                            <option value="ECHO">ECHO</option>
                            <option value="EEG-EMG">EEG-EMG</option>
                            <option value="EKG">EKG</option>
                            <option value="Eligibility">Eligibility</option>
                            <option value="Emergency Department">Emergency Department</option>
                            <option value="Explanation of Benefits">Explanation of Benefits</option>
                            <option value="External Record Summary">External Record Summary</option>
                            <option value="History and Physical">History and Physical</option>
                            <option value="Holter Monitor">Holter Monitor</option>
                            <option value="Hospital History">Hospital History</option>
                            <option value="Immunization History">Immunization History</option>
                            <option value="Insurance Card">Insurance Card</option>
                            <option value="Insurance Correspondence">Insurance Correspondence</option>
                            <option value="Insurance Referral">Insurance Referral</option>
                            <option value="Legal Document">Legal Document</option>
                            <option value="Letter of Medical Necessity">Letter of Medical Necessity</option>
                            <option value="Lien Document">Lien Document</option>
                            <option value="Mammography Document">Mammography Document</option>
                            <option value="Medical Record Request">Medical Record Request</option>
                            <option value="Medical Report">Medical Report</option>
                            <option value="Misc. Form">Misc. Form</option>
                            <option value="Misc. Hospital Document">Misc. Hospital Document</option>
                            <option value="Misc. Lab Result">Misc. Lab Result</option>
                            <option value="Missed Appointment">Missed Appointment</option>
                            <option value="MRI-MRA Document">MRI-MRA Document</option>
                            <option value="Narrative Report">Narrative Report</option>
                            <option value="Neurosensory Test">Neurosensory Test</option>
                            <option value="Nursing Home Visit/Home Care">Nursing Home Visit/Home Care</option>
                            <option value="OB Documentation">OB Documentation</option>
                            <option value="OB Non-Stress Test">OB Non-Stress Test</option>
                            <option value="Office Consult Note">Office Consult Note</option>
                            <option value="Office History and Physical">Office History and Physical</option>
                            <option value="Office Procedure Report">Office Procedure Report</option>
                            <option value="Operative Report">Operative Report</option>
                            <option value="Order">Order</option>
                            <option value="Other">Other</option>
                            <option value="Other Office Letter">Other Office Letter</option>
                            <option value="Other Office Note">Other Office Note</option>
                            <option value="Pathology Report">Pathology Report</option>
                            <option value="Patient Authorization/Referral">Patient Authorization/Referral</option>
                            <option value="Patient Correspondence">Patient Correspondence</option>
                            <option value="Patient Demographics">Patient Demographics</option>
                            <option value="Patient Driver's License">Patient Driver's License</option>
                            <option value="Patient Insurance Card">Patient Insurance Card</option>
                            <option value="Patient Letter">Patient Letter</option>
                            <option value="Payment Batch">Payment Batch</option>
                            <option value="Phone Call/Message">Phone Call/Message</option>
                            <option value="Physician Established Patient Note">Physician Established Patient Note</option>
                            <option value="Physician New Patient Note">Physician New Patient Note</option>
                            <option value="Prescriptions">Prescriptions</option>
                            <option value="Radiology Diagnostic">Radiology Diagnostic</option>
                            <option value="Radiology/Oncology">Radiology/Oncology</option>
                            <option value="Referral Letter">Referral Letter</option>
                            <option value="Referral Received">Referral Received</option>
                            <option value="Release of Information">Release of Information</option>
                            <option value="Request for Amendment">Request for Amendment</option>
                            <option value="Summary of Care Received">Summary of Care Received</option>
                            <option value="Summary of Care Sent">Summary of Care Sent</option>
                            <option value="Superbill">Superbill</option>
                            <option value="Superbill Batch">Superbill Batch</option>
                            <option value="Surgery/Procedure Report">Surgery/Procedure Report</option>
                            <option value="Tests">Tests</option>
                            <option value="Therapy Note">Therapy Note</option>
                            <option value="Treadmill Report">Treadmill Report</option>
                            <option value="Ultrasound">Ultrasound</option>
                            <option value="Ultrasound Document">Ultrasound Document</option>
                            <option value="Urgent Care Visit Note">Urgent Care Visit Note</option>
                        </select>
                    </div>
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">Status</label>
                        <select name="status" class="form-control form-control-sm">
                            <option value="">-- select --</option>
                            <option value="New">New</option>
                            <option value="In-Process">In-Process</option>
                            <option value="Processed">Processed</option>
                        </select>
                    </div>
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">Effective Date</label>
                        <input type="date" class="form-control form-control-sm"
                               name="effectiveDate" value="{{ date('Y-m-d') }}" max="{{ date('Y-m-d') }}">
                    </div>
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">Provider</label>
                        <select name="provider" provider-search class="form-control form-control-sm">
                            <option value=""> --select-- </option>
                            @foreach($pros as $iPro)
                                <option value="{{$iPro->uid}}">{{$iPro->displayName()}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="mb-2">
                        <label for="" class="text-sm text-secondary mb-1">Notes</label>
                        <textarea type="text" class="form-control form-control-sm" name="notes"></textarea>
                    </div>
                    <div class="d-flex align-items-center">
                        <button class="btn btn-sm btn-primary mr-2" type="submit">Send</button>
                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                    </div>
                </form>
            </div>
        </div>
        <table class="table table-striped table-sm table-bordered mb-0">
            <thead>
            <tr>
                <th class="px-2 text-secondary">Created</th>
                <th class="px-2 text-secondary">Title</th>
                <th class="px-2 text-secondary">Category</th>
                <th class="px-2 text-secondary">Status</th>
                <th class="px-2"></th>
            </tr>
            </thead>
            <tbody>
            @foreach($patient->documents as $document)
                @if(!$document->is_removed)
                <tr>
                    <td class="px-2">{{ friendly_date_time($document->created_at) }}</td>
                    <td class="px-2">{{ $document->title }}</td>
                    <td class="px-2">{{ $document->category }}</td>
                    <td class="px-2">{{ $document->status }}</td>
                    <td class="px-2">
                        <a class="on-hover-opaque mr-2 pdf-viewer-trigger" native target="_blank"
                           href="/api/clientDocument/download/{{ $document->uid }}"
                           title="View">
                            <i class="font-size-11 fa fa-eye"></i>
                        </a>
                        <a class="on-hover-opaque mr-2" native target="_blank"
                           href="/api/clientDocument/download/{{ $document->uid }}"
                           title="Download">
                            <i class="font-size-11 fa fa-download"></i>
                        </a>
                        <span moe relative class="mr-2">
                            <a href="#" start show class="on-hover-opaque"><i class="fa fa-edit text-primary"></i></a>
                            <form url="/api/clientDocument/updateBasic" right>
                                <input type="hidden" name="uid" value="{{ $document->uid }}">
                                <div class="mb-2">
                                    <label for="" class="text-sm text-secondary mb-1">Title *</label>
                                    <input type="text" class="form-control form-control-sm" name="title"
                                           value="{{ $document->title }}" placeholder="Title" required>
                                </div>
                                <div class="mb-2">
                                    <label for="" class="text-sm text-secondary mb-1">Category *</label>
                                    <select required name="category" class="form-control form-control-sm">
                                        <option value="">-- select --</option>
                                        <option {{ $document->category === 'Advanced Directive' ? 'selected' : '' }} value="Advanced Directive">Advanced Directive</option>
                                        <option {{ $document->category === 'Advanced Directive Waiver' ? 'selected' : '' }} value="Advanced Directive Waiver">Advanced Directive Waiver</option>
                                        <option {{ $document->category === 'Authorization' ? 'selected' : '' }} value="Authorization">Authorization</option>
                                        <option {{ $document->category === 'Cardiopulmonary Diagnosis' ? 'selected' : '' }} value="Cardiopulmonary Diagnosis">Cardiopulmonary Diagnosis</option>
                                        <option {{ $document->category === 'Clinical Summary' ? 'selected' : '' }} value="Clinical Summary">Clinical Summary</option>
                                        <option {{ $document->category === 'Consent for Treatment' ? 'selected' : '' }} value="Consent for Treatment">Consent for Treatment</option>
                                        <option {{ $document->category === 'Consultation' ? 'selected' : '' }} value="Consultation">Consultation</option>
                                        <option {{ $document->category === 'Continuity of Care Received' ? 'selected' : '' }} value="Continuity of Care Received">Continuity of Care Received</option>
                                        <option {{ $document->category === 'Copay Log' ? 'selected' : '' }} value="Copay Log">Copay Log</option>
                                        <option {{ $document->category === 'CT Report' ? 'selected' : '' }} value="CT Report">CT Report</option>
                                        <option {{ $document->category === 'Death Certificate' ? 'selected' : '' }} value="Death Certificate">Death Certificate</option>
                                        <option {{ $document->category === 'Demographics' ? 'selected' : '' }} value="Demographics">Demographics</option>
                                        <option {{ $document->category === 'Diagnostic Ultrasound' ? 'selected' : '' }} value="Diagnostic Ultrasound">Diagnostic Ultrasound</option>
                                        <option {{ $document->category === 'Disability Info' ? 'selected' : '' }} value="Disability Info">Disability Info</option>
                                        <option {{ $document->category === 'Discharge Summary' ? 'selected' : '' }} value="Discharge Summary">Discharge Summary</option>
                                        <option {{ $document->category === 'Dismissals' ? 'selected' : '' }} value="Dismissals">Dismissals</option>
                                        <option {{ $document->category === 'Document Batch' ? 'selected' : '' }} value="Document Batch">Document Batch</option>
                                        <option {{ $document->category === 'Drivers License' ? 'selected' : '' }} value="Drivers License">Drivers License</option>
                                        <option {{ $document->category === 'ECHO' ? 'selected' : '' }} value="ECHO">ECHO</option>
                                        <option {{ $document->category === 'EEG-EMG' ? 'selected' : '' }} value="EEG-EMG">EEG-EMG</option>
                                        <option {{ $document->category === 'EKG' ? 'selected' : '' }} value="EKG">EKG</option>
                                        <option {{ $document->category === 'Eligibility' ? 'selected' : '' }} value="Eligibility">Eligibility</option>
                                        <option {{ $document->category === 'Emergency Department' ? 'selected' : '' }} value="Emergency Department">Emergency Department</option>
                                        <option {{ $document->category === 'Explanation of Benefits' ? 'selected' : '' }} value="Explanation of Benefits">Explanation of Benefits</option>
                                        <option {{ $document->category === 'External Record Summary' ? 'selected' : '' }} value="External Record Summary">External Record Summary</option>
                                        <option {{ $document->category === 'History and Physical' ? 'selected' : '' }} value="History and Physical">History and Physical</option>
                                        <option {{ $document->category === 'Holter Monitor' ? 'selected' : '' }} value="Holter Monitor">Holter Monitor</option>
                                        <option {{ $document->category === 'Hospital History' ? 'selected' : '' }} value="Hospital History">Hospital History</option>
                                        <option {{ $document->category === 'Immunization History' ? 'selected' : '' }} value="Immunization History">Immunization History</option>
                                        <option {{ $document->category === 'Insurance Card' ? 'selected' : '' }} value="Insurance Card">Insurance Card</option>
                                        <option {{ $document->category === 'Insurance Correspondence' ? 'selected' : '' }} value="Insurance Correspondence">Insurance Correspondence</option>
                                        <option {{ $document->category === 'Insurance Referral' ? 'selected' : '' }} value="Insurance Referral">Insurance Referral</option>
                                        <option {{ $document->category === 'Legal Document' ? 'selected' : '' }} value="Legal Document">Legal Document</option>
                                        <option {{ $document->category === 'Letter of Medical Necessity' ? 'selected' : '' }} value="Letter of Medical Necessity">Letter of Medical Necessity</option>
                                        <option {{ $document->category === 'Lien Document' ? 'selected' : '' }} value="Lien Document">Lien Document</option>
                                        <option {{ $document->category === 'Mammography Document' ? 'selected' : '' }} value="Mammography Document">Mammography Document</option>
                                        <option {{ $document->category === 'Medical Record Request' ? 'selected' : '' }} value="Medical Record Request">Medical Record Request</option>
                                        <option {{ $document->category === 'Medical Report' ? 'selected' : '' }} value="Medical Report">Medical Report</option>
                                        <option {{ $document->category === 'Misc. Form' ? 'selected' : '' }} value="Misc. Form">Misc. Form</option>
                                        <option {{ $document->category === 'Misc. Hospital Document' ? 'selected' : '' }} value="Misc. Hospital Document">Misc. Hospital Document</option>
                                        <option {{ $document->category === 'Misc. Lab Result' ? 'selected' : '' }} value="Misc. Lab Result">Misc. Lab Result</option>
                                        <option {{ $document->category === 'Missed Appointment' ? 'selected' : '' }} value="Missed Appointment">Missed Appointment</option>
                                        <option {{ $document->category === 'MRI-MRA Document' ? 'selected' : '' }} value="MRI-MRA Document">MRI-MRA Document</option>
                                        <option {{ $document->category === 'Narrative Report' ? 'selected' : '' }} value="Narrative Report">Narrative Report</option>
                                        <option {{ $document->category === 'Neurosensory Test' ? 'selected' : '' }} value="Neurosensory Test">Neurosensory Test</option>
                                        <option {{ $document->category === 'Nursing Home Visit/Home Care' ? 'selected' : '' }} value="Nursing Home Visit/Home Care">Nursing Home Visit/Home Care</option>
                                        <option {{ $document->category === 'OB Documentation' ? 'selected' : '' }} value="OB Documentation">OB Documentation</option>
                                        <option {{ $document->category === 'OB Non-Stress Test' ? 'selected' : '' }} value="OB Non-Stress Test">OB Non-Stress Test</option>
                                        <option {{ $document->category === 'Office Consult Note' ? 'selected' : '' }} value="Office Consult Note">Office Consult Note</option>
                                        <option {{ $document->category === 'Office History and Physical' ? 'selected' : '' }} value="Office History and Physical">Office History and Physical</option>
                                        <option {{ $document->category === 'Office Procedure Report' ? 'selected' : '' }} value="Office Procedure Report">Office Procedure Report</option>
                                        <option {{ $document->category === 'Operative Report' ? 'selected' : '' }} value="Operative Report">Operative Report</option>
                                        <option {{ $document->category === 'Order' ? 'selected' : '' }} value="Order">Order</option>
                                        <option {{ $document->category === 'Other' ? 'selected' : '' }} value="Other">Other</option>
                                        <option {{ $document->category === 'Other Office Letter' ? 'selected' : '' }} value="Other Office Letter">Other Office Letter</option>
                                        <option {{ $document->category === 'Other Office Note' ? 'selected' : '' }} value="Other Office Note">Other Office Note</option>
                                        <option {{ $document->category === 'Pathology Report' ? 'selected' : '' }} value="Pathology Report">Pathology Report</option>
                                        <option {{ $document->category === 'Patient Authorization/Referral' ? 'selected' : '' }} value="Patient Authorization/Referral">Patient Authorization/Referral</option>
                                        <option {{ $document->category === 'Patient Correspondence' ? 'selected' : '' }} value="Patient Correspondence">Patient Correspondence</option>
                                        <option {{ $document->category === 'Patient Demographics' ? 'selected' : '' }} value="Patient Demographics">Patient Demographics</option>
                                        <option {{ $document->category === 'Patient Driver\'s License' ? 'selected' : '' }} value="Patient Driver's License">Patient Driver's License</option>
                                        <option {{ $document->category === 'Patient Insurance Card' ? 'selected' : '' }} value="Patient Insurance Card">Patient Insurance Card</option>
                                        <option {{ $document->category === 'Patient Letter' ? 'selected' : '' }} value="Patient Letter">Patient Letter</option>
                                        <option {{ $document->category === 'Payment Batch' ? 'selected' : '' }} value="Payment Batch">Payment Batch</option>
                                        <option {{ $document->category === 'Phone Call/Message' ? 'selected' : '' }} value="Phone Call/Message">Phone Call/Message</option>
                                        <option {{ $document->category === 'Physician Established Patient Note' ? 'selected' : '' }} value="Physician Established Patient Note">Physician Established Patient Note</option>
                                        <option {{ $document->category === 'Physician New Patient Note' ? 'selected' : '' }} value="Physician New Patient Note">Physician New Patient Note</option>
                                        <option {{ $document->category === 'Prescriptions' ? 'selected' : '' }} value="Prescriptions">Prescriptions</option>
                                        <option {{ $document->category === 'Radiology Diagnostic' ? 'selected' : '' }} value="Radiology Diagnostic">Radiology Diagnostic</option>
                                        <option {{ $document->category === 'Radiology/Oncology' ? 'selected' : '' }} value="Radiology/Oncology">Radiology/Oncology</option>
                                        <option {{ $document->category === 'Referral Letter' ? 'selected' : '' }} value="Referral Letter">Referral Letter</option>
                                        <option {{ $document->category === 'Referral Received' ? 'selected' : '' }} value="Referral Received">Referral Received</option>
                                        <option {{ $document->category === 'Release of Information' ? 'selected' : '' }} value="Release of Information">Release of Information</option>
                                        <option {{ $document->category === 'Request for Amendment' ? 'selected' : '' }} value="Request for Amendment">Request for Amendment</option>
                                        <option {{ $document->category === 'Summary of Care Received' ? 'selected' : '' }} value="Summary of Care Received">Summary of Care Received</option>
                                        <option {{ $document->category === 'Summary of Care Sent' ? 'selected' : '' }} value="Summary of Care Sent">Summary of Care Sent</option>
                                        <option {{ $document->category === 'Superbill' ? 'selected' : '' }} value="Superbill">Superbill</option>
                                        <option {{ $document->category === 'Superbill Batch' ? 'selected' : '' }} value="Superbill Batch">Superbill Batch</option>
                                        <option {{ $document->category === 'Surgery/Procedure Report' ? 'selected' : '' }} value="Surgery/Procedure Report">Surgery/Procedure Report</option>
                                        <option {{ $document->category === 'Tests' ? 'selected' : '' }} value="Tests">Tests</option>
                                        <option {{ $document->category === 'Therapy Note' ? 'selected' : '' }} value="Therapy Note">Therapy Note</option>
                                        <option {{ $document->category === 'Treadmill Report' ? 'selected' : '' }} value="Treadmill Report">Treadmill Report</option>
                                        <option {{ $document->category === 'Ultrasound' ? 'selected' : '' }} value="Ultrasound">Ultrasound</option>
                                        <option {{ $document->category === 'Ultrasound Document' ? 'selected' : '' }} value="Ultrasound Document">Ultrasound Document</option>
                                        <option {{ $document->category === 'Urgent Care Visit Note' ? 'selected' : '' }} value="Urgent Care Visit Note">Urgent Care Visit Note</option>
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <label for="" class="text-sm text-secondary mb-1">Status</label>
                                    <select name="status" class="form-control form-control-sm">
                                        <option value="">-- select --</option>
                                        <option {{ $document->status === 'New' ? 'selected' : '' }} value="New">New</option>
                                        <option {{ $document->status === 'In-Process' ? 'selected' : '' }} value="In-Process">In-Process</option>
                                        <option {{ $document->status === 'Processed' ? 'selected' : '' }} value="Processed">Processed</option>
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <label for="" class="text-sm text-secondary mb-1">Effective Date</label>
                                    <input type="date" class="form-control form-control-sm"
                                           name="effectiveDate" value="{{ date('Y-m-d') }}" max="{{ date('Y-m-d') }}">
                                </div>
                                <div class="mb-2">
                                    <label for="" class="text-sm text-secondary mb-1">Provider</label>
                                    <select name="provider" class="form-control form-control-sm">
                                        <option value=""> --select-- </option>
                                        @foreach($pros as $iPro)
                                            <option {{ $document->provider === $iPro->uid ? 'selected' : '' }} value="{{$iPro->uid}}">{{$iPro->displayName()}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <label for="" class="text-sm text-secondary mb-1">Notes</label>
                                    <textarea class="form-control form-control-sm" name="notes">{{ $document->notes }}</textarea>
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Submit</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        <span moe relative class="mr-2">
                            <a start show class="on-hover-opaque"><i class="fa fa-trash-alt text-danger"></i></a>
                            <form url="/api/clientDocument/remove" right>
                                <input type="hidden" name="uid" value="{{ $document->uid }}">
                                <p class="small">Are you sure you want to delete this document?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                    </td>
                </tr>
                @endif
            @endforeach
            </tbody>
        </table>
    </div>
    <script>
        function submitDocument(_form) {
            showMask();
            $.ajax({
                type: "POST",
                enctype: 'multipart/form-data',
                url: _form.action,
                data: new FormData(_form),
                processData: false,
                contentType: false,
                cache: false,
                timeout: 600000,
                success: function (data) {
                    hideMask();
                    if(data.success) {
                        fastReload();
                    }
                    else {
                        toastr.error(data.message);
                    }
                },
                error: function (e) {
                    hideMask();
                    toastr.error('Unable to upload document!');
                }
            });
            return false;
        }
    </script>
@endsection
