<?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="VitalSignQualifier" name="gov.va.med.cds.template.generated.vitalsigns.subquery.VitalSignQualifierWrapper" table="VISTA_HDSI.GMRV_VITAL_X_QUAL_120_505_EXT" >
		<id name="id" type="java.lang.String">
			<column name="ROWID" />
			<generator class="assigned" />
		</id>

		<property name="gmrvVitalMeasurement" column="GMRV_VITAL_MEASUREMENT" type="big_decimal" insert="false" update="false" />

		<component name="qualifier" class="gov.va.med.cds.template.generated.vitalsigns.VitalSignQualifier">
			<component name="value" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="QualifierVuid" type="java.lang.String" node="code" />
				<property name="displayText" column="QUALIFIERX" type="java.lang.String" node="displayText" />
				<property name="codingSystem" type="java.lang.String" node="codingSystem">
					<formula>
						(CASE
						WHEN (QualifierVuid IS NOT NULL OR QUALIFIERX IS NOT NULL) THEN '99VA120.52'
						ELSE NULL
						END)
        		</formula>
				</property>
			</component>
		</component>

	</class>

	<class entity-name="VitalSignQualifierVW" name="gov.va.med.cds.template.generated.vitalsigns.subquery.VitalSignQualifierWrapper" table="VISTA_HDSI.GMRV_VITAL_X_QUAL_120_505_EXT" >
		<id name="id" type="java.lang.String">
			<column name="ROWID" />
			<generator class="assigned" />
		</id>

		<property name="gmrvVitalMeasurement" column="GMRV_VITAL_MEASUREMENT" type="big_decimal" insert="false" update="false" />

		<component name="qualifier" class="gov.va.med.cds.template.generated.vitalsigns.VitalSignQualifier">
			<component name="value" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="QualifierVuid" type="java.lang.String" node="code" />
				<property name="displayText" column="QUALIFIERX" type="java.lang.String" node="displayText" />
				<property name="codingSystem" type="java.lang.String" node="codingSystem">
					<formula>
						(CASE
						WHEN (QualifierVuid IS NOT NULL OR QUALIFIERX IS NOT NULL) THEN '99VA120.52'
						ELSE NULL
						END)
        		</formula>
				</property>
			</component>
		</component>

	</class>

	<!-- VitalSignQualifier Named Queries HQL -->

	<!-- <query name="VitalsignsRead40010.VitalSignObservationEvent.patient"> -->
	<query name="VitalsignsRead40010.VitalSignObservationEvent.qualifier">
		<![CDATA[
		select vm
		from VitalSignObservationEvent vital, VitalSignQualifier vm
		where vital.id = vm.gmrvVitalMeasurement
		      and vital.patient.identifier.identity in ( :pids )
		]]>
	</query>

	<query name="VWVitalsignsRead40010.VitalSignObservationEvent.qualifier">
		<![CDATA[
		select vm
		from  VitalSignObservationEvent vital, VitalSignQualifierVW vm
		where vital.id = vm.gmrvVitalMeasurement
		      and vital.patient.identifier.identity in ( :pids )
		]]>
	</query>
 
	<query name="VWVitalsignsRead40010.VitalSignObservationEvent.qualifier.date">
		<![CDATA[
		select vm
		from  VitalSignObservationEvent vital, VitalSignQualifierVW vm
		where vital.id = vm.gmrvVitalMeasurement 
		       and vital.patient.identifier.identity in ( :pids )
			   and ( (vital.observationTime.timestamp between :startDate and :endDate) or (vital.observationTime.timestamp is null))
		]]>
	</query>

	<query name="VitalsignsRead40010.VitalSignObservationEvent.qualifier.date">
		<![CDATA[
		select vm
		from  VitalSignObservationEvent vital, VitalSignQualifier vm
		where vital.id = vm.gmrvVitalMeasurement 
		       and vital.patient.identifier.identity in ( :pids )
			   and ( (vital.observationTime.timestamp between :startDate and :endDate) or (vital.observationTime.timestamp is null))
		]]>
	</query>

</hibernate-mapping>