|
@@ -371,6 +371,15 @@ class Pro extends Model
|
|
|
return $favorites;
|
|
|
}
|
|
|
|
|
|
+ function get_patients_count_as_admin() {
|
|
|
+ $query = Client::whereNull('shadow_pro_id');
|
|
|
+ return $query->where('is_active', true)
|
|
|
+ ->where(function ($q) {
|
|
|
+ $q->whereNull('client_engagement_status_category')
|
|
|
+ ->orWhere('client_engagement_status_category', '<>', 'DUMMY');
|
|
|
+ })->count();
|
|
|
+ }
|
|
|
+
|
|
|
function get_patients_count_as_mcp() {
|
|
|
$query = Client::whereNull('shadow_pro_id');
|
|
|
return $query->where('mcp_pro_id', $this->id)
|
|
@@ -387,6 +396,12 @@ class Pro extends Model
|
|
|
->count();
|
|
|
}
|
|
|
|
|
|
+ function get_new_patients_awaiting_visit_count_as_admin() {
|
|
|
+ $query = Client::whereNull('shadow_pro_id');
|
|
|
+ return $query->where('has_mcp_done_onboarding_visit', '!=', 'YES')
|
|
|
+ ->count();
|
|
|
+ }
|
|
|
+
|
|
|
function get_notes_pending_signature_count_as_mcp() {
|
|
|
return Note::where('hcp_pro_id', $this->id)
|
|
|
->where('is_cancelled', '<>', true)
|
|
@@ -395,6 +410,13 @@ class Pro extends Model
|
|
|
->count();
|
|
|
}
|
|
|
|
|
|
+ function get_notes_pending_signature_count_as_admin() {
|
|
|
+ return Note::where('is_cancelled', '<>', true)
|
|
|
+ ->where('is_core_note', '<>', true)
|
|
|
+ ->where('is_signed_by_hcp', '<>', true)
|
|
|
+ ->count();
|
|
|
+ }
|
|
|
+
|
|
|
function get_notes_pending_summary_suggestion_as_mcp_query(){
|
|
|
$segmentsWithProposedSummarySuggestion = Segment::whereHas('proposedSegmentSummarySuggestion', function($sugQuery){
|
|
|
return $sugQuery->where('status', '=', 'PENDING');
|
|
@@ -493,6 +515,12 @@ class Pro extends Model
|
|
|
->count();
|
|
|
}
|
|
|
|
|
|
+ function get_notes_pending_billing_count_as_admin() {
|
|
|
+ return Note::where('is_cancelled', '<>', true)
|
|
|
+ ->where('is_signed_by_hcp', true)
|
|
|
+ ->where('is_billing_marked_done', '<>', true)
|
|
|
+ ->count();
|
|
|
+ }
|
|
|
|
|
|
function get_measurements_awaiting_review_count_as_mcp() {
|
|
|
$result = DB::select(DB::raw("
|
|
@@ -529,6 +557,12 @@ WHERE mcp_pro_id = :pro_id
|
|
|
->count();
|
|
|
}
|
|
|
|
|
|
+ function get_incoming_reports_pending_signature_count_as_admin() {
|
|
|
+ return IncomingReport::where('has_hcp_pro_signed', '<>', true)
|
|
|
+ ->where('is_entry_error', '<>', true)
|
|
|
+ ->count();
|
|
|
+ }
|
|
|
+
|
|
|
function get_patients_without_appointment_query() {
|
|
|
return Client::where('mcp_pro_id', $this->id)
|
|
|
->whereNull('today_mcp_appointment_date')
|
|
@@ -551,6 +585,15 @@ WHERE mcp_pro_id = :pro_id
|
|
|
return $this->get_patients_without_appointment_query()->count();
|
|
|
}
|
|
|
|
|
|
+ function get_patients_without_appointment_count_as_admin() {
|
|
|
+ return Client::whereNull('shadow_pro_id')
|
|
|
+ ->whereNull('today_mcp_appointment_date')
|
|
|
+ ->where(function($q){
|
|
|
+ $q->whereNull('next_mcp_appointment_id')
|
|
|
+ ->orWhere('next_mcp_appointment_date', '<=', DB::raw('NOW()::DATE'));
|
|
|
+ })->count();
|
|
|
+ }
|
|
|
+
|
|
|
function get_patients_overdue_for_visit_query() {
|
|
|
return Client::where('mcp_pro_id', $this->id)
|
|
|
->where(function($q){
|
|
@@ -633,6 +676,66 @@ WHERE mcp_pro_id = :pro_id
|
|
|
->count();
|
|
|
}
|
|
|
|
|
|
+ function get_unsigned_rpm_bills_count_as_mcp() {
|
|
|
+
|
|
|
+ $query = "
|
|
|
+SELECT count(distinct(care_month.id))
|
|
|
+FROM care_month join client on care_month.client_id = client.id join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
|
|
|
+ left join bill on care_month.mcp_rm_generic_bill_id = bill.id
|
|
|
+ left join note mrmnote on mrmnote.id = (
|
|
|
+ select max(n.id) from note n
|
|
|
+ where
|
|
|
+ n.client_id = client.id AND
|
|
|
+ n.is_cancelled = FALSE AND
|
|
|
+ (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
|
|
|
+ n.effective_dateest::date >= care_month.start_date::date AND
|
|
|
+ n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
|
|
|
+ )
|
|
|
+WHERE
|
|
|
+ care_month.mcp_pro_id = {$this->id}
|
|
|
+ AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
|
|
|
+ AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
|
|
|
+ AND care_month.mcp_rm_generic_bill_id IS NOT NULL
|
|
|
+ AND bill.is_signed_by_generic_pro = TRUE
|
|
|
+";
|
|
|
+
|
|
|
+ // dd($query);
|
|
|
+
|
|
|
+ $count = DB::select($query);
|
|
|
+
|
|
|
+ return $count[0]->count;
|
|
|
+ }
|
|
|
+
|
|
|
+ function get_unsigned_rpm_bills_count_as_rmm() {
|
|
|
+
|
|
|
+ $query = "
|
|
|
+SELECT count(distinct(care_month.id))
|
|
|
+FROM care_month join client on care_month.client_id = client.id join note mrnote on client.most_recent_completed_mcp_note_id = mrnote.id
|
|
|
+ left join bill on care_month.rmm_rm_generic_bill_id = bill.id
|
|
|
+ left join note mrmnote on mrmnote.id = (
|
|
|
+ select max(n.id) from note n
|
|
|
+ where
|
|
|
+ n.client_id = client.id AND
|
|
|
+ n.is_cancelled = FALSE AND
|
|
|
+ (n.is_signed_by_hcp IS NOT NULL AND n.is_signed_by_hcp = TRUE) AND
|
|
|
+ n.effective_dateest::date >= care_month.start_date::date AND
|
|
|
+ n.effective_dateest::date < (care_month.start_date::date + INTERVAL '1 month')
|
|
|
+ )
|
|
|
+WHERE
|
|
|
+ care_month.rmm_pro_id = {$this->id}
|
|
|
+ AND EXTRACT(MONTH from care_month.start_date) = EXTRACT(MONTH from now())
|
|
|
+ AND EXTRACT(YEAR from care_month.start_date) = EXTRACT(YEAR from now())
|
|
|
+ AND care_month.rmm_rm_generic_bill_id IS NOT NULL
|
|
|
+ AND bill.is_signed_by_generic_pro = TRUE
|
|
|
+";
|
|
|
+
|
|
|
+ // dd($query);
|
|
|
+
|
|
|
+ $count = DB::select($query);
|
|
|
+
|
|
|
+ return $count[0]->count;
|
|
|
+ }
|
|
|
+
|
|
|
function get_birthdays_today_as_mcp(){
|
|
|
return;
|
|
|
$queryClients = $this->performer()->pro->getAccessibleClientsQuery();
|
|
@@ -954,6 +1057,19 @@ WHERE mcp_pro_id = :pro_id
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ public function get_open_tickets_count_as_mcp(){
|
|
|
+ $self = $this;
|
|
|
+ return Ticket::where(function ($q) use ($self) {
|
|
|
+ $q->where('assigned_pro_id', $self->id)
|
|
|
+ ->orWhere('manager_pro_id', $self->id)
|
|
|
+ ->orWhere('ordering_pro_id', $self->id)
|
|
|
+ ->orWhere('initiating_pro_id', $self->id);
|
|
|
+ })
|
|
|
+ ->where('category', 'other')
|
|
|
+ ->where('is_open', true)
|
|
|
+ ->count();
|
|
|
+ }
|
|
|
+
|
|
|
//DNA_DASHBOARD
|
|
|
|
|
|
//queries
|