modify dashboard and services fetch source data
This commit is contained in:
@@ -575,6 +575,33 @@ class DashboardService
|
||||
*/
|
||||
public function provinceCircles($startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
|
||||
return SurveillanceCase::join('case_lab_results', function ($join) {
|
||||
$join->on('surveillance_cases.lab_code', '=', 'case_lab_results.lab_code')
|
||||
->on('surveillance_cases.surveillance_id', '=', 'case_lab_results.surveillance_id');
|
||||
})
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw(
|
||||
"(surveillance_cases.year_data * 100 + surveillance_cases.week_data) BETWEEN ? AND ?",
|
||||
[
|
||||
$startYear * 100 + $startWeek,
|
||||
$endYear * 100 + $endWeek
|
||||
]
|
||||
);
|
||||
})
|
||||
->whereRaw('case_lab_results.is_positive = 1 and surveillance_cases.surveillance_id not in(6) and case_lab_results.indicator="Influenza"')
|
||||
->selectRaw("
|
||||
surveillance_cases.patient_province,
|
||||
case_lab_results.subtype as pathogen_name,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
")
|
||||
->groupBy(
|
||||
'surveillance_cases.patient_province',
|
||||
'case_lab_results.subtype'
|
||||
)
|
||||
->get();
|
||||
|
||||
|
||||
return SurveillanceCase::leftJoin(
|
||||
'case_lab_results',
|
||||
'surveillance_cases.lab_code',
|
||||
@@ -590,28 +617,156 @@ class DashboardService
|
||||
->whereRaw(
|
||||
"(surveillance_cases.year_data < ? OR (surveillance_cases.year_data = ? AND surveillance_cases.week_data <= ?))",
|
||||
[$endYear, $endYear, $endWeek]
|
||||
);
|
||||
)
|
||||
->whereRaw('case_lab_results.is_positive = 1 and surveillance_cases.surveillance_id not in(6)');
|
||||
})
|
||||
|
||||
->selectRaw("
|
||||
surveillance_cases.patient_province,
|
||||
surveillance_cases.surveillance_id,
|
||||
case_lab_results.pathogen_name,
|
||||
|
||||
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 surveillance_cases.lab_code) as total
|
||||
")
|
||||
|
||||
->groupBy(
|
||||
'surveillance_cases.patient_province',
|
||||
'surveillance_cases.surveillance_id'
|
||||
'case_lab_results.pathogen_name'
|
||||
)
|
||||
|
||||
->get();
|
||||
}
|
||||
|
||||
/* Start Overview Section */
|
||||
|
||||
public function influenzaSubtypeDetected($startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::join('case_lab_results', function ($join) {
|
||||
$join->on('surveillance_cases.lab_code', '=', 'case_lab_results.lab_code')
|
||||
->on('surveillance_cases.surveillance_id', '=', 'case_lab_results.surveillance_id');
|
||||
})
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw(
|
||||
"(surveillance_cases.year_data * 100 + surveillance_cases.week_data) BETWEEN ? AND ?",
|
||||
[
|
||||
$startYear * 100 + $startWeek,
|
||||
$endYear * 100 + $endWeek
|
||||
]
|
||||
);
|
||||
})
|
||||
->whereRaw('case_lab_results.is_positive = 1 and surveillance_cases.surveillance_id not in(6) and case_lab_results.indicator="Influenza"')
|
||||
->selectRaw("
|
||||
case_lab_results.subtype,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
")
|
||||
->groupBy(
|
||||
'case_lab_results.subtype'
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function covidDistributedByAgeGroup($startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::join('case_lab_results', function ($join) {
|
||||
$join->on('surveillance_cases.lab_code', '=', 'case_lab_results.lab_code')
|
||||
->on('surveillance_cases.surveillance_id', '=', 'case_lab_results.surveillance_id');
|
||||
})
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw(
|
||||
"(surveillance_cases.year_data * 100 + surveillance_cases.week_data) BETWEEN ? AND ?",
|
||||
[
|
||||
$startYear * 100 + $startWeek,
|
||||
$endYear * 100 + $endWeek
|
||||
]
|
||||
);
|
||||
})
|
||||
->whereRaw('case_lab_results.is_positive = 1 and surveillance_cases.surveillance_id not in(6) and case_lab_results.indicator="Covid-19"')
|
||||
->selectRaw("
|
||||
CASE
|
||||
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
|
||||
")
|
||||
->groupBy('age_group', 'age_order')
|
||||
->orderBy('age_order')
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
public function covidLineageRelativeOverTime($startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::join('case_lab_results', function ($join) {
|
||||
$join->on('surveillance_cases.lab_code', '=', 'case_lab_results.lab_code')
|
||||
->on('surveillance_cases.surveillance_id', '=', 'case_lab_results.surveillance_id');
|
||||
})
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw(
|
||||
"(surveillance_cases.year_data * 100 + surveillance_cases.week_data) BETWEEN ? AND ?",
|
||||
[
|
||||
$startYear * 100 + $startWeek,
|
||||
$endYear * 100 + $endWeek
|
||||
]
|
||||
);
|
||||
})
|
||||
->whereRaw('case_lab_results.is_positive = 1 and surveillance_cases.surveillance_id=6 and case_lab_results.indicator="Covid-19" and case_lab_results.pathogen_name not in("","unable to align","N/A","NA")')
|
||||
->selectRaw("
|
||||
case_lab_results.pathogen_name as lineage,
|
||||
concat(surveillance_cases.year_data,'-',surveillance_cases.week_data) as week,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
")
|
||||
->groupBy(
|
||||
'case_lab_results.pathogen_name',
|
||||
'week'
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function influenzaRelativeOverTime($startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::join('case_lab_results', function ($join) {
|
||||
$join->on('surveillance_cases.lab_code', '=', 'case_lab_results.lab_code')
|
||||
->on('surveillance_cases.surveillance_id', '=', 'case_lab_results.surveillance_id');
|
||||
})
|
||||
->where(function ($q) use ($startYear, $startWeek, $endYear, $endWeek) {
|
||||
$q->whereRaw(
|
||||
"(surveillance_cases.year_data * 100 + surveillance_cases.week_data) BETWEEN ? AND ?",
|
||||
[
|
||||
$startYear * 100 + $startWeek,
|
||||
$endYear * 100 + $endWeek
|
||||
]
|
||||
);
|
||||
})
|
||||
->whereRaw('case_lab_results.is_positive = 1 and surveillance_cases.surveillance_id not in(6) and case_lab_results.indicator="Influenza"')
|
||||
->selectRaw("
|
||||
case_lab_results.subtype as lineage,
|
||||
concat(surveillance_cases.year_data,'-',surveillance_cases.week_data) as week,
|
||||
COUNT(DISTINCT surveillance_cases.lab_code) as total
|
||||
")
|
||||
->groupBy(
|
||||
'case_lab_results.subtype',
|
||||
'week'
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
||||
/* End Overview Section */
|
||||
|
||||
public function provinceProgram($surveillanceId, $startYear, $startWeek, $endYear, $endWeek)
|
||||
{
|
||||
return SurveillanceCase::selectRaw("
|
||||
@@ -699,7 +854,7 @@ class DashboardService
|
||||
|
||||
->selectRaw("
|
||||
CASE
|
||||
WHEN LOWER(case_lab_results.pathogen_name) LIKE '%influenza%'
|
||||
WHEN LOWER(case_lab_results.pathogen_name) LIKE '%influenza%'
|
||||
THEN 'Influenza'
|
||||
ELSE case_lab_results.pathogen_name
|
||||
END as pathogen,
|
||||
@@ -740,7 +895,7 @@ class DashboardService
|
||||
|
||||
->where('case_lab_results.subtype', '!=', 'Positive')
|
||||
|
||||
->groupBy('subtype')
|
||||
->groupBy('subtype')
|
||||
->orderByDesc('total')
|
||||
->get();
|
||||
|
||||
@@ -874,4 +1029,4 @@ class DashboardService
|
||||
->orderBy('period')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user