-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get patient dashboard connected to DB and update address functionalit…
…y working
- Loading branch information
Matthew
committed
Nov 14, 2024
1 parent
e84be23
commit 4b5b149
Showing
13 changed files
with
269 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using SecureDesignProject.Extensions; | ||
using SecureDesignProject.Models; | ||
using SecureDesignProject.Services; | ||
|
||
namespace SecureDesignProject.Controllers; | ||
|
||
public class DashboardController : Controller | ||
public class DashboardController(PatientService patientService) : Controller | ||
{ | ||
public IActionResult Patient() | ||
{ | ||
var model = new PatientInfo | ||
var patient = patientService.GetPatientInfoByAccountId(HttpContext.GetAccountId()); | ||
|
||
if (patient == null) return RedirectToAction("Error", "Home"); | ||
|
||
|
||
return View(patient); | ||
} | ||
|
||
public IActionResult UpdateAddress() | ||
{ | ||
var address = patientService.GetAddressByAccountId(HttpContext.GetAccountId()); | ||
return View(address); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult UpdateAddress(Address address) | ||
{ | ||
var success = patientService.AttemptUpdateAddress(HttpContext.GetAccountId(), address); | ||
|
||
if (!success) | ||
{ | ||
AssignedCaregivers = ["Dr Steve London", "Dr Bruce Potter"], | ||
PatientName = "John Doe", | ||
Address = "123 Main Street\nLondon\nEC5 8BC", | ||
Appointments = [ | ||
new AppointmentInfo | ||
{ | ||
Caregiver = "Dr Steve London", | ||
Patient = "John Doe", | ||
AppointmentTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm"), | ||
AppointmentDuration = "30", | ||
Notes = "Notes for Dr Steve London. And Dr Bruce Potter is the same time as the day. ALSO IT is the same time as the day. The day is the same time as the day. This is very strange auto complete." | ||
} | ||
] | ||
}; | ||
TempData["errorMsg"] = "Failed to update address."; | ||
return View(address); | ||
} | ||
|
||
return View(model); | ||
return RedirectToAction("Patient"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using SecureDesignProject.Models; | ||
|
||
namespace SecureDesignProject.Services; | ||
|
||
public class PatientService(DatabaseService dbService) | ||
{ | ||
public PatientInfo? GetPatientInfoByAccountId(Guid accountId) | ||
{ | ||
var patient = dbService.GetPatientByAccountId(accountId); | ||
if (patient == null) return null; | ||
|
||
var caregivers = dbService | ||
.GetCaregiversByAssignedPatient(patient.PatientId) | ||
.Select(x => x.FirstName + " " + x.LastName) | ||
.ToArray(); | ||
|
||
|
||
var splitAddress = patient.Address?.Split('\n'); | ||
|
||
return new PatientInfo | ||
{ | ||
PatientName = patient.FirstName + " " + patient.LastName, | ||
Address = splitAddress != null ? | ||
new Address | ||
{ | ||
Line1 = splitAddress[0], | ||
Line2 = splitAddress[1], | ||
City = splitAddress[2], | ||
Postcode = splitAddress[3], | ||
} : null, | ||
AssignedCaregivers = caregivers, | ||
Appointments = [] //TODO: implement appointments | ||
}; | ||
} | ||
|
||
public Address? GetAddressByAccountId(Guid accountId) | ||
{ | ||
var patient = dbService.GetPatientByAccountId(accountId); | ||
|
||
if (patient == null) return null; | ||
|
||
var splitAddress = patient.Address?.Split('\n'); | ||
|
||
if (splitAddress == null) return new Address(); | ||
|
||
return new Address | ||
{ | ||
Line1 = splitAddress[0], | ||
Line2 = splitAddress[1], | ||
City = splitAddress[2], | ||
Postcode = splitAddress[3], | ||
}; | ||
} | ||
|
||
public bool AttemptUpdateAddress(Guid accountId, Address address) | ||
{ | ||
var patient = dbService.GetPatientByAccountId(accountId); | ||
if (patient == null) return false; | ||
|
||
var addressString = address.Line1 + "\n" + address.Line2 + "\n" + address.City + "\n" + address.Postcode; | ||
|
||
dbService.UpdatePatient(patient with | ||
{ | ||
Address = addressString | ||
}); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.