-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatientRecords.java
128 lines (104 loc) · 2.33 KB
/
PatientRecords.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package Lab8;
public class PatientRecords {
private int id;
private int month;
private int day;
private int year;
private String date;
private String reasonForVisit;
private String treatmentPrescribed;
//constructor
PatientRecords(){
id = 0;
date = null;
reasonForVisit = null;
treatmentPrescribed = null;
}
//constructor with id and date
PatientRecords(int id, int month, int day, int year,String reason, String treatment) throws BadVisitDateException{
this.id = id;
if(month<1 || month >12){
throw new BadVisitDateException("Month not in range 1-12");
}
this.month = month;
if(day<1 || day >31){
throw new BadVisitDateException("Day not in range 1-31");
}
this.day = day;
if(year <1900 || year >2014){
throw new BadVisitDateException("Year not great than 1900 and less than 2014");
}
this.year = year;
this.date = String.valueOf(month)+"-"+String.valueOf(day)+"-"+String.valueOf(year);
reasonForVisit = reason;
treatmentPrescribed = treatment;
}
//set ID
void setID(int num_id){
id = num_id;
}
//get ID
int getID() {
return id;
}
//get day
int getDay(){
return day;
}
//get month
int getMonth(){
return month;
}
//get year
int getYear(){
return year;
}
//set date
void setDate(String currentDate){
date = currentDate;
}
//get date
String getDate(){
return date;
}
//set reasonForVisit
void setReason(String reason){
reasonForVisit = reason;
}
//get reason for visit
String getReason(){
return reasonForVisit;
}
//set Treatment Prescribed
void setTreatment(String treatment){
treatmentPrescribed = treatment;
}
//get treatment prescribed
String getTreatment(){
return treatmentPrescribed;
}
@Override
public String toString(){
return "Patient ID: "+id+" visited on "+date+".\n The reason for visiting is "+
reasonForVisit+".\n Treatment prescribe is "+treatmentPrescribed+".";
}
@Override
public boolean equals(Object obj){
if(obj == null)
return false;
if(obj instanceof PatientRecords){
if(((PatientRecords) obj).getID() == this.getID()){
if(((PatientRecords) obj).getDate().equals(this.getDate()))
return true;
}
}
return false;
}
@Override
public int hashCode(){
final int prime = 31;
int result = 1;
result = prime*result + Math.abs(id*date.hashCode());
return result;
}
}