<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class erx_SINGLE_Controller extends Controller
{
    public $selfName = 'erx_SINGLE_Controller';
    public $dashboardName = 'dashboard';

	// GET /erx/view/{uid}/ACTION_signAsPrescriber
	public function ACTION_signAsPrescriber(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/ACTION_signAsPrescriber');
		}
		return response()->view('pro/erx_SINGLE/ACTION_signAsPrescriber', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /erx/view/{uid}/ACTION_updateToFacility
	public function ACTION_updateToFacility(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/ACTION_updateToFacility');
		}
		return response()->view('pro/erx_SINGLE/ACTION_updateToFacility', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /erx/view/{uid}/ACTION_updateContent
	public function ACTION_updateContent(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/ACTION_updateContent');
		}
		return response()->view('pro/erx_SINGLE/ACTION_updateContent', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /erx/view/{uid}/ACTION_updateStatus
	public function ACTION_updateStatus(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/ACTION_updateStatus');
		}
		return response()->view('pro/erx_SINGLE/ACTION_updateStatus', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /erx/view/{uid}/ACTION_efax
	public function ACTION_efax(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/ACTION_efax');
		}
		return response()->view('pro/erx_SINGLE/ACTION_efax', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /erx/view/{uid}/SUB_dashboard
	public function SUB_dashboard(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/SUB_dashboard');
		}
		return response()->view('pro/erx_SINGLE/SUB_dashboard', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /erx/view/{uid}/SUB_audit_log
	public function SUB_audit_log(Request $request, $uid) {
		$record = DB::table('action_item')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('action_item')->where('id', $uid)->first();
			if($record) return redirect('/erx/view/' . $record->uid . '/SUB_audit_log');
		}
		return response()->view('pro/erx_SINGLE/SUB_audit_log', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}
}
