I'm just putting together a small project, checking to see if this would be the fastest/cleanest way to write out a function that grabs the 3 latest vital signs.
Edit: I am thinking GetRecentVitalSigns
should be in the domain model.
Also, if I wanted to grab all the vital signs, I would just call the VitalSigns
list, but I was thinking I could make that as private
and create a GetAllVitalSigns
, but that seems redundant. Any advice would be excellent (on anything related).
public class Patient
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime AdmissionDate { get; set; }
public List<string> Allergies { get; set; }
public List<VitalSign> VitalSigns { get; set; }
public List<VitalSign> GetRecentVitalSigns()
{
if(VitalSigns.Count > 0)
{
var results = VitalSigns
.Take(3)
.OrderBy(x => x.DateTimeChecked)
.ToList();
return results;
}
return null;
}
}
public class VitalSign
{
public decimal BodyTemperature { get; set; }
public int Pulse { get; set; }
public int BloodPressure { get; set; }
public int RespiratoryRate { get; set; }
public DateTime DateTimeChecked { get; set; }
}
New structure
public class Patient
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime AdmissionDate { get; set; }
public List<string> Allergies { get; set; }
private List<VitalSign> vitalSigns;
private IEnumerable<VitalSign> VitalSigns
{
get { return vitalSigns; }
}
public IEnumerable<VitalSign> GetRecentVitalSigns(int vitalSignsCount = 3)
{
var recentVitalSigns = new IEnumerable<VitalSign>();
if (recentVitalSigns.Any())
{
recentVitalSigns = vitalSigns
.OrderBy(vs => vs.DateTimeChecked)
.Take(vitalSignsCount);
}
return recentVitalSigns;
}
}
public class VitalSign
{
public decimal BodyTemperature { get; set; }
public int Pulse { get; set; }
public int BloodPressure { get; set; }
public int RespiratoryRate { get; set; }
public DateTime DateTimeChecked { get; set; }
}
Allergies
be anenum
instead of string? I can see there being hundreds of elements, but IMHO type safety, intelisense, and avoiding string gotchas (CaSe, typos) wins out. Finally, theenum
necessarily defines all possible allergies and does so in one place in code. \$\endgroup\$