<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


/*
 * if no pro performer, then redirect to /login2
 * [Cell Number] [Password] field -> proLogInWithPassword -> /pro/dashboard
 * -> they are authenticated in... see the home dashboard... logout button to -> /login
 */


Route::get('login', 'LoginController@showLoginForm')->name('login');
Route::post('login', 'LoginController@login');
Route::get('logout', 'LoginController@logout');

Route::get('request_password_reset', 'LoginController@showRequestPasswordReset')->name('request_password_reset');
Route::post('request_password_reset', 'LoginController@processRequestPasswordReset')->name('process_request_password_reset');
Route::get('self_reset_password', 'LoginController@showSelfResetPassword')->name('self_reset_password');
Route::post('self_reset_password', 'LoginController@processSelfResetPassword')->name('process_self_reset_password');

Route::get('/pro_log_in_with_session_key/{sessionKey}/{appAccessUID?}', 'LoginController@loginWithSessionKey')->name('login_with_session_key');

Route::post('logout', 'LoginController@logout')->name('logout');

Route::post('/confirm_sms_auth_token', 'HomeController@postConfirmSmsAuthToken')->name('post-confirm_sms_auth_token');
Route::post('/resend_sms_auth_token', 'HomeController@resendSmsAuthToken')->name('post-resend_sms_auth_token');
Route::post('/set_password', 'HomeController@postSetPassword')->name('post-set_password');
Route::post('/set_security_questions', 'HomeController@postSetSecurityQuestions')->name('post-set_security_questions');

Route::get("/guest/section/{accessToken}", 'GuestController@section')->name('guest_section_access');
Route::get("/guest/handout/{handoutClientUid}", 'GuestController@handout')->name('guest_handout_access');
Route::get("/appointment-confirmation/{appointmentUid}", 'GuestController@appointmentConfirmation')->name('appointment_confirmation');
Route::post("/process-appointment-confirmation", 'GuestController@processAppointmentConfirmation')->name('process-appointment_confirmation');

Route::get('/ticket-download-as-pdf/{ticket}', 'TicketController@downloadAsPdf')->name('ticket-download-as-pdf');

Route::middleware('pro.auth')->group(function () {

    //complete authentication

    Route::get('/confirm_sms_auth_token', 'HomeController@confirmSmsAuthToken')->name('confirm_sms_auth_token');

    Route::get('/set_password', 'HomeController@setPassword')->name('set_password');

    Route::get('/set_security_questions', 'HomeController@setSecurityQuestions')->name('set_security_questions');

    Route::get('/blank', 'HomeController@blank')->name('blank');

    Route::get('/', 'HomeController@dashboard')->name('dashboard');

    Route::get('/new-patient', 'HomeController@newPatient')->name('new-patient');

    Route::get('/patients/{filter?}', 'HomeController@patients')->name('patients');

    Route::get('/unmapped-sms/{filter?}', 'HomeController@unmappedSMS')->name('unmapped-sms');


    Route::name('practice-management.')->prefix('practice-management')->group(function () {
        Route::get('rates/{selectedProUid?}', 'PracticeManagementController@rates')->name('rates');
        Route::get('dashboard', 'PracticeManagementController@dashboard')->name('dashboard');
        Route::get('previous-bills', 'PracticeManagementController@previousBills')->name('previousBills');
        Route::get('financial-transactions', 'PracticeManagementController@financialTransactions')->name('financialTransactions');
        Route::get('pending-bills-to-sign', 'PracticeManagementController@pendingBillsToSign')->name('pendingBillsToSign');
        Route::get('hr', 'PracticeManagementController@hr')->name('hr');
        Route::get('direct-deposit-settings', 'PracticeManagementController@directDepositSettings')->name('directDepositSettings');
        Route::get('w9', 'PracticeManagementController@w9')->name('w9');
        Route::get('contract', 'PracticeManagementController@contract')->name('contract');
        Route::get('notes/{filter?}', 'PracticeManagementController@notes')->name('notes');
        Route::get('bills/{filter?}', 'PracticeManagementController@bills')->name('bills');
        Route::get('my-tickets/{filter?}', 'PracticeManagementController@myTickets')->name('myTickets');
        Route::get('my-text-shortcuts', 'PracticeManagementController@myTextShortcuts')->name('myTextShortcuts');
        Route::get('my-favorites/{filter?}', 'PracticeManagementController@myFavorites')->name('myFavorites');
        Route::get('pro-availability/{proUid?}', 'PracticeManagementController@proAvailability')->name('proAvailability');
        Route::get('calendar/{proUid?}', 'PracticeManagementController@calendar')->name('proCalendar');

        Route::get('billing-manager/{proUid?}', 'PracticeManagementController@billingManager')->name('billingManager');

        Route::get('cellular-device-manager/{proUid?}', 'PracticeManagementController@cellularDeviceManager')->name('cellularDeviceManager');



        Route::middleware('pro.auth.admin')->group(function(){

            Route::get('cellular-measurements', 'PracticeManagementController@cellularMeasurements')->name('cellularMeasurements');

            Route::get('processing-bill-matrix/{proUid?}', 'PracticeManagementController@processingBillMatrix')->name('processingBillMatrix');

            Route::get('hcp-bill-matrix/{proUid?}', 'PracticeManagementController@hcpBillMatrix')->name('hcpBillMatrix');

            Route::get('tickets', 'PracticeManagementController@tickets')->name('tickets');
            Route::get('claims', 'PracticeManagementController@claims')->name('claims');
            Route::get('claims-download', 'PracticeManagementController@downloadClaims')->name('download-claims');

            Route::get('treatment-service-util', 'PracticeManagementController@treatmentServiceUtil')->name('treatmentServiceUtil');

        });
    });

    Route::middleware('pro.auth.admin')->group(function(){
        Route::get('patients/view/mcp-requests/{patient?}', 'PatientController@mcpRequests')->name('patients.view.mcp-requests');
        Route::get('patients/view/eligible-refreshes/{patient}', 'PatientController@eligibleRefreshes')->name('patients.view.eligible-refreshes');
    });

    Route::name('patients.view.')->prefix('patients/view/{patient}')->group(function () {
        Route::get('intake', 'PatientController@intake')->name('intake');
        Route::get('', 'PatientController@dashboard')->name('dashboard');
        Route::get('care-plan', 'PatientController@carePlan')->name('care-plan');
        Route::get('medications', 'PatientController@medications')->name('medications');
        Route::get('dx-and-focus-areas', 'PatientController@dxAndFocusAreas')->name('dx-and-focus-areas');
        Route::get('care-team', 'PatientController@careTeam')->name('care-team');
        Route::get('devices', 'PatientController@devices')->name('devices');
        Route::get('measurements', 'PatientController@measurements')->name('measurements');
        Route::get('labs-and-studies', 'PatientController@labsAndStudies')->name('labs-and-studies');
        Route::get('history', 'PatientController@history')->name('history');
        Route::get('memos', 'PatientController@memos')->name('memos');
        Route::get('sms', 'PatientController@sms')->name('sms');
        Route::get('sms-numbers', 'PatientController@smsNumbers')->name('sms-numbers');
        Route::get('immunizations', 'PatientController@immunizations')->name('immunizations');
        Route::get('allergies', 'PatientController@allergies')->name('allergies');
        Route::get('action-items', 'PatientController@actionItems')->name('action-items');
        Route::get('action-items-erx/view/{ticket}', 'PatientController@actionItemsErxSingle')->name('action-items-erx-single');
        Route::get('action-items-lab/view/{ticket}', 'PatientController@actionItemsLabSingle')->name('action-items-lab-single');
        Route::get('action-items-imaging/view/{ticket}', 'PatientController@actionItemsImagingSingle')->name('action-items-imaging-single');
        Route::get('action-items-equipment/view/{ticket}', 'PatientController@actionItemsEquipmentSingle')->name('action-items-equipment-single');
        Route::get('action-items-other/view/{ticket}', 'PatientController@actionItemsOtherSingle')->name('action-items-other-single');
        Route::get('action-items-erx/{filter?}', 'PatientController@actionItemsErx')->name('action-items-erx');
        Route::get('action-items-lab/{filter?}', 'PatientController@actionItemsLab')->name('action-items-lab');
        Route::get('action-items-imaging/{filter?}', 'PatientController@actionItemsImaging')->name('action-items-imaging');
        Route::get('action-items-equipment/{filter?}', 'PatientController@actionItemsEquipment')->name('action-items-equipment');
        Route::get('action-items-other/{filter?}', 'PatientController@actionItemsOther')->name('action-items-other');
        Route::get('notes/{filter?}', 'PatientController@notes')->name('notes');
        Route::name('notes.view.')->prefix('notes/view/{note}')->group(function () {
            Route::get('', 'NoteController@dashboard')->name('dashboard');
        });
        Route::get('sections', 'PatientController@sections')->name('sections');
        Route::get('handouts', 'PatientController@handouts')->name('handouts');
        Route::get('settings', 'PatientController@settings')->name('settings');
        Route::get('pros', 'PatientController@pros')->name('pros');
        Route::get('account', 'PatientController@account')->name('account');
        Route::get('care-checklist', 'PatientController@careChecklist')->name('care-checklist');
        Route::get('documents', 'PatientController@documents')->name('documents');
        Route::get('incoming-reports', 'PatientController@incomingReports')->name('incoming-reports');
        Route::get('education', 'PatientController@education')->name('education');
        Route::get('messaging', 'PatientController@messaging')->name('messaging');
        Route::get('duplicate', 'PatientController@duplicate')->name('duplicate');
        Route::get('care-months', 'PatientController@careMonths')->name('care-months');
        Route::name('care-months.view.')->prefix('care-months/view/{careMonth}')->group(function () {
            Route::get('', 'CareMonthController@dashboard')->name('dashboard');
        });

        // appointment calendar
        Route::get('calendar/{currentAppointment?}', 'PatientController@calendar')->name('calendar');

        // programs
        Route::get('programs/{filter?}', 'PatientController@programs')->name('programs');

        // flowsheets
        Route::get('flowsheets/{filter?}', 'PatientController@flowsheets')->name('flowsheets');

        // vitals-graph
        Route::get('vitals-graph/{filter?}', 'PatientController@vitalsGraph')->name('vitals-graph');

        // tickets
        Route::get('tickets', 'PatientController@tickets')->name('patient-tickets');

        // appointments
        Route::get('appointments/{forPro}/{status}', 'PatientController@appointments')->name('appointments');
    });

    // pro dashboard events (ajax)
    Route::get('pro-dashboard-events/{from}/{to}', 'HomeController@dashboardAppointments')->name('pro-dashboard-events');

    // pro dashboard measurements
    Route::get('pro-dashboard-measurements/{filter}', 'HomeController@dashboardMeasurements')->name('pro-dashboard-measurements');

    // events for fc
    Route::get('/appointment/getAllAppointmentsForPros', 'AppointmentController@events')->name('events');

    //events for availability
    Route::post('/availability/load/{proUid}', 'PracticeManagementController@loadAvailability')->name('loadAvailability');
    Route::post('/pro-availability/filter', 'PracticeManagementController@proAvailabilityFilter')->name('pro-availability-filter');

    // load template set
    Route::get('/note-template-set/exam/{exam}/{template}', 'HomeController@noteExamTemplateSet');
    Route::get('/note-template-set/{section}/{template}', 'HomeController@noteTemplateSet');

    // Patient suggest
    Route::get('/patients-suggest', 'HomeController@patientsSuggest');

    // Pharmacy suggest
    Route::get('/pharmacy-suggest', 'HomeController@pharmacySuggest');

    // Pro suggest
    Route::get('/pro-suggest', 'HomeController@proSuggest');
    Route::get('/pro-display-name/{pro}', 'HomeController@proDisplayName');

    // embeddable sections
    Route::get('/embed/{patient}/{section}/{selectable}', 'PatientController@embedSection')->name('embed-section');

    // AJAX presence poll
    Route::get('/patients/{patient}/presence', 'PatientController@presence');

    // refresh single ticket
    Route::get('/get-ticket/{ticket}', 'PatientController@getTicket');


    Route::get('/appointment-confirmation-history/{appointment}', 'AppointmentController@appointmentConfirmationHistory')->name('appointment-confirmation-history');

    // 2-pane outer page housing lhs (practice management) and rhs (video call)
    Route::get('/mc/{fragment?}', 'HomeController@mc')
        ->where('fragment', '.*')
        ->name('mc');

    // pro meeting
    Route::get('/pro/check-video/{uid}', 'PracticeManagementController@checkVideo');
    Route::get('/pro/meet/{uid?}', 'PracticeManagementController@meet');
    Route::post('/pro/meet/get-participant-info', 'PracticeManagementController@getParticipantInfo');
    Route::get('/pro/get-opentok-session-key/{uid}', 'PracticeManagementController@getOpentokSessionKey');
    Route::get('/patients-in-queue', 'PracticeManagementController@getPatientsInQueue');
    Route::get('/current-work', 'PracticeManagementController@currentWork');

    //Notes stuff
    Route::get('/note/{note_uid}', 'NoteController@renderNote')->name('render-note');
    Route::get('/section_create_form/{note_uid}/{section_template_uid}', 'NoteController@sectionCreateForm')->name('section_create_form');
    Route::get('/section_update_form/{section_uid}', 'NoteController@sectionUpdateForm')->name('section_update_form');


    Route::get("/log_in_as", 'HomeController@logInAs')->name('log-in-as');
    Route::post("/process-log_in_as", 'HomeController@processLogInAs')->name('process-log-in-as');
    Route::post("/back_to_admin_pro", 'HomeController@backToAdminPro')->name('back-to-admin-pro');
});

Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');
Route::get("/get-default-section-data/{patientID}/{sectionTemplateID}", 'NoteController@getDefaultValueForSection')->name('get_default_section_data');

