Implement patient methods in WaitingRoom
This commit is contained in:
parent
3941f2e4b6
commit
02ff071ebe
4 changed files with 97 additions and 18 deletions
|
|
@ -6,5 +6,11 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Node
|
public sealed class Node
|
||||||
{
|
{
|
||||||
// TODO
|
public Patient Data { get; }
|
||||||
|
public Node? Next { get; set; }
|
||||||
|
|
||||||
|
public Node(Patient patient)
|
||||||
|
{
|
||||||
|
Data = patient;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,18 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Patient
|
public sealed class Patient
|
||||||
{
|
{
|
||||||
// TODO ctor
|
public Patient(string name, DateTime arrival)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Arrival = arrival;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Patient(string name, DateTime arrival, bool isEmergency)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Arrival = arrival;
|
||||||
|
IsEmergency = isEmergency;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the patient
|
/// Gets the name of the patient
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class PatientQueue
|
public sealed class PatientQueue
|
||||||
{
|
{
|
||||||
//private Node? _head;
|
private Node? _head;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the number of patients currently waiting in this queue
|
/// Gets the number of patients currently waiting in this queue
|
||||||
|
|
@ -20,7 +20,25 @@ public sealed class PatientQueue
|
||||||
/// <param name="patient">Patient to add to the queue</param>
|
/// <param name="patient">Patient to add to the queue</param>
|
||||||
public void Enqueue(Patient patient)
|
public void Enqueue(Patient patient)
|
||||||
{
|
{
|
||||||
// TODO
|
var newNode = new Node(patient);
|
||||||
|
|
||||||
|
if (_head == null || patient.Arrival < _head.Data.Arrival)
|
||||||
|
{
|
||||||
|
newNode.Next = _head;
|
||||||
|
_head = newNode;
|
||||||
|
Size++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var current = _head;
|
||||||
|
while (current.Next != null && current.Next.Data.Arrival <= patient.Arrival)
|
||||||
|
{
|
||||||
|
current = current.Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
newNode.Next = current.Next;
|
||||||
|
current.Next = newNode;
|
||||||
|
Size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -29,8 +47,15 @@ public sealed class PatientQueue
|
||||||
/// <returns>The next patient to be treated; null if no patient is waiting</returns>
|
/// <returns>The next patient to be treated; null if no patient is waiting</returns>
|
||||||
public Patient? Dequeue()
|
public Patient? Dequeue()
|
||||||
{
|
{
|
||||||
// TODO
|
if (_head == null)
|
||||||
return null;
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var patient = _head.Data;
|
||||||
|
_head = _head.Next;
|
||||||
|
Size--;
|
||||||
|
return patient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -41,7 +66,31 @@ public sealed class PatientQueue
|
||||||
/// <returns>True if the patient could be removed; false otherwise</returns>
|
/// <returns>True if the patient could be removed; false otherwise</returns>
|
||||||
public bool Remove(Patient patient)
|
public bool Remove(Patient patient)
|
||||||
{
|
{
|
||||||
// TODO
|
if (_head == null)
|
||||||
return false;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_head.Data == patient)
|
||||||
|
{
|
||||||
|
_head = _head.Next;
|
||||||
|
Size--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var current = _head;
|
||||||
|
while (current.Next != null && current.Next.Data != patient)
|
||||||
|
{
|
||||||
|
current = current.Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.Next == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
current.Next = current.Next.Next;
|
||||||
|
Size--;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,20 +14,17 @@ public sealed class WaitingRoom
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current number of emergency patients waiting
|
/// Gets the current number of emergency patients waiting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// TODO
|
public int CountEmergency => _emergencyQueue.Size;
|
||||||
public int CountEmergency => -1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current number of normal patients waiting
|
/// Gets the current number of normal patients waiting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// TODO
|
public int CountNormal => _normalQueue.Size;
|
||||||
public int CountNormal => -1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current number of all patients waiting
|
/// Gets the current number of all patients waiting
|
||||||
/// </summary>
|
/// </summary>
|
||||||
// TODO
|
public int CountAll => CountEmergency + CountNormal;
|
||||||
public int CountAll => -1;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a string representation of the waiting room, showing statistics
|
/// Creates a string representation of the waiting room, showing statistics
|
||||||
|
|
@ -43,15 +40,25 @@ public sealed class WaitingRoom
|
||||||
/// <param name="patient">Patient to admit</param>
|
/// <param name="patient">Patient to admit</param>
|
||||||
public void AddPatient(Patient patient)
|
public void AddPatient(Patient patient)
|
||||||
{
|
{
|
||||||
// TODO
|
if (patient.IsEmergency)
|
||||||
|
{
|
||||||
|
_emergencyQueue.Enqueue(patient);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_normalQueue.Enqueue(patient);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the next patient to be treated, removing it from its waiting queue
|
/// Returns the next patient to be treated, removing it from its waiting queue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Next patient to treat, if any</returns>
|
/// <returns>Next patient to treat, if any</returns>
|
||||||
// TODO
|
public Patient? Next()
|
||||||
public Patient? Next() => null;
|
{
|
||||||
|
var emergency = _emergencyQueue.Dequeue();
|
||||||
|
return emergency ?? _normalQueue.Dequeue();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Promotes a patient to be an emergency case.
|
/// Promotes a patient to be an emergency case.
|
||||||
|
|
@ -60,6 +67,12 @@ public sealed class WaitingRoom
|
||||||
/// <param name="patient">Patient to declare an emergency for</param>
|
/// <param name="patient">Patient to declare an emergency for</param>
|
||||||
public void SetPatientToEmergency(Patient patient)
|
public void SetPatientToEmergency(Patient patient)
|
||||||
{
|
{
|
||||||
// TODO
|
if (!_normalQueue.Remove(patient))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
patient.IsEmergency = true;
|
||||||
|
_emergencyQueue.Enqueue(patient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue