+1 (315) 557-6473 

C++ Program to Create Patient Management System Assignment Solution.


Instructions

Objective
Write a program to create patient management system in c++.

Requirements and Specifications

Project 4 - Patient Management System (cont)
Overview
Develop a patient management system as the continuation of our prior project 2 and 3. This project focuses on the features about input and output of strings and files.
Learning Objectives
  • Modular with classes
  • Text menu
  • Dynamic data
  • Memory management
  • String stream I/O
  • File I/O
Project Description
You are to implement a program to manage information of multiple patients.
The list of requirements and constraints for the system are as follows:
  1. The name of each patient is unique and can be used to locate the information on a specific patient.
  2. User will be asked for a file name to load initial data from. Validation and error handling required. The input file format is demonstrated in the example below. The first line holds the count of patients and the rest of lines holds patients' information. Each line have three fields delimited by commas. Do not modify the provided patients.txt file!
  3. User can print all patient information.
  4. User can update the information of a patient by providing a valid id (index) of an existing patient and provide updates on his name, age and gender information. Validations of the id and gender are expected.
  5. The user can save the patient list to a file by providing a file name. The format should be the same as the input file.
Sample patients.txt file as input file
3
Alan Harry, 24, Male
Ching Peppard, 32, Male
Lorelei Saad, 18, Female
Code organization
The class diagram is in the PlantUML format. The green circle means public while red square means private. Hollow icon means instance variable while solid icon means methods. You can check this document for more information.
main.cpp
The main entry point of the executable. Set up the app class and run it. Provided file, do not modify!
Patient Class

The class to handle information related to one patient.

  • The info() method should provide a string with the format like:
  • Name: Alan Harry \| Age: 24 \| Gender: Male
  • The constructor that takes a line of text will parse the text in the format show below and assign value to the instance variables accordingly.
  • Alan Harry, 24, Male
  • Another constructor that takes three parameters will directly set the values of all instance variables.
Patients Class
The class to manage the list of patients.
  • The count instance variable stores the count of patients
  • The patients instance variable is a pointer to the dynamic array of Patient typed objects
  • The default constructor will set up an empty object
  • The load() method takes a file name. It read the content from the file and create the dynamic array patients to hold the information. The count in the first line of the file should be read first as the size of dynamic array. This function should return true on success and return false when the file cannot be opened correctly.
  • The save() method takes a file name. It saves the information of stored patients to a file following the exactly same format of the input file.
  • The destructor should release the memory of the dynamic array
  • The updatePatient() will update an existing patient object in the dynamic array.
  • The getPatientInfo() method will take an id (index) of the patient and print the detail of the patient.
  • The printAll() function prints the list of a patients' information in the format shown in the sample run when option 1 is chosen. It should ask each Patient object to provide the string by calling the info() method and print the details.
TextMenuApp Class
The main application class the drives a text menu based program. It drives the text menu to run the program. The behavior of the text menu is defined in the sample run. Pay attention to the input validations.
makefile
The makefile is the same as project 3 so is provided. You can use it directly.
test.cpp
Provided test file to test the Patient and Patients objects. It can be run with the command make test
Implementation Notes
  • Download the provided files here Download here.
  • The included main-linux file is an executable that you can run on the SSH server or Linux to see how the solution works.
  • Make the corresponding cpp files as needed. Follow the naming convention.
  • You can run make or make main to compile your app and execute using ./main
  • You can run make test to compile and run tests.
  • A makefile rule named test-run is provided and you can run it using make test-run to reproduce the sample run shown in the instruction with all user inputs skipped (the format will look different).
Sample run
Input the file name to load initial data from: not-exist.txt
File cannot be opened! Input again!
Input the file name to load initial data from: patients.txt
File loaded!
1. Print all patients;
2. Update information of a patient;
3. Save file;
4. Exit.
Please choose an option(1-4): 1
0: Name: Alan Harry | Age: 24 | Gender: Male
1: Name: Ching Peppard | Age: 32 | Gender: Male
2: Name: Lorelei Saad | Age: 18 | Gender: Female
3 patients in total.
1. Print all patients;
2. Update information of a patient;
3. Save file;
4. Exit.
Please choose an option(1-4): 2
Please input patient's id as shown in the list: -1
Invalid index, please input again!
Please input patient's id as shown in the list: 4
Invalid index, please input again!
Please input patient's id as shown in the list: 2
The existing info:
Name: Lorelei Saad | Age: 18 | Gender: Female
Please input patient's new name: John Smith
Please input patient's new age: 17
Pleas input patients's new gender(Male/Female): M
Invalid input, Male, or Female only!
Pleas input patients's gender(Male/Female): Male
Patient updated!
1. Print all patients;
2. Update information of a patient;
3. Save file;
4. Exit.
Please choose an option(1-4): 1
0: Name: Alan Harry | Age: 24 | Gender: Male
1: Name: Ching Peppard | Age: 32 | Gender: Male
2: Name: John Smith | Age: 17 | Gender: Male
3 patients in total.
1. Print all patients;
2. Update information of a patient;
3. Save file;
4. Exit.
Please choose an option(1-4): 3
Input the file name to save the data to: output.txt
File saved!
1. Print all patients;
2. Update information of a patient;
3. Save file;
4. Exit.
Please choose an option(1-4): 4
Thank you for using the app!
Submission
You may want to transfer all files to the SSH server and give a final test run there.
Run make clean and you should have only required source code files, makefile and diary files left in your directory. Compress the whole directory to a zip file and upload to Canvas.
Grading Breakdown
Functionality
  • [5 pts] Compile and run make main and ./main
  • [45 pts] Text menu driven app make test-run
  • [10 pts] load file, read name from user, open failure handling
  • [10 pts] Working menu system to take in user input and call functionality
  • [10 pts] Print all patients
  • [10 pts] Update patients, validation
  • [5 pts] Save file, read name from user
  • [30 pts] Pass all tests make test (Patient and Patients class)
Code
  • [10 pts] Clean and correct submission
  • [10 pts] Clear, easy-to-read code
Penalty
  • [-20 pts] Project not compile usiing make until minor fix from the grader
  • [-50 pts] Not following the class decomposition. Not using the classes to implement the functionality
Source Code
APPOINTMENT
#ifndef appointments_h
#define appointments_h
#include "patient.hpp"
#include
using namespace std;
class Appointments
{
public:
// Initialize the appointments
Appointments(Patient* patients, int patientCount);
// Operations
void printPatients() const;
void printAppointments() const;
void appointPatient(const string& patientName, int appointmentHour);
void freeAppointment(int appointmentHour);
private:
Patient* patients;
int patientCount;
// Index 0 for 8:00
// Index 1 for 9:00
// Index 2 for 10:00
// ...
// Index 7 for 15:00
// The value stored in the array is the index of a patient in the patients array
int scheduledPatients[8];
int findPatient(const string& patientName) const;
};
// Initialize the appointments
Appointments::Appointments(Patient* patients, int patientCount)
: patients(patients), patientCount(patientCount)
{
// Set -1 to the schedule to indicate that no patient
// is scheduled for that time slot
for (int i = 0; i < 8; i++)
scheduledPatients[i] = -1;
}
// Print all patients
void Appointments::printPatients() const
{
cout << "Patients List:" << endl;
for (int i = 0; i < patientCount; i++)
cout << " " << patients[i].getName() << endl;
}
// Print all appointments from 8:00 to 15:00
void Appointments::printAppointments() const
{
cout << "Appointments:" << endl;
int currentHour = 8;
for (int i = 0; i < 8; i++)
{
cout << " " << currentHour << ":00 - ";
if (scheduledPatients[i] == -1)
cout << "FREE";
else
cout << patients[scheduledPatients[i]].getName();
cout << endl;
currentHour++;
}
}
// Find the patient in the list, returns the index of patient otherwise -1 if not found
int Appointments::findPatient(const string& patientName) const
{
for (int i = 0; i < patientCount; i++)
if (patients[i].getName() == patientName)
return i;
return -1;
}
// Appoint the patient on the given hour
void Appointments::appointPatient(const string& patientName, int appointmentHour)
{
// Check that the clinic is open at the given hour
if (appointmentHour < 8 || appointmentHour > 15)
{
cout << "I'm sorry but the clinic is closed at the given hour." << endl;
return;
}
// Check that the schedule is free
int appointmentIndex = appointmentHour - 8;
if (scheduledPatients[appointmentIndex] != -1)
{
cout << "I'm sorry but the selected hour is currently appointed to " << patients[scheduledPatients[appointmentIndex]].getName() << "." << endl;
return;
}
// Check that the patient exists
int patientIndex = findPatient(patientName);
if (patientIndex == -1)
{
cout << "I'm sorry but the patient does not exist." << endl;
return;
}
// If all good then appoint patient to schedule
scheduledPatients[appointmentIndex] = patientIndex;
cout << "Ok, patient appointed on the said schedule." << endl;
}
// Free an appointment at the given hour
void Appointments::freeAppointment(int appointmentHour)
{
// Check that the clinic is open at the given hour
if (appointmentHour < 8 || appointmentHour > 15)
{
cout << "I'm sorry but the clinic is closed at the given hour." << endl;
return;
}
// Check that the schedule is not free
int appointmentIndex = appointmentHour - 8;
if (scheduledPatients[appointmentIndex] == -1)
{
cout << "I'm sorry but the selected hour is currently free." << endl;
return;
}
// Free the schedule
scheduledPatients[appointmentIndex] = -1;
cout << "Ok, schedule has been freed." << endl;
}
#endif
DATA
#ifndef data_h
#define data_h
#include "patient.hpp"
// Initialize 5 patients
int initPatientCount = 5;
Patient initPatients[] =
{
Patient("Alice"),
Patient("Bob"),
Patient("Charlie"),
Patient("Dan"),
Patient("Esther")
};
#endif
PATIENT
#ifndef patient_h
#define patient_h
#include
#include
using namespace std;
class Patient
{
public:
// Constructor
Patient(const string& name);
// Getter methods
string getName() const;
private:
string name;
};
// Initialize a patient
Patient::Patient(const string& name)
: name(name)
{
}
// Return the name
string Patient::getName() const
{
return name;
}
#endif
TEXT MENU APP
#ifndef textmenuapp_h
#define textmenuapp_h
#include "appointments.hpp"
#include
using namespace std;
// Handle the text based user interface menu
class TextMenuApp
{
public:
// Constructor
TextMenuApp(Appointments &patientManager);
// Operations
void run();
private:
Appointments patientManager;
};
// Initialize the text menu app
TextMenuApp::TextMenuApp(Appointments& patientManager)
: patientManager(patientManager)
{
}
// Run the text menu app
void TextMenuApp::run()
{
while (true)
{
// Display options to user on what they want to do
cout << "Menu" << endl;
cout << "1. Print all patient information" << endl;
cout << "2. Print all appointment information" << endl;
cout << "3. Add appointment for a patient" << endl;
cout << "4. Clear a scheduled appointment" << endl;
cout << "0. Exit" << endl;
cout << "Option: ";
int option;
cin >> option;
// Execute the user's option
if (option == 1)
{
// Print all patients
patientManager.printPatients();
}
else if (option == 2)
{
// Print all appointments
patientManager.printAppointments();
}
else if (option == 3)
{
// Appoint a patient to a schedule
cout << "Enter patient's name to appoint: ";
string patientName;
cin >> patientName;
cout << "Enter at what hour to appoint (8 to 15): ";
int appointmentHour;
cin >> appointmentHour;
patientManager.appointPatient(patientName, appointmentHour);
}
else if (option == 4)
{
// Clear appointed schedule
cout << "Enter at what hour you want to free (8 to 15): ";
int appointmentHour;
cin >> appointmentHour;
patientManager.freeAppointment(appointmentHour);
}
else if (option == 0)
{
// Exit program
break;
}
}
}
#endif