4 * Created on 10. april 2005, 13:50
7 package drno
.swingui
.guiController
;
9 import java
.rmi
.RemoteException
;
10 import java
.sql
.Timestamp
;
11 import java
.util
.Vector
;
14 import java
.text
.DateFormat
;
15 import java
.util
.GregorianCalendar
;
17 import drno
.interfaces
.EmployeeHandler
;
18 import drno
.interfaces
.IEmployee
;
19 import drno
.interfaces
.IPatient
;
20 import drno
.interfaces
.ITidsreservation
;
21 import drno
.interfaces
.LoginHandler
;
22 import drno
.interfaces
.PatientHandler
;
23 import drno
.interfaces
.TidsreservationsHandler
;
31 public class TableHandler
{
33 PatientHandler p_handler
;
34 EmployeeHandler e_handler
;
35 TidsreservationsHandler t_handler
;
36 Hashtable reservations
;
40 /** Creates a new instance of TableHandler
45 public TableHandler(PatientHandler p_handler
, EmployeeHandler e_handler
, TidsreservationsHandler t_handler
, LoginHandler lh
){//throws SecurityDisallowedException {
48 this.p_handler
= p_handler
;
49 this.e_handler
= e_handler
;
50 this.t_handler
= t_handler
;
51 reservations
= new Hashtable();
52 //data = new Object[28][2];
53 df2
= DateFormat
.getTimeInstance(DateFormat
.SHORT
);
60 public Object
[] getDoctors(){
62 Vector docs
= e_handler
.getAllDoctors();
63 Object
[] docData
= new Object
[docs
.size()];
64 docs
.copyInto(docData
);
73 public Object
[][] getTableData(){
75 Vector ip
= p_handler
.getAllPatients();
76 Object
[][] Pdata
= new Object
[ip
.size()][6];
78 for(int i
=0; i
<ip
.size(); i
++) {
79 Pdata
[i
][0] = ((IPatient
)ip
.elementAt(i
)).getFornavn()+" "+((IPatient
)ip
.elementAt(i
)).getEfternavn();
80 Pdata
[i
][1] = ((IPatient
)ip
.elementAt(i
)).getCpr();
81 Pdata
[i
][2] = ((IPatient
)ip
.elementAt(i
)).getAdresse();
82 Pdata
[i
][3] = ((IPatient
)ip
.elementAt(i
)).getTlf();
83 Pdata
[i
][4] = new Integer(((IPatient
)ip
.elementAt(i
)).getSex());
84 Pdata
[i
][5] = ((IPatient
)ip
.elementAt(i
)).getDoctor();
94 public Object
[][] makeCalendar(int kolloner
, int tidsopdeling
) {
95 Object
[][] data
= new Object
[33][kolloner
];
96 GregorianCalendar c
= new GregorianCalendar();
97 DateFormat df2
= DateFormat
.getTimeInstance(DateFormat
.SHORT
);
98 //Timestamp t = new Timestamp(c.getTimeInMillis());
99 Timestamp t
= new Timestamp(c
.getTimeInMillis());
102 String s
= df2
.format(t
);
103 for(int i
=0; i
<data
.length
;i
++){
105 t
.setMinutes(t
.getMinutes()+tidsopdeling
);
111 public Object
[][] makeCalendarFromLogin() {
113 IEmployee e
= lh
.getUser();
114 int tidsopdeling
= e
.getTidsOpdeling();
115 Object
[][] data
= new Object
[60/tidsopdeling
*8][2];
116 GregorianCalendar c
= new GregorianCalendar();
117 //Timestamp t = new Timestamp(c.getTimeInMillis());
118 Timestamp t
= new Timestamp(c
.getTimeInMillis());
121 String s
= df2
.format(t
);
123 for(int i
=0; i
<data
.length
;i
++){
125 t
.setMinutes(t
.getMinutes()+tidsopdeling
);
130 catch(Exception exception
){
131 exception
.printStackTrace();
135 public Object
[][] makeCalendarFromEmployee(IEmployee e
) {
137 int tidsopdeling
= e
.getTidsOpdeling();
138 Object
[][] data
= new Object
[60/tidsopdeling
*8][2];
139 GregorianCalendar c
= new GregorianCalendar();
140 //Timestamp t = new Timestamp(c.getTimeInMillis());
141 Timestamp t
= new Timestamp(c
.getTimeInMillis());
144 String s
= df2
.format(t
);
146 for(int i
=0; i
<data
.length
;i
++){
148 t
.setMinutes(t
.getMinutes()+tidsopdeling
);
153 catch(Exception exception
){
154 exception
.printStackTrace();
158 //Laver en Util date objekt til et SQL timestamp objekt
159 public java
.sql
.Timestamp
DateToTimestamp(java
.util
.Date d
){
160 Calendar c
= new GregorianCalendar();
162 Timestamp h
= new Timestamp(c
.getTimeInMillis());
163 //Dump tidsreservations databasen i tabellen
167 public Object
[][] getReservationFromDateAndDoc(Object
[][] data
, Timestamp t
, IEmployee e
){
169 reservations
.clear();
170 Vector reservation
= t_handler
.getFromDate(t
,e
);
171 if(reservation
.size()==0){
175 for(int i
=0; i
<reservation
.size(); i
++){
176 ITidsreservation rv
= (ITidsreservation
)reservation
.elementAt(i
);
177 String tbase
= df2
.format(rv
.getTidStart()); //tid fra databasen
179 for(int j
=0; j
<data
.length
;j
++){
180 if(data
[j
][0].equals(tbase
)){
181 reservations
.put(data
[j
][0],rv
);
182 IPatient p
= rv
.getPatient();
183 String navn
= p
.getFornavn()+" "+p
.getEfternavn();
191 catch(Exception exception
){
192 exception
.printStackTrace();
197 public Object
[][] getReservationFromDate(Object
[][] data
, Timestamp t
){
199 reservations
.clear();
200 Vector reservation
= t_handler
.getFromDate(t
); //henter alle reservationer for idag
201 if(reservation
.size()==0){
205 for(int i
= 0; i
<reservation
.size(); i
++){
206 ITidsreservation rv
= (ITidsreservation
)reservation
.elementAt(i
);
207 String tbase
= df2
.format(rv
.getTidStart()); //tid fra databasen
209 for(int j
=0; j
<data
.length
;j
++){
210 if(data
[j
][0].equals(tbase
)){
211 reservations
.put(data
[j
][0],rv
);
212 IPatient p
= rv
.getPatient();
213 String navn
= p
.getFornavn()+" "+p
.getEfternavn();
227 public Hashtable
getHashtable(){
228 if(reservations
.isEmpty()){
236 public int getTidsopdeling(){
239 IEmployee e
= lh
.getUser();
240 int tidsopdeling
= e
.getTidsOpdeling();
242 } catch (RemoteException e
) {
243 // TODO Auto-generated catch block
250 public Vector
getReservationFromPatient(IPatient p
){
252 Vector v
= t_handler
.getFromPatient(p
);
260 catch(Exception exception
){
261 exception
.printStackTrace();
265 public String
PInfo_toString(IPatient p
){
267 String output
= "PATIENT INFO:\n"+
268 "Fornavn:\t"+p
.getFornavn()+"\n"+
269 "Efternavn:\t"+p
.getEfternavn()+"\n"+
270 "CPR:\t"+p
.getCpr()+"\n"+
271 "Adresse:\t"+p
.getAdresse()+"\n"+
272 "TLF:\t"+p
.getTlf()+"\n"+
273 "Alder:\t"+p
.getAlder()+"\n\n";
275 } catch (RemoteException e
) {
276 // TODO Auto-generated catch block
282 public String
TInfo_toString(ITidsreservation t
){
284 String output
= "RESERVATION INFO:\n"+
285 "Tidstart:\t"+t
.getTidStart()+"\n"+
286 "Emne:\t"+t
.getEmne()+"\n";
288 } catch (RemoteException e
) {
289 // TODO Auto-generated catch block
295 public void print(String str
) {
296 //System.out.print(str);
298 public void println(String str
) {
299 //System.out.println(str);