Clinic Management System in C++ | Codewithrandom

Clinic Management System in C++ | Codewithrandom 

Clinic Management System in C++ | Codewithrandom

Introduction

Hello, learners. I hope you are all doing well. If you have been following us for a while, We hope that you are following our C++ projects. Today we will make a clinic management system using simple C++ concepts. I will be explaining the code if there is any hard part.

This project is beginner-friendly. Anyone who knows the overview of concepts like structures and linked lists can understand it easily.

If you are not familiar with the linked list concept, I will explain it in the coming sections.


User Interface and Working

The starting User Interface Image is seen above the Introduction section.

Let’s discuss each option in detail.


1)Adding patients record:


Clinic Management System in C++ | Codewithrandom


The first thing to do in a clinic management system is to have data about the patients. So we will use this option where we add the following information.

  • Patient’s ID
  • Patient’s First Name
  • Patient’s Last Name
  • patient’s Age 
  • Patient’s Gender
  • Patient’s Blood Group
  • Patient’s Contact
  • Patient’s CNIC(National Level ID)
  • Patient’s Address

These are just the necessary things to be taken from a patient before the doctor’s visit.


2)Adding the Patient’s prescription:


Clinic Management System in C++ | Codewithrandom


Once the patient is at the doctor, we need a way to take the patient’s input about the symptoms and diagnose them.

We should also provide more information like the tablets to be used.

(NOTE: Enter multiple things using a comma as a separation.)


3)Full History of a Patient:


Clinic Management System in C++ | Codewithrandom


If we want to view the history of a patient, we will use the patient’s ID assigned by us to display it.

ADVERTISEMENT

We will display the information we took in the first and second options combined.

ADVERTISEMENT


ADVERTISEMENT

4)Delete Patient Record:


In general, the clinic should have a record of basic information, to use the next time. 

ADVERTISEMENT

But, we provide an option to delete a record if needed.

ADVERTISEMENT

It is to learn the concept that we use in the project.


5) Update Patient Record 


Clinic Management System in C++ | Codewithrandom

In case the patient’s details need to be changed, instead of deleting we can use this option. 

It includes the contact numbers, addresses, medicines, symptoms.


In our project, we give the user the advantage of editing only the needed field instead of re-writing the whole information.


That is the explanation User Interface of the app and its functions.

Now let’s see the concepts we have to know to understand them clearly.


Concepts Used

  1. Structures
  2. Linked lists
  3. Classes and objects

1) Structures :

In C++ are user-defined data types, used to store a group of items of non-similar data types. 

We will use it to create variables that can be used when we need them.


2)Linked Lists:


A linked list is a linear data structure in which the elements aren’t stored at contiguous memory locations. The elements in a linked list are linked using pointers. 


3)Classes and Objects.


Classes in any language follow the OOP’s concepts such as abstraction, encapsulation, security, etc. So, we use objects to access the variables and methods inside a class. Objects are the instance of a class. 


Code


1:    
2: #include<iostream>
3: #include<ctime>
4: #include<cstdlib>
5: using namespace std;
6: struct node
7: {
8: char fname[20];
9: char sname[20];
10: char address[200];
11: char contact[10];
12: char cnic[100];
13: int age;
14: char gender[8];
15: char blood_gp[5];
16: char disease_past[50];
17: int id;
18: char symptom[500];
19: char diagnosis[500];
20: char medicine[500];
21: char addmission[30];
22: struct node *next;
23: bool diagnose;
24: };
25: struct node *head,*lastptr;
26: bool check=true;
27: int arr[20]={0},i=0;
28: bool check_id(int ch)
29: {
30: for(int a=0;a<i;a++)
31: {
32: if(ch==arr[a])
33: {
34: return true;
35: }
36: }
37: return false;
38: };
39: class doctor
40: {
41: public:
42: void add()
43: {
44:
45: node *p;
46: p=new node;
47: p->diagnose=false;
48: cout<<"enter Patient ID"<<endl;
49: cin>>p->id;
50: cout<<"enter Patient First name"<<endl;
51: cin>>p->fname;
52: cout<<"enter Patient Last name"<<endl;
53: cin>>p->sname;
54: cout<<"enter Patient Age"<<endl;
55: cin>>p->age;
56: cout<<"enter Patient Gender"<<endl;
57: cin>>p->gender;
58: cout<<"enter Patient Blood Group"<<endl;
59: cin>>p->blood_gp;
60: cout<<"enter Patient Contact "<<endl;
61: cin>>p->contact;
62: fflush(stdin);
63: cout<<"enter Patient CNIC"<<endl;
64: cin.getline(p->cnic,100);
65: fflush(stdin);
66: cout<<"enter Patient Address"<<endl;
67: cin.getline(p->address,1000);
68:
69: p->next=NULL;
70: arr[i]=p->id;
71:
72: i++;
73: if(check)
74: {
75: head=p;
76: lastptr=p;
77: check=false;
78: }
79: else
80: {
81: lastptr->next=p;
82: lastptr=p;
83: }
84:
85: }
86: void show()
87: {
88: int n;
89: node *current=NULL,*prev=NULL;
90: prev=head;
91: current=head;
92: int ch;
93: cout<<"enter Patient ID"<<endl;
94: cin>>ch;
95: if(check_id(ch))
96: {
97: while(current->id!=ch)
98: {
99: prev=current;
100: current=current->next;
101: }
102:
103: cout<<"enter Patient First name"<<endl;
104: cout<<current->fname<<endl;
105: cout<<"enter Patient Last name"<<endl;
106: cout<<current->sname<<endl;
107: cout<<"enter Patient ID"<<endl;
108: cout<<current->id<<endl;
109: cout<<"enter Patient Age"<<endl;
110: cout<<current->age<<endl;
111: cout<<"enter Patient Gender"<<endl;
112: cout<<current->gender<<endl;
113: cout<<"enter Patient Blood Group"<<endl;
114: cout<<current->blood_gp<<endl;
115: cout<<"enter Patient Contact "<<endl;
116: cout<<current->contact<<endl;
117: cout<<"CNIC number"<<endl;
118: cout<<current->cnic<<endl;
119: cout<<"enter Patient Address"<<endl;
120: cout<<current->address<<endl;
121: cout<<"*********************************"<<endl;
122: if(current->diagnose){
123: cout<<"Enter Symptoms"<<endl;
124: cout<<current->symptom<<endl;
125: cout<<"Enter Diagnosis"<<endl;
126: cout<<current->diagnosis<<endl;
127: cout<<"Enter Medicines"<<endl;
128: cout<<current->medicine<<endl;
129: cout<<"Admit Required to Hospital?"<<endl;
130: cout<<current->addmission<<endl;
131: }}
132: else
133: {
134: cout<<"ID not present"<<endl;
135: }
136: }
137: void diagnosis()
138: {
139: int n;
140: node *p=NULL,*prev=NULL;
141: p=new node;
142: prev=head;
143: p=head;
144: int ch;
145: cout<<"enter Patient ID"<<endl;
146: cin>>ch;
147: if(check_id(ch)){
148: while(p->id!=ch )
149: {
150: prev=p;
151: p=p->next;
152: }
153: p->diagnose=true;
154: cout<<"Enter Symptoms"<<endl;
155: cin>>p->symptom;
156: cout<<"Enter Diagnosis"<<endl;
157: cin>>p->diagnosis;
158: cout<<"Enter Medicines"<<endl;
159: cin>>p->medicine;
160: cout<<"Admit Required to Hospital?"<<endl;
161: cin>>p->addmission;
162:
163: }
164:
165: else
166: cout<<"ID is not Registeredn";
167:
168: }
169: void deleteList()
170: {
171: int counter=0;
172: node *current=NULL,*prev=NULL;
173: //current =new node;
174: prev=head;
175: current=head;
176: int ch;
177: cout<<"Enter the ID: ";
178: cin>>ch;
179: if(check_id(ch)){
180: // temp=head;
181: while(current->id!=ch)
182: {
183: prev=current;
184: current=current->next;
185: }
186: prev->next=current->next;
187: free(current);
188:
189: }
190:
191: else
192: cout<<"ID not present"<<endl;
193: for(int a=0;a<i;a++)
194: {
195: if(arr[a]==ch){
196: for (int j=a;j<i;j++){
197: arr[j]=arr[j+1];
198: }
199: i--;
200: }
201: }
202: cout<<"SUCCESSFULLY DELETED ALL NODES OF LINKED LISTn";
203:
204:
205: }
206: void update_menu()
207: {
208: cout<<"enter 1 Patient First name"<<endl;
209: cout<<"enter 2 Patient Last name"<<endl;
210: cout<<"enter 3 Patient ID"<<endl;
211: cout<<"enter 4 Patient Age"<<endl;
212: cout<<"enter 5 Patient Gender"<<endl;
213: cout<<"enter 6 Patient Blood Group"<<endl;
214: cout<<"enter 7 Patient Contact "<<endl;
215: cout<<"enter 8 patient CNIC"<<endl;
216: cout<<"enter 9 Patient Address"<<endl;
217: cout<<"*********************************"<<endl;
218: cout<<"Enter 10 Symptoms"<<endl;
219: cout<<"Enter 11 Diagnosis"<<endl;
220: cout<<"Enter 12 Medicines"<<endl;
221: cout<<"Admit 13 Required to Hospital?"<<endl;
222: }
223: void update_data(){
224: node *current=NULL,*prev=NULL;
225: current=head;
226: prev=head;
227: int id,ch;
228: cout<<"enter ID"<<endl;
229: cin>>id;
230: if(check_id(id)){
231: while(current->id!=id)
232: {
233: prev=current;
234: current=current->next;
235: }
236: update_menu();
237: cout<<"choose number"<<endl;
238: cin>>ch;
239: if(ch==1){
240: cout<<"enter first name"<<endl;
241: cin>>current->fname;
242: }
243: else if(ch==2){
244: cout<<"enter second name"<<endl;
245: cin>>current->sname;
246: }
247: else if(ch==3){
248: cout<<"enter ID"<<endl;
249: cin>>current->id;
250: }
251: else if(ch==4){
252: cout<<"enter age"<<endl;
253: cin>>current->age;
254: }
255: else if(ch==5){
256: cout<<"enter gender"<<endl;
257: cin>>current->gender;
258: }
259: else if(ch==6){
260: cout<<"enter blood group"<<endl;
261: cin>>current->blood_gp;
262: }
263: else if(ch==7){
264: cout<<"enter contact"<<endl;
265: cin>>current->contact;
266: }
267: else if(ch==8){
268: cout<<"enter CNIC"<<endl;
269: cin>>current->cnic;
270: }
271: else if(ch==9){
272: cout<<"enter address"<<endl;
273: cin>>current->address;
274: }
275: else if(ch==10){
276: cout<<"Enter 10 Symptoms"<<endl;
277: cin>>current->symptom;
278: }
279: else if(ch==11){
280: cout<<"Enter 11 Diagnosis"<<endl;
281: cin>>current->diagnosis;
282: }
283: else if(ch==12){
284: cout<<"Enter 12 Medicines"<<endl;
285: cin>>current->medicine;
286: }
287: else if(ch==13){
288: cout<<"Admit 13 Required to Hospital?"<<endl;
289: cin>>current->addmission;
290: }
291: }
292: else
293: cout<<"ID not present"<<endl;
294: }
295: };
296:
297: void dis()
298: {
299: cout<<"1 Add New Patient Record "<<endl;
300: cout<<"2 Add Patient prescription "<<endl;
301: cout<<"3 Full History of the Patient"<<endl;
302: cout<<"4 delete Patient Record"<<endl;
303: cout<<"5 update Patient Record"<<endl;
304: }
305: void menu()
306: {
307: cout<<"press 1 to doctor menu"<<endl;
308: cout<<"press 2 to patients menu"<<endl;
309: cout<<"press 3 to pharmacist menu"<<endl;
310: }
311: int main()
312: {
313: struct node* head=NULL;
314: doctor u;
315: int i=0;
316: do{
317: dis();
318: cin>>i;
319: if(i==1)
320: u.add();
321: else if(i==2)
322: u.diagnosis();
323: else if(i==3)
324: u.show();
325: else if(i==4)
326: u.deleteList();
327: else if(i==5)
328: u.update_data();
329: }while(1);
330: return 0;
331: }


Code Explanation


Let’s start from the top.

After the headers, we create a structure called a “node”. Inside the structure, some variables and pointers are of the type node. 


As I said before, we will use the linked list concept where each node will have the attributes declared inside the structure.


After the creation of pointers to the linked list, we create a class “doctor” that has the methods(functions) of the project.

Let’s explore each function.


1) void add() 


In the add function, we create a new node to the linked list using the “new” keyword of C++.

Then we use the arrow symbol to assign the values to the attributes of that node.

It goes on every time we enter a new record.

We take the data that I have said in the explanation of the UI. 


2)void show()


We use this function when the user selects the third option, Full History of the patient.

In this function, we assign the current and prev node as NULL. After that, we iterate through all the ids of the nodes till we find the ID of the patient required is found to display it.


3)void diagnosis()


We use this function when the user selects the option, Add patient prescription.  

It is similar to add() function. Except, here we use the ID to first search the record of the patient and iterate till we find it.

Once found, we take the information that we need for the prescription.


4)void deletelist()


So, when we want to delete the record of a patient, we are deleting the node of a linked list using the ID. 

So, we iterate through the nodes and when we find it, we delete it.

The linked list has a process for deletion.

If the node to be deleted is the starting one, we just simply make the next node as the start node. 

If it is in middle, we use a temporary node to store and then delete it.


5) void update_data()


In this function, we just call the update_menu() and choose a value for the corresponding field.

Then using an if-else loop, we update only that field or the attribute of the chosen ID’s node.


6) void menu(), void dis()


These are just helper functions to display the options. 

These functions are called in main() function.


7)main() 


Here, we create an object to doctor and use the “.” operator to access the methods of class for the appropriate option.


Conclusion


We have reached the end of the article but we have a lot more projects in C++ coming. 

If you have enjoyed the article and learned something new today, let us know in the comments. Check out some more articles here. 

1) MultiStep Form using HTML-CSS

2) Tilting Maze game using JS

Visit our Instagram Page for more awesome content on Web development.

Thank you.

Happy Reading 🙂



Leave a Reply