com.pixelmed.database
Class DatabaseInformationModel

java.lang.Object
  extended by com.pixelmed.database.DatabaseInformationModel
Direct Known Subclasses:
DicomDatabaseInformationModel

public abstract class DatabaseInformationModel
extends Object

The DatabaseInformationModel class is an abstract class that contains the core functionality for storing, accessing and maintaining a persistent representation of selected attributes of composite objects.

It hides an underlying SQL database implementation that stores the attributes of each entity in the information model in tables.

Abstract sub-classes, such as DicomDatabaseInformationModel, may refine the type of information model supported, since this base class is fairly generic and not dependent on any particular DICOM information model. Concrete sub-classes define particular models by overriding the methods that define the root entities and the relationship between entities, as well as the unique keys for each particular entity.

In addition, the concrete sub-classes define which attributes of each entity will be included in the persistent representation (the database tables), usually by means of a specialized sub-class of DicomDictionary which contains the sub-set of relevant attributes and may change their mapping to information entities, such as DicomDictionaryForPatientStudySeriesConcatenationInstanceModel.

For example, an application might instantiate a PatientStudySeriesConcatenationInstanceModel or a StudySeriesInstanceModel, as follows:

        final DatabaseInformationModel d = new PatientStudySeriesConcatenationInstanceModel("test");
 

Composite objects previously read into a AttributeList from a DICOM file in a persistent location could be inserted into the persistent representation (the database) as follows, indicating in this case that the file was copied (and may later be deleted) rather than referenced:

        d.insertObject(list,fileName,DatabaseInformationModel.FILE_COPIED);
 

External (unsecure) SQL access to the database is possible if a databaseServerName argument is supplied in the constructor, in which case a tool like org.hsqldb.util.DatabaseManagerSwing (described in detail at Hsqldb User Guide: Appendix F. Database Manager) can be used to query or manage the database. For example:

% java -cp lib/additional/hsqldb.jar org.hsqldb.util.DatabaseManagerSwing --url "jdbc:hsqldb:hsql://hostname/databaseServerName"
 

where "hostname" is the name of the host (perhaps "localhost"), and "databaseServerName" is the name supplied in the constructor.

Note that the default username ("sa") and password (empty) are not secure.

See Also:
com.pixelmed.database

Field Summary
protected  HashMap additionalIndexMapOfColumnsToTables
           
protected  Connection databaseConnection
           
protected  String databaseRootName
           
protected static String defaultDatabaseRootName
           
protected  DicomDictionary dictionary
           
protected  Server externalServerInstance
           
static String FILE_COPIED
           
static String FILE_REFERENCED
           
protected  HashMap listsOfAttributesByInformationEntity
           
protected static String localFileName
           
protected static String localFileReferenceTypeColumnName
           
protected static String localParentReferenceColumnName
           
protected static String localPrimaryKeyColumnName
           
protected static String localRecordInsertionTimeColumnName
           
protected static String personNameCanonicalColumnNamePrefix
           
protected static String personNameCanonicalColumnNameSuffix
           
protected static String personNamePhoneticCanonicalColumnNamePrefix
           
protected static String personNamePhoneticCanonicalColumnNameSuffix
           
protected  InformationEntity rootInformationEntity
           
protected static String userColumnName1
           
protected static String userColumnName2
           
protected static String userColumnName3
           
protected static String userColumnName4
           
 
Constructor Summary
DatabaseInformationModel(String databaseFileName, InformationEntity rootInformationEntity, DicomDictionary dictionary)
          Instantiate a persistent information model using the named database.
DatabaseInformationModel(String databaseFileName, InformationEntity rootInformationEntity, DicomDictionary dictionary, String databaseRootName)
          Instantiate a persistent information model using the named database.
DatabaseInformationModel(String databaseFileName, String databaseServerName, InformationEntity rootInformationEntity, DicomDictionary dictionary)
          Instantiate a persistent information model using the named database allowing external SQL access.
DatabaseInformationModel(String databaseFileName, String databaseServerName, InformationEntity rootInformationEntity, DicomDictionary dictionary, String databaseRootName)
          Instantiate a persistent information model using the named database allowing external SQL access.
 
Method Summary
protected static void appendExactOrIsNullMatch(StringBuffer b, String value)
          Append a check for a match against a string value, accounting for the need to use the "IS NULL" rather than "=" expression when wanting to explciitly have NULL match NULL rather to never match.
 void close()
          Close the underlying connection to the database and shutdown any external SQL server.
protected  void createAdditionalIndexes()
          Create any additional indexes to optimize queries, for example for UIDs.
protected abstract  String createPrimaryKeyForSelectedInformationEntity(InformationEntity ie)
          Create a new unique key which may be used to identify a new instance of an entity.
 void deleteRecord(InformationEntity ie, String localPrimaryKeyValue)
          Delete a database record (a particular instance of an information entity).
 void deleteSelectedRecord(InformationEntity ie, String localPrimaryKeyValue)
          Deprecated. use deleteRecord(InformationEntity,String) instead
protected  void doCommonConstructorStuff(String databaseFileName, String databaseServerName, InformationEntity rootInformationEntity, DicomDictionary dictionary, String databaseRootName)
          Instantiate a persistent information model using the named database.
protected  void extendCreateStatementStringWithAnyExtraAttributes(StringBuffer b, InformationEntity ie)
          Extend a SQL CREATE TABLE statement in the process of being constructed with any additional attributes (columns) that the model requires.
protected  void extendCreateStatementStringWithDerivedAttributes(StringBuffer b, InformationEntity ie)
          Extend a SQL CREATE TABLE statement in the process of being constructed with any derived attributes (columns) that the model requires.
protected  void extendCreateStatementStringWithUserColumns(StringBuffer b, InformationEntity ie)
          Extend a SQL CREATE TABLE statement in the process of being constructed with any user optional columns that the model requires.
protected abstract  void extendInsertStatementStringWithAttributeNamesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie)
          Extend a SQL INSERT statement in the process of being constructed with the names of the attributes in the instance for the entity.
protected abstract  void extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie, String fileName)
          Deprecated. use extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity() instead
protected abstract  void extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie, String fileName, String fileReferenceType)
          Extend a SQL INSERT statement in the process of being constructed with the values of the attributes in the instance for the entity.
protected abstract  void extendInsertStatementStringWithDerivedAttributeNamesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie)
          Extend a SQL INSERT statement in the process of being constructed with the names of the derived attributes in the instance for the entity.
protected abstract  void extendInsertStatementStringWithDerivedAttributeValuesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie)
          Extend a SQL INSERT statement in the process of being constructed with the values of the derived attributes in the instance for the entity.
protected abstract  void extendInsertStatementStringWithPersonNameSearchColumnsForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie)
          Extend a SQL INSERT statement in the process of being constructed with the names of the additional search columns derived from person name attributes in the instance for the entity.
protected abstract  void extendInsertStatementStringWithPersonNameSearchValuesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie)
          Extend a SQL INSERT statement in the process of being constructed with the values of the additional search columns derived from person name attributes in the instance for the entity.
protected abstract  void extendStatementStringWithMatchingAttributesForSelectedInformationEntity(StringBuffer b, AttributeList list, InformationEntity ie)
          Extend a SQL SELECT statement in the process of being constructed with matching clauses for the unique keys of the entity and all its parents.
protected  void finalize()
           
 ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntity(InformationEntity ie)
          For all records of an information entity, get the values of all the columns in the entity's database table.
 ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithMatchingParent(InformationEntity ieWanted, InformationEntity ieParent, String parentMatchingAttribute, String parentMatchingValue)
          For all records of an information entity with all parents matching a particular attribute value, get the values of all attributes.
 ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedKeyValue(InformationEntity ie, String keyName, String keyValue)
          For all records of an information entity matching the specified key value, get the values of all the columns in the entity's database table.
 ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedParent(InformationEntity ie, String localParentReference)
          For all records of an information entity with the specified parent, get the values of all the columns in the entity's database table.
 ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedUID(InformationEntity ie, String uid)
          For all records of an information entity matching the specified UID, get the values of all the columns in the entity's database table.
 Map findAllAttributeValuesForSelectedRecord(InformationEntity ie, String localPrimaryKeyValue)
          For a particular instance of an information entity, get the values of all the columns in the entity's database table.
 AttributeTag getAttributeTagFromDatabaseColumnName(String columnName)
          Get the name of the DICOM element corresponding to the database table column.
abstract  InformationEntity getChildTypeForParent(InformationEntity ie)
          For an information entity (regardless of a particular instance), find the next information entity lower down in the information model hierarchy in the general case.
abstract  InformationEntity getChildTypeForParent(InformationEntity ie, AttributeList list)
          For a particular instance of an information entity, find the next information entity lower down in the information model hierarchy.
abstract  InformationEntity getChildTypeForParent(InformationEntity ie, boolean concatenation)
          For a particular instance of an information entity, find the next information entity lower down in the information model hierarchy.
static String getDatabaseColumnNameFromDicomName(String descriptiveName)
          Get the name of the table column corresponding to the DICOM element name.
 String getDatabaseColumnNameFromDicomTag(AttributeTag tag)
          Get the name of the table column corresponding to the DICOM tag.
abstract  String getDescriptiveColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the first of three descriptive attributes for the entity.
 String getDicomNameFromDatabaseColumnName(String columnName)
          Get the name of the DICOM element corresponding to the database table column.
 InformationEntity getInformationEntityFromTag(AttributeTag tag)
          Get the information entity in this information model for the specified tag
 String getLocalFileNameColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the local file name of a stored object.
 String getLocalFileReferenceTypeColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the reference type of a stored object.
 String getLocalParentReferenceColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the reference to an instance of the entity's parent.
 String getLocalPrimaryKeyColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the primary key of an instance of the entity.
 String getLocalRecordInsertionTimeColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the record insertion time recorded as the value returned by System.currentTimeMillis().
abstract  String getNametoDescribeThisInstanceOfInformationEntity(InformationEntity ie, Map returnedAttributes)
          For a particular instance of an information entity, find a descriptive name for the entity suitable for rendering.
abstract  String getOtherDescriptiveColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the second of three descriptive attributes for the entity.
abstract  String getOtherOtherDescriptiveColumnName(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the third of three descriptive attributes for the entity.
 QueryResponseGeneratorFactory getQueryResponseGeneratorFactory(int debugLevel)
          Get a factory to manufacture a query response generator capable of performing a query and returning the results.
 RetrieveResponseGeneratorFactory getRetrieveResponseGeneratorFactory(int debugLevel)
          Get a factory to manufacture a retrieve response generator capable of performing a retrieve and returning the results.
static String getSQLTypeFromDicomValueRepresentation(byte[] vr)
          Given a DICOM Value Representation, determine the appropriate corresponding SQL type to use.
static String getTableNameForInformationEntity(InformationEntity ie)
          Get the table name for an information entity.
abstract  String getUIDColumnNameForInformationEntity(InformationEntity ie)
          For a particular information entity, find the name of the column in the entity's database table containing the DICOM UID for the entity.
 void insertObject(AttributeList list, String fileName)
          Deprecated. use insertObject() instead
 void insertObject(AttributeList list, String fileName, String fileReferenceType)
          Insert a DICOM composite object, and the relevant attributes of all the entities it contains, into the database.
protected abstract  boolean isInformationEntityInModel(InformationEntity ie)
          Is the entity in the information model ?
protected  boolean isInformationEntityInModel(String ieName)
          Is the named entity in the information model ?
 String localFileNameColumnName(InformationEntity ie)
          Deprecated. use getLocalFileNameColumnName() instead
 String toString()
          Returns a string describing the structure (not the contents) of the database.
 void updateSelectedRecord(InformationEntity ie, String localPrimaryKeyValue, String key, String value)
          For a particular instance of an information entity, update the record in the database table with a new value for the specified attribute (column).
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_COPIED

public static final String FILE_COPIED
See Also:
Constant Field Values

FILE_REFERENCED

public static final String FILE_REFERENCED
See Also:
Constant Field Values

defaultDatabaseRootName

protected static final String defaultDatabaseRootName
See Also:
Constant Field Values

localPrimaryKeyColumnName

protected static final String localPrimaryKeyColumnName
See Also:
Constant Field Values

localParentReferenceColumnName

protected static final String localParentReferenceColumnName
See Also:
Constant Field Values

localRecordInsertionTimeColumnName

protected static final String localRecordInsertionTimeColumnName
See Also:
Constant Field Values

localFileName

protected static final String localFileName
See Also:
Constant Field Values

localFileReferenceTypeColumnName

protected static final String localFileReferenceTypeColumnName
See Also:
Constant Field Values

personNameCanonicalColumnNamePrefix

protected static final String personNameCanonicalColumnNamePrefix
See Also:
Constant Field Values

personNameCanonicalColumnNameSuffix

protected static final String personNameCanonicalColumnNameSuffix
See Also:
Constant Field Values

personNamePhoneticCanonicalColumnNamePrefix

protected static final String personNamePhoneticCanonicalColumnNamePrefix
See Also:
Constant Field Values

personNamePhoneticCanonicalColumnNameSuffix

protected static final String personNamePhoneticCanonicalColumnNameSuffix
See Also:
Constant Field Values

userColumnName1

protected static final String userColumnName1
See Also:
Constant Field Values

userColumnName2

protected static final String userColumnName2
See Also:
Constant Field Values

userColumnName3

protected static final String userColumnName3
See Also:
Constant Field Values

userColumnName4

protected static final String userColumnName4
See Also:
Constant Field Values

rootInformationEntity

protected InformationEntity rootInformationEntity

listsOfAttributesByInformationEntity

protected HashMap listsOfAttributesByInformationEntity

additionalIndexMapOfColumnsToTables

protected HashMap additionalIndexMapOfColumnsToTables

databaseConnection

protected Connection databaseConnection

externalServerInstance

protected Server externalServerInstance

dictionary

protected DicomDictionary dictionary

databaseRootName

protected String databaseRootName
Constructor Detail

DatabaseInformationModel

public DatabaseInformationModel(String databaseFileName,
                                InformationEntity rootInformationEntity,
                                DicomDictionary dictionary)
                         throws DicomException

Instantiate a persistent information model using the named database.

Will open a connection to the database, and create any tables if this is the first time, or re-use any persistent information if not.

Parameters:
databaseFileName - the file name of the underlying SQL database instance to be used
rootInformationEntity - the top entity of the information model; specific to a particular model's constructor
dictionary - used to decide which attributes to include for each entity when creating the tables
Throws:
DicomException - thrown if a connection to the database cannot be established

DatabaseInformationModel

public DatabaseInformationModel(String databaseFileName,
                                InformationEntity rootInformationEntity,
                                DicomDictionary dictionary,
                                String databaseRootName)
                         throws DicomException

Instantiate a persistent information model using the named database.

Will open a connection to the database, and create any tables if this is the first time, or re-use any persistent information if not.

Parameters:
databaseFileName - the file name of the underlying SQL database instance to be used
rootInformationEntity - the top entity of the information model; specific to a particular model's constructor
dictionary - used to decide which attributes to include for each entity when creating the tables
databaseRootName - the name used for the root node of the database in TreeModel
Throws:
DicomException - thrown if a connection to the database cannot be established

DatabaseInformationModel

public DatabaseInformationModel(String databaseFileName,
                                String databaseServerName,
                                InformationEntity rootInformationEntity,
                                DicomDictionary dictionary)
                         throws DicomException

Instantiate a persistent information model using the named database allowing external SQL access.

Will open a connection to the database, and create any tables if this is the first time, or re-use any persistent information if not.

Parameters:
databaseFileName - the file name of the underlying SQL database instance to be used
databaseServerName - the name to use for external TCP access to database (such a server will not be started if this value is null or zero length)
rootInformationEntity - the top entity of the information model; specific to a particular model's constructor
dictionary - used to decide which attributes to include for each entity when creating the tables
Throws:
DicomException - thrown if a connection to the database cannot be established

DatabaseInformationModel

public DatabaseInformationModel(String databaseFileName,
                                String databaseServerName,
                                InformationEntity rootInformationEntity,
                                DicomDictionary dictionary,
                                String databaseRootName)
                         throws DicomException

Instantiate a persistent information model using the named database allowing external SQL access.

Will open a connection to the database, and create any tables if this is the first time, or re-use any persistent information if not.

Parameters:
databaseFileName - the file name of the underlying SQL database instance to be used
databaseServerName - the name to use for external TCP access to database (such a server will not be started if this value is null or zero length)
rootInformationEntity - the top entity of the information model; specific to a particular model's constructor
dictionary - used to decide which attributes to include for each entity when creating the tables
databaseRootName - the name used for the root node of the database in TreeModel
Throws:
DicomException - thrown if a connection to the database cannot be established
Method Detail

doCommonConstructorStuff

protected void doCommonConstructorStuff(String databaseFileName,
                                        String databaseServerName,
                                        InformationEntity rootInformationEntity,
                                        DicomDictionary dictionary,
                                        String databaseRootName)
                                 throws DicomException

Instantiate a persistent information model using the named database.

Will open a connection to the database, and create any tables if this is the first time, or re-use any persistent information if not.

Parameters:
databaseFileName - the file name of the underlying SQL database instance to be used (or "mem:name" if the database is to be in-memory and not persisted)
databaseServerName - the name to use for external TCP access to database (such a server will not be started if this value is null or zero length)
rootInformationEntity - the top entity of the information model; specific to a particular model's constructor
dictionary - used to decide which attributes to include for each entity when creating the tables
databaseRootName - the name used for the root node of the database in TreeModel
Throws:
DicomException - thrown if a connection to the database cannot be established

close

public void close()

Close the underlying connection to the database and shutdown any external SQL server.

Prior to actually closing will also try to formally shutdown and compact the database.


finalize

protected void finalize()
Overrides:
finalize in class Object

isInformationEntityInModel

protected abstract boolean isInformationEntityInModel(InformationEntity ie)

Is the entity in the information model ?

Will be specific to a particular concrete information model.

Returns:
boolean the information entity is in the information model

isInformationEntityInModel

protected boolean isInformationEntityInModel(String ieName)

Is the named entity in the information model ?

Will be specific to a particular concrete information model.

Parameters:
ieName - a String name, whose case is ignored (e.g., a database table named for the corresponding information entity)
Returns:
the name corresponds to an information entity that is in the information model

getDatabaseColumnNameFromDicomTag

public String getDatabaseColumnNameFromDicomTag(AttributeTag tag)

Get the name of the table column corresponding to the DICOM tag.

Parameters:
tag - the tag of the DICOM element
Returns:
a String column name, or null if not known

getDatabaseColumnNameFromDicomName

public static String getDatabaseColumnNameFromDicomName(String descriptiveName)

Get the name of the table column corresponding to the DICOM element name.

Parameters:
descriptiveName - the name of the DICOM element
Returns:
the upper case String column name, or null if not known

getDicomNameFromDatabaseColumnName

public String getDicomNameFromDatabaseColumnName(String columnName)

Get the name of the DICOM element corresponding to the database table column.

Parameters:
columnName - the name of the database column
Returns:
a String descriptive name of the DICOM element, or null if not known

getAttributeTagFromDatabaseColumnName

public AttributeTag getAttributeTagFromDatabaseColumnName(String columnName)

Get the name of the DICOM element corresponding to the database table column.

Parameters:
columnName - the name of the database column
Returns:
the tag, or null if not known

createAdditionalIndexes

protected void createAdditionalIndexes()
                                throws DicomException

Create any additional indexes to optimize queries, for example for UIDs.

Called after creating tables and default indexes.

Throws:
DicomException

extendCreateStatementStringWithAnyExtraAttributes

protected void extendCreateStatementStringWithAnyExtraAttributes(StringBuffer b,
                                                                 InformationEntity ie)

Extend a SQL CREATE TABLE statement in the process of being constructed with any additional attributes (columns) that the model requires.

Called when creating the tables for a new database.

Specific to each concrete information model extending DatabaseInformationModel. Defaults to adding no extra columns if not overridden (i.e. it is not abstract).

For example, there may be a DICOM attribute that is defined to be in a particular information entity in the dictionary (for example InstanceNumber is at the concatenation level), but for the convenience of the user of tree and table browsers it may be nice to replicate it into the tables for lower levels of the information model as well; hence this method might add InstanceNumber at the instance level. Once created, such attributes will automatically be included during database inserts. See also PatientStudySeriesConcatenationInstanceModel for example.

Parameters:
b - the statement being constructed
ie - the InformationEntity for which a create table statement is being constructed

extendCreateStatementStringWithDerivedAttributes

protected void extendCreateStatementStringWithDerivedAttributes(StringBuffer b,
                                                                InformationEntity ie)

Extend a SQL CREATE TABLE statement in the process of being constructed with any derived attributes (columns) that the model requires.

Called when creating the tables for a new database.

Specific to each concrete information model extending DatabaseInformationModel. Defaults to adding no extra columns if not overridden (i.e. it is not abstract).

For example, there may be dates and times derived from DICOM attributes.

Parameters:
b - the statement being constructed
ie - the InformationEntity for which a create table statement is being constructed

extendCreateStatementStringWithUserColumns

protected void extendCreateStatementStringWithUserColumns(StringBuffer b,
                                                          InformationEntity ie)

Extend a SQL CREATE TABLE statement in the process of being constructed with any user optional columns that the model requires.

Called when creating the tables for a new database.

Specific to each concrete information model extending DatabaseInformationModel. Defaults to adding four extra columns for each table if not overridden (i.e. it is not abstract).

Parameters:
b - the statement being constructed
ie - the InformationEntity for which a create table statement is being constructed

deleteSelectedRecord

public void deleteSelectedRecord(InformationEntity ie,
                                 String localPrimaryKeyValue)
                          throws DicomException
Deprecated. use deleteRecord(InformationEntity,String) instead

Throws:
DicomException

deleteRecord

public void deleteRecord(InformationEntity ie,
                         String localPrimaryKeyValue)
                  throws DicomException

Delete a database record (a particular instance of an information entity).

For example, for the study entity, this would delete a particular study.

Does NOT delete its children, if any.

Does NOT delete any referenced files, if any.

Parameters:
ie - the InformationEntity that corresponds to the table containing the record to be deleted
localPrimaryKeyValue - primary key of the record
Throws:
DicomException - thrown if there are problems executing the database statement

insertObject

public void insertObject(AttributeList list,
                         String fileName)
                  throws DicomException
Deprecated. use insertObject() instead

Insert a DICOM composite object, and the relevant attributes of all the entities it contains, into the database.

Such a composite object may contain information about the patient, study, series and instance and so on, and for each of these entities the appropriate records will be created in the appropriate tables

If records for any entities already exist (as they will often do when inserting multiple objects for the same patient or study, for example), they are matched based on the unique key for the appropriate level. They are not replaced and they are not updated, even if some of the attributes for that entity (other than the unique key) are different or additional. Even at the instance level (e.g. if an object with the same SOPInstanceUID is received), the first record will not be overwritten. Whether or not the application calling this method will have overwritten the corresponding file in the supplied argument or not is outside the scope of this class.

The information is taken from the supplied AttributeList, which is presumed to have already been read from a file or obtained through some other means. The supplied filename is only used to fill in the appropriate instance level attribute.

The file reference type is left empty since unknown.

Parameters:
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
fileName - the name of a file where the object is stored and from whence it may later be read
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

insertObject

public void insertObject(AttributeList list,
                         String fileName,
                         String fileReferenceType)
                  throws DicomException

Insert a DICOM composite object, and the relevant attributes of all the entities it contains, into the database.

Such a composite object may contain information about the patient, study, series and instance and so on, and for each of these entities the appropriate records will be created in the appropriate tables

If records for any entities already exist (as they will often do when inserting multiple objects for the same patient or study, for example), they are matched based on the unique key for the appropriate level. They are not replaced and they are not updated, even if some of the attributes for that entity (other than the unique key) are different or additional. Even at the instance level (e.g. if an object with the same SOPInstanceUID is received), the first record will not be overwritten. Whether or not the application calling this method will have overwritten the corresponding file in the supplied argument or not is outside the scope of this class.

The information is taken from the supplied AttributeList, which is presumed to have already been read from a file or obtained through some other means. The supplied filename is only used to fill in the appropriate instance level attribute.

Parameters:
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
fileName - the name of a file where the object is stored and from whence it may later be read
fileReferenceType - "C" for copied (i.e., delete on purge), "R" for referenced (i.e., do not delete on purge)
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithPersonNameSearchColumnsForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithPersonNameSearchColumnsForSelectedInformationEntity(StringBuffer b,
                                                                                                           AttributeList list,
                                                                                                           InformationEntity ie)
                                                                                                    throws DicomException

Extend a SQL INSERT statement in the process of being constructed with the names of the additional search columns derived from person name attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which a select statement is being constructed
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithPersonNameSearchValuesForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithPersonNameSearchValuesForSelectedInformationEntity(StringBuffer b,
                                                                                                          AttributeList list,
                                                                                                          InformationEntity ie)
                                                                                                   throws DicomException

Extend a SQL INSERT statement in the process of being constructed with the values of the additional search columns derived from person name attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which a select statement is being constructed
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendStatementStringWithMatchingAttributesForSelectedInformationEntity

protected abstract void extendStatementStringWithMatchingAttributesForSelectedInformationEntity(StringBuffer b,
                                                                                                AttributeList list,
                                                                                                InformationEntity ie)
                                                                                         throws DicomException

Extend a SQL SELECT statement in the process of being constructed with matching clauses for the unique keys of the entity and all its parents.

For example, a model might specify the unique key for the patient to be PatientID, the study to be StudyInstanceUID, the series to be SeriesInstanceUID and so on. A match requested at the series level would then require PatientID, StudyInstanceUID and SeriesInstanceUID to match what was in the supplied AttributeList

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which a select statement is being constructed
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithAttributeNamesForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithAttributeNamesForSelectedInformationEntity(StringBuffer b,
                                                                                                  AttributeList list,
                                                                                                  InformationEntity ie)
                                                                                           throws DicomException

Extend a SQL INSERT statement in the process of being constructed with the names of the attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which an insert statement is being constructed
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity(StringBuffer b,
                                                                                                   AttributeList list,
                                                                                                   InformationEntity ie,
                                                                                                   String fileName)
                                                                                            throws DicomException
Deprecated. use extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity() instead

Extend a SQL INSERT statement in the process of being constructed with the values of the attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

The file reference type is left empty since unknown.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which an insert statement is being constructed
fileName - the local filename, which may be non-null for INSTANCE level insertions
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithAttributeValuesForSelectedInformationEntity(StringBuffer b,
                                                                                                   AttributeList list,
                                                                                                   InformationEntity ie,
                                                                                                   String fileName,
                                                                                                   String fileReferenceType)
                                                                                            throws DicomException

Extend a SQL INSERT statement in the process of being constructed with the values of the attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which an insert statement is being constructed
fileName - the local filename, which may be non-null for INSTANCE level insertions
fileReferenceType - "C" for copied (i.e., delete on purge), "R" for referenced (i.e., do not delete on purge)
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithDerivedAttributeNamesForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithDerivedAttributeNamesForSelectedInformationEntity(StringBuffer b,
                                                                                                         AttributeList list,
                                                                                                         InformationEntity ie)
                                                                                                  throws DicomException

Extend a SQL INSERT statement in the process of being constructed with the names of the derived attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which an insert statement is being constructed
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

extendInsertStatementStringWithDerivedAttributeValuesForSelectedInformationEntity

protected abstract void extendInsertStatementStringWithDerivedAttributeValuesForSelectedInformationEntity(StringBuffer b,
                                                                                                          AttributeList list,
                                                                                                          InformationEntity ie)
                                                                                                   throws DicomException

Extend a SQL INSERT statement in the process of being constructed with the values of the derived attributes in the instance for the entity.

Called when inserting a new record for an instance of the entity.

Specific to each concrete information model extending DatabaseInformationModel.

Parameters:
b - the statement being constructed
list - the DICOM attributes of a composite object, containing the attributes describing this instance of the entity
ie - the InformationEntity for which an insert statement is being constructed
Throws:
DicomException - thrown if there are problems extracting the DICOM attributes

createPrimaryKeyForSelectedInformationEntity

protected abstract String createPrimaryKeyForSelectedInformationEntity(InformationEntity ie)

Create a new unique key which may be used to identify a new instance of an entity.

Called when inserting a new record for an instance of the entity.

Parameters:
ie - the InformationEntity for which a key is requested
Returns:
string value of a unique key

updateSelectedRecord

public void updateSelectedRecord(InformationEntity ie,
                                 String localPrimaryKeyValue,
                                 String key,
                                 String value)
                          throws DicomException

For a particular instance of an information entity, update the record in the database table with a new value for the specified attribute (column).

For example, for the study entity, this would update an attribute of a particular study, for example the StudyID attribute.

Parameters:
ie - the InformationEntity of the record to be updated
localPrimaryKeyValue - the string value of the unique key which identifies the instance of the entity (not including wildcards)
key - the string name of the attribute (column) to be set (updated)
value - the string value to set
Throws:
DicomException - thrown if the update fails

findAllAttributeValuesForSelectedRecord

public Map findAllAttributeValuesForSelectedRecord(InformationEntity ie,
                                                   String localPrimaryKeyValue)
                                            throws DicomException

For a particular instance of an information entity, get the values of all the columns in the entity's database table.

For example, for the study entity, this would return the attributes for a particular study.

Parameters:
ie - the InformationEntity of the record to be returned
localPrimaryKeyValue - the string value of the unique key which identifies the instance of the entity (not including wildcards)
Returns:
a TreeMap of String values indexed by String upper case column names
Throws:
DicomException - thrown if the query fails

findAllAttributeValuesForAllRecordsForThisInformationEntity

public ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntity(InformationEntity ie)
                                                                      throws DicomException

For all records of an information entity, get the values of all the columns in the entity's database table.

For example, for the study entity, this would return the attributes for all the studies in the database.

Parameters:
ie - the InformationEntity of the records to be returned
Returns:
an ArrayList of records, each value of which is a TreeMap of String values indexed by String upper case column names
Throws:
DicomException - thrown if the query fails

findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedUID

public ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedUID(InformationEntity ie,
                                                                                             String uid)
                                                                                      throws DicomException

For all records of an information entity matching the specified UID, get the values of all the columns in the entity's database table.

For example, for the study entity, this would return the attributes for all the studies with the specified UID in the database.

For the instance entity, this would return the attributes for all the instances with the specified UID in the database.

In an ideal world, this method should only ever return one record, since the DICOM model is predicated on UIDs being unique !

Parameters:
ie - the InformationEntity of the records to be returned
uid - the String UID of the records to be returned
Returns:
an ArrayList of records, each value of which is a TreeMap of String values indexed by String upper case column names
Throws:
DicomException - thrown if the query fails

findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedKeyValue

public ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedKeyValue(InformationEntity ie,
                                                                                                  String keyName,
                                                                                                  String keyValue)
                                                                                           throws DicomException

For all records of an information entity matching the specified key value, get the values of all the columns in the entity's database table.

For example, for the study entity, this would return the attributes for all the studies with the specified key value in the database.

Parameters:
ie - the InformationEntity of the records to be returned
keyName - the String name of the key to be matched
keyValue - the String value of the key to be matched
Returns:
an ArrayList of records, each value of which is a TreeMap of String values indexed by String upper case column names
Throws:
DicomException - thrown if the query fails

findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedParent

public ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithSpecifiedParent(InformationEntity ie,
                                                                                                String localParentReference)
                                                                                         throws DicomException

For all records of an information entity with the specified parent, get the values of all the columns in the entity's database table.

For example, for the series entity, this would return the attributes for all the series of a particular study (parent).

Parameters:
ie - the InformationEntity of the records to be returned
localParentReference - the string value of the unique key which identifies the instance of the parent entity (not including wildcards)
Returns:
an ArrayList of records, each value of which is a TreeMap of String values indexed by String upper case column names
Throws:
DicomException - thrown if the query fails

findAllAttributeValuesForAllRecordsForThisInformationEntityWithMatchingParent

public ArrayList findAllAttributeValuesForAllRecordsForThisInformationEntityWithMatchingParent(InformationEntity ieWanted,
                                                                                               InformationEntity ieParent,
                                                                                               String parentMatchingAttribute,
                                                                                               String parentMatchingValue)
                                                                                        throws DicomException

For all records of an information entity with all parents matching a particular attribute value, get the values of all attributes.

For example, for the instance entity, this could return the instance local file name for all the series (parents) with a particular frame of reference UID.

Parameters:
ieWanted - the InformationEntity of the record level of the attribute to be returned
ieParent - the InformationEntity of the record level of the parent to be matched
parentMatchingAttribute - the string name of the attribute of the parent whose value is to be matched
parentMatchingValue - the string value of the attribute of the parent to be matched (not including wildcards)
Returns:
an ArrayList of records, each value of which is a TreeMap of String values indexed by String upper case column names
Throws:
DicomException - thrown if the query fails

getTableNameForInformationEntity

public static String getTableNameForInformationEntity(InformationEntity ie)

Get the table name for an information entity.

Parameters:
ie - the InformationEntity that is the parent, such as a patient, study, etc.
Returns:
the upper case name of the table as used in the database

getChildTypeForParent

public abstract InformationEntity getChildTypeForParent(InformationEntity ie)

For an information entity (regardless of a particular instance), find the next information entity lower down in the information model hierarchy in the general case.

For a patient, this might be a study.

For a series, this might be a concatenation or an instance, depending on the information model.

This method essentially returns the most complex model possible and is used when building the database table schema.

Parameters:
ie - the InformationEntity that is the parent, such as a patient, study, etc.
Returns:
the InformationEntity that is the child

getChildTypeForParent

public abstract InformationEntity getChildTypeForParent(InformationEntity ie,
                                                        boolean concatenation)

For a particular instance of an information entity, find the next information entity lower down in the information model hierarchy.

For a patient, this might be a study. For a series, this might be a concatenation or an instance, depending on both the information model and whether concatenations are to be considered in the model.

This method may return a simpler view than the more general method, and is used when traversing the database tables.

Parameters:
ie - the InformationEntity that is the parent, such as a patient, study, etc.
concatenation - true if concatenations are to be considered in the model
Returns:
the InformationEntity that is the child

getChildTypeForParent

public abstract InformationEntity getChildTypeForParent(InformationEntity ie,
                                                        AttributeList list)

For a particular instance of an information entity, find the next information entity lower down in the information model hierarchy.

For a patient, this might be a study. For a series, this might be a concatenation or an instance, depending on both the information model and the contents of the instance itself.

This method may return a simpler view than the more general method, and is used when traversing the database tables.

Parameters:
ie - the InformationEntity that is the parent, such as a patient, study, etc.
list - the AttributeList that are the contents the instance
Returns:
the InformationEntity that is the child

getNametoDescribeThisInstanceOfInformationEntity

public abstract String getNametoDescribeThisInstanceOfInformationEntity(InformationEntity ie,
                                                                        Map returnedAttributes)

For a particular instance of an information entity, find a descriptive name for the entity suitable for rendering.

For a patient, this might be the name Patient. For an instance, this will depend on the SOPClassUID, and might be an Image, a Waveform, etc.

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
returnedAttributes - the attributes from the selected row of the table for this instance of the entity
Returns:
a human-readable string name of the entity

getDescriptiveColumnName

public abstract String getDescriptiveColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the first of three descriptive attributes for the entity.

For example, for an instance (e.g. an image), this might be the InstanceNumber. For a patient, this might be the PatientName.

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
Returns:
the upper case string name of the column, or null if there is no such column

getOtherDescriptiveColumnName

public abstract String getOtherDescriptiveColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the second of three descriptive attributes for the entity.

For example, for an instance (e.g. an image), this might be the InConcatenationNumber. Frequently null for other entities.

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
Returns:
the upper case string name of the column, or null if there is no such column

getOtherOtherDescriptiveColumnName

public abstract String getOtherOtherDescriptiveColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the third of three descriptive attributes for the entity.

For example, for an instance (e.g. an image), this might be the ImageComments. For a patient, this might be the PatientID.

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
Returns:
the upper case string name of the column, or null if there is no such column

getUIDColumnNameForInformationEntity

public abstract String getUIDColumnNameForInformationEntity(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the DICOM UID for the entity.

For example, for an instance (e.g. an image), this might be the name of the column corresponding to the SOP Instance UID.

Parameters:
ie - the InformationEntity, such as a study, series, instance, etc.
Returns:
the upper case string name of the column, or null if there is no such column

getLocalPrimaryKeyColumnName

public String getLocalPrimaryKeyColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the primary key of an instance of the entity.

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
Returns:
the upper case string name of the column

getLocalFileNameColumnName

public String getLocalFileNameColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the local file name of a stored object.

Parameters:
ie - the InformationEntity, such as a instance (e.g. an image)
Returns:
the upper case string name of the column

localFileNameColumnName

public String localFileNameColumnName(InformationEntity ie)
Deprecated. use getLocalFileNameColumnName() instead

For a particular information entity, find the name of the column in the entity's database table containing the local file name of a stored object.

Parameters:
ie - the InformationEntity, such as a instance (e.g. an image)
Returns:
the upper case string name of the column

getLocalFileReferenceTypeColumnName

public String getLocalFileReferenceTypeColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the reference type of a stored object.

Parameters:
ie - the InformationEntity, such as a instance (e.g. an image)
Returns:
the upper case string name of the column

getLocalParentReferenceColumnName

public String getLocalParentReferenceColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the reference to an instance of the entity's parent.

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
Returns:
the upper case string name of the column

getLocalRecordInsertionTimeColumnName

public String getLocalRecordInsertionTimeColumnName(InformationEntity ie)

For a particular information entity, find the name of the column in the entity's database table containing the record insertion time recorded as the value returned by System.currentTimeMillis().

Parameters:
ie - the InformationEntity, such as a patient, study, etc.
Returns:
the upper case string name of the column

getSQLTypeFromDicomValueRepresentation

public static String getSQLTypeFromDicomValueRepresentation(byte[] vr)

Given a DICOM Value Representation, determine the appropriate corresponding SQL type to use.

For example, the DICOM AE VR should be represented as a CHAR(16), an SS as an INTEGER, and so on.

Parameters:
vr - the 2 letter DICOM Value Representation as an array of two ASCII bytes.
Returns:
the string representing the SQL type.

appendExactOrIsNullMatch

protected static void appendExactOrIsNullMatch(StringBuffer b,
                                               String value)

Append a check for a match against a string value, accounting for the need to use the "IS NULL" rather than "=" expression when wanting to explciitly have NULL match NULL rather to never match.

Parameters:
b - the buffer to append to
value - either NULL or the quoted escaped string value to append

getQueryResponseGeneratorFactory

public QueryResponseGeneratorFactory getQueryResponseGeneratorFactory(int debugLevel)

Get a factory to manufacture a query response generator capable of performing a query and returning the results.

Parameters:
debugLevel - zero for no debugging messages, higher values more verbose messages
Returns:
the response generator factory

getRetrieveResponseGeneratorFactory

public RetrieveResponseGeneratorFactory getRetrieveResponseGeneratorFactory(int debugLevel)

Get a factory to manufacture a retrieve response generator capable of performing a retrieve and returning the results.

Parameters:
debugLevel - zero for no debugging messages, higher values more verbose messages
Returns:
the response generator factory

getInformationEntityFromTag

public InformationEntity getInformationEntityFromTag(AttributeTag tag)
Get the information entity in this information model for the specified tag

Parameters:
tag -

toString

public String toString()

Returns a string describing the structure (not the contents) of the database.

Overrides:
toString in class Object
Returns:
a list of all the attributes for each information entities followed by a description of each table obtained from the database metadata, if a connection can be established, or the string value of the exception if it cannot.