<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
	version="1.0">
	<description>CCHT</description>
	<persistence-unit-metadata>
		<xml-mapping-metadata-complete />
	</persistence-unit-metadata>

	<named-native-query name="purgeCompletedReports" result-set-mapping="deletedReportCount">
		<query><![CDATA[delete from ht.completed_reports where report_expiration_date < getdate()]]></query>
	</named-native-query>
	
	
	<sql-result-set-mapping name="deletedReportCount">
		<column-result name="total_number" />
	</sql-result-set-mapping>
	
	<mapped-superclass
		class="gov.va.med.ccht.model.report.AbstractCompletedReport"
		access="FIELD">
		<attributes>
			<basic name="inactivatedDate">
				<column name="REPORT_INACTIVATED_DATE" />
			</basic>
			<basic name="completedDate">
				<column name="REPORT_COMPLETED_DATE" />
			</basic >
			<basic name="reportName">
				<column name="REPORT_NAME" />
			</basic>
			<basic name="fromDate">
				<column name="REPORT_PARM_FROM_DATE" />
			</basic>
			<basic name="toDate">
				<column name="REPORT_PARM_TO_DATE" />
			</basic>
			<basic name="asOfDate">
				<column name="REPORT_PARM_ASOF_DATE" />
			</basic>						
			<basic name="reportParameterText">
				<column name="REPORT_PARAMETER_TXT" />
			</basic>
			<basic name="userName">
				<column name="REPORT_GENERATED_BY" />
			</basic>
			<basic name="expirationDate">
				<column name="REPORT_EXPIRATION_DATE" />
			</basic>
			<many-to-one name="standardReport" target-entity="gov.va.med.ccht.model.terminology.StandardReport">
				<join-column name="STANDARD_HT_REPORT_ID" />
			</many-to-one>
			<many-to-one name="fileType" target-entity="gov.va.med.fw.report.ReportExportedType">
				<join-column name="RPT_OP_FTYPE_ID" />
			</many-to-one>								
		</attributes>
	</mapped-superclass>
	
	<mapped-superclass
		class="gov.va.med.ccht.model.report.AbstractScheduledReport"
		access="FIELD">
		<attributes>
			<basic name="reportParameterText">
				<column name="RPT_PARAMETER_TXT" />
			</basic>
			<basic name="reportScheduleText">
				<column name="RPT_SCHEDULED_TXT" />
			</basic>
			<basic name="reportGenerateDate">
				<column name="RPT_GENERATE_DATE" />
			</basic>			
			<basic name="userName">
				<column name="RPT_SCHEDULED_BY" />
			</basic>
			<basic name="email">
				<column name="RPT_RECIPIENT_EMAIL" />
			</basic>			
			<many-to-one name="standardReport" target-entity="gov.va.med.ccht.model.terminology.StandardReport">
				<join-column name="STANDARD_HT_REPORT_ID" />
			</many-to-one>
			<many-to-one name="fileType" target-entity="gov.va.med.fw.report.ReportExportedType">
				<join-column name="RPT_OP_FTYPE_ID" />
			</many-to-one>								
		</attributes>
	</mapped-superclass>
		
	<entity class="gov.va.med.ccht.model.report.SimpleCompletedReport" access="FIELD"
		name="SimpleCompletedReport">
		<table schema="HT" name="COMPLETED_REPORTS" />
		<named-query name="getCompletedReports">
			<query>
	    		<![CDATA[
	    			select l from gov.va.med.ccht.model.report.SimpleCompletedReport l
	    			order by l.completedDate desc
	    		]]>
	    	</query>
		</named-query>

		<named-query name="getCompletedReportsByUser">
			<query>
	    		<![CDATA[
	    			select l from gov.va.med.ccht.model.report.SimpleCompletedReport l
	    			where  l.userName = :user order by l.completedDate desc
	    		]]>
	    	</query>
		</named-query>
		<named-query name="getCompletedReportsByIds">
			<query>
	    		<![CDATA[
	    			select l from gov.va.med.ccht.model.report.SimpleCompletedReport l
	    			where l.id in (:reportIds) order by l.completedDate desc
	    		]]>
	    	</query>
		</named-query>
		
		<attribute-override name="id">
			<column name="COMPLETED_REPORT_ID" />
		</attribute-override>
		<attributes/>					
	</entity>

	<entity class="gov.va.med.ccht.model.report.CompletedReport" access="FIELD"
		name="CompletedReport">
		<table schema="HT" name="COMPLETED_REPORTS" />		
		<attribute-override name="id">
			<column name="COMPLETED_REPORT_ID"/>
		</attribute-override>
		<attributes>
			<basic name="reportFileContent">
				<column name="REPORT_OUTPUT_DATA" />
			</basic>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.report.ScheduledReport" access="FIELD"
		name="ScheduledReport">
		<table schema="HT" name="RPT_SCHEDULED_REPORTS" />
		<named-query name="getScheduledReports">
			<query>
	    		<![CDATA[
	    			select l from gov.va.med.ccht.model.report.ScheduledReport l
	    			order by l.id
	    		]]>
	    	</query>
		</named-query>
		<named-query name="getScheduledReportsByUser">
			<query>
	    		<![CDATA[
	    			select l from gov.va.med.ccht.model.report.ScheduledReport l
	    			where  l.userName = :user order by l.id
	    		]]>
	    	</query>
		</named-query>				
		<attribute-override name="id">
			<column name="RPT_SCHEDULED_REPORT_ID"/>
		</attribute-override>		
		<attributes>
			<transient name="reportSchedule"/>
			<transient name="reportParameters"/>
		</attributes>
		
	</entity>
</entity-mappings>
 

