Programming Report
Programming Report
ASD2
Programming Report of Mini-Project 2
Introduction:
In this mini-project that has been presented to us, we are concerned with making a patient diagnosis system
employing linked lists to store and manage a healthcare environment efficiently, this will take form as a
computer program written in the C programming language.
To realize this tangible result, we have gone with a paradigm similar in merit to the standard scientific
method; that is:
Observation → Question → Hypothesis → Experiment → Analysis → Conclusion
However, it was slightly altered to account for the nature of mathematical and logical problems into:
Observation → Question → Analysis → Hypothesis → Experiment → Conclusion
We also had to take into consideration some obstacles that may arise such as:
-The inherent limitations of the computational machine that we are using.
-The syntactic restrictions imposed by the C programming language.
Problematic:
The preceding problem can be broken down into 4 individual parts
Part 1: Patients
In this part, we want to define a patient record with various fields, namely:
● Patient ID
● Full Name
● Age
● Gender
● Height
We also want to define some actions involving the management of said records, such as:
● Patient ID
● Diagnosis
● Diagnosis date
● Next appointment date
And we also have to implement the same actions as the patient’s for the diagnostics:
Part 3: Doctor
We have to then make another system for recording doctors, this will be done the same way as the
previously aforementioned parts, the doctor will have 3 fields:
● Doctor ID
● Full name
● Specialty
The doctor system will have the same functions as the previous 2 systems.
Part 4: Link Up
Here we have to link up the diagnoses to their respective doctor who performs them which will be identified
by hi doctor ID.
Analysis:
To analyze this problem we must break down each sub-problem and articulate each input and output that
they will take and give, since some aspects of this solution are rather trivial we will only focus on the main
problems, those being:
1) This problem requires the use of dynamic data structures since the amount of space needed for this
program is initially unknown, thus we will implement a clever tool called a linked list in order to
dynamically hold the information necessary for this program .
2) The nature of this problem demands a sort of graphical user interface and hence we will have to
improvise one in the command prompt along with a system for navigating different interfaces based
on user input.
3) This project will require a lot of repetitive code and so it would make sense to utilize an abstraction
method called modules or subprogramming, which will then let us reuse our code but in a more
readable and maintainable manner.
We will discuss the problems stated above in much more details in the algorithm and programming part, for
now we will concentrate on the fundamentals.
We have already determined that the dynamic data management will be implemented using linked lists.
Linked lists are a data structure consisting of a sequence of elements, each containing a pointer to the next
element in the sequence containting its address as shown in the diagram below. This allows for efficient
insertion and deletion of elements, as the structure does not require continuous memory allocation.
We have to then understand how each of the operations on the linked list will take place, and for that we will
have to do some analysis
Adding an Element
To add an element we have to do an interesting manoeuvre called prepending since it is easier and since the
order of our items does not matter, its steps are as follows
1. Create an empty record node for either one of our examples (patient, diagnostic, or doctor).
2. Fill in the information we need.
3. Set it to point at what the head is pointing at.
4. Set the head to point at our new node.
We have gone with inputing the data straight from the user rather than pluging them as input into a function.
Deleting an Element
The process for this is fairly basic and just requires some more techniques, they go as follows.
Updating an Element
This is by far the simplest action as we just need to locate our target node by inputing its address and
refilling all our information.
Printing an Element
Here we will find our target node and then write each element in a neatly formatted string.
Searching an Element
To implement this we will take an ID as input and give us the address of the node containing said ID by:
We have to present the user with a user interface that they can interact with and navigate around, the user
should be able to switch between interfaces or go back to the previous interface or even exit the program
should he desire to.
The way we have implemented this is by using nested do while loops and, a global state variable, and switch
statements such that the program will initially start with a global state of 1 and display some options, it will
keep prompting us for a choice until we either choose to exit the program or pick an option, once we do, it will
increase the state and put us in another do while loop on the condition that the state does not change,
because if it does, that means we have either went back to state 1 ( the starting interface ) or are going to
perform an option after which we will repeat prompting the user for their next action.
Algorithm:
To get the expected result we must first evaluate our inputs and outputs and create some base algorithms
that we will use as the primary building blocks for our full-fledged program, we will state the algorithms
necessary for each part of this problem along with their respective application:
We can assume that the node record will look something like this:
Else
while(curr != NULL)
Begin
If (next(curr) == target)
Begin
Next = next(next(curr))
free(next(curr))
curr = next
End
End
End
End
And finally we can add a function to search patients using their IDs
Function: search
Input: ID : integer
Output: target: ^node
Variables: iterator: ^node
Start
Iterator = listHead
while( iterator != NULL)
Begin
if(iterator^.ID == ID)
Return iterator
Else
Iterator = next(iterator)
End
Procedure: RenderStartingScreen
Start
state = 2
Repeat
write(“Welcome . . . “)
read(choice)
switch(choice)
Case 1:
RenderScreen1()
….
Case N:
RenderScreenN()
until( state == 2)
Program:
Part 1: The basics
Here we will look into the equivalent of the algorithms in the C programming language and the actual
applications that will be executed by the computer:
First we start by importing some libraries, the stdio.h library which contains the functions we will use to
print messages onto the terminal, and the stdlib.h library which has the function malloc() which we will use to
allocate memory with.
Then we will declare the some color constants to print colored text which will be much more presentable.
And then define the record structures for the patients, diagnostics, and doctors.
Next we’ll define empty linked lists and the state and choice as global variables.
Part 2: Linked list manipulation
we will present the code for operations on linked lists using only patient examples but note that these can
apply to any of the other systems.
Adding a patient.
void addPatient(){
//flag on success
printf( GREEN "patient added, id: %i\n\n" RESET,newPatient->patientID);
}
Printing a Patient
void printPatient(struct patient* target){
Searching a Patient
Deleting a Patient
void deletePatient(struct patient* target){
//declare traversing pointers
struct patient* currNode = patientList;
struct patient* nextNode = NULL;
Updating a Patient
void printAllpatients(){
if (patientList == NULL)
{
printf(RED"\nThere are currently no patients registered\n\n" RESET);
}else{
struct patient* p = patientList;
printf("\n******************************************************************\n");
for (int i = 1; p!= NULL; i++)
{
printf("%i: ",i);
printPatient(p);
p = p->next;
}
printf("\n******************************************************************\n");
And finally we made a function that converts diagnosis and specialty enumerations to strings for printing
messages.
We will use the a clever technique to create a terminal user interface using a bunch of do while loops and
switch statements, first we start by defining a function that renders the main screen
void RenderStartingScreen(){
state = 1;
printf(BLUE"\nPATIENT DIAGNOSTIC SYSTEM (by Islam)"RESET);
printf("\n\nWhat would you like to manage?.\n\n1)Patients\n2)Diagnoses\n3)Doctors\n4)Exit program\n\n choice: ");
scanf("%i",&choice);
switch (choice)
{
case 1:
RenderPatientScreen();
break;
case 2:
RenderDiagnosticScreen();
break;
case 3:
RenderDoctorScreen();
break;
case 4:
state--;
break;
default:
printf(RED"\n\nPlease enter a valid choice\n\n"RESET);
break;
}
}
// MAIN THREAD
int main(void){
state = 1;
do
{
RenderStartingScreen();
} while (state == 1);
return 0;
}
Notice how this will keep repeating aslong as we don’t pick 4 ( exit ) which will promptly decrease the state
causing us to exit the loop and thus exit the program, however if we pick any other option then we will run into
one of the other rendering functions, let’s take RenderPatientScreen() for example.
void RenderPatientScreen(){
// set to next state
state = 2;
int id;
do
{
printf(BLUE"\nPatient Management:"RESET);
// determine what action needs to be done
printf("\n\n1)Add patient\n2)Update patient\n3)Delete patient\n4)View all
patients\n5)Back\n\nChoice:");
scanf("%i",&choice);
switch (choice)
{
case 1:
addPatient();
break;
case 2:
// unless if the list is empty search for the patient and update it
if(patientList != NULL){
printf("Enter the ID of the patient you want to Update: ");
scanf("%i",&id);
if(searchPatient(id)!=NULL){
updatePatient(searchPatient(id));
}
break;
//otherwise it will not
}else{printf(RED"\nThere are currently no patients registered\n\n" RESET);break;}
case 3:
//will delete the wanted node if the list is not empty
if(patientList!=NULL){
printf("Enter the ID of the patient you want to Delete: ");
scanf("%i",&id);
if(searchPatient(id)!=NULL){
deletePatient(searchPatient(id));
}
break;
// otherwise output a message
}else{printf(RED"\nThere are currently no patients registered\n\n" RESET);break;}
case 4:
printAllpatients();
break;
case 5:
// break out of the loop to return to previous interface
state--;
break;
default:
// error message in unexpected cases
printf(RED"\n\nPlease enter a valid choice\n\n"RESET);
break;
}
} while (state == 2);
Notice how this function will also keep repeating aslong as the state is 2 unless we either input 5 which will
cause us to exit out of this loop back to our original loop (the starting screen) or if input one of the options it
will perform the action and then reprompt our menu.
Part 4: Linking diagnostics
All we have to do here is make an extra field for every doctor record which will be a pointer to a diagnostic
which will serve as the head of a new linked list, we will then also have to add a field for the diagnostics
record to have a pointer for the next element in the list of diagnoses appointed to the doctor.
void addDiagnosticToDoctor(){
state = 3;
int diagid;
int docid;
struct doctor* doctor;
struct diagnostic* diagnostic;
do
{
//prints diagnostics for context
printAllDiagnostics();
}else{appendDiagnotic(doctor,diagnostic);}
state--;
break;
case 3:
case 4:
if (doctor->specialty != 2)
{
printf(RED"\nDoctor is not qualified."RESET);
}else{appendDiagnotic(doctor,diagnostic);}
state--;
break;
case 5:
case 6:
if (doctor->specialty != 3)
{
printf(RED"\nDoctor is not qualified."RESET);
}else{appendDiagnotic(doctor,diagnostic);}
state--;
break;
default:
printf(RED"\n\nPlease enter a valid response\n\n"RESET);
break;
}
}
}
In wich we call a function append diagnostic that will simply prepend the node onto the list.
Conclusion:
In this problem, we were focused on the developpment of a patient diagnosis system for healthcare and
after careful analysis we used a combination of clever techniques and tools like linked lists and control
structures to eventually materialise it into a working program.
While this program is relatively efficient and gets the job done we also recognize the capacity for
improvements, whether it is using a different control structure or a more optimal algorithm, however this is
what our minds came up with and we have executed it to the best of our abilities.
By contrasting this solution with the works of our peers, we found much more interesting approaches to this
problem and hence by experience we have come to realize the necessity of collaboration.