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

<class entity-name="RequestsAndExamsRead1ER" table="VISTA_HDSI.F2507_REQUEST" node="examRequest">

	<id name="id" type="java.lang.String">
		<column name="ROWID" />
		<generator class="assigned" />
	</id>

  <component name="patient" node="patient">
    <component name="identifier" node="identifier">
      <property name="identity" column="NAME" type="big_decimal" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>	
  </component>	
	
	<property name="requestDate" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false" node="requestDate//literal">
    <column name="REQUEST_DATE"/>
    <formula>VISTA_HDSI.HDSREPSQLUtil1_StationNumber()</formula>
  </property>

  <component name="regionalOfficeNumber" node="regionalOfficeNumber">
    <component name="identifier" node="identifier">
      <property name="identity" column="REGIONAL_OFFICE_NUMBER" type="java.lang.String" node="identity" />
      <property name="name" column="REGIONALOFFICENUMBERX" type="java.lang.String" node="name" />
    </component>	
    <property name="officialVAName" formula="VISTA_HDSI.HDSREPSQLUtil1_OfficialVaName()" type="java.lang.String" node="officialVAName" />
  </component>
  
  <component name="requestor" node="requestor">
    <component name="identifier" node="identifier">
      <property name="identity" column="REQUESTER" type="java.lang.String" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>	
    <component name="name" node="name">
      <property name="displayName" column="REQUESTERX" type="java.lang.String" node="displayName" />
    </component>	
  </component>
  
	<property name="dateReportedToMas" formula="STRING(DATE_REPORTED_TO_MAS,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateReportedToMas//literal" />

	<property name="dateSchedulingCompleted" formula="STRING(DATE_SCHEDULING_COMPLETED,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateSchedulingCompleted//literal" />

	<property name="dateCompleted" formula="STRING(DATE_COMPLETED,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateCompleted//literal" />
 
  <component name="priorityOfExam" node="priorityOfExam">
	 <property name="code" column="PRIORITY_OF_EXAM" type="java.lang.String" node="code" />
	 <property name="displayText" type="java.lang.String" node="displayText">
	   <formula>
          (CASE
          WHEN ( PRIORITY_OF_EXAM = 'T' ) THEN 'TERMINAL'
          WHEN ( PRIORITY_OF_EXAM = 'P' ) THEN 'POW'
          WHEN ( PRIORITY_OF_EXAM = 'OS' ) THEN 'ORIGINAL SC'
          WHEN ( PRIORITY_OF_EXAM = 'ON' ) THEN 'ORIGINAL NSC'
          WHEN ( PRIORITY_OF_EXAM = 'I' ) THEN 'INCREASE'
          WHEN ( PRIORITY_OF_EXAM = 'R' ) THEN 'REVIEW'
          WHEN ( PRIORITY_OF_EXAM = 'OTR' ) THEN 'OTHER'
          WHEN ( PRIORITY_OF_EXAM = 'E' ) THEN 'INSUFFICIENT EXAM'
          ELSE NULL
          END )
     </formula>
	 </property>
  </component>	
 
	<property name="otherDisabilitiesLine1" column="OTHER_DISABILITIES_Line_1" type="java.lang.String" node="otherDisabilitiesLine1" />
	
	<property name="otherDisabilitiesLine2" column="OTHER_DISABILITIES_Line_2" type="java.lang.String" node="otherDisabilitiesLine2" />

	<property name="otherDisabilitiesLine3" column="OTHER_DISABILITIES_Line_3" type="java.lang.String" node="otherDisabilitiesLine3" />

	<property name="transcriptionDate" formula="STRING(TRANSCRIPTION_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="transcriptionDate//literal" />

	<property name="dateApproved" formula="STRING(DATE_APPROVED,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateApproved//literal" />

	<property name="dateReleased" formula="STRING(DATE_RELEASED,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateReleased//literal" />
 
  <component name="releasedBy" node="releasedBy">
    <component name="identifier" node="identifier">
      <property name="identity" column="RELEASED_BY" type="java.lang.String" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>	
    <component name="name" node="name">
      <property name="displayName" column="RELEASEDBYX" type="java.lang.String" node="displayName" />
    </component>	
  </component>
  
	<property name="datePrintedByRO" formula="STRING(DATE_PRINTED_BY_THE_RO,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="datePrintedByRO//literal" />
  
  <component name="printedBy" node="printedBy">
    <component name="identifier" node="identifier">
      <property name="identity" column="PRINTED_BY" type="java.lang.String" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>  
    <component name="name" node="name">
      <property name="displayName" column="PRINTEDBYX" type="java.lang.String" node="displayName" />
    </component>  
  </component>
  
  <component name="status" node="status">
	 <property name="code" column="REQUEST_STATUS" type="java.lang.String" node="code" />
	 <property name="displayText" type="java.lang.String" node="displayText" >
	      <formula>
          (CASE
          WHEN ( REQUEST_STATUS = 'N' ) THEN 'NEW'
          WHEN ( REQUEST_STATUS = 'P' ) THEN 'PENDING, REPORTED'
          WHEN ( REQUEST_STATUS = 'S' ) THEN 'PENDING, SCHEDULED'
          WHEN ( REQUEST_STATUS = 'R' ) THEN 'RELEASED TO RO, NOT PRINTED'
          WHEN ( REQUEST_STATUS = 'C' ) THEN 'COMLETED, PRINTED BY RO'
          WHEN ( REQUEST_STATUS = 'X' ) THEN 'CANCELLED BY MAS'
          WHEN ( REQUEST_STATUS = 'RX' ) THEN 'CANCELLED BY RO'
          WHEN ( REQUEST_STATUS = 'T' ) THEN 'TRANSCRIBED'
          WHEN ( REQUEST_STATUS = 'NT' ) THEN 'NEW, TRANSFERRED IN'
          WHEN ( REQUEST_STATUS = 'CT' ) THEN 'COMPLETED, TRANSFERRED OUT'
          ELSE NULL
          END )
     </formula>
   </property>
  </component>

	<property name="elapsedTime" column="ELAPSED_TIME" type="java.lang.String" node="elapsedTime" />

	<property name="cancellationDate" formula="STRING(CANCELLATION_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="cancellationDate//literal" />

  <component name="cancelledBy" node="cancelledBy">
    <component name="identifier" node="identifier">
      <property name="identity" column="CANCELLED_BY" type="java.lang.String" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>  
    <component name="name" node="name">
      <property name="displayName" column="CANCELLEDBYX" type="java.lang.String" node="displayName" />
    </component>  
  </component>

  <component name="claimFolderRequired" node="claimFolderRequired">
   <property name="displayText" column="CLAIM_FOLDER_REQUIRED" type="java.lang.String" node="displayText" />
  </component>  
  
  <component name="otherDocumentsRequired" node="otherDocumentsRequired">
   <property name="displayText" column="OTHER_DOCUMENTS_REQUIRED" type="java.lang.String" node="displayText" />
  </component>  

	<property name="lastExamAddDate" formula="STRING(LAST_EXAM_ADD_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="lastExamAddDate//literal" />
  
  <component name="lastPersonToAddExam" node="lastPersonToAddExam">
    <component name="identifier" node="identifier">
      <property name="identity" column="LAST_PERSON_TO_ADD_EXAM" type="java.lang.String" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>  
    <component name="name" node="name">
      <property name="displayName" column="LASTPERSONTOADDEXAMX" type="java.lang.String" node="displayName" />
    </component>  
  </component>
  
	<property name="remarksModificationDate" formula="STRING(REMARKS_MODIFICATION_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="remarksModificationDate//literal" />

  <component name="remarksModifiedBy" node="remarksModifiedBy">
    <component name="identifier" node="identifier">
      <property name="identity" column="REMARKS_MODIFIED_BY" type="java.lang.String" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>  
    <component name="name" node="name">
      <property name="displayName" column="REMARKSMODIFIEDBYX" type="java.lang.String" node="displayName" />
    </component>  
  </component>

  <component name="routingLocation" node="routingLocation">
    <property name="identity" column="ROUTING_LOCATION" type="java.lang.String" node="identity" />
	  <property name="name" column="ROUTINGLOCATIONX" type="java.lang.String" node="name" />
  </component>
  
	<property name="approvedBy" column="APPROVED_BY" type="java.lang.String" node="approvedBy" />
  
	<property name="approvalDateTime" formula="STRING(APPROVAL_DATETIME,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="approvalDateTime//literal" />

	<property name="returnedToOwnerSiteBy" column="RETURNED_TO_OWNER_SITE_BY" type="java.lang.String" node="returnedToOwnerSiteBy" />

  <component name="ownerDomain" node="ownerDomain">
	 <property name="code" column="OWNER_DOMAIN" type="java.lang.String" node="code" />
	 <property name="displayText" column="OWNERDOMAINX" type="java.lang.String" node="displayText" />
  </component>	

	<property name="lastRatingExamDate" formula="STRING(LAST_RATING_EXAM_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="lastRatingExamDate//literal" />

	<property name="originalRequestPointer" column="ORIGINAL_REQUEST_POINTER" type="java.lang.String" node="originalRequestPointer" />

  <component name="transferredToAnotherSite" node="transferredToAnotherSite">
	 <property name="displayText" column="TRANSFERRED_TO_ANOTHER_SITE" type="java.lang.String" node="displayText" />
  </component>

	<property name="dateTransferredToOtherSite" formula="STRING(DATE_TRANSFERRED_TO_OTHER_SITE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateTransferredToOtherSite//literal" />

	<property name="dateTransferredInFromRemoteSite" formula="STRING(DATE_TRANSFRD_IN_FRM_REM_SITE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateTransferredInFromRemoteSite//literal" />

	<property name="dateAllTransfersReturned" formula="STRING(DATE_ALL_TRANSFERS_RETURNED,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateAllTransfersReturned//literal" />

  <component name="original2507Request" node="original2507Request">
	 <property name="identity" column="ORIGINAL_2507_REQUEST" type="java.lang.String" node="identity" />
   <property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_396.3'" type="java.lang.String" node="namespaceId"/>
  </component>	

	<property name="original2507ProcessingTime" column="ORIGINAL_2507_PROCESSING_TIME" type="java.lang.String" node="original2507ProcessingTime" />

  <component name="recordIdentifier" node="recordIdentifier">
   <property name="identity" column="ROWID" type="java.lang.String" insert="false" update="false" node="identity" />
   <property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_409.68'" type="java.lang.String" node="namespaceId"/>
  </component>  
	
</class>

  <query name="RequestsAndExamsRead1.ExamRequest2507.examRequests">
    <![CDATA[
        from RequestsAndExamsRead1ER er
        where er.patient.identifier.identity in ( :pids )
    ]]>
  </query>

  <query name="RequestsAndExamsRead1.ExamRequest2507.examRequests.date">
    <![CDATA[
        from RequestsAndExamsRead1ER er
        where er.patient.identifier.identity in ( :pids )
        and ( (er.requestDate.timestamp between :startDate and :endDate) or (er.requestDate.timestamp is null) )
    ]]>
  </query>
  
  <query name="RequestsAndExamsRead1.ExamRequest2507.examRequests.date.requestStatus">
    <![CDATA[
        from RequestsAndExamsRead1ER er
        where er.patient.identifier.identity in ( :pids )
        and ( (er.requestDate.timestamp between :startDate and :endDate) or (er.requestDate.timestamp is null) )
        and er.status.code in (:requestStatus)
    ]]>
  </query>
  
  
  <query name="RequestsAndExamsRead1.ExamRequest2507.examRequests.requestStatus">
    <![CDATA[
        from RequestsAndExamsRead1ER er
        where er.patient.identifier.identity in ( :pids )
        and er.status.code in (:requestStatus)
    ]]>
  </query>


<!-- <sql-query name="RequestsAndExamsRead1.ExamRequest2507.examRequests"> -->
<!--     <![CDATA[ -->
<!--     {call VISTA.HDSREPRPC_Exams(:pids,'','','')} -->
<!--     ]]> -->
<!-- </sql-query> -->

<!-- <sql-query name="RequestsAndExamsRead1.ExamRequest2507.examRequests.status"> -->
<!--     <![CDATA[ -->
<!--     {call VISTA.HDSREPRPC_Exams(:pids,'','',:status)} -->
<!--     ]]> -->
<!-- </sql-query> -->

<!-- <sql-query name="RequestsAndExamsRead1.ExamRequest2507.examRequests.date"> -->
<!--     <![CDATA[ -->
<!--     {call VISTA.HDSREPRPC_Exams(:pids,:startDate,:endDate,'')} -->
<!--     ]]> -->
<!-- </sql-query> -->

<!-- <sql-query -->
<!-- 	name="RequestsAndExamsRead1.ExamRequest2507.examRequests.date.status"> -->
<!--     <![CDATA[ -->
<!--     {call VISTA.HDSREPRPC_Exams(:pids,:startDate,:endDate,:status)} -->
<!--     ]]> -->
<!-- </sql-query> -->

</hibernate-mapping>
