This project is a simple Hospital Management System built in Java. It helps manage patient and doctor records, update patient diagnoses, treat patients, and handle invalid data inputs.
- Manage patient records
- Manage doctor records
- Update patient diagnoses
- Track the number of patients treated by a doctor
- Handle invalid data inputs with exceptions
A Patient has:
- ID: Unique identifier
- Name: Patient's name
- Age: Patient's age
- Diagnosis: Current diagnosis
A Doctor has:
- ID: Unique identifier
- Name: Doctor's name
- Specialization: Doctor's field of expertise
- Patients Treated: Number of patients treated
To run the project, execute the main method in the Main class. This will:
- Create a
Patientand aDoctor. - Update the patient's diagnosis to "Flu".
- Print the patient's details.
- Treat the patient and increase the doctor's
patientsTreatedcount. - Attempt to set the patient's age to a negative value and catch the exception.
- Attempt to update the patient's diagnosis to an empty string and catch the exception.
public class Main {
public static void main(String[] args) {
Patient patient1 = new Patient("P001", "John Smith", 45, "Fever");
Doctor doctor1 = new Doctor("D101", "Dr. Alice", "General Medicine");
// Updates the diagnosis to "Flu"
patient1.updateDiagnosis("Flu");
System.out.println(patient1);
doctor1.treatPatient();
try {
patient1.setAge(-19);
} catch (IllegalArgumentException e) {
System.out.println(e);
}
try {
patient1.updateDiagnosis("");
} catch (IllegalArgumentException e) {
System.out.println(e);
}
}
}