A java application to implement hospital management system

By | October 31, 2012

This Hospital management application performs the following operations.

1. Register a patient with following details Patient-Name, patient Address, Age, Patient-Sex, Patient-Illness,Amount-for-Appointment.
2. Update entered patient details
3. Display patient detials
4. Remove inactive patient. A patient is treated as inactive if he is 15 days old from the the date of admit to the hospital.

 

package Hospital;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;

public class HospitalProcess {

static ArrayList<Patient> arl = new ArrayList<Patient>();
static String joindate;

public static void main(String[] args) throws IOException {

char l='i';
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter=  new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");
joindate = formatter.format(currentDate.getTime());

Patient p1 = new Patient(1,"Raja", "Miyapur,Hyderabad" ,40 ,'m' ,"Fever" ,250f ,joindate);
arl.add(p1);
Patient p2 = new Patient(2,"Rani", "Madhapur,Hyderabad" ,45 ,'f' ,"Cough" ,250f ,joindate);
arl.add(p2);
Patient p3 = new Patient(3,"James", "Hydernagar,Hyderabad" ,56 ,'m' ,"Cancer" ,300f ,joindate);
arl.add(p3);
do
{

Patient p = new Patient();
System.out.println("Press 1 to register a Patient,2 to update Patient details,3 to deactivate Patient details,4 to display  Patient details,");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int choice =Integer.parseInt(br.readLine());

switch(choice)
{
case 1:
p.registerPatient();
System.out.println("Patient Registered Successfully !!!");
p.showPatientDetails();
break;
case 2:
p.showPatientDetails();
p.updatePatientDetails();

break;
case 3:
p.removeInactivePatient();
break;
case 4:
Collections.sort(arl);
p.showPatientDetails();
break;
default:
System.out.println("Patient with that id doesnot exists");
System.out.println("Try again");
break;
}

System.out.println("Do you wanna continue selecting options(y/n):");
l=(char)br.read();
}while(l=='y');
}

}
class Patient implements Comparable<Patient> {

int patientID;
String patientName;
String patientAddress;
int age;
char patientSex;
String patientIllness;
float amountForAppointment;
String joindate;

HospitalProcess hm = new HospitalProcess();

Patient()    {}

public int compareTo(Patient p)
{
return this.patientID-p.patientID;
}

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Patient(int patientID,String patientName,String patientAddress,int age,char patientSex,String patientIllness,float amountForAppointment, String joindate)
{
this.patientID=patientID;
this.patientName=patientName;
this.patientAddress=patientAddress;
this.age=age;
this.patientSex=patientSex;
this.patientIllness=patientIllness;
this.amountForAppointment=amountForAppointment;
this.joindate = joindate;
}

void registerPatient()throws IOException
{
Patient pr = new Patient();
pr.showPatientDetails();
int patientID=hm.arl.size();
pr.patientID = patientID+1;
System.out.println("Enter Patient name:");
pr.patientName = br.readLine();
System.out.println("Enter Patient Address:");
pr.patientAddress =br.readLine();
System.out.println("Enter Patient Age:");
pr.age =Integer.parseInt(br.readLine());
System.out.println("Enter Patient Sex:");
String temp = br.readLine();
pr.patientSex =temp.charAt(0);
System.out.println("Enter Patient Illness:");
pr.patientIllness =br.readLine();
System.out.println("Enter the amount patient needs to pay for appointment:");
pr.amountForAppointment =Float.parseFloat(br.readLine());
pr.joindate = hm.joindate;
hm.arl.add(pr);

}
void removeInactivePatient() throws IOException
{
Patient p2 = new Patient();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Patient ID:");
int id1= Integer.parseInt(br.readLine());
int flag=0;
int flag2=0;
String presentdate;
String afteraddingdays;
for(int i=0;i<hm.arl.size();i++)
{
if(id1!=hm.arl.get(i).patientID)
{
flag=0;

}
else if(id1==hm.arl.get(i).patientID)
{
presentdate=hm.arl.get(i).joindate;
int daysToIncrement = 15;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 15);
SimpleDateFormat formatter=  new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");
afteraddingdays = formatter.format(cal.getTime());
flag=1;
if(presentdate==afteraddingdays)
{
hm.arl.remove(i);
System.out.println("Patient deleted as his time expired");
flag2=1;
}
else{
flag2=0;
}
}
}

if((flag) == 0)
{
System.out.println("Patient with that ID doesnot exist");
}
if(flag2==0)
{
System.out.println("Patient has still more days left before his appointment expires");
}

}

void updatePatientDetails() throws IOException

{
char l='n';
Patient p2 = new Patient(patientID,patientName,patientAddress,age,patientSex,patientIllness,amountForAppointment,joindate);
do{
System.out.println("Enter patient ID you want to update:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int idnum= Integer.parseInt(br.readLine());
for(int i=0;i<hm.arl.size();i++)
{
if(idnum == hm.arl.get(i).patientID)
{
System.out.println("Press 1 change Patient name,2 to change Patient Address,3 to change Patient age,4 to change Patient sex,5 to change Patient illness,6 to change Patient amount for appointment along with the medical expenses");
int ch =Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("Enter new Patient name:");
p2.patientName = br.readLine();
p2.patientID=hm.arl.get(i).patientID;
p2.patientAddress=hm.arl.get(i).patientAddress;
p2.age=hm.arl.get(i).age;
p2.patientSex=hm.arl.get(i).patientSex;
p2.patientIllness=hm.arl.get(i).patientIllness;
p2.amountForAppointment=hm.arl.get(i).amountForAppointment;
p2.joindate=hm.arl.get(i).joindate;
hm.arl.set(i,p2);
System.out.println("Patient updated !!!");
break;

case 2:
System.out.println("Enter new patient Address:");
p2.patientAddress =br.readLine();
p2.patientID=hm.arl.get(i).patientID;
p2.patientName=hm.arl.get(i).patientName;
p2.age=hm.arl.get(i).age;
p2.patientSex=hm.arl.get(i).patientSex;
p2.patientIllness=hm.arl.get(i).patientIllness;
p2.amountForAppointment=hm.arl.get(i).amountForAppointment;
p2.joindate=hm.arl.get(i).joindate;
hm.arl.set(i,p2);
System.out.println("Patient updated !!!");
break;

case 3:
System.out.println("Enter new Patient age:");
p2.age =Integer.parseInt(br.readLine());
p2.patientID=hm.arl.get(i).patientID;
p2.patientName=hm.arl.get(i).patientName;
p2.patientAddress=hm.arl.get(i).patientAddress;
p2.patientSex=hm.arl.get(i).patientSex;
p2.patientIllness=hm.arl.get(i).patientIllness;
p2.amountForAppointment=hm.arl.get(i).amountForAppointment;
p2.joindate=hm.arl.get(i).joindate;
hm.arl.set(i,p2);
System.out.println("Patient updated !!!");
break;

case 4:
System.out.println("Enter new Patient illness:");
p2.age =hm.arl.get(i).age;
p2.patientID=hm.arl.get(i).patientID;
p2.patientName=hm.arl.get(i).patientName;
p2.patientAddress=hm.arl.get(i).patientAddress;
p2.patientSex=hm.arl.get(i).patientSex;
p2.patientIllness=br.readLine();
p2.amountForAppointment=hm.arl.get(i).amountForAppointment;
p2.joindate=hm.arl.get(i).joindate;
hm.arl.set(i,p2);
System.out.println("Patient updated !!!");
break;

case 5:
System.out.println("Enter the new amount which the patient needs to pay:");
p2.age =hm.arl.get(i).age;
p2.patientID=hm.arl.get(i).patientID;
p2.patientName=hm.arl.get(i).patientName;
p2.patientAddress=hm.arl.get(i).patientAddress;
p2.patientSex=hm.arl.get(i).patientSex;
p2.patientIllness=hm.arl.get(i).patientIllness;
p2.amountForAppointment=Float.parseFloat(br.readLine());
p2.joindate=hm.arl.get(i).joindate;
hm.arl.set(i,p2);
System.out.println("Patient updated !!!");
break;

default:
System.out.println("Invalid choice.");
break;
}
}
}
System.out.println("Do you want to continue updating(y/n):");
l=(char)br.read();
}while(l=='y');

}
void showPatientDetails()
{
System.out.println("patient-ID  Patient-Name  patient Address  Age   Patient-Sex  Patient-Illness  Amount-for-Appointment  Join-date");

for(int i=0;i<hm.arl.size();i++)
{

System.out.println(hm.arl.get(i).patientID+"           "+hm.arl.get(i).patientName+"         "+hm.arl.get(i).patientAddress+"      "+hm.arl.get(i).age+"         "+hm.arl.get(i).patientSex+"         "+hm.arl.get(i).patientIllness+"        "+hm.arl.get(i).amountForAppointment+"         "+hm.arl.get(i).joindate);
}
}

}
Please Share: Tweet about this on TwitterShare on FacebookShare on Google+Share on RedditPin on PinterestShare on LinkedInDigg thisShare on StumbleUponShare on TumblrBuffer this pageShare on VKEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *