<?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"
[
<!ENTITY patientLite SYSTEM 	"classpath://gov/va/med/cds/persistence/hibernate/common/PatientLitePojo.hbm">
]
>

<hibernate-mapping default-lazy="false"	default-cascade="all">
	<class name="gov.va.med.cds.template.generated.vitalsigns.VitalSignObservationEvent"  table="VITAL30_V" lazy="false" >
		<id type="java.lang.Long" name="id">
			<column name="VITAL_ID" />
			<generator class="sequence">
				<param name="sequence">vital_seq_id</param>
			</generator>
		</id>

		<component name="recordIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
			<property name="identity" column="RECORDIDENTIFIER_IDENTITY" type="java.lang.String" />
			<property name="namespaceId" column="RECORDIDENTIFIER_NAMESPACEID" type="java.lang.String" />
			<property name="universalId" column="RECORDIDENTIFIER_UNIVERSALID" type="java.lang.String" />
			<property name="universalIdType" column="RECORDIDENTIFIER_UNIVERSTYP" type="java.lang.String"  />
		</component>

		<!-- import from .../common/PatientLite.hbm -->
		&patientLite;

		<property name="observationTime" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType" >
			<column name="VITAL_OBSERVATION_TM" />
			<column name="VITAL_OBSERVATION_TM_NBR" />
		</property>
		
		<component name="observationMethod" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="displayText" column="OBSERVATION_METHOD_DSPLYTXT" type="java.lang.String"/>		
		</component>

		<component name="observedCharacteristic" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="displayText" column="OBSERVED_CHAR_DSPLYTXT" type="java.lang.String"  />
		</component>

		<component name="homeTelehealthMonitor" class="gov.va.med.cds.template.generated.vitalsigns.HomeTelehealthMonitor"> 
 			<property name="measurementDevice" column="HTH_MEASURE_DEVICE" type="java.lang.String" />
        </component>

		<property name="status" column="VITAL_STATUS" type="java.lang.String"  />

		<component name="supplementalOxygen" class="gov.va.med.cds.template.generated.vitalsigns.OxygenAdministration"> 
			<property name="flowRateValue" column="FLOW_RATE_VAL" type="java.lang.String" />
	        <component name="flowRateUnit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="displayText" column="FLOW_RATE_UOFM_DSPLYTXT" type="java.lang.String" />
			</component> 
			<property name="concentrationValue" column="CONCENTRATION_VAL" type="java.lang.String"  />
	        <component name="concentrationUnit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="displayText" column="CONCENTRATION_UOFM_DSPLYTXT" type="java.lang.String" />
			</component>        
        </component>

		 <component name="orderingFacilityIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72OrganizationIdentifier">
			<property name="name" column="ORD_FCLTY_NAME" type="java.lang.String"  />
		</component>

		<!-- one-to-many set -->
		<component name="vitalSignObservation" class="gov.va.med.cds.template.generated.vitalsigns.VitalSignObservation">
			<property name="value" column="OBSERVATION_VAL" type="java.lang.String"/>
	        <component name="unit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="displayText" column="OBSERVATION_UOFM_DSPLYTXT" type="java.lang.String"/>
			</component>
			
			<list name="qualifier" cascade="all" fetch="subselect" batch-size="100">
				<key column="VITAL_ID" not-null="true" update="false" />
				<list-index column="LINE_NBR" />
				<one-to-many entity-name="VitalSignQualifierVW"/>
			</list>
		</component>

		<component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
			<property name="namespaceId" column="RECORDSOURCE_NAMESPACEID" type="java.lang.String"  />
			<property name="universalId" column="RECORDSOURCE_UNIVERSALID" type="java.lang.String"  />
			<property name="universalIdType" column="RECORDSOURCE_UNIVERSTYP" type="java.lang.String"  />
		</component>
		
		<property name="recordVersion" column="RECORD_VERSION" type="integer"  />
		
        <property name="recordUpdateTime" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType" >
            <column name="RECORD_UPDATE_TM"/>
            <column name="RECORD_UPDATE_TM_NBR"/>
        </property>
    
		<property name="requestId" column="REQUEST_ID" type="java.lang.String"/>

	</class>


	<!-- Vitals Named Queries HQL -->

	<query name="VWVitalsignsRead40010.VitalSignObservationEvent.patient">
		<![CDATA[
		from VitalSignObservationEvent vital
		where vital.patient.identifier.assigningFacility || '/' || vital.patient.identifier.identity in ( :pids )
		]]>
	</query>

	<query name="VWVitalsignsRead40010.VitalSignObservationEvent.patient.date">
		<![CDATA[
		from VitalSignObservationEvent vital
		where vital.patient.identifier.assigningFacility || '/' || vital.patient.identifier.identity in ( :pids )
		and ( vital.observationTime.numeric between :startDate and :endDate or vital.observationTime.numeric is null )
		]]>
	</query>

	<query name="VWVitalsignsRead40010.VitalSignObservationEvent.patient.identifiers">
		<![CDATA[
		from VitalSignObservationEvent vital
		where vital.patient.identifier.assigningFacility || '/' || vital.patient.identifier.identity in ( :pids ) and
		vital.recordIdentifier.identity || '/' || vital.recordIdentifier.namespaceId || '/' ||
		vital.recordIdentifier.universalId || '/' || vital.recordIdentifier.universalIdType in ( :recordIdentifiers )
		]]>
	</query>

</hibernate-mapping>
