import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Hospital { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Map<Integer,Patient> patients=new HashMap<Integer,Patient>(); PatientFunction pf=new PatientFunction(); Patient p1=new Patient(); Calendar c=Calendar.getInstance(); Date d=new Date(); d.setMonth(d.getMonth()-1); c.setTime(d); p1.setAge(25); p1.setName("Arg"); p1.setLastAppointment(c); patients.put(p1.getPatientId(), p1); Scanner s=new Scanner(System.in); int ctr=0; do { System.out.println("::::::::Hospital::::::::"); System.out.println("Enter 1.Add a patient 2.Update Patient 3.Search patient 4.Display patients or View status"); ctr=s.nextInt(); s.nextLine(); switch(ctr) { case 1: Patient p=pf.addPatient(); if(p==null) System.out.println("Incorrect input"); else patients.put(p.getPatientId(), p); break; case 2: System.out.println("Enter a patient ID"); int pid=s.nextInt(); s.nextLine(); if(patients.containsKey(pid)) { Patient p2=pf.updatePatient(patients.get(pid)); if(p2!=null) patients.put(p2.getPatientId(), p2); else System.out.println("Invalid input"); } else { System.out.println("Patient with the ID does not exist"); } break; case 3: System.out.println("Enter a patient ID"); pid=s.nextInt(); s.nextLine(); if(patients.containsKey(pid)) { pf.displayPatientDetails(patients.get(pid)); } else { System.out.println("Patient with the ID does not exist"); } break; case 4: if(patients.size()==0) System.out.println("No patients in list"); else { ArrayList<Patient> al=new ArrayList<Patient>(patients.values()); pf.displayAll(al); } break; } System.out.println("Continue? Enter y or n"); if(s.nextLine().toLowerCase().equals("y")) ctr=999; } while(ctr==999); } } import java.util.Calendar; import java.util.Date; public class Patient { static int lastId=10000; private int patientId; private String name; private String address; private int age; private String sex; private String illness; private float amount; private Calendar lastAppointment; private String prescription; public String getPrescription() { return prescription; } public void setPrescription(String prescription) { this.prescription = prescription; } public int getPatientId() { return patientId; } public void setPatientId(int patientId) { this.patientId = patientId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getIllness() { return illness; } public void setIllness(String illness) { this.illness = illness; } public float getAmount() { return amount; } public void setAmount(float amount) { this.amount = amount; } public Calendar getLastAppointment() { return lastAppointment; } public void setLastAppointment(Calendar lastAppointment) { this.lastAppointment = lastAppointment; } public static int getLastId() { return lastId; } public static void setLastId(int lastId) { Patient.lastId = lastId; } public Patient(){ this.patientId=++Patient.lastId; lastAppointment=Calendar.getInstance(); } } import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class PatientFunction { Scanner s=new Scanner(System.in); public Patient updatePatient(Patient p) { int ctr=0; try { do { System.out.println("::::Update Customer::::\n1.Name 2.Address 3.Age 4.Sex 5.Illness 6.Amount"); ctr=s.nextInt();s.nextLine(); switch(ctr) { case 1: System.out.println("Current Name:: "+p.getName()); p.setName(s.nextLine()); break; case 2: System.out.println("Current Address:: "+p.getAddress()); p.setAddress(s.nextLine()); break; case 3: System.out.println("Current Age:: "+p.getAge()); p.setAge(Integer.parseInt(s.nextLine()); break; case 4: System.out.println("Current Sex:: "+p.getSex()); p.setSex(s.nextLine()); break; case 5: System.out.println("Current Illness:: "+p.getIllness()); p.setIllness(s.nextLine()); break; case 6: System.out.println("Current Amount:: "+p.getName()); p.setAmount(Float.parseFloat(s.nextLine())); break; } Calendar c=Calendar.getInstance(); c.setTime(new Date()); p.setLastAppointment(c); System.out.println("Update other details? Enter y or n"); if(s.nextLine().toLowerCase().equals("y")) ctr=999; } while(ctr==999); } catch(Exception e) { return null; } return p; } public Patient addPatient() { Patient p=new Patient(); try { System.out.println("Enter Name:: "); p.setName(s.nextLine()); System.out.println("Enter Address:: "); p.setAddress(s.nextLine()); System.out.println("Enter Age:: "); p.setAge(Integer.parseInt(s.nextLine())); System.out.println("Enter Sex:: "); p.setSex(s.nextLine()); System.out.println("Enter Illness:: "); p.setIllness(s.nextLine()); System.out.println("Enter Amount:: "); p.setAmount(Float.parseFloat(s.nextLine())); } catch(Exception e) { return null; } return p; } public void displayPatientDetails(Patient p) { System.out.println(":::Customer Details:"); System.out.println("Customer ID:"+p.getPatientId()); System.out.println("Customer Name:"+p.getName()); System.out.println("Customer Age:"+p.getAge()); System.out.println("Customer Address:"+p.getAddress()); System.out.println("Customer Illness:"+p.getIllness()); System.out.println("Customer Amount:"+p.getAmount()); p.getLastAppointment().add(Calendar.DAY_OF_MONTH, 15); if(p.getLastAppointment().getTime().compareTo(new Date())>0) System.out.println("Customer Status: Active"); else System.out.println("Customer Status: InActive"); p.getLastAppointment().add(Calendar.DAY_OF_MONTH, -15); } public void displayAll(ArrayList<Patient> pl) { for(int i=0;i<pl.size();i++) { Patient p=pl.get(i); p.getLastAppointment().add(Calendar.DAY_OF_MONTH, 15); if(p.getLastAppointment().getTime().compareTo(new Date())>0) System.out.println("Customer ID:: "+p.getPatientId()+"\t Name:"+p.getName()+"\tCustomer Status: Active"); else System.out.println("Customer ID:: "+p.getPatientId()+"\t Name:"+p.getName()+"\tCustomer Status: InActive"); p.getLastAppointment().add(Calendar.DAY_OF_MONTH, -15); } } }
Ads