<?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="RequestsAndExamsRead1EX" table="VISTA_HDSI.F2507_EXAM" node="exam">

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

	<property name="examReferenceNumber" column="EXAM_REFERENCE_NUMBER" type="java.lang.String" node="examReferenceNumber" />

  <component name="patient" node="patient">
    <component name="identifier" node="identifier">
      <property name="identity" column="f2507_REQUEST" type="big_decimal" insert="false" update="false" node="identity" />
      <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
    </component>	
  </component>
  
  <component name="request2507" node="request2507">
    <property name="identity" column="f2507_REQUEST" type="java.lang.String" node="identity" />
    <property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" node="namespaceId" />
  </component>
  
  <component name="examType" node="examType">
    <property name="code" column="EXAM_TYPE" type="java.lang.String" node="code" />
  </component>

	<property name="printName" column="EXAMTYPEX" type="java.lang.String" node="printName" />

  <component name="status" node="status">
   <property name="code" column="STATUS" type="java.lang.String" node="code" />
   <property name="displayText" type="java.lang.String" node="displayText" >
     <formula>
          (CASE
          WHEN ( STATUS = 'O' ) THEN 'OPEN'
          WHEN ( STATUS = 'C' ) THEN 'COMLETED'
          WHEN ( STATUS = 'X' ) THEN 'CANCELLED BY MAS'
          WHEN ( STATUS = 'RS' ) THEN 'CANCELLED BY RO'
          WHEN ( STATUS = 'T' ) THEN 'TRANSFERRED OUT'
          ELSE NULL
          END )
     </formula>
   </property>
  </component>  

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

  <property name="dateOfExam" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false" node="dateOfExam//literal">
    <column name="DATE_OF_EXAM"/>
    <formula>VISTA_HDSI.HDSREPSQLUtil1_StationNumber()</formula>
  </property>

	<property name="examiningPhysician" column="EXAMINING_PHYSICIAN" type="java.lang.String" node="examiningPhysician" />

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

  <component name="examPlace" node="examPlace">
   <property name="code" column="EXAM_PLACE" type="java.lang.String" node="code" />
   <property name="displayText" type="java.lang.String" node="displayText" >
     <formula>
          (CASE
          WHEN ( STATUS = 'O' ) THEN 'OTHER STATION'
          WHEN ( STATUS = 'C' ) THEN 'CLINIC'
          WHEN ( STATUS = 'F' ) THEN 'FEE LOCATION'
          ELSE NULL
          END )
     </formula>
   </property>

  </component>  

  <component name="insufficientReason" node="insufficientReason">
   <property name="code" column="INSUFFICIENT_REASON" type="java.lang.String" node="code" />
   <property name="displayText" column="INSUFFICIENTREASONX" type="java.lang.String" node="displayText" />
  </component>  

	<property name="originalProvider" column="ORIGINAL_PROVIDER" type="java.lang.String" node="originalProvider" />
	
  <component name="cancelledBy" node="cancelledBy">
    <component name="identifier" node="identifier">
      <property name="identity" column="CANCELED_BY" 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 name="name" node="name">
      <property name="displayName" column="CANCELEDBYX" type="java.lang.String" node="displayName" />
    </component>  
  </component>
	
  <component name="cancellationReason" node="cancellationReason">
   <property name="code" column="CANCELLATION_REASON" type="java.lang.String" node="code" />
   <property name="displayText" column="CANCELLATIONREASONX" type="java.lang.String" node="displayText" />
  </component>  

	<property name="transferredOutBy" column="TRANSFERRED_OUT_BY" type="java.lang.String" node="transferredOutBy" />
	
	<component name="transferredOutTo" node="transferredOutTo">
	 <property name="identity" column="TRANSFERRED_OUT_TO" type="java.lang.String" node="identity" />
	 <property name="name" column="TRANSFERREDOUTTOX" type="java.lang.String" node="name" />
	</component>
	
	<property name="dateTransferredIn" formula="STRING(DATE_TRANSFERRED_IN,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="dateTransferredIn//literal" />

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

	<property name="insufficientRemarks" column="INSUFFICIENTREMARKSWP" type="java.lang.String" node="insufficientRemarks" />

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

  <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()||'_396.4'" type="java.lang.String" node="namespaceId"/>
  </component>  
	
</class>

  <query name="RequestsAndExamsRead1.Exam2507.exams">
    <![CDATA[
        from RequestsAndExamsRead1EX ex
        where ex.patient.identifier.identity in ( :pids )
    ]]>
  </query>

  <query name="RequestsAndExamsRead1.Exam2507.exams.date">
    <![CDATA[
        from RequestsAndExamsRead1EX ex
        where ex.patient.identifier.identity in ( :pids )
        and ( (ex.dateOfExam.timestamp between :startDate and :endDate) or (ex.dateOfExam.timestamp is null) )
    ]]>
  </query>
  
  <query name="RequestsAndExamsRead1.Exam2507.exams.date.status">
    <![CDATA[
        from RequestsAndExamsRead1EX ex
        where ex.patient.identifier.identity in ( :pids )
        and ( (ex.dateOfExam.timestamp between :startDate and :endDate) or (ex.dateOfExam.timestamp is null) )
        and ex.status.code in (:status)
    ]]>
  </query>

  <query name="RequestsAndExamsRead1.Exam2507.exams.status">
    <![CDATA[
        from RequestsAndExamsRead1EX ex
        where ex.patient.identifier.identity in ( :pids )
        and ex.status.code in (:status)
    ]]>
  </query>
</hibernate-mapping>
