Parkinson Disease Database

spirals.motol.database
Class Database

java.lang.Object
  extended by spirals.motol.database.Database

public class Database
extends java.lang.Object

Root class for storing database.

Each time database is exported all pacients are stored in random order without surname and firstname. No corespondence between database and exported data should be found.

Database contains Pacients. Pacients have Visits and Visits consist of Data. Database is stored in directory 'data' containing root file and direcotries of pacients. Only root file is loaded on application startup. Each pacient directory contains xml files representing visits and zip archives with captured tablet data for visits.

Copyright: Copyright (c) 2005 Jan Dolezel

Company: ÈVUT FEL, Prague

See Also:
TabletData, Data, Pacient, Visit

Nested Class Summary
static class Database.SORT
          Enumerates sorting possibilities
 
Field Summary
static java.lang.String backupAttr
          name of backup date attribute
private  java.util.HashMap<java.lang.String,Pacient> database
          main database content
static java.lang.String databaseTag
          database tag (root element)
private  Engine engine
          engine
private  Database.SORT howSort
          current algorithm for sorting
private  java.util.Date lastBackup
          date of last backup
private  java.util.List<Pacient> listAll
          sorted list of all pacients
private  java.util.List<Pacient> listRestricted
          sorted list of choosen pacients
private  boolean restricted
          whether show all or only choosen pacients
private  java.io.File rootFile
          root file of stored database
 
Constructor Summary
Database(Engine engine)
          create new database or load content from file Check if database exist.
 
Method Summary
 void addPacient(Pacient pacient)
          add pacient to database and save Updates or inserts information about pacient, sort lists of pacients and saves database to disk.
 void backuped()
          must be called when database is backuped
 void clearRestricted()
          clear list with choosen pacients
private  void createDB()
          create new database Creates new database directory and root file.
 void export()
          exports data from database to user choosen file All database data are read, new hash string for pacients are generated.
 java.util.List<Pacient> getAll()
          return list of all pacients in database
 long getDatabaseSize()
          return size of database stored on disk
 org.jdom.Element getElement()
          return XML representation of database Stores all pacient information.
 Engine getEngine()
          return engine
 java.util.Date getLastBackup()
          return date of last database backup
 java.lang.String getNextID()
          generates next unused hash string for new pacient Output is something that nears md5 hash output.
 long getPacientCount()
          return number of all pacients
 java.util.List<Pacient> getRestricted()
          returns list of choosen pacients
 int getTreeCount()
          return size of actual list of pacients
 int getTreeIndex(Pacient pacient)
          return index of pacient in actual list of pacients
 Pacient getTreePacient(int index)
          return pacient on specified position in actual list of pacients
private  void loadFromFile(java.io.File file)
          load database from file Load database root file.
private  java.lang.String makeID(long id)
          create text representation of long
 void save()
          save database to disk Calls getElement() to produce XML representation and store it to disk.
 void setRestricted(boolean restricted)
          sets all or only choosen pacients
 void setRestrictedBorn(java.util.Date dateBegin, java.util.Date dateEnd)
          add pacients to list of choosen which were born between dateBegin and dateEnd
 void setRestrictedName(java.lang.String nameBegin, java.lang.String nameEnd)
          add pacients to list of choosen which surname is between nameBegin and nameEnd
 void setRestrictedVisit(java.util.Date dateBegin, java.util.Date dateEnd)
          add pacients to list of choosen which have visit between dateBegin and dateEnd
 void sort()
          sort both lists of pacients
private  void sort(java.util.Comparator c)
          sort both lists of pacients with specified comparator
 void sort(Database.SORT how)
          sort both lists of pacients with specified criteria
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engine

private Engine engine
engine


database

private java.util.HashMap<java.lang.String,Pacient> database
main database content


listAll

private java.util.List<Pacient> listAll
sorted list of all pacients


listRestricted

private java.util.List<Pacient> listRestricted
sorted list of choosen pacients


restricted

private boolean restricted
whether show all or only choosen pacients


howSort

private Database.SORT howSort
current algorithm for sorting


rootFile

private java.io.File rootFile
root file of stored database


lastBackup

private java.util.Date lastBackup
date of last backup


databaseTag

public static final java.lang.String databaseTag
database tag (root element)

See Also:
Constant Field Values

backupAttr

public static final java.lang.String backupAttr
name of backup date attribute

See Also:
Constant Field Values
Constructor Detail

Database

public Database(Engine engine)
create new database or load content from file

Check if database exist. If so, load it from disk, otherwise create new one.

Method Detail

createDB

private void createDB()
create new database

Creates new database directory and root file.


loadFromFile

private void loadFromFile(java.io.File file)
load database from file

Load database root file. All other files ar loaded after first need of them. Main file consist only from pacient names, their born date, right-hand attribute and hash representation. Hash identifies pacient in database and in directory structure on disk.


save

public void save()
save database to disk

Calls getElement() to produce XML representation and store it to disk.

See Also:
getElement()

getElement

public org.jdom.Element getElement()
return XML representation of database

Stores all pacient information.


getAll

public java.util.List<Pacient> getAll()
return list of all pacients in database


getRestricted

public java.util.List<Pacient> getRestricted()
returns list of choosen pacients


clearRestricted

public void clearRestricted()
clear list with choosen pacients


setRestrictedVisit

public void setRestrictedVisit(java.util.Date dateBegin,
                               java.util.Date dateEnd)
add pacients to list of choosen which have visit between dateBegin and dateEnd


setRestrictedBorn

public void setRestrictedBorn(java.util.Date dateBegin,
                              java.util.Date dateEnd)
add pacients to list of choosen which were born between dateBegin and dateEnd


setRestrictedName

public void setRestrictedName(java.lang.String nameBegin,
                              java.lang.String nameEnd)
add pacients to list of choosen which surname is between nameBegin and nameEnd


setRestricted

public void setRestricted(boolean restricted)
sets all or only choosen pacients


getTreeCount

public int getTreeCount()
return size of actual list of pacients


getTreePacient

public Pacient getTreePacient(int index)
return pacient on specified position in actual list of pacients


getTreeIndex

public int getTreeIndex(Pacient pacient)
return index of pacient in actual list of pacients


sort

public void sort()
sort both lists of pacients


sort

public void sort(Database.SORT how)
sort both lists of pacients with specified criteria


sort

private void sort(java.util.Comparator c)
sort both lists of pacients with specified comparator


getNextID

public java.lang.String getNextID()
generates next unused hash string for new pacient

Output is something that nears md5 hash output.


addPacient

public void addPacient(Pacient pacient)
add pacient to database and save

Updates or inserts information about pacient, sort lists of pacients and saves database to disk.


getPacientCount

public long getPacientCount()
return number of all pacients


getDatabaseSize

public long getDatabaseSize()
return size of database stored on disk

Returns:
long number of bytes

getLastBackup

public java.util.Date getLastBackup()
return date of last database backup


getEngine

public Engine getEngine()
return engine


backuped

public void backuped()
must be called when database is backuped


export

public void export()
exports data from database to user choosen file

All database data are read, new hash string for pacients are generated. These 'hash' strings are from numbered sequence form zero to number of pacients. Each pacient recieves random number from this sequence. In each export the same pacient will have another number from sequence. The links in file structure based on these hash strings must be updated.
Exported database is saved in zip archive.


makeID

private java.lang.String makeID(long id)
create text representation of long

Returns:
String 8 characters

Parkinson Disease Database