Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 61 additions & 18 deletions PainTrackerPT/Controllers/Analytics/AnalyticsLogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,67 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using PainTrackerPT.Models;
using PainTrackerPT.Data.Analytics;
using PainTrackerPT.Models.Analytics;
using analyticsModel = PainTrackerPT.Models.Analytics.GFPatient;
using PainTrackerPT.Trends;
using PainTrackerPT.Trends.Aggregate;

namespace PainTrackerPT.Controllers
{
public class AnalyticsLogsController : Controller
{
private readonly PainTrackerPTContext _context;

public AnalyticsLogsController(PainTrackerPTContext context)
private readonly IGinyuGateway _gateway;
private readonly IGFPatientGateway _patientGateway;
private readonly IGFPatientMedicineIntakeGateway _patientMedicineIntakeGateway;

public AnalyticsLogsController(IGinyuGateway gateway, IGFPatientGateway _patient, IGFPatientMedicineIntakeGateway _medicineIntake)
{
_context = context;
_gateway = gateway;
_patientGateway = _patient;
_patientMedicineIntakeGateway = _medicineIntake;
}

public async Task<ActionResult> PatientTrend()
{
analyticsModel.PainDiary PainDiary = _patientGateway.SelectById(1);
List<analyticsModel.MedicineIntake> Mitl = _patientMedicineIntakeGateway.SelectAll();

//All trends related to PainDiary
IPatientTrend PainIntensityTrend = new PainIntensityTrend(PainDiary.PainIntensity);
IPatientTrend SleepTrend = new SleepTrend(PainDiary.Sleep);
IPatientTrend MoodTrend = new MoodTrend(PainDiary.Mood);
IPatientPatternTrend InterferenceTrend = new InterferenceTrend(PainDiary.Interference);

//Trends related to MedicineIntake
IPatientTrend MedicineIntakeTrend = new MedicineIntakeTrend(Mitl);

//Plot SuperImposed Graph in view
ViewBag.PainIntensityPlots = PainIntensityTrend.PlotGraph();
ViewBag.InterferencePlots = InterferenceTrend.PlotGraph();
ViewBag.MoodPlots = MoodTrend.PlotGraph();
ViewBag.SleepPlots = SleepTrend.PlotGraph();
ViewBag.MedicineIntakePlots = MedicineIntakeTrend.PlotGraph();


//Send PieChart data to frontend
ViewBag.PainAreaPie = PainIntensityTrend.PlotPie();
ViewBag.MoodDoughnut = MoodTrend.PlotPie();

//Send Pattern data to front end
ViewBag.InterferenceRows = InterferenceTrend.RetrievePattern();
ViewBag.SleepRows = SleepTrend.PlotPie();

return View();
}

// GET: AnalyticsLogs
public async Task<IActionResult> Index()
{
return View(await _context.AnalyticsLog.ToListAsync());
//Currently Retrieving a specific user information for testing
return View(_gateway.SelectAll());
//return View(_patientGateway.SelectById(1));
}

// GET: AnalyticsLogs/Details/5
Expand All @@ -33,8 +76,8 @@ public async Task<IActionResult> Details(Guid? id)
return NotFound();
}

var analyticsLog = await _context.AnalyticsLog
.FirstOrDefaultAsync(m => m.Id == id);
var analyticsLog = _gateway.Find(id);

if (analyticsLog == null)
{
return NotFound();
Expand All @@ -59,8 +102,9 @@ public async Task<IActionResult> Create([Bind("Id,Description,timeStamp")] Analy
if (ModelState.IsValid)
{
analyticsLog.Id = Guid.NewGuid();
_context.Add(analyticsLog);
await _context.SaveChangesAsync();

_gateway.Insert(analyticsLog);
_gateway.Save();
return RedirectToAction(nameof(Index));
}
return View(analyticsLog);
Expand All @@ -74,7 +118,7 @@ public async Task<IActionResult> Edit(Guid? id)
return NotFound();
}

var analyticsLog = await _context.AnalyticsLog.FindAsync(id);
var analyticsLog = _gateway.Find(id);
if (analyticsLog == null)
{
return NotFound();
Expand All @@ -98,8 +142,9 @@ public async Task<IActionResult> Edit(Guid id, [Bind("Id,Description,timeStamp")
{
try
{
_context.Update(analyticsLog);
await _context.SaveChangesAsync();
_gateway.Update(analyticsLog);
_gateway.Save();

}
catch (DbUpdateConcurrencyException)
{
Expand All @@ -125,8 +170,7 @@ public async Task<IActionResult> Delete(Guid? id)
return NotFound();
}

var analyticsLog = await _context.AnalyticsLog
.FirstOrDefaultAsync(m => m.Id == id);
var analyticsLog = _gateway.Find(id);
if (analyticsLog == null)
{
return NotFound();
Expand All @@ -140,15 +184,14 @@ public async Task<IActionResult> Delete(Guid? id)
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(Guid id)
{
var analyticsLog = await _context.AnalyticsLog.FindAsync(id);
_context.AnalyticsLog.Remove(analyticsLog);
await _context.SaveChangesAsync();
_gateway.Delete(id);
_gateway.Save();
return RedirectToAction(nameof(Index));
}

private bool AnalyticsLogExists(Guid id)
{
return _context.AnalyticsLog.Any(e => e.Id == id);
return _gateway.Exist(id);
}
}
}
89 changes: 89 additions & 0 deletions PainTrackerPT/Data/Analytics/GFPatientGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PainTrackerPT.Models;
using PainTrackerPT.Models.Analytics.GFPatient;

namespace PainTrackerPT.Data.Analytics
{
public class GFPatientGateway : IGFPatientGateway
{
private readonly PainTrackerPTContext _context;
public GFPatientGateway(PainTrackerPTContext context)
{
_context = context;
}

public PainDiary SelectById(int? id)
{
List<Interference> interferenceList = new List<Interference>();
List<Mood> moodList = new List<Mood>();
List<Sleep> sleepList = new List<Sleep>();
List<PainIntensity> painIntensityList = new List<PainIntensity>();

//retrieve painDiary based on patient id
PainDiary pain = _context.PainDiary.Find(id);

//retrieve all records tied to patient pain diaries
pain.Interference = retrieveInterferenceById(pain.PainDiaryID);
pain.Mood = retrieveMoodById(pain.PainDiaryID);
pain.Sleep = retrieveSleepById(pain.PainDiaryID);
pain.PainIntensity = retrievePainIntensityById(pain.PainDiaryID);

return pain;
}

public List<Interference> retrieveInterferenceById(int? id)
{
List<Interference> list = new List<Interference>();
foreach (Interference entry in _context.Interference)
{
if (entry.PainDiaryID == id)
{
list.Add(entry);
}
}
return list;
}

public List<Mood> retrieveMoodById(int? id)
{
List<Mood> list = new List<Mood>();
foreach (Mood entry in _context.Mood)
{
if (entry.PainDiaryID == id)
{
list.Add(entry);
}
}
return list;
}

public List<PainIntensity> retrievePainIntensityById(int? id)
{
List<PainIntensity> list = new List<PainIntensity>();
foreach (PainIntensity entry in _context.PainIntensity)
{
if (entry.PainDiaryID == id)
{
list.Add(entry);
}
}
return list;
}

public List<Sleep> retrieveSleepById(int? id)
{
List<Sleep> list = new List<Sleep>();
foreach (Sleep entry in _context.Sleep)
{
if (entry.PainDiaryID == id)
{
list.Add(entry);
}
}
return list;
}
}
}
27 changes: 27 additions & 0 deletions PainTrackerPT/Data/Analytics/GFPatientMedicineIntakeGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PainTrackerPT.Models;
using PainTrackerPT.Models.Analytics.GFPatient;

namespace PainTrackerPT.Data.Analytics
{
public class GFPatientMedicineIntakeGateway : IGFPatientMedicineIntakeGateway
{
private readonly PainTrackerPTContext _context;
public GFPatientMedicineIntakeGateway(PainTrackerPTContext context)
{
_context = context;
}

public List<MedicineIntake> SelectAll()
{
List<MedicineIntake> MedicineIntakeList = new List<MedicineIntake>();
//retrieve painDiary based on patient id
MedicineIntakeList = _context.MedicineIntake.ToList();
return MedicineIntakeList;

}
}
}
63 changes: 63 additions & 0 deletions PainTrackerPT/Data/Analytics/GinyuGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using PainTrackerPT.Models;
using PainTrackerPT.Models.Analytics;

namespace PainTrackerPT.Data.Analytics
{
public class GinyuGateway : IGinyuGateway
{
private readonly PainTrackerPTContext _context;

public GinyuGateway(PainTrackerPTContext context)
{
_context = context;
}

public IEnumerable<AnalyticsLog> SelectAll()
{
return _context.AnalyticsLog.ToList();
}

public AnalyticsLog SelectById(int? id)
{
return _context.AnalyticsLog.Find(id);
}

public AnalyticsLog Find(Guid? id)
{
return _context.AnalyticsLog.FirstOrDefault(m => m.Id == id);
}

public void Insert(AnalyticsLog analyticsLog)
{
_context.Add(analyticsLog);

}

public void Delete(Guid id)
{
AnalyticsLog analyticsLog = _context.AnalyticsLog.Find(id);
_context.AnalyticsLog.Remove(analyticsLog);
}

public void Update(AnalyticsLog analyticsLog)
{
_context.Update(analyticsLog);
}

public void Save()
{
_context.SaveChangesAsync();
}

public bool Exist(Guid? id)
{
return _context.AnalyticsLog.Any(e => e.Id == id);

}
}
}
18 changes: 18 additions & 0 deletions PainTrackerPT/Data/Analytics/IGFPatientGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using PainTrackerPT.Models.Analytics.GFPatient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PainTrackerPT.Data.Analytics
{
public interface IGFPatientGateway
{
PainDiary SelectById(int? id);
List<Interference> retrieveInterferenceById(int? id);
List<Mood> retrieveMoodById(int? id);
List<Sleep> retrieveSleepById(int? id);
List<PainIntensity> retrievePainIntensityById(int? id);

}
}
13 changes: 13 additions & 0 deletions PainTrackerPT/Data/Analytics/IGFPatientMedicineIntakeGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PainTrackerPT.Models.Analytics.GFPatient;

namespace PainTrackerPT.Data.Analytics
{
public interface IGFPatientMedicineIntakeGateway
{
List<MedicineIntake> SelectAll();
}
}
23 changes: 23 additions & 0 deletions PainTrackerPT/Data/Analytics/IGinyuGateway.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using PainTrackerPT.Models.Analytics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PainTrackerPT.Data.Analytics
{
public interface IGinyuGateway
{
//implement CRUD for Logger
IEnumerable<AnalyticsLog> SelectAll();
AnalyticsLog SelectById(int? id);
AnalyticsLog Find(Guid? id);
Boolean Exist(Guid? id);

void Update(AnalyticsLog analyticsLog);
void Delete(Guid id);
void Insert(AnalyticsLog analyticsLog);

void Save();
}
}
8 changes: 8 additions & 0 deletions PainTrackerPT/Data/PainTrackerPTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public PainTrackerPTContext (DbContextOptions<PainTrackerPTContext> options)
{
}

//Ginyu Force Analytics
public DbSet<PainTrackerPT.Models.Analytics.GFPatient.PainDiary> PainDiary { get; set; }
public DbSet<PainTrackerPT.Models.Analytics.GFPatient.Interference> Interference { get; set; }
public DbSet<PainTrackerPT.Models.Analytics.GFPatient.Mood> Mood { get; set; }
public DbSet<PainTrackerPT.Models.Analytics.GFPatient.PainIntensity> PainIntensity { get; set; }
public DbSet<PainTrackerPT.Models.Analytics.GFPatient.Sleep> Sleep { get; set; }
public DbSet<PainTrackerPT.Models.Analytics.GFPatient.MedicineIntake> MedicineIntake { get; set; }

public DbSet<PainTrackerPT.Models.Analytics.AnalyticsLog> AnalyticsLog { get; set; }

public DbSet<PainTrackerPT.Models.Doctors.DoctorsLog> DoctorsLog { get; set; }
Expand Down
Loading