<?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="all">

    <class entity-name="TiuImage" table="VISTA_HDSI.TIU_EXT_DATA_LINK_8925_91_EXT" lazy="false" name="gov.va.med.cds.template.generated.tiu.ClincalDocumentEvent$Images"> 
         <id name="idV" type="big_decimal">
            <column name="ROWID" />
            <generator class="assigned" />
        </id>
        
        <property name="tiuDocumentNumber" column="DOCUMENT" type="big_decimal" insert="false" update="false" />

		<component name="singleImage" class="gov.va.med.cds.template.generated.tiu.Image">
	        <component name="imageLinkCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="IMAGE" type="java.lang.String" insert="false" update="false"/>
				<property name="codingSystem" column="ImageLinkCodeCS" type="java.lang.String" insert="false" update="false"/>
			</component>
		</component>

	</class>
	
	<!-- Association images Queries -->
    <query name="TiuDocumentListRead2.ClinicalDocumentEvent.images.date.documentClass">
        <![CDATA[
         select img
         from TiuImage img, TiuDocumentListRead2 cd
         where cd.idV = img.tiuDocumentNumber
         	and cd.patient.identifier.identity in ( :pids )
         	and cd.referenceDate.timestamp between :startDate and :endDate
         	and VISTA_HDSI.HDSREPTIUUtil1_IsDocOfClass(cd.idV, :documentClass)=1 
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
    </query>

    <query name="TiuDocumentListRead2.ClinicalDocumentEvent.images.documentClass">
        <![CDATA[
         select img
         from TiuImage img, TiuDocumentListRead2 cd
         where cd.idV = img.tiuDocumentNumber
         	and cd.patient.identifier.identity in ( :pids )
         	and VISTA_HDSI.HDSREPTIUUtil1_IsDocOfClass(cd.idV, :documentClass)=1 
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
    </query>

    <query name="TiuDocumentListRead2.ClinicalDocumentEvent.images.date.documentType">
        <![CDATA[
         select img
         from TiuImage img, TiuDocumentListRead2 cd
         where cd.idV = img.tiuDocumentNumber
	        and cd.patient.identifier.identity in ( :pids )
         	and cd.referenceDate.timestamp between :startDate and :endDate
         	and cd.standardizedDocumentType.code in ( :documentType )
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
    </query>

    <query name="TiuDocumentListRead2.ClinicalDocumentEvent.images.documentType">
        <![CDATA[
         select img
         from TiuImage img, TiuDocumentListRead2 cd
         where cd.idV = img.tiuDocumentNumber
	        and cd.patient.identifier.identity in ( :pids )
         	and cd.standardizedDocumentType.code in ( :documentType )
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
    </query>
</hibernate-mapping>
