Skip to content
Permalink
Browse files

Created API and updated frontend to use the API for retrieving number…

… of case reports per health risk per week
  • Loading branch information...
karolikl committed Apr 14, 2019
1 parent 4bc6a22 commit e711638067be5083c52049d7da411db7be232acb
@@ -29,11 +29,9 @@
<link href="css/theme.css" rel="stylesheet" media="all">
<link href="css/Epicurvebyday.css" rel="stylesheet" media="all">
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

</head>

@@ -239,10 +237,8 @@
<div class="au-card-inner">
<table class="table">
<thead class="thead-light">
<tr>
<tr><th>SEX</th>
<th>NO CASE REPORTS</th></tr>
</tr>
</thead>
<tbody>
<tr><td>FEMALE</td><td id="male"></td></tr>
@@ -268,15 +264,12 @@
<div class="col-lg-6">
<table class="table " width="30%">
<thead class="thead-light">
<tr>
<tr><th>AGE</th>
<th>NO CASE REPORTS</th></tr>

</tr>
</thead>
<tbody>
<tr><td>>5</td><td id="under5"></td></tr>
<tr><td> < 5 </td><td id="over5"></td></tr>
<tr><td> &lt;5 </td><td id="over5"></td></tr>
</tbody>
</table>
<div></div>
@@ -310,6 +303,7 @@
<!-- END MAIN CONTENT-->
<!-- END PAGE CONTAINER-->
</div>
</div>



@@ -1,3 +1,4 @@
using Read.HealthRisks;
using Read.Models.CaseReports;
using System;
using System.Collections.Generic;
@@ -30,5 +31,28 @@ public CaseReportTotals GetCaseReportTotals(DateTimeOffset from, DateTimeOffset

return caseReportTotals;
}

public List<CaseReportTotalsPerHealthRisk> GetCaseReportTotalsPerHealthRisk(int numberOfWeeks)
{
var today = DateTimeOffset.Now;
var days = numberOfWeeks * 7;
var healthRisks = _mongoDBHandler.GetQueryable<HealthRisk>().ToList();
var totalsList = new List<CaseReportTotalsPerHealthRisk>();

foreach (var healthRisk in healthRisks)
{
var total = new CaseReportTotalsPerHealthRisk(healthRisk.Name);

for (int i = 0; i < numberOfWeeks; i++){
var endDate = today.AddDays(i*-7);
var startDate = endDate.AddDays(-6);
var numberOfReportsThisWeek = healthRisk.ReportsPerDay.Where(x => x.Key >= startDate && x.Key <= endDate).Sum(x => x.Value);

total.ReportsPerWeek.Add(new ReportsPerWeek { Week = i, NumberOfReports = numberOfReportsThisWeek });
}
totalsList.Add(total);
}
return totalsList;
}
}
}
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace Read.Models.CaseReports
{
public class CaseReportTotalsPerHealthRisk
{
public string Name { get; }

public List<ReportsPerWeek> ReportsPerWeek { get; set;}

public CaseReportTotalsPerHealthRisk(string name)
{
Name = name;
ReportsPerWeek = new List<ReportsPerWeek>();
}
}
}
@@ -0,0 +1,8 @@
namespace Read.Models.CaseReports
{
public class ReportsPerWeek
{
public int Week { get; set; }
public int NumberOfReports { get; set; }
}
}
@@ -30,7 +30,7 @@ class NationalSocietyOverview extends Component {

let oneWeekBack = new Date();
oneWeekBack.setDate(oneWeekBack.getDate()-6);
this.url = `${BASE_URL}CaseReport/${formatDate(oneWeekBack)}/${formatDate(new Date())}/`;
this.url = `${BASE_URL}CaseReport/Totals/${formatDate(oneWeekBack)}/${formatDate(new Date())}/`;

this.setState({ isLoading: true });

@@ -6,6 +6,7 @@ import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';
import Paper from '@material-ui/core/Paper';
import { getJson } from "../../utils/request";
import { BASE_URL } from "../NationalSocietyOverview";

class CaseReportByHealthRiskTable extends Component {
constructor(props) {
@@ -19,15 +20,14 @@ class CaseReportByHealthRiskTable extends Component {
}

fetchData() {
this.url = 'http://5cb05d0af7850e0014629bce.mockapi.io/api/HealthRisksLast4Weeks';
//this.url = `${BASE_URL}KPI/${formatDate(from)}/${formatDate(to)}/`;
this.url = `${BASE_URL}CaseReport/TotalsPerHealthRisk/4/`;

this.setState({ isLoading: true });

getJson(this.url)
.then(json =>
this.setState({
healthRisks: json.healthRisks,
healthRisks: json,
isLoading: false,
isError: false
})
@@ -63,8 +63,8 @@ class CaseReportByHealthRiskTable extends Component {
<TableCell component="th" scope="row">
{healthRisk.name}
</TableCell>
{healthRisk.timeSeries.map(time => (
<TableCell key={time.name} align="right">{time.numberOfCaseReports}</TableCell>
{healthRisk.reportsPerWeek.map(reports => (
<TableCell key={reports.week} align="right">{reports.numberOfReports}</TableCell>
))}
</TableRow>
))}
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Read.CaseReports;
using Read.Models.CaseReports;
@@ -15,10 +16,16 @@ public CaseReportController(CaseReportRepository caseReportRepository)
_caseReportRepository = caseReportRepository;
}

[HttpGet("{from}/{to}", Name = "GetCaseReportTotals")]
[HttpGet("Totals/{from}/{to}", Name = "GetCaseReportTotals")]
public ActionResult<CaseReportTotals> GetCaseReportTotals(DateTimeOffset from, DateTimeOffset to)
{
return _caseReportRepository.GetCaseReportTotals(from, to);
}

[HttpGet("TotalsPerHealthRisk/{numberOfWeeks}", Name = "GetCaseReportTotalsPerHealthRisk")]
public ActionResult<List<CaseReportTotalsPerHealthRisk>> GetCaseReportTotalsPerHealthRisk(int numberOfWeeks)
{
return _caseReportRepository.GetCaseReportTotalsPerHealthRisk(numberOfWeeks);
}
}
}

0 comments on commit e711638

Please sign in to comment.
You can’t perform that action at this time.