(last revision Sept 28, 1997) ////////////////////////////////////////////////// CS 3100 PROGRAMMING ASSIGNMENT #02 -- The Medical Clinic ////////////////////////////////////////////////// Level #1 DUE October 03, 1997 Level #2 DUE October 10, 1997 Final Level DUE October 20, 1997 ASSIGNMENT # 02 Please read the class documents entitled: programAssignmentRules, sampleProgramSubmission-level01, sampleProgramSubmission-level02, sampleProgramSubmission-level03, howToMakeTestScript-level01, sampleTestScript-level01, sampleTestScript-level02, and sampleTestScript-level03 before beginning to do this programming assignment. You will find the documents under "CourseDocuments" in the class directory. Also, be sure to ask questions in class! The Medical Clinic This problem is a version of one of the programming assignments found in an early edition of Pascal Plus Data Structures, by Nell Dale and Susan C. Lilly. We will pretend that the local medical clinic has decided to automate scheduling services, and you have been assigned to design the initial version (prototype) of the scheduler. The basic functions that the clinic has in mind are doctor check-in and check-out and patient check-in and check-out. A doctor checking-in tells the scheduler his name, an examination room number, and a specialist code that tells what kind of doctor he is. The doctor is likely to have a favorite examination room. The scheduler checks to see if the room specified by the physician is free. If so, it assigns the doctor to the room. If not, it rejects the request with a message, and if the doctor still wants to check-in, he has to go through the check-in procedure from the beginning. When a doctor checks-out, the examination room is freed. In the (unusual) event that a doctor checks-out when there are still patients waiting to see him, the patients have to be reassigned, if possible, to other doctors in the clinic. If there are no doctors left in the clinic, the remaining patients have to be told to go find another hospital. A patient checking-in gives a name, age, specialist code, and emergency indication (the emergency indication is basically just a yes/no variable (a flag) that says whether the patient's problem requires immediate attention). The scheduler decides what to do with the patient by following a set of rules which will be described below. Patients who are being reassigned as described in the previous paragraph are handled using the same set of rules. If there are any doctors at all in the clinic, a patient requesting to be checked-in, or being reassigned, is placed in a dequeue -- a structure much like a queue, except that it is possible for the patient to be inserted either at the front, or the rear of the dequeue, according to the emergency indication. Usually the patient is put at the rear of a dequeue. If, however, the patient's problem is an emergency, he is put at the front, ahead of any other patients. The patient at the front of a dequeue is the one currently being seen by the doctor. The rules for assigning patients to doctors are as follows. Note that the scheduler has to obey every one of these rules every time that it handles a request from a patient to check-in, and every time it reassigns a patient whose doctor checked-out before seeing him. 1. If the patient is 9 years of age or younger, and if a pediatrician is available, then the patient must be assigned to see a pediatrician 2. If the patient is of age greater than 9, but not over 17, and if a general practitioner is available, then the patient must be assigned to a general practitioner. 3. If the patient is of age greater than 17, and if a specialist of the type requested by the patient is available, then the patient must be assigned to such a specialist. 4. If following rules 1 - 3 does not result in finding a doctor to whom to assign the patient, and if a specialist in general practice, internal medicine, pediatrics, or obstetrics is available, then the patient must be assigned to one of those specialists. 5. If following rules 1 - 4 does not result in finding a doctor to whom to assign the patient, then the patient can be assigned to a doctor with any speciality. 6. If there is a group of two or more doctors in the clinic that the rules allow the current patient to be assigned to, then the patient must be assigned to a doctor in that group whose dequeue is of minimal length. 7. In the event that there are no doctors at all in the clinic, the patient must be told to go find another hospital. INPUT: This will be an interactive program. It must prompt the users to input the correct information. The initial prompt must be: `TYPE D FOR DOCTOR OR P FOR PATIENT: ' The next prompt must be: `TYPE I FOR CHECK-IN OR O FOR CHECK-OUT: ' According to the request, your program must prompt the user for additional information. Below is a table with the information that must be requested for each type of job. You must ask for precisely this information, with no changes. JOB INFO NEEDED Doctor check-in ....... doctor name room number specialty code Doctor check-out ...... room number Patient check-in ...... patient name patient age specialty (code requested) emergency flag Patient check-out ..... patient name room number You will decide upon and implement the format for the input processed and the other prompts printed by your program. The entire interaction with the user MUST be conducted so that the program is EASY and FAST to use. In order to accomplish this you must give the user the DIRECTIONS he needs to receive from the program, WHEN he needs them. Keep in mind the fact that you are writing this program for someone who knows generally what it is supposed to do, but does not know all the details of how the program expects to communicate with him. Your program should help this person by telling him the things he does not know, but needs to know to run the program. Don't waste his time, though, by giving him information that he obviously already has, or does not need. Remember that when I test your program, I am probably going to be using it for the very first time, and I will have many similar programs to run that day. You ought not to make me work too hard to get your program to do what I need it to do. All input must be read in as character data -- in other words every character in the in the input must be read into a variable whose data type is "char". All input routines must be carefully written so that slight mistakes in input do not crash the program. It is alright to handle cases of incorrect input by starting the current check-in or check-out over again. OUTPUT: The output for each request is in the form of messages to the user in accordance with the request. The program will loop, processing one request for check-in or check-out per cycle. After handling each request, the program will ask the user if he wishes to see the STATE of the clinic -- the contents of the dequeues, the current assignments of doctors to examination rooms, and the respective specialty codes of each doctor. When showing the contents of the dequeues, you must include the name, age, specialty code requested, and emergency indication given, for each patient, and you must list patient information in front-to-rear order. When the user asks for it, the program will show the state information in a CLEAR, COMPACT format which is easy to read. COMPACT means don't be "greedy" about the amount of space you take to print things. (Please don't do "clear screen" operations of any kind.) There is a trade-off involved here. If you use too much space then very little information can be seen on the screen at any given time. If you use too little space, the eye has difficulty picking out the information. Unless a proper balance is achieved, the display will lack intelligibility. At the end of each cycle, the scheduler program will ask the user if he wants to terminate execution of the program or go on, and will halt or start another cycle depending on the reply. Here is a table showing what sorts of messages must be printed for each type of job: JOB TYPE OF MESSAGE REQUIRED Doctor check-in ....... confirmation that room is available or error message if room is in use. Doctor check-out ....... goodbye message to doctor, and messages indicating what was done with any patients left in the doctor's dequeue when the doctor checked out. (It is possible that some waiting patients may have to be told to find another hospital if the last physician in the clinic decides to leave while patients are still there.) Patient check-in ....... message telling patient which room to go to and which doctor has been assigned, if applicable. If the patient has had to be assigned, or reassigned, to a type of specialist that he did not request, or if no doctors are in the clinic at all, an appropriate message of apology. Patient check-out ..... goodbye message, or error message if an attempt is made to check-out a patient that has not reached the front of a dequeue. DETAILS AND ASSUMPTIONS 1. There are 6 examination rooms at the clinic, each with a dequeue attached. 2. Specialty codes are: PED Pediatrics GP General Practice INT Internal Medicine CARD Cardiology SUR Surgeon OBS Obstetrics PSY Psychiatry NEUR Neurology ORTH Orthopedics DERM Dermatology OPH Ophthalmology ENT Ear, Nose, and Throat The user is allowed to type these codes in any combination of upper and lower case characters -- e.g. Neur, EnT, oph, DERM. 3. You may assume that no patient leaves without checking out. DATA STRUCTURES The basic data structure is a group of examination rooms with a dequeue attached to each. Since the number of rooms is fixed and it will be convenient to have random access to the rooms, it seems that an array of records is a logical way to represent the group of rooms. You must design the data structures used for this program. You are answerable for the wisdom and efficacy of your choice. You must implement each data structure in a way consistent with the DEFINITION we have chosen for the term "Data Type" -- a set of data values together with operations on those data values. We will have class discussion regarding the design decisions. Keep in mind that you have to maintain some sort of access to critical data. One example is that the number of patients in each dequeue becomes important when there are two or more doctors available with a specialty requested by an adult patient. This is a small detail, but there are many such details that you must try to consider early in your design of the program. Before deciding on the final form of each data structure, write a description of each operation your program will need to perform on the data, and what information each such operation will need to use. Look in your textbook for examples of properly specified and implemented data types and data structures. You need to create a package of code that implements the values and operations of each data structure. This should be done in a way that separates the different packages, or modules, from each other as completely as possible, in order to achieve the goals of modular code, top down design, data encapsulation, and information hiding. If you don't remember exactly what all these terms mean, then review them in our text, or review them the text book you had for your second programming course, or ask me. Proper design methodology is very important.