In: Computer Science
Hello I need this written in C# with a few comments thanks
Modify the Patient class to reference a demographic object that contains the patient phone number, email and next of kin. Create a demographic class to store this information. Make sure to create a constructor in the class for this information.
Modify the Patient constructor to pass in this additional information at the time of instantiation.
Modify the display method to display all the data
HERE IS THE CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Example2Aggregation
{
class Program
{
static void Main(string[] args)
{
Patient p1 = new Patient(1234, "Smith", "Jane", "O", "+");
displayPatient(p1);
Patient p2 = new Patient();
p2.PatientId = 444;
p2.LastName = "Doe";
p2.FirstName = "John";
BloodData b1 = new BloodData("A", "-");
p2.BloodData = b1;
p2.displayPatient();
}
//display method
public static void displayPatient(Patient p)
{
Console.WriteLine("Patient ID: " + p.PatientId + " " + p.LastName +
" Blood Data: " + p.BloodData.BloodType + " " + p.BloodData.RhFactor);
}
}
}
PATIENT CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
The Program is straight forward as per the requirements. The comments are included in the program wherever applicable.
The new class to hold the demographic information is created and used in the program. The constructors are created as stated in the requirements.
Code
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//Patient1 & Patient2. Provide the details. Here all the values
are supplied through the constructor
//The Blood Group related information is also passed in the
constructor.
Patient p1 = new Patient(1234, "Smith", "Jane", "O", "+",
"888-999-6666", "[email protected]", "Jane", "888-333-444");
//Invoke the Display function which will prints the data on to the
screen.
p1.displayPatient();
//Initialise the 2nd patient & display the details
Patient p2 = new Patient(444, "John", "Doe", "A", "-",
"888-876-6666", "[email protected]", "Doe", "888-873-444");
p2.displayPatient();
Console.ReadKey();
}
}
class Patient
{
//This class holds the Patient details
private int patientId;
private string firstName;
private string lastName;
private BloodDataWrapper bloodData;
private DemographicWrapper demographicInfo;
public Patient(int patientId, string firstName, string lastName,
string bloodType, string rhFactor,
string patientPhoneNumber, string patientEmail, string nextOfKin,
string nextOfKinPhoneNumber)
{
this.patientId = patientId;
this.firstName = firstName;
this.lastName = lastName;
this.bloodData = new BloodDataWrapper(bloodType, rhFactor);
this.demographicInfo = new DemographicWrapper(patientPhoneNumber,
patientEmail, nextOfKin, nextOfKinPhoneNumber);
}
//display method
public void displayPatient()
{
//Print each of the data in a separate line.
Console.WriteLine("Patient ID: {0}", patientId);
Console.WriteLine("First Name: {0}", firstName);
Console.WriteLine("Last Name: {0}", lastName);
Console.WriteLine("Blood Type: {0}", bloodData.BloodType);
Console.WriteLine("RH factor: {0}", bloodData.RHFactor);
Console.WriteLine("Patient Phone Number: {0}",
demographicInfo.PatientPhoneNumber);
Console.WriteLine("Patient Email: {0}",
demographicInfo.PatientEmail);
Console.WriteLine("Next Of Kin: {0}",
demographicInfo.NextOfKin);
Console.WriteLine("Next Of Kin Phone Number: {0}\n",
demographicInfo.NextOfKinPhoneNumber);
}
}
class BloodDataWrapper
{
//This class holds the Blood Group related information
private string bloodType;
private string rhFactor;
public string BloodType { get => bloodType; }
public string RHFactor { get => rhFactor; }
public BloodDataWrapper(string bloodType, string rhFactor)
{
this.bloodType = bloodType;
this.rhFactor = rhFactor;
}
}
class DemographicWrapper
{
//This class holds the demographic information of the patient
private string patientPhoneNumber;
private string patientEmail;
private string nextOfKin;
private string nextOfKinPhoneNumber;
public string PatientPhoneNumber { get => patientPhoneNumber;
}
public string PatientEmail { get => patientEmail; }
public string NextOfKin { get => nextOfKin; }
public string NextOfKinPhoneNumber { get =>
nextOfKinPhoneNumber; }
public DemographicWrapper(string patientPhoneNumber, string
patientEmail, string nextOfKin, string nextOfKinPhoneNumber)
{
this.patientPhoneNumber = patientPhoneNumber;
this.patientEmail = patientEmail;
this.nextOfKin = nextOfKin;
this.nextOfKinPhoneNumber = nextOfKinPhoneNumber;
}
}
}