-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHospitalPatientManagementSystem.java
127 lines (102 loc) · 3.24 KB
/
HospitalPatientManagementSystem.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
import java.util.*;
abstract class Patient{
private String patientId;
private String name;
private int age;
public Patient(String patientId, String name, int age) {
this.patientId = patientId;
this.name = name;
this.age = age;
}
public String getPatientId() {
return patientId;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void getPatientDetails() {
System.out.println("Patient ID: " + patientId + ", Name: " + name + ", Age: " + age);
}
public abstract double calculateBill();
}
interface MedicalRecord {
void addRecord(String record);
void viewRecords();
}
class InPatient extends Patient implements MedicalRecord {
private double dailyRate;
private int daysAdmitted;
private String medicalHistory;
public InPatient(String patientId, String name, int age, double dailyRate, int daysAdmitted) {
super(patientId, name, age);
this.dailyRate = dailyRate;
this.daysAdmitted = daysAdmitted;
this.medicalHistory = "";
}
@Override
public double calculateBill() {
return dailyRate * daysAdmitted;
}
@Override
public void addRecord(String record) {
this.medicalHistory += record + "\n";
}
@Override
public void viewRecords() {
System.out.println("Medical History for " + getName() + ":\n" + medicalHistory);
}
}
class OutPatient extends Patient implements MedicalRecord {
private double consultationFee;
private String medicalHistory;
public OutPatient(String patientId, String name, int age, double consultationFee) {
super(patientId, name, age);
this.consultationFee = consultationFee;
this.medicalHistory = "";
}
@Override
public double calculateBill() {
return consultationFee;
}
@Override
public void addRecord(String record) {
this.medicalHistory += record + "\n";
}
@Override
public void viewRecords() {
System.out.println("Medical History for " + getName() + ":\n" + medicalHistory);
}
}
public class HospitalPatientManagementSystem {
public static void main(String[] args) {
List<Patient> patients = new ArrayList<>();
InPatient arun = new InPatient("P001", "Arun Kumar", 45, 2000, 5);
OutPatient arjun = new OutPatient("P002", "Arjun Singh", 30, 500);
arun.addRecord("Admitted with fever, prescribed antibiotics.");
arjun.addRecord("Routine check-up, advised vitamins.");
patients.add(arun);
patients.add(arjun);
for (Patient patient : patients) {
patient.getPatientDetails();
System.out.println("Total Bill: " + patient.calculateBill());
if (patient instanceof MedicalRecord) {
((MedicalRecord) patient).viewRecords();
}
System.out.println();
}
}
}
//SampleOutput
//Patient ID: P001, Name: Arun Kumar, Age: 45
//Total Bill: 10000.0
//Medical History for Arun Kumar:
//Admitted with fever, prescribed antibiotics.
//
//
//Patient ID: P002, Name: Arjun Singh, Age: 30
//Total Bill: 500.0
//Medical History for Arjun Singh:
//Routine check-up, advised vitamins.