|
@@ -4,12 +4,14 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Lib\Backend;
|
|
|
use App\Models\Appointment;
|
|
|
+use App\Models\AppSession;
|
|
|
use App\Models\ClientSMS;
|
|
|
use DateTime;
|
|
|
|
|
|
use App\Models\Client;
|
|
|
use App\Models\Bill;
|
|
|
use App\Models\Note;
|
|
|
+use App\Models\Pro;
|
|
|
use App\Models\ProTransaction;
|
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
|
use Illuminate\Http\Request;
|
|
@@ -35,7 +37,8 @@ class HomeController extends Controller
|
|
|
return view('app/set_security_questions');
|
|
|
}
|
|
|
|
|
|
- public function postConfirmSmsAuthToken(Request $request) {
|
|
|
+ public function postConfirmSmsAuthToken(Request $request)
|
|
|
+ {
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -47,24 +50,22 @@ class HomeController extends Controller
|
|
|
];
|
|
|
|
|
|
$response = Http::asForm()
|
|
|
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
+ ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
|
|
|
->post($url, $data)
|
|
|
->json();
|
|
|
|
|
|
- if(!isset($response['success']) || !$response['success']){
|
|
|
+ if (!isset($response['success']) || !$response['success']) {
|
|
|
$message = 'API error';
|
|
|
- if(isset($response['error'])) {
|
|
|
+ if (isset($response['error'])) {
|
|
|
$message = $response['error'];
|
|
|
- if(isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
- }
|
|
|
- else if(isset($response['message'])) $message = $response['message'];
|
|
|
+ if (isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
+ } else if (isset($response['message'])) $message = $response['message'];
|
|
|
return redirect('/confirm_sms_auth_token')
|
|
|
->withInput()
|
|
|
->with('message', $message);
|
|
|
}
|
|
|
|
|
|
return redirect('/');
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
return redirect()->back()
|
|
|
->with('message', 'Unable to process your request at the moment. Please try again later.')
|
|
@@ -72,7 +73,8 @@ class HomeController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function resendSmsAuthToken(Request $request) {
|
|
|
+ public function resendSmsAuthToken(Request $request)
|
|
|
+ {
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -81,24 +83,22 @@ class HomeController extends Controller
|
|
|
$data = [];
|
|
|
|
|
|
$response = Http::asForm()
|
|
|
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
+ ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
|
|
|
->post($url, $data)
|
|
|
->json();
|
|
|
|
|
|
- if(!isset($response['success']) || !$response['success']){
|
|
|
+ if (!isset($response['success']) || !$response['success']) {
|
|
|
$message = 'API error';
|
|
|
- if(isset($response['error'])) {
|
|
|
+ if (isset($response['error'])) {
|
|
|
$message = $response['error'];
|
|
|
- if(isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
- }
|
|
|
- else if(isset($response['message'])) $message = $response['message'];
|
|
|
+ if (isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
+ } else if (isset($response['message'])) $message = $response['message'];
|
|
|
return redirect('/confirm_sms_auth_token')
|
|
|
->withInput()
|
|
|
->with('message', $message);
|
|
|
}
|
|
|
|
|
|
return redirect()->back()->withInput()->with('message', "SMS Auth Token sent.");
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
return redirect()->back()
|
|
|
->with('message', 'Unable to process your request at the moment. Please try again later.')
|
|
@@ -106,7 +106,8 @@ class HomeController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function postSetPassword(Request $request) {
|
|
|
+ public function postSetPassword(Request $request)
|
|
|
+ {
|
|
|
try {
|
|
|
|
|
|
$url = env('BACKEND_URL', 'http://localhost:8080/api') . '/pro/selfPutPassword';
|
|
@@ -117,31 +118,30 @@ class HomeController extends Controller
|
|
|
];
|
|
|
|
|
|
$response = Http::asForm()
|
|
|
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
+ ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
|
|
|
->post($url, $data)
|
|
|
->json();
|
|
|
|
|
|
- if(!isset($response['success']) || !$response['success']){
|
|
|
+ if (!isset($response['success']) || !$response['success']) {
|
|
|
$message = 'API error';
|
|
|
- if(isset($response['error'])) {
|
|
|
+ if (isset($response['error'])) {
|
|
|
$message = $response['error'];
|
|
|
- if(isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
- }
|
|
|
- else if(isset($response['message'])) $message = $response['message'];
|
|
|
+ if (isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
+ } else if (isset($response['message'])) $message = $response['message'];
|
|
|
return redirect('/set_password')
|
|
|
->withInput()
|
|
|
->with('message', $message);
|
|
|
}
|
|
|
|
|
|
return redirect('/');
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
return redirect()->back()
|
|
|
->with('message', 'Unable to process your request at the moment. Please try again later.')
|
|
|
->withInput($request->input());
|
|
|
}
|
|
|
}
|
|
|
- public function postSetSecurityQuestions(Request $request) {
|
|
|
+ public function postSetSecurityQuestions(Request $request)
|
|
|
+ {
|
|
|
|
|
|
try {
|
|
|
|
|
@@ -155,30 +155,27 @@ class HomeController extends Controller
|
|
|
];
|
|
|
|
|
|
$response = Http::asForm()
|
|
|
- ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
|
|
|
+ ->withHeaders(['sessionKey' => $request->cookie('sessionKey')])
|
|
|
->post($url, $data)
|
|
|
->json();
|
|
|
|
|
|
- if(!isset($response['success']) || !$response['success']){
|
|
|
+ if (!isset($response['success']) || !$response['success']) {
|
|
|
$message = 'API error';
|
|
|
- if(isset($response['error'])) {
|
|
|
+ if (isset($response['error'])) {
|
|
|
$message = $response['error'];
|
|
|
- if(isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
- }
|
|
|
- else if(isset($response['message'])) $message = $response['message'];
|
|
|
+ if (isset($response['path'])) $message .= ': ' . $response['path'];
|
|
|
+ } else if (isset($response['message'])) $message = $response['message'];
|
|
|
return redirect('/set_password')
|
|
|
->withInput()
|
|
|
->with('message', $message);
|
|
|
}
|
|
|
|
|
|
return redirect('/');
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
return redirect()->back()
|
|
|
->with('message', 'Unable to process your request at the moment. Please try again later.')
|
|
|
->withInput($request->input());
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function dashboard(Request $request)
|
|
@@ -272,7 +269,7 @@ class HomeController extends Controller
|
|
|
$appointment->newStatus = $appointment->status;
|
|
|
$appointment->dateYMD = date('Y-m-d', strtotime($appointment->start_time));
|
|
|
$appointment->clientName = $appointment->client->displayName();
|
|
|
- $appointment->clientInitials = substr($appointment->client->name_first, 0, 1).substr($appointment->client->name_last, 0, 1);
|
|
|
+ $appointment->clientInitials = substr($appointment->client->name_first, 0, 1) . substr($appointment->client->name_last, 0, 1);
|
|
|
$appointment->friendlyStartTime = friendly_time($appointment->start_time);
|
|
|
$appointment->friendlyEndTime = friendly_time($appointment->end_time);
|
|
|
$appointment->clientSummary = friendly_date_time($appointment->client->dob, false) . ' (' .
|
|
@@ -281,18 +278,16 @@ class HomeController extends Controller
|
|
|
')';
|
|
|
|
|
|
$appointment->started = false;
|
|
|
- $appointment->inHowManyHours = date_diff(date_create('now'), date_create($appointment->start_time),false)
|
|
|
+ $appointment->inHowManyHours = date_diff(date_create('now'), date_create($appointment->start_time), false)
|
|
|
->format('%R%h h, %i m');
|
|
|
- if($appointment->inHowManyHours[0] === '-') {
|
|
|
+ if ($appointment->inHowManyHours[0] === '-') {
|
|
|
$appointment->inHowManyHours = substr($appointment->inHowManyHours, 1) . ' ago';
|
|
|
$appointment->started = true;
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
$appointment->inHowManyHours = 'Appt. in ' . substr($appointment->inHowManyHours, 1);
|
|
|
}
|
|
|
$appointment->clientUid = $appointment->client->uid;
|
|
|
$appointment->proUid = $appointment->pro->uid;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
$milliseconds = strtotime(date('Y-m-d')) . '000';
|
|
@@ -303,11 +298,10 @@ class HomeController extends Controller
|
|
|
public function patients(Request $request, $filter = '')
|
|
|
{
|
|
|
$proID = $this->performer()->pro->id;
|
|
|
- if($this->performer()->pro->pro_type === 'ADMIN') {
|
|
|
+ if ($this->performer()->pro->pro_type === 'ADMIN') {
|
|
|
$query = Client::where('id', '>', 0);
|
|
|
- }
|
|
|
- else {
|
|
|
- $query = Client::where(function ($q) use($proID) {
|
|
|
+ } else {
|
|
|
+ $query = Client::where(function ($q) use ($proID) {
|
|
|
$q->where('mcp_pro_id', $proID)
|
|
|
->orWhere('cm_pro_id', $proID)
|
|
|
->orWhere('rmm_pro_id', $proID)
|
|
@@ -320,7 +314,7 @@ class HomeController extends Controller
|
|
|
$query = $query->where('has_mcp_done_onboarding_visit', '<>', 'YES');
|
|
|
break;
|
|
|
|
|
|
- // more cases can be added as needed
|
|
|
+ // more cases can be added as needed
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -328,23 +322,24 @@ class HomeController extends Controller
|
|
|
return view('app/patients', compact('patients', 'filter'));
|
|
|
}
|
|
|
|
|
|
- public function patientsSuggest(Request $request) {
|
|
|
+ public function patientsSuggest(Request $request)
|
|
|
+ {
|
|
|
$term = $request->input('term') ? trim($request->input('term')) : '';
|
|
|
- if(empty($term)) return '';
|
|
|
- $clients = Client::where(function ($q) use($term) {
|
|
|
+ if (empty($term)) return '';
|
|
|
+ $clients = Client::where(function ($q) use ($term) {
|
|
|
$q->where('name_first', 'ILIKE', '%' . $term . '%')
|
|
|
->orWhere('name_last', 'ILIKE', '%' . $term . '%');
|
|
|
})->get();
|
|
|
return view('app/patient-suggest', compact('clients'));
|
|
|
}
|
|
|
|
|
|
- public function unmappedSMS(Request $request, $filter = '') {
|
|
|
+ public function unmappedSMS(Request $request, $filter = '')
|
|
|
+ {
|
|
|
$proID = $this->performer()->pro->id;
|
|
|
- if($this->performer()->pro->pro_type === 'ADMIN') {
|
|
|
+ if ($this->performer()->pro->pro_type === 'ADMIN') {
|
|
|
$query = Client::where('id', '>', 0);
|
|
|
- }
|
|
|
- else {
|
|
|
- $query = Client::where(function ($q) use($proID) {
|
|
|
+ } else {
|
|
|
+ $query = Client::where(function ($q) use ($proID) {
|
|
|
$q->where('mcp_pro_id', $proID)
|
|
|
->orWhere('cm_pro_id', $proID)
|
|
|
->orWhere('rmm_pro_id', $proID)
|
|
@@ -376,10 +371,74 @@ class HomeController extends Controller
|
|
|
return view('app/blank');
|
|
|
}
|
|
|
|
|
|
- public function noteTemplateSet(Request $request, $section, $template) {
|
|
|
+ public function noteTemplateSet(Request $request, $section, $template)
|
|
|
+ {
|
|
|
return view('app/patient/note/_template', [
|
|
|
"sectionInternalName" => $section,
|
|
|
"templateName" => $template
|
|
|
]);
|
|
|
}
|
|
|
+
|
|
|
+ public function logInAs(Request $request)
|
|
|
+ {
|
|
|
+ if($this->pro->pro_type != 'ADMIN'){
|
|
|
+ return redirect()->to(route('dashboard'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $pros = Pro::where('pro_type', '!=', 'ADMIN')->orWhereNull('pro_type')->get();
|
|
|
+ return view('app/log-in-as', compact('pros'));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function processLogInAs(Request $request)
|
|
|
+ {
|
|
|
+
|
|
|
+ $api = new Backend();
|
|
|
+
|
|
|
+ try {
|
|
|
+ $apiResponse = $api->post('session/proLogInAs', [
|
|
|
+ 'proUid' => $request->post('proUid')
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'sessionKey'=>$this->performer()->session_key
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $data = json_decode($apiResponse->getContents());
|
|
|
+
|
|
|
+ if (!property_exists($data, 'success') || !$data->success) {
|
|
|
+ return redirect()->to(route('log-in-as'))->with('message', $data->message)
|
|
|
+ ->withInput($request->input());
|
|
|
+ }
|
|
|
+
|
|
|
+ Cookie::queue('sessionKey', $data->data->sessionKey);
|
|
|
+
|
|
|
+ return redirect('/mc');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return redirect()->to(route('log-in-as'))
|
|
|
+ ->with('message', 'Unable to process your request at the moment. Please try again later.')
|
|
|
+ ->withInput($request->input());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function backToAdminPro(Request $request){
|
|
|
+ $adminPerformerId = $this->performer->logged_in_as_pro_from_admin_pro_app_session_id;
|
|
|
+ $adminPerformer = AppSession::where('id', $adminPerformerId)->first();
|
|
|
+ $url = "/session/pro_log_in_with_session_key/".$adminPerformer->session_key;
|
|
|
+ $api = new Backend();
|
|
|
+ try {
|
|
|
+ $apiResponse = $api->post($url, []);
|
|
|
+ $data = json_decode($apiResponse->getContents());
|
|
|
+
|
|
|
+ if (!property_exists($data, 'success') || !$data->success) {
|
|
|
+ return redirect('/mc');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Cookie::queue('sessionKey', $data->data->sessionKey);
|
|
|
+
|
|
|
+ return redirect(route('dashboard'));
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return redirect(route('dashboard'));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|