Below is my program I just have some issues when I want to c
Below is my program, I just have some issues when I want to check out a patient and when I want to print a specific patient. Please help. I think there is a minor error, but I can\'t find it. PATIENT ID MUST BE \"LASTNAMEFIRSTNAMEYEAR\" example PattersonMathew2005. Please read instructions help me solve the problem.
In this assignment, you will write a struct plus two simple classes and then write a program that uses them all. The first class is a Date class. You are given code for this at the end of this assignment, but you must make some modifications. The other is a Patient class; you are given the class definition and you must write the implementation. The program will keep track of patients at a walk-in clinic. For each patient, the clinic keeps a record of all procedures done. This is a good candidate for a class, but to simplify the assignment, we will make a procedure into a struct. We will assume that the clinic has assigned all care providers (doctors, nurses, lab technicians) with IDs and each procedure (“office visit”, “physical exam”, “blood sample taken”, etc.) also has an ID. Each patient will also have an ID, which is formed by the last name concatenated with the first name and the year of birth. All other IDs (care providers, procedures) will be just integers.
When the user runs the program at the start of the day, it first tries to read in from a binary file calledCurrentPatients.dat. It will contain the number of patients(in binary format) followed by binary copies of records for the patients at the clinic . This information should be read and stored in an array of Patient objects. There will be a separate array, initially empty at the start of the program that will store patient records for all patients who are currently checked in at the clinic. It then asks the user to enter the current date and reads it in. It should then presents the user with a simple menu: the letter N to check in a new patient, R for checking in a returning patient, O to check out a patient, I to print out information on a particular patient, P to print the list of patients who have checked in, but not yet checked out, and Q for quitting the program.
The following tasks are done when the appropriate letter is chosen.
N: The new patient’s first name, last name, and birthdate are asked for and entered. The new patient ID will be the last name concatenated with the first name and the year of birth. (Example: SmithJohn1998) The primary doctor’s ID is also entered. The new patient object is placed in both arrays: one keeping all patients, and one keeping the patients who checked in today.
R: The returning patient’s ID is asked for, and the array holding all patients is searched for the patient object. If found, a copy of the patient object is placed in the array for all currently checked in patients. If not found, the user is returned to the main menu after asking them to either try R again, making sure the correct ID was entered, or choose N to enter the patient as a new patient.
O: Using the patient’s ID, the patient object is found in the array holding currently checked in patients. (If not found, the user is returned to the main menu after asking them to either try O again, making sure the correct ID was entered, or choose N or R to check in the patient as a new or returing patient.) The procedure record is updated by entering a new entry, with the current date, procedure ID, and provider ID. The up-dated patient object is then removed from the array of currently checked in patients, and replaces the old patient object in the main array. If the update fails, a message is output.
I: Using the patient’s ID, the main array holding all patients is searched for the patient object. If found the information it holds: the names, birthdate, the primary doctor ID, and a list of all past procedures done (date, procedure ID, procedure provider ID) is printed to the monitor.
P: From the array holding all patients currently checked in, a list is printed in nice readable form, showing the patient ID, first and last names, and the primary doctor ID for each patient.
Q: If the list of patients currently checked in is not empty, the list is printed out and the user asked to keep running the program so they can be checked out. If the list is empty, the program will write the patient objects in the main array to the binary file CurrentPatients.dat. It should overwrite all previous information in the file.
// Definition of class Date in date.h
#ifndef Date_h
#define Date_h
#include <iostream>
#include <string>
using namespace std;
class Date {
friend ostream &operator<<(ostream &, const Date &); // allows easy output to a ostream
public:
Date(int m = 1, int d = 1, int y = 1900); // constructor, note the default values
void setDate(int, int, int); // set the date
const Date &operator+=(int); // add days, modify object
bool leapYear(int) const; // is this a leap year?
bool endOfMonth(int) const; // is this end of month?
int getMonth() const // You need to implement this
{
return month;
}
int getDay() const // You need to implement this
{
return day;
}
int getYear() const // You need to implement this
{
return year;
}
string getMonthString() const; // You need to implement this
Date& operator=(Date other);//Added by Roberto
private:
int month;
int day;
int year;
static const int days[]; // array of days per month
static const string monthName[]; // array of month names
void helpIncrement(); // utility function
};
#endif
// Member function definitions for Date class in separate date.cpp file
#include <iostream>
#include \"Date.h\"
#include <string>
// Initialize static members at file scope;
// one class-wide copy.
const int Date::days[] = { 0, 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
const string Date::monthName[] = { \"\", \"January\",
\"February\", \"March\", \"April\", \"May\", \"June\",
\"July\", \"August\", \"September\", \"October\",
\"November\", \"December\" };
// Date constructor
Date::Date(int m, int d, int y) { setDate(m, d, y); }
// Set the date
void Date::setDate(int mm, int dd, int yy)
{
month = (mm >= 1 && mm <= 12) ? mm : 1;
year = (yy >= 1900 && yy <= 2100) ? yy : 1900;
// test for a leap year
if (month == 2 && leapYear(year))
day = (dd >= 1 && dd <= 29) ? dd : 1;
else
day = (dd >= 1 && dd <= days[month]) ? dd : 1;
}
// Add a specific number of days to a date
const Date &Date::operator+=(int additionalDays)
{
for (int i = 0; i < additionalDays; i++)
helpIncrement();
return *this; // enables cascading
}
// If the year is a leap year, return true;
// otherwise, return false
bool Date::leapYear(int testYear) const
{
if (testYear % 400 == 0 || (testYear % 100 != 0 && testYear % 4 == 0))
return true; // a leap year
else
return false; // not a leap year
}
// Determine if the day is the end of the month
bool Date::endOfMonth(int testDay) const
{
if (month == 2 && leapYear(year))
return (testDay == 29); // last day of Feb. in leap year
else
return (testDay == days[month]);
}
// Function to help increment the date
void Date::helpIncrement()
{
if (!endOfMonth(day)) { // date is not at the end of the month
day++;
}
else if (month < 12) { // date is at the end of the month, but month < 12
day = 1;
++month;
}
else // end of month and year: last day of the year
{
day = 1;
month = 1;
++year;
}
}
//class function added by Roberto
Date& Date :: operator=(Date other)
{
day = other.day;
month = other.month;
year = other.year;
return *this;
}
// Overloaded output operator
ostream &operator<<(ostream &output, const Date &d)
{
output << d.monthName[d.month] << \' \'
<< d.day << \", \" << d.year;
return output; // enables cascading
}
string Date::getMonthString() const // Added by Roberto
{
return monthName[month];
}
//patient.cpp
#include \"Patient.h\"
#include<iostream>
using namespace std;
Patient::Patient()
{
//added after programmed was debugged
/*this->setID(\'\\0\');
this->setFirstName(\'\\0\');
this->setLastName(\'\\0\');
this->setBirthDate(Date());
this->setPrimaryDoctorID(0);*/
}
Patient::Patient(const char *patientID, const char *fName, const char *lName, Date birthDate, int doctorID)
{
this->setID(patientID);
this->setFirstName(fName);
this->setLastName(lName);
this->setBirthDate(birthDate);
this->setPrimaryDoctorID(doctorID);
}
Patient :: ~Patient()
{
}
Patient & Patient::setID(const char *patientID)
{
if (strlen(patientID) > 32)
strncpy_s(ID, patientID, 32);
else
strcpy_s(ID, patientID);
return(*this);
}
Patient & Patient::setFirstName(const char *fName)
{
if (strlen(fName) > 15)
{
strncpy_s(firstName, fName, 14);
}
else
{
strcpy_s(firstName, fName);
}
return(*this);
}
Patient & Patient::setLastName(const char *lName)
{
if (strlen(lName) > 15)
{
strncpy_s(lastName, lName, 14);
}
else
{
strcpy_s(lastName, lName);
}
return(*this);
}
Patient & Patient::setBirthDate(Date birthDate)
{
birthdate = birthDate;
return(*this);
}
Patient & Patient::setPrimaryDoctorID(int doctorID)
{
primaryDoctorID = doctorID;
return(*this);
}
const char * Patient::getID()
{
return ID;
}
const char * Patient::getFirstName()
{
return firstName;
}
const char * Patient::getLastName()
{
return lastName;
}
Date Patient::getBirthDate()
{
return birthdate;
}
int Patient::getPrimaryDoctorID()
{
return primaryDoctorID;
}
bool Patient::enterProcedure(Date procedureDate, int procedureID, int procedureProviderID)
{
if (currentCountOfProcedures > 500)
{
cout << \"Cannot add any more procedures\" << endl;
return 0;
}
else
{
procedure newProcedure;
newProcedure.dateOfProcedure = procedureDate;
newProcedure.procedureID = procedureID;
newProcedure.procedureProviderID = procedureProviderID;
//record[currentCountOfProcedures].dateOfProcedure = procedureDate;
// record[currentCountOfProcedures].procedureID = procedureID;
//record[currentCountOfProcedures].procedureProviderID = procedureProviderID;
currentCountOfProcedures++;
return 1;
}
}
void Patient::printAllProcedures()
{
cout << \"Procedures of patient\" << endl;
for (int i = 0; i < currentCountOfProcedures; i++)
{
cout << \"Date of Procedure: \" << record[i].dateOfProcedure.getDay() << endl;
cout << \"Procedure of ID \" << record[i].procedureID << endl;
cout << \"Procedure Provider ID: \" << record[i].procedureProviderID << endl;
}
}
//recently added
Patient& Patient::operator=(Patient other)
{
strcpy_s(ID, other.ID);
strcpy_s(firstName, other.firstName);
strcpy_s(lastName, other.lastName);
birthdate = other.birthdate;
primaryDoctorID = other.primaryDoctorID;
for (int i = 0; i < other.currentCountOfProcedures; i++)
{
record[i] = other.record[i];
}
currentCountOfProcedures = other.currentCountOfProcedures;
return *this;
}
//patient.h
#ifndef Patient_h
#define Patient_h
#include \"Date.h\"
#include<iostream>
#include <string>
struct procedure
{
Date dateOfProcedure;
int procedureID;
int procedureProviderID;
};
class Patient
{
private:
char ID[33];
char firstName[15];
char lastName[15];
Date birthdate;
int primaryDoctorID;
procedure record[100];
int currentCountOfProcedures = 0; //initialized to 0
public:
Patient(); //default constructor
Patient(const char *, const char *, const char *, Date, int);
//Put in default values just as in Date class
//Use the set functions so input values are checked
~Patient();
Patient & setID(const char *); //check if length of name string is < 32.
// if not, shorten to 32 letters.
Patient & setFirstName(const char *); //check if length of name string is <
// 15, if not, shorten to 14 letters.
Patient & setLastName(const char *); //check if length of name string is <
// 15, if not, shorten to 14 letters.
Patient & setBirthDate(Date);
Patient & setPrimaryDoctorID(int);
const char * getID();
const char * getFirstName();
const char * getLastName();
Date getBirthDate();
int getPrimaryDoctorID();
Patient& operator=(Patient other); //Added by Roberto
bool enterProcedure(Date procedureDate, int procedureID,
int procedureProviderID);//tries to add a new entry to record array, returns //true if added, false if cannot be added
void printAllProcedures();
};
#endif
//main
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstring>
#include<string>
//Classes added
#include\"Patient.h\"
#include\"Date.h\"
using namespace std;
//functions added
void printMenu();
void RemovePatient(Patient checkIn[], int & count, int index);
//main function
int main(int argc, const char* argv[])
{
int procedureID = 0;
Patient checkIn[10];
Patient patient[20];
char userValue;
int i = 0;
char patientID[33];
int doctorID = 0;
int count = 0;
int countAll = 0;
int tempMonth = 0, tempDay = 0, tempYear = 0;
char fName[20], lName[30];
Date tempDate, birthDate;
bool patientFound = false;
//============================ binary to read file ===================
ifstream file;
file.open(\"PatientHospitalRecords.bin\", ios::in | ios::binary);
if (file.is_open())
{
file.read((char*)&countAll, sizeof(int));
for (int i = 0; i < countAll; i++)
{
file.read((char*)&patient[i], sizeof(Patient));
}
file.close();
}
//=========================== Print welcome info =====================
cout << \"Welcome to the Hospital Records Program \" << endl;
cout << \"Please enter the date in integers according to the following format mm dd yyyy: \";
cout << endl;
cin >> tempMonth;
cin.get(); // this will read /
cin >> tempDay;
cin.get(); // this will read the second /
cin >> tempYear;
tempDate.setDate(tempMonth, tempDay, tempYear);
//while statemtn for each letter the user choices.
do
{
printMenu();
cin >> userValue; //user enters value from menue
userValue = toupper(userValue); //Convertion from lowercase to upper case
switch (userValue)
{
case \'N\': //Check in a new patient
//statement to check in a new patient fix
cout << \"Check in a new patient \" << endl;
cout << \"First name: \";
cin >> fName;
checkIn[count].setFirstName(fName);
cout << \"Last name: \";
cin >> lName;
checkIn[count].setLastName(lName);
cout << \"Doctor ID: \";
cin >> doctorID;
checkIn[count].setPrimaryDoctorID(doctorID);
cout << \"Patient birthdate: \" << endl;
cout << \"Day: \";
cin >> tempDay;
cout << \"Month: \";
cin >> tempMonth;
cout << \"Year: \";
cin >> tempYear;
//added code
//code added after program was debugged
/* char patientID1[33];
strncpy_s(patientID, lName, 14);
strncat_s(patientID, lName, 14);
strcat_s(patientID, fName);
char year[5];
sprintf_s(year, \"%d\", tempYear);
strcat_s(patientID1, year);
//return(*this);*/
//end of code added when programmed was debugged
checkIn[count].setFirstName(fName);
checkIn[count].setLastName(lName);
checkIn[count].setPrimaryDoctorID(doctorID);
birthDate.setDate(tempMonth, tempDay, tempYear);
checkIn[count].setBirthDate(birthDate);
char year[5];
strncpy_s(patientID, lName, \' \');
strcat_s(patientID, fName);
sprintf_s(year, \"%d\", tempYear);
strcat_s(patientID, year);
checkIn[count].setID(patientID);
count++;
countAll++;
cout << endl;
cout << \" Checking in a patient. \" << endl;
break;
case \'R\': //check in a returning patient
cout << \"Check In a returning patient\" << endl;
patientFound = false;
i = 0;
do
{
cout << \"Please, enter the patient ID: \";
cin >> patientID;
do
{
if (patient[i].getID() == patientID)
{
checkIn[count] = patient[i];
count++;
patientFound = true;
}
i++;
} while (!patientFound && i < countAll);
if (!patientFound)
{
cout << \"Patient entered is not found on records\" << endl;
cout << \"Would you like to check in as a new Patient (Y/N): \";
cin >> userValue;
}
} while (!patientFound && userValue == toupper(\'N\'));
break;
case \'O\': //Check out a patient
patientFound = false;
cout << \"Check out a patient: \" << endl;
i = 0;
do
{
cout << \"Enter Patient ID to proceed the check out: \";
cin >> patientID;
for (int i = 0; i < count; i++)
{
if ((checkIn[i].getID()) == patientID)
{
cout << \"Enter doctor\'s ID: \";
cin >> doctorID;
cout << \"Enter patient\'s ID: \";
cin >> patientID;
checkIn[i].enterProcedure(tempDate, procedureID, doctorID);
//use enterProcedure()
for (int j = 0; j < countAll; j++)
if (patient[j].getID() == checkIn[i].getID())
{
patient[j].enterProcedure(tempDate, tempDay, doctorID);
cout << j;
cout << \"Patient ID: \" << j + 1 << \" has been chekced out \" << endl << endl;
}
RemovePatient(checkIn, count, i);
patientFound = true;
cout << \"Test \" << endl;
checkIn[i].printAllProcedures();
}
i++;
}
if (!patientFound)
{
cout << \"Patient ID is not in the records \" << endl;
cout << \"Would you like to check in as a new patient or returning patient? (Y/N): \";
cout << endl;
cout << checkIn[i].getID() << endl << patientID;
cin >> userValue;
}
} while (!patientFound && userValue == toupper(\'N\'));
break;
case \'I\': //Print information on particular patient
patientFound = false;
cout << \"To display information of the patient, please enter the patient ID: \";
cin >> patientID;
i = 0;
do
{
if (patient[i].getID() == patientID)
{
cout << \"Patient ID \" << patient[i].getID() << endl;
cout << \"Name: \" << patient[i].getFirstName() << \" \" << patient[i].getLastName() << endl;
cout << \"Birthdate: \" << patient[i].getBirthDate() << endl;
cout << \"Doctor ID: \" << patient[i].getPrimaryDoctorID() << endl;
patient[i].printAllProcedures();
patientFound = true;
}
i++;
} while (!patientFound && i < countAll);
if (!patientFound)
{
cout << \"Record not available \" << endl;
}
break;
case \'P\': //Print list of all patients.
//if statement to print out record of books
cout << \"List of all patients still check in: \" << endl;
if (count > 0)
{
for (int i = 0; i < count; i++)
{
cout << \"Patient ID \" << checkIn[i].getID() << endl;
cout << \"Name: \" << checkIn[i].getFirstName() << \" \" << checkIn[i].getLastName() << endl;
cout << \"Birthdate \" << checkIn[i].getBirthDate() << endl;
cout << \"Doctor ID: \" << checkIn[i].getPrimaryDoctorID() << endl;
}
}
else
{
cout << \"All patients have been checked out \" << endl;
}
break;
case \'Q\':
if (count == 0)
{
//=================================== binary to write file =============================
ofstream oFile;
oFile.open(\"PatientHospitalRecords.bin\", ios::out | ios::binary);
if (oFile.is_open())
{
oFile.write((char*)&countAll, sizeof(int));
for (int i = 0; i < countAll; i++)
oFile.write((char*)&patient[i], sizeof(Patient));
oFile.close();
cout << \"You chose to close the patient records program \" << endl << \"GOOD BYE!!!\";
}
}
else
{
for (int i = 0; i < count; i++)
{
cout << checkIn[i].getID() << endl;
cout << checkIn[i].getFirstName() << \" \" << checkIn[i].getLastName() << endl;
cout << checkIn[i].getBirthDate() << endl;
cout << checkIn[i].getPrimaryDoctorID() << endl;
}
userValue = \'A\';
}
break;
default:
cout << \"Error!!! You have entered an invalid value \" << endl << \"Please try again\" << endl;
cout << endl;
cout << \"Please select another option.\ \";
cin >> userValue;
userValue = toupper(userValue);
break;
}//end of switch statemnt
}while (userValue != \'Q\');//end of do loop
return 0;
}
//void function to print out the menu.
void printMenu()
{
cout << \"_________________________________________________\" << endl;
cout << \"Please enter your one letter choice as follows: \" << endl;
cout << \"N:\\tCheck in a new patient: \"<< endl;
cout << \"R:\\tCheck in a returning patient: \"<< endl;
cout << \"O:\\tChekc out a patient: \" << endl;
cout << \"I:\\tPrint out information about a particular patient: \" << endl;
cout << \"P:\\tPrint list of patients who have checked in: \" << endl;
cout << \"Q:\\tQuit the program\" <<endl;
cout << endl;
}
//void function to remove patient from records
void RemovePatient(Patient checkIn[], int & count, int index)
{
for (int i = index; i < count; i++)
{
checkIn[i] = checkIn[i + 1];
count--;
}
}
Solution
It is hard to let go of the thinking behind some of the management tools we still use today. Designed for types of work that are no longer prevalent, these systems were designed for another time.











