0% found this document useful (0 votes)
3 views43 pages

Dsa Project Code Files

Uploaded by

sarariaz487
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views43 pages

Dsa Project Code Files

Uploaded by

sarariaz487
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

public class AdminList {

AdminNode first;
AdminNode last;

public AdminList(){
[Link] = null;
[Link] = null;
}

public void addAdmin(String username, String password){


AdminLogin tempAdmin = new AdminLogin(username, password);
if(first == null && last == null){
first = new AdminNode(tempAdmin);
[Link] = first;
}
else{
[Link] = new AdminNode(tempAdmin);
last = [Link];
}
}

public boolean checkAdmin(String username, String password){


AdminNode tempPointer = first;
if(first == null){
[Link]("--- No admins in the list---");
}
else {
while(tempPointer != null){
if([Link](username, password))
return true;
tempPointer = [Link];
}
}
return false;
}
}
public class AdminLogin {
public String username;
public String password;

public AdminLogin(String username, String password){


[Link] = username;
[Link] = password;
}

public boolean validateAdmin(String username, String password){


return [Link](username) &&
[Link](password);
}
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class AdminManager {


AdminList adminList;
PatientTree patientTree;
HashMap<String, Doctor> doctorList;
DepartmentManager departmentManager;
PatientManager patientManager;
Hospital hospital;

DateTimeFormatter dateFormatter = [Link]("dd-MM-


yyyy");

public AdminManager(Hospital hospital){


[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = hospital;
[Link] = new AdminList();
addAdmin();
}
Scanner myInput = new Scanner([Link]);

public void addAdmin(){


[Link]("mateen","002");
[Link]("ammar","029");
[Link]("sara","110");
}

public void askPassword(){


[Link]("Enter username");
String userName = [Link]();

[Link]("Enter password");
String pass = [Link]();

validateAdmin(userName,pass);
}

public void validateAdmin(String username, String password){


if([Link](username, password)){
adminMenu();
}
else{
[Link]("Invalid");
}
}

public void adminMenu(){


while (true){
[Link]("\t==============================");
[Link]("\t *** Admin ka menu *** ");
[Link]("\t==============================");

[Link]("[1] Register Doctor");


[Link]("[2] Patient Functions");
[Link]("[3] Have Checkup");
[Link]("[4]. Ambulance Details");
[Link]("[5]. Bed Details");
[Link]("0. ↩ Back");

int choice = [Link]();


[Link]();
switch (choice){
case 1:
doctorFunctions();
break;
case 2:
patientFunctions();
break;
case 3:
haveCheckup();
break;
case 4:
ambulanceDetailsMenu();
break;
case 5:
bedDetailsMenu();
break;
case 0:
return;
}
}

public void patientFunctions() {


while (true) {
[Link]("\t===== Patient Functions =====");
[Link]("1. Add Patients");
[Link]("2. Search Patient");
[Link]("3. View Patients");
[Link]("4. Delete Patient");
[Link]("0. ↩ Back");

int choice = [Link]();


[Link]();
switch (choice) {
case 1:
addPatient();
break;
case 2:
searchPatient();
break;
case 3:
viewPatients();
break;
case 4:
deletePatient();
break;
case 0:
return;
default:
[Link]("Invalid choice");
}

[Link]();

}
}

public void addPatient(){


Patient tempPatient = new Patient(departmentManager);

[Link]("\n\t-------Add Patient------");
[Link]("Enter CNIC #: ");
[Link] = [Link]();

[Link]("Enter patient Name:");


[Link] = [Link]();

[Link] = [Link]();

[Link]("Enter patient's blood type:");


[Link] = [Link]();

[Link]("Enter password: ");


[Link] = [Link]();

[Link]("Enter Address:");
[Link] = [Link]();

[Link]("Enter Date of Birth (dd-MM-YYYY)");


String date = [Link]();
[Link] = [Link](date,dateFormatter);

[Link] = [Link];
[Link](tempPatient);

public void doctorFunctions(){


[Link]("Enter Department Name: ");
String depName = [Link]();

if([Link](depName)!=null) {
while (true) {
[Link]("======= DOCTOR FUNCTIONS ======");
[Link]("Please select and option: ");
[Link]("[1] Add Doctor");
[Link]("[2] Delete Doctor");
[Link]("[3] View Department Doctors: ");
[Link]("[0] Exit");
char choice = [Link]().charAt(0);

switch (choice) {
case '1':

[Link]([Link](), depName);
break;
case '2':
[Link](depName);
break;
case '3':
[Link](depName);
break;

case '0':
return;
}
}
} else {
[Link]("❌Department Doesn't exist");
}
}

// public void Doctor(){


// [Link]("Enter Department Name: ");
// String depName = [Link]();
//
//
// while (true) {
// [Link]("==== DOCTOR FUNCTIONS ====");
// [Link]("Choose Function you want to perform: ");
// [Link]("1. Add Doctor");
// [Link]("2. Delete Doctor");
// [Link]("3. View Department Doctors: ");
// [Link]("0. Exit");
// char choice = [Link]().charAt(0);
//
// switch (choice){
// case '1':
//
[Link]([Link](), depName);
// break;
// case '2':
// [Link](depName);
// break;
// case '3':
// [Link](depName);
// break;
// case '0':
// return;
// }
// }
// }

public void haveCheckup(){

public void searchPatient(){


[Link]("Enter patient's id card number: ");
String idCardNum = [Link]();
[Link](idCardNum);
}

public void viewPatients(){


[Link]();
}

public void deletePatient(){


[Link]("Enter the patient's id Card Number: ");
String idCardNum = [Link]();

[Link](idCardNum);
}

public void ambulanceDetailsMenu() {


while (true) {
[Link]("\n--- Ambulance Details ---");
[Link]("1. View Available Ambulances");
[Link]("2. View Unavailable Ambulances");
[Link]("0. Back to Admin Menu");

int choice = [Link]();


[Link]();

switch (choice) {
case 1:
[Link]("✅ Available Ambulances:");
[Link]();
break;
case 2:
[Link]("🚫 Unavailable Ambulances:");
[Link]();
break;

case 0:
return;
default:
[Link]("Invalid choice.");
}
}
}
public void moveUnavailableAmbulances() {
if ([Link]()) {
[Link]("❌ No unavailable ambulances to move.");
return;
}

AmbulanceList unavailableAmbulances= [Link];


Ambulance ambulance = [Link]();
while (ambulance!= null) {
[Link](ambulance);
ambulance = [Link]();
}
}

public void bedDetailsMenu() {


while (true) {
[Link]("\n--- Bed Details ---");
[Link]("1. View All Beds");
[Link]("2. View Occupied Beds");
[Link]("3. View Available Beds");
[Link]("4. Back to Admin Menu");

int choice = [Link]();


[Link]();

ArrayList<Bed> beds = [Link]; // assumes public bedList


in hospital

switch (choice) {
case 1:
for (Bed bed : beds) {
[Link]([Link]() + " - " +
[Link]());
}
break;
case 2:
for (Bed bed : beds) {
if (![Link]()) {
[Link]([Link]() + " - " +
[Link]() + " (" + [Link]().name + ")");
}
}
break;
case 3:
for (Bed bed : beds) {
if ([Link]()) {
[Link]([Link]() + " -
AVAILABLE");
}
}
break;
case 4:
return;
default:
[Link]("Invalid choice.");
}
}
}

public class AdminNode {


public AdminLogin admin;
public AdminNode next;

public AdminNode(AdminLogin admin){


[Link] = admin;
[Link] = null;
}
}
public class Ambulance {
private String driverName;
private String registrationNumber;
private String companyName;

public Ambulance(String driverName, String registrationNumber, String


companyName) {
[Link] = driverName;
[Link] = registrationNumber;
[Link] = companyName;
}

public String getDriverName() {


return driverName;
}

public String getRegistrationNumber() {


return registrationNumber;
}

public String getCompanyName() {


return companyName;
}

// Used in Admin views


@Override
public String toString() {
return "Ambulance{" +
"Driver='" + driverName + '\'' +
", Reg#='" + registrationNumber + '\'' +
", Company='" + companyName + '\'' +
'}';
}

// Used in Emergency
public String shortInfo() {
return "Ambulance{" +
"Driver='" + driverName + '\'' +
", Reg#='" + registrationNumber + '\'' +
'}';
}
}
import [Link];
import [Link];
import [Link];
import [Link];

public class AppointmentManager {


Map<LocalDate, HashMap<String,Doctor>> doctorsList;
HashMap<String, Doctor> depDoctors;
Scanner myInput = new Scanner([Link]);

public AppointmentManager (Department department){


[Link] = [Link];
[Link] = new HashMap<>();
}

public void manageAppointment(LocalDate date, Patient patient){


HashMap<String, Doctor> doctors = [Link](date);
if( doctors == null){
doctors = new HashMap<>(depDoctors);
[Link](date,doctors);
}

Doctor appointmentDoctor = selectDoctor(doctors, patient);

if( appointmentDoctor != null)


[Link]("Your appointment has been scheduled for Dr.
"+[Link]+ " at "+[Link]());

public Doctor selectDoctor(HashMap<String, Doctor> doctors, Patient


patient){

//Any random doctor would be saved, and we would use insertion


Algorithm logic for comparison
Doctor minPatientDoc = (Doctor) [Link]().iterator().next();
Doctor tempDoc = null; //

for(String docName: [Link]()) {


tempDoc = [Link](docName);
if (tempDoc != null && [Link] <
[Link])
minPatientDoc = tempDoc;
}

[Link](patient,minPatientDoc);
return minPatientDoc;
}
}
public class Bed {
private String bedId;
private BedStatus status;
private Patient patient;

public Bed(int i){


[Link] = [Link]("B%03d",i);
status = [Link];
patient = null;
}

// public void assignPatient(Patient patient) {


// [Link] = patient;
// [Link]("Bed id is: " + bedId);
// [Link]("===Bed assigned to " + [Link] + "===");
// }

public boolean isAvailable() {


return status == [Link];
}

public void assignPatient(Patient patient) {


if (status == [Link]) {
[Link]("⚠ Bed already occupied.");
return;
}
[Link] = patient;
[Link] = [Link];
[Link]("✅ Bed ID: " + bedId + " assigned to " +
[Link]);
}

public void releaseBed() {


[Link] = null;
[Link] = [Link];
[Link]("🔄 Bed " + bedId + " is now available.");
}

public String getBedId() {


return bedId;
}

public Patient getPatient() {


return patient;
}

public BedStatus getStatus() {


return status;
}
}

public enum BedStatus {


AVAILABLE,
OCCUPIED
}
import [Link];
import [Link];
import [Link].*;

public class Department {


protected String name;
protected String depId;
ArrayList<Bed> emptyBeds = new ArrayList<>();
protected ArrayList<Bed> bedList = new ArrayList<>();
protected HashMap<String, Doctor> doctorList;
ArrayList<Bed> occupiedBeds = new ArrayList<>();
DoctorManager doctorManager;

public Department(String name, String depId){


[Link] = name;
[Link] = depId;
[Link] = new HashMap<>();
//Pass list of doctors to add in the other list which is managed by
date
[Link] = new DoctorManager([Link]);
addBeds();
}

public Department(){

}
public void addBeds(){
for (int i=1; i<=10; i++) {
Bed tempBed = new Bed(i);
[Link](tempBed);
}
}

public Bed getAvailableBed() {


for (Bed bed : bedList) {
if ([Link]()) {
return bed;
}
}
return null;
}

public void showAllBeds() {


for (Bed bed : bedList) {
[Link]([Link]() + " - " + [Link]());
}
}

public HashMap<String, Doctor> getDoctorList() {


return doctorList;
}

public void assignBed(){


[Link]([Link]());
}

// public HashMap<String, DoctorLogin> getDoctorLoginList() {


// return doctorLoginList;
// }
//
// public void setDoctorLoginList(HashMap<String, DoctorLogin>
doctorLoginList) {
// [Link] = doctorLoginList;
// }
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DepartmentManager {
HashMap<String, Department> departmentList;
HashMap<String, DoctorLogin> doctorLogin;

Scanner myInput = new Scanner([Link]);


//Constructor
public DepartmentManager(Hospital hospital){
[Link] = [Link];
[Link] = new HashMap<>();
addDepartments();
addDoc("Zadif", "pass1");
addDoc("Ammar","pass2");
addDoc("Fareed","pass3");
}

//Ask for date and get doctor from the list of desired date
public void selectDoctor(Department department, String docId){
[Link]("Enter today's date: ");
String dateString = [Link]();

//Object required to format date


DateTimeFormatter formatter = [Link]("dd-MM-
yyyy");

//Input 1 = Date in our format Input2 = we are telling in which


format date is being added
LocalDate date = [Link](dateString,formatter);

//Now access the doctor object


HashMap<String, Doctor> tempDocList =
[Link](date);
//Call doctor's functions which will be shown on login
if(tempDocList!=null) {
Doctor doctor = [Link](docId);
[Link]();
} else{
[Link]("❌ No Appointments as of now");
[Link]("\033[H\033[2J");
}
}

public void addDepartments(){


[Link]("Cardiology", new Department("Cardiology","001"));
[Link]("Neurology",new Department("Neurology","002"));
[Link]("Orthopedic",new Department("Orthopedic","003"));
[Link]("Dermatology",new Department("Dermatology","004"));
[Link]("Urology",new Department("Urology","005"));
}

public void addDoctor(String doctorId, String depName){


Department department = [Link](depName);

Doctor tempDoctor = new Doctor();


[Link] = doctorId;

[Link]("Enter the doctor Name: ");


[Link] = [Link]();

[Link]("Enter id Card Number: ");


[Link] = [Link]();

[Link]("Enter password: ");


[Link] = [Link]();

// keeping doctor id as key in doctor hashmap


[Link](doctorId,tempDoctor);
DoctorLogin docLogin = new DoctorLogin(doctorId, [Link],
depName);
[Link](doctorId, docLogin);
}

public void deleteDoctor(String depName){


[Link]("====== ❗ Delete Doctor ======");

[Link]("Enter the doctor Id");


String id = [Link]();

[Link](depName).[Link](id);

public void viewDepartmentDoctors(String depName){

for ([Link]<String, Doctor> doctor :


[Link](depName).[Link]()){
[Link]([Link]());
}
}

public void doctorLogin(){


[Link]("==================================");
[Link](" Doctor Login ");
[Link]("==================================");
[Link]();
[Link]("Enter Doctor Id: ");
String docId = [Link]();
[Link]("Enter password: ");
String password = [Link]();

DoctorLogin doctorLoginVariable = [Link](docId);


if(doctorLoginVariable!=null) {
String depName = [Link](docId,
password);

if (depName != null) {
[Link]("✔ Logged in Successfully");
Department department = [Link](depName);
selectDoctor(department, docId);
} else {
[Link]("🚫Invalid credentials");
}
}else {
[Link]("❌Invalid Username");
}

}
public void addDoc(String name, String pass){
String id1 = [Link]();
[Link](id1);
Doctor doc1 = new Doctor(id1,name,pass);
[Link]("Cardiology").[Link](id1,doc1);
DoctorLogin docLogin = new DoctorLogin(id1,pass,"Cardiology");
[Link](id1,docLogin);
}
}
public class DijkstraSimple {
final int INF = 999999;

private final String[] nodeNames = {


"Hospital", "Johar Town", "Ali Town", "Canal View", "UET", "Sanda",
"Samanabad", "GPO", "Anarkali", "High Court", "GCU"
};

private final int numNodes = [Link];

private final int[][] graph = new int[numNodes][numNodes];

public DijkstraSimple() {
for (int i = 0; i < numNodes; i++) {
for (int j = 0; j < numNodes; j++) {

if (i == j)
graph[i][j] = 0;
else
graph[i][j] = INF;

}
}

setEdge("Hospital", "Johar Town", 5);


setEdge("Hospital", "Ali Town", 8);
setEdge("Johar Town", "Canal View", 4);
setEdge("Ali Town", "Canal View", 3);
setEdge("Canal View", "UET", 6);
setEdge("UET", "Sanda", 2);
setEdge("Sanda", "Samanabad", 4);
setEdge("Samanabad", "GPO", 3);
setEdge("GPO", "Anarkali", 2);
setEdge("Anarkali", "High Court", 2);
setEdge("High Court", "GCU", 3);
setEdge("Johar Town", "Samanabad", 10);
setEdge("Ali Town", "Sanda", 9);
setEdge("GCU", "Hospital", 12); // Return edge
}

private void setEdge(String from, String to, int distance) {


int i = getIndex(from);
int j = getIndex(to);
if (i != -1 && j != -1) {
graph[i][j] = distance;
}
}

public void displayLocationMenu() {


for (int i = 1; i < numNodes; i++) {
[Link](i + ". " + nodeNames[i]);
}
}

public int getNumNodes() {


return numNodes;
}

public String getLocationName(int index) {


return nodeNames[index];
}

private int getIndex(String name) {


for (int i = 0; i < numNodes; i++) {
if (nodeNames[i].equalsIgnoreCase(name)) {
return i;
}
}
return -1;
}

public void dijkstra(String startName, String endName) {


int start = getIndex(startName);
int end = getIndex(endName);

if (start == -1 || end == -1) {


[Link]("Invalid start or end location.");
return;
}

int[] dist = new int[numNodes];


boolean[] visited = new boolean[numNodes];
int[] prev = new int[numNodes];

for (int i = 0; i < numNodes; i++) {


dist[i] = INF;
visited[i] = false;
prev[i] = -1;
}

dist[start] = 0;

for (int i = 0; i < numNodes - 1; i++) {


int u = getMinIndex(dist, visited);
if (u == -1) break;

visited[u] = true;

for (int v = 0; v < numNodes; v++) {


if (!visited[v] && graph[u][v] != INF && dist[u] + graph[u][v] <
dist[v]) {
dist[v] = dist[u] + graph[u][v];
prev[v] = u;
}
}
}

[Link]("\n📍 Shortest path from " + startName + " to " +


endName + ":");
if (dist[end] == INF) {
[Link]("No path.");
} else {
printPath(prev, end);
[Link]("\nDistance: " + dist[end] + " km");
}
}

private int getMinIndex(int[] dist, boolean[] visited) {


int min = INF, idx = -1;
for (int i = 0; i < numNodes; i++) {
if (!visited[i] && dist[i] < min) {
min = dist[i];
idx = i;
}
}
return idx;
}

private void printPath(int[] prev, int current) {


if (prev[current] == -1) {
[Link](nodeNames[current]);
return;
}
printPath(prev, prev[current]);
[Link](" → " + nodeNames[current]);
}
}
import [Link];
import [Link];

public class Doctor{


public String doctorId;
public String name;
public String age;
public String cnicNum;
public String contactNum;
public String password;
public PatientQueue patientQueue = new PatientQueue();
public Doctor(String id, String name, String password){
[Link] = id;
[Link] = name;
[Link] = password;
}

public Doctor(){
}

public Doctor(Doctor doctor){


[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = new PatientQueue();
}

public void setDoctorId(String doctorId) {


[Link] = doctorId;
}

public String getDoctorId() {


return doctorId;
}

public void setName(String name) {


[Link] = name;
}

public String getCnicNum() {


return cnicNum;
}

public void setCnicNum(String cnicNum) {


[Link] = cnicNum;
}

Scanner myInput = new Scanner([Link]);

public void checkNextPatient(){

//Get patient object from queue


Patient patient = [Link]();

[Link]().addMedicalRecord(this);
}

public String getName(){


return [Link];
}

public void viewTodayPatients(){

[Link]();
}

public void performFunctions(){


while (true) {
[Link]("========================================");
[Link](" " + [Link] + "'s Profile ");
[Link]("========================================");
[Link]();
[Link]("Please select an option: ");
[Link]("[1] View Today's Patients");
[Link]("[2] Check Next Patient");
[Link]("[0] Back");
String choice = [Link]();

switch (choice) {
case "1":
viewTodayPatients();
break;
case "2":
checkNextPatient();
break;
case "0":
return;
default:
[Link]("🚫Invalid Input");
}
}
}

@Override
public String toString() {
return "Doctor{" +
"doctorId='" + doctorId + '\'' +
", name='" + name + '\'' +
", age='" + age + '\'' +
", cnicNum='" + cnicNum + '\'' +
", contactNum='" + contactNum + '\'' +
", password='" + password + '\'' +
'}';
}

public PatientQueue getPatientQueue() {


return patientQueue;
}
}
public class DoctorLogin {
private String doctorId;
private String password;
private String department;

public DoctorLogin(String doctorId, String password, String department){


[Link] = doctorId;
[Link] = password;
[Link] = department;
}
public String getDoctorId() {
return doctorId;
}

public String getPassword() {


return password;
}

public void setDoctorId(String doctorId) {


[Link] = doctorId;
}

public void setPassword(String password) {


[Link] = password;
}
public void setDepartment(String department) {
[Link] = department;
}

public String getDepartment() {


return department;
}

public String validateLogin(String id, String pass){


if( [Link](id) && [Link](pass))
return department;
else return null;
}
}
import [Link];
import [Link].*;

public class DoctorManager {


Map<LocalDate, HashMap<String,Doctor>> doctorsList; //Contains Doctors
List Based on Dates
HashMap<String, Doctor> depDoctors;
Scanner myInput = new Scanner([Link]);

public DoctorManager (HashMap<String, Doctor> depDoctors){


[Link] = depDoctors;
[Link] = new HashMap<>();
}

public void manageAppointment(LocalDate date, Patient patient){


HashMap<String, Doctor> doctors = [Link](date);
if( doctors == null){
HashMap<String, Doctor> copy = new HashMap<>();
for ([Link]<String, Doctor> entry : [Link]()) {
[Link]([Link](), new Doctor([Link]())); //
assuming copy constructor
}
[Link](date,copy);
doctors = copy;
}

Doctor appointmentDoctor = selectDoctor(doctors, patient);

if( appointmentDoctor != null)


[Link]("Your appointment has been scheduled for Dr.
"+[Link]+ " at "+[Link]());

public Doctor selectDoctor(HashMap<String, Doctor> doctors, Patient


patient){

//Any random doctor would be saved, and we would use insertion


Algorithm logic for comparison
if ([Link]()) throw new IllegalArgumentException("No doctors
available");

Doctor selectedDoctor = [Link]()


.stream()
.min([Link](d -> [Link]().size()))
.orElse(getRandomDoctor(doctors)); // fallback

[Link]().enqueuePatient(patient,selectedDoctor);
return selectedDoctor;
}

public static Doctor getRandomDoctor(HashMap<String, Doctor> doctors) {


if (doctors == null || [Link]()) {
throw new IllegalArgumentException("Doctor map is empty or
null.");
}

// Convert keys to a list so we can get random index


List<String> keys = new ArrayList<>([Link]());
String randomKey = [Link](new Random().nextInt([Link]()));

return [Link](randomKey);
}

// public void checkPatient(){


// Patient patient = [Link]();
//
// // [Link]();
// }

}
import [Link];
public class Emergency {
Scanner sc = new Scanner([Link]);
TemporaryPatient tempPatient = new TemporaryPatient();
DijkstraSimple pathFinder = new DijkstraSimple();
AdminManager adminManager;
Hospital hospital;

Scanner myInput = new Scanner([Link]);


public Emergency(Hospital hospital) {
[Link] = hospital;
[Link] = [Link];
}

public void enterDetails() {


String choice;
do {
Patient p = new Patient([Link]);
[Link]("\t==============================");
[Link]("\t * Emergency * ");
[Link]("\t==============================");
[Link]("\nEnter Emergency Patient Details:");
[Link]("Name: ");
[Link] = [Link]();
[Link]("CNIC: ");
[Link] = [Link]();

[Link]("Reason: ");
String reason = [Link]();

[Link]("\nChoose your current location:");


[Link]();

int locationIndex;
while (true) {
[Link]("Enter location number: ");
locationIndex = [Link]();
[Link]();
if (locationIndex >= 1 && locationIndex <
[Link]()) break;
[Link]("Invalid choice. Try again.");
}

String patientLocation =
[Link](locationIndex);

[Link](locationIndex);
[Link](reason);
[Link](p);
Ambulance amb = [Link]();
if (amb != null) {
[Link]("🚑 Ambulance dispatched: " +
[Link]());
[Link](amb); // Move to
unavailable
} else {
[Link]("❌ No ambulance available.");
}

[Link]("Hospital", patientLocation);
[Link](patientLocation, "Hospital");

[Link]("\n Patient " + [Link] + " successfully


registered.");

Bed availableBed = getAvailableBedFromHospital();


if (availableBed != null) {
[Link](p); // marks bed OCCUPIED
} else {
[Link]("❌ No available beds!");
}

[Link]("Do you want to continue:(yes/no) ");


choice = [Link]();
}while ([Link]("yes"));
[Link]();
}
private Bed getAvailableBedFromHospital() {
for (Bed bed : [Link]) {
if ([Link]()) {
return bed;
}
}
return null;
}

}
import [Link];
import [Link];
import [Link];
public class Hospital {
// private String hName;
HashMap<String, Department> departmentList;
AdminManager adminManager;
DepartmentManager departmentManager;
PatientTree patientTree;
ArrayList<Bed> bedList;
HashMap<String, Doctor> doctorList;
PatientManager patientManager;
public Emergency e;
public AmbulanceList availableAmbulances;
public AmbulanceList unavailableAmbulances;

public Hospital(){
patientTree = new PatientTree();
[Link] = new HashMap<>();
[Link] = new HashMap<>();
[Link] = new DepartmentManager(this);
bedList = new ArrayList<>();
for (int i = 1; i <= 10; i++) {
[Link](new Bed(i));
}
[Link] = new PatientManager(this);
[Link] = new AdminManager(this);
e=new Emergency(this);
[Link]();
availableAmbulances = new AmbulanceList();
unavailableAmbulances = new AmbulanceList();

// Load sample ambulances


[Link](new Ambulance("Ali", "REG001",
"Toyota"));
[Link](new Ambulance("Bilal", "REG002",
"Honda"));
[Link](new Ambulance("Usman", "REG003",
"Suzuki"));
[Link](new Ambulance("Zain", "REG004",
"Ford"));
[Link](new Ambulance("Ahsan", "REG005",
"Hyundai"));

}
}
public class IdGenerator {
private static int doctorCounter = 1;
private static int patientCounter =1;
private static String doctorId;

public static String generateDoctorId(){


return [Link]("D"+"%03d",doctorCounter++);
}

public static String generatePatientId(){


return [Link]("P"+"%03d",patientCounter++);
}

}
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="[Link]"/> icon in the gutter.
import [Link];
import [Link];

public class Main {


public static void main(String[] args) {
Scanner myInput = new Scanner([Link]);
Hospital hospital = new Hospital();

while (true) {
[Link]("======================================1=========");
[Link](" 🏥 Hospital Management System 🏥 ");
[Link]("===============================================");
[Link]();
[Link]();
[Link]("Please Select an Option:");
[Link]("[1] Admin Portal");
[Link]("[2] Doctor Portal");
[Link]("[3] Patient Portal");
[Link]("[4] Emergency Portal");
[Link]("[0] Exit");
[Link]();

[Link]("Enter your choice: ");


String choice = [Link]();

switch (choice) {
case "1":
[Link]();
break;
case "2":
[Link]();
break;
case "3":
[Link]();
break;
case "4":
[Link]();
break;
case "0":
return;

default:
[Link]("🚫Invalid credentials");
}
}

public void mainChoiceMenu(){

}
import [Link];
import [Link];
import [Link];

public class MedicalRecord {


private String recordId;
private String initialDiagnosis;
private String diagnosis;
private String severity;
private boolean admitStatus;
private Doctor doctor;
private String bedNumber;
private List<String> medications;
private DateTimeFormatter checkUpDate;

public void setRecordId(String recordId) {


[Link] = recordId;
}

public void setInitialDiagnosis(String initialDiagnosis) {


[Link] = initialDiagnosis;
}

public void setDiagnosis(String diagnosis) {


[Link] = diagnosis;
}

public void setSeverity(String severity) {


[Link] = severity;
}

public void setAdmitStatus(boolean admitStatus) {


[Link] = admitStatus;
}

public void setDoctor(Doctor doctor) {


[Link] = doctor;

public void setBedNumber(String bedNumber) {


[Link] = bedNumber;
}

public void setMedications(List<String> medications) {


[Link] = medications;

public void setCheckUpDate(DateTimeFormatter checkUpDate) {


[Link] = checkUpDate;
}

public String getRecordId() {


return recordId;
}

public String getInitialDiagnosis() {


return initialDiagnosis;
}

public String getDiagnosis() {


return diagnosis;
}

public String getSeverity() {


return severity;
}

public boolean isAdmitStatus() {


return admitStatus;
}

public Doctor getDoctor() {


return doctor;
}

public String getBedNumber() {


return bedNumber;
}

public List<String> getMedications() {


return medications;
}

public DateTimeFormatter getCheckUpDate() {


return checkUpDate;
}

public MedicalRecord() {
}

public MedicalRecord(String medicalDiagnosis){


[Link] = medicalDiagnosis;
}

public void addMedicalRecord() {

}
}

import [Link];
import [Link];
import [Link];
import [Link];

public class MedicalRecordList {


private MedicalRecordNode head;
private MedicalRecordNode tail;
private int size;

public MedicalRecordList() {
head = null;
tail = null;
size = 0;
}

public MedicalRecordNode getTail() {


return tail;
}

// Add a medical record with MedicalRecord object


public void addMedicalRecord(MedicalRecord record) {
MedicalRecordNode recordNode = new MedicalRecordNode(record);

if (head == null) {
head = recordNode;
tail = recordNode;
} else {
[Link] = recordNode;
tail = recordNode;
}
size++;
}

public void addMedicalRecord(Doctor doctor) {


Scanner scanner = new Scanner([Link]);
MedicalRecord newRecord = new MedicalRecord();

[Link]("\n=== Add New Medical Record ===");

[Link]("Enter record ID: ");


[Link]([Link]());

[Link]("Enter initial diagnosis: ");


[Link]([Link]());

[Link]("Enter current diagnosis: ");


[Link]([Link]());

[Link]("Enter severity: ");


[Link]([Link]());
[Link]("Admit status (true/false): ");
[Link]([Link]());
[Link]();

[Link](doctor);

[Link]("Enter bed number (if admitted): ");


[Link]([Link]());

[Link]("Enter medications [only-one per line, blank line


to finish:");

List<String> medications = new ArrayList<>();


while (true) {
String med = [Link]();
if ([Link]()) {
break;
}
[Link](med);
}
[Link](medications);

// [Link](DateTimeFormatter.ISO_LOCAL_DATE);

[Link](newRecord);
[Link]("Medical record added successfully!");
}

public MedicalRecord searchMedicalRecord(String recordId) {


MedicalRecordNode current = head;
while (current != null) {
if ([Link]().equals(recordId)) {
return [Link];
}
current = [Link];
}
return null;
}

public void searchAndDisplayRecord() {


Scanner scanner = new Scanner([Link]);
[Link]("Enter Record ID to search: ");
String recordId = [Link]();

MedicalRecord record = searchMedicalRecord(recordId);


if (record != null) {
[Link]("\n=== Found Medical Record ===");
[Link]("Record ID: " + [Link]());
[Link]("Diagnosis: " + [Link]());
[Link]("Severity: " + [Link]());

[Link]("Admit Status: " + [Link]());


[Link]("Attending Doctor: ");

if ([Link]() != null) {
[Link]([Link]().getName());
} else {
[Link]("N/A");
}
[Link]("Medications: " + [Link]());
} else {
[Link]("No record found with ID: " + recordId);
}
}

public boolean removeMedicalRecordByRecordId(String recordId) {


if (head == null) return false;

// Case 1: Remove head node


if ([Link]().equals(recordId)) {
head = [Link];
if (head == null) {
tail = null;
}
size--;
return true;
}

// Case 2: Find and remove non-head node


MedicalRecordNode current = head;
while ([Link] != null) {
if ([Link]().equals(recordId)) {
[Link] = [Link];
if ([Link] == null) {
tail = current;
}
size--;
return true;
}
current = [Link];
}

return false;
}

public void removeRecordInteractive() {


Scanner scanner = new Scanner([Link]);
[Link]("Enter Record ID to remove: ");
String recordId = [Link]();

if (removeMedicalRecordByRecordId(recordId)) {
[Link]("Record " + recordId + " removed
successfully");
} else {
[Link]("Failed to remove record. ID not found: " +
recordId);
}
}
// Get the size of the list
public int size() {
return size;
}
// Check if list is empty
public boolean isEmpty() {
return size == 0;
}

// Display all medical records


public void displayAllRecords() {
if (isEmpty()) {
[Link]("No medical records available.");
return;
}

[Link]("\n=== Medical Records ===");


MedicalRecordNode current = head;
int counter = 1;

while (current != null) {


MedicalRecord record = [Link];
[Link]("Record #" + counter);
[Link](" Diagnosis: " + [Link]());
[Link](" Severity: " + [Link]());
[Link](" Admit Status: " + [Link]());
[Link](" Medications: " + [Link]());
[Link]("----------------------------------");

current = [Link];
counter++;
}
}

public void viewLastRecord() {


if (isEmpty()) {
[Link]("No record available");
return;
}
[Link]([Link]());

public class MedicalRecordNode {


MedicalRecord data;
MedicalRecordNode next;

public MedicalRecordNode(MedicalRecord record){


[Link] = record;
[Link] = null;
}
}

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Patient {


public String patientId;
public String bloodType;
public String name;
public String cnicNum;
public String password;
public LocalDate dateofbirth;
public String reason;
public List<String> allergies;
public String location;
private MedicalRecordList medicalRecordList;
public DepartmentManager departmentManager;
private int locationIndex;
Scanner scanner = new Scanner([Link]);
public Patient(DepartmentManager departmentManager) {
[Link] = new ArrayList<>();
[Link] = departmentManager;
[Link] = new MedicalRecordList();
}

public String getPatientId() {


return patientId;
}

public void setPatientId(String patientId) {


[Link] = patientId;
}

public String getBloodType() {


return bloodType;
}

public void setBloodType(String bloodType) {


[Link] = bloodType;
}

public MedicalRecordList getMedicalRecordList() {


return medicalRecordList;
}

public void setMedicalRecordList(MedicalRecordList medicalRecordList) {


[Link] = medicalRecordList;
}

public String getName() {


return name;
}

public void setName(String name) {


[Link] = name;
}

public String getCnicNum() {


return cnicNum;
}

public void setCnicNum(String cnicNum) {


[Link] = cnicNum;
}

public String getPassword() {


return password;
}

public void setPassword(String password) {


[Link] = password;
}

public LocalDate getDateofbirth() {


return dateofbirth;
}

public void setDateofbirth(LocalDate dateofbirth) {


[Link] = dateofbirth;
}

public String getReason() {


return reason;
}

public void setReason(String reason) {


[Link] = reason;
}

public List<String> getAllergies() {


return allergies;
}

public void setAllergies(List<String> allergies) {


[Link] = allergies;
}

public String getLocation() {


return location;
}

public void setLocation(String location) {


[Link] = location;
}

public void patientDashboard() {


while (true) {
[Link]("\n\t===== Patient Dashboard =====");
[Link]("1. View My Information");
[Link]("2. Update My Information");
[Link]("3. View Medical Records");
[Link]("4. Last Checkup Record");
[Link]("5. Book New Appointment");
[Link]("0. Logout");
int choice = [Link]();
[Link]();

switch (choice) {
case 1:
[Link]();
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
[Link]();
break;
case 0:
return;
default:
[Link]("Invalid choice");
}
}
}

private void viewPatientInfo() {


[Link]("\n\t------- Your Information -------");
[Link]("Patient ID: " + patientId);
[Link]("Name: " + name);
[Link]("CNIC: " + cnicNum);
[Link]("Date of Birth: " + dateofbirth);
[Link]("Blood Type: " + bloodType);
[Link]("Location: " + location);
}

private void updatePatientInfo() {


[Link]("\n\t------- Update Information -------");
[Link]("(Leave field blank to keep current value)");

[Link]("Current name: " + [Link]);


[Link]("Enter new name:");
String newName = [Link]();
if ([Link]()) {
return;
}

[Link] = newName;

[Link]("Current blood type: " + [Link]);


[Link]("Enter new blood type:");
String newBloodType = [Link]();
if (![Link]()) {
[Link] = newBloodType;
}
[Link]("Current location: " + location);
[Link]("Enter new location:");
String newLocation = [Link]();
if (![Link]()) {
[Link] = newLocation;
}

[Link]("Information updated successfully!");


}

public void bookAppointments(){


[Link]("Enter appointment date (DD-MM-YYYY): ");
String dateInput = [Link]();

DateTimeFormatter formatter = [Link]("dd-MM-


yyyy");
LocalDate appointmentDate = [Link](dateInput, formatter);

[Link]("Enter department name: ");


String depName = [Link]();

Department department = [Link](depName);

if (department == null) {
[Link]("Error: Department '" + depName + "' not
found!");
return;
}

if ([Link] == null) {
[Link]("Error: No doctor manager available for this
department");
return;
}

[Link](appointmentDate, this);

private void viewMedicalRecords() {


[Link]();
}

public void setLocation(int index) {


[Link] = index;
} public void addEmergencyMedicalRecord(String reason) {
MedicalRecord emergencyRecord = new MedicalRecord(reason);
[Link](emergencyRecord);
}

}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class PatientManager {
AdminList adminList;
PatientTree patientTree;
DepartmentManager departmentManager;
DateTimeFormatter dateFormat = [Link]("dd-MM-yyyy");

public PatientManager(Hospital hospital) {


[Link] = new AdminList();
[Link] = [Link];
[Link] = [Link];
}
Scanner myInput = new Scanner([Link]);

public void patientPortal(){

while (true) {
[Link]("Please select one option: ");
[Link]("[1]. Login");
[Link]("[2]. Signup");
[Link]("[0]. ⭕Exit");
String choice = [Link]();

switch (choice) {
case "1":
patientLogin();
break;
case "2":
registerPatient();
break;
case "0":
return;
default:
[Link]("❌ Invalid choice");
}
}
}
public void patientLogin() {
[Link]("\n\t------- Patient Login -------");
[Link]("Enter your CNIC number:");
String cnic = [Link]();
[Link]("Enter your password:");
String password = [Link]();

Patient patient = [Link](cnic).pData;

if (patient != null && [Link]().equals(password)) {


[Link]("✅Login successful! Welcome, " + [Link]);
[Link]();
} else {
[Link]("Invalid CNIC or password. Please try again.");
}
}
// New method for patient registration
public void registerPatient() {
Patient newPatient = new Patient(departmentManager);
[Link]("\n\t------- Patient Registration -------");
[Link]("Enter your CNIC number:");
[Link] = [Link]();

// Check if patient already exists


if ([Link]([Link]) != null) {
[Link]("A patient with this CNIC is already
registered.");
return;
}

[Link]("Create a password:");
[Link]([Link]());

[Link]("Enter your full name:");


[Link] = [Link]();

[Link]("Enter your blood type:");


[Link] = [Link]();

newPatient = getDate(newPatient);

[Link]("Enter your location:");


[Link] = [Link]();

[Link] = [Link]();

[Link] = [Link];
[Link](newPatient);

[Link]("Registration successful! Your patient ID is: " +


[Link]);
}

public void patientFunctionsMenu() {


while (true) {
[Link]("\t===== Patient Functions =====");
[Link]("1. Add Patients");
[Link]("2. Search Patient");
[Link]("3. View Patients");
[Link]("4. Delete Patient");
[Link]("5. Exit");

int choice = [Link]();


[Link]();
switch (choice) {
case 1:
//addPatient();
break;
case 2:
searchPatient();
break;
case 3:
viewPatients();
break;
case 4:
deletePatient();
break;
case 5:
return;
default:
[Link]("Invalid choice");
}
}
}
/* public void addPatient() {
Patient tempPatient = new Patient();

[Link]("\n\t-------Add Patient------");
[Link]("Enter patient Name:");
[Link] = [Link]();

[Link]("Enter ID card #: ");


[Link] = [Link]();

[Link]("Enter patient's blood type:");


[Link] = [Link]();

[Link](tempPatient);
}*/

// public void addPatient() {


// Patient tempPatient = new Patient();
// Scanner myInput = new Scanner([Link]);
//
// [Link]("\n\t------- Add Patient -------");
//
// // Personal Information
// [Link]("Enter patient ID:");
// [Link] = [Link]();
//
// [Link]("Enter patient Name:");
// [Link] = [Link]();
//
// [Link]("Enter ID card # (CNIC):");
// [Link] = [Link]();
//
// [Link]("Enter date of birth (YYYY-MM-DD):");
// try {
// [Link] = new SimpleDateFormat("yyyy-MM-
dd").parse([Link]());
// } catch (Exception e) {
// [Link]("Invalid date format.");
// // [Link] = new Date();
// }
//
// [Link]("Enter blood type:");
// [Link] = [Link]();
//
// [Link]("Enter location:");
// [Link] = [Link]();
//
// // Medical Information
// [Link]("Enter reason for visit:");
// [Link] = [Link]();
//
// [Link]("Enter allergies (comma separated):");
// List<String> allergies = new ArrayList<>();
// while(true){
// String allergy = [Link]();
// if([Link]()){
// break;
// }
// [Link]((allergy));
// }
//
// // Add to patient tree
// [Link](tempPatient);
// [Link]("Patient added successfully!");
//
// }
public void searchPatient() {
[Link]("Enter patient's id card number: ");
String cnicNum = [Link]();
[Link](cnicNum);
}

public void viewPatients() {


[Link]();
}

public void deletePatient() {


[Link]("Enter the patient's id Card Number: ");
String idCardNum = [Link]();
[Link](idCardNum);
}

public Patient getDate(Patient patient){


[Link]("Enter your date of birth (DD-MM-YYYY):");
String date = [Link]();

try {
[Link] = [Link](date,dateFormat);
} catch (Exception e) {
[Link]("❌ Invalid Date format.");
[Link]();
getDate(patient);
}
return patient;
}
}
public class PatientQueue {
Patient[] queue = new Patient[5];
int front = -1;
int rear = -1;
int size = 0;

public void enqueuePatient(Patient patient, Doctor doctor){


if(rear == 4){
[Link]("No vacant spot for today");
return;
}

queue[++rear] = patient;
size++; //This size variable would be used to check how much
patients are there in the queue,
//so we can check which doctor has less patients

public Patient dequeuePatient(){


if (front == rear ){
[Link]("You do not have any patients waiting");
return null;
}

size--;
return queue[++front];
}

public void viewPatients(){


if(front == rear){
[Link]("You do not have any patients waiting");
return;
}

for (int i=front+1; i<=rear; i++){


[Link]("Patient Name: "+queue[i].name +" Patient ID:
"+ queue[i].patientId);
}

public int size() {


return size;
}
}
import [Link];

public class PatientTree {


PatientTreeNode root;
private MedicalRecordList medicalRecordList;

//===================================================
// Add Patient Functions
public void addPatient(Patient patient){
root = addPatient(root, patient);
}

//Patient would be inserted in the tree


private PatientTreeNode addPatient(PatientTreeNode patientNode,Patient
patient ){
if(patientNode == null){
//----Mistake: returned new PatientTreeNode(patient) Node
directly rather than saving it to patientNode
patientNode = new PatientTreeNode(patient);
}
else {
//String class has its own built-in compareTo function
//so it compares the string character by character based on UNI
code
//And we do not need comparable

//length of CNIC Numbers must be same, otherwise tree would be


compromised
int result = [Link]([Link]);
//
// BigInteger num1 = new BigInteger([Link]);
// BigInteger num2 = new BigInteger([Link]);
// int result = [Link](num2);
[Link]("Patient comparison with previous node:
"+result);
if (result < 0) {
[Link] = addPatient([Link], patient);
} else if (result > 0) {
[Link] = addPatient([Link], patient);
}

}
//calculating or updating height at every node
[Link] = [Link](height([Link]),
height([Link])) + 1;
return rotate(patientNode);
}

//===============================================================

public void viewPatients(){


viewPatients(root);
}

private void viewInfix(PatientTreeNode patient){


if (patient == null)
return;

[Link]([Link]());
viewInfix([Link]);
viewInfix([Link]);
}

public void viewPatients(PatientTreeNode patient){


if(patient == null)
return;

viewPatients([Link]);
[Link]([Link]());
viewPatients([Link]);
}
public int height(PatientTreeNode node){
if (node == null)
return -1;

return [Link];

//=============================================
// Delete Patients functions
public void deletePatients(String nicNum){
[Link]("Root Patient called in delete Patient: ");
[Link]([Link]());
root = deletePatient(root, nicNum);
}

//search node to be deleted


private PatientTreeNode deletePatient(PatientTreeNode node, String
idNumber){
if(node == null){
return null;
}
String tempId = [Link];
if([Link](tempId) < 0){
[Link] = deletePatient([Link],idNumber);
} else if([Link](tempId) > 0){
[Link] = deletePatient([Link],idNumber);
} else {
node = delete(node);
}

return node;
}
// this function will delete patient from patient tree and also his medical
record from linked list
public void deletePatient(String cnicNum, MedicalRecordList recordList) {
// 1. First find the patient node
PatientTreeNode node = searchPatient(root, cnicNum);

if (node != null) {
// now Get the record ID from patient's medical record
// Remove from MedicalRecordList
// Delete patient from tree
root = deletePatient(root, cnicNum);
[Link]("Patient and medical record deleted");
} else {
[Link]("Patient not found");
}
}
//deletePatientLogic
private PatientTreeNode delete(PatientTreeNode node){
//if patient Node has no child node
if(height([Link]) == -1 && height([Link]) == -1)
return null;
//if patient node has just left child
else if(height([Link]) == -1)
return [Link];
//if patient node has just right child
else{

//----Mistake: passed node instead of [Link]


PatientTreeNode tempNode = findMin([Link]);
[Link] = [Link];
[Link] = deletePatient([Link], [Link]);
[Link]([Link]());
return node;
}
}

public PatientTreeNode findMin(PatientTreeNode root){


if(root == null){
return null;
}
[Link] = findMin([Link]);
if([Link]!= null){
return [Link];
} else{
return root;
}
}

//=================================================

//=================================================
// Rotation function to make tree AVL
private PatientTreeNode rotate(PatientTreeNode node){

if(height([Link])-height([Link])>1){
//left-left case
//-----Mistake: let difference of children > 1 / -1 instead of >
or < 0
if(height([Link])-height([Link])>0){
node = rightRotate(node);
}
//left-right case
else if(height([Link])-height([Link])<0){
[Link] = leftRotate([Link]);
node = rightRotate(node);
}
}
else if(height([Link]) - height([Link])<-1){
//right-right case
if(height([Link])-height([Link])<0){
node = leftRotate(node);
}
//right-left case
else if(height([Link])-height([Link])>0){
[Link] = rightRotate([Link]);
node = leftRotate(node);
}
}
return node;
}
private PatientTreeNode rightRotate(PatientTreeNode node){
PatientTreeNode tempNode = node;
node = [Link];

[Link] = [Link];
[Link] = tempNode;

[Link] =
[Link](height([Link]),height([Link]))+1;
[Link] = [Link](height([Link]), height([Link]))+1;

return node;
}

private PatientTreeNode leftRotate(PatientTreeNode node){


PatientTreeNode tempNode = node;
node = [Link];
[Link] = [Link];
[Link] = tempNode;

[Link] =
[Link](height([Link]),height([Link]))+1;
[Link] = [Link](height([Link]), height([Link]))+1;

return node;
}

//===========================================

public PatientTreeNode searchPatient(String cnicNum){


PatientTreeNode patient;
patient = searchPatient(root, cnicNum);

if (patient!= null){
[Link]([Link]());
return patient;
}else {
return null;
}

private PatientTreeNode searchPatient(PatientTreeNode patient, String


cnicNum){
if(patient == null){
return null;
}

int result = [Link]([Link]);

if(result<0){
return searchPatient([Link],cnicNum);
} else if(result>0){
return searchPatient([Link], cnicNum);
}else{
return patient;
}
}

}
public class PatientTreeNode {
Patient pData;
PatientTreeNode left;
PatientTreeNode right;
int height;

public PatientTreeNode(Patient data){


[Link] = data;
left = null;
right = null;
[Link] = -1;
}
}

You might also like