-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatientList.cpp
91 lines (65 loc) · 1.63 KB
/
PatientList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//Kanellaki Maria Anna - 1115201400060
#include "PatientList.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
PatientNode::PatientNode(PatientRecord *rec) //initializes a record with given PatientRecord
{
record = rec;
next = NULL;
}
PatientNode::~PatientNode() //deletes record only
{
delete record;
}
PatientList::PatientList() //initializes empty list
{
head = NULL;
}
PatientList::~PatientList() //deletes whole list
{
PatientNode *rec, *temp = head;
while (temp)
{
rec = temp;
temp = temp->getNext();
delete rec; //PatientRecords are deleted only by the list
}
}
PatientRecord* PatientList::SearchRecord(string id) //searches for a record with recordID = given id
{
PatientNode *rec = head;
while (rec)
{
if (rec->getRecord()->getRecordId() == id)
return rec->getRecord();
rec = rec->getNext();
}
delete rec;
return NULL;
}
void PatientList::push(PatientNode *rec) //insertion at the beginning of the list for speed
{
if (SearchRecord(rec->getRecord()->getRecordId()))
{
cout << "Error. This record ID already exists."<< endl;
exit(-1);
}
if (head)
rec->setNext(head);
head = rec;
}
//getters and setters for both classes
PatientRecord *PatientNode::getRecord() const
{
return record;
}
PatientNode *PatientNode::getNext() const
{
return next;
}
void PatientNode::setNext(PatientNode *next)
{
PatientNode::next = next;
}