<?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="TiuDocumentUpdateEvent" table="VISTA_HDSI.TIU_AUDIT_TRAIL_8925_5_EXT" lazy="false" name="gov.va.med.cds.template.generated.tiu.ClincalDocumentEvent$DocumentUpdateEvents">
        <id name="idV" type="big_decimal">
			<column name="ROWID" />
			<generator class="assigned" />
		</id>
		
		<property name="tiuDocumentName" column="TIU_DOCUMENT_NAME" type="big_decimal" insert="false" update="false"/>

		<component name="singleDocumentUpdateEvent" class="gov.va.med.cds.template.generated.tiu.DocumentUpdateEvent">	
			<component name="interdisciplinaryNoteMarker" class="gov.va.med.cds.template.generated.common.PractitionerLite">				
				<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier" >
					<property name="identity" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType">
						<formula>
						(CASE
				    		WHEN (PERSON IS NOT NULL) THEN PERSON
				    		ELSE NULL
				 		END)
						</formula>
					</property>
					<property name="assigningFacility" type="java.lang.String" >
						<formula>
						(CASE
				    		WHEN (PERSON IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()
				    		ELSE NULL
				 		END)
						</formula>
					</property>
					<property name="assigningAuthority" type="java.lang.String" >
						<formula>
						(CASE
				    		WHEN (PERSON IS NOT NULL) THEN 'USVHA'
				    		ELSE NULL
				 		END)
						</formula>
					</property>
				</component>
				<property name="name" column="InterdisciplinaryNoteMarkerNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
			</component>		
			
			<property name="interdisciplinaryNoteParent" column="ID_PARENT" type="java.lang.String"/>			
	        
	        <component name="interdisciplinaryNoteActionCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="IDISCNOTEACTIONVUID" type="java.lang.String"/>
				<property name="displayText" column="INTERDISCIPLINARY_NOTE_ACTION" type="java.lang.String"/>
				<property name="codingSystem" column="IDiscNoteActionVuid" type="java.lang.String"/>
			</component>
			
			<property name="interdisciplinaryNoteActionDate" formula="STRING(DATETIME_OF_ACTION,'^',VISTA_HDSI.HDSREPSQLUtil1_StationNumber())" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" update="false" insert="false"/>
	
			<component name="interdisciplinaryNoteEntryStatus" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
				<property name="code" column="ID_ENTRY_STATUS" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType"/>
				<property name="displayText" column="IDENTRYSTATUSX" type="java.lang.String"/>			
			</component>
		</component>	
	</class>
  
    
    <!-- Association documentUpdateEvents Queries -->
    <query name="TiuDocumentListRead2.ClinicalDocumentEvent.documentUpdateEvents.date.documentClass">
        <![CDATA[
         select due
         from TiuDocumentUpdateEvent due, TiuDocumentListRead2 as cd
         where cd.idV = due.tiuDocumentName
            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.documentUpdateEvents.documentClass">
        <![CDATA[
         select due
         from TiuDocumentUpdateEvent due, TiuDocumentListRead2 as cd
         where cd.idV = due.tiuDocumentName
            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.documentUpdateEvents.date.documentType">
        <![CDATA[
         select due
         from TiuDocumentUpdateEvent due, TiuDocumentListRead2 as cd
         where cd.idV = due.tiuDocumentName
            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.documentUpdateEvents.documentType">
        <![CDATA[
         select due
         from TiuDocumentUpdateEvent due, TiuDocumentListRead2 as cd
         where cd.idV = due.tiuDocumentName
            and cd.patient.identifier.identity in ( :pids )
         	and cd.standardizedDocumentType.code in ( :documentType )
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
    </query>
</hibernate-mapping>
