Tuesday, November 28, 2017

Programming Challenge 13.20 - Patient Fees

Example Files: PatientFees.7z

PatientAccount.h


#ifndef PATIENT_ACCOUNT_H_
#define PATIENT_ACCOUNT_H_

#include <string>
using std::string;

#include <vector>
using std::vector;

class Patient
{
    private:
        const double DAILY_RATE = 45.99;

        const vector<int> patientID{ 153565, 453245, 243343 };
        const vector<string> patientName{ "Marie J. Holden", "Larry J. Ingols", "Esther P. Reese" };

        int    recordID;                        // Stores a patients' record ID
        string performedSurgery;            // Holds the name of a performed surgery
        string administeredMedication;    // Holds the name of the administered medication
        int    numDaysStay;                    // Holds the number of days of stay of a patient
        double surgeryCharge;                // Holds the surgery charge
        double medicationCharge;            // Holds the medication charge
        double stayCharge;                    // Holds the charge for a given number of days
        double totalCharge;                    // Holds the total charges
       
    public:
        Patient();

        void outputRecords();
        void setRecordID();
        void setNumDaysStay();
        void setSurgeryCharge(double);
        void setPerformedSurgery(string);
        void setAdministeredMedication(string);
        void setMedicationCharge(double);
        void calcCharges();

        int getRecordID() const
        { return recordID; }

        double getNumDaysStay() const
        { return numDaysStay; }

        double getStayCharge() const
        { return stayCharge; }

        string getAdministeredSurgery() const
        { return performedSurgery; }

        double getSurgeryCharge() const
        { return surgeryCharge; }

        string getAdministeredMedication() const
        { return administeredMedication; }

        double getMedicationCharge() const
        { return medicationCharge; }

        double getTotalCharge() const
        { return totalCharge; }

        double getDailyRate() const
        { return DAILY_RATE; }

        int getPatientID(int pID)
        { return patientID[pID]; }

        string getPatientName(int pID)
        { return patientName[pID]; }
};

#endif

PatientAccount.cpp


#include "PatientAccount.h"

#include<iomanip>
using std::left;
using std::right;
using std::setw;

#include <iostream>
using std::cin;
using std::cout;

/* **********************************************************
            Patient::Patient() - Default Constructor
   ********************************************************** */

Patient::Patient()
{
    recordID = 0;
    performedSurgery = "";
    administeredMedication = "";
    numDaysStay = 0;
    surgeryCharge = 0.0;
   medicationCharge = 0.0;       
    stayCharge = 0.0;
    totalCharge = 0.0;
}

/* **********************************************************
            Patient::outputRecords()
    This function outputs a list of patient ID numbers and
    names.
   ********************************************************** */

void Patient::outputRecords()
{
    int cnt = 1;

    auto itID = patientID.begin();
    auto itName = patientName.begin();

    for (; itID != patientID.end() && itName != patientName.end(); ++itID, ++itName)
    {
        cout << (cnt++) << ": " << setw(24) << left << (*itID)
                                        << right << (*itName) << "\n";
    }
}

/* **********************************************************
            Patient::setRecordID()
    This function asks the user to enter a number to retrieve
    that particular patients' record.
   ********************************************************** */

void Patient::setRecordID()
{
    int tempRecID = 0;

    cout << "\n\nPATIENT RECORD DEPARTMENT\n\n";
    cout << "   Patient ID" << setw(27) << "Patient Name\n";
    cout << "------------------------------------------\n";

    outputRecords();

    cout << "\nEnter patients record number (1-3): ";
    cin >> tempRecID;

    while (tempRecID <= 0 || tempRecID > patientID.size())
    {
        cout << "Enter patients record number (1-3): ";
        cin >> tempRecID;
    }

    recordID = tempRecID - 1;
}

/* **********************************************************
            Patient::setNumDaysStay()
    This function asks the user to enter the numbers of days
    a patient stayed in the hospital.
    ********************************************************** */

void Patient::setNumDaysStay()
{
    cout << "\nEnter number of days of stay (min: 1 day): ";
    cin >> numDaysStay;

    while (numDaysStay <= 0)
    {
        cout << "Enter number of days of stay (min: 1day): ";
        cin >> numDaysStay;
    }
    cout << "\n\n";
}

/* **********************************************************
            Patient::setPerformedSurgery() : string
    This function accepts a string object, holding the name of
    the surgery having been performed. It gets assigned to the
    performedSurgery member variable.
   ********************************************************** */

void Patient::setPerformedSurgery(string sType)
{
    performedSurgery = sType;
}

/* **********************************************************
            Patient::setAdministeredMedication() : string
    This function accepts a string object, holding the name of
    the medication administered to a patient. It gets assigned
    to the administeredMedication member variable.
   ********************************************************** */

void Patient::setAdministeredMedication(string mType)
{
    administeredMedication = mType;
}

/* **********************************************************
            Patient::setSurgeryCharge() : double
    This function accepts a double, holding the cost of the
    surgery performed on the patient. It gets assigned
    to the surgeryCharge member variable.
   ********************************************************** */

void Patient::setSurgeryCharge(double sChrg)
{
    surgeryCharge = sChrg;
}

/* **********************************************************
            Patient::setSurgeryCharge() : double
    This function accepts a double, holding the cost of the
    medication administered to the patient. It gets assigned
    to the medicationCharge member variable.
   ********************************************************** */

void Patient::setMedicationCharge(double medChrg)
{
    medicationCharge = medChrg;
}

/* **********************************************************
            Patient::calcCharges()
    This function calculates the charges the patient has to
    pay.
    ********************************************************** */

void Patient::calcCharges()
{
    stayCharge = (numDaysStay * DAILY_RATE);
    totalCharge = (surgeryCharge + medicationCharge + stayCharge);
}

Surgery.h


#ifndef SURGERY_H_
#define SURGERY_H_

#include "PatientAccount.h"

#include <string>
using std::string;

#include <vector>
using std::vector;

class Surgery
{
    private:
    const    vector<string> surgeryType{ "Pneumonectomy", "Otoplasty", "Neurosurgery", "Gastropexy", "Cardiotomy" };
   const vector<double> charge{ 1460.75, 1250.35, 2750.95, 1760.45, 4730.25 };

        Patient &patient;

    public:
        // Constructor accepting a reference to a Patient class object
        Surgery(Patient &p) : patient(p)       
        {
        }

        void outputProcedures();
        void setSurgeryType();
        void updatePatientRecord(int);
};

#endif

Surgery.cpp


#include "Surgery.h"

#include <iomanip>
using std::left;
using std::right;
using std::setw;

#include <iostream>
using std::cin;
using std::cout;

/* **********************************************************
            Surgery::outputProcedures()
    This function outputs the surgical procedure names and
    charges.
   ********************************************************** */

void Surgery::outputProcedures()
{
    int cnt = 1;

    auto itSurgery = surgeryType.begin();
    auto itCharge = charge.begin();

    for (; itSurgery != surgeryType.end() && itCharge != charge.end(); ++itSurgery, ++itCharge)
    {
        cout << (cnt++) << ": " << setw(30) << left << (*itSurgery)
                                        << right << "$ " << (*itCharge) << "\n";
    }
}

/* **********************************************************
            Surgery::setSurgeryType()
    This function asks the user to enter a number for the
    type of surgery having been performed.
   ********************************************************** */

void Surgery::setSurgeryType()
{
    int sProcNum = 0;

    cout << "\n\nBILLING SYSTEM - SURGERY DEPARTMENT\n\n";
    cout << setw(3) << "   Type of Surgery" << setw(25) << "Cost\n";
    cout << "------------------------------------------\n";

    outputProcedures();

    cout << "\nEnter number: ";
    cin >> sProcNum;

    while (sProcNum <= 0 || sProcNum > surgeryType.size())
    {
        cout << "Enter number: ";
        cin >> sProcNum;
    }

    updatePatientRecord(sProcNum - 1);
}

/* **********************************************************
            Surgery::updatePatientRecord()
    This function updates two patient class member variables.
    It assigns to them the name of a surgery and a charge.
   ********************************************************** */

void Surgery::updatePatientRecord(int typeNum)
{
    patient.setPerformedSurgery(surgeryType[typeNum]);
    patient.setSurgeryCharge(charge[typeNum]);
}

Pharmacy.h


#ifndef PHARMACY_H_
#define PHARMACY_H_

#include "PatientAccount.h"

#include <string>
using std::string;

#include <vector>
using std::vector;

#include <iostream>
using std::cout;

class Pharmacy
{
    private:
    const vector<string> medicationName{ "Albendazole 200 mg", "Pyrazinamide 400 mg",
                                                   "Ketamine 20 ml", "Bisacodyl 5 mg", "Lamotrigine 100 mg" };
    const vector<double> charge{ 12.35, 15.99, 12.13, 16.53, 25.99 };

     Patient &patient;

    public:
        // Constructor accepting and initializing a reference to a Patient object
        Pharmacy(Patient &p) : patient(p)
        {
        }

        void outputMedication();
        void setMedicationType();
        void updatePatientRecord(int);
};

#endif

Pharmacy.cpp


#include "Pharmacy.h"

#include <iomanip>
using std::left;
using std::right;
using std::setw;

#include <iostream>
using std::cin;
using std::cout;

/* **********************************************************
            Pharmacy::outputMedication()
    This function outputs the medication names and charges.
   ********************************************************** */

void Pharmacy::outputMedication()
{
    int cnt = 1;

    auto itMedication = medicationName.begin();
    auto itCharge = charge.begin();

    for (; itMedication != medicationName.end() && itCharge != charge.end(); ++itMedication, ++itCharge)
    {
        cout << (cnt++) << ": " << setw(31) << left << (*itMedication)
                                        << right << "$  " << left << (*itCharge) << "\n";
    }
}

/* **********************************************************
            Pharmacy::outputMedication()
    This function asks the user to enter a number to retrieve
    the type of medication having been administered.
   ********************************************************** */

void Pharmacy::setMedicationType()
{
    int productNum = 0;

    cout << "\n\nBILLING SYSTEM - PHARMACOLOGY DEPARTMENT\n\n";
    cout << setw(3) << "   Name of Medicine" << setw(24) << "Cost\n";
    cout << "------------------------------------------\n";

    outputMedication();

    cout << "\nEnter product ID: ";
    cin >> productNum;

    while (productNum <= 0 || productNum > medicationName.size())
    {
        cout << "Enter product ID: ";
        cin >> productNum;
    }

    updatePatientRecord(productNum-1);
}

/* **********************************************************
            Pharmacy::updatePatientRecord()
    This function updates two patient class member variables.
    It assigns to them the name of a medication and a charge.
   ********************************************************** */

void Pharmacy::updatePatientRecord(int typeNum)
{
    patient.setAdministeredMedication(medicationName[typeNum]);
    patient.setMedicationCharge(charge[typeNum]);
}

PatientFees.cpp


#include "PatientAccount.h"
#include "Surgery.h"
#include "Pharmacy.h"

#include <iomanip>
using std::right;
using std::left;
using std::setw;
using std::fixed;
using std::setprecision;

#include <iostream>
using std::cin;
using std::cout;

const enum Options { CHECKOUT = 'C', PRINT_FORM = 'P', QUIT = 'Q' };

void outputCheckoutReport(Patient &);

int main()
{
    const int NUM_RECORDS = 3;

    char choice = ' ';

    Patient patient;
    Pharmacy medication(patient);
    Surgery surgery(patient);

    do
    {
        cout << "\nMt. RAKUTEI HOSPITAL - FRONT DESK\n\n";
        cout << "[C] PATIENT CHECKOUT\n"
              << "[P] PRINT CHECKOUT FORM\n"
             << "[Q] QUIT\n\n";

        cout << "Select Option: ";
        cin >> choice;
        cin.ignore();

        switch (choice)
        {
            case CHECKOUT:
            {
                patient.setRecordID();
                surgery.setSurgeryType();
                medication.setMedicationType();
                patient.setNumDaysStay();
                patient.calcCharges();
            } break;

            case PRINT_FORM:
            {
                outputCheckoutReport(patient);
            } break;
        }
    } while (choice != QUIT);

    return 0;
}

void outputCheckoutReport(Patient &patient)
{
    string eLine = "------------------------------------------\n";
    string qLine = "==========================================\n\n";

    cout << fixed << setprecision(2);
    cout << "\n\nPATIENT CHECKOUT REPORT\n\n";
    cout << "Patient ID" << setw(33) << right << "Patient Name\n";
    cout << eLine;
    cout << setw(27) << left << patient.getPatientID(patient.getRecordID())
          << setw(5) << right << patient.getPatientName(patient.getRecordID()) << "\n";
    cout << qLine;

    cout << "Type of Surgery\n";
    cout << eLine;
    cout << setw(33) << left << patient.getAdministeredSurgery()
          << right << "$ " << patient.getSurgeryCharge() << "\n";
    cout << qLine;
   
    cout << "Administered Medication\n";
    cout << eLine;
    cout << setw(33) << left << patient.getAdministeredMedication()
          <<  "$  " << setw(6) << right << patient.getMedicationCharge() << "\n";
    cout << qLine;

    cout << "Days of Stay" << setw(31) << "Daily Rate\n";
    cout << eLine;
    cout << setw(35) << "$ " << setw(7) << right << patient.getDailyRate() << "\n";
    cout << eLine;
    cout << setw(33) << left << patient.getNumDaysStay()
           << "$  " << setw(6) << right << patient.getStayCharge() << "\n";
    cout << qLine;

    cout << setw(33) << left << "Total Charge: "
          << "$ " << right << patient.getTotalCharge() << "\n";
    cout << qLine;
}


Example Output:




No comments:

Post a Comment