finalize detail page except NDS and squencing
This commit is contained in:
@@ -50,12 +50,7 @@ class DashboardController extends Controller
|
||||
|
||||
public function summary()
|
||||
{
|
||||
$dateFrom = Carbon::now()->subDays(7)->toDateString();
|
||||
$dateTo = Carbon::now()->toDateString();
|
||||
|
||||
$data = $this->service->summaryCards($dateFrom, $dateTo);
|
||||
|
||||
return response()->json($data);
|
||||
return response()->json($this->service->summaryCards());
|
||||
}
|
||||
|
||||
|
||||
@@ -148,21 +143,22 @@ class DashboardController extends Controller
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function sentinelMap(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
// public function sentinelMap(Request $request)
|
||||
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
// {
|
||||
// $range = $this->getEpiRange($request);
|
||||
|
||||
$data = $this->service->sentinelMap(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
// if (!$range) {
|
||||
// return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
// }
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
// $data = $this->service->sentinelSites(
|
||||
// $range['startYear'],
|
||||
// $range['startWeek'],
|
||||
// $range['endYear'],
|
||||
// $range['endWeek']
|
||||
// );
|
||||
|
||||
// return response()->json($data);
|
||||
// }
|
||||
}
|
||||
@@ -25,27 +25,32 @@ class DashboardService
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function summaryCards($dateFrom, $dateTo)
|
||||
public function summaryCards()
|
||||
{
|
||||
$programs = Surveillance::orderBy('id')->get();
|
||||
$results = [];
|
||||
|
||||
$today = date('Y-m-d');
|
||||
|
||||
$currentFrom = date('Y-m-d', strtotime('-6 days'));
|
||||
$currentTo = $today;
|
||||
|
||||
$prevFrom = date('Y-m-d', strtotime('-13 days'));
|
||||
$prevTo = date('Y-m-d', strtotime('-7 days'));
|
||||
|
||||
foreach ($programs as $program) {
|
||||
|
||||
$current = SurveillanceCase::where('surveillance_id', $program->id)
|
||||
->whereBetween('case_date', [$dateFrom, $dateTo])
|
||||
->whereBetween('case_date', [$currentFrom, $currentTo])
|
||||
->count();
|
||||
|
||||
$previous = SurveillanceCase::where('surveillance_id', $program->id)
|
||||
->whereBetween('case_date', [
|
||||
date('Y-m-d', strtotime($dateFrom . ' -7 days')),
|
||||
date('Y-m-d', strtotime($dateFrom . ' -1 day'))
|
||||
])
|
||||
->whereBetween('case_date', [$prevFrom, $prevTo])
|
||||
->count();
|
||||
|
||||
$percentChange = $previous > 0
|
||||
? round((($current - $previous) / $previous) * 100, 1)
|
||||
: 0;
|
||||
: ($current > 0 ? 100 : 0);
|
||||
|
||||
$results[] = [
|
||||
'surveillance_id' => $program->id,
|
||||
@@ -59,7 +64,6 @@ class DashboardService
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Fast SARI Summary (single query)
|
||||
@@ -80,31 +84,31 @@ class DashboardService
|
||||
->where('surveillance_cases.week_data', $week)
|
||||
|
||||
->selectRaw("
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total_cases,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total_cases,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as overall_positive,
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as overall_positive,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
AND (
|
||||
LOWER(case_lab_results.pathogen_name) LIKE '%influenza%'
|
||||
OR LOWER(case_lab_results.pathogen_name) LIKE '%influzena%'
|
||||
)
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as influenza_positive,
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
AND (
|
||||
LOWER(case_lab_results.pathogen_name) LIKE '%influenza%'
|
||||
OR LOWER(case_lab_results.pathogen_name) LIKE '%influzena%'
|
||||
)
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as influenza_positive,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
AND (
|
||||
LOWER(case_lab_results.pathogen_name) LIKE '%covid%'
|
||||
OR LOWER(case_lab_results.pathogen_name) LIKE '%sars%'
|
||||
)
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as covid_positive
|
||||
")
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
AND (
|
||||
LOWER(case_lab_results.pathogen_name) LIKE '%covid%'
|
||||
OR LOWER(case_lab_results.pathogen_name) LIKE '%sars%'
|
||||
)
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as covid_positive
|
||||
")
|
||||
|
||||
->first();
|
||||
|
||||
@@ -136,7 +140,51 @@ class DashboardService
|
||||
| Program Summary
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public function afiTrend($surveillanceId, $startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return CaseLabResult::join(
|
||||
'surveillance_cases',
|
||||
'case_lab_results.lab_code',
|
||||
'=',
|
||||
'surveillance_cases.lab_code'
|
||||
)
|
||||
|
||||
->where('surveillance_cases.surveillance_id', $surveillanceId)
|
||||
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw("(year_data > ? OR (year_data = ? AND week_data >= ?))", [$startYear, $startYear, $startWeek])
|
||||
->whereRaw("(year_data < ? OR (year_data = ? AND week_data <= ?))", [$endYear, $endYear, $endWeek]);
|
||||
})
|
||||
|
||||
->where('case_lab_results.is_positive', 1)
|
||||
|
||||
->whereNotNull('case_lab_results.pathogen_name')
|
||||
->where('case_lab_results.pathogen_name', '!=', '')
|
||||
->where('case_lab_results.pathogen_name', '!=', 'Positive')
|
||||
|
||||
->selectRaw("
|
||||
surveillance_cases.year_data as year,
|
||||
surveillance_cases.week_data as period,
|
||||
|
||||
CASE
|
||||
WHEN LOWER(case_lab_results.pathogen_name) LIKE '%influenza%' THEN 'Influenza'
|
||||
ELSE case_lab_results.pathogen_name
|
||||
END as pathogen,
|
||||
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
")
|
||||
|
||||
->groupBy(
|
||||
'surveillance_cases.year_data',
|
||||
'surveillance_cases.week_data',
|
||||
'pathogen'
|
||||
)
|
||||
|
||||
->orderBy('surveillance_cases.year_data')
|
||||
->orderBy('surveillance_cases.week_data')
|
||||
|
||||
->get();
|
||||
}
|
||||
public function programSummary($surveillanceId, $startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
|
||||
@@ -308,6 +356,13 @@ class DashboardService
|
||||
$endYear,
|
||||
$endWeek
|
||||
),
|
||||
'afi_trend' => $this->afiTrend(
|
||||
$surveillanceId,
|
||||
$startYear,
|
||||
$startWeek,
|
||||
$endYear,
|
||||
$endWeek
|
||||
),
|
||||
|
||||
'province_distribution' => $this->provinceProgram(
|
||||
$surveillanceId,
|
||||
@@ -520,22 +575,55 @@ class DashboardService
|
||||
*/
|
||||
public function provinceCircles($startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::selectRaw(" surveillance_cases.site_province_name, surveillance_cases.surveillance_id, COUNT(*) as total ")->join('case_lab_results', 'surveillance_cases.lab_code', '=', 'case_lab_results.lab_code')->where('case_lab_results.is_positive', 1)->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw("(surveillance_cases.year_data > ? OR (surveillance_cases.year_data = ? AND surveillance_cases.week_data >= ?))", [$startYear, $startYear, $startWeek])->whereRaw("(surveillance_cases.year_data < ? OR (surveillance_cases.year_data = ? AND surveillance_cases.week_data <= ?))", [$endYear, $endYear, $endWeek]);
|
||||
})->groupBy('surveillance_cases.site_province_name', 'surveillance_cases.surveillance_id')->get();
|
||||
return SurveillanceCase::leftJoin(
|
||||
'case_lab_results',
|
||||
'surveillance_cases.lab_code',
|
||||
'=',
|
||||
'case_lab_results.lab_code'
|
||||
)
|
||||
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw(
|
||||
"(surveillance_cases.year_data > ? OR (surveillance_cases.year_data = ? AND surveillance_cases.week_data >= ?))",
|
||||
[$startYear, $startYear, $startWeek]
|
||||
)
|
||||
->whereRaw(
|
||||
"(surveillance_cases.year_data < ? OR (surveillance_cases.year_data = ? AND surveillance_cases.week_data <= ?))",
|
||||
[$endYear, $endYear, $endWeek]
|
||||
);
|
||||
})
|
||||
|
||||
->selectRaw("
|
||||
surveillance_cases.patient_province,
|
||||
surveillance_cases.surveillance_id,
|
||||
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as positive
|
||||
")
|
||||
|
||||
->groupBy(
|
||||
'surveillance_cases.patient_province',
|
||||
'surveillance_cases.surveillance_id'
|
||||
)
|
||||
|
||||
->get();
|
||||
}
|
||||
public function provinceProgram($surveillanceId, $startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::selectRaw("
|
||||
surveillance_cases.site_province_name,
|
||||
surveillance_cases.patient_province,
|
||||
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as positive
|
||||
")
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN case_lab_results.is_positive = 1
|
||||
THEN surveillance_cases.lab_code
|
||||
END) as positive
|
||||
")
|
||||
|
||||
->join(
|
||||
'case_lab_results',
|
||||
@@ -560,7 +648,7 @@ class DashboardService
|
||||
|
||||
})
|
||||
|
||||
->groupBy('surveillance_cases.site_province_name')
|
||||
->groupBy('surveillance_cases.patient_province')
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -583,7 +671,7 @@ class DashboardService
|
||||
})
|
||||
|
||||
->groupBy('sentinel_site_name')
|
||||
->orderByDesc('total') // nice for chart
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
}
|
||||
|
||||
@@ -597,16 +685,13 @@ class DashboardService
|
||||
{
|
||||
$total = $this->totalTested($surveillanceId, $startYear, $startWeek, $endYear, $endWeek);
|
||||
|
||||
$rows = CaseLabResult::join(
|
||||
'surveillance_cases',
|
||||
'case_lab_results.lab_code',
|
||||
'=',
|
||||
'surveillance_cases.lab_code'
|
||||
)
|
||||
->where('surveillance_cases.surveillance_id', $surveillanceId)
|
||||
$rows = CaseLabResult::where('case_lab_results.surveillance_id', $surveillanceId)
|
||||
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw("(year_data > ? OR (year_data = ? AND week_data >= ?))", [$startYear, $startYear, $startWeek])
|
||||
->whereIn('lab_code', function ($q) use ($surveillanceId, $startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->select('lab_code')
|
||||
->from('surveillance_cases')
|
||||
->where('surveillance_id', $surveillanceId)
|
||||
->whereRaw("(year_data > ? OR (year_data = ? AND week_data >= ?))", [$startYear, $startYear, $startWeek])
|
||||
->whereRaw("(year_data < ? OR (year_data = ? AND week_data <= ?))", [$endYear, $endYear, $endWeek]);
|
||||
})
|
||||
|
||||
@@ -614,18 +699,12 @@ class DashboardService
|
||||
|
||||
->selectRaw("
|
||||
CASE
|
||||
WHEN LOWER(case_lab_results.pathogen_name) LIKE '%influenza%'
|
||||
OR LOWER(case_lab_results.pathogen_name) LIKE '%influzena%'
|
||||
WHEN LOWER(case_lab_results.pathogen_name) LIKE '%influenza%'
|
||||
THEN 'Influenza'
|
||||
|
||||
WHEN case_lab_results.pathogen_name = 'Positive'
|
||||
AND case_lab_results.indicator LIKE '%Covid%'
|
||||
THEN 'SARS-CoV-2'
|
||||
|
||||
ELSE case_lab_results.pathogen_name
|
||||
END as pathogen,
|
||||
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
COUNT(DISTINCT case_lab_results.lab_code) as total
|
||||
")
|
||||
|
||||
->groupBy('pathogen')
|
||||
@@ -642,29 +721,36 @@ class DashboardService
|
||||
{
|
||||
$total = $this->totalTested($surveillanceId, $startYear, $startWeek, $endYear, $endWeek);
|
||||
|
||||
$rows = CaseLabResult::join(
|
||||
'surveillance_cases',
|
||||
'case_lab_results.lab_code',
|
||||
'=',
|
||||
'surveillance_cases.lab_code'
|
||||
)
|
||||
->where('surveillance_cases.surveillance_id', $surveillanceId)
|
||||
->where('case_lab_results.is_positive', 1)
|
||||
$rows = CaseLabResult::where('case_lab_results.surveillance_id', $surveillanceId)
|
||||
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw("(year_data > ? OR (year_data = ? AND week_data >= ?))", [$startYear, $startYear, $startWeek])
|
||||
->whereRaw("(year_data < ? OR (year_data = ? AND week_data <= ?))", [$endYear, $endYear, $endWeek]);
|
||||
->whereIn('case_lab_results.lab_code', function ($q) use ($surveillanceId, $startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->select('lab_code')
|
||||
->from('surveillance_cases')
|
||||
->where('surveillance_id', $surveillanceId)
|
||||
->whereRaw(
|
||||
"(year_data > ? OR (year_data = ? AND week_data >= ?))",
|
||||
[$startYear, $startYear, $startWeek]
|
||||
)
|
||||
->whereRaw(
|
||||
"(year_data < ? OR (year_data = ? AND week_data <= ?))",
|
||||
[$endYear, $endYear, $endWeek]
|
||||
);
|
||||
})
|
||||
|
||||
->where('case_lab_results.is_positive', 1)
|
||||
|
||||
->selectRaw("
|
||||
subtype,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
case_lab_results.subtype,
|
||||
COUNT(DISTINCT case_lab_results.lab_code) as total
|
||||
")
|
||||
|
||||
->groupBy('subtype')
|
||||
->havingRaw("subtype IS NOT NULL AND subtype != 'Positive' AND subtype != ''")
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
->whereNotNull('case_lab_results.subtype')
|
||||
->where('case_lab_results.subtype', '!=', '')
|
||||
->where('case_lab_results.subtype', '!=', 'Positive')
|
||||
|
||||
->groupBy('case_lab_results.subtype')
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
|
||||
return $rows->map(function ($r) use ($total) {
|
||||
$r->rate = $total > 0 ? round(($r->total / $total) * 100, 1) : 0;
|
||||
@@ -672,7 +758,6 @@ class DashboardService
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Age Distribution
|
||||
@@ -681,18 +766,31 @@ class DashboardService
|
||||
|
||||
public function ageDistribution($surveillanceId, $startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
|
||||
return SurveillanceCase::selectRaw("
|
||||
CASE
|
||||
WHEN patient_age_inday < 365 THEN '<1 year'
|
||||
WHEN patient_age_inday < 1825 THEN '1–4 years'
|
||||
WHEN patient_age_inday < 6570 THEN '5–17 years'
|
||||
WHEN patient_age_inday < 16425 THEN '18–44 years'
|
||||
WHEN patient_age_inday < 23725 THEN '45–64 years'
|
||||
WHEN patient_age_inday <= 28 THEN '0–28 days'
|
||||
WHEN patient_age_inday <= 364 THEN '29 days–11 months'
|
||||
WHEN patient_age_inday <= 1460 THEN '1–4 years'
|
||||
WHEN patient_age_inday <= 5110 THEN '5–14 years'
|
||||
WHEN patient_age_inday <= 8765 THEN '15–24 years'
|
||||
WHEN patient_age_inday <= 18250 THEN '25–49 years'
|
||||
WHEN patient_age_inday <= 23725 THEN '50–64 years'
|
||||
ELSE '65+ years'
|
||||
END as age_group,
|
||||
|
||||
CASE
|
||||
WHEN patient_age_inday <= 28 THEN 1
|
||||
WHEN patient_age_inday <= 364 THEN 2
|
||||
WHEN patient_age_inday <= 1460 THEN 3
|
||||
WHEN patient_age_inday <= 5110 THEN 4
|
||||
WHEN patient_age_inday <= 8765 THEN 5
|
||||
WHEN patient_age_inday <= 18250 THEN 6
|
||||
WHEN patient_age_inday <= 23725 THEN 7
|
||||
ELSE 8
|
||||
END as age_order,
|
||||
|
||||
COUNT(*) as total
|
||||
")
|
||||
")
|
||||
|
||||
->where('surveillance_id', $surveillanceId)
|
||||
|
||||
@@ -702,7 +800,6 @@ class DashboardService
|
||||
"(year_data > ? OR (year_data = ? AND week_data >= ?))",
|
||||
[$startYear, $startYear, $startWeek]
|
||||
)
|
||||
|
||||
->whereRaw(
|
||||
"(year_data < ? OR (year_data = ? AND week_data <= ?))",
|
||||
[$endYear, $endYear, $endWeek]
|
||||
@@ -710,13 +807,11 @@ class DashboardService
|
||||
|
||||
})
|
||||
|
||||
->groupBy('age_group')
|
||||
->groupBy('age_group', 'age_order')
|
||||
->orderBy('age_order')
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sex Distribution
|
||||
|
||||
Reference in New Issue
Block a user