Skip to content

Commit

Permalink
updated client list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Nov 15, 2023
1 parent 384f6aa commit 8f16062
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
15 changes: 12 additions & 3 deletions app/Http/Controllers/NewReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public function clients_list()
->leftJoin('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name')
->leftJoin('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id')
->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id')
->leftJoin(DB::raw('(SELECT client_id, DATE(created_at) AS created_at
FROM tbl_appointment a1
WHERE a1.id = (SELECT MAX(a2.id) FROM tbl_appointment a2 WHERE a2.client_id = a1.client_id)
AND a1.consented = "YES") a'), 'tbl_client.id', '=', 'a.client_id')
->select(
'tbl_client.id',
'tbl_client.clinic_number',
Expand All @@ -225,7 +229,8 @@ public function clients_list()
'tbl_client.l_name',
'tbl_client.dob',
'tbl_client.created_at',
'tbl_client.smsenable',
DB::raw('CASE WHEN tbl_client.smsenable="Yes" THEN "Yes" WHEN a.client_id IS NOT NULL THEN
"Yes" ELSE "No" END as smsenable'),
DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'),
DB::raw('DATE(tbl_client.art_date) AS art_date'),
'tbl_client.motivational_enable',
Expand All @@ -251,7 +256,6 @@ public function clients_list()
'tbl_client.locator_location',
'tbl_client.upi_no'
)
->where('tbl_client.status', '=', 'Active')
->whereNull('tbl_client.hei_no')
->where('tbl_client.mfl_code', Auth::user()->facility_id)
->paginate(20000);
Expand All @@ -275,6 +279,10 @@ public function clients_list()
->join('tbl_condition', 'tbl_client.client_status', '=', 'tbl_condition.name')
->join('tbl_marital_status', 'tbl_client.marital', '=', 'tbl_marital_status.id')
->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id')
->leftJoin(DB::raw('(SELECT client_id, DATE(created_at) AS created_at
FROM tbl_appointment a1
WHERE a1.id = (SELECT MAX(a2.id) FROM tbl_appointment a2 WHERE a2.client_id = a1.client_id)
AND a1.consented = "YES") a'), 'tbl_client.id', '=', 'a.client_id')
->select(
'tbl_client.id',
'tbl_client.clinic_number',
Expand All @@ -283,7 +291,8 @@ public function clients_list()
'tbl_client.l_name',
'tbl_client.dob',
'tbl_client.created_at',
'tbl_client.smsenable',
DB::raw('CASE WHEN tbl_client.smsenable="Yes" THEN "Yes" WHEN a.client_id IS NOT NULL THEN
"Yes" ELSE "No" END as smsenable'),
DB::raw('DATE(tbl_client.enrollment_date) AS enrollment_date'),
DB::raw('DATE(tbl_client.art_date) AS art_date'),
'tbl_client.motivational_enable',
Expand Down
24 changes: 15 additions & 9 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,28 @@ public function consented_report()
}

if (Auth::user()->access_level == 'Facility') {
$consented_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id')
->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at', 'tbl_client.smsenable', 'tbl_client.enrollment_date', 'tbl_client.art_date', 'tbl_client.updated_at', 'tbl_client.status', 'tbl_client.consent_date')
->where('tbl_client.smsenable', '=', 'Yes')
->where('tbl_client.status', '=', 'Active')
$consented_clients = Client::leftJoin('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id')
->leftJoin(DB::raw('(SELECT client_id, DATE(created_at) AS created_at
FROM tbl_appointment a1
WHERE a1.id = (SELECT MAX(a2.id) FROM tbl_appointment a2 WHERE a2.client_id = a1.client_id)
AND a1.consented = "YES") a'), 'tbl_client.id', '=', 'a.client_id')
->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at', DB::raw('CASE WHEN tbl_client.smsenable="Yes" THEN "Yes" WHEN a.client_id IS NOT NULL THEN
"Yes" ELSE "No" END as smsenable'), 'tbl_client.enrollment_date', 'tbl_client.art_date', 'tbl_client.updated_at', 'tbl_client.status', 'tbl_client.consent_date')
->whereNull('tbl_client.hei_no')
->where('tbl_client.mfl_code', Auth::user()->facility_id)
->paginate(1000);
->paginate(15000);
}

if (Auth::user()->access_level == 'Partner') {
$all_partners = Partner::where('status', '=', 'Active')
->pluck('name', 'id');
$consented_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id')
->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at', 'tbl_client.smsenable', 'tbl_client.enrollment_date', 'tbl_client.art_date', 'tbl_client.updated_at', 'tbl_client.status', 'tbl_client.consent_date')
->where('tbl_client.smsenable', '=', 'Yes')
->where('tbl_client.status', '=', 'Active')
$consented_clients = Client::leftJoin('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id')
->leftJoin(DB::raw('(SELECT client_id, DATE(created_at) AS created_at
FROM tbl_appointment a1
WHERE a1.id = (SELECT MAX(a2.id) FROM tbl_appointment a2 WHERE a2.client_id = a1.client_id)
AND a1.consented = "YES") a'), 'tbl_client.id', '=', 'a.client_id')
->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at', DB::raw('CASE WHEN tbl_client.smsenable="Yes" THEN "Yes" WHEN a.client_id IS NOT NULL THEN
"Yes" ELSE "No" END as smsenable'), 'tbl_client.enrollment_date', 'tbl_client.art_date', 'tbl_client.updated_at', 'tbl_client.status', 'tbl_client.consent_date')
->whereNull('tbl_client.hei_no')
->where('tbl_client.partner_id', Auth::user()->partner_id)
->paginate(1000);
Expand Down

0 comments on commit 8f16062

Please sign in to comment.