<?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="TiuDocumentListRead2" table="VISTA_HDSI.TIU_DOCUMENT_8925_EXT" lazy="false" name="gov.va.med.cds.template.generated.tiu.ClincalDocumentEvent">
        <id name="idV" type="big_decimal">
			<column name="ROWID" />
			<generator class="assigned" />
		</id>
	
		<component name="recordIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
			<property name="identity" column="ROWID" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType" insert="false" update="false" />
			<property name="namespaceId" formula="NAMESPACEID||'_8925'" type="java.lang.String"/>
			<property name="universalId" formula="''" type="java.lang.String"/>
			<property name="universalIdType" formula="''" type="java.lang.String"/>
		</component>
        
        <component name="patient" class="gov.va.med.cds.template.generated.common.PatientLite">
            <component name="identifier"  class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier">
                <property name="identity" column="Patient" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false"/>
                <property name="assigningFacility" column="NAMESPACEID" type="java.lang.String" insert="false" update="false" /> 
                <property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" insert="false" update="false"/>
    	    </component>
    	    <property name="name" column="PatientNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
        </component>

        <property  name="referenceDate" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false">
            <column name="REFERENCE_DATE"/>
            <column name="NAMESPACEID" />
        </property>

		<component name="parentIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
            <property name="identity" column="PARENT" type="java.lang.String"/>
            <property name="namespaceId" formula="NAMESPACEID||'_8925'" type="java.lang.String"/>
		</component>
   
		<component name="standardizedDocumentTitle" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
            <property name="code" column="StandardTitleVuid" type="java.lang.String"/>
            <property name="displayText" column="StandardTitleText" type="java.lang.String"/>
            <property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (StandardTitleVuid IS NOT NULL OR StandardTitleText IS NOT NULL) THEN StandardTitleCS
				    ELSE NULL
				 END)
        		</formula>
        	</property>            
        </component>

		<property name="localDocumentTitle" type="java.lang.String" column="LocalDocumentTitle" />

		<property name="documentSubject" column="SUBJECT_OPTIONAL_description" type="java.lang.String" />
    
		<component name="statusCode" class="gov.va.med.cds.template.generated.basedatatypes.DocumentStatusHL72CodedElementLite">
            <property name="code" column="STATUSVUID" type="java.lang.String"/>
            <property name="displayText" column="STATUSX" type="java.lang.String"/>
        </component>

        <component name="authorDictator" class="gov.va.med.cds.template.generated.common.PractitionerLite">
			<property name="identifier" formula="AuthorDictatorNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
			<property name="name" column="AuthorDictatorNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
		</component>

		<component name="chartMarkedSigned" class="gov.va.med.cds.template.generated.common.PractitionerLite">
			<property name="identifier" formula="ChartMarkedSignedNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
			<property name="name" column="ChartMarkedSignedNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
		</component>
		
		<component name="chartMarkedCosigned" class="gov.va.med.cds.template.generated.common.PractitionerLite">
			<property name="identifier" formula="ChartMarkedCosignedNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
			<property name="name" column="ChartMarkedCosignedNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
		</component>
		
		<component name="expectedSigner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
			<property name="identifier" formula="ExpectedSignerNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
			<property name="name" column="ExpectedSignerNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
		</component>

        <component name="signer" class="gov.va.med.cds.template.generated.common.ManagedPractitionerParticipationLite">
        	<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
        		<property name="identifier" formula="SignerNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
				<property name="name" column="SignerNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        	</component>
           <property name="signatureBlockName" column="SignatureBlockValue" type="java.lang.String" />
            <property name="signatureBlockTitle" column="SignatureTitleValue" type="java.lang.String" />
            <component name="signatureMode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
                 <property name="displayText" type="java.lang.String" column="SignatureModeText" />
            </component>
        </component>
        
        <property name="printName" column="PrintName" type="java.lang.String" />
        
        <component name="standardizedDocumentType" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
        	<property name="code" column="StdDocTypeVuid" type="java.lang.String"/>
        	<property name="displayText" column="StdDocTypeText" type="java.lang.String"/>
        	<property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (STDDOCTYPEVUID IS NOT NULL OR STDDOCTYPETEXT IS NOT NULL) THEN '99VA8926_6'
				    ELSE NULL
				 END)
        		</formula>
        	</property>
        </component>
        
        <component name="expectedCosigner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
            <property name="identifier" formula="ExpectedCosignerNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
			<property name="name" column="ExpectedCosignerNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        </component>
        
       <component name="cosigner" class="gov.va.med.cds.template.generated.common.ManagedPractitionerParticipationLite">
      		<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
        		<property name="identifier" formula="CosignerNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
				<property name="name" column="CosignerNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        	</component>
            <property name="participationDate" formula="STRING(COSIGNATURE_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
            <property name="signatureBlockName" column="COSIGNATUREBLOCKVALUE" type="java.lang.String"  />
            <property name="signatureBlockTitle" column="COSIGNATURETITLEVALUE" type="java.lang.String"  />
            <component name="signatureMode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
                 <property name="displayText" type="java.lang.String" column="COSIGNATUREMODETEXT" />
            </component>
        </component>
       
        <component name="amender" class="gov.va.med.cds.template.generated.common.ManagedPractitionerParticipationLite">
        	<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
	        	<property name="identifier" formula="AmenderNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
				<property name="name" column="AmenderNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        	</component>
            <property name="participationDate" formula="STRING(AMENDMENT_SIGNED,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false"/>
            <property name="signatureBlockName" column="AmendSignatureBlockValue" type="java.lang.String"/>
            <property name="signatureBlockTitle" column="AmendSignatureTitleValue" type="java.lang.String"/>
        </component>
        
        <property name="amendmentDate" formula="STRING(AMENDMENT_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
       
        <property name="dictationDate" formula="STRING(DICTATION_DATE,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
       
        <property name="patientMovementDate" formula="STRING(PATIENTMOVEMENT_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
        
        <property name="archiveDate" formula="STRING(ARCHIVEPURGE_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
        
        <property name="procedureDate" formula="STRING(DATETIME_PERFORMED,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />

        <property name="enteredDate" formula="STRING(ENTRY_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />

		<component name="procedureSummaryCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
			<property name="code" column="PROCEDURESUMMARYCODEVUID" type="java.lang.String"/>
			<property name="displayText" column="PROCEDURE_SUMMARY_CODE" type="java.lang.String"/>
			<property name="codingSystem" type="java.lang.String" >
        		<formula>
        		(CASE
				    WHEN (PROCEDURESUMMARYCODEVUID IS NOT NULL OR PROCEDURE_SUMMARY_CODE IS NOT NULL) THEN '99VA8985.1'
				    ELSE NULL
				 END)
        		</formula>
        	</property>            
		</component>
		
		<component name="treatingSpecialtyCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
			<property name="code" column="TREATINGSPECIALTYVUID" type="java.lang.String"/>
			<property name="displayText" column="TREATINGSPECIALTYNAME" type="java.lang.String"/>
			<property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (TREATINGSPECIALTYVUID IS NOT NULL OR TREATINGSPECIALTYNAME IS NOT NULL) THEN TREATINGSPECIALTYCS
				    ELSE NULL
				 END)
        		</formula>
        	</property>
        </component>
		
		<component name="serviceCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
			<property name="code" column="SERVICEVUID" type="java.lang.String"/>
			<property name="displayText" column="SERVICENAME" type="java.lang.String"/>
			<property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (SERVICEVUID IS NOT NULL OR SERVICENAME IS NOT NULL) THEN SERVICECS
				    ELSE NULL
				 END)
        		</formula>
        	</property>
		</component>
		
		<component name="cosignatureNeeded" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
			<property name="code" column="COSIGNATURENEEDEDVUID" type="java.lang.String"/>
			<property name="displayText" type="java.lang.String">
	        	<formula>
	        		(CASE
					   	WHEN (COSIGNATURE_NEEDED = 1) THEN 'YES'
					   	WHEN (COSIGNATURE_NEEDED = 0) THEN 'NO'
					    ELSE NULL
					 END)
	        	</formula>
			</property>
			<property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (COSIGNATURENEEDEDVUID IS NOT NULL OR COSIGNATURE_NEEDED IS NOT NULL) THEN '99VA8985.1'
				    ELSE NULL
				 END)
        		</formula>
        	</property>
		</component>

        <component name="treatmentEpisode" class="gov.va.med.cds.template.generated.tiu.TreatmentEpisode">
            <property name="treatmentBeginDate" formula="STRING(EPISODE_BEGIN_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
            <property name="treatmentEndDate" formula="STRING(EPISODE_END_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
        </component>
        
        <component name="tiuPatientVisit" class="gov.va.med.cds.template.generated.tiu.TiuPatientVisit">
            <component name="assignedLocation" class="gov.va.med.cds.template.generated.basedatatypes.HL72LocationIdentifier" >
                <property name="pointOfCare" column="CLINICNAME" type="java.lang.String" />
                <property name="facilityNamespaceId" column="DIVISION" type="java.lang.String" />
                <property name="facilityUniversalId" column="DIVISIONX" type="java.lang.String" />
            </component>
            <property name="visitAdmitDate" formula="STRING(VISIT_DATETIME,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false"/>
            <property name="servicingFacility" column="ServiceName" insert="false" update="false" type="java.lang.String"/>
			<component name="serviceLocation" class="gov.va.med.cds.template.generated.basedatatypes.HL72LocationIdentifier" >
            	<property name="pointOfCare" column="ServiceName" insert="false" update="false" type="java.lang.String"/>
            </component>
        </component>
       
        <component name="urgency" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite" >
        	<property name="code" column="URGENCYVUID" type="java.lang.String" />
        	<property name="displayText" column="URGENCY" type="java.lang.String" />
        	<property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (URGENCYVUID IS NOT NULL OR URGENCY IS NOT NULL) THEN '99VA8985.1'
				    ELSE NULL
				 END)
        		</formula>
        	</property>
        </component>
    
        <component name="attendingPhysician" class="gov.va.med.cds.template.generated.common.PractitionerLite">
            <property name="identifier" formula="AttendingPhysicianNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
			<property name="name" column="AttendingPhysicianNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        </component>
        
        <!-- 
        <component name="recordSource" node="recordSource" >
        	<property name="namespaceId" formula="NAMESPACEID||'_8925'" type="java.lang.String" node="namespaceId" />
        	<property name="universalId" column="DOMAINNAMEX" type="java.lang.String" node="universalId" />
        	<property name="universalIdType" formula="'DNS'" type="java.lang.String" node="universalIdType" />
        </component>
         -->
	</class>
	
	 <!--  TODO: These queries are  not valid and need to be reworked to work with the two template/filter definitions that we have. -->
	 <!--  
	 		Named Query Naming Convention
	 		[DomainEntryPointName].[Association Name].[identifiers]|.[date].[Filter Parameters]
	 
	  -->

    <!-- Patient Queries -->
	<query name="TiuDocumentListRead2.ClinicalDocumentEvent.clinicalDocumentEvents.date.documentClass">
		<![CDATA[
		from TiuDocumentListRead2 cd
        where cd.patient.identifier.identity in ( :pids )
         	and ( (cd.referenceDate.timestamp between :startDate and :endDate) or (cd.referenceDate.timestamp is null) )
         	and VISTA_HDSI.HDSREPTIUUtil1_IsDocOfClass(cd.idV, :documentClass)=1 
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
	</query>
	
	<query name="TiuDocumentListRead2.ClinicalDocumentEvent.clinicalDocumentEvents.documentClass">
		<![CDATA[
		from TiuDocumentListRead2 cd
        where 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.clinicalDocumentEvents.date.documentType">
		<![CDATA[
		from TiuDocumentListRead2 cd
        where cd.patient.identifier.identity in ( :pids )
         	and ( (cd.referenceDate.timestamp between :startDate and :endDate) or (cd.referenceDate.timestamp is null) )
         	and cd.standardizedDocumentType.code in ( :documentType )
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
	</query>
	
	<query name="TiuDocumentListRead2.ClinicalDocumentEvent.clinicalDocumentEvents.documentType">
		<![CDATA[
		from TiuDocumentListRead2 cd
        where cd.patient.identifier.identity in ( :pids )
         	and cd.standardizedDocumentType.code in ( :documentType )
         	and cd.statusCode.code in ('4501286','4501290','4501014')
      ]]>
	</query>
	
	<query name="TiuDocumentListRead2.ClinicalDocumentEvent.clinicalDocumentEvents.identifiers">
		<![CDATA[
		from TiuDocumentListRead2 cd
        where cd.patient.identifier.identity in ( :pids )
        	and cd.idV in ( :recordIdentifiers )
      ]]>
	</query>
 
    <query name="TiuDocumentListRead2.ClinicalDocumentEvent.clinicalDocumentEvents">
        <![CDATA[
        from TiuDocumentListRead2 cd
        where cd.patient.identifier.identity in ( :pids )
      ]]>
    </query>

</hibernate-mapping>
