<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false" default-cascade="save-update">
    <class name="gov.va.med.cds.clinicaldata.FilterMetaData" table="FILTER_SCHEMA" lazy="false">
        <id type="java.lang.Long" >
            <column name="FILTER_SCHEMA_ID" />
 			<generator class="sequence">
				<param name="sequence">filter_schema_seq_id</param>
			</generator>
        </id>


		<property name="filterId" column="FILTER_IDENTIFIER" type="java.lang.String" />
		<property name="filterDescription" column="FILTER_DESCRIPTION" type="java.lang.String" />

		<property name="dateAdded" column="DATE_ADDED" type="java.util.Date" />
		<property name="dateActivated" column="DATE_ACTIVATED" type="java.util.Date" />
		<property name="dateDeactivated" column="DATE_DEACTIVATED" type="java.util.Date" />
		<property name="dateDeprecated" column="DATE_DEPRECATED" type="java.util.Date" />
		<property name="dateUpdated" column="DATE_UPDATED" type="java.util.Date" />
		
		<property name="status" column="STATUS" type="java.lang.String" />

		<property name="containsCorrelation" column="CONTAINS_CORRELATION" type="yes_no" />
			
		<property name="filterSchemaXml" column="FILTER_SCHEMA_TXT" type="string" />

 
	    <set name="entryFilters" table="FILTER_SCHEMA_ENTRY_FILTER">
	        <key column="FILTER_SCHEMA_ID"/>
	        <many-to-many column="ENTRY_FILTER_ID" 
	            class="gov.va.med.cds.clinicaldata.EntryFilter"/>
	    </set>

	    <set name="vhimVersionWrappers" table="FILTER_SCHEMA_VHIM_VERSION">
	        <key column="FILTER_SCHEMA_ID" not-null="true" />
	        <many-to-many column="VHIM_VERSION_ID" unique="true"
	            class="gov.va.med.cds.clinicaldata.VhimVersionWrapper"/>
	    </set>

    </class>



    <query name="FilterSchemaId">
		<![CDATA[
		from FilterMetaData fmd
		where fmd.filterId = :filterId
      ]]>
	</query>

	
	<sql-query name="FilterSchemaIdsByStatus">
		SELECT fs.filter_identifier
  		FROM filter_schema fs, vhim_version vv, filter_schema_vhim_Version fsvv
 		WHERE FS.FILTER_SCHEMA_ID = FSVV.FILTER_SCHEMA_ID
        AND FS.STATUS = :status
	</sql-query>
	
	
    <query name="AllFilterSchemaIds">
		<![CDATA[
		select filterId from FilterMetaData
      ]]>
	</query>

</hibernate-mapping>
