<?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="errorReasons" name="gov.va.med.cds.template.generated.vitalsigns.subquery.ErrorReasonWrapper" table="VISTA_HDSI.GMRVX_REASON_ENT_I_120_506_EXT" node="errorReason">

		<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="reason" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="ReasonEnteredInErrorVuid" type="java.lang.String" node="code" insert="false" update="false" />
			<property name="displayText" column="REASON_ENTERED_IN_ERROR" type="java.lang.String" node="displayText" insert="false" update="false" />
			<property name="codingSystem" type="java.lang.String" node="codingSystem">
				<formula>
					(CASE
					WHEN (GMRV_VITAL_MEASUREMENT IS NOT NULL OR REASON_ENTERED_IN_ERROR IS NOT NULL) THEN '99VA8985.1'
					ELSE NULL
					END)
        		</formula>
			</property>
		</component>
	</class>

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

	<query name="VitalsignsRead40010.VitalSignObservationEvent.errorReasons.date">
		<![CDATA[
		select er
		from errorReasons er, VitalSignObservationEvent vital
		where vital.id = er.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>
