<?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="performingOrganization" table="VISTA_HDSI.LABORATOX_ACCESSION_AREA_60_11_EXT" lazy="false" node="performingOrganization">
		<id name="id" type="java.lang.String">
			<column name="RowId"/>
			<generator class="assigned"/>
		</id>
		<property name="laboratoryTest" type="big_decimal" column="LABORATORY_TEST" node="laboratoryTest"/>
		<component name="identifier" node="identifier">
			<property name="identity" type="big_decimal" column="INSTITUTION" node="identity"/>
			<property name="name" type="java.lang.String" column="INSTITUTIONX" node="name"/>
			<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" node="assigningAuthority"/>
			<property name="stationNumber" column="PerformingOrgStationNumberExt" type="java.lang.String" node="stationNumber"/>
		</component>
		<component name="address" node="address">
			<property name="line1" column="PerformingOrgStreet1Ext" type="java.lang.String" node="line1"/>
			<property name="line2" column="PerformingOrgStreet2Ext" type="java.lang.String" node="line2"/>
			<property name="city" column="PerformingOrgCityExt" type="java.lang.String" node="city"/>
			<property name="state" column="PerformingOrgStateExt" type="java.lang.String" node="state"/>
			<property name="postalCode" column="PerformingOrgPostalCodeExt" type="java.lang.String" node="postalCode"/>
			<property name="country" formula="'USA'" type="java.lang.String" node="country"/>
		</component>
	</class>

	<class entity-name="inst4PerformingOrganization" table="VISTA_HDSI.INSTITUTION_4" lazy="false" node="performingOrganization">
		<id name="id" type="big_decimal">
			<column name="ROWID"/>
			<generator class="assigned"/>
		</id>
		<component name="identifier" node="identifier">
			<property name="identity" type="big_decimal" column="ROWID" insert="false" update="false" node="identity"/>
			<property name="name" type="java.lang.String" node="name">
				<formula>
				     (CASE
				      WHEN (OFFICIAL_VA_NAME IS NOT NULL) THEN OFFICIAL_VA_NAME
				      ELSE NAME
				      END)
				</formula>
			</property>
			<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" node="assigningAuthority"/>
			<property name="stationNumber" column="STATION_NUMBER" type="java.lang.String" node="stationNumber"/>
		</component>
		<component name="address" node="address">
			<property name="line1" column="STREET_ADDR_1" type="java.lang.String" node="line1"/>
			<property name="line2" column="STREET_ADDR_2" type="java.lang.String" node="line2"/>
			<property name="city" column="CITY" type="java.lang.String" node="city"/>
			<property name="state" type="java.lang.String" node="state">
				<formula>
					(SELECT ST.ABBREVIATION
					FROM VISTA_HDSI.STATE_5 ST
					WHERE ST.ROWID = state)
				</formula>			
			</property>
			<property name="postalCode" column="ZIP" type="java.lang.String" node="postalCode"/>
			<property name="country" formula="'USA'" type="java.lang.String" node="country"/>
		</component>
	</class>
	
	<query name="labTests.labTest.chemistryResults.chemistryResult.performingOrganization"> 
		<![CDATA[ 
	 		from performingOrganization performingOrganization
	 		where performingOrganization.laboratoryTest = :labTestFieldNum
	 	]]>
	</query>
	
	<query name="labTests.labTest.chemistryResults.chemistryResult.inst4PerformingOrganization"> 
	 	<![CDATA[ 
	 		from inst4PerformingOrganization performingOrganization
	 		where performingOrganization.identifier.identity = :labTestFieldNum
	 	]]>
	</query>

</hibernate-mapping>