|
@@ -188,39 +188,26 @@ class HomeController extends Controller
|
|
|
|
|
|
$keyNumbers = [];
|
|
$keyNumbers = [];
|
|
|
|
|
|
- $totalPatients = Client::where('mcp_pro_id', $performer->pro->id)->count();
|
|
|
|
- $keyNumbers['totalPatients'] = $totalPatients;
|
|
|
|
-
|
|
|
|
- $patientNotSeenYet = Client::where('mcp_pro_id', $performer->pro->id)
|
|
|
|
- ->where(function ($query) {
|
|
|
|
- $query->where('has_mcp_done_onboarding_visit', 'UNKNOWN')
|
|
|
|
- ->orWhere('has_mcp_done_onboarding_visit', 'NO');
|
|
|
|
|
|
+ $queryClients = $this->performer()->pro->getAccessibleClientsQuery();
|
|
|
|
+
|
|
|
|
+ $keyNumbers['totalPatients'] = $queryClients->count();
|
|
|
|
+
|
|
|
|
+ // patientNotSeenYet
|
|
|
|
+ $patientNotSeenYet = $queryClients
|
|
|
|
+ ->where(function ($query) use ($performer) { // own patient and primary OB visit pending
|
|
|
|
+ $query->where('mcp_pro_id', $performer->pro->id)
|
|
|
|
+ ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
|
|
|
|
+ })
|
|
|
|
+ ->orWhere(function ($query) { // mcp of any client program and program OB pending
|
|
|
|
+ $query->where(function ($_query) {
|
|
|
|
+ $_query->select(DB::raw('COUNT(id)'))
|
|
|
|
+ ->from('client_program')
|
|
|
|
+ ->whereColumn('client_id', 'client.id')
|
|
|
|
+ ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
|
|
|
|
+ }, '>=', 1);
|
|
})->count();
|
|
})->count();
|
|
$keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
|
|
$keyNumbers['patientsNotSeenYet'] = $patientNotSeenYet;
|
|
|
|
|
|
- // patientsPendingProgramOB
|
|
|
|
- $proID = $this->performer()->pro->id;
|
|
|
|
- if ($this->performer()->pro->pro_type === 'ADMIN') {
|
|
|
|
- $query = Client::where('id', '>', 0);
|
|
|
|
- } else {
|
|
|
|
- $query = Client::where(function ($q) use ($proID) {
|
|
|
|
- $q->where('mcp_pro_id', $proID)
|
|
|
|
- ->orWhere('cm_pro_id', $proID)
|
|
|
|
- ->orWhere('rmm_pro_id', $proID)
|
|
|
|
- ->orWhere('rme_pro_id', $proID)
|
|
|
|
- ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
|
|
|
|
- ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE pro_id = ?)', [$proID]);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- $query = $query->where(function ($_query) {
|
|
|
|
- $_query->select(DB::raw('COUNT(id)'))
|
|
|
|
- ->from('client_program')
|
|
|
|
- ->whereColumn('client_id', 'client.id')
|
|
|
|
- ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
|
|
|
|
- }, '>=', 1);
|
|
|
|
- $keyNumbers['patientsPendingProgramOB'] = $query->count();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
$pendingBillsToSign = Bill::where(function ($query) use ($performerProID) {
|
|
$pendingBillsToSign = Bill::where(function ($query) use ($performerProID) {
|
|
$query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
|
|
$query->where('hcp_pro_id', $performerProID)->where('is_signed_by_hcp', false)->where('is_cancelled', false);
|
|
})
|
|
})
|
|
@@ -337,32 +324,24 @@ class HomeController extends Controller
|
|
|
|
|
|
public function patients(Request $request, $filter = '')
|
|
public function patients(Request $request, $filter = '')
|
|
{
|
|
{
|
|
- $proID = $this->performer()->pro->id;
|
|
|
|
- if ($this->performer()->pro->pro_type === 'ADMIN') {
|
|
|
|
- $query = Client::where('id', '>', 0);
|
|
|
|
- } else {
|
|
|
|
- $query = Client::where(function ($q) use ($proID) {
|
|
|
|
- $q->where('mcp_pro_id', $proID)
|
|
|
|
- ->orWhere('cm_pro_id', $proID)
|
|
|
|
- ->orWhere('rmm_pro_id', $proID)
|
|
|
|
- ->orWhere('rme_pro_id', $proID)
|
|
|
|
- ->orWhereRaw('id IN (SELECT client_id FROM client_pro_access WHERE is_active AND pro_id = ?)', [$proID])
|
|
|
|
- ->orWhereRaw('id IN (SELECT client_id FROM appointment WHERE pro_id = ?)', [$proID]);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ $performer = $this->performer();
|
|
|
|
+ $query = $performer->pro->getAccessibleClientsQuery();
|
|
|
|
|
|
switch ($filter) {
|
|
switch ($filter) {
|
|
case 'not-yet-seen':
|
|
case 'not-yet-seen':
|
|
- $query = $query->where('has_mcp_done_onboarding_visit', '<>', 'YES');
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 'program-onboarding-pending':
|
|
|
|
- $query = $query->where(function ($_query) {
|
|
|
|
- $_query->select(DB::raw('COUNT(id)'))
|
|
|
|
- ->from('client_program')
|
|
|
|
- ->whereColumn('client_id', 'client.id')
|
|
|
|
- ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
|
|
|
|
- }, '>=', 1);
|
|
|
|
|
|
+ $query = $query
|
|
|
|
+ ->where(function ($query) use ($performer) { // own patient and primary OB visit pending
|
|
|
|
+ $query->where('mcp_pro_id', $performer->pro->id)
|
|
|
|
+ ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
|
|
|
|
+ })
|
|
|
|
+ ->orWhere(function ($query) { // mcp of any client program and program OB pending
|
|
|
|
+ $query->where(function ($_query) {
|
|
|
|
+ $_query->select(DB::raw('COUNT(id)'))
|
|
|
|
+ ->from('client_program')
|
|
|
|
+ ->whereColumn('client_id', 'client.id')
|
|
|
|
+ ->where('has_mcp_done_onboarding_visit', '!=', 'YES');
|
|
|
|
+ }, '>=', 1);
|
|
|
|
+ });
|
|
break;
|
|
break;
|
|
|
|
|
|
// more cases can be added as needed
|
|
// more cases can be added as needed
|